My arduino is connected to ultrasonic sensor and I am trying to read the value from it. When I tried running "tail -f > /dev/ttyACM0" my arduino is sending some weird characters that I am not able to decode
It would seem you failed to configure the port on the Linux side. By
default, it is configured to who-knows-what baud rate, and to a “cooked”
mode where the data is preprocessed by the kernel driver. You want
instead to set it to the correct baud rate and to “raw” mode. The stty
(meaning, “set terminal”) command does this:
stty -F /dev/ttyACM0 raw 9600
Replace 9600 with whatever baud rate your Arduino is using.
If you Arduino program attempts to read the serial port, it will see the echo of the characters it sends. In that case you probably want to disable this echo also:
stty -F /dev/ttyACM0 raw -echo 9600
-
I have done this with the right baudrate but no change in the output – Santhoshkumar Sundararaj Mar 26 at 10:38
-
@SanthoshkumarSundararaj: There may be something wrong with the sending code. Try to replace it with something trivial, like
void setup(){Serial.begin(9600);} void loop(){Serial.println("Hello!");}
. – Edgar Bonet Mar 26 at 12:29 -
Unfortunately I cant change the code. I am working with AUDI autonomous car. So it has four arduino micro connected with 5 ultrasonic sensors. My task is to establish the connection and get the values from arduino. – Santhoshkumar Sundararaj Mar 26 at 12:42
Most likely this is incorrect baud rate. You can try with a program dedicated to serial ports, my personal choice is picocom but it can by minicom or any other:
$ picocom -b 9600 /dev/ttyACM0
The -b
parameter is used for specifying the baud rate, depending on the sketch it can be something else than 9600, the most common ones are: 9600, 14400, 19200, 28800, 38400, 57600
Another solution is to configure the /dev/ttyACM0
with correct baud rate using stty
:
stty -F /dev/ttyACM0 9600 cs8 -cstopb -parenb
This will configure the serial port to 9600 bps, 8 bits, 1 stop bit, no parity, and allow the tail
command to read it correctly, if the communication parameters match what the arduino is sending
-
I have tried both but still it is giving the same strange characters – Santhoshkumar Sundararaj Mar 26 at 10:03
ssty
? – Edgar Bonet Mar 25 at 15:58