I2c communication between Raspberry Pi Pico and Arduino Nano

I2c communication between Raspberry Pi Pico and Arduino Nano

In this article I want to show the serial communication of Raspberry Pi Pico and Arduino Nano with I2c protocol.

In particular Arduino send data to Raspberry Pi Pico.

Note that Raspberry Pi Pico is configured as SLAVE

Arduino code

#include <Wire.h>

const int I2C_ADD =0x50;

  
void setup() {
    Wire.begin();
    Serial.begin(9600);
  
    pinMode(LED_BUILTIN, OUTPUT);

    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
}
  
void loop() {
  
    delay(1000);      
    
    for(int i = 0;i<100;i++){
       Wire.beginTransmission(I2C_ADD );
       Wire.write('a' );
       Wire.endTransmission();
       
       delay(500);
       digitalWrite(LED_BUILTIN, HIGH);
       delay(500);
       digitalWrite(LED_BUILTIN, LOW);
    }
}

Raspberry Pi Pico Code

static int I2C_ADD = 0x50;

int main() {
 
    stdio_init_all();
    
    i2c_init(i2c_default,  100000); //100kHZ
    gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
    gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
    gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
    gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
    bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C));

    i2c_set_slave_mode(i2c_default,true,I2C_ADD);
    

    uint8_t buffer[1];   

    while(1){
        
        int readResult = i2c_read_blocking(i2c_default, I2C_ADD, buffer, 1, false);
        
        if(readResult>0){
            printf("Lenght= %d. Received: %d\n",readResult, buffer[0]);
        }
       
    }
}

Wiring

Wiring Arduino and Raspberry Pi Pico

NOTE: pullup restistors have a value of 4.7 KOhm