Code:
#include <i2c_device.h>
#include "i2c_driver.h"
#include <i2c_driver_wire.h>
#include <i2c_register_slave.h>
int pins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 20, 21, 22, 23, 24, 26};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for (int i = 0; i < 23; i++){
pinMode(pins[i], INPUT_PULLUP);
Wire.begin();
}
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 23; i++){
Serial.print(digitalRead(pins[i]));
Serial.print("\t");
Wire.beginTransmission(1);
Wire.write(digitalRead(pins[i]));
Wire.endTransmission(false);
}
Serial.println();
delay(5);
}
So I fixed the code a little. Had to add a wire.endtranmission in there.
This is the slave device, it is very generic but I got it to communicate.
Code:
// 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(1); // join I2C bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(5);
}
// 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("\t");
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
Serial.print("\t");
}
Now I can see the serial printout. I'm trying to get it in the same format as the master device.