hello there!
I have a weird serial port issue and I am trying to debug but i need some help:
I have an arduino sending some data to my imp with a sparkful arduino shield on pins 8,9 and on imp 57.
here is the arduino code and the imp code:
void WriteSerialPort(){ // Send all info to the imp Serial.print("SEND TO imp: "); String dataTosend = String(tempnowC) + "," + String(humiditynow) + "," + String(OLED_mode) + delimiter; Serial.println(dataTosend); impSerial.print(dataTosend); delay(100); }
And imp code receiving the serial port stuff:
`
function arduinoData() {
local result = arduino.read();
while(result >= 0) {
if (result == ‘|’) {
server.log("SERIAL PORT RCVD: " + buffer);
updateData(buffer);
buffer = “”;
} else {
buffer = buffer + result.tochar();
}
result = hardware.uart12.read();
}
toggleRxLED();
}
function updateData(dataIn)
{
try {
local sp = split(dataIn, “,”);
// Assign variables
temperatureC = sp[0];
temperatureC = temperatureC.tofloat();
humidity = sp[1];
humidity = humidity.tofloat();
oled_mode = sp[2];
oled_mode = oled_mode.tointeger();
server.log("-> temperatureC: " + temperatureC);
server.log("-> humidity: " + humidity);
server.log("-> oled_mode: " + oled_mode);
}
catch (e){
server.log("Something went wrong: " + e);
}
}
arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData);
`
Most of the time it works fine, but there are many times where i receive twice the result or half the result like this:
`
SERIAL PORT RCVD: ,24.41,4|
2013-12-15 19:48:11 UTC-8: [Device] Something went wrong: the index ‘1’ does not exist
2013-12-15 19:48:11 UTC-8: [Device] SERIAL PORT RCVD: 23.88
2013-12-15 19:48:11 UTC-8: [Device] Something went wrong: the index ‘2’ does not exist
2013-12-15 19:48:16 UTC-8: [Device] SERIAL PORT RCVD: 23.81,25.19,4|
2013-12-15 19:49:26 UTC-8: [Device] SERIAL PORT RCVD: 23.88
2013-12-15 19:49:26 UTC-8: [Device] Something went wrong: the index ‘1’ does not exist
2013-12-15 19:49:26 UTC-8: [Device] SERIAL PORT RCVD: ,25.67,2|
2013-12-15 19:49:26 UTC-8: [Device] Something went wrong: the index ‘2’ does not exist
2013-12-15 19:49:42 UTC-8: [Device] Setting LED to: 1
2013-12-15 19:49:42 UTC-8: [Device] SERIAL PORT RCVD: 23.88,25.35
2013-12-15 19:49:42 UTC-8: [Device] Something went wrong: the index ‘2’ does not exist
`
Any ideas why that might be caused? I have tried different bauds, currently at 9600 but i went up to 19200 and still issues.
Any help will be greatly appreciated! thanks!