New driver development

Hello,
I would like to add a light sensor and a hygrometer on the Pixhawk I2C bus so I will have to develop a custom driver.
Is there an example on how to develop it? I saw the optical flow example but the code seems to be spread all over several files, while I only need a basic sensor value reading and transmission to the base station.
Thank you

I have developed a custom I2C driver for my sensor. I used the Airspeed sensor as my example, stripping out the parts that I didn’t need. (calibration, etc.) If you search the forums, I think folks have asked about this in the past, it might (or might not) be helpful.
https://discuss.ardupilot.org/t/incorporating-external-sensors-to-pixhawk-via-i2c/24161/3?u=hunt0r

I was trying with a simpler and more supported sensor, a BME280 weather sensor (sensing temperature, humidity and pressure) with I2C interface.
The source code for TSYS01, found in AP_TemperatureSensor seems a good starting point, however I am unsure how to deal with shifting registers.

bool TSYS01::_read_prom()
{
    bool success = false;
    for (int i = 0; i < 5; i++) {
        // Read only the prom values that we use
        _k[I] = _read_prom_word(5-i); 
       /*
        while in the sparkfun library sensor reading is handled this way
        calibration.dig_T1 = ((uint16_t)((readRegister(BME280_DIG_T1_MSB_REG) << 8) + readRegister(BME280_DIG_T1_LSB_REG)));
       calibration.dig_T2 = ...
       ...
       */
        success |= _k[i] != 0;
    }
    return success;
}

Is it possible to use the SparkFun library, designed for an Arduino?

I’m sorry, I don’t understand you question.

Are you asking if you can copy-and-paste some Sparkfun library into the ArduPilot code and get it to work?

If that’s your question, the answer is: “Maybe.” It depends on how the Sparkfun library works, what its dependencies are, and things like that… I expect you’ll want a high level of programming skill to patch it together. BUT, I’m not familiar with the code you’re mentioning, so… you might get lucky! Perhaps it’s actually quite easy to patch in? I don’t know.

I mean if I can use their same approach to reading the sensor. I’ve never worked with this sensor so using an existing library seems a good alternative.
Another possible way would be to wire the light sensor to a companion computer and avoid messing up with Ardupilot.

Ah, I understand. Thanks.

Good luck with whichever you pursue, and let us know how it goes!