readPowerSupply.ino 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // FILE: readPowerSupply.ino
  3. // AUTHOR: Rob Tillaart
  4. // VERSION: 0.1.0
  5. // PURPOSE: demo
  6. // DATE: 2020-02-10
  7. //
  8. // Released to the public domain
  9. //
  10. // Include the libraries we need
  11. #include <OneWire.h>
  12. #include <DallasTemperature.h>
  13. // Data wire is plugged into port 2 on the Arduino
  14. #define ONE_WIRE_BUS 2
  15. // Setup a oneWire instance to communicate with any OneWire devices
  16. OneWire oneWire(ONE_WIRE_BUS);
  17. // Pass our oneWire reference to Dallas Temperature.
  18. DallasTemperature sensors(&oneWire);
  19. // arrays to hold device addresses
  20. DeviceAddress insideThermometer, outsideThermometer;
  21. // Assign address manually. The addresses below will beed to be changed
  22. // to valid device addresses on your bus. Device address can be retrieved
  23. // by using either oneWire.search(deviceAddress) or individually via
  24. // sensors.getAddress(deviceAddress, index)
  25. // DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  26. // DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
  27. int devCount = 0;
  28. /*
  29. * The setup function. We only start the sensors here
  30. */
  31. void setup(void)
  32. {
  33. Serial.begin(115200);
  34. Serial.println("Arduino Temperature Control Library Demo - readPowerSupply");
  35. sensors.begin();
  36. devCount = sensors.getDeviceCount();
  37. Serial.print("#devices: ");
  38. Serial.println(devCount);
  39. // report parasite power requirements
  40. Serial.print("Parasite power is: ");
  41. if (sensors.readPowerSupply()) Serial.println("ON"); // no address means "scan all devices for parasite mode"
  42. else Serial.println("OFF");
  43. // Search for devices on the bus and assign based on an index.
  44. if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  45. if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
  46. // show the addresses we found on the bus
  47. Serial.print("Device 0 Address: ");
  48. printAddress(insideThermometer);
  49. Serial.println();
  50. Serial.print("Power = parasite: ");
  51. Serial.println(sensors.readPowerSupply(insideThermometer));
  52. Serial.println();
  53. Serial.println();
  54. Serial.print("Device 1 Address: ");
  55. printAddress(outsideThermometer);
  56. Serial.println();
  57. Serial.print("Power = parasite: ");
  58. Serial.println(sensors.readPowerSupply(outsideThermometer));
  59. Serial.println();
  60. Serial.println();
  61. }
  62. // function to print a device address
  63. void printAddress(DeviceAddress deviceAddress)
  64. {
  65. for (uint8_t i = 0; i < 8; i++)
  66. {
  67. // zero pad the address if necessary
  68. if (deviceAddress[i] < 0x10) Serial.print("0");
  69. Serial.print(deviceAddress[i], HEX);
  70. }
  71. }
  72. // empty on purpose
  73. void loop(void)
  74. {
  75. }
  76. // END OF FILE