I am seeing a very odd behavior with my Xenon -> Raspberry Pi, and I honestly am not sure where the issue is. I am trying to write to the Pi over the USB port. The problem - it will work and then fail. For example, it worked last night and this morning - same code - does not. If you see a Raspberry Pi flying out the window, it may have been mine…
In my Xenon, in setup()
I have the following:
Serial.begin(9600);
Mesh.subscribe("meter-data", writeDataToUSB);
writeDataToUSB
is a simple function to write data to the Serial port.
// -----------------------------------------------------------------------------
void writeDataToUSB(const char *event, const char *data)
// -----------------------------------------------------------------------------
{
Serial.println(data);
String deviceID;
String data_copy = String(data);
deviceID = data_copy.substring(11, data_copy.indexOf('",') - 1);
Mesh.publish("publish-response", deviceID);
}
I test this by connecting the Xenon to my comp and can follow the serial output to see data is coming out. particle serial monitor --follow
However on the Pi side -
- I have opened the Serial interface for data.
- Run
dmesg | grep tty
which returns the port:
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 console=tty1 root=PARTUUID=d9b3f436-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cgroup_enable=memory cgroup_memory=1
[ 0.000301] console [tty1] enabled
[ 0.812585] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 81, base_baud = 0) is a PL011 rev2
[ 0.814150] 3f215040.serial: ttyS0 at MMIO 0x0 (irq = 53, base_baud = 31250000) is a 16550
[ 4.867127] cdc_acm 1-1.5:1.0: ttyACM0: USB ACM device
I then open a Python3 terminal, can see the port is open, but then get empty results.
import serial
port = "ttyACM0"
ser = serial.Serial("/dev/%s" % port, 9600, timeout=0.5)
while True:
line = ser.readline()
print(line)
print(line.decode())
Returns:
b''
b''
b''
Last night I was able to open the same port and get the following:
Any ideas? This one has me totally flabbergasted.