Simple arduino serial -> openframework missing bytes


#1

Hi,

I am a beginner but not too much to find this very weird. I send a series of bytes (0 to 24) from the arduino, openframework (debian raspberry) do not receive the 17 and 19 values! I tried on two raspberry pi, and two arduinos, same result. wtf?

Here is the code. On my mac it’s work fine.

Thanks.

ARDUIO:
void setup() {
Serial.begin(9600);
}

void loop() {
for (int x = 0 ; x < 25 ; x++) {
Serial.write(x);
delay(20);
}
delay(2000);
}

OPENFRAMEWORK:

include “ofApp.h”

void ofApp::setup(){

serial.listDevices();
vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList();
int baud = 9600;
serial.setup(0, baud);

}

void ofApp::update(){

while(serial.available()) {
printf( “%d \n”, serial.readByte());
}
}

And I got:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
18 <-- wtf ?
20
21
22
23
24

Summary

This text will be hidden


#2

Out of curiosity, what happens if you change the while to an if, and perhaps increase the delay from 20 to 100 just to see if it’s some kind of latency issue?


#3

I was having some trouble with something like this recently - I solved it by by making the communication synchronous, i.e., sending a byte from the oF app with serial.writeByte(byte) and letting the Arduino only respond when it receives the byte. I think this has to do with some latency issue somewhere.

Arduino code:

//read values from the computer
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 1) {
      Serial.println(value);
    }

I eventually moved the computers code to a python app and ditched oF for this because there was no drawing happening and I needed to take advantage of a few Python modules so unfortunately I don’t have anything to share from that side.

Edit: In the above example, value is being updated all the time (it’s reading a analog input) but only sending it over when the computer requests it.


#4

Hi thank you for your reply. By changing while to if the terminal printing is more fluid. I changed to 100mSec the same problem.


#5

Ok! by changing the baudrate to 115200 it solved the problem, but the problem at 9600 remains strange. Thank you for your answers.


#6

No is doesn’t. Its worked for a while after using python for reading datas. After using python, Open frame work works for a while and stop again (no 17 no 19) for I don’t know which reason!

Python code
import serial
ser - serial.Serial(’/dev/ttyACM0’,115200)
while true:
data =ser.read(1)
print (ord(data))


#7

Thank you, but I cannot do that for my application, it’s 33 bytes transmitting via xbee, time critical.