Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
82
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(2); // 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. Serial.println(addr);
  26. for( i = 0; i < 8; i++) {
  27. Serial.print("0x");
  28. if (addr[i] < 16) {
  29. Serial.print('0');
  30. }
  31. Serial.print(addr[i], HEX);
  32. if (i < 7) {
  33. Serial.print(", ");
  34. }
  35. }
  36. if ( OneWire::crc8( addr, 7) != addr[7]) {
  37. Serial.print("CRC is not valid!\n");
  38. return;
  39. }
  40. }
  41. Serial.print("\n\r\n\rThat's it.\r\n");
  42. ds.reset_search();
  43. return;
  44. }
  45.  
  46. void loop(void) {
  47. // nothing to see here
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement