Thank you for your answer.
ABout printing, Serial Monitor doesn't print any information after the attempt to read bytes from the device.
Here is the code I'm using now for testing(It's not that good as I want to, but for the testing purposes it works well):
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <string.h>
#include <stdio.h>
#define LENGTH 32
LiquidCrystal lcd(8, 11, 9, 4, 5, 6, 7);
OneWire ds(4);
int inputBtn = 0;
char buffer[LENGTH];
enum States{Stop = 0, Start} states;
taskLoop(ReadButton)
{
checkBtn();
delay(50);
}
taskLoop(ReadTemperature)
{
if(states == Start)
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius;
if ( !ds.search(addr)) {
lcd.clear();
lcd.print("No more addresses");
ds.reset_search();
delay(250);
return;
}
if (OneWire::crc8(addr, 7) != addr[7]) {
lcd.clear();
lcd.print("CRC is not valid!");
return;
}
// the first ROM byte indicates which chip
//we don't need it. Since the device's type_s = 0
switch (addr[0]) {
case 0x10:
//old DS1820
type_s = 1;
break;
case 0x28:
//Chip = DS18B20;
type_s = 0;
break;
case 0x22:
//Chip = DS1822;
type_s = 0;
break;
default:
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
//The app will never pass here
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
ToString(celsius);
lcd.clear();
lcd.print(buffer);
}
delay(100);
}
void ToString(float num)
{
memset(buffer, 0, LENGTH);
sprintf(buffer, "%.2f", num);
}
void checkBtn()
{
inputBtn = analogRead(0);
if(inputBtn >= 710 && inputBtn < 900)
{
states = Start;
}
else if(inputBtn >= 470 && inputBtn < 700)
{
states = Stop;
lcd.clear();
lcd.print("Stopped");
}
}
void setup()
{
lcd.begin(16, 2);
lcd.home();
lcd.print("Greetings!");
createTaskLoop(ReadButton, NORMAL_PRIORITY);
createTaskLoop(ReadTemperature, NORMAL_PRIORITY);
}
void loop()
{
//TO DO: add some code
}
How could I know the Arduino gets stuck there? I put the lcd.print("TEST"); delay(5000); before bytes reading and lcd.print("ABC"); delay(5000); after reading. So, the first one will be printed. But the second one will not be printed, even after 5 seconds of waiting. Also I've tried to do it without delays. Result is the same. I've tried to do it with a serial monitor - same result as before.
I really appreciate, if somebody will show me the working code for the same configuration: Arduino Uno 1.03 + DS18B20 + DuinOS v. 0.4 alpha.
I know, Arduino all alone works perfectly with onewire, but I need a bit more for my small project.