Home        Store        Docs        Blog

Using I2C sensors with QgroundControl


(Reza) #1

I’ve gotten a i2c thermometer and humidity sensor that I’d like to measure inside of the electronics enclosure of my ROV. It’s currently plugged into the pixhawk. How can I/ can I read the sensor data over the tether on QGroundcontrol?

Send data with MavLink to QgroundControl
(Jacob) #2

What sensor have you got? It will probably not be plug and play, new software will need to be written to support it.

(Reza) #3

The sensors are: Adafruit HTU21D-F Temperature & Humidity Sensor Breakout Board. What will the process be for writing the software, as I anticipate needing to add a wide range of sensors to the custom ROV that I am building.

(Jacob) #4

If you want it to show up in QGC, it can take quite a lot of effort the first time around.

You will need to

  1. Write a driver for the sensor that runs on the pi or the pixhawk (The pi can be easier, or even an arduino connected to the pi if you can find an arduino library).
  2. Send the sensor value via mavlink or some other method.
  3. Receive the sensor value and display it in QGC.

(Reza) #5

How different will the pixhawk driver be from arduino driver, since I already have that, but I don’t not really space for an arduino.

Do you have an example of writing a driver for pixhawk that I could follow?

(Jacob) #6

You can look at the source code for existing i2c sensors like the Bar100:

(Reza) #7

Great, I am working on writing the driver now. When that is done, how can I get it to be sent over MAVlink to QGC?

(Jacob) #8

You will need to set something up in the vehicle code to do that. You can use the named value float messages like we do here.

(Reza) #9

Is there good documentation for the different I2C commands? With arduino, there is the Wire library which is very straight forward, but I am struggling to understand what is what with the I2C library for pixhawk.

(Jacob) #10

No, your best guide from here will be looking at source code. Beware my initial warnings:

(Reza) #11

How would connecting the I2C sensor to Raspberry Pi work? Where would I write the code to get it to send data to QGC?

(Patrick José Pereira) #12


For that, it’ll be necessary to write a python or C++ code to communicate with your I²C sensor, after doing that, you should improve your code to connect with mavproxy, that is running already in your ardusub companion computer, and send mavlink messages like NAMED_VALUE_FLOAT, as Jacob described.

We have some pymavlink examples in ardusub.com.

(Reza) #13

So I am trying to install a library to the Pi, using the terminal, but I can’t connect to wifi. What is the problem?

(Jacob) #14

Can you show us the error that you are seeing?

If you are using our rpi image, you should be able to connect to wifi by visiting in a browser.

(Reza) #15

I am using your rpi image, and am going to Only one wifi network shows up, and even then it never connects to the network

(Jacob) #16

Do you have the password for the network? Are you entering it correctly? Your router may be blocking the connection.

(Reza) #17

Yes, of course I have the correct password for the network, and have been entering it correctly.

(Reza) #18

I can see all of the networks when I enter:

sudo iwlist wlan0 scan

yet none of them show up when using the companion web interface

(Jacob) #19

Interesting. There is a log file at ~/.webui.log. You can send that and I’ll have a look.

Did you get connected to wifi through the command line?

(Reza) #20

I was not able to. How can I find the log file?