Hi everyone, I'm using for a project an old Arduino yun as a ADC, connected to a low power Linux 4.14.78 PC. I send a request about various sensors connected to the Arduino in the form of a single char, and the Arduino answers with the analog read. On Linux, i can see the Arduino as /dev/ttyACM0, as usual. Everything works for 30 minutes, after which the usb connection resets itself, and from the journal i see:
Mar 25 08:06:19 kernel: usb 1-1: USB disconnect, device number 3
Mar 25 08:06:19 kernel: cdc_acm 1-1:1.0: failed to set dtr/rts
Mar 25 08:06:21 kernel: usb 1-1: new full-speed USB device number 4 using ci_hdrc
Mar 25 08:06:21 kernel: cdc_acm 1-1:1.0: ttyACM0: USB ACM device
This breaks my logic on the PC side. Is it a problem on the serial connection of Arduino? i can see others had similar problems too, i can move this thread in the yun subforum in case. The sketch running is this:
void setup() {
Serial.begin(9600, SERIAL_8N1);
while (!Serial) {
; // Wait for serial port to connect
}
}
void loop() {
char cmd = Serial.read();
if (cmd == 'W') { // as in "WIND"
int analog_value = analogRead(A0);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'L') { // as in "LEFT"
int analog_value = analogRead(A1);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'R') { // as in "RIGHT"
int analog_value = analogRead(A2);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'l') { // as in "left"
int analog_value = analogRead(A3);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'r') { // as in "right"
int analog_value = analogRead(A4);
Serial.print(analog_value);
Serial.print('\n');
}
}
In addition to the kernel information @ledsyn asked you about, I would also like to point out that in the loop() it would be more correct and efficient if you executed those instructions only after checking Serial.available():
void loop() {
if (Serial.available()) {
char cmd = Serial.read();
if (cmd == 'W') { // as in "WIND"
int analog_value = analogRead(A0);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'L') { // as in "LEFT"
int analog_value = analogRead(A1);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'R') { // as in "RIGHT"
int analog_value = analogRead(A2);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'l') { // as in "left"
int analog_value = analogRead(A3);
Serial.print(analog_value);
Serial.print('\n');
} else if (cmd == 'r') { // as in "right"
int analog_value = analogRead(A4);
Serial.print(analog_value);
Serial.print('\n');
}
}
}
This is not the culprit, but it's just my 5 cents with a common practice to improve the efficiency of the code (perhaps using the "switch...case" clause instead of a chain of "if...else if...").
I ask because of the above, but you got a more recent kernel I believe. Anyway it seems to be linked to the problem at hand. How long ago did you reboot? There's a lot of hits if you search for failed to set dtr/rts and wanna do some own analysis.
the PC is booted every day, so i don't think that's the isse. Moreover, the fault happens exactly over the same amount of time. Maybe the yun has some kind of watchdog implemented Linino dside?
I have never used a Yun, but I wonder if the problem could be caused by the missing "Serial.available()" call... If you call "Serial.read()" with no bytes in the serial buffer it returns -1 to indicate "no data", but there's a chance it does something wrong when you have thousands of subsequent calls to "Serial.read()" on an empty buffer.
Just to rule out this hypothesis, could you try using the code I posted before and see if the problem persists? After all, it's a test that takes a little more than 30 minutes...
i don't think that's the issue, because i can see the arduino disconnecting even when the system is idle and the application isn't running. this makes me think even more it is a feature of the yun. i'll try anyway and i'll let you know, thanks!
Ok, but what do you mean with "application" on "the system is idle and the application isn't running"? If you mean the Linux side, the problem could be on the Yun side (due to something with a kinda "messed" USB-serial connection). I know nothing about Yun, and I'm not sure it's the culprit, but since the application on Arduino is always running when powered on, it could be at the root of the problem, making your system raise that event you are scared about.
Another cause could be a bad device driver (e.g. are you sure it doesn't need to be updated?), or even the USB cable (have you tried another one?) or that USB port (tried another one too?).
From the serial connection on usb, i can see the Arduino yun is resetting every 30 minutes. what can be the cause? Pheraps something in the Linino part? Related to this question. Thanks!
If it works like the UNO, a reset is automatically executed each time the serial has been opened (e.g. like connecting the USB cable), so you should try to figure out what is the cause and what is the effect.
I mean, either the PC reports that event because the Yun has rebooted, or the Yun resets because the serial connection is kinda unstable (or because the PC for some reason closes it, or for some other reason).
But in either case, if this happens regularly every 30 minutes or so (have you checked on the system log if it happens at a fixed and stable rate?), it's something to do with Yun or the PC in timed manner. If the Yun firmware hasn't changed, the only side where IMO you could investigate is the Linux one. Maybe a system update, or, as I said before, is it necessary to update the USB-serial device driver?
Thanks for your suggestions. i found the problem however, and it was way simpler than i imagined: the Arduinos we are using are recycled from an old project of my company, and in the Linino part of the device there was an init script that was resetting the serial every 30 minutes. no idea why, but i'm happy i found it! thanks anyway for your kind support!