Go Down

Topic: random success when executing "cat /dev/ttyACM0" or minicom (Read 1 time) previous topic - next topic

cmkpl

Mar 04, 2013, 04:40 am Last Edit: Mar 04, 2013, 04:51 am by cmkpl Reason: 1
I wrote a program on Arduino UNO like:

Code: [Select]
#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!

spatula

#1
Mar 04, 2013, 04:53 am Last Edit: Mar 04, 2013, 04:55 am by spatula Reason: 1
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.

cmkpl

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.

spatula

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.

Erdin

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

sonnyyu

#5
Mar 06, 2013, 02:34 am Last Edit: Mar 06, 2013, 02:37 am by sonnyyu Reason: 1
2 things worth to try;-

1. stty set communication parameter


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


Code: [Select]
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: [Select]
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) {
//...


sonnyyu

one more possibility;-

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

spatula


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

cmkpl

Thanks for sonnyyu's solution, adding
Code: [Select]
  if (Serial.available() > 0) {
     Serial.read();

really helps!

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

Go Up