Maxbotix XL-MaxSonar-EZ4 Detection/Wiring Issues

Hey guys - I am trying to configure a XL-MaxSonar-EZ4 to eventually use BendyRuler for obstacle avoidance. When looking for ways to send the signals to my Pixhawk 4, I ran into a few problems. I originally thought I would plug it into the FMU PWM OUT [AUX] ports because they were currently unused (my motor ESC’s and servos both come from I/O PWM OUT [MAIN]) but after some testing and setting the RNGFND1_PIN to 50 (AUX 1) it still could not detect the rangefinder. Am I doing something wrong, or should I try and send it to the CAP & ADC in port? If I did choose to do that, which ADC would it be in MP? There are three different options for ADC port in RNGFND1_PIN, and I’m not sure which one it would be. I am currently using the SBUS port for RC, so that is out of the question also. Any thoughts or help is welcome.

Update for the CAP & ADC IN port: I cannot seem to find that much information online about the specific pin out, along with troubles of the Pixhawk not coming with a compatible cable. Is the AUX row even useable for inputs?

Another update: I hooked back up the sonar sensor with the original setup (FMU PWM OUT [AUX] with RNGFND1_PIN set to 50 (AUX 1) and then it would let me arm the rover without giving me the error β€œRangefinder 1 not detected.” The sonar sensor is also now emitting very quiet clicks (I presume that is good, because it is sonar.) Even with this new development, β€œsonarrange” in the status panel remains at zero. Any thoughts?

have you set SERVOx_FUNCTION to -1 so it can be used for GPIO?

If I am using the aux bar instead of the main bar, would it be SERVO9_FUNCTION for input 1 of the aux?

yes, aux 1 is servo 9

OK - I have SERVO9_FUNCTION set to -1 (GPIO) and RNGFND1_TYPE set to 1 (analog) and RNGFND1_PIN set to 50 (aux 1) and still sonarrange remains at zero. :frowning:

where have you connected it to on the sonar, it has different outputs and it sounds like your getting mixed up with them,

it can do PWM output, thats a type 5 rangefinder thats connected to the AUX SERVO pins
it can do analog that you connect to one of the ADC pins on the pixhawk.

it sounds like your trying to set it up as an analog rangefinder on the aux pins, that wont work.

these are the ADC pins, you need to connect it to one of these if you’re using it as analog.

to use it as a pwm rangefinder you need to set it as a type 5 and make sure its connected to the correct output on the sonar.

1 Like

Can I use an analog rangefinder as a PWM rangefinder by switching the pins I have it soldered to? I am pretty sure the answer is no, which means it should go into the ADC port. The problem is that I am using a pixhawk 4, which does not appear to have a dedicated ADC port :pensive:. It has a CAP & ADC IN ports, but the documentation for how I would wire something to that 8-pin input does not appear to be easily found.
image
Here is an image of a pixhawk 4 - you can see the 8-pin CAP & ADC IN port

I was acually able to find the pinout of the CAP & ADC IN port -


Would it just be wired as:
VCC β†’ V+
GND β†’ GND
and ADC_SPARE_1 β†’ to the signal pin on the sonar?

what output on the sonar are you connected to? it has 3 different outputs.

to get it to work as analog you want to connect pin 3 AN output of the sonar to ADC1_spare_1 of your pixhawk

I am connected to the middle one (3) as says the documentation on this particular sensor.
Maxbotix Analog Sonar β€” Rover documentation (ardupilot.org)

Thank you! I will try this out now.

Thank you so much @geofrancis! I am now getting results on sonarrange. The values seem a little wonky (it is always between 3.50 and 3.9) but I am sure some params just need to be changed. Again, thanks for your help!

Edit: The sonarrange values always stays a little bit above whatever I set the RNGFND1_SCALING to. Interestingly, when I first tested the rangefinder I have the type accidentally set to 5 (PWM) but when I switched it back to 1 (analog) nothing changed.

I realize now that I connected the signal output of the sonar sensor to the ADC_spare_2 of the pixhawk. Does this change the read distance?

Edit: Looks like I cannot wire the output to the ADC_spare_1, it has a voltage limit of 3.3v and the sonar sensor outputs up to 5v.

Updates: It was not working as I thought it was.
No matter what I set RNGFND1_TYPE to, the sonarrange is always the same. It varies slightly when touch the sonar sensor, but other than that it always varies with whatever RNGFND1_SCALING is, no matter what the sonar sensor actually takes in. For reference, I have a Maxbotix XL Maxsonar EZ4 which I have wired into the CAP & ADC port of a pixhawk 4. Using the wiring graph below, I have VCC connectede to the voltage on the sensor, GND to the GND, and the 3 pin on the sensor connected to ADC1_SPARE_2. Any thoughts or question are welcome.


Anyway, I’m going to go sleep on it and maybe it will start working in the morning. :crossed_fingers:

do you have a multimeter to verify the AN pin on the sonar is changing voltage?

Yes, after testing the sonar with a multimeter the output pin changes from 0v to 5v as expected. The weird part is when I fully disconnect the sonar from mission planner is still reads sonarrange as the same value. If I switch the RNGFND1_PIN to something else, both sonarrange and sonarvoltage go back to zero. But when I use 14 (Pixhawk ADC #3) for RNGFND1_PIN the values sit at:
sonarvoltage: 1190-1210 (varies slightly)
sonarrange: 2.42-2.46
Nothing that I do (whether I plug in the sonar sensor or not) changes these values.

I think you must have the wrong pin selected for the ADC, can you find out what one its mapped to on a pixhawk 4? it might be different to a pixhawk v1.

Analog inputs

The Pixhawk4 has 7 analog inputs

ADC Pin0 -> Battery Voltage
ADC Pin1 -> Battery Current Sensor
ADC Pin2 -> Battery Voltage 2
ADC Pin3 -> Battery Current Sensor 2
ADC Pin4 -> ADC port pin 2
ADC Pin14 -> ADC port pin 3
ADC Pin10 -> ADC 5V Sense
ADC Pin11 -> ADC 3.3V Sense
ADC Pin103 -> RSSI voltage monitoring

That directly conflicts with the chart I found here: Pixhawk4-Pinouts.pdf (sparkfun.com) and here: Pixhawk4-Pinouts.pdf (shopify.com)
Also, the ADC port only has 8 pins so if your graph is correct which pin is not there?

If using the one on github, would I plug the signal wire into Pin10? I also don’t see a ground.