
Analog in put C# coding
#2
Posted 09 January 2011 - 03:59 AM
I have a range finder that outputs 6.4mV per inch I want to read that input and lets say if less than or = to 10 inches do X if grater than 10 inches do Y
is this even possible?
Sounds like a simple if/else statement. We might be able to help you better if you explain further (i.e. sensor model, brand, etc.) that way someone can reference the datasheet.
#3
Posted 09 January 2011 - 02:27 PM
OK thanks it is the Maxbotix LV-EZ1 http://www.sparkfun.com/products/639Sounds like a simple if/else statement. We might be able to help you better if you explain further (i.e. sensor model, brand, etc.) that way someone can reference the datasheet.
here is the data sheet http://www.maxbotix....1-Datasheet.pdf
I was thinking that I could connect it to the 3.3V and the Aref and one of the analog inputs on the netduino the data sheet says at 3.3v the out put is around 6.4mV per inch. I was hoping to have this interrupt the forward motion of a robot cause one set of wheels spin the other way turning to avoid objects in front of it then return to moving forward. I am trying to understand how to read the analog input voltage in C# the data sheet says it sends an analog reading constantly so no timing is needed? and after rereading I saw this "Analog, (Vcc/512) / inch" I have powered it up by it self and attached a meter to the output and did see around 6.4mV per inch output but when something is closer than 6 inches the output stops showing changes this is why I chose 10 inches as the distance for making the turn.
I have all the motor control code figured out and have the bot moving forward or turning in a circle
here is a photo of the finished bot.
thanks for your help

#4
Posted 09 January 2011 - 02:40 PM
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); } } } }
The above code is from here.
- Giuliano likes this
#5
Posted 09 January 2011 - 04:11 PM
#6
Posted 09 January 2011 - 04:19 PM
#7
Posted 09 January 2011 - 05:01 PM
I am not sure how much is left after the Netduino have taken it´s share from the regulator.
/Jan Olof
Should be plenty! And yes, debug.print should put stuff in the "output" window -- it should be in the lower left, although you might have to select the "output" tab. I can't remember, I set it up my visual studio layout some time ago, and the settings stick.
#8
Posted 09 January 2011 - 06:07 PM
#9
Posted 09 January 2011 - 06:32 PM
int i = a5.read(); if (i > 20) { // do whatever }
If you want to get the analog readings in mV, search the forums for "setrange".
#10
Posted 09 January 2011 - 07:15 PM
Awesome! thanks I will post a video of it avoiding stuff tonightthe line with the a5.read, I convert to a string, I believe it normally returns a number, so if you did something like:
int i = a5.read(); if (i > 20) { // do whatever }
If you want to get the analog readings in mV, search the forums for "setrange".
#11
Posted 01 May 2012 - 02:32 AM
#12
Posted 01 May 2012 - 07:56 AM
Heey guys.. Question, my ultrasonic range finder sensor(Maxbotix LV-EZ1)currently works fine with a 5 V supply (hard wired to USB), however, in a 3.3V Lipo battery powered case, the ultrasonic conversion leads to significant errors. Currently I accept Analog input from the ultrasonic to the ardupilot. Is there a correct conversion arduino code for the ultrasonic (Maxbotix LV-EZ1) sensor when powered by a 3.3 V Lipo battery? Any ideas why am I getting this when I do use the 3.3v Lipo Battery?
The sensor seems working fine even below 3V (from the specs).
Not sure about your problem in general, though. Are you using Arduino or Netduino?
#13
Posted 01 May 2012 - 12:50 PM
#14
Posted 18 September 2012 - 05:31 AM
#15
Posted 18 September 2012 - 11:57 AM
Follow the datasheet's instructions to calibrate the sensor and adjust your code to take this into account:Heey Mr. Vernari thanks for your response. Yes, I am using Arduino(Ardupilot)system. EZ1-Ardupilot-3.3V battery. It works really fine with the USB port connection 5V and yes I have 4 different 3.3v batteries brand new but for any unknown reason, when I connect the 3.3v on it, the ultrasonic conversion leads to significant errors. Noise. Any Ideas, I know it is weird.
AN – Outputs analog voltage with a scaling factor of (Vcc/512) per
inch. A supply of 5V yields ~9.8mV/in. and 3.3V yields ~6.4mV/in.
The output is buffered and corresponds to the most recent range data.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users