0

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 decodeenter image description here

  • Did you ssty? – Edgar Bonet Mar 25 at 15:58
  • What is that means? Can you explain? – Santhoshkumar Sundararaj Mar 25 at 16:01
  • In addition to the answers, be sure to "Serial.println(sensorValue, DEC)", to be sure it's printed decimally and not as individual incorrect ASCII characters – Paul Mar 25 at 20:03
  • Have you looked at the data coming back in hex or binary? That might make it easier to see if the source is possibly using a different character set page in Unicode. The graphics symbols are not standard ASCII. I saw a mention of the source being Audi so it's possible the character set is a European one. – Kelly S. French Mar 26 at 13:15
  • This other post looks similiar: (arduino.stackexchange.com/questions/12617/…) and I have to ask if you have any documentation or reference on the sensor. It's just as likely to be sending data in binary, do you have any reason to suspect that it should be ASCII values? – Kelly S. French Mar 27 at 14:51
4

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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.