random success when executing "cat /dev/ttyACM0" or minicom

I wrote a program on Arduino UNO like:

#include <Wire.h>
#include <Adafruit_BMP085.h>

Adafruit_BMP085 bmp;
int HIH_Pin = 2;
float HIH_humid = 0;
float temperature = 0;

void setup() {

void loop() {
    temperature = bmp.readTemperature();
    Serial.print("Temperature = ");
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.println(" Pa");
    HIH_humid = ((5 * analogRead(HIH_Pin) / 1024.0)/5 - 0.16) / 0.0062;
    //temperature compensation
    HIH_humid = HIH_humid / (1.0546 - 0.00216 * temperature);
    Serial.print("RH = ");
    Serial.println(" %");

I do it on my BeagleBoard (Ubuntu 11.04) only setting the speed on minicom. When I try to execute “cat /dev/ttyACM0” or minicom, sometimes it is successful printing the value, sometimes it fails with message like “I/O Error”.

Any hints? Thanks!

I believe that using cat is more or less like opening a serial terminal window... causing the Arduino to reset. You may be more successful with tail -f, but I can't try at the moment.

[edit] no, stupid suggestion.

I can see TX light on Arduino does not blink but lights up. When there is I/O error, it will blink once, then lights up continuously.

In my own experience, TX remains ON when the arduino is trying to transmit but there is no device/program at the other end reading (and emptying) the serial buffer. When you connect to the serial port using cat or minicom you are probably seeing what was put in the serial buffer when the arduino started, but you also cause the Arduino to reset which gives you the I/O error. You may look for a program that can open the serial port without sending the DTR signal. Or maybe it's a configuration option you can set using stty.

In this forum you will also find the hardware 'trick' of using a (removable) capacitor on the Arduino.

To capture data, I use GtkTerm, and let it log to a file.

2 things worth to try;-

  1. stty set communication parameter

spatula: Or maybe it's a configuration option you can set using stty.

stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

u need run it before cat and fine tune it to fit you need.

  1. modify the code
void setup()
  // start serial port at 9600 bps and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

void loop()
  if (Serial.available() > 0) {

one more possibility;-

your sensor is random functionally; to prove this is the case, substitute code to example code to confirm.


  1. stty set communication parameter
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

Thank you for that, it’ll come in handy when I return to my linux box.

Thanks for sonnyyu's solution, adding

  if (Serial.available() > 0) {

really helps!

Just don't let the board output anything before I issue command to it!