I am making a split keyboard with a pair of 4.0s and I am unable to get a basic master read sample working. Do I need pull up resistors for this scenario? I'm using a common ground and pins 18 and 19. Any tips would be appreciated.
slave code:
master code:
slave code:
Code:
#include <Arduino.h>
#include <i2c_driver.h>
#include <i2c_driver_wire.h>
#include <i2c_register_slave.h>
void requestEvent();
int led = LED_BUILTIN;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop(){
Serial.println("hey");
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
digitalWrite(led, HIGH); // briefly flash the LED
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
digitalWrite(led, LOW);
}
master code:
Code:
#include <i2c_driver.h>
#include <i2c_driver_wire.h>
#include <i2c_device.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 peripheral device #8
while (Wire.available()) { // peripheral may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
Serial.println("hey");
delay(500);
}