Hi -
I'm kind of new to i2c but I have a need to have 2 Arduinos talk to each other so I was thinking of using the i2c. Wired up the master and slave and loaded the example sketches and all works fine.
I then wanted to add a oled screen to the slave for some features. The screen seems to work but the communication between the 2 Arduinos stopped working. I know Adafruit_SSD1306 uses i2c internally so there may be something I need to make this work
MASTER :
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
SLAVE: ( If you uncomment the code that starts up the display the master stops getting data. )
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ArduinoBLE.h>
#include <WiFiNINA.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS_RIGHT 0x3D
Adafruit_SSD1306 left_display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
delay(2000);
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
// if (!left_display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS_RIGHT)) {
// Serial.println(F("SSD1306 allocation failed"));
// for (;;); // Don't proceed, loop forever
// }
// left_display.display();
}
void loop() {
delay(100);
}
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}