Created
July 21, 2016 19:19
-
-
Save ankitdaf/ba7b1326f4d909763effa27201704115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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