We’ve gotten used to the GPIO-available functions of Raspberry Pi computers remaining largely the same over the years, which is why it might have flown a little bit under the radar: the Raspberry Pi 4 has six SPI controllers, six I2C controllers, and six UARTs – all on its 40-pin header. You can’t make use of all of these at once, but with up to four different connections wired to a single pin you can carve out a pretty powerful combination of peripherals for your next robotics, automation or cat herding project.
The datasheet for these peripherals is pleasant to go through, with all the register maps nicely laid out – even if you don’t plan to work with the register mappings yourself, the maintainers of your preferred hardware enablement libraries will have an easier time! And, of course, these peripherals are present on the Compute Module 4, too. It might feel like such a deluge of interfaces is excessive, however, it lets you achieve some pretty cool stuff that wouldn’t be possible otherwise.
Having multiple I2C interfaces helps deal with various I2C-specific problems, such as address conflicts, throughput issues, and mixing devices that support different maximum speeds, which means you no longer need fancy mux chips to run five low-resolution Melexis thermal camera sensors at once. (Oh, and the I2C clock stretching bug has been fixed!) SPI interfaces are used for devices with high bandwidth, and with a few separate SPI ports, you could run multiple relatively high-resolution displays at once, No-Nixie Nixie clock style.
As for UARTs, the Raspberry Pi’s one-and-a-half UART interface has long been an issue in robotics and home automation applications. With a slew of devices like radio receivers/transmitters, LIDARs and resilient RS485 multi-drop interfaces available in UART form, it’s nice that you no longer have to sacrifice Bluetooth or a debug console to get some fancy sensors wired up to your robot’s brain. You can enable up to six UARTs.
HOW TO USE THESE INTERFACES?
Enabling these interfaces seems to be straightforward, and people on Raspberry Pi forums and other places have been test-driving them for their own endeavors. All three kinds of interfaces can be enabled using dtoverlay
lines in config.txt
. For SPI, the [MaSt] blog helpfully provides some examples:
# enabling SPI6 with two CS pins - one on GPIO16 and other on GPIO26
dtoverlay=spi6-2cs,cs0_pin=16,cs1_pin=26
For I2C and UART, Raspberry Pi forum threads provided a few examples. I2C example:
# Enabling I2C3, with SDA on GPIO4 and SCL on GPIO5
dtoverlay=i2c3,pins_4_5
# Enabling UART, with RTS and CTS pins (omit the 'ctsrts' part to disable them)
dtoverlay=uart3,ctsrts
From here, these interfaces will appear as you’d expect them, as /dev/spi6
, /dev/i2c-3
and /dev/ttyAMA*
respectively. (The serial ports don’t have aliases yet, so you’ll get one more /dev/ttyAMA
port added to existing ones.)
We were surprised to learn about these new peripherals, and maybe you were too? We can’t wait to see what you’ll do with them.
Source: DID YOU KNOW THAT THE RASPBERRY PI 4 HAS MORE SPI, I2C, UART PORTS?