In this post, we’re going to quickly tell you how to use the second hardware I2C port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all that’s needed to do is call the appropriate functions in your sketch.
The default hardware I2C port uses the A4 (SDA) & A5 (SCL) pins for communication. This is very common across almost all the Arduino boards. The second hardware I2C port uses the PE0 (SDA) & PE1 (SCL) pins for communication. These are also marked as SD1 and SC1 on the pinout cards. These are present as test pads on the reverse of the Pico.
For this example, we are going to interface the Accelerometer Blob using the I2C bus for communication. The Pico and Nano are both 5V boards so please make sure the module you use is 5V compatible or else you will need to use a level shifter to convert the 5V signals to 3.3V and vice-versa. The accelerometer blob already contains the necessary level shifting so we can interface it directly to the Pico/Nano.
For this demo, we will be using the following connections:
- Connect the SDA pin to PE0
- Connect the SCL pin to PE1
- Connect the 5V and GND pins to the microcontroller or appropriate power source
Using the new I2C/wire port is very simple. You simply need to use Wire1 instead of Wire. Here’s what the sketch looks like:
We start by setting up the serial port as we want to send serial messages to it. We then setup the Wire1 bus and begin communicating with the module. This follows the standard I2C communication protocol and doesn’t make use of any 3rd party libraries.
We request the accelerometer blob to send us it’s ID which is a unique byte for the LIS3DH chip. We then print this to the serial port to make sure everything is OK.
After uploading the code, you need to open up the serial monitor from the Arduino IDE (Tools -> Serial Monitor). Make sure the correct baud rate is selected. Press the rest button on the board and you should be able to see an output similar to the one shown below:
That’s all you need to do to use the new I2C port. If you are using existing 3rd party libraries, then you will have to manually update the libraries to use Wire1 instead of Wire. Unfortunately, not all the libraries currently support using an alternate serial port.