• I have a phone module connected.

    I also have a setWatch on a port where i look for a loss of contact between D27 and D28:

    digitalWrite(D27,1);
    pinMode(D28, "input_pulldown");
    
    setWatch(function() {
      sendAlert();
    }, D28, { repeat: true, edge: 'falling', debounce: 50 });
    

    The serial connection over D29, D30 and D31 seems to set off the contact watch. There is no soldering on the board that could be causing a short, just an unpowered serial device

  • I guess you're setting Serial up somewhere else? Do you think you could post up a little bit of example code that shows the problem by itself?

    D28 is the default UART TX pin at boot (if D29 (default UART RX) is pulled high when power is applied), so I wonder whether somehow it's got stuck as the UART TX pin, so every time you try and send data to the UART, it's sending data to that pin, which is triggering your setWatch?

  • I thought that must be it... but I moved the setWatch to pin 27, connecting with the + of the battery.

    When all I have is the two wires, the setWatch works perfectly responsive. But as soon as the serial is connected to D29, D30, D31 and a switch signal coming from D1 and D2, things go wrong.

    Even when I havent declared any serial, just the presence of the other connection interferes with the contact setWatch.. It responds, but sluggish, and it misses some disconnections.

    Powering on the serial device also triggers the setWatch.

    this is all the code.

    clearWatch();
    clearInterval();
    digitalWrite(D1,0);
    digitalWrite(D2,0);
    
    pinMode(D27, "input_pulldown");
    
    // do check on lost contact
    setWatch(function() {
      sendAlert();
    }, D27, { repeat: true, edge: 'falling', debounce: 50 });
    
    
    function sendAlert(){
    console.log("Contact lost");
    }
    
  • What exactly are D29/30 and 31 connected to? Does the switch make any difference?

    Puck.js is only 3.3v tolerant, so if you were connecting a 5v output signal right to it, that would explain all kinds of trouble, including some crashes!

  • maybe it more the console not keeping up. When I light up a LED on every lost contact it seems to ok..

    Anyway, good to know it shouldn't keep D28 high, thanks

  • Are you using up to date firmware, like 1v93? I know older firmwares could have problems if you printed a lot of data over Bluetooth when it wasn't connected.

  • i am using a mosfet to switch something on and off. But as soon as the signal wire is connected, the contact setWatch becomes unreliable.

    The mosfet connects with the signal wire and ground to the Puck. That ground is also connected to the source of the separate battery running the peripheral.

    Does that mess up what is ground to the puck somehow?

  • any problem with using D27, which is also the capacitance measuring pin?

  • That sounds ok... D27 shouldn't be the capsense pin either (it's D11), but it shouldn't cause you any problems.

    Could you post up the full circuit you're using? My worry would be that if you're switching GND on the external device, when the device itself is off then the voltage on that device (and all pins coming from it) will be at the battery's voltage - which is probably far higher than Puck.js is supposed to take.

    You could try measuring the voltage between GND and every wire going to Puck.js - realistically they should never be any higher than 3.6v. If they are if could be causing damage to Puck.js, and would certainly explain watches going off all the time.

  • how could i prevent that? Guess that is what is happening.

    I have to turn off the serial device (sim800), it then remains connected with Tx, Rx and GND.

    I am switching the GSM on and off through a mosfet and a signal wire. The puck has to share the GND with the GSM gnd going to the mosfet's Source pin right.

    But I think the messy contact alarm happens even without using the mosfet switching

  • I think you need a P-channel MOSFET - which would allow you to switch the positive voltage to the SIM800 rather than GND, and then a resistor to turn it off, and a diode to drop the extra voltage. It's a shame it gets so complicated when the two voltage levels are different and the device isn't 5v tolerant...

    Something like this:

    Battery V+  ---------+--------+---------------------­-+
                         |        |
                        +-+       |
                        |-|       |
                        |-|       |
                        |-|       |
                        +-+       |
                         |    +   |
                         |    +---+
                         +----+
                         |    +---+
                         |    +   |
                         |        |
                         |        +------------------+  SIM800 PWR
                       +-+-+
                        \ /
                       --+--
                         |
                         |
    Espruino ------------+
    
    
    
    
    Espruino GND  ----------------------------------------­+  SIM800 GND
    

    It seems some SIM800 modules have a PWR pin that can be used to switch them on and off though, which would be so much easier.

  • Thanks

    but why is switching ground in this case a problem, others have used Mosfets to switch higher voltages haven't they?

  • It's not the switching that's the problem... It's the fact that you're disconnecting the ground wire. Without ground connected, the voltage across the SIM800 will become 0, and as the power wire is connected, the SIM800's ground (and all its signal outputs) will become the same voltage as the power wire.

    In this case I guess it's connected to a LiPo battery, which could be 4 volts or so? So either you're putting too many volts into Puck.js's inputs, or you're putting a negative voltage (relative to the SIM800's GND) into the SIM800, which it won't like either!

    It's the same reason you're supposed to put the switch for mains-powered devices (like light bulbs) on the live wires, not the neutral wires. If you switch neutral then when the switch is open, the voltage on the neutral wire from the light bulb ends up the same as the live wire - which could be a problem if you weren't expecting it!

  • I do have the ground on the puck connected to the ground on the sim800's power supply, something like this:

    Shouldn't that prevent a difference in ground level?

  • The blue line gets disconnected so that wouldn't help the serial ground.

    Could the serial ground not be connected to the external power supply as well?

  • I'm not sure what you mean by 'Serial ground'?

    So you're saying the SIM800 is the motor here? That's definitely what I'm going on about. When the SIM800 is off, use a volt meter and measure the voltage on the SIM800 GND relative to battery GND.

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

Any reason why a serial connection might interfere with a setWatch for a contact on other ports?

Posted by Avatar for user80197 @user80197

Actions