Skip to content

Commit 31e7561

Browse files
author
Kevin Moloney
committed
Missing examples folder in Wire library
- Slave examples not relevant because AtlasPeak does not support slave-mode I2C. - Examples included digital_potentiometer, master_reader, master_writer, SFRRanger_reader. Signed-off-by: Kevin Moloney <kevin.moloney@emutex.com>
1 parent 7436867 commit 31e7561

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder
2+
// by Nicholas Zambetti <http://www.zambetti.com>
3+
// and James Tichenor <http://www.jamestichenor.net>
4+
5+
// Demonstrates use of the Wire library reading data from the
6+
// Devantech Utrasonic Rangers SFR08 and SFR10
7+
8+
// Created 29 April 2006
9+
10+
// This example code is in the public domain.
11+
12+
13+
#include <Wire.h>
14+
15+
void setup()
16+
{
17+
Wire.begin(); // join i2c bus (address optional for master)
18+
Serial.begin(9600); // start serial communication at 9600bps
19+
}
20+
21+
int reading = 0;
22+
23+
void loop()
24+
{
25+
// step 1: instruct sensor to read echoes
26+
Wire.beginTransmission(112); // transmit to device #112 (0x70)
27+
// the address specified in the datasheet is 224 (0xE0)
28+
// but i2c adressing uses the high 7 bits so it's 112
29+
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
30+
Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50)
31+
// use 0x51 for centimeters
32+
// use 0x52 for ping microseconds
33+
Wire.endTransmission(); // stop transmitting
34+
35+
// step 2: wait for readings to happen
36+
delay(70); // datasheet suggests at least 65 milliseconds
37+
38+
// step 3: instruct sensor to return a particular echo reading
39+
Wire.beginTransmission(112); // transmit to device #112
40+
Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
41+
Wire.endTransmission(); // stop transmitting
42+
43+
// step 4: request reading from sensor
44+
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
45+
46+
// step 5: receive reading from sensor
47+
if (2 <= Wire.available()) // if two bytes were received
48+
{
49+
reading = Wire.read(); // receive high byte (overwrites previous reading)
50+
reading = reading << 8; // shift high byte to be high 8 bits
51+
reading |= Wire.read(); // receive low byte as lower 8 bits
52+
Serial.println(reading); // print the reading
53+
}
54+
55+
delay(250); // wait a bit since people have to read the output :)
56+
}
57+
58+
59+
/*
60+
61+
// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08)
62+
// usage: changeAddress(0x70, 0xE6);
63+
64+
void changeAddress(byte oldAddress, byte newAddress)
65+
{
66+
Wire.beginTransmission(oldAddress);
67+
Wire.write(byte(0x00));
68+
Wire.write(byte(0xA0));
69+
Wire.endTransmission();
70+
71+
Wire.beginTransmission(oldAddress);
72+
Wire.write(byte(0x00));
73+
Wire.write(byte(0xAA));
74+
Wire.endTransmission();
75+
76+
Wire.beginTransmission(oldAddress);
77+
Wire.write(byte(0x00));
78+
Wire.write(byte(0xA5));
79+
Wire.endTransmission();
80+
81+
Wire.beginTransmission(oldAddress);
82+
Wire.write(byte(0x00));
83+
Wire.write(newAddress);
84+
Wire.endTransmission();
85+
}
86+
87+
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// I2C Digital Potentiometer
2+
// by Nicholas Zambetti <http://www.zambetti.com>
3+
// and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>
4+
5+
// Demonstrates use of the Wire library
6+
// Controls AD5171 digital potentiometer via I2C/TWI
7+
8+
// Created 31 March 2006
9+
10+
// This example code is in the public domain.
11+
12+
// This example code is in the public domain.
13+
14+
15+
#include <Wire.h>
16+
17+
void setup()
18+
{
19+
Wire.begin(); // join i2c bus (address optional for master)
20+
}
21+
22+
byte val = 0;
23+
24+
void loop()
25+
{
26+
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
27+
// device address is specified in datasheet
28+
Wire.write(byte(0x00)); // sends instruction byte
29+
Wire.write(val); // sends potentiometer value byte
30+
Wire.endTransmission(); // stop transmitting
31+
32+
val++; // increment value
33+
if (val == 64) // if reached 64th position (max)
34+
{
35+
val = 0; // start over from lowest value
36+
}
37+
delay(500);
38+
}
39+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Wire Master Reader
2+
// by Nicholas Zambetti <http://www.zambetti.com>
3+
4+
// Demonstrates use of the Wire library
5+
// Reads data from an I2C/TWI slave device
6+
// Refer to the "Wire Slave Sender" example for use with this
7+
8+
// Created 29 March 2006
9+
10+
// This example code is in the public domain.
11+
12+
13+
#include <Wire.h>
14+
15+
void setup()
16+
{
17+
Wire.begin(); // join i2c bus (address optional for master)
18+
Serial1.begin(9600); // start serial for output
19+
}
20+
21+
void loop()
22+
{
23+
Wire.requestFrom(8, 6,false); // request 6 bytes from slave device #8
24+
25+
while (Wire.available()) // slave may send less than requested
26+
{
27+
char c = Wire.read(); // receive a byte as character
28+
Serial1.print(c); // print the character
29+
Serial1.println();
30+
31+
}
32+
33+
delay(500);
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Wire Master Writer
2+
// by Nicholas Zambetti <http://www.zambetti.com>
3+
4+
// Demonstrates use of the Wire library
5+
// Writes data to an I2C/TWI slave device
6+
// Refer to the "Wire Slave Receiver" example for use with this
7+
8+
// Created 29 March 2006
9+
10+
// This example code is in the public domain.
11+
12+
13+
#include <Wire.h>
14+
15+
void setup()
16+
{
17+
Wire.begin(); // join i2c bus (address optional for master)
18+
Serial1.begin(9600);
19+
}
20+
21+
byte x = 1;
22+
byte rdata;
23+
void loop()
24+
{
25+
Wire.beginTransmission(8); // transmit to device #8
26+
//Wire.write("x is "); // sends five bytes
27+
Wire.write(x); // sends one byte
28+
int result = Wire.endTransmission(); // stop transmitting
29+
Serial1.println();
30+
Serial1.print("x = ");
31+
Serial1.print(x);
32+
x++;
33+
delay(500);
34+
}

0 commit comments

Comments
 (0)