4.3. Serial Communication

4.3.1. What is Serial Communication?

Serial communication is a way to send information from one device to another over a single wire. Instead of connecting 10 pins from one device to 10 pins of the other, each pin representing whether one wheel will move forwards or backwards, we encode this information into a stream of many bits and we send them at a known time interval over a single pin.

This drastically reduces the amount of wires needed but adds extra complexity in software as you need to properly configure the speed at which you will send the bits on each device. Additionally, you will need to cut up your data into standard little packages that can be sent over the serial bus. Fortunately for us, there are many libraries that already do this for us, such as pyserial (see next sections).

Note

USB stands for Universal Serial Bus as it is doing serial communication!

For more information, see the Serial Tutorial from Sparkfun

4.3.2. Why do we Use Serial?

As we are sending a host of different information between our Raspberry Pi and our arduino, serial is a great way to communicate between both as it lets us send numbers, characters or even strings of text very easily thanks to the powerful libraries available.

Warning

Our arduino’s pins work at 5V and our Raspberry Pi’s pins at 3.3V, do not ever connect them together as you will fry the Raspberry Pi!

In addition, this lets us use a simple USB cable between our Raspberry Pi and our Arduino which frees us from the need of using level shifters to communicate between both.

Note

A level shifters is a small electronic chip which you put in the middle of a serial bus, it transforms a signal at 3.3V to one at 5V (for example).

4.3.3. Python Packages for Serial

Make sure you have been through the Python3 section of the documentation before installing the serial packages.

To install the pyserial library systemwide on your device, open up a terminal and run:

sudo apt install python3-serial -y

Arduino IDE Logo
Arduino IDE Logo
If you run into any issue, apply the workflow described in the debugging cookbook and if you still can't figure it out, send a message on the microver.ch Discord Forum

Please signal any mistake to: errata@microver.ch