Skip to content

Commit 4ff6c1f

Browse files
committed
Add i2c examples
Signed-off-by: Bigbits <[email protected]>
1 parent 44a57b0 commit 4ff6c1f

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
#include <Wire.h>
3+
4+
void setup() {
5+
Serial.begin (115200);
6+
7+
// Leonardo: wait for serial port to connect
8+
while (!Serial)
9+
{
10+
}
11+
12+
Serial.println ();
13+
Serial.println ("I2C Testing ...");
14+
byte count = 0;
15+
16+
Wire.begin();
17+
Wire.beginTransmission(0x3C);
18+
Wire.write(0x80);
19+
Wire.write(0xAF);
20+
Wire.endTransmission();
21+
Serial.println ("Done.");
22+
23+
} // end of setup
24+
25+
void loop() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// I2C Scanner
2+
// Written by Nick Gammon
3+
// Date: 20th April 2011
4+
5+
#include <Wire.h>
6+
7+
void setup() {
8+
Serial.begin (115200);
9+
10+
// Leonardo: wait for serial port to connect
11+
while (!Serial)
12+
{
13+
}
14+
15+
Serial.println ();
16+
Serial.println ("I2C scanner. Scanning ...");
17+
byte count = 0;
18+
19+
Wire.begin();
20+
for (byte i = 8; i < 120; i++)
21+
{
22+
Wire.beginTransmission (i);
23+
if (Wire.endTransmission () == 0)
24+
{
25+
Serial.print ("Found address: ");
26+
Serial.print (i, DEC);
27+
Serial.print (" (0x");
28+
Serial.print (i, HEX);
29+
Serial.println (")");
30+
count++;
31+
//delay (1); // maybe unneeded?
32+
} // end of good response
33+
} // end of for loop
34+
Serial.println ("Done.");
35+
Serial.print ("Found ");
36+
Serial.print (count, DEC);
37+
Serial.println (" device(s).");
38+
} // end of setup
39+
40+
void loop() {}

libraries/Wire/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Allows the communication between devices or sensors connected via Two W
66
paragraph=
77
category=Signal Input/Output
88
url=http://arduino.cc/en/Reference/Wire
9-
architectures=riscv
9+
architectures=k210

0 commit comments

Comments
 (0)