costelljoe
New member
I am using usb serial to send data from a Teensy 3.2 to a Ubuntu computer. The teensy reads in data from an SD file, then repeatedly sends over serial. The receiving computer uses PySerial to read in the data (code below).
However, PySerial often times-out and doesn't read in any data, or reads in some then throws the error "serial.serialutil.SerialException: device reports readiness to read but returned no data".
The arduino serial monitor reads in the data consistently.
Is there any way to make the connection more consistent? The end goal is to eventually stream recorded audio over serial.
Thanks!
Teensy Code
Python Code
However, PySerial often times-out and doesn't read in any data, or reads in some then throws the error "serial.serialutil.SerialException: device reports readiness to read but returned no data".
The arduino serial monitor reads in the data consistently.
Is there any way to make the connection more consistent? The end goal is to eventually stream recorded audio over serial.
Thanks!
Teensy Code
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
File audiofile;
const int chipSelect = 10;
const int N = 512;
byte buffer1[N];
bool fileLoaded = false;
void setup() {
Serial.begin(115200);
// Initialize SD card
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(chipSelect))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
// Make sure file exists
if (!SD.exists("record.txt")) {
while (1) {
Serial.println("No audio data saved on teensy");
delay(500);
}
}
// load file
audiofile = SD.open("record.txt", FILE_READ);
audiofile.read(buffer1, N);
fileLoaded = true;
}
void loop() {
if (fileLoaded) {
Serial.write(buffer1, N);
delay(1);
}
}
Python Code
Code:
import serial
# setup serial connection
ser = serial.Serial('/dev/tty.ACM0', 115200, timeout=1)
ser.reset_input_buffer()
print("serial connected")
N = 512
while True:
if ser.in_waiting > N:
# print available data
response = ser.read(N)
print(response)
ser.close()