Created
November 30, 2011 04:15
-
-
Save dydx/1407987 to your computer and use it in GitHub Desktop.
Arduino I2C setup
This file contains hidden or 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
| // Running on an Arduino Mega2560 R.3 | |
| // #20 - SDA | |
| // #21 - SCL | |
| #include <Wire.h> | |
| void setup() { | |
| pinMode(13, OUTPUT); | |
| Wire.begin(); | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| Wire.requestFrom(2, 6); // request 6 bytes from slave #2 | |
| while(Wire.available()) { | |
| char c = Wire.receive(); | |
| Serial.print(c); | |
| // blink #13 to show communication | |
| digitalWrite(13, HIGH); | |
| delay(100); | |
| digitalWrite(13, LOW); | |
| } | |
| delay(500); | |
| } |
This file contains hidden or 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
| // Running on an Arduino Diecimila | |
| // #4 - SDA | |
| // #5 - SCL | |
| #include <Wire.h> | |
| void setup() { | |
| pinMode(13, OUTPUT); | |
| Wire.begin(2); | |
| Wire.onRequest(requestEvent); | |
| } | |
| void loop() { | |
| delay(100); | |
| } | |
| void requestEvent() { | |
| Wire.send("hello "); | |
| // blink #13 to show communication | |
| digitalWrite(13, HIGH); | |
| delay(100); | |
| digitalWrite(13, LOW); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment