Analog input

Discussion in 'UDOO NEO' started by Brendan Hansknecht, Nov 25, 2015.

  1. Brendan Hansknecht

    Brendan Hansknecht New Member

    Joined:
    Nov 25, 2015
    Messages:
    4
    Likes Received:
    0
    So I was trying to read analog voltage using the udoo neo and I am getting numbers that are out of wack. The expected range for an arduino is 0 - 1023 which map out to 0 - 5V. I used that same mapping and circuit on that I would use on an arduino to measure voltage on the udoo neo and the analog input reads numbers that are equivalent to 20V(much higher than 1023) on about a 3.2V input. Am I missing something because I can't seem to properly read from analog input using the udoo neo.
     
  2. Xykon

    Xykon Member

    Joined:
    Nov 1, 2013
    Messages:
    64
    Likes Received:
    20
    It would help if you posted more details about your hardware set-up and how you are trying to read the analogue input values.
     
    Andrea Rovai likes this.
  3. his

    his New Member

    Joined:
    Sep 8, 2015
    Messages:
    24
    Likes Received:
    4
    Hi,
    I think your problem comes from 12bit adc. You assume it has 10 bit adc. 12 bit equals to 4096. You need to divide the value with 4096 or 4095 instead of 1023. Then you can get 5V instead of 20V.
     
  4. Brendan Hansknecht

    Brendan Hansknecht New Member

    Joined:
    Nov 25, 2015
    Messages:
    4
    Likes Received:
    0
    Just to give people an idea of my circuit and code, I have a 10k pull down resistor between A0 and gnd. And then I connect a battery to A0(positive terminal) and gnd(negative terminal) in order to read voltage. My code is very simple because it just analog reads and then converts to voltage and serial writes the number.

    Thanks for the information that it is a 12bit adc,but that is is still not quite working right and I am not sure why. When I use (AnalogValue*5.0/4096.0) for getting the voltage, It does read a max voltage of 5v, but when I connect a 3.2V battery, I still get a reading equivalent to 5V. Any ideas?
     
  5. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    I can confirm 12 bit for ADC.
    Are you making this reading through NEO? In this case AREF is 3.3, not 5
    imx6 is a 3.3 v compliant processor, so AREF is 3.3V so your abovementioned formula should be *3.3, not *5
     
  6. Brendan Hansknecht

    Brendan Hansknecht New Member

    Joined:
    Nov 25, 2015
    Messages:
    4
    Likes Received:
    0
    Thanks for the reply. Based on that, if I set the udoo neo to use external reference and then plug in 5V into the aref pin it should give me values from 0 to 5V. I am gonna test that. Thanks for all the help.
     
  7. Brendan Hansknecht

    Brendan Hansknecht New Member

    Joined:
    Nov 25, 2015
    Messages:
    4
    Likes Received:
    0
    So I tested using 3.3 and 4096 as the numbers in the equation and the voltage measure now works besides it reads about .1 volts lower than the actually voltage but that is not a huge deal. Thanks for all the help.
     
  8. Xykon

    Xykon Member

    Joined:
    Nov 1, 2013
    Messages:
    64
    Likes Received:
    20
    Just to make sure if anyone else is reading this... UDOO NEO isn't 5V tolerant so don't feed 5V into the AREF or analogue input pins! The maximum is 3.3V!
     
    Andrea Rovai likes this.
  9. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    @Brendan Hansknecht follow the advice of Xykon and don't do that or you'll fuck up your board
     
  10. Tengoles

    Tengoles New Member

    Joined:
    Nov 23, 2016
    Messages:
    14
    Likes Received:
    3
    Hello I am having a problem sort of related to this, I am running this code on Arduino:

    void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
    pinMode(13,OUTPUT);
    }

    void loop() {
    // put your main code here, to run repeatedly:
    int Analog=0;
    float fAnalog=0;
    digitalWrite(13,HIGH);
    Analog=analogRead(0);
    fAnalog=Analog*3.3/4096;
    Serial.print(fAnalog);
    Serial.println();
    delay(2000);
    digitalWrite(13,LOW);
    Analog=analogRead(0);
    fAnalog=Analog*3.3/4096;
    Serial.print(fAnalog);
    Serial.println();
    delay(2000);
    }

    And what reads using the minicom -D /dev/ttyMCC command on linux is 0 and 0.82 when it should be 0 and 3.3. Although if I use fAnalog=Analog*3.3/1024 then it reads 0 and 3.3. Does that mean that the Arduino on my board has less bits on the ADC? why whould that be? my board is NEO FULL by the way.
     
  11. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Once upon a time the default resolution was 12 bits (max value 4095). But I think for compatibility reasons with existing Arduino Uno sketches the default resolution has been set back to 10 bits. (Max value 1023)

    If you want to use the higher resolution use analogReadResolution(12); in the setup section of your sketch.

    @Andrea Rovai. Please update the documentation with this instruction.
     
    Last edited: Dec 6, 2016
    Maurice likes this.
  12. Tengoles

    Tengoles New Member

    Joined:
    Nov 23, 2016
    Messages:
    14
    Likes Received:
    3
    Thank for the answer!
     

Share This Page