analog input issue: A0 to A9

Dear all

I am currently working on obstacle avoidance for an indoor quadrotor, using ardupilot. I already implemented a height controller using an ultrasonic sensor on A0.

As i started to test multiple ultrasonic sensors i stumbled across some problems. I have been testing on 2 different APM2.5: 1 at home and 1 at the university. The first tests happened on the ground without props. When i tested at home i could use anaolog inputs A1, A2, A2 and A5 succesfull and read out 4 extra different ultrasonic sensors. ( I fire them sequentially with a I2C expander.)

However when i tested the exact same code i used at home on the APM2.5 at school, I don't get any meaningfull readings out the sensors A1, A2, A3 or A5, i only get fluctuating values. When i started investigating further, i discovered that when i connected the A1, A2, A3 and A5  to the ground or to 5V, they still didn't respond! Still fluctuating results between 0 and 1023 (raw value). Only A6 and A7 went to 0 (+2) when connected to ground and to 1023 (-2) when connected to 5V. When i put the ultrasonic sensor to these pins, the reading still fluctuated really bad (due to unability of sensor to pull up or down i think?).

Also pin A4 didnt work on either APM2.5, aswell as A8 and A9.

The ultrasonic sensors themselves are fine since they are tested at home and gave stable and 'correct' (within centimeters or inches) readings.

Pin A0 works very well. Also note that when A0 was grounded, A1, A2 and A3 were not fluctuating much anymore: they showed reading of arround 20, 50 and 120 (raw values -> sonar1.raw_value), even when grounded or connected to 5V!

I am wondering what is wrong with the analog inputs? I have checked the soldering (board was presoldered btw). But maybe there is an internal disconnection? Or did i forgot some code which is crucial? But how is it possible that it worked on the APM2.5 at home for the exact same pins?

I have also a question relating the ADC of APM2.5. Isn't it a 16 bit adc? How can i then get raw values between 0 and 1023 (wich are 10 bits unsigned)?

The code which i used for the sensors is given in the attached file.

Can somone clear this out or has any suggestions what might be wrong or what i might have overlooked. I have the eagle files, but maybe i overlooked something there?

Important note for anyone who wants to use more than 5 analog inputs: adjust the MAX_PIN_SOURCES in the AP_AnalogSource_Arduino.cpp file! Else your APM2.5 will not respond to the mission planner and to the Serial Port in Arduino!

Kind regard

Jonas

code_ultrasonic_sensor.txt

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Dear Mr. Jonas,

    I am a beginner with APM and in my project I just want to read three sonar sensors outputs which are placed in my quad. I appreciate if you can list what codes are needed and where I need create extra code and variables to add in the extra sensors.

    Cheers

    Reza

This reply was deleted.

Activity

DIY Robocars via Twitter
6 hours ago
DIY Robocars via Twitter
RT @NVIDIADRIVE: Season Beta has arrived! Check out the first race of the @roborace season, livestreaming from Anglesey Circuit Sept. 24-26…
14 hours ago
DIY Robocars via Twitter
RT @IndyAChallenge: Here is the ROS-based small-scale vehicle platform showing the ROS Visualization (Rviz) screen with multiple ROS nodes…
yesterday
DIY Robocars via Twitter
RT @IndyAChallenge: Here is Black & Gold Autonomous Racing's simulated racecar running a lap @IMS and showing the team's code overtaking ot…
yesterday
DIY Robocars via Twitter
yesterday
DIY Robocars via Twitter
RT @donkey_car: New Maintainers! Donkey Car 4.0 and more! Here is our September Newsletter! https://donkeycar.substack.com/p/september-donkey-newsletter?r=2ji2t&utm_campaign=post&utm_medium=web&utm_source=copy
yesterday
DIY Robocars via Twitter
RT @chr1sa: Kinda cool that we just hit 2,500 members of our Bay Area self-driving car racing league. More than 10k globally. Fast, cheap…
yesterday
DIY Robocars via Twitter
RT @chr1sa: Our next @DIYRobocars virtual AI car race is next Saturday. Compete from home using the @donkey_car simulator -- no physical ca…
Sunday
DIY Robocars via Twitter
RT @RoboticMasters: Students from @Sydney_Uni working hard on improvements and changes to @donkey_car simulator. @diyrobocars @adafruit…
Sunday
DIY Robocars via Twitter
Practice virtual race this Saturday; the real thing will be on Oct 3 https://www.meetup.com/DIYRobocars/
Sep 23
DIY Robocars via Twitter
Sep 23
Derrick Davies liked lisa TDrones's profile
Sep 23
DIY Robocars via Twitter
Sep 21
DIY Robocars via Twitter
RT @SahikaGenc: AWS DeepRacer & Hot Wheels Track https://youtu.be/4H0Ei07RdR4 via @YouTube
Sep 14
DIY Robocars via Twitter
Sep 8
DIY Robocars via Twitter
RT @davsca1: We are releasing the code of our Fisher Information Field, the first dedicated map for perception-aware planning that is >10x…
Sep 8
More…