Analog in put C# coding - General Discussion - Netduino Forums
   
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

Analog in put C# coding


  • Please log in to reply
14 replies to this topic

#1 swestcott

swestcott

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationMontclair Va

Posted 09 January 2011 - 12:30 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?

#2 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

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 swestcott

swestcott

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationMontclair Va

Posted 09 January 2011 - 02:27 PM

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.

OK thanks it is the Maxbotix LV-EZ1 http://www.sparkfun.com/products/639
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

Attached File  P1012974.JPG   1.1MB   49 downloads

#4 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 09 January 2011 - 02:40 PM

That's a cool little car. Is this all you're looking for, to test? Hook up 3.3v to aref, and the analog output from the sensor to A5 (plus whatever else the sensor needs, like power and ground), and i think you'll be all set to test.

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.

#5 swestcott

swestcott

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationMontclair Va

Posted 09 January 2011 - 04:11 PM

Can I use the 3.3v connected to Aref as the power source for the sensor I saw in another thread that was what you do? and where should I be looking for this out put I thought it would show in a windows in studio express? sorry kinda new to C# coming from a VB background and self taught on that I understand your code sample but not sure on reading output Thia is what I have Analog out on sensor connected to A5, GND to GND, Aref to 3.3 to power in on sensor run the code no errors but not sure what I am looking for? Thanks

#6 Jan Olof

Jan Olof

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • LocationSweden

Posted 09 January 2011 - 04:19 PM

Hi He uses Debug.Print that output should you see in the Output window when running the debugger. On my screen this window pops up in the lowe left corner, think I have standard configuration but not sure. And yes you can take some power from the 3.3V pin, but I am not sure how much is left after the Netduino have taken it´s share from the regulator. /Jan Olof

#7 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

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 swestcott

swestcott

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationMontclair Va

Posted 09 January 2011 - 06:07 PM

OK cool yep just chose output window from the Debug menu the out put is a bit unstable but I can work with it I think but this an integer and not a string so the code I was thinking will not work if (s >= 20); I do get an output though a big step forward

#9 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 09 January 2011 - 06:32 PM

the 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".

#10 swestcott

swestcott

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationMontclair Va

Posted 09 January 2011 - 07:15 PM

the 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".

Awesome! thanks I will post a video of it avoiding stuff tonight

#11 FDC30

FDC30

    New Member

  • Members
  • Pip
  • 2 posts

Posted 01 May 2012 - 02:32 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?

#12 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

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?
Biggest fault of Netduino? It runs by electricity.

#13 FDC30

FDC30

    New Member

  • Members
  • Pip
  • 2 posts

Posted 01 May 2012 - 12:50 PM

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.

#14 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 18 September 2012 - 05:31 AM

Does the EZ1 works in low light condition or it doesn't matter because it works just with a ultrasonic wave to determine distance to objects? Does humidity or heat affects the reading?

#15 Geancarlo2

Geancarlo2

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts

Posted 18 September 2012 - 11:57 AM

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.

Follow the datasheet's instructions to calibrate the sensor and adjust your code to take this into account:

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

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.