проблема с большим количеством датчиков ds18b20
- Войдите на сайт для отправки комментариев
Пт, 05/12/2014 - 14:07
Здравствуйте, у меня проблема с монитором порта при использовании 20 датчиков ds18b20, монитор ничего не показывает, но если количество датчиков в программном коде уменьшить до 17, все работает отлично. Буду благодарен, если кто поможет с данной проблемой, прилагаю программный код на 20 датчиков, может проблема в компьютере потому что делаю с нетбука, при использовании этого кода через убунту при 18 датчиках монитор работал исправно, если больше, то либо пусто, либо символы непонятные
#include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 10 #define TEMPERATURE_PRECISION 9 // 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 Thermometer1, Thermometer2, Thermometer3, Thermometer4, Thermometer5, Thermometer6, Thermometer7, Thermometer8, Thermometer9, Thermometer10, Thermometer11, Thermometer12, Thermometer13, Thermometer14, Thermometer15, Thermometer16, Thermometer17, Thermometer18, Thermometer19, Thermometer20; 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(Thermometer1, 0)) Serial.println("Unable to find address for Device 0"); if (!sensors.getAddress(Thermometer2, 1)) Serial.println("Unable to find address for Device 1"); if (!sensors.getAddress(Thermometer3, 2)) Serial.println("Unable to find address for Device 2"); if (!sensors.getAddress(Thermometer4, 3)) Serial.println("Unable to find address for Device 3"); if (!sensors.getAddress(Thermometer5, 4)) Serial.println("Unable to find address for Device 4"); if (!sensors.getAddress(Thermometer6, 5)) Serial.println("Unable to find address for Device 5"); if (!sensors.getAddress(Thermometer7, 6)) Serial.println("Unable to find address for Device 6"); if (!sensors.getAddress(Thermometer8, 7)) Serial.println("Unable to find address for Device 7"); if (!sensors.getAddress(Thermometer9, 8)) Serial.println("Unable to find address for Device 8"); if (!sensors.getAddress(Thermometer10, 9)) Serial.println("Unable to find address for Device 9"); if (!sensors.getAddress(Thermometer11, 10)) Serial.println("Unable to find address for Device 10"); if (!sensors.getAddress(Thermometer12, 11)) Serial.println("Unable to find address for Device 11"); if (!sensors.getAddress(Thermometer13, 12)) Serial.println("Unable to find address for Device 12"); if (!sensors.getAddress(Thermometer14, 13)) Serial.println("Unable to find address for Device 13"); if (!sensors.getAddress(Thermometer15, 14)) Serial.println("Unable to find address for Device 14"); if (!sensors.getAddress(Thermometer16, 15)) Serial.println("Unable to find address for Device 15"); if (!sensors.getAddress(Thermometer17, 16)) Serial.println("Unable to find address for Device 16"); if (!sensors.getAddress(Thermometer18, 17)) Serial.println("Unable to find address for Device 17"); if (!sensors.getAddress(Thermometer19, 18)) Serial.println("Unable to find address for Device 18"); if (!sensors.getAddress(Thermometer20, 19)) Serial.println("Unable to find address for Device 19"); // 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(); // assigns the first address found to insideThermometer //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer"); // assigns the seconds address found to outsideThermometer //if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer"); // show the addresses we found on the bus Serial.print("Device 0 Address: "); printAddress(Thermometer1); Serial.println(); Serial.print("Device 1 Address: "); printAddress(Thermometer2); Serial.println(); Serial.print("Device 2 Address: "); printAddress(Thermometer3); Serial.println(); Serial.print("Device 3 Address: "); printAddress(Thermometer4); Serial.println(); Serial.print("Device 4 Address: "); printAddress(Thermometer5); Serial.println(); Serial.print("Device 5 Address: "); printAddress(Thermometer6); Serial.println(); Serial.print("Device 6 Address: "); printAddress(Thermometer7); Serial.println(); Serial.print("Device 7 Address: "); printAddress(Thermometer8); Serial.println(); Serial.print("Device 8 Address: "); printAddress(Thermometer9); Serial.println(); Serial.print("Device 9 Address: "); printAddress(Thermometer10); Serial.println(); Serial.print("Device 10 Address: "); printAddress(Thermometer11); Serial.println(); Serial.print("Device 11 Address: "); printAddress(Thermometer12); Serial.println(); Serial.print("Device 12 Address: "); printAddress(Thermometer13); Serial.println(); Serial.print("Device 13 Address: "); printAddress(Thermometer14); Serial.println(); Serial.print("Device 14 Address: "); printAddress(Thermometer15); Serial.println(); Serial.print("Device 15 Address: "); printAddress(Thermometer16); Serial.println(); Serial.print("Device 16 Address: "); printAddress(Thermometer17); Serial.println(); Serial.print("Device 17 Address: "); printAddress(Thermometer18); Serial.println(); Serial.print("Device 18 Address: "); printAddress(Thermometer19); Serial.println(); Serial.print("Device 19 Address: "); printAddress(Thermometer20); Serial.println(); // set the resolution to 9 bit sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer3, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer4, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer5, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer6, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer7, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer8, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer9, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer10, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer11, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer12, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer13, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer14, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer15, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer16, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer17, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer18, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer19, TEMPERATURE_PRECISION); sensors.setResolution(Thermometer20, TEMPERATURE_PRECISION); Serial.print("Device 0 Resolution: "); Serial.print(sensors.getResolution(Thermometer1), DEC); Serial.println(); Serial.print("Device 1 Resolution: "); Serial.print(sensors.getResolution(Thermometer2), DEC); Serial.println(); Serial.print("Device 2 Resolution: "); Serial.print(sensors.getResolution(Thermometer3), DEC); Serial.println(); Serial.print("Device 3 Resolution: "); Serial.print(sensors.getResolution(Thermometer4), DEC); Serial.println(); Serial.print("Device 4 Resolution: "); Serial.print(sensors.getResolution(Thermometer5), DEC); Serial.println(); Serial.print("Device 5 Resolution: "); Serial.print(sensors.getResolution(Thermometer6), DEC); Serial.println(); Serial.print("Device 6 Resolution: "); Serial.print(sensors.getResolution(Thermometer7), DEC); Serial.println(); Serial.print("Device 7 Resolution: "); Serial.print(sensors.getResolution(Thermometer8), DEC); Serial.println(); Serial.print("Device 8 Resolution: "); Serial.print(sensors.getResolution(Thermometer9), DEC); Serial.println(); Serial.print("Device 9 Resolution: "); Serial.print(sensors.getResolution(Thermometer10), DEC); Serial.println(); Serial.print("Device 10 Resolution: "); Serial.print(sensors.getResolution(Thermometer11), DEC); Serial.println(); Serial.print("Device 11 Resolution: "); Serial.print(sensors.getResolution(Thermometer12), DEC); Serial.println(); Serial.print("Device 12 Resolution: "); Serial.print(sensors.getResolution(Thermometer13), DEC); Serial.println(); Serial.print("Device 13 Resolution: "); Serial.print(sensors.getResolution(Thermometer14), DEC); Serial.println(); Serial.print("Device 14 Resolution: "); Serial.print(sensors.getResolution(Thermometer15), DEC); Serial.println(); Serial.print("Device 15 Resolution: "); Serial.print(sensors.getResolution(Thermometer16), DEC); Serial.println(); Serial.print("Device 16 Resolution: "); Serial.print(sensors.getResolution(Thermometer17), DEC); Serial.println(); Serial.print("Device 17 Resolution: "); Serial.print(sensors.getResolution(Thermometer18), DEC); Serial.println(); Serial.print("Device 18 Resolution: "); Serial.print(sensors.getResolution(Thermometer19), DEC); Serial.println(); Serial.print("Device 19 Resolution: "); Serial.print(sensors.getResolution(Thermometer20), 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); Serial.print(" Temp F: "); Serial.print(DallasTemperature::toFahrenheit(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.println(); } void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); Serial.println("DONE"); // print the device information printData(Thermometer1); printData(Thermometer2); printData(Thermometer3); printData(Thermometer4); printData(Thermometer5); printData(Thermometer6); printData(Thermometer7); printData(Thermometer8); printData(Thermometer9); printData(Thermometer10); printData(Thermometer11); printData(Thermometer12); printData(Thermometer13); printData(Thermometer14); printData(Thermometer15); printData(Thermometer16); printData(Thermometer17); printData(Thermometer18); printData(Thermometer19); printData(Thermometer20); delay(5000); }
Вы что про циклы не слышали? :)
У библиотеки OneWire есть пример опрашивающий все DS18B20 на шине, попробуйте его. Он работает?
Извините, ошибся, при 16 датчиках работает исправно, при использовании 17, датчики начинают показывать неправильную температуру
Спасибо большое, не слышал)
Поразительно, ещё паруд ней наза ничего ненайти было про множество датчиков на одной шине и на тебе и мне помогли и тут код шикарный, скопипастил конечное
http://arduino.ru/forum/proekty/dva-datchika-ds18b20-i-vyvod-na-lcd
Поразительно, ещё паруд ней наза ничего ненайти было про множество датчиков на одной шине и на тебе и мне помогли и тут код шикарный, скопипастил конечное
Так это родной пример из библиотки OneWire. Сегодня пятница все добрые :).