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