Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- // Data wire is plugged into port 7 on the Arduino
- #define ONE_WIRE_BUS 7
- #define TEMPERATURE_PRECISION 12
- // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- // arrays to hold device addresses
- DeviceAddress zero, jeden, dwa, trzy, cztery, piec, szesc, siedem, osiem, dziewiec, dziesiec, jedenascie;
- void setup(void)
- {
- // start serial port
- Serial.begin(9600);
- Serial.println("Dallas Temperature IC Control Library Demo");
- // Start up the library
- sensors.begin();
- // locate devices on the bus
- Serial.print("Locating devices...");
- Serial.print("Found ");
- Serial.print(sensors.getDeviceCount(), DEC);
- Serial.println(" devices.");
- // report parasite power requirements
- Serial.print("Parasite power is: ");
- if (sensors.isParasitePowerMode()) Serial.println("ON");
- else Serial.println("OFF");
- // Assign address manually. The addresses below will beed to be changed
- // to valid device addresses on your bus. Device address can be retrieved
- // by using either oneWire.search(deviceAddress) or individually via
- // sensors.getAddress(deviceAddress, index)
- //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
- //outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
- // Search for devices on the bus and assign based on an index. Ideally,
- // you would do this to initially discover addresses on the bus and then
- // use those addresses and manually assign them (see above) once you know
- // the devices on your bus (and assuming they don't change).
- //
- // method 1: by index
- if (!sensors.getAddress(zero, 0)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(jeden, 1)) Serial.println("Unable to find address for Device 2");
- if (!sensors.getAddress(dwa, 2)) Serial.println("Unable to find address for Device 3");
- if (!sensors.getAddress(trzy, 3)) Serial.println("Unable to find address for Device 4");
- if (!sensors.getAddress(cztery, 4)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(piec, 5)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(szesc, 6)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(siedem, 7)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(osiem, 8)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(dziewiec, 9)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(dziesiec, 10)) Serial.println("Unable to find address for Device 1");
- if (!sensors.getAddress(jedenascie, 11)) Serial.println("Unable to find address for Device 1");
- // method 2: search()
- // search() looks for the next device. Returns 1 if a new address has been
- // returned. A zero might mean that the bus is shorted, there are no devices,
- // or you have already retrieved all of them. It might be a good idea to
- // check the CRC to make sure you didn't get garbage. The order is
- // deterministic. You will always get the same devices in the same order
- //
- // Must be called before search()
- oneWire.reset_search();
- if (!oneWire.search(zero)) Serial.println("Unable to find address for 1");
- if (!oneWire.search(jeden)) Serial.println("Unable to find address for 2");
- if (!oneWire.search(dwa)) Serial.println("Unable to find address for 3");
- if (!oneWire.search(trzy)) Serial.println("Unable to find address for 4");
- if (!oneWire.search(cztery)) Serial.println("Unable to find address for 5");
- if (!oneWire.search(piec)) Serial.println("Unable to find address for 6");
- if (!oneWire.search(szesc)) Serial.println("Unable to find address for 7");
- if (!oneWire.search(siedem)) Serial.println("Unable to find address for 8");
- if (!oneWire.search(osiem)) Serial.println("Unable to find address for 9");
- if (!oneWire.search(dziewiec)) Serial.println("Unable to find address for 10");
- if (!oneWire.search(dziesiec)) Serial.println("Unable to find address for 11");
- if (!oneWire.search(jedenascie)) Serial.println("Unable to find address for 12");
- // show the addresses we found on the bus
- Serial.print("Device 1 Address: ");
- printAddress(zero);
- Serial.println();
- Serial.print("Device 2 Address: ");
- printAddress(jeden);
- Serial.println();
- Serial.print("Device 3 Address: ");
- printAddress(dwa);
- Serial.println();
- Serial.print("Device 4 Address: ");
- printAddress(trzy);
- Serial.println();
- Serial.print("Device 5 Address: ");
- printAddress(cztery);
- Serial.println();
- Serial.print("Device 6 Address: ");
- printAddress(piec);
- Serial.println();
- Serial.print("Device 7 Address: ");
- printAddress(szesc);
- Serial.println();
- Serial.print("Device 8 Address: ");
- printAddress(siedem);
- Serial.println();
- Serial.print("Device 9 Address: ");
- printAddress(osiem);
- Serial.println();
- Serial.print("Device 10 Address: ");
- printAddress(dziewiec);
- Serial.println();
- Serial.print("Device 11 Address: ");
- printAddress(dziesiec);
- Serial.println();
- Serial.print("Device 12 Address: ");
- printAddress(jedenascie);
- Serial.println();
- // set the resolution to 12 bit per device
- sensors.setResolution(zero, TEMPERATURE_PRECISION);
- sensors.setResolution(jeden, TEMPERATURE_PRECISION);
- sensors.setResolution(dwa, TEMPERATURE_PRECISION);
- sensors.setResolution(trzy, TEMPERATURE_PRECISION);
- sensors.setResolution(cztery, TEMPERATURE_PRECISION);
- sensors.setResolution(piec, TEMPERATURE_PRECISION);
- sensors.setResolution(szesc, TEMPERATURE_PRECISION);
- sensors.setResolution(siedem, TEMPERATURE_PRECISION);
- sensors.setResolution(osiem, TEMPERATURE_PRECISION);
- sensors.setResolution(dziewiec, TEMPERATURE_PRECISION);
- sensors.setResolution(dziesiec, TEMPERATURE_PRECISION);
- sensors.setResolution(jedenascie, TEMPERATURE_PRECISION);
- Serial.print("01:");
- Serial.print(sensors.getResolution(zero), DEC);
- Serial.println();
- Serial.print("02:");
- Serial.print(sensors.getResolution(jeden), DEC);
- Serial.println();
- Serial.print("03:");
- Serial.print(sensors.getResolution(dwa), DEC);
- Serial.println();
- Serial.print("04:");
- Serial.print(sensors.getResolution(trzy), DEC);
- Serial.println();
- Serial.print("05:");
- Serial.print(sensors.getResolution(cztery), DEC);
- Serial.println();
- Serial.print("06:");
- Serial.print(sensors.getResolution(piec), DEC);
- Serial.println();
- Serial.print("07:");
- Serial.print(sensors.getResolution(szesc), DEC);
- Serial.println();
- Serial.print("08:");
- Serial.print(sensors.getResolution(siedem), DEC);
- Serial.println();
- Serial.print("09:");
- Serial.print(sensors.getResolution(osiem), DEC);
- Serial.println();
- Serial.print("10:");
- Serial.print(sensors.getResolution(dziewiec), DEC);
- Serial.println();
- Serial.print("11:");
- Serial.print(sensors.getResolution(dziesiec), DEC);
- Serial.println();
- Serial.print("12:");
- Serial.print(sensors.getResolution(jedenascie), DEC);
- Serial.println();
- }
- // function to print a device address
- void printAddress(DeviceAddress deviceAddress)
- {
- for (uint8_t i = 0; i < 8; i++)
- {
- // zero pad the address if necessary
- if (deviceAddress[i] < 16) Serial.print("0");
- Serial.print(deviceAddress[i], HEX);
- }
- }
- // function to print the temperature for a device
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- Serial.print("Temp C: ");
- Serial.print(tempC);
- }
- // function to print a device's resolution
- void printResolution(DeviceAddress deviceAddress)
- {
- Serial.print("Resolution: ");
- Serial.print(sensors.getResolution(deviceAddress));
- Serial.println();
- }
- // main function to print information about a device
- void printData(DeviceAddress deviceAddress)
- {
- //Serial.print("Device Address: ");
- printAddress(deviceAddress);
- Serial.print(" ");
- printTemperature(deviceAddress);
- Serial.print(" ");
- // Serial.println();
- }
- /*
- * Main function, calls the temperatures in a loop.
- */
- void loop(void)
- {
- Serial.println();
- // call sensors.requestTemperatures() to issue a global temperature
- // request to all devices on the bus
- Serial.print("Requesting temperatures:");
- sensors.requestTemperatures();
- Serial.print("DONE ");
- // delay(9000);
- // print the device information
- printData(zero);
- printData(jeden);
- printData(dwa);
- printData(trzy);
- printData(cztery);
- printData(piec);
- printData(szesc);
- printData(siedem);
- printData(osiem);
- printData(dziewiec);
- printData(dziesiec);
- printData(jedenascie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement