The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
First, the circuit. You'll want to read about voltage dividers to really understand what is happening. The potentiometer acts as one of the resistors in the voltage divider -- and since a potentiometer's resistance changes by turning it, it provides a good source for the analog input. If you are comfortable with Ohms Law (V=IR) the wikipedia article on voltage dividers is pretty approachable in my opinion. Something important in the circuit is the link from 3.3v to the aref pin. Aref is "analog reference" and sets the ceiling of the analog input. The max is 3.3v. I believe the revision B netduino boards have an internal tie in so that using aref is optional.
... and what it might look like on a breadboard:
... and the program:
using System.Text;
using Microsoft.SPOT;
using System.Threading;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NDP_SocketSender1
{
public class Program
{
public static void Main()
{
AnalogInput a5 = new AnalogInput(Pins.GPIO_PIN_A5);
while (true)
{
string s = a5.Read().ToString();
Debug.Print(s);
Thread.Sleep(100);
}
}
}
}
Basically, the program opens up an analog input port (a5 in this case), reads the value into a string, and prints the string to the output window in visual studio every 100ms. As you adjust the potentiometer, the values displayed in debug should change, varying from about 0 to about 1023, which are the bounds of the 10-bit ADC (analog-digital coverter) built in to the netduino.
Since I have a Netduino Plus, I have also set it up send the readings over the network and graph them in a Windows Forms Application, so I could see the results visually as I turned the potentiometer to different positions. It's important to realize that digital inputs read either 1 or 0; analog inputs have a range, and the graph from my netduino plus illustrates this:
If you don't have a netduino plus, you can cut and paste the data from the output window in Visual Studio into Excel or a Google spreadsheet and graph from there.
If this is interesting to you, I would encourage you to search the forums for "analog", "analoginput", and "setrange" for lots more useful information.
I just tried this today. It was my first non-blinking led project on the netduino.
What are the units that are displayed in the output window?
It seems like it's the resistance in the potentiometer plus the resistance of the resistor plus a bit of on board resistance.
Am I right or is it a coincidence?
Hi Bill.
In your diagram, the input can never be 0 because R2 would always have a voltage applied to it meaning that the input at A5 would always be raised above 0.
Wouldn't the attached be better since this would give you a full range of inputs from 0 to 3.3v. Unless I'm missing something? Maybe you can damage the netduino if you apply 0v to the inputs or something??
@bill.french, this is an excellent post. I've been meaning to make some like this myself, but haven't gotten around to it just yet. I hope to see more.
How did I miss seano's question? Sorry. The units are from 0-1023, because it's a 10bit adc, and 2^10 (minus 1) is 1024. Search the forums for "setrange" for interesting info.
@vaticanuk: yes you are right, but i thought using a voltage divider circuit would be slightly more useful (in my opinion) for the example because you can replace the potentiometer with something else, like a thermistor. In your circuit the potentiometer is the voltage divider.
Does using an analog input require that you use the Aref in your circuit? Or could you use an external circuit with a voltage out to the analog input?
If you have a "Rev A" Netduino/Netduino Plus, you'll need to wire up the AREF to a 3.3V source. If you have a "Rev B" unit (or a Netduino Mini), 3.3V AREF is built-in and used by default.
If you have a "Rev A" Netduino/Netduino Plus, you'll need to wire up the AREF to a 3.3V source. If you have a "Rev B" unit (or a Netduino Mini), 3.3V AREF is built-in and used by default.
Chris
Does AREF have to be 3.3V or could I change it? Also is the function of AREF to compare the voltage of the analog input so it knows how many bits to convert it to? Like 0V at the analog input is 0bits, and 3.3V at the analog input is 1023bits?
Does AREF have to be 3.3V or could I change it? Also is the function of AREF to compare the voltage of the analog input so it knows how many bits to convert it to? Like 0V at the analog input is 0bits, and 3.3V at the analog input is 1023bits?
Hi capn,
AREF can be between 2.7V and 3.3V (using the external AREF pin). It represents the high-end of the analog voltage range. So 0V will always be "0" and the voltage matching AREF will be "1023".
Voltages in between are represented linearly throughout the 0...1023 range (e.g. 1.65V = 511).
AREF can be between 2.7V and 3.3V (using the external AREF pin). It represents the high-end of the analog voltage range. So 0V will always be "0" and the voltage matching AREF will be "1023".
Voltages in between are represented linearly throughout the 0...1023 range (e.g. 1.65V = 511).
Chris
Ok, that's easy enough to understand. This might be for another topic, but if you have an analog voltage that doesn't vary from 0-3.3V, say 1.65-3.3V, can you shift the 0bit to 1.65V and still have the 1023 bit at 3.3V?
Ok, that's easy enough to understand. This might be for another topic, but if you have an analog voltage that doesn't vary from 0-3.3V, say 1.65-3.3V, can you shift the 0bit to 1.65V and still have the 1023 bit at 3.3V?
AnalogInput.SetRange lets you pick a custom range. So if you gave it a range of -1023 to 1023, then 1.65V would be 0.
Do you have to use an AREF if your analog sensor is requiring a 5V and you are not using a 3.3V?
AREF is the measuring stick against which the analog signals are measured. If AREF is 3.3V and the signal is 1.65V, then the signal's value is "50%" of the range (value of ~511 on the default range of 0-1023).
AREF = analog reference voltage
The output voltage of the sensors usually depends on the input voltage given to the sensors. If your sensor inputs 5V and outputs up to 5V, then you will need to bring that voltage down (with a voltage divider, or with a sensor that can take a 3.3V input). Sending more than 3.3V to an analog input (or more than the AREF voltage) can damage your Netduino's microcontroller.
AREF is the measuring stick against which the analog signals are measured. If AREF is 3.3V and the signal is 1.65V, then the signal's value is "50%" of the range (value of ~511 on the default range of 0-1023).
AREF = analog reference voltage
The output voltage of the sensors usually depends on the input voltage given to the sensors. If your sensor inputs 5V and outputs up to 5V, then you will need to bring that voltage down (with a voltage divider, or with a sensor that can take a 3.3V input). Sending more than 3.3V to an analog input (or more than the AREF voltage) can damage your Netduino's microcontroller.
Does that help answer your question?
Chris
Thanks for the help. I am new and still fuzzy. I will study this. In the short term, I am using this http://www.phidgets....product_id=1120 . I have it powered by the 5V on my N+. I am using A01 as my input. What do you recommend?
Thanks for the help. I am new and still fuzzy. I will study this. In the short term, I am using this http://www.phidgets....product_id=1120 . I have it powered by the 5V on my N+. I am using A01 as my input. What do you recommend?
I just put a MultiMeter on the analog line that would plug into A01, it is rading 4.XX V. This is what you were talking about when you said too much coming back and could damage my N+?
That is my only sensor, does this mean I need to implement a voltage divider?
Thanks for the help. I am new and still fuzzy. I will study this. In the short term, I am using this http://www.phidgets....product_id=1120 . I have it powered by the 5V on my N+. I am using A01 as my input. What do you recommend?
I would contact Phidgets and ask them if you can use a 3.3V input. The product specs say that it requires 4.5V to 5.25V input, but the FAQs for FlexForce seems to indicate otherwise.
Alternatively, you can use a voltage divider (using resistors) to convert the 0-5V output to 0-2.5V instead. If you then set your AnalogInput range to 0...1350 using AnalogInput.SetRange(0, 1350), you'll get a value of 0-1023 based on pressure.
Target range calculation (to recalibrate for 2.5V input instead of 3.3V input)
1350 = 1023 x (3.3 / 2.5)
I would contact Phidgets and ask them if you can use a 3.3V input. The product specs say that it requires 4.5V to 5.25V input, but the FAQs for FlexForce seems to indicate otherwise.
Alternatively, you can use a voltage divider (using resistors) to convert the 0-5V output to 0-2.5V instead. If you then set your AnalogInput range to 0...1350 using AnalogInput.SetRange(0, 1350), you'll get a value of 0-1023 based on pressure.
Target range calculation (to recalibrate for 2.5V input instead of 3.3V input)
1550 = 1023 x (3.3 / 2.5)
Chris
Extremely helpful, thanks. Last questions… . I have changed my voltage to 3.3 and added the AREF lead as well. I now measure my input lead at 2.9 to 3.4V. Is that too high for an input line?
If I wanted to use a voltage divider I understand implementing a resister but I do not follow the Max Range Value? Where did you get those numbers 1350, 1023 and 1550? I assume this adjustment is needed to regulate my sensor values because I dropped voltage?