Warning
This page is located in archive.

Lab 03

Exercise Objectives

  • Introduce UART communication
  • Program to duplex communication with RPi Pico

UART Communication

The goal of this subtask is to send information about the speed at which the LED on the Raspberry Pi Pico board should light up via the UART interface. However, we can first try out the communication itself, such as sending characters from the microcontroller and receiving them on the PC side.

Application on Raspberry Pi

The machine.UART class is intended for creating a physical UART interface using a pair of RX/TX pins. If we wanted to use it, we would need a similar device on the other side, such as another Pico. If we want to communicate with a PC this way, a UART-USB converter is needed, for example with an FTDI chip (e.g., this).

However, we can take advantage of the fact that the USB interface on the Raspberry Pi operates as a serial interface with a speed of 115200 bps. Therefore, data from the Pico board can be sent to the PC recipient, for example, using the print() function.

from machine import Pin, Timer
import sys
 
led = Pin('LED', Pin.OUT)
 
while True:
  # x = input()
  x = sys.stdin.read(1)
  if x == 'a':
    led.toggle()
  print("UART: {}".format(x))

Application on PC

On the PC, we can use any of serial monitors, for example Putty. Find your COM port and configure serial connection.

courses/be2m37mam/labs/03.txt · Last modified: 2023/11/08 12:16 by viteks