seg9585
23-02-2015, 19:26
All,
I have been trying to configure our RioDuino (plugged into the MXP port on the roboRio) for serial transfer, but the Java Serial class seems to be giving me quite a few problems.
On the arduino side, for purposes of troubleshooting I simplified the code to just listen for an ASCII character, store in a variable, then echo that character back to the serial port to be heard on the roboRio. This uses the Serial.read(); and Serial.write(); functions
I verified this works without issue when I transmit this character through the Arduino serial monitor
On the roboRio side, I use the SerialPort.writeString(myString); command to transmit that value, and the SerialPort.readString(1); command to listen to just 1 byte. I then print this value to the SmartDashboard
However I'm having problems on both sides of the transaction. On the roboRio readString(1); side, there appears to be buffering issues -- the data isn't getting cleared from the buffer so the resulting character is very delayed. I am aware there's a known bug and a patch out there which I haven't tried yet, so not too worried about that, but...
On the writeString(), I am getting very strange results read by the Arduino. For example, if I repeatedly send SerialPort.writeString("1"), I don't get the number 49 (ASCII 1) or "1" echoed in the Arduino Serial Monitor, but I get numbers like 204, 17, or some other random numbers. Sending multiple times produces different numbers every time, although some tend to repeat.
I'm not sure what to make of this. Is the Serial port malfunctioning, or maybe there's a bug in the WPI code? Do I need to "interpret" the incoming values a different way?
I realize I can use I2C for communication. I'm already using I2C for a different sensor so I can make use of it for this as well, but I would really like to figure out why I'm having so many problems with Serial.
FYI, yes I verified both roboRio and Arduino are using the same bitrate (9600)
I have been trying to configure our RioDuino (plugged into the MXP port on the roboRio) for serial transfer, but the Java Serial class seems to be giving me quite a few problems.
On the arduino side, for purposes of troubleshooting I simplified the code to just listen for an ASCII character, store in a variable, then echo that character back to the serial port to be heard on the roboRio. This uses the Serial.read(); and Serial.write(); functions
I verified this works without issue when I transmit this character through the Arduino serial monitor
On the roboRio side, I use the SerialPort.writeString(myString); command to transmit that value, and the SerialPort.readString(1); command to listen to just 1 byte. I then print this value to the SmartDashboard
However I'm having problems on both sides of the transaction. On the roboRio readString(1); side, there appears to be buffering issues -- the data isn't getting cleared from the buffer so the resulting character is very delayed. I am aware there's a known bug and a patch out there which I haven't tried yet, so not too worried about that, but...
On the writeString(), I am getting very strange results read by the Arduino. For example, if I repeatedly send SerialPort.writeString("1"), I don't get the number 49 (ASCII 1) or "1" echoed in the Arduino Serial Monitor, but I get numbers like 204, 17, or some other random numbers. Sending multiple times produces different numbers every time, although some tend to repeat.
I'm not sure what to make of this. Is the Serial port malfunctioning, or maybe there's a bug in the WPI code? Do I need to "interpret" the incoming values a different way?
I realize I can use I2C for communication. I'm already using I2C for a different sensor so I can make use of it for this as well, but I would really like to figure out why I'm having so many problems with Serial.
FYI, yes I verified both roboRio and Arduino are using the same bitrate (9600)