Set output pin High before message initialising



  • Is there a way to set an output pin high before sending the init message to the gateway?
    so before
    // Initialize messages
    MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP);
    MyMessage sleepMsg(CHILD_ID_SLEEP, V_TEXT);

    I want to save energy (300µA) so I want to power the MAX485 only when sending messages.
    This is manageable in the sketch (set output pin high after returning from sleep mode, low before sleep) but at first start it isn't. I walked through the libraries but I didn't find the code where the DE pin is managed in order to send data to the MAX chip whch will send the data to the gateway. If I could find this I can make a similar set-up. Thanks in advance.



  • Not sure, if I got your ideas right. Imo, (de-) powering the AMX485 may just be fine within the loop(). Some remarks wrt this (afaik):

    • the MyMessage-definitions are just definitions to prepare sending command structures, but there's no direct send command issued. So there's no need to (de-)power any transceiver at this point in time
    • the DE-PIN is not related to powering the transceiver - it just indicates the direction of communication (high, when receiving, low while sending, maybe pulled to low from transceiver side when receiving starts (RE) to trigger an interrupt at PIN2)
    • when switching transceiver on manually in loop(), you may need a short wait() to make sure, transceiver is correctly initialised (didn't test anything like that bevore).


  • hello rejoe2, you have to power the MAX chip before you come into the loop() because the first time you have to send the node configuration to the gw.
    Putting the

    pinMode(SENSOR_POWER_PIN, OUTPUT);
    digitalWrite(SENSOR_POWER_PIN, HIGH);

    code in the setup() is also too late.
    If the MAX isn't powered before, you get error messages because the node can't connect to the gw.

    btw the DE-PIN is not related to powering the transceiver --> right, it's a similar management, it was an example to find a solution


  • Mod

    @arduisens I am not at all familiar with RS485, but maybe the before() function or preHwInit() is what you're looking for?

    See also https://github.com/mysensors/MySensors/issues/927 for an attempt to clarify which order the different functions are called.



  • @mfalkvidd
    OK, the before() works!

    0 MCO:BGN:INIT NODE,CP=RSNNA--,VER=2.1.1
    3 MCO:BGN:BFR
    running before() function
    2006 TSM:INIT
    2011 TSF:WUR:MS=0
    2012 TSM:INIT:TSP OK
    2014 TSM:INIT:STATID=25
    2016 TSF:SID:OK,ID=25
    2018 TSM:FPAR
    2036 TSF:MSG:SEND,25-25-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2850 TSF:MSG:READ,0-0-25,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    2855 TSF:MSG:FPAR OK,ID=0,D=1
    4043 TSM:FPAR:OK

    thanks for the cooperation mfalkvidd & rejoe2


 

449
Online

8.0k
Users

8.8k
Topics

94.4k
Posts