ExternalPullup.ino 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. // Data wire is plugged into port 2 on the Arduino, while external pullup P-MOSFET gate into port 3
  4. #define ONE_WIRE_BUS 2
  5. #define ONE_WIRE_PULLUP 3
  6. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  7. OneWire oneWire(ONE_WIRE_BUS);
  8. // Pass our oneWire reference to Dallas Temperature.
  9. DallasTemperature sensors(&oneWire, ONE_WIRE_PULLUP);
  10. void setup(void)
  11. {
  12. // start serial port
  13. Serial.begin(9600);
  14. Serial.println("Dallas Temperature IC Control Library Demo");
  15. // Start up the library
  16. sensors.begin();
  17. }
  18. void loop(void)
  19. {
  20. // call sensors.requestTemperatures() to issue a global temperature
  21. // request to all devices on the bus
  22. Serial.print("Requesting temperatures...");
  23. sensors.requestTemperatures(); // Send the command to get temperatures
  24. Serial.println("DONE");
  25. for(int i=0;i<sensors.getDeviceCount();i++) {
  26. Serial.println("Temperature for Device "+String(i)+" is: " + String(sensors.getTempCByIndex(i)));
  27. }
  28. }