NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Basic Electronics » Problem with code (2 inputs)
February 23, 2012 by Langermanagement |
Here is the code :
The message that I get from command prompt when I try to download this code is:
|
---|---|
February 23, 2012 by Rick_S |
In lines 54 and 56 the adc.read should be adc_read. Don't know why they are like that... Rick |
February 23, 2012 by hevans (NerdKits Staff) |
Hi Langermanagement, You seem to be using adc.read(), I think you meant adc_read(). Humberto |
February 23, 2012 by Langermanagement |
Thanks Rick, I'm using to programming in java, and am completely new to this stuff. |
February 23, 2012 by Langermanagement |
Ok, it compiled as planned Unfortunately it prints two of the same inputs even though input 1 should have a value of 0 . Both show a value of about 380 to 420. |
February 23, 2012 by Langermanagement |
I got it to compile, Unfortunately both inputs seem to have the same value, despite the fact that nothing is hooked up into the input 1 on my breadboard. What in the code could be causing this? Thanks for all your help Lucas |
February 23, 2012 by Langermanagement |
sorry for double post, was viewing from an old window |
February 23, 2012 by Rick_S |
You need someting connected to it otherwise it will pick up stray interference and give erroneous readings. A simple test would be to connect it to GND and see if it reads zero, then disconnect GND and connect it to 5V. It should read 1023 or something close. If it does, then it is working. Rick |
February 23, 2012 by Langermanagement |
Rick, I did the exact test which you suggested and it gave me the 0 and 1023 values I expected. How can I get separate values for the two inputs? |
February 23, 2012 by Rick_S |
One thing I noticed, you don't need to re-initialize the ADC everytime you change channels to read. All you have to do is set ADMUX to the channel you want to read. Other than that, I'm not too sure what you meant by "it gave me the 0 and 1023 values I expected" and then you asked how to get separate values. Did it work as expected or not?? Here is a sample of how I did it a while ago. Rick |
February 23, 2012 by Langermanagement |
I changed the code. I am still getting the same input for both pins for some reason. The input value always seems to be that of pin0 |
February 24, 2012 by Rick_S |
OK, a couple of changes to your code above. I don't know what you have changed already, but there were some issues as written.
Try these changes. I rearranged the flow in adc_read so that you get the value of your current reading. I also changed your main so you aren't re-declaring your variables and re-initializing everything. Plus, you had no loop in main to repeat. WarningI hand typed this and did not actually compile the code to beware of typo's Rick |
Please log in to post a reply.
Did you know that the sparks present in motors can be dangerous for your microcontroller and other electronics? Learn more...
|