1-wire Temp Sensor / Spin code Help
Wookie
Posts: 27
As some of you may have been following, I am working on reading in several 1-wire DS18B20 temperature sensors along with GPS data. I am on the home stretch here, but I am having trouble implementing one last feature. In short, the ugly code posted below takes in GPS data as well as temp sensor data and sends it out serially in a comma separated format to a PC. I have everything working except getting the three temperature sensor readings independently all on one line. In an effort to fix each sensor reading to one place in the output, I decided that I would enter the sensor serial codes as constants at the beginning of the program and define them as constants so that when I make the conversions, I am sure that my output data is properly ordered. The trouble is that with current code, I can't get the output data to display all three sensor data readings at once. Instead, the temperature reading for one sensor fills all the locations of the temp data for a few outputted lines before another sensor data rotates in place. This goes on and on like this:
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
If I change each of the sensor serial codes to something non-matching, I drop that sensors reading in the loop, so I know that feature is working. I added several temp conversion routines at the end to try and avoid this, but no luck.
Could someone please look at my admittedly sloppy code and let me know what they think (I have reposted a cleaner version of the code later in this thread)? I have a deadline approaching on Monday, so REALLY appreciate any help I can get!
Thanks!!!!
Joe
Post Edited (Wookie) : 1/11/2010 6:14:56 AM GMT
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
If I change each of the sensor serial codes to something non-matching, I drop that sensors reading in the loop, so I know that feature is working. I added several temp conversion routines at the end to try and avoid this, but no luck.
Could someone please look at my admittedly sloppy code and let me know what they think (I have reposted a cleaner version of the code later in this thread)? I have a deadline approaching on Monday, so REALLY appreciate any help I can get!
Thanks!!!!
Joe
Post Edited (Wookie) : 1/11/2010 6:14:56 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
Your Main program should call up the SAME readTemperature Method each time the Main needs to read a temperature from a new device.
The way your program is working now, I think, is that each called up Method of readTemperature is starting the sensor read process all over again and thus your system is seeing only the first/same device on the line but doing so 3 times in a row.
I hope that helps.
I added the 3 separate read statements, as I was trying to generate 3 separate output variables. I had everything on a single read statement, but the problem still exists.
I figured it didnt matter though, as I needed to call the routine 3 separate times anyway to read the 1-wire bus for each sensor.
Of course, I may be missing something with the read statement operation as you suggest.
Maybe the easier thing to do here is to ask if anyone has a routine or suggestion as to how to read multiple devices on a 1-wire network that will generate 3 variables that I can
call on to convert to degrees F and then post them as a string to my CSV output statement.
I think I got those hidden spaces.
I guess my space key got stuck sometime during my coding.....sorry.
take a look at Micah Dowty's SPIN version of the 1-wire routine.
obex.parallax.com/objects/342/
If I remember correctly, this has a demo in it that reads the temperature on up to 8 DS18B20s on a single wire and will display it on a VGA or TV.
I think it shows how to do exactly what you need.
Sorry, but I'm away from the computer that I have my own code on, otherwise I'd post it for you, but my own stuff was derived almost verbatim from Dowty's code.
I hope that helps,
Mark
I've tried to paste the relevant chunks of code that demonstrate reading multiple DS18B20's on one wire.
This stuff was extracted from a giant dirty snow ball of code I use in one of my programs, so it's very possible I've left out something.
Hopefully, it might help you figure out how to read all of your DS18B20's.
Post Edited (ElectricAye) : 1/10/2010 11:52:09 PM GMT
First off, thank you for taking the time to post this code up for me. I see how you are reading in the data from the sensors, and am generally doing the same thing as you. For whatever reason, I keep getting other sensor data bleeding into all my declared variables. As I watch the terminal program,
the sensor data still writes as such...
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,73.5, 73.5, 73.5
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,80.0, 80.0, 80.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
.....,40.0. 40.0. 40.0
If I change a single constant containing a sensor serial number so that it doesnt match, the output data will then rotate on the remaining two sensors. If I change all but one sensor to a non-matching serial number, I then get the data for the remaining sensor in the exact place specified in output dataset.
An example is if the temp for air is 80F and the location for the air temp data is in the last position of the output string, my output will look like this:
,,80
If I then change the serial number in the constants to match another sensor, say the water temp and that is reading 100F and is supposed to show up in the second to last location of the output string
,100,
This confirms several things to me. I am correctly identifying each sensor by serial number, and that when each sensor is queried individually, the data shows up at the correctly defined variable location.
I am totally out of ideas at this point. I have cleaned up the code and will post it below. If anyone sees an error, please let me know. Thanks!!!
I'm not sure, but maybe this:
should be this:
I think it might need that +4 to indicate the proper chunk of the LONG it is looking for.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Post Edited (ElectricAye) : 1/11/2010 1:57:08 PM GMT
I wish I were better at programming and could pinpoint this problem for you but so far the only odd thing I see is that you are using the same local variables in this:
as you are in this:
I don't know if that could create some kind of memory problem or not.
I must admit, I'm baffled, too.
Wookie,
the only other thing I can suggest at this point is to place Debug statements every once in a while and insert some fake data, fake temperature readings, etc. and try to sniff out where the program is taking a wrong turn.
Sorry I can't help you more than that.
Maybe one of the Forum software gurus can jump on this and take a look???
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Ill give your idea about inserting dummy variables along the way. In either case, I wanted to thank you for all of your help over the last couple of days! I really appreciate it!
I may be wrong but it seem to me the
may not always get the correct sensor. In your case this may not be the problem because for the devices on the bus none of the upper or lower halves
of the 64-bit address match.
AirT = $8F917A28
WaterT = $8F6E6328
FuelT = $8F9ACB28
But it seems to me to be safe (and to rule this possible problem out) you need to check the upper and lower halves of the address against AirT, WaterT, FuelT.
I'm not sure about this. It's possible that your code above compares 8 bytes but when something is called as a long (as in long[noparse][[/noparse]addr]) I would suspect it only
checks 4 bytes. You may need to split up your constants into AirT_Upper=$8F91 and AirT_Lower=$7A28 then check against both before reading the temp:
if ( (long[noparse][[/noparse]@addr][noparse][[/noparse]0] == AirT_Upper ) AND (long[noparse][[/noparse]@addr] == AirT_Lower) )
RAirT := readTemperature1(addr)
I'm not sure this is your problem or if what I've written is even correct, but it might be worth some consideration if you haven't found the problem.
Best of luck.
Peter