Create a gist now

Instantly share code, notes, and snippets.

/*
* Blog post describing the use case for this script is here :
* http://blog.ankitdaf.com/snooping-on-i2c-making-an-oled-display-work/
*
*/
#include <Wire.h>
int buff[1024];
int buff_pointer = 0;
void setup()
{
Serial.begin(115200); // start serial for output
Serial.println("Ready");
Wire.begin(0x3c); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
}
void loop()
{
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
int j = 0;
while (j < howMany) // loop through all but the last
{
int c = Wire.read(); // receive byte as a character
Serial.print("0x"); // print the character in Hex
Serial.print(c,HEX);
Serial.print(" ");
Serial.print(c); // print the character as ascii
Serial.print(" ");
++j;
}
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment