Can't control actuator



  • Hi Every body!
    I have a new problem.... Sorry :-()

    I have my arduino nano as serial gateway.
    I already have a mini as light actuator (without relay but with a led to see if it works)

    My code for the mini :

    #include <Relay.h>
    #include <SPI.h>
    #include <EEPROM.h>
    #include <RF24.h>

    #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1
    #define RELAY_ON 0
    #define RELAY_OFF 1

    Sensor gw;

    void setup()
    {
    gw.begin(42);

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Relay", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    for (int i=0; i<NUMBER_OF_RELAYS;i++) {
    gw.sendSensorPresentation(1, S_LIGHT);
    }
    // Fetch relay status
    for (int i=0; i<NUMBER_OF_RELAYS;i++) {
    // Make sure relays are off when starting up
    digitalWrite(RELAY_1+i, RELAY_OFF);
    // Then set relay pins in output mode
    pinMode(RELAY_1+i, OUTPUT);

    // Request/wait for relay status
    gw.getStatus(RELAY_1+i, V_LIGHT);
    setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
    

    }

    }

    /*

    • Example on how to asynchronously check for new messages from gw
      */
      void loop()
      {
      if (gw.messageAvailable()) {
      message_s message = gw.getMessage();
      setRelayStatus(message);
      }
      }

    void setRelayStatus(message_s message) {
    if (message.header.messageType==M_SET_VARIABLE &&
    message.header.type==V_LIGHT) {
    int incomingRelayStatus = atoi(message.data);
    // Change relay state
    digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
    // Write some debug info
    Serial.print("Incoming change for relay on pin:");
    Serial.print(message.header.childId);
    Serial.print(", New status: ");
    Serial.println(incomingRelayStatus);
    }
    }

    When i open the serial monitor in arduino (with the port of my nano of course) and i type :
    42;3;1;2;0 or 42;3;1;2;1 nothing happens
    Is it possible to command led at distance with the gateway?
    I do a mistake?

    In the serial monitor, i have :
    0;0;4;11;Arduino startup complete.
    42;3;2;2;
    42;3;2;2;

    42;3;2;2; is a presentation messsage isn't it?
    Why does it present every 5 seconds? can i change this time?
    Thank you for your help


  • Admin

    @nono056 said:

    42;3;2;2; is a presentation messsage isn't it?

    No, your actuator requests relay status from controller at startup.

    node(42); child id(3) , request status (2), V_LIGHT (2)

    If you don't have any controller, remove the following lines:

    gw.getStatus(RELAY_1+i, V_LIGHT);
    setRelayStatus(gw.getMessage());


  • OK thanks for this precision!
    How i ca control it?
    Can i send 42;3;1;2;0 or 42;3;1;2;1 via arduino IDE serial monitor?
    It doesn't work for me...


  • Admin

    @nono056

    No,

    You have to send commands over the air to you actuator.

    Build and use the serial gateway for issuing commands like that.



  • @hek
    I have tested via the serial gateway and nothing happened.
    Can I do that via serial monitor of arduino connected on Serial Gateway?


  • Admin

    @nono056 said:

    Can I do that via serial monitor of arduino connected on Serial Gateway?

    yes. you can control it with a serial gateway connected to your computer.

    Is your radio communication really working? Did you enable debug prints?



  • @nono056 said:

    OK for the serial Gateway.
    My radios communicate really. I test it with a ds18b20 and i have my temperature (thanks for yesterday!!!)
    I've just activate the debug and it says :
    0;0;4;11;Arduino startup complete.
    0;0;4;11;Message available on pipe 1
    0;0;4;11;Sent ack msg to 42
    0;0;4;11;Rx: fr=42,to=0,la=42,ci=255,mt=0,t=17,cr=166(ok): 1.3b3 (18
    0;0;4;11;Message addressed for this node.
    42;255;0;17;1.3b3 (18848a2)
    0;0;4;11;Message available on pipe 1
    0;0;4;11;Sent ack msg to 42
    0;0;4;11;Rx: fr=42,to=0,la=42,ci=255,mt=4,t=7,cr=234(ok): 0
    42;255;4;7;0
    0;0;4;11;Message available on pipe 1
    0;0;4;11;Sent ack msg to 42
    0;0;4;11;Rx: fr=42,to=0,la=42,ci=255,mt=4,t=14,cr=83(ok): Relay
    42;255;4;14;Relay
    0;0;4;11;Message available on pipe 1
    0;0;4;11;Sent ack msg to 42
    0;0;4;11;Rx: fr=42,to=0,la=42,ci=255,mt=4,t=15,cr=97(ok): 1.0
    42;255;4;15;1.0
    0;0;4;11;Message available on pipe 1
    0;0;4;11;Sent ack msg to 42
    0;0;4;11;Rx: fr=42,to=0,la=42,ci=1,mt=0,t=3,cr=37(ok): 1.3b3 (18848a
    0;0;4;11;Message addressed for this node.
    42;1;0;3;1.3b3 (18848a2)

    I don't see anything when i send this : 42;3;1;2;0
    I think my numbers are good
    I don't understand why it doesn't work 😞



  • I've tested with an another computer near the first (1 meter)
    the only things i see in this serial monitor (the relay or led node) i have this :

    Started sensor.
    Relay=0, distance=1
    Relaying message back to gateway.
    Tx: fr=42,to=0,la=42,ne=0,ci=255,mt=0,ty=17,cr=166: 1.3b3 (18848a2)
    Ack: received OK
    Relaying message back to gateway.
    Tx: fr=42,to=0,la=42,ne=0,ci=255,mt=4,ty=7,cr=234: 0
    Ack: received OK
    Relaying message back to gateway.
    Tx: fr=42,to=0,la=42,ne=0,ci=255,mt=4,ty=14,cr=83: Relay
    Ack: received OK
    Relaying message back to gateway.
    Tx: fr=42,to=0,la=42,ne=0,ci=255,mt=4,ty=15,cr=97: 1.0
    Ack: received OK
    Relaying message back to gateway.
    Tx: fr=42,to=0,la=42,ne=0,ci=1,mt=0,ty=3,cr=37: 1.3b3 (18848a2)
    Ack: received OK

    nothing when the gateway send this : 42;3;1;2;0
    I have inverted the two nrf24l01 and it is the same
    Any idea?



  • Hello!
    I have inverted the 2 arduinos, now nano is the relay actuator node and the mini is the serial gateway.
    Nothing happens else...
    Someone can help me?
    thanks


  • Admin

    Looks like your communication is working (in one direction at least).
    What is your setting in serial console (Newline?) when you send commands?
    Is the gateway really sending anything? After entering your command in the serial console you should see a Tx: .......



  • @nono056 said:
    I use arduino ide for serial communication.
    I write 42;3;1;2;0 in the serial send line and clic on Send.
    Nothiing appears.
    For debugging, i had Serial.println(inputString); at the end of serialEvent funtion for testing what i was sending
    and i have this appearing :
    0;0;4;11;Arduino startup complete.
    4
    42
    42;3
    42;3;
    42;3;1;
    42;3;1;2;
    42;3;1;2;0

    No tx line...



  • @nono056 said:

    42;3;1;2;0

    I have found where is the error!
    In the SerialGateway sketch, if we use the serial monitor with arduino IDE (with my PC), there isn't a "\n" char who is send.
    i have to change this in the sketch with z.
    now it function!!

    so the new serialEvent function is :

    void serialEvent() {
    while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) {
    if (inChar == 'z') {
    inputString[inputPos] = 0;
    commandComplete = true;
    } else {
    // add it to the inputString:
    inputString[inputPos] = inChar;
    inputPos++;
    }

    } else {
       // Incoming message too long. Throw away 
        inputPos = 0;
    }
    

    }
    }

    and to activate my led (or relay), i use this line : 42;3;1;2;0z in the serial monitor on arduino

    Is it my PC, the Arduino serial monitor or the script which isn't atapted with this tools?
    i don't know...

    Et voila for the solution (for my problem in fact)
    thanks for all!


  • Admin

    That is why I asked the following:

    What is your setting in serial console (Newline?) when you send commands?



  • @hek
    I haven't understand this question, we can't change this in arduino?


  • Admin



  • ARF!!!!!!!
    3 years i use Arduino and i have never pay attention to this line... 😞
    Thanks!


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 1
  • 5
  • 2
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts