Reputation: 33
I have application uses serial port to send data from odroid xu4 to Arduino pro mini, the data is packages of 10 bytes i use "Serial_Port.write(struct.pack('cBBBBBBBBB', "R", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], cmd[8]))
" and the odroid send two packages every 20 millisecond (50Hz), on the arduino this is the code:
ARDUINO CODE:
#include <Wire.h>
char CMD[] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
char hand;
void setup() {
Serial.begin(115200);
Serial.setTimeout(10);
Serial.println("Arduinno serial to I2C converter 115200");
}
void loop() {
if (Serial.available() == 10) {
Serial.readBytes(CMD, 10);
Serial.println(CMD);
}
}
i use two XBee PRO S2C to transmit the data from XU4 to the Arduino, i connect the XBee with XU4 using Tx Rx pins, port: '/dev/ttySAC0'.
when i run the programs the Arduino receives only the first two or three frames of data then it stops working until i press the reset button. can any one help me with this problem, it take me a lot of time searching for solution but no good results. also i tried to replace the Arduino with raspberry Pi B+ but same problem.
Upvotes: 1
Views: 435
Reputation: 43495
Not an arduino spcialist, but I would suggest changing
if (Serial.available() == 10) {
to
if (Serial.available() >= 10) {
The current code relies on there being exactly one message available. If the Python code manages to send two messages in the time between subsequent reads, the current code will fail.
Upvotes: 1