Pi Pico i2c Write&Reader on Arduino IDE?

Hello, I'm trying make two raspberry Pi Pico talk to each other in i2c one with a writer and the second one as a reader. I used this link here to get started https://www.electronicwings.com/arduino/arduino-i2c. For some odd reason and I'm not sure I'm unable to get one to write or read it. I'm not sure what is wrong.

Does the pi pico use the same wire i2c libraries? I'm just wondering if the examples or library is the problem? The i2c pins I'm using on the pi pico are pin 11 and pin12, also sharing a Ground pin on pin13.

Edit: I'm just wondering what am I missing or doing wrong?

Example Sketches

Writter:

// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop() {
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting

  x++;
  delay(500);
}

Reader:

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

Joseph

The default i2c for a pico uses pins 6 & 7, but you can change them. Wire (I2C Master and Slave) — Arduino-Pico 3.3.0 documentation

receiveEvent is called in interrupt context, so you must not use any code that depends on interrupts (such as using the Serial object).

The default pins for the I2C bus are 4 and 5 for the Raspberry Pi Pico.
You can tell which they are by printing I2C_SDA and I2C_SCL or look in pins_arduino.h

This is if you have the normal Arduino on top of Mbed for the Pico.

The real question is if the Pico supports the I2C Slave mode.

Thank you i will try that out.

Is there a better way example for writing and reading for i2c?

I will try that out thank you. 4&5 shows it to be i2c1. The default i2c is suppose to be i2c0 correct?

Hello, Thank you all for the help. I got the pi pico to work on the i2c it was the 6th and 7th pin for i2c default pins. I wanted to try the pi pico because of the 3.3v logic level. I have a custom board a friend of mine has that uses the Arduino zero SamdD21 processor. I wanted to connect to but his board uses the sircom ports. It has a modify pinout. I had no arduino zero board but I do have pi pico boards to see If I can talk from one pico to another. My next step is to try to connect to his board and see If It can talk to my pico board.

Which Raspberry Pi Pico do you have ?
Which board did you install in the Arduino IDE ?

I have a Raspberry Pi Pico (not an Arduino board): https://www.kiwi-electronics.com/nl/raspberry-pi-pico-10494
I use the Arduino IDE 2.1.1 and I have installed the board: "Arduino Mbed OS RP2040 Boards" by Arduino, version 4.0.2.

The board I have says Raspberry pi pico copy right 2020 thats all. It's not the wireless one. I did manage to get i2c working now.

I have arduino ide 1.8.16. I can program the pico with no problem. I just couldn't get i2c working until nlow. I was on the wrong pins.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.