DS18B20 help please

ok guys, I'm trying to add support for the DS18B20 one wire temp sensor.

I can get it working perfectly using the example code from http://www.arduino.cc/playground/Learning/OneWire, however when I try furring the code into my sketch it fails on ds.select(addr); giving the ever useful expected unqualified-id before numeric constant error...

After much fiddling I've made no progress.

The program is too bit to post directly on the forum, so I've hosted the file here -> http://www.beigematchbox.co.uk/forums/arduino/ipod/in_car_controller_with_temp/in_car_controller_with_temp.pde

The offending function is at the bottom void getTemp(), it is only called from void loop()

Any ideas? I'm stumped :-[

Beige, It took me a bit but... may I suggest that when you #define a symbol, that you UPPERCASE that symbol so that it does not "look" like a variable or class member.

Case in point:

define select 3

The preprocessor for C and C++ (and thus the Arduino) literally does a string replace of select with 3 throughout the source code. When you call ds.select(addr) the compiler is actually trying to compile ds.3(addr), which doesn't make much sense. :-)

Some other suggestions if I may: 1) move your display and iPod interface functions into separate source files and create appropriate header files so that those functions can be accessed by #include'ing those .h files. 2) After reading the scratchpad memory from the temp. sensors, it might be a good idea to do a CRC calculation on those bytes. 3) Two's complements is how numbers are represented so there's no need to XOR with 0xffff and add one -- just do this: TReading = -TReading; 4) Try to put all your #include's at the top of the file, for readability. 5) In your lineWrap() function, this will never work:

else if (state == false){ if (state == true){

Since the if () that matches the above else already tests the value of state, just remove the above if statements (or the second one at the very least).

6) In getTemp(), there's no need for performing a CRC calculation on constant data.

Good luck with your project!

-Rusty-

I love you :-*

so obvious now I look at it, sometimes fresh eyes spot things you just can't see

I'll go through and change the other bits you have suggested and post the updated code for completeness.

Thanks you for your time

Right, heres the working code - http://www.beigematchbox.co.uk/forums/arduino/ipod/in_car_controller_with_temp/in_car_controller_with_temp_working.pde

Still got some learning to do to get the LCD and iPod functions in an external file, but I'll do that before I finish 8-)

Attaboy! It's looking good!

You didn't have to change the #define "select" except to uppercase it so that it wouldn't conflict with the OneWire object's method but if it works for you, go for it! Keep in mind that symbol names in C/C++ are case-sensitive so BOO is different from boo or bOO or BoO.

That compiler error message continues to intrigue me. Glad I could help!

-Rusty-

After going through the code I found "#define select 3" was legacy and was missed on my last pruning run, so that why I got rid

Anyway, it's all integrated into the program now and has it's own menu entry, happy days 8-)