Serial-Communication behaves wierd


#1

Hi

I use a HC-SR04 ultrasonic-sensor with a arduino nano and send a range between 0-25 via Serial to my axoloti.

in my axoloti I have this script/script2-object connected to a disp/i .. and a disp/chart_b

this is my code:

void setup(void) {
} 

   void loop(void) {
    // send a single byte, value from in1
    sdPut(&SD2, 220); 


    // read all pending bytes, value to out1
    while(!sdGetWouldBlock(&SD2)) {
	out1 = sdGet(&SD2)<<21;
}

chThdSleepMilliseconds(3);
}

somehow the recieved values are wierd.. the disp/i only goes from 53-47 and jumps every time up to 53.

why is that? do I hae to terminate the values I am sending somehow?


#2

Have you set the baud rate?


#3

Yes.. the gpio/serial/config-object is set to 9600 and also on my arduino I initialize the same baudrate.


#4

I’m also confused, this code looks like Arduino. How does it run on Axoloti?


#5

it runs in a script/script2-object.

I have solved it :smiley: .. the problem was, I was sending it from the arduino side via Serial.print(); .. I have changed it to Serial.write(); and now everything works fine.


#6

yes, Serial.print on arduino preformats text to be displayed nicely on the serial monitor. for midi and the like always use Serial.write. glad you got it sorted!