Developing in C for the ATmega328P: Raspberry Pi and VS Code Setup Part 3

2 minute read

Where I demonstrate how to use additional tools such as the serial monitor, tio, along with VS Code on your PC to develop code on your Raspberry Pi for the Arduino Uno (ATmega328P).

Introduction

Even though VS Code has a serial monitor, in fact, in has many serial monitor extensions, I’ve found tio to be the best. The VS Code version has failed to connect too many times, while tio has been rock solid. It also has a nice configuration method and is easy to connect/disconnect.

In this entry, I’ll also additional CLI commands which will become required to work well with the Raspberry Pi and Uno.

Know

Good to Know

Serial Communication

Communicating with the Uno via LED, can be a bit laborious. I will use the built-in LED to indicate when I’ve had success (or failure), however, a more effective medium is the serial port.

The serial port is the USB port, however, instead of using it to upload programs, I use it for a bi-directional text communications. As this is the same port used to upload programs, so its important to disconnect it from the serial program while attempting to upload code.

Serial Monitor

I’ve had the best results in a CLI serial communication monitor using tio. I attempted to use the Microsoft Serial Monitor Extension and had some many problems, I don’t install it.

Another nice feature of tio, is the ability to setup a configuration file so its easy to invoke a specific port and baud rate with a single word. In my case, my configuration file looks like this:

[default]
baudrate = 250000
databits = 8
parity = none
stopbits = 1
local-echo = true
color = 11

[acm]
device = /dev/ttyACM0
color = 12

[usb]
device = /dev/ttyUSB0
color = 15

[usb-devices]
pattern = ^usb([0-9]*)
device = /dev/ttyUSB%m1
color = 14

Given this configuration file, stored at the root level of my home folder, I start tio with a tio acm and immediately connect to the Uno at /dev/ttyACM0 with a baud rate of 250000.

Serial Example

In VS Code Explorer, go to examples/serialio_readline, open main.c and compile/upload it to your Uno.

In your CLI, do the following:

# make sure you are in your home folder
cd
# using the tab key, quickly go to the same example as above
cd AVR_C/examples/serialio_readline
# start your serial monitor, with the Uno device name
tio acm
# interact with the serial port
# use Ctrl-t q to quit tio

When you have successfully loaded the Uno and you execute the commands above, you will see a screen which looks like this:

tio success with readline

tio success with readline

Large Version to see detail

Comments powered by Talkyard.