1-Wire
Zo stránky SensorWiki
- 1-Wire bus description (wikipedia.org)
- Design guide
Example program:
#include <LiquidCrystal.h>
#include <OneWire.h>
OneWire ow(12);
LiquidCrystal lcd(3, 2, 1, 4, 5, 6, 7);
byte addr[8];
String keyStatus="";
void setup(void) {
lcd.begin(8, 2);
lcd.print( "iButton-" );
lcd.setCursor(0, 1);
lcd.print( "--reader" );
}
void loop(void) {
getKeyCode();
if ( keyStatus == "ok" ) {
int i;
lcd.setCursor(0, 0);
for( i = 7; i > 3; i-- )
printHex( addr[i] );
lcd.setCursor(0, 1);
for( i = 3; i >= 0; i-- )
printHex( addr[i] );
}
else if ( keyStatus != "nothing" ) {
lcd.clear();
lcd.print(keyStatus);
}
delay(50);
}
void getKeyCode(){
if ( !ow.search(addr) ) {
ow.reset_search();
keyStatus = "nothing";
return;
}
if ( OneWire::crc8(addr, 7) != addr[7] ) {
keyStatus = "CRC err";
return;
}
if ( addr[0] != 0x01 ) {
keyStatus = "DS1990A";
return;
}
keyStatus = "ok";
ow.reset();
}
void printHex(byte x)
{
lcd.print( x / 16, HEX );
lcd.print( x % 16, HEX );
}