Help a nubi please

Hi.
Just purchased n ATMEGA328 to automate a BIO reactor process.
I am having some probs sorting some code out.
Anyone help with the scripts to cure the following??? Please

1st. Can I assign all the digital pins as outputs in one command line.

2nd. I wish to put thermisters on analogue pins 0 and 1 to check the temperature of the oil and when it reaches a set temp carry on with the process. (thermisters are resistors that change resistance with temperature).
I can not work out the script for this, also how do you differenciate between analogue pins 0 - 5 and digital pins 0 - 5??

3rd. I want to use analogue pins 2 - 4 as switch inputs again I can not work out how to do this.

Any HEXPERTS out there?????
Regards John

  1. As a noob, no not easily.

  2. & 3) There is no need for you to differentiate between analogue and digital pins - "analogRead" doesn't work on digital pins.
    If you want to use the analogue pins as digital, they're pins 14..19, so set the pinMode for 16..18 (analogue 2..4)as INPUT.

Thanks Mate
I think I have worked it all out now.
Just completed about 5 A4 pages of code which complied to about 1.6k.
Just need to test it.

Just another question ref my thermister.

It will be wired between +5 and analog pin 0 with say 10k pot to ground how do I know what the actual input reading will be.
I know it will be between 0 and 5v but when I am reading this pin and comparing it do I use the actual voltage, say 4.2 or is it a binary number between say 0 and 1024????
regards John

or is it a binary number between say 0 and 1024?

Not quite:-
It will be a number between 0 and 1023

Just need to test it.

best tip you will ever get. Don't write 5 pages of code and then test it, you will never get it to work. Just write a few lines of code and then test it. Then when that does what you want write some more and test it again. Never write more than 30 lines of code without testing it. That way it is easy to find out where you are going wrong, and beleve me you will be.

Hi Mike
I take your point, I did do compilations as I went along and did have lots of probs to sort, (mostly with { } )

I just wanted to get the basic structure of all the sequences I needed.

At the moment the compiler likes it I am now getting down to the details.

Basically I need to test the return from my thermister and if the temp is lower or greater than 90c then I need to start another sequence.

My problem is I dont know how to code the thermister input.

What I have done so far is read the input and "if" lower than 1000 (a guess I assigned to a threshold) then "goto" the read again.
"else" carry on with the next sequence.

Are you saying that the input will read between 0 and 1023 for 0 to 5v. Is this implied or do I have to define it?
If it is implied then I can read my input at 90c with a DVM and assign the value, ie: 2.5v would be 512.

am I close or way off base???? Is there a way to read the input and print it somewhere, say the computer I am using to write the program.??
regards John

Just found the programming manual in the playground.

All should be clear from here on.
Thanks for all your help..
John

you should also find the data sheet for the thermister, it will list the tolerances along with a conversion formula that you can use in the code to convert it to the actual temp in C or F.

I use http://www.alldatasheet.com/ for most projects.
and http://www.findchips.com/ for hard to find electronic parts.

Thanks Buda, most helpfull
John

when starting out with a sensor i find it helpful to just stream the reading back to the pc over serial to see what the range and behaviour is like.

Hi Bill.
Thanks for that, once I found out how these things work I did infact do just that.

I also used a cup of boiling water and a thermometer and plotted the the readings as the water cooled.

I like the idea of using a table to print the actual/approximate temperature but have not figured out how to do that as yet.

I plan to use an old Panasonic Toughbook as the computer to drive my Reactor (use the 5volts from the USB) and print out messages and readings as the program progresses.
The serial command is just brilliant for this.
Regards John