Connecting ESP32 via I2C to PixHawk 6c

I have been attempting to connect an ESP32 module via I2C to a PixHawk 6C. So far I’ve been unsuccessful. The goal is to connect an Yuneec Typhoon H Sonar Sensor, which appears to be similar to a HC SR04 sensor. I’ve have the sensor working on the ESP32. What is correct method to get the ESP32 communicating with the PixHawk 6C? I’ve tried using the pin pullup on the ESP32.

Here is a diagram of my test setup.

I grabbed some code from here and added a few tweaks on the sender side:

master reader and slave sender with distance sensor

Why do you use the ESP32 in-between? I would just write the driver using PX4 inspired by any of these distance drivers whichever is closest.

The closet one is broken, HC-SR04. No solution was noted. So I basically, wrote a simple driver on ESP32… I just need a way to interface it to the FC. The sensor interface is simple, in that uses two GPIO pins and does not really require I2C, UART, nor CAN to operate.

There is another PX4 sensor driver, srf02, that is similar but, it requires using I2C. Hence, my motivation to use I2C and interface it with the srf02 driver.

Additional, I have this idea of using multiple range finder sensors. The ESP32 may come in handy.

As I understand it, PX4 needs a driver to turn the I2C data into something it can use. The driver basically converts whatever is coming into the bus in some known protocol into UORB topics (in this case distance sensor topics).

If you’re going to connect via an ESP32 you’ll need to code in the ESP32 to send that on the I2C bus and a driver in PX4 to turn that into distance sensor information. There isn’t a “generic interface” in PX4 for all things the ESP32 might do.

I could be wrong.

1 Like

I was kinda hoping to use srf02 driver or clone it. However, the better solution would be to connect the ultrasonic sensor directly to the FC via GPIO and then use the hc srf04 driver…

Here is half a solution (slave):

HC-SR04 Python

While I’ve been waiting for a reply, I began experimenting with ArduPilot and within 15 minutes I was able to connect the sonar sensor via GPIO. So, I no longer need to sort out I2C. Looks like ArduPilot is the answer I needed.

No worries, glad you found a solution!

1 Like