pastebin - collaborative debugging tool
kpaste.net RSS


arduino firmware
Posted by Anonymous on Sat 23rd Nov 2013 10:10
raw | new post

  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3.  
  4. // Data wire is plugged into pin 2 on the Arduino
  5. #define ONE_WIRE_BUS 8
  6.  
  7. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  8. OneWire oneWire(ONE_WIRE_BUS);
  9.  
  10. // Pass our oneWire reference to Dallas Temperature.
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. void setup(void)
  14. {
  15.   // start serial port
  16.   Serial.begin(9600);
  17.   //Serial.println("Dallas Temperature IC Control Library Demo");
  18.     delay(50);
  19.  
  20.   // Start up the library
  21.   sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
  22.       delay(100);
  23.  
  24. sensors.setResolution(0, 12);
  25.  
  26. }
  27.  
  28.  
  29. void loop(void)
  30. {
  31.   // call sensors.requestTemperatures() to issue a global temperature
  32.   // request to all devices on the bus
  33.  // Serial.print("Requesting temperatures...");
  34.   sensors.requestTemperatures(); // Send the command to get temperatures
  35.  // Serial.println("DONE");
  36.     delay(100);
  37.  // Serial.print("Temperature for Device 1 is: ");
  38.   Serial.print(sensors.getTempFByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  39.   Serial.print("^");
  40.     delay(50);
  41.   Serial.print(sensors.getTempFByIndex(1));
  42.   Serial.print("^");
  43.     delay(50);
  44.   Serial.println(sensors.getTempFByIndex(2));
  45.     delay(50);
  46. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at