Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3.  
  4. // Data wire is plugged into port 7 on the Arduino
  5. #define ONE_WIRE_BUS 7
  6. #define TEMPERATURE_PRECISION 12
  7.  
  8. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  9. OneWire oneWire(ONE_WIRE_BUS);
  10.  
  11. // Pass our oneWire reference to Dallas Temperature.
  12. DallasTemperature sensors(&oneWire);
  13.  
  14. // arrays to hold device addresses
  15. DeviceAddress zero, jeden, dwa, trzy, cztery, piec, szesc, siedem, osiem, dziewiec, dziesiec, jedenascie;
  16.  
  17. void setup(void)
  18. {
  19. // start serial port
  20. Serial.begin(9600);
  21. Serial.println("Dallas Temperature IC Control Library Demo");
  22.  
  23. // Start up the library
  24. sensors.begin();
  25.  
  26. // locate devices on the bus
  27. Serial.print("Locating devices...");
  28. Serial.print("Found ");
  29. Serial.print(sensors.getDeviceCount(), DEC);
  30. Serial.println(" devices.");
  31.  
  32. // report parasite power requirements
  33. Serial.print("Parasite power is: ");
  34. if (sensors.isParasitePowerMode()) Serial.println("ON");
  35. else Serial.println("OFF");
  36.  
  37. // Assign address manually. The addresses below will beed to be changed
  38. // to valid device addresses on your bus. Device address can be retrieved
  39. // by using either oneWire.search(deviceAddress) or individually via
  40. // sensors.getAddress(deviceAddress, index)
  41. //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
  42. //outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
  43.  
  44. // Search for devices on the bus and assign based on an index. Ideally,
  45. // you would do this to initially discover addresses on the bus and then
  46. // use those addresses and manually assign them (see above) once you know
  47. // the devices on your bus (and assuming they don't change).
  48. //
  49. // method 1: by index
  50. if (!sensors.getAddress(zero, 0)) Serial.println("Unable to find address for Device 1");
  51. if (!sensors.getAddress(jeden, 1)) Serial.println("Unable to find address for Device 2");
  52. if (!sensors.getAddress(dwa, 2)) Serial.println("Unable to find address for Device 3");
  53. if (!sensors.getAddress(trzy, 3)) Serial.println("Unable to find address for Device 4");
  54. if (!sensors.getAddress(cztery, 4)) Serial.println("Unable to find address for Device 1");
  55. if (!sensors.getAddress(piec, 5)) Serial.println("Unable to find address for Device 1");
  56. if (!sensors.getAddress(szesc, 6)) Serial.println("Unable to find address for Device 1");
  57. if (!sensors.getAddress(siedem, 7)) Serial.println("Unable to find address for Device 1");
  58. if (!sensors.getAddress(osiem, 8)) Serial.println("Unable to find address for Device 1");
  59. if (!sensors.getAddress(dziewiec, 9)) Serial.println("Unable to find address for Device 1");
  60. if (!sensors.getAddress(dziesiec, 10)) Serial.println("Unable to find address for Device 1");
  61. if (!sensors.getAddress(jedenascie, 11)) Serial.println("Unable to find address for Device 1");
  62.  
  63.  
  64. // method 2: search()
  65. // search() looks for the next device. Returns 1 if a new address has been
  66. // returned. A zero might mean that the bus is shorted, there are no devices,
  67. // or you have already retrieved all of them. It might be a good idea to
  68. // check the CRC to make sure you didn't get garbage. The order is
  69. // deterministic. You will always get the same devices in the same order
  70. //
  71. // Must be called before search()
  72. oneWire.reset_search();
  73.  
  74. if (!oneWire.search(zero)) Serial.println("Unable to find address for 1");
  75. if (!oneWire.search(jeden)) Serial.println("Unable to find address for 2");
  76. if (!oneWire.search(dwa)) Serial.println("Unable to find address for 3");
  77. if (!oneWire.search(trzy)) Serial.println("Unable to find address for 4");
  78. if (!oneWire.search(cztery)) Serial.println("Unable to find address for 5");
  79. if (!oneWire.search(piec)) Serial.println("Unable to find address for 6");
  80. if (!oneWire.search(szesc)) Serial.println("Unable to find address for 7");
  81. if (!oneWire.search(siedem)) Serial.println("Unable to find address for 8");
  82. if (!oneWire.search(osiem)) Serial.println("Unable to find address for 9");
  83. if (!oneWire.search(dziewiec)) Serial.println("Unable to find address for 10");
  84. if (!oneWire.search(dziesiec)) Serial.println("Unable to find address for 11");
  85. if (!oneWire.search(jedenascie)) Serial.println("Unable to find address for 12");
  86.  
  87.  
  88. // show the addresses we found on the bus
  89. Serial.print("Device 1 Address: ");
  90. printAddress(zero);
  91. Serial.println();
  92.  
  93. Serial.print("Device 2 Address: ");
  94. printAddress(jeden);
  95. Serial.println();
  96.  
  97. Serial.print("Device 3 Address: ");
  98. printAddress(dwa);
  99. Serial.println();
  100.  
  101. Serial.print("Device 4 Address: ");
  102. printAddress(trzy);
  103. Serial.println();
  104.  
  105. Serial.print("Device 5 Address: ");
  106. printAddress(cztery);
  107. Serial.println();
  108.  
  109. Serial.print("Device 6 Address: ");
  110. printAddress(piec);
  111. Serial.println();
  112.  
  113. Serial.print("Device 7 Address: ");
  114. printAddress(szesc);
  115. Serial.println();
  116.  
  117. Serial.print("Device 8 Address: ");
  118. printAddress(siedem);
  119. Serial.println();
  120.  
  121. Serial.print("Device 9 Address: ");
  122. printAddress(osiem);
  123. Serial.println();
  124.  
  125. Serial.print("Device 10 Address: ");
  126. printAddress(dziewiec);
  127. Serial.println();
  128.  
  129. Serial.print("Device 11 Address: ");
  130. printAddress(dziesiec);
  131. Serial.println();
  132.  
  133. Serial.print("Device 12 Address: ");
  134. printAddress(jedenascie);
  135. Serial.println();
  136.  
  137.  
  138. // set the resolution to 12 bit per device
  139. sensors.setResolution(zero, TEMPERATURE_PRECISION);
  140. sensors.setResolution(jeden, TEMPERATURE_PRECISION);
  141. sensors.setResolution(dwa, TEMPERATURE_PRECISION);
  142. sensors.setResolution(trzy, TEMPERATURE_PRECISION);
  143. sensors.setResolution(cztery, TEMPERATURE_PRECISION);
  144. sensors.setResolution(piec, TEMPERATURE_PRECISION);
  145. sensors.setResolution(szesc, TEMPERATURE_PRECISION);
  146. sensors.setResolution(siedem, TEMPERATURE_PRECISION);
  147. sensors.setResolution(osiem, TEMPERATURE_PRECISION);
  148. sensors.setResolution(dziewiec, TEMPERATURE_PRECISION);
  149. sensors.setResolution(dziesiec, TEMPERATURE_PRECISION);
  150. sensors.setResolution(jedenascie, TEMPERATURE_PRECISION);
  151.  
  152. Serial.print("01:");
  153. Serial.print(sensors.getResolution(zero), DEC);
  154. Serial.println();
  155.  
  156. Serial.print("02:");
  157. Serial.print(sensors.getResolution(jeden), DEC);
  158. Serial.println();
  159.  
  160. Serial.print("03:");
  161. Serial.print(sensors.getResolution(dwa), DEC);
  162. Serial.println();
  163.  
  164. Serial.print("04:");
  165. Serial.print(sensors.getResolution(trzy), DEC);
  166. Serial.println();
  167.  
  168. Serial.print("05:");
  169. Serial.print(sensors.getResolution(cztery), DEC);
  170. Serial.println();
  171.  
  172. Serial.print("06:");
  173. Serial.print(sensors.getResolution(piec), DEC);
  174. Serial.println();
  175.  
  176. Serial.print("07:");
  177. Serial.print(sensors.getResolution(szesc), DEC);
  178. Serial.println();
  179.  
  180. Serial.print("08:");
  181. Serial.print(sensors.getResolution(siedem), DEC);
  182. Serial.println();
  183.  
  184. Serial.print("09:");
  185. Serial.print(sensors.getResolution(osiem), DEC);
  186. Serial.println();
  187.  
  188. Serial.print("10:");
  189. Serial.print(sensors.getResolution(dziewiec), DEC);
  190. Serial.println();
  191.  
  192. Serial.print("11:");
  193. Serial.print(sensors.getResolution(dziesiec), DEC);
  194. Serial.println();
  195.  
  196. Serial.print("12:");
  197. Serial.print(sensors.getResolution(jedenascie), DEC);
  198. Serial.println();
  199.  
  200.  
  201. }
  202.  
  203. // function to print a device address
  204. void printAddress(DeviceAddress deviceAddress)
  205. {
  206. for (uint8_t i = 0; i < 8; i++)
  207. {
  208. // zero pad the address if necessary
  209. if (deviceAddress[i] < 16) Serial.print("0");
  210. Serial.print(deviceAddress[i], HEX);
  211. }
  212. }
  213.  
  214. // function to print the temperature for a device
  215. void printTemperature(DeviceAddress deviceAddress)
  216. {
  217. float tempC = sensors.getTempC(deviceAddress);
  218. Serial.print("Temp C: ");
  219. Serial.print(tempC);
  220.  
  221. }
  222.  
  223. // function to print a device's resolution
  224. void printResolution(DeviceAddress deviceAddress)
  225. {
  226. Serial.print("Resolution: ");
  227. Serial.print(sensors.getResolution(deviceAddress));
  228. Serial.println();
  229. }
  230.  
  231. // main function to print information about a device
  232. void printData(DeviceAddress deviceAddress)
  233. {
  234. //Serial.print("Device Address: ");
  235. printAddress(deviceAddress);
  236. Serial.print(" ");
  237. printTemperature(deviceAddress);
  238. Serial.print(" ");
  239. // Serial.println();
  240. }
  241.  
  242. /*
  243. * Main function, calls the temperatures in a loop.
  244. */
  245. void loop(void)
  246. {
  247.  
  248. Serial.println();
  249. // call sensors.requestTemperatures() to issue a global temperature
  250. // request to all devices on the bus
  251. Serial.print("Requesting temperatures:");
  252. sensors.requestTemperatures();
  253. Serial.print("DONE ");
  254.  
  255. // delay(9000);
  256.  
  257.  
  258.  
  259. // print the device information
  260. printData(zero);
  261. printData(jeden);
  262. printData(dwa);
  263. printData(trzy);
  264. printData(cztery);
  265. printData(piec);
  266. printData(szesc);
  267. printData(siedem);
  268. printData(osiem);
  269. printData(dziewiec);
  270. printData(dziesiec);
  271. printData(jedenascie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement