In this chapter, we dive into advanced IO by learning how to use UART, I2C, and SPI with the Pico. These are all communication protocols which are just methods or sets of rules that devices can use to communicate information between them. This is a step up from basic IO as they allow us to send data as strings instead of voltages.


So we know how to read digital and analog signals and these are great, they're really handy but what if instead we wanted to use some more advanced sensors like this GPS module here? How on earth do you read GPS coordinates with a digital or analog input? Well this is where we're going to need to use something called a communication protocol.

Communication protocols use ones and zeros or bits to send information between devices in binary. And our Pico here does this by setting the voltages on its pins, zero volts is a zero and 3.3 volts is a one. So the Pico can set those two voltages very quickly to send bits of ones and zeros to another device. So we can take information like a GPS coordinate, turn it into ones and zeros, then send it over a wire to another device, our Pico in this case, and then that Pico can turn those ones and zeros back into GPS coordinates. We're kind of just turning data into voltages and then on the other device turning those voltages back into meaningful data.

Now both of these devices must speak the same binary language and they also must agree on a system of how they are connected to each other and how they transfer data to each other and this system they both used is called a communication protocol. We will be covering the three most common of them, UART, SPI and I2C. And all of them have their own unique quirks and different applications, but we'll get into that later.

We're going to learn how to use modules with our Pico. For example, this is an atmospheric sensor with an onboard temperature sensor. You connect 3.3 volts on ground to power it and then you connect these two wires back to your Pico. And from these two wires it's going to send the exact temperature reading back to your Pico. But if we were to use a temperature sensor through an analog input on our Pico, we would only get back a voltage. And then we'd need to look at the data sheet and use some equations to figure out what's the temperature based on the voltage that the sensor is reading. And that's fine, there are situations where you would do that, but you could also just grab one of these sensor modules and that would do all the work for you and it just reports back the final temperature. And that is a huge advantage of these modules, they are easy to wire up, easier to use and most of the time they're going to save you a lot of time. And you can find a module for basically anything.

Here is an OLED screen that you might have seen that's been using already. And here is one to control servos on, you can plug four servos into it and then control that with just two wires. Here is an ultrasonic distance sensor, a colour sensor, atmospheric pressure sensor, a compass. There is a lot of different sensors and peripherals that come on modules.

I'd like to finish here by saying that this world of UART, SBI and I2C opens up some very deep rabbit holes that get very complex very quickly. The in-depth details of what fully goes on with these communication protocols is way, way, way beyond the scope of this course and it's not beginner friendly at all. But thankfully, using UART, SBI and I2C with modules is actually extremely easy with the help of libraries, which is how you're probably going to use them 99% of the time. In fact, they're probably as easy to use as basic I.O. because the libraries let a lot of that complex wizardry happen behind the curtain. And we're left with a relatively plug-and-play setup using modules.



Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.