Skip to content

Instantly share code, notes, and snippets.

@ankitdaf
Created July 21, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitdaf/ba7b1326f4d909763effa27201704115 to your computer and use it in GitHub Desktop.
Save ankitdaf/ba7b1326f4d909763effa27201704115 to your computer and use it in GitHub Desktop.
/*
* 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