Home Forums EasyTransfer Library Support Forum easyTransfer methods receiving data

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3408
    Anonymous
    Inactive

    After searching the forum topics and reading several of them, I did not find my answer.

    I’m having trouble reading the data returned from a buss member.   When data is sent out and then received (by all of the nodes),  I don’t always get what I think I should get.  Using a logic analyzer (saleae) and setting the analyzer to serial etc.   The data is what I expect.    A node (in this case it’s a the main node) requests status from a node with a specific address. The node checks to see if the address matches the local address.   If it matches, the node sends out it’s status to the requesting node.   When the node gets the response from the requested node.  It checks to see if it matches the address that it requested status from.  If it’s correct it turns on the LED, else turns it off.  (this is just for a visual indication of  request, receive, complete loop).  I modified the pot servo examples.  increment the address of the recipient, then send the request.  The receiving node simply sends the received address back to the calling node.

    I would expect that each time the main(requesting node) receives a response, it should match the address that it sent out.   I’m using a mega2560 for the main node; Serial. is for monitor/debug info, and Serial1. is used for serial com on the RS485 buss.  (At one point I completely removed the 485 circuitry and just connected the TX to RX and RX to TX, to verify that it wastn’t RS485 problem…..it wasn’t)  I expected the Serial.println( of the address value) to be …. 0,1,2,3,4,5…..etc.    but what I get is something along the lines of     0,1,2,2,2,5,6,6,6,9,    If you were to change the value that stutters with what it should have been, the 5 and the 9 happen at the correct place.

    My question….. example  code..
    for(int i=0; i<5; i++)
    {
    //remember, you could use an if() here to check for new data, this time it’s not needed.
    ETin.receiveData();
    txdata.address=rxdata.address;
    //set our LED on or off based on what we received from the other Arduino
    digitalWrite(13, rxdata.buttonstate);

    //set our servo position based on what we received from the other Arduino
    //we will also map the ADC value to a servo value
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));

    //delay
    delay(10);
    }

    What does the for loop of  0 <5 actually do?

    Does   ETin.receiveData();  take everything from the hardware uart buffer and transfer it to the associated structure rxdata?   Why the 5 times.   The example said….   //remember, you could use an if() here to check for new data, this time it’s not needed.  As I said, everything is correct on the logic analyzer and I’m using a 500mSec delay at the end of the loop in the main.

    I’ll keep playing with it, but I’m not getting anywhere fast.  PS…Beautiful 2015 Porter Christmas light show on youtube.

     

    #3409
    Anonymous
    Inactive

    I have some working code, but I’m not sure why this works but the other didn’t

    replaced :

    for(int i=0; i<5; i++)
    {
    //remember, you could use an if() here to check for new data, this time it’s not needed.
    ETin.receiveData();
    txdata.address=rxdata.address;
    //set our LED on or off based on what we received from the other Arduino
    digitalWrite(13, rxdata.buttonstate);

    //set our servo position based on what we received from the other Arduino
    //we will also map the ADC value to a servo value
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));

    //delay
    delay(10);
    }

    with:

    while(   ! ET_RECV.receiveData()  )
    {
    //                Serial.println(“waiting for data”);
    //                delay(1);
    ;
    }  //end of while not received

    the print and delay was just to see what was happening. Code works without them …sent address value = received. Now need to add timeout code if node doesn’t respond within a certain time.

    Is there a method available for that already?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.