I have just received my second Arduino so I can continue developing the temperature monitoring system.
My first attempt at using 2 Dallas DS18B20 sensors failed. It took way longer than it should have with the bread board to get them reading correctly.
The first step to using two sensors is to identify the ROM code with each chip. To do this, I connect one – then load the sketch from HackTronics that gets the ROM address. I then plug that address into a logging sketch and call each chip individually.
I have soldiered the sensors to 50′ lines with telephone jacks on the end. Then I built a small arduino shield that is wired to telephone plug with a 3 port splitter on it. It was a ton of fun testing – one in the freezer, one on the heat vents and one ambient temperature. The sensors seem to be slow to react to temperature changes (a couple minutes) but extremely accurate once the temperature has stabilized.
That completed the easy part. The hard part was writing the code. I need this to be expandable as I add future sensors so I wrote a simple Task Scheduler that allows me create tasks, then assign them a time to run. Once they’ve run, they re-assign themselves their next run. So far so good.
I also don’t want to connect to the server every time a sensor is checked. I’d like to be able to grab a few data points, then, try to log them. If the log fails, continue trying but also continue grabbing new data points (as memory allows).
I was concerned that connecting to the server might take a few seconds or even minutes at times, and might therefor cut into processor time that could be used logging events. Since I had no idea how busy the processor would actually be doing all this, I built each task to log the time it takes, then every time period (I use every minute) I calculate the processor usage. I add this to my data logging object which will log this to the server with my other data.
For a guy that doesn’t know C programming this was quite a challenge. I completely realize how I was taking “Strings” for granted in other programming languages. Simply adding together two sets of characters in C can be quite a task. My first attempt failed due to poor documentation on the Pachube website. I planned to have Pachube take a list of datapoints in the format
<feed_id>,<stream_id>,<timestamp>,<value>
I finally got this mostly working, but while using the debugging data from Pachube I realized that feature is not yet supported. My only direct option is to log using a simple <timestamp>,<value> set. This completely changes the way I have to store my data on the Arduino, so that put me back to the drawing board. The next obstacle was getting the timestamp on the arduino correct. Since the Arduino can only keep time by counting seconds, it has to know what time it was initialized. Since my device will always be connected, I plan to have it update it’s clock using Time Services. The problem here was that the Time examples that Arduino provided all used the old Arduino Ethernet libraries. So after many hours of debugging and updating that, I finally got that working.
Earlier this week, I though I had everything working. Then the device would freeze at seemingly random intervals. I thought the problem was memory related so I spent hours building functions to track memory usage to see if I had a leak.
Tonight, I finally figure out the problem isn’t mine – it’s the Time library functions. Every couple minutes the clock tries to resync itself, and for some reason it’s freezing during that process. More on that once I get that worked out!