1

I want to communicate between 2 Pi Pico's using I2C. I want to do program these with the Arduino IDE. I have tried using Wire.h and some examples I found online. However, they don't seem to be able to connect to each other.

This is my Master code:

#include "Wire.h"

void setup() {

  Wire.begin();
  Serial.begin(9600);
  
  bool setSDA(1);
  bool setSCL(2);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {

  Wire.requestFrom(8, 6);    
  Serial.println("Waiting...");

  while (Wire.available()) { 
    char c = Wire.read();
    Serial.print(c);      }

  delay(500);
}

This is my slave code:

#include "Wire.h"

void setup() {
  Wire.begin(8);
  Wire.onRequest(requestEvent);
  Serial.begin();

  bool setSDA(1);
  bool setSCL(2);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
  delay(100);
  Serial.println("Recieving...");
}

void requestEvent() {
  Wire.write("hello "); 

}

What am I doing wrong?

joshuagws
  • 21
  • 3
  • Your Master sketch is a Master Reader which waiting for a Slave `0x08` to send 6 bytes of data. Your Slave sketch is a Slave Sender. Your Master sketch didn't setup as a Master and didn't setup a Master i2c address, your Slave sketch is expecting Master to send the request in order to send the data out. In order to achieve full-duplex or synchronous i2c communication, you also need to also implement the Master Sender on the Master sketch, and Slave Reader on the Slave sketch. – hcheung Aug 19 '22 at 07:40

0 Answers0