M
M
MisterSmith2016-10-06 20:13:39
Arduino
MisterSmith, 2016-10-06 20:13:39

How to configure UART on Raspberry pi?

Good afternoon.
Connected Rasberry PI and Arduino via UART via USB cable.
But for some reason it doesn't work the way it should. When sending data from raspberry, it is clear that the data is coming to the arduino (the built-in RX and TX LEDs are blinking), but the arduino program does not process the input data correctly.
On arduino, a simple program (essence):

...
if ((String)buffer_in == "777"){
digitalWrite(7, HIGH); 
    delay(1000);       
    digitalWrite(7, LOW); 
    delay(1000);
}
...

Those. the LED does not light up.
But when you execute the command " minicom -b 9600 -o -D /dev/ttyACM0 " on the raspberry, after that calling the script transmitting data to the arduino 2-3 more times, everything becomes normal. And the data is now transmitted and on the arduino side everything is received and correctly processed.
What can be wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
evgeniy_lm, 2016-10-06
@evgeniy_lm

Your Arduino is trying to receive at a speed of 9600, this is the minimum speed and the UART should work without problems, so they poke it into all the sketches and you drew it. The Raspberry thing is cooler and the default UART settings are cooler. Data transmission is synchronous, i.e. the speeds must match, when you change the speed on the raspberry under the Arduino, then everything becomes normal.
You can try to change UART speed on Arduino under Raspberry

R
Roman Bazalevsky, 2016-10-10
@rvbglas

Set the speed and mode of the port from the RPi side to the same as expected by the arduino, for example, by calling stty with the necessary parameters.

M
MisterSmith, 2016-10-26
@MisterSmith

An interesting moment was discovered
If you call two console windows and write

>>> python
>>> import serial
>>> ser = serial.Serial("/dev/ttyACM0", 9600)

Then when you call in another window a script that sends data to the arduino using the python sendtoarduino.py script, everything works fine
import serial

ser = serial.Serial("/dev/ttyACM0", 9600)
ser.open()
ser.write("777,led,add")
ser.close()

Moreover, it can be seen that stty -F / dev / ttyACM0 issues code1 before the call and after the same port settings.
The whole point is here:
https://yadi.sk/i/LevrXMU3xevo4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question