Skip to content

Commit

Permalink
Three example sketches
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergibbons committed Feb 24, 2014
1 parent dd2c475 commit 2c34e45
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
61 changes: 61 additions & 0 deletions examples/DallasTemperature/DallasTemperature.ino
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);
}
52 changes: 52 additions & 0 deletions examples/I2C_Scanner/I2C_Scanner.ino
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
}
61 changes: 61 additions & 0 deletions examples/Scan_1Wire_Bus/Scan_1Wire_Bus.ino
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);
}

0 comments on commit 2c34e45

Please sign in to comment.