• I have a few different issues regarding puck.js and SIM 800L module. The first issue is that if I power down the puck (remove the power from the VCC pin, and power it back up, it does not run the initialization code from onInit(). I have tried both onInit() and Save on Send option (w/o) onInit() and neither appear to work. I have to reconnect the puck to the web bluetooth and re-install the code. Please see the SMS.js file attached, which is essentially the same exact code that was provided in the 'Control Bluetooth Lights with SMS' tutorial.

    The second issue that I have is that adding a function in the sms.init section causes the sensor(I've tried both PIR and Microwave sensors) to go crazy and appears to keep the pin on as high level even when motion is not detected, sending me multiple texts. I am sure that I am probably doing something wrong here that needs corrected. I have included the PIR.js file as well for review.

    A few other things to mention, for the PIR and Microwave sensor, I have ensured to place these on a separate power rail and have a filter cap between VCC and Ground rails. I have tried both 3.3 and 5 volts for both of the sensors as well. Additionally, if I just load up a .js file to test the sensor (without the SIM 800L module in the code, but still connected to the puck) then they work and properly log when motion is detected.

    Additionally, I had to revert the firmware from v2.00 to v1.99 as my puck disappeared from the Web bluetooth as a selectable device and refreshing to v2.00 still didn't get it to show. Not sure if I have a defective puck, but there have been a few quirks with it. Overall, very satisfied with it and hope to iron everything out. Thanks for any insight anyone may be able to provide and please let me know if there are any questions for me.


    2 Attachments

  • Hi! For SMS, can you try:

    var sms;
    
    function onInit() {
    Bluetooth.setConsole(1);
    Serial1.setup(115200, { rx: D1, tx : D2 });
    var ATSMS = require("ATSMS");
    sms = new ATSMS(Serial1);
    
    sms.init(function(err) {
      if (err) throw err;
      console.log("Initialised!");
    
      sms.list("ALL", function(err,list) {
        if (err) throw err;
        if (list.length)
          console.log(list);
        else
          console.log("No Messages");
      });
    
      // and to send a message:
      //sms.send('+441234567890','Hello world!', callback)
    });
    
    sms.on('message', function(msgIndex) {
      console.log("Got message #",msgIndex);
      sms.get(msgIndex, function(err, msg) {
        if (err) throw err;
        print("Read message", msg);
        var txt = msg.text.toLowerCase();
        if (txt=="on") LED1.set();
        if (txt=="off") LED1.reset();
        // delete all messages to stop us overflowing
        sms.delete("ALL");
      });
    });
    }
    
    onInit();
    

    It's a minor tweak but it seems you had sms.on('message' being called while sms was still undefined, and I imagine that would have caused an error.

    Using save on send with the code as provided from the 'Control Bluetooth Lights with SMS' tutorial should have worked fine though.

    With the PIR, did you ensure that GND was properly shared between all devices? That's usually the biggest cause of this kind of problem - that to send a signal you actually need two wires (GND and signal), not just the signal wire on its own.

    And for the 2v00 upgrade, did you try long-pressing the button when you apply power? http://www.espruino.com/Puck.js#resettinĀ­g-puck-js That would clear out any old saved code that might potentially have caused problems when you upgraded

  • Hi Gordon,

    Thank you for your quick follow up. I have actually tried wrapping the entire code in onInit, but then nothing runs at all, it just hangs and nothing is spit out on the console. I had tried several times to update the firmware and there was a long press of the button prior to applying power. Had a green light, then switch to the red light each time. Only after downgrading to v1.99 did it seem to be recognized again.

    As for the PIR and Microwave sensors, I've tried common ground initially, prior to connecting to a separate rail, I typically do a common ground, but have heard that sometimes these sensors need a separate power rail as they can cause noise, hence the reason for the filter cap. In either case, when I have introduced the SMS module code in addition to the sensor, it locks the input pin from the sensor on high and multiple messages are sent.

    I'm wondering what else I can try at this point. Thanks again for all of your help.

  • Hmm - it's a bit tricky to debug stuff like this.

    Could you try - once you're connected via Bluetooth - typing load() on the left-hand side? This will have more or less the same effect as a power-on reset, so you should be able to see if there are any errors or anything written to the console. Failing that, you could try blinking LEDs to give you some idea of the status of your code.

    Had a green light, then switch to the red light each time.

    And it just stays on red? It should go:

    • Green (3 sec)
    • Brighter green (0.5 sec)
    • All LEDs on
    • 1 sec
    • Red flashing 5 times

    Is it possible that you downloaded and flashed the wrong firmware package? Like the Pixl rather than Puck, or something like that? Maybe you could try re-downloading, especially as there is a 2v01 firmware now.

    As for the PIR and Microwave sensors, I've tried common ground initially

    Could you post up a quick sketch of your circuit?

    You could try uploading just:

    setInterval(function() {
      LED.write(pin.read());
    }, 10);
    

    And see what happens?

    It's possible that some sensors only provide a pullup(or pull down) on a signal and are open circuit the rest of the time. In that case you'd need to turn on the Puck's internal pullup resistors with pinMode(pin, "input_pullup") (or input_pulldown).

    The other potential issue is if you're using (for instance) a 5v circuit for the sensor then it might be outputting 5v signals directly into the Puck, which would cause all kinds of havoc (it's only designed for 3.3v level signals).

  • Hey Gordon, thanks for the continued follow ups. I have made sure that it is puck.js firmware being uploaded to the board. That said, I upgraded the firmware tonight to v2.01. I immediately noticed that code is substantially faster to load to the board. I also hard reset prior to uploading the firmware to clear anything out beforehand.

    I measured the voltage passed to the puck from the output of the PIR sensor, it logs 3.27V at it's high peak, so everything looks good there.

    I have omitted the PIR sensor for the time being as I really want to focus on getting the code to work after removing and restoring power. If I disconnect from the serial bluetooth connection, but keep power supplied to the board, it will continue to work. However, if I remove power and restore power, I get no response when sending on or off via text message.

    I did notice that if I restore power and connect via web bluetooth and then call the load(); in the REPL, that it initializes and then works. I have a feeling that maybe the code running prior to the modem getting power may be causing problems when the code runs. However, I have also tried applying power to the modem until the modem boots up, then powering up the module and still no luck. I then tried to wrap all of the code in a setTimeout(function(){all of code here},12000); to see if setting a 12 second delay to allow the modem to boot up would help.

    I've commented out Bluetooth.setConsole(1) as well as uncommented it. As mentioned, it all works great, when connected to the web console and even after disconnecting from the console, just as soon as I remove power, it no longer works.

    As for a sketch of what I have wired up, I have attached a schematic with Fritzing(I had to substitute a pico.js board as there were no puck.js boards)

    It's pretty barebones as I have removed the PIR sensor from the equation at this time. Please let me know if you have any other thoughts. I did get the MDBT42Q breakout board today, but aside from soldering the headers to the board, I haven't been able to flash firmware or test on that board yet.

    Thanks again for all of the help and please let me know if you have any questions for me. I have also included the current sketch that I am using (I've omitted all of the other tests that I had mentioned, to confirm that even on a clean sketch using direct to flash execute code on boot and only the SIM800L module with 3.3 V power supply being fed to the puck it is still not working as expected).

    Bluetooth.setConsole(1);
    Serial1.setup(9600, { rx: D29, tx : D28 });
    var ATSMS = require("ATSMS");
    var sms = new ATSMS(Serial1);
    
    sms.init(function(err) {
      if (err) throw err;
      console.log("Initialised!");
    
      sms.list("ALL", function(err,list) {
        if (err) throw err;
        if (list.length)
          console.log(list);
        else
          console.log("No Messages");
      });
    
      // and to send a message:
      //sms.send('+441234567890','Hello world!', callback)
    });
    
    
    sms.on('message', function(msgIndex) {
      console.log("Got message #",msgIndex);
      sms.get(msgIndex, function(err, msg) {
        if (err) throw err;
        print("Read message", msg);
        var txt = msg.text.toLowerCase();
        if (txt=="on") LED1.set();
        if (txt=="off") LED1.reset();
        // delete all messages to stop us overflowing
        sms.delete("ALL");
      });
    });
    

    2 Attachments

  • Thanks for trying all that and for posting up the photo - that really helps.

    Could you try sending the above code with 'save on send' set to 'direct to flash', and replace Bluetooth.setConsole(1); with:

    var log="";
    LoopbackB.on('data',d=>log+=d);
    LoopbackA.setConsole();
    

    Then after you reset, power on, and waiting a bit do print(log) and see if it says anything - it should show you if there were any error messages displayed.

    Also, do you have a lithium ion battery available that you could use as a power source? I've had a lot of issues when trying to power SIM800 off of mains adaptors. It draws huge peaks of current when trying to connect to GSM and mostly they really struggle supplying enough power and then the SIM800 bottoms out. A LiPo battery can pretty much always supply enough instantaneous power though - they fact that it's a bit below 5v isn't usually a problem.

  • So, I replaced Bluetooth.setConsole(1); with the code snippet you sent and also ensured that the code is set to 'direct to flash' then reset and waited a bit and did the print(log) and returned the following:

    <- Serial1
    Uncaught ATE0 ERROR undefined
    -> Bluetooth
    =undefined

    As for the LiPo, I do have a few lying around, but do not have a proper jumper to connect to breadboard at the moment. I'll have to see if I can locate something to rig it up. Actually I do have a protoshield with a battery. I will charge it and try later today.

    Thanks again!

  • As an added question, do you know of any solid liPo's that would be compatible with breadboard (future protoboard) with easy ability to charge? Most that I have seen have the tiny j connectors (which are the ones I currently have).

    Thanks again

  • <- Serial1
    Uncaught ATE0 ERROR undefined
    -> Bluetooth
    =undefined
    

    Ok, great - that's good(ish). So the code is running, but it's the SIM900 that isn't responding.

    So I guess it's either power, or you need to try with a delay before initialising it.

    do you know of any solid liPo's that would be compatible with breadboard

    Not specifically. I use LiPos with a JST connector. The JST connectors have a 2mm pitch on them so if you have a socket for one you can poke it into breadboard directly (it's not a very tight fit) or you can actually just solder a bit of 0.1" header onto the end of the socket.

  • I was able to get this to work with both the power adaptor and also with a 9V battery as a separate test. I had to wrap the code in a setTimeout with a delay of 15 seconds to get the modem to initilize. I had performed this step initially; However, it seems wrapping Bluetooth.setConsole(1) inside of the setTimeout caused me problems.

    So, in the end wrapping the entire code(with the exception of the Bluetooth.setConsole(1) in a setTimeout for 15 seconds, in addition to the 'Direct to flash(Execute at boot)' was the needed fix to resolve this one. I hope others find this post useful should the encounter the same issues I did. Final code is posted below. On a side note and you will see the PIR block of code included below, this is also now stable and works as expected. Seems that the setTimeout is pretty crucial, and maybe in certain other cases could use a longer timeout than 15 seconds, to get this to work.

    Bluetooth.setConsole(1);
    setTimeout(function(){
    Serial1.setup(9600, { rx: D29, tx : D28 });
    var ATSMS = require("ATSMS");
    var sms = new ATSMS(Serial1);
    
    sms.init(function(err) {
      if (err) throw err;
      console.log("Initialised!");
    
      sms.list("ALL", function(err,list) {
        if (err) throw err;
        if (list.length)
          console.log(list);
        else
          console.log("No Messages");
      });
    
      // and to send a message:
      //sms.send('+441234567890','Hello world!', callback)
       setInterval(function readPIR(){
       PIR = digitalRead(D30);
       print(PIR);
         if(PIR == 1){
           digitalWrite(LED3,1);
           sms.send('+15555555555', 'Motion Detected!');
      }  else{
           digitalWrite(LED3,0);
      }
    }, 2500);
    });
    
    sms.on('message', function(msgIndex) {
      console.log("Got message #",msgIndex);
      sms.get(msgIndex, function(err, msg) {
        if (err) throw err;
        print("Read message", msg);
        var txt = msg.text.toLowerCase();
        if (txt=="on") LED1.set();
        if (txt=="off") LED1.reset();
        // delete all messages to stop us overflowing
        sms.delete("ALL");
      });
    });
    },15000);
    

    I would like to thank you again for all of your help and generous inputs! It has certainly helped me towards a resolution.

  • That's great! Thanks for posting up the code that worked for you as well!

    It's strange about the setConsole being needed right at the start but I guess it's possible that because the SIM900 is on the default Serial1 pins, Espruino auto-initialises serial and moves the console to it, and then maybe the SIM900 sends some messages when it boots and these interfere with Espruino...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Puck.js and SIM 800L module unable to initialize after cutting and restoring power

Posted by Avatar for ok2chatt @ok2chatt

Actions