Serial buffer delay cased by overflow!?
in
Integration and Hardware
•
2 years ago
Hey,
I am working on an robot and the comunication works kind of well.
Sending data to an Arduino works pretty perfect but getting data is an other thing...
The whole calculation is beeing done by the pc and than send to the robot.
sensor data is beeing send to processing vie serial.
I use the callback method for comunication:
processing says: "S"
arduino sends: "45S" back.
so far so good. The probleme is that the arduino gets much faster the request and sends the information than processing can read it, because it does quite a lot simultaniously.
I used a "delay" every 200ms(not the delay(); funktion) to cut the data a little down but that didn't work that well either.
I used the port.clear(); to clean the buffer. That worked well fot the one sensor but I lost the whole other sensory data....
I can not put the port.write("S"); into the if ( port.available() >= 2) { than the dataflow would possible be just right but it will never be called...
someone an idea for me??
thank you :)
Florian
my Code looks something like that: (I won't post it because it is longer than 750 lines)
I am working on an robot and the comunication works kind of well.
Sending data to an Arduino works pretty perfect but getting data is an other thing...
The whole calculation is beeing done by the pc and than send to the robot.
sensor data is beeing send to processing vie serial.
I use the callback method for comunication:
processing says: "S"
arduino sends: "45S" back.
so far so good. The probleme is that the arduino gets much faster the request and sends the information than processing can read it, because it does quite a lot simultaniously.
I used a "delay" every 200ms(not the delay(); funktion) to cut the data a little down but that didn't work that well either.
I used the port.clear(); to clean the buffer. That worked well fot the one sensor but I lost the whole other sensory data....
I can not put the port.write("S"); into the if ( port.available() >= 2) { than the dataflow would possible be just right but it will never be called...
someone an idea for me??
thank you :)
Florian
my Code looks something like that: (I won't post it because it is longer than 750 lines)
- int IR,Voltage;Ampere;
- void draw(){
- text(sensor data);
- funktion_That_Needs_Sensordata (sensor data);
- Sensors();
- big_Calculation_Stuff();
- }
- void Sensors(){
- port.write("S");
- if ( port.available() >= 2) {
- int ch = port.read();
- if ( ch >= '0' && ch <= '9') {v = v *10 + ch - '0';}
- else{
- switch(ch){
- case 'I': IR = v; break;
- case 'V': Voltage = v/10.0; break;
- case 'A': Ampere = v/10.0; break;
- }
- v = 0;
- //port.clear();
- }
- }
- }
1