Pages: [1]   Go Down
Author Topic: random success when executing "cat /dev/ttyACM0" or minicom  (Read 1471 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote a program on Arduino UNO like:

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

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

void setup() {
  Serial.begin(9600);
  bmp.begin();
}

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

    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    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.print(HIH_humid);
    Serial.println(" %");
  
    Serial.println();
    delay(2000);
}

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!
« Last Edit: March 03, 2013, 10:51:34 pm by cmkpl » Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 03, 2013, 10:55:57 pm by spatula » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 57
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Earth
Offline Offline
Edison Member
*
Karma: 41
Posts: 1388
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

2 things worth to try;-

1. stty set communication parameter

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

Code:
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.

2. modify the code

Code:
void setup()
{
  // start serial port at 9600 bps and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
//...
}

void loop()
{
  if (Serial.available() > 0) {
//...
« Last Edit: March 05, 2013, 08:37:45 pm by sonnyyu » Logged

Earth
Offline Offline
Edison Member
*
Karma: 41
Posts: 1388
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

one more possibility;-

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

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. stty set communication parameter
Code:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for sonnyyu's solution, adding
Code:
  if (Serial.available() > 0) {
     Serial.read();
really helps!

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

Pages: [1]   Go Up
Jump to: