Here are the steps to follow to configure your device to control a microcontroller with I²C and possibly a second microcontroller, as well as the LCD panel.
For the configuration of the first microcontroller, we assume that you have connected the cables enabling configuration between your device and the microcontroller.
Make sure that I²C is enabled by default. Check the file /boot/firmware/syscfg.txt and see if you have the following line:
dtparam=i2c_arm=on
If not, maybe you can append them on /boot/firmware/usercfg.txt and reboot, and hopefully, that works. If that doesn't work, maybe do sudo apt update && sudo full-upgrade -y
and see if there are any distro updates needed.
- Refer to this post.
You can also add the following line to /etc/modules:
i2c-dev
- Refer to this post.
On a RPi, with raspi-config
, you can enable I²C by navigating to Interface Options->Advanced->I²C and then enable it.
If you're not using a second microcontroller and you don't have an LCD panel, you can go straight to the next step.
Now when you log in you can type the following command to see all the connected devices:
sudo i2cdetect -y 1 # Or 0, depends on the device you use.
If your robot uses two microcontrollers, then you can figure the second I²C by following the instructions below.
We first have to edit /boot/config.txt:
sudo nano /boot/config.txt
If we scroll to the bottom we may find the remnants of the precious peripheral (if it was added here previously):
dtoverlay=i2c-rtc,pcf8523,wakeup-source # RTC
We now need to add an additional device under a new bus — e.g. bus 2 or 4 (I personally used bus 4). We do this by adding an additional line with the content below: You can modify the values according to the ports & bus you have chosen for your Raspberry Pi.
dtoverlay=i2c-gpio,bus=4,i2c_gpio_sda=23,i2c_gpio_scl=24 # 23 & 24 can be changed to the port you want.
Here's a second method for configuring a second port, if you don't want to set this port as the default when you start your device. When using a Raspberry Pi, you must first have dtoverlay installed for the manual configuration. Install it by copying this command:
sudo apt install libraspberrypi-bin
If we do not want to change any files we can tell our Raspberry Pi to load the port through a shell script with the following command. This method is easier for optional loads or prototyping. The dtoverlay the command is similar to that of the config.txt file.
sudo dtoverlay i2c-gpio bus=2 i2c_gpio_sda=23 i2c_gpio_scl=24
- Refer to this post
Note that there are other ways to acccomplish this.
To configure the LCD, you'll need to set up a new I²C port, in the same way as for configuring the second microcontroller input. After selecting the SDA, SCL port & bus to be configured, enter this command and modify it as required. Here's an example (I personally chosed bus 3):
sudo dtoverlay i2c-gpio bus=3 i2c_gpio_sda=10 i2c_gpio_scl=9
ROS2 Humble still uses the old setup.py
method of installing packages within its enviornment. This has been deprecated in python 3.10.
If you are getting these warnings you can safely ignore them but if you want to surpress them you can downgrade your version of setup tools
doing the following.
pip install setuptools==58.2.0
Next step: Build the project