Description

⚙ Hardware Needed


📚 External Libraries Needed


None

📑 Code


Using only built-in libraries:

import board
import busio
import time
import digitalio

uart = busio.UART(board.TX, board.RX, baudrate=9600)

while True:
		if uart.in_waiting: # check if there's anything in uart buffer
			data = uart.read(32) # read at most 32 bytes

			# data is a bytearray, we'll want to convert it to a string
			data_string = ''.join([chr(b) for b in data])
			print(data_string)
		time.sleep(0.1)

Using the pycubed.py helper library:

from pycubed import cubesat
import time

while True:
		if cubesat.uart.in_waiting: # check if there's anything in uart buffer
			data = cubesat.uart.read(32) # read at most 32 bytes

			# data is a bytearray, we'll want to convert it to a string
			data_string = ''.join([chr(b) for b in data])
			print(data_string)
		time.sleep(0.1)

Details


📖CircuitPython UART documentation

↩ Return Home

↩ Return to Resources

↩ Return to Code Examples