Developing in C for the ATmega328P: Raspberry Pi and VS Code Setup Part 3
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.
Links for Reading
Know
- Learning the Command Line
- Editing Remotely Using VS Code
- Developing in C on the AVR ATmega328P: Frequently Asked Questions (FAQ)
- Developing in C on the AVR ATmega328P: Frequently Found Errors (FFE)
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](../images/tio_success.png)
tio success with readline
Update tio to latest
In Raspberry Pi Bookworm, the latest version of the Raspberry Pi OS (as of July 2024), tio is a much older version. And it has been upgraded significantly in the last year. The new version is at least 3.5 and can be installed on the Raspberry Pi using this set of instructions.
cd ~/avr-build
sudo apt install meson
wget https://github.com/tio/tio/releases/download/v3.5/tio-3.5.tar.xz
tar -xvf tio-3.5.tar.xz
cd tio-3.5/
sudo apt install -y libglib2.0-dev liblua5.2-dev
meson setup build
meson compile -C build
sudo meson install -C build
cd
# remove build directory, its quite large, might take a few minutes
rm -rf avr-build/
nano .tioconfig
6. Update tio to latest
The CLI serial monitor program tio is quite handy and has been upgraded significantly in the last year. The new version is at least 3.5 and will be installed.
cd ~/avr-build
wget https://github.com/tio/tio/releases/download/v3.5/tio-3.5.tar.xz
tar -xvf tio-3.5.tar.xz
cd tio-3.5/
sudo apt install -y libglib2.0-dev liblua5.2-dev
meson setup build
meson compile -C build
sudo meson install -C build
cd
# remove build directory, its quite large, might take a few minutes
rm -rf avr-build/
nano .tioconfig
You may paste the text below into the .tioconfig file as a starting point.
[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
Ctrl-S (save) Ctrl-X(exit)
Comments powered by Talkyard.