Unable to read from /dev/serial0 on Raspberry Pi 3

113 views
Skip to first unread message

Diego Braga

unread,
Jul 3, 2017, 5:45:58 PM7/3/17
to Node-RED
Hi everyone,

I hope you'll help me to find out what's wrong with my configuration.

I have to XBee nodes, one connected via usb to my mac and one connected via tx/rx port to the raspberry pi 3.

I wrote two script, one that sends packets (from mac) and one that reads packets (to the pi).

The scripts are the following - on mac:

import serial
from xbee import XBee, ZigBee

serial_port
= serial.Serial('/dev/tty.usbserial-A5025UGJ', 9600)
xbee
= ZigBee(serial_port, escaped=True)

# coordinator = 00 13 A2 00 40 8B B1 5A

while True:
   
try:
       
# Send AT packet
        xbee
.send('tx',frame_id='A', dest_addr_long='\x00\x13\xA2\x00\x40\x8B\xB1\x5A', data='amoremi0i')
        parameter
= xbee.wait_read_frame()
       
print 'parameter='
       
print parameter

   
except KeyboardInterrupt:
       
break

serial_port
.close()




On Pi:

import serial
from xbee import XBee, ZigBee

serial_port
= serial.Serial('/dev/serial0', 9600)
xbee
= ZigBee(serial_port, escaped=True)

while True:
   
try:

       
# Receive AT packet
        parameter
= xbee.wait_read_frame()
       
print 'parameter='
       
print parameter

   
except KeyboardInterrupt:
       
break

serial_port
.close()



The output of the first script is the following (the sender):

parameter=

{'retries': '\x00', 'frame_id': 'A', 'deliver_status': '\x00', 'dest_addr': '\x00\x00', 'discover_status': '\x00', 'id': 'tx_status'}



The output of the second script is the following (the receiver):

parameter=

{'source_addr_long': '\x00\x13\xa2\x00@\x8b\xb1L', 'rf_data': 'amoremi0i', 'source_addr': '\xa3\x19', 'id': 'rx', 'options': '\x01'}



Now if I start Node-Red 0.17.2 and I use the "serial input" module, connected to a debug output module, i cannot see anything incoming. The port is the same (/dev/serial0).



[
   
{
       
"id": "e6aa5379.9fd8c",
       
"type": "debug",
       
"z": "35e84ae.5ae88b6",
       
"name": "",
       
"active": true,
       
"console": "false",
       
"complete": "true",
       
"x": 432.5,
       
"y": 213,
       
"wires": []
   
},
   
{
       
"id": "63563843.bba178",
       
"type": "serial in",
       
"z": "35e84ae.5ae88b6",
       
"name": "",
       
"serial": "fbf0b4fa.9b2918",
       
"x": 209.5,
       
"y": 201,
       
"wires": [
           
[
               
"e6aa5379.9fd8c"
           
]
       
]
   
},
   
{
       
"id": "fbf0b4fa.9b2918",
       
"type": "serial-port",
       
"z": "",
       
"serialport": "/dev/serial0",
       
"serialbaud": "9600",
       
"databits": "8",
       
"parity": "none",
       
"stopbits": "1",
       
"newline": "\\n",
       
"bin": "false",
       
"out": "char",
       
"addchar": false
   
}
]


Is anyone able to tell me what am I doing wrong?


Many thanks in advance,


Diego

Diego Braga

unread,
Jul 3, 2017, 6:03:45 PM7/3/17
to Node-RED
I found out that serial input is unable to split on the \n char because the last char received is in the following decimal format: 178

The hexadecimal value is: 0xb2.

Is there a better way to read Xbee packets?

Dave C-J

unread,
Jul 9, 2017, 12:47:15 PM7/9/17
to Node-RED
Hi

sorry - missed this...

you can set the split character to 0xb2 if you need to.
Reply all
Reply to author
Forward
0 new messages