Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <OneWire.h>
  2.  
  3. OneWire ds(10);
  4.  
  5. void setup(void) {
  6. Serial.begin(9600);
  7. }
  8.  
  9. void loop(void) {
  10. byte i;
  11. byte present = 0;
  12. byte data[12];
  13. byte addr[8];
  14.  
  15. if ( !ds.search(addr)) {
  16. Serial.print("Nema uredjaja.\n");
  17. ds.reset_search();
  18. return;
  19. }
  20.  
  21. Serial.print("R=");
  22.  
  23. for( i = 0; i < 8; i++) {
  24. Serial.print(addr[i], HEX);
  25. Serial.print(" ");
  26. }
  27.  
  28. if ( OneWire::crc8( addr, 7) != addr[7]) {
  29. Serial.print("CRC is not valid!\n");
  30. return;
  31. }
  32.  
  33. if ( addr[0] == 0x28)
  34. {
  35. Serial.print("Nije DS18B20\n");
  36. }
  37. else
  38. {
  39. Serial.print("Nepoznat: 0x");
  40. Serial.println(addr[0],HEX);
  41. return;
  42. }
  43.  
  44. ds.reset();
  45. ds.select(addr);
  46. ds.write(0x44,1); // start conversion, with parasite power on at the end
  47. delay(1000); // maybe 750ms is enough, maybe not
  48. // we might do a ds.depower() here, but the reset will take care of it.
  49. present = ds.reset();
  50. ds.select(addr);
  51. ds.write(0xBE); // Read Scratchpad
  52. Serial.print("P=");
  53. Serial.print(present,HEX);
  54. Serial.print(" ");
  55.  
  56. for ( i = 0; i < 9; i++) { // we need 9 bytes
  57. data[i] = ds.read();
  58. Serial.print(data[i], HEX);
  59. Serial.print(" ");
  60. }
  61. Serial.print(" CRC=");
  62. Serial.print( OneWire::crc8( data, 8), HEX);
  63. Serial.println();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement