Netduino home hardware projects downloads community

Jump to content


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.
Photo

A Most Perplexing Analog Input Problem


  • Please log in to reply
8 replies to this topic

#1 Paul

Paul

    Member

  • Members
  • PipPip
  • 14 posts

Posted 23 September 2010 - 10:44 PM

I'm another one of those Netduino newbies. I got my Netduino about two weeks ago. I've been reading the forums and researching various issues and reading about a number of interesting projects. My first effort was simply to get output to an LCD. I got the Sparfun serial LCD and with the help of Niels R. posting of his SerLCD class things went very smoothly. My next effort was to interface one of the Maxbotix sonar sensors. I wired up the sensor to use 3.3v, ran a 3.3v to Aref pin and the analog output of the Maxbotix to Analog Pin 0. I used the Distance class posted by Crispin as my starting point. My problem is that the readings I am getting on the analog input pin don't make sense to me. I set up the sensor to point at a wall near the table I am working on. When I measure the input voltage at Analog Pin 0 with a digital multimeter I am getting a steady 240mv. Using the Maxbotix datasheet which specifies that with 3.3v input the scaling factor is 6.4mV/Inch, the input voltage of 240mv resolves to a disntace of 37.5 inches which is exactly what it should be. I am displaying the value read from Analog Pin 0 on the SparkFun serial LCD. When I display the value that is being read at the Analog Input pin, it is shown as 70 +/- 2; it doesn't hold steady but doesn't vary by much. I would be expecting to see the value of 240. Below is the code from the Distance class that I am using; it is a slight modification of Crispin's work. Note: I am not doing any scaling in the _baseDistance() routine because I was just curious to see the "raw" value returned on the anlagoue input pint. public enum SensorType //mV/Inch { Maxbotix_LV_EZ = 1 } private Cpu.Pin inputPin { get; set; } private AnalogInput analogInput { get; set; } public SensorType sensorType { get; set; } public double vRef { get; set; } private const double _mmPerInch = 25.4; private const double _inchPerFoot = 12.00; public Distance(Cpu.Pin analogInputPin) { this.inputPin = analogInputPin; this.analogInput = new AnalogInput(inputPin); } public double getDistanceIn_Inch() { return _baseDistance(); } private double _baseDistance() { return Convert.ToDouble(analogInput.Read().ToString()); } Below is the main routine I use to call the Distance class; the inital 350ms delay is to allow the Maxbotix sensor to power up and go through a calibration cycle as per the specs. One more note, I am using the very latest firmware build and I did try grounding all of the unused analog pins but saw no difference. Any help would be greatly appreciated. Thanks, Paul namespace SerialLCD_030 { public class Program { static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); static SerLCD serialLCD = new SerLCD(SerialPorts.COM1); //static Boolean toggle = true; public static void Main() { Distance dis = new Distance(Pins.GPIO_PIN_A0); string sDis = ""; Thread.Sleep(350); while (true) { sDis = dis.getDistanceIn_Inch().ToString(); led.Write(!led.Read()); serialLCD.Write("Distance: " + sDis); Thread.Sleep(250); serialLCD.ClearDisplay(); } } } }

#2 hari

hari

    Advanced Member

  • Members
  • PipPipPip
  • 131 posts

Posted 23 September 2010 - 11:47 PM

Do you have AREF pin connected to 3.3V? This is a very common thing everyone missed (myself included).
http://g33k.blogspot...naloginput.html

#3 Paul

Paul

    Member

  • Members
  • PipPip
  • 14 posts

Posted 24 September 2010 - 09:48 AM

Do you have AREF pin connected to 3.3V? This is a very common thing everyone missed (myself included).
http://g33k.blogspot...naloginput.html



Thanks for the response. As I mentioned in my original post, I do have AREF connected to 3.3V. In researching the forums on using the analog inputs I did come across a number of postings in which this was discussed. I also found a post which suggested grounding all unused analog input terminals. I tried this too but it made no difference.

Paul

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 September 2010 - 09:51 AM

Hi Paul, Can you snap a photo for us? Also, I assume that you have wired your sensor to the Netduino's ground as well... Chris

#5 Paul

Paul

    Member

  • Members
  • PipPip
  • 14 posts

Posted 24 September 2010 - 10:05 AM

Hi Paul,

Can you snap a photo for us?

Also, I assume that you have wired your sensor to the Netduino's ground as well...

Chris


I did wire the sensor to the Netduino's ground too. However, I am using jumper wires so it occurs to me that I should make sure they are actually getting pushed far enough into the headers to make proper contact - perhaps the fact that the meter ready I am getting is steady and the results I am seeing on the display jump around a lot should have been a hint about the soundness of my wire connections.

Beyond all that, a genuine Newbie question: I assume the "Analog In" pins are the ones numbered 0 - 5 under the label "Analog In" on the board and that "Pins.GPIO_PIN_A0" refers to the "Analog In" pin marked 0.

I'll recheck the integrity of all my connections tonight and retry it.

Thanks,
Paul

#6 Crispin

Crispin

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationLondon, England, Earth

Posted 24 September 2010 - 12:10 PM

urm 70 is about right for the analog in. 3.3/1023 * 68 = 219mV 3.3/1023 * 70 = 225mV 3.3/1023 * 72 = 232mV 3.3/1023 * 240 = 774mV Slight margin of error... The value you are reading on the input is not voltage, it's a digital representation of the vRef. 0=0v, 1023=3.3V The last example, if you saw 240 in the .Read() you would actually have a voltage of 774mV
--
Take a seat, I'll be right with you.

#7 Mark H

Mark H

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationPerth, Western Australia

Posted 24 September 2010 - 01:32 PM

Set your analogue input voltage scale as 0, 3300. This will then read out mV rather than the raw ADC value. I don't have the SDK installed on this PC so i can't give you the exact code, however when i was looking through the netduino libraries earlier it was there. If you're getting about 70mv, this is about right for a device that isn't hooked up correctly, check your ground, make sure the maxbotix is powered, and make sure you have the avref connected as above.

#8 Paul

Paul

    Member

  • Members
  • PipPip
  • 14 posts

Posted 24 September 2010 - 02:33 PM

urm 70 is about right for the analog in.

3.3/1023 * 68 = 219mV
3.3/1023 * 70 = 225mV
3.3/1023 * 72 = 232mV
3.3/1023 * 240 = 774mV

Slight margin of error...


The value you are reading on the input is not voltage, it's a digital representation of the vRef.
0=0v, 1023=3.3V

The last example, if you saw 240 in the .Read() you would actually have a voltage of 774mV


Crispin,

Thank you, both for your original Distance class and for explaining how I was misinterpreting what I was seeing on the analog input pin. I now realize that I am seeing the digital representation of the vRef when reading the analog input pin rather than the actual voltage I was seeing on the digital multimeter. The computation which you use I now realize is based on the fact that the Netduino is using a 10 bit ADC.

I'm guessing the fluctuations I am seeing in my readings are due to electrical noise - I soldered a female header onto the Maxbotix but the connections themselves are just jumper wires pushed into headers.

Again, thanks for your help.

Paul

#9 Crispin

Crispin

    Advanced Member

  • Members
  • PipPipPip
  • 65 posts
  • LocationLondon, England, Earth

Posted 24 September 2010 - 06:10 PM

np, Glad the class helped :) Thanks for the hint of waiting after start-up - I had forgotten I should do that. :rolleyes:
--
Take a seat, I'll be right with you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.