forked from cybergibbons/DS2482_OneWire
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd2c475
commit 2c34e45
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <Wire.h> | ||
#include <OneWire.h> | ||
|
||
OneWire oneWire; | ||
|
||
void printAddress(uint8_t deviceAddress[8]) | ||
{ | ||
Serial.print("{ "); | ||
for (uint8_t i = 0; i < 8; i++) | ||
{ | ||
// zero pad the address if necessary | ||
Serial.print("0x"); | ||
if (deviceAddress[i] < 16) Serial.print("0"); | ||
Serial.print(deviceAddress[i], HEX); | ||
if (i<7) Serial.print(", "); | ||
|
||
} | ||
Serial.print(" }"); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println("Checking for I2C devices...:"); | ||
if (oneWire.checkPresence()) | ||
{ | ||
Serial.println("DS2482-100 present"); | ||
|
||
oneWire.deviceReset(); | ||
|
||
Serial.println("\tChecking for 1-Wire devices..."); | ||
if (oneWire.wireReset()) | ||
{ | ||
Serial.println("\tDevices present on 1-Wire bus"); | ||
|
||
uint8_t currAddress[8]; | ||
|
||
Serial.println("\t\tSearching 1-Wire bus..."); | ||
|
||
while (oneWire.wireSearch(currAddress)) | ||
{ | ||
Serial.print("\t\t\tFound device: "); | ||
printAddress(currAddress); | ||
Serial.println(); | ||
} | ||
|
||
oneWire.wireResetSearch(); | ||
|
||
} | ||
else | ||
Serial.println("No devices on 1-Wire bus"); | ||
} | ||
else | ||
Serial.println("No DS2482-100 present"); | ||
|
||
delay(5000); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <Wire.h> | ||
|
||
void setup() | ||
{ | ||
Wire.begin(); | ||
|
||
Serial.begin(9600); | ||
Serial.println("\nI2C Scanner"); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
byte error, address; | ||
int nDevices; | ||
|
||
Serial.println("Scanning..."); | ||
|
||
nDevices = 0; | ||
for(address = 1; address < 127; address++ ) | ||
{ | ||
// The i2c_scanner uses the return value of | ||
// the Write.endTransmisstion to see if | ||
// a device did acknowledge to the address. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
|
||
if (error == 0) | ||
{ | ||
Serial.print("I2C device found at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.print(address,HEX); | ||
Serial.println(" !"); | ||
|
||
nDevices++; | ||
} | ||
else if (error==4) | ||
{ | ||
Serial.print("Unknow error at address 0x"); | ||
if (address<16) | ||
Serial.print("0"); | ||
Serial.println(address,HEX); | ||
} | ||
} | ||
if (nDevices == 0) | ||
Serial.println("No I2C devices found\n"); | ||
else | ||
Serial.println("done\n"); | ||
|
||
delay(5000); // wait 5 seconds for next scan | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <Wire.h> | ||
#include <OneWire.h> | ||
|
||
OneWire oneWire; | ||
|
||
void printAddress(uint8_t deviceAddress[8]) | ||
{ | ||
Serial.print("{ "); | ||
for (uint8_t i = 0; i < 8; i++) | ||
{ | ||
// zero pad the address if necessary | ||
Serial.print("0x"); | ||
if (deviceAddress[i] < 16) Serial.print("0"); | ||
Serial.print(deviceAddress[i], HEX); | ||
if (i<7) Serial.print(", "); | ||
|
||
} | ||
Serial.print(" }"); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println("Checking for I2C devices...:"); | ||
if (oneWire.checkPresence()) | ||
{ | ||
Serial.println("DS2482-100 present"); | ||
|
||
oneWire.deviceReset(); | ||
|
||
Serial.println("\tChecking for 1-Wire devices..."); | ||
if (oneWire.wireReset()) | ||
{ | ||
Serial.println("\tDevices present on 1-Wire bus"); | ||
|
||
uint8_t currAddress[8]; | ||
|
||
Serial.println("\t\tSearching 1-Wire bus..."); | ||
|
||
while (oneWire.wireSearch(currAddress)) | ||
{ | ||
Serial.print("\t\t\tFound device: "); | ||
printAddress(currAddress); | ||
Serial.println(); | ||
} | ||
|
||
oneWire.wireResetSearch(); | ||
|
||
} | ||
else | ||
Serial.println("\tNo devices on 1-Wire bus"); | ||
} | ||
else | ||
Serial.println("No DS2482-100 present"); | ||
|
||
delay(5000); | ||
} |