c++ - Openframeworks, reading serial data from Arduino -


i'm trying read serial data arduino uno using ofserialobject , assign int. able read in individual bytes, however, values i'm receiving in openframeworks console not same values i'm reading in arduino serial monitor.

i have provided screenshots of respective consoles:

arduino serial monitor

openframeworks console

my arduino code basic "analogreadserial" example available arduino ide.

// setup routine runs once when press reset: void setup() {     // initialize serial communication @ 9600 bits per second:     serial.begin(9600); }  // loop routine runs on , on again forever: void loop() {     // read input on analog pin 0:     int sensorvalue = analogread(a0);     // print out value read:     serial.println(sensorvalue);     delay(1);        // delay in between reads stability } 

whereas c++ code copied documentation ofserial readbyte function.

void serialreader::setup() {     serial.listdevices();     vector <ofserialdeviceinfo> devicelist = serial.getdevicelist();      serial.setup("com4", 9600); //open first device , talk @ 9600 baud }   void serialreader::printbytetoconsole() {     int mybyte = 0;     mybyte = serial.readbyte();     if ( mybyte == of_serial_no_data )         printf("\nno data read");     else if ( mybyte == of_serial_error )         printf("\nan error occurred");     else         printf("\nmybyte %d ", mybyte); } 

any insight may causing disparity between readings appreciated. thank you.

arduino's serial.println translates raw bytes ascii equivalent , sends bytes followed linefeed (10) , carriage return (13) bytes. so, raw byte 12 sent 4 total bytes -- 2 bytes representing ascii 1 (49), 2 (50) , (10) , (13) new line characters. so, since openframeworks not automatically translate ascii values raw bytes, seeing ascii version. arduino console shows ascii version readable text.

you can see translation between ascii , raw bytes (decimal / aka dec) here:

http://www.asciitable.com/

if want 2 numbers match on both sides, consider using serial.write in arduino write raw bytes without ascii translation , new line characters.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -