Advertisement
RuiViana

1Wire_Finder

Oct 26th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // This sketch looks for 1-wire devices and
  2. // prints their addresses (serial number) to
  3. // the UART, in a format that is useful in Arduino sketches
  4. // Tutorial:
  5. // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
  6.  
  7. #include <OneWire.h>
  8.  
  9. OneWire ds(3); // Connect your 1-wire device to pin 3
  10.  
  11. void setup(void) {
  12. Serial.begin(9600);
  13. discoverOneWireDevices();
  14. }
  15.  
  16. void discoverOneWireDevices(void) {
  17. byte i;
  18. byte present = 0;
  19. byte data[12];
  20. byte addr[8];
  21.  
  22. Serial.print("Looking for 1-Wire devices...\n\r");
  23. while(ds.search(addr)) {
  24. Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
  25. for( i = 0; i < 8; i++) {
  26. Serial.print("0x");
  27. if (addr[i] < 16) {
  28. Serial.print('0');
  29. }
  30. Serial.print(addr[i], HEX);
  31. if (i < 7) {
  32. Serial.print(", ");
  33. }
  34. }
  35. if ( OneWire::crc8( addr, 7) != addr[7]) {
  36. Serial.print("CRC is not valid!\n");
  37. return;
  38. }
  39. }
  40. Serial.print("\n\r\n\rThat's it.\r\n");
  41. ds.reset_search();
  42. return;
  43. }
  44.  
  45. void loop(void) {
  46. // nothing to see here
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement