NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Reading more than one Temp
January 28, 2011 by billwis |
I am new to NerdKits and C programming but not electronics. I have run the tempsensor project and did some minor code changes that worked. My problem is getting more than one sensor to work. I have tried all the suggestions on the forum and get nowhere. I only need to get that little light in my head to go on with this C language. Is there a sample from start to finish that I could use. I did some Basic programming with the PIC years ago and it was simple. Thanks
BillWis |
---|---|
January 28, 2011 by Ralphxyz |
Hi BillWis, welcome, had you searched the Nerdkit forum for "multi sensor"? You would even find my multi sensor code, which might not be very elegant but does work. This is just modified tempsensor project code. Ralph |
January 29, 2011 by billwis |
Thanks for getting back so fast. I have tried many different examples but have had no luck getting things to run. Would you have the code for adc1 and adc2 I could copy and work with? I have no idea what I am doing wrong. bill |
January 29, 2011 by hevans (NerdKits Staff) |
Hi billwis, The code that Mike wrote in the post that Ralph linked you too is pretty much as bare bones as you can get for reading two sensors. The trick is to understand that the ADC input is multiplexed across the six different possible inputs. You can only read from one at a time and the one you are reading from is determined by the ADMUX register. If ADMUX is set to 0, then the ADC will read off the ADC0 pin (see page two of the datasheet. If ADMUX is set to 1, then the ADC will read off the ADC1 pin. I think with that you should be able to modify the code to read off the pins you want. If you run into trouble feel free to post your code and there are plenty of people here that would be happy to help. Humberto |
February 09, 2011 by billwis |
OK I have been trying to get two seperate LM34 sensors to read and display on the LCD. My problem is figuring out how to select the different ADC channel ( I understand the multiplexing ). I can read them individually but can not get them to read together. I have tried the code in many different ways, searched the internet and found many different ways to try but nothing will work. I get errors when I try to upload to the MC. Do I have to select the ADC channels by themselves or is there a for / next loop like in BASIC that can be used to select the channel? Also do I have to write the conversion code for the individual channels or can I make a call to it some how? It should not be this hard but I am just stumped! Thanks for the help Bill |
February 09, 2011 by Ralphxyz |
What in my referenced link does not answer your questions? I included my working multi sensor code at the end. Now which is your problem? Code that does not work or problems uploading to mcu? As far selecting the ADC channels (mux) this "switch/case" statement steps through 6 sensors. The syntax is very similar to what you would use in BASIC :
re: "It should not be this hard but I am just stumped!" Just slow down and take it step by step it will start to fit together and work for you. Try to narrow your questions down to being more specific, as mongo has said in other threads make a flow chart of your code (great advice). Some times if you have a visual representation of your code errors in your logic or implementation become very clear. And of course ask often. Ralp |
March 06, 2011 by billwis |
It has taken a while for me to get back to the kit. As I was searching the net for my answers I came across Ralphs multiple ADC program. What an eye opener. I was real close with my code but had the lines in the wrong place. After going through the code I found my problem and modified it to do what I wanted. Thank you all for the help. Nothing left but to control the world. Thanks BillWis |
Please log in to post a reply.
Did you know that you can make a capacitive proximity sensor with some aluminum foil and paperclips? Learn more...
|