Read/write from peripherals

Learn to read incoming messages and send built messages to all SBC peripherals

Read/write RS232

This example writes “hello” in the RS232#1 peripheral and reads 10 bytes from the RS232#1 peripheral.
You can find more information about the RS232 class here: RS232 - Serial Port.

>>> import sbc
>>> rs232 = sbc.RS232( 115200 )
>>> rs232.write( b"hello" )
>>> print( rs232.read( 10 ) )
1234567890

Read/write XBee socket

This example writes “Hello World!” in the XBEE A peripheral and reads 12 bytes from the XBEE A peripheral.
You can find more information about the Xbee class here: XBEE.

>>> import sbc
>>> pm = sbc.Power_Module()
>>> pm.xbee_on()
>>> xbee = sbc.Xbee( 115200, "XBEE_A" )
>>> sent_bytes = xbee.write( "Hello World!" )
>>> print('Bytes sent: ', sent_bytes)
Bytes sent:  12
>>> print(xbee.read(12))
b'Hello World!'

Read/write GPS/GNSS sentences

This example sends an hexadecimal array to Gps1 and reads everything Gps1 sent.
You can find more information about the Gps class here: GPS – Global Positioning System.

>>> import sbc
>>> gps1 = sbc.Gps( 1, 115200 )
>>> buf_tx = bytes( [ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03 ] )
>>> bytes_sent = gps1.write( buf_tx )
>>> print('Bytes sent: ', bytes_sent)
Bytes sent: 13
>>> print(gps.read())
$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76

Read/write from the microPython terminal

To write a message to the microPython terminal, use the print function.
To enter any information from the terminal, use the input() function.

>>> print( "Hello World!" )
Hello World!
>>> input_msg = input()
This message is written in the terminal as an input
>>> print('Input message is: ',input_msg)
Input message is: This message is written in the terminal as an input