ProfHuster
Active member
I'm going crazy trying to communicate to a Teensy 3.2 from a Raspberry Pi. I want to read from (and in another application, write to) the Teensy. Python code that works fine between a Mac & Teensy or a laptop running Linux Mint and a Teensy, fails on a Raspberry Pi. Yesterday one of my students stumbled after much experimentation a temporary fix
Plug in the Teensy then immediately start the python code!
Why does this "fix" the problem? Even then, successive reads fails.
I have searched for issues like this and nothing in the suggestions stand out.
Here is what I found. I wrote a small Teensy program that prints every second 200 bytes and every few seconds some other information. The code is below. I have tried several ways to read the data one is to `cat /dev/ttyACM0` (yes, that is the right device). The **first time** I run `cat` it grabs some data, at most about 512 bytes, then it won't read anything else from the device. Successive `cat` commands just hang.
If I run a simple python program readTeensy.py (to emphasize **it works on a Linux Mint machine**) and it reads nothing. If I unplug the Teensy while readTeensy.py is running, but get the exception below.
Teensy code:
Output from `cat`. I type ^C after 30+ seconds.
Exception from unplugging while python code running:
Plug in the Teensy then immediately start the python code!
Why does this "fix" the problem? Even then, successive reads fails.
I have searched for issues like this and nothing in the suggestions stand out.
Here is what I found. I wrote a small Teensy program that prints every second 200 bytes and every few seconds some other information. The code is below. I have tried several ways to read the data one is to `cat /dev/ttyACM0` (yes, that is the right device). The **first time** I run `cat` it grabs some data, at most about 512 bytes, then it won't read anything else from the device. Successive `cat` commands just hang.
If I run a simple python program readTeensy.py (to emphasize **it works on a Linux Mint machine**) and it reads nothing. If I unplug the Teensy while readTeensy.py is running, but get the exception below.
Teensy code:
Code:
/* 456789012345678901234567890123456789012345678901234567890123456789012
*
* Dann-PrintSim
* Simulates Muon output
*
* ProfHuster
* 2019-04-07
*
*/
static char pgm[] = "Dann-PrintSim\nPrints every 10 s, coinc every 30s";
void blinkLED();
#define LED_PIN 13
static char bigStr[] = ""
"1234567890123456789012345678901234567890\n"
"1234567890123456789012345678901234567890\n"
"1234567890123456789012345678901234567890\n"
"1234567890123456789012345678901234567890\n"
"1234567890123456789012345678901234567890\n";
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.print("# ");
Serial.println(pgm);
pinMode(LED_PIN, OUTPUT);
for(int i=0; i<10; i++)
{
blinkLED();
}
}
volatile long nLoops = 0;
void loop(){
if(nLoops % 10 == 0){
Serial.print("12, 15, ");
Serial.println(nLoops);
blinkLED();
}
if(nLoops % 30 == 0){
Serial.print(nLoops);
Serial.println(", -1, -1");
}
delay(1000);
nLoops++;
Serial.print(bigStr);
}
void blinkLED()
{
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(200);
}
Output from `cat`. I type ^C after 30+ seconds.
Code:
# Dann-PrintSim
Prints every 10 s, coinc every 30s
12, 15, 0
0, -1, -1
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
1234567890123456789012345678901234567890
^C
Exception from unplugging while python code running:
Code:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 490, in read
'device reports readiness to read but returned no data '
serial.serialutil.SerialException: device reports readiness to read but returned no data
(device disconnected or multiple access on port?)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./readTeensy.py", line 7, in <module>
serial_line = ser.readline().decode('utf-8')
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 497, in read
raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: device reports readiness to read but
returned no data (device disconnected or multiple access on port?)