Programming Language?

Oh yes! Everything you ever wanted to know about equipment or ask about equipment, this is the place to be! Share photos or ideas about equipment here.

Moderator: Post Moderators

User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

dhempy wrote:So did the LED light up too? Over what period are those temp readings (maybe you could add a timestamp to the Serial.print statements.

How are you connected to the PC .. serial (RS232?)

Dan
This code is just to see if I could get the temp sensor to read and then do something with it, so it's pretty ugly code and probably not even what I'll use for a basis. T

here is a built-in LED on pin13 on this version of the Arduino and yes it lights to indicate the solenoid is on.

That output is at 1-second sampling. This line:

Code: Select all

delay(1000);     // maybe 750ms is enough, maybe not 
  // we might do a ds.depower() here, but the reset will take care of it. 

delays the second, so that's the only delay in the code. The DS18B20 is very fast. The temperature was changed by just grabbing it between my fingers for a few seconds, you can see how fast it reacts. The resolution is scalable but default is 12 bit or 0.0625*.

I'm still going to play with the thermistors I have just to see which I like better and which method has less code overhead. Tonight I'll try breadboarding that up.

One idea I like about these DS chips is that 8 can be run on the same pair of wires. So I could make a temp probe for the mash that could have a sensor every 2" and get an average of the mash instead of reading a single hot or cold spot.

Oh and this version of the Arduino uses a USB interface which also powers it up. 8)
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

Dan, asctime won't work on the Arduino because it doesn't have a CMOS clock that keeps the time. Also, this is an embedded device with extremely limited system resources. Even linking in parts of the standard C library adds size to the binary and you can run out of space pretty quickly. I wanted to use sprintf in my code, but it just wasn't practical. You've only got 14k available for program memory. (This adds a kind of fun challenge, optimize for size.)

The PC connection is serial over USB. Part of the arduino board is a USB to Serial conversion, and like BB said the USB can also power the board.

I am a bit surprised at how much code it takes to read the temp sensor, but it seems pretty straightforward. The thermistor will be easier, though it will probably require a lookup table (eating memory) or fancy math (kind of slow, but that's probably not an issue). You could also have one wire with sensors for your mash tun, hot liquor tank and kettle if you wanted. 8 sensors in the mash seems like a bit of overkill. :)
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

brahn wrote:I am a bit surprised at how much code it takes to read the temp sensor, but it seems pretty straightforward. The thermistor will be easier, though it will probably require a lookup table (eating memory) or fancy math (kind of slow, but that's probably not an issue). You could also have one wire with sensors for your mash tun, hot liquor tank and kettle if you wanted. 8 sensors in the mash seems like a bit of overkill. :)
I plan to read temp on several different things, but I'll probably use a single pin for each group of sensors. So the HLT and the MLT would each be on their own pin and if I did decide to use more than a single sensor in a single vessel, I'd run them on the same pin. Otherwise wiring the whole thing and being able to break it all down would be pretty much a pain in the ass. Don't worry, the 8 sensors in the mash was for demonstrative purposes. :wink: While $4.25 per sensor isn't a lot of money, it'd still add up quick!
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

So the trick would be to grab the data from the arduino in in a PC program and then add the timestamp, right? The PC program would just look for data from the USB port?!?

Dan
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

[quote=dhempy]So the trick would be to grab the data from the arduino in in a PC program and then add the timestamp, right? The PC program would just look for data from the USB port?!?

Dan[/quote]

Right!

BB, I didn't realize how expensive those DS1820s are, wow! Maybe you could use those where you want multiple sensors like the MLT and use simpler/cheaper sensors in the HLT, kettle, etc. Also, if you're using thermistors and you want to use a lookup table remember that the arduino only has 1K of ram available and your table + and strings and variables your program uses all need to fit in there.
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

Yeah I know there's not a lot of room there for code. I think the thing to do might be to code the sketch to do all the comparisons in the sensor's native output since the serial output will be to a PC and not a display. Then have the PC do the math and/or lookups. That way no space is wasted on conversions or lookup tables.

The sample sketch I just downloaded and compiled to read a 10K thermistor with a lookup table too like 4400+ bytes.
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

Well, there's 2 issues: code size and data size. The code size can be up to 14k, and at 4400 you've got plenty of room left. The data size is only 1k and that can get eaten up pretty quickly by strings and arrays. You might be able to get away with keeping the lookup table in the 'code' area by using the PROGMEM keyword. The problem with using the thermistor's value without converting it is that it's not linear. You could do that with DS1820's or LM34's though.
User avatar
jward
Posts: 2103
Joined: Mon Feb 21, 2005 10:22 pm
Location: Irvine, CA
Contact:

Post by jward »

Since you are already doing the Dallas protocols you might look at Dallas' other devices. They will run on the expensive side like the DS1820s do, but may help with storage or such if you get into a big enough pinch.
Image
User avatar
brahn
Site Admin
Posts: 1799
Joined: Wed May 31, 2006 5:12 pm
Location: Tustin, CA
Contact:

Post by brahn »

Yea, there's certainly other options for memory if you really start hitting a limit.

BB, are you going to the brewday this weekend? I've got a few extra LM34's sitting around that I can bring if you want to try one of those too. Maybe I'll even bring the laptop and arduino and we can really geek out. :)
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

Well, I was planning on brewing and trying out my new Boilermaker mashtun. But maybe I'll just go over there. I'll have to see as the weekend gets closer.

It looks like I might be able to get DS18B20s for a little less on eBay. It's not like I need 20 of them or anything.
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

OK, so what do I do with this?

I bought several thermistors to play with. The first was a known brand 10K thermistor. The other two were unknown, however, after looking at the 10K thermistor and taking note that it looked very similar to one of the unknown thermistors only smaller, I quickly realized the pretty colored bands were standard resistor color coding and the unknown thermistor is a 1K thermistor. (I'm not as stupid as I look).

So, I breadboarded the 10K thermistor with a 10K resistor to make a voltage divider and the 1K thermistor with a 1K resistor. Here's the output reading the raw port:

Code: Select all

Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 532
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 530
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 524    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 531
Raw Reading 1K thermistor 523    Raw Reading 10K thermistor 531
Sampled at .5 seconds. Obviously they are very close and they both react proportionately to temp changes.

What do I do with this? :oops: (Here's where I'm every bit as stupid as I look) I know that the analog pins have 1023 resolution and so 0 volts = 0 and +5v = 1023. But how do I convert this to degrees F? I also know that the thermistors are non-linear
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

Did you find anything on the web?

What about this or this?
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

I found a site that gave a pretty simple method for calibrating a thermistor and logging its output for my use. The idea is to hook the thermistor up to the Arduino and have it spit out the output just like I displayed above. Next, log as many points as you can against a calibrating thermometer. So for example above, 531 = 79.8*F. Get as wide a temperature swing as you can and as many points as possible.

Next, pliug all the numbers into Excel and Scatter graph them. Ask Excel to plot the most logical line through the scatter graph and then ask it for the formula it came up with. Use that Formula in the Arduino sketch to convert the analog output to a readable temperture.

Seems like work with lots of room for error, but without solid specs on the thermistor, seems like the best way to go. I'm going to try it tonight and see if I like the results but I'm still leaning towards the DS18B20's since they are already calibrated. They are also smaller than the thermistors I have and will fit in a smaller diameter probe.
dhempy
Posts: 2357
Joined: Mon May 09, 2005 4:10 pm
Location: Santa Rosa Valley, CA

Post by dhempy »

Derrin:

Hi from Iowa!

This thread is directly attributable to your new sig line ! :lol:

Good luck with the experiment!

Dan
User avatar
backyard brewer
Posts: 3774
Joined: Fri Feb 18, 2005 5:38 pm
Location: Orange County, CA
Contact:

Post by backyard brewer »

Just an update: I'm still playing around with this. Last night I soldered up a single 2pr cable with a digital DS18B20 and one of the 1K thermistors I have. I have a lot of these thermistors so I really wanted to learn about them and see if I can use them.

So now I have one of each sensor at the end of a single cable. One is reading actual *F and the other returning a 1024 step number relating to temperature. I stuck them in the oven and captured the output of both, so I was able to use the 18B20 to calibrate and give be a side-by-side correlation to the thermistor output. With this I can either build a lookup table or use the method above to calculate the formula.
Post Reply