Xbee class manages the XBEE sockets as if they were serial ports.
Xbee(uart_baudrate, identifier, uart_rxbuf=4096)¶
The class needs to be initialized with the following parameters:
9600, 19200, 38400, 57600,
115200, 230400, 460800,
GNSS receiver UART1 baudrate
XBEE_A or XBEE_B
XBEE socket (A or B) at which
you want to connect
any, default value is 4096
RX buffer size
Read data from Xbee
size: number of bytes to receive. Use read() to read all available data.
Example to read data:
>>> import sbc >>> xbee = sbc.Xbee( 115200, "XBEE_A" ) >>> print(xbee.read(12)) b'Hello World!'
The ouput messages from the XBEE socket are being stored in the
The default buffer size (4096 bytes) should be enough to read continuously, but be aware that if you don’t read the buffer during a long time, the buffer will be completed and the new messages from the XBEE socket will be lost, and by the time you read the buffer you will read “old” messages.
If you want to discard old messages, you can empty the buffer with
Write data to the Xbee
data: data to send
Number of bytes written
Example to write data:
>>> import sbc >>> xbee = sbc.Xbee( 115200, "XBEE_A" ) >>> sent_bytes = xbee.write( "Hello World!" ) >>> print('Bytes sent: ', sent_bytes) Bytes sent: 12
Initializes XBEE UART port
Fordwards XBEE data to a peripheral with UART
uart_fwd: peripheral object (Gps, Xbee, RS232)
- Example to forward information received on the XBEE A socket to GPS1 UART1:
>>> import sbc >>> pm = sbc.Power_Module() >>> pm.xbee_on() >>> xbee = sbc.Xbee( 115200, "XBEE_A" ) >>> gps1 = sbc.Gps( 1, 115200 ) >>> xbee.forward_to(gps1)
Disables XBEE forwarding
Get XBEE UART port.
get_uart_id() method of the
Xbee class returns a microPython UART object, it has all its methods.
To do not duplicate the documentation, we suggest to take a look at the official microPython project documentation to see what methods you can additionaly use.
- Example of additional methods:
>>> import sbc >>> xbeeA = sbc.Xbee( 115200, "XBEE_A" ) >>> print('There are: ',xbeeA.any(),' characters to be read') There are: 1580 characters to be read >>> print(xbeeA.get_uart_id().readline()) b'$GNGGA,142222.00,4136.52091,N,00036.70322,E,2,10,1.27,203.6,M,49.8,M,,0000*4D\r\n'