Avatar for barry_b_benson

barry_b_benson

Member since Jan 2017 • Last active Jul 2019
  • 43 conversations
  • 93 comments

Most recent activity

  • in Interfacing
    Avatar for barry_b_benson

    Hi, I programmed my MDBT42Q module to make a small beep sound whenever I press or release a button. This is the code for my piezo sound effects:

    function beep(f) { 
      if (f===0) digitalWrite(spk,0);
      else analogWrite(spk, 0.5, { freq: f } );
    }
    
    function buttonBoop(f) {
      beep(f);
      setTimeout(function() {digitalWrite(spk, 0);}, 50);
    }
    

    pretty simple, right?

    So I tried to put them into setWatch functions so that my wristwatch(the PCB that houses the MDBT42Q module) can make a small beep whenever a button is pressed. The two setwatches are for when the button is pressed and released. When the button is pressed, the watch displays the hour on its two 7-seg LEDs for as long as the button is held down. when the button is released, the watch displays the minutes for 300 milliseconds. Here is the code:

    setWatch(function(e) {
      data();  // grabs date & time
      buttonBoop(650); // supposed to beep piezo at 650hz for 50 milliseconds
      while (digitalRead(select) != 1) { // the watch displays the hour
        display(1, hourFirstDigit);
        display(2, hourSecondDigit);
      }
      allClear(); // resets 7-segment displays
    }, select, {repeat: true, debounce: 50, edge: "falling"});
    
    setWatch(function(e) {
      data(); // grabs date & time
      buttonBoop(950); // supposed to beep piezo at 950 hz for 50 milliseconds
      for (i = 0; i < 30; i++) { // watch displays the minutes
        display(1, minFirstDigit);
        display(2, minSecondDigit);
      }
        allClear(); // resets the 7 seg LEDs
    }, select, {repeat: true, debounce: 50, edge: "rising"});
    }
    

    the problem is, whenever I press/release the button, the piezo speaker beeps until the LEDs are cleared. That is, when the button is pressed, the piezo beeps at 650hz until I release it, and when the button is released, the piezo beeps at 950mhz for 300mhz - which is when the LEDs are cleared. Sorry if this sounds confusing for you, I can't find a way to word it well.

    I only want the piezo to beep for 50 milliseconds, what is making it go for the entire setWatch() duration?

    The strange thing is, when do a clearWatch() and run this instead...

    setWatch(function(e) {
      buttonBoop(650);
    }, select, {repeat: true, debounce: 50, edge: "falling"});
    
    setWatch(function(e) {
      buttonBoop(950);
    }, select, {repeat: true, debounce: 50, edge: "rising"});
    

    the piezo behaves just fine. A short beep when the button is pressed, and another short beep when the button is released. It's the same setWatch() code but with all the LED/time related code removed. But I can't find anything with my LED/time code. Thought this would help.

    This is the entire source code for my watch. The buggy part is near the end.

    Thanks.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    my plan was to have different devices that I would plug in one at a time. For example, one day I would plug in an I2C LCD module and another day I would take that off and plug in a USB to serial cable. I guess I would be fine with that

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    @Gordon Thanks for the idea, I don't have the skill or area on my circuit board to integrate a lipo charging circuit, so I might just have an off-the-shelf charging board in my charging dock/cable.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    Hey @AkosLukacs, I have two multiplexed 7-segment LEDs and five more LEDs each with their own GPIO pin, all colored blue. All of them are tied to a 330 ohm resistor in series. The microcontroller I'm using operates on 3.3v logic so this might not be necessary, I just tossed the resistors in for safety. The LEDs are fairly visible during normal use, although not at their peak brightness. My circuit is a wristwatch, so I don't have the real estate for two AA batteries.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    Hey @Gordon and @allObjects,
    I just tried this out on a breadboard, and while it does work, my LEDs (multiplexed 7 segments) are very dim when powered by the coin cell only. Without the diode between the coin cell and the microcontroller the LEDs are nice and bright. I have 5 other LEDs each wired to an IO pin and they are slightly dimmer too. When powered by USB though they all light up perfectly.

    I bought 1N4007 diodes, the shop didn't have any schottky diodes. Will the LEDs be fine if I use a schottky diode? Thanks.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    Hi,
    Since the MDBT42Q module is based on the nRF52832, and the nRF52832 chip can assign any two pins as SCL/SDA, can i use both i2c and serial with the same two pins? Not simultaneously, of course, but I would like to use them and switch between I2C and Serial on the fly.

    Thanks.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for barry_b_benson

    You have just to know that your module has 3 - diodeForwardVoltage as input voltage (less than 3V).

    Sorry, but can you clarify that in layman's terms for me please?

Actions