Hello all,
The arduino is collecting data remotely and transmitting back to the computer.
The payload is around 100 bytes, so I increased the send buffer to 128 so the print would not block.
all baud rates are 9600
right now the send is timed to once a second, and it works fine.
As I reduce the time between sends, it starts to choke and data to the computer becomes erratic. dropped characters etc etc. Even when the arduino is switched off, the receive side still outputs data for a few seconds. This would indicate it must be buffered somewhere between the receiving xbee and windows application correct?
I am using a cheap amazon xbee usb adaptor on the computer side, which I presume has its own buffer before it sends over USB? (not accurate statement)
I have tried messing with the settings in windows device manager with no change.
Here is some code stripped down. If you imagine other methods are updating these variables in background, the attached is simulating the sending over serial to the xbee link.
Adafruit_GPS GPS(&Serial2);
uint32_t message_timer = millis();
struct Point q2 = {0, 0};
int lap = 0;
String lap_string;
String lap_change_string;
float ax_conv, ay_conv;
float GPS_speed = 0;
int obd_rpm;
int obd_coolant_temp;
float obd_battery;
void setup() {
// put your setup code here, to run once:
Serial3.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (millis() - message_timer > 1000) {
Send_message();
message_timer = millis();
}
}
void Send_message()
{
Serial3.print("A"); Serial3.print(",");
Serial3.print(GPS.fix); Serial3.print(",");
Serial3.print(q2.x, 8); Serial3.print(",");
Serial3.print(q2.y, 8); Serial3.print(",");
Serial3.print(lap); Serial3.print(",");
Serial3.print(ax_conv); Serial3.print(",");
Serial3.print(ay_conv); Serial3.print(",");
Serial3.print(lap_string); Serial3.print(",");
Serial3.print(lap_change_string); Serial3.print(",");
Serial3.print(GPS_speed, 0); Serial3.print(",");
Serial3.print(obd_rpm); Serial3.print(",");
Serial3.print(obd_coolant_temp); Serial3.print(",");
Serial3.print(obd_battery); Serial3.print(",");
Serial3.print("Z");
}
resulting serial data at the computer
1 second delay between transmissions - normal
timestamp payload
05.54.40.165 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.54.41.169 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.54.42.174 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.54.43.178 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
300 msec between transmissions
timestamp payload
05.59.19.754 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.20.726 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.20.796 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.20.888 A,0,0.00000000,0.0000A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.21.958 ERROR0
05.59.22.029 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.22.159 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.23.098 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.23.166 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.23.296 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.24.366 ERROR0
05.59.24.541 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.24.670 A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,A,0,0.00000000,0.00000000,0,0,0,----------,----------,0,0,0,0.00,Z
05.59.25.741 ERROR0
note: i have no idea where the ERROR0 is coming from it is not my code...
I would like to change the timing to be as frequent as possible, using Serial.availableForWrite() or similar and only pushing into the Tx buffer when there is room and it won't block. but I am stumbling here.
Please let me know anything that comes to mind.
in the meantime, i will try using an uno as the usb adaptor instead of the amazon xbee adaptor