I successfully obtained data from my I2C device in Arduino:

#include <Wire.h>
... // read function:
Wire.write(startAddress >> 8);
Wire.write(startAddress & 0xFF);
uint16_t numberOfBytesToRead = bytesRemaining;

Wire.requestFrom((uint8_t)address, numberOfBytesToRead);
if (Wire.available()) {
  for (uint16_t x = 0 ; x < numberOfBytesToRead / 2; x++) {
    data[dataSpot] = Wire.read() << 8; //MSB    // uint16_t *data
    data[dataSpot] |= Wire.read(); //LSB

Now I need to do the same in STM32F411 FC:

  1. obtain this data in Betaflight loop, along with other sensors data
  2. send it to OSD, along with other sensors data

Please help me with specific code examples or suggest which files and functions should I edit? I'm still very new to Betaflight project structure 🙏

  • 1
    $\begingroup$ Welcome to the forum! This is quite a complicated process that would involve a significant amount of learning on your part, based on the fact that you're presenting us with Arduino code (on which I in no way intend to be bashing). Converting Arduino code to the low-level C used in the Betaflight source is not really an easy feat and we'd likely have to write a multi-page answer to adequately describe the process. Your question is a good one, which is why I don't want to close it, but just know that you aren't likely to get a satisfying answer. Sorry to be the bearer of bad news! :) $\endgroup$
    – ifconfig
    Commented Sep 10, 2022 at 6:23
  • 1
    $\begingroup$ @ifconfig I've looked through Betaflight source code. There is code that launches tasks: \src\main\scheduler\scheduler.c. Also, there is a list of sensors in \src\main\sensors. Can I just add my custom sensor there and implement functions? Then read its data as it is done for other sensors. Please suggest me which specific steps do I need to take to achieve this. I've already built custom Betaflight, I know C/C++ too. But I'm stuck with this specific problem $\endgroup$
    – user255936
    Commented Sep 11, 2022 at 16:31
  • 1
    $\begingroup$ Yes, that is likely to be the correct approach. Driver integration of your custom code into the Betaflight build system and into the OSD codebase might be a significant chore, though. Also keep in mind that you'll have no option to configure the new OSD element from the configurator, as it relies on the pre-existing element set in Betaflight. $\endgroup$
    – ifconfig
    Commented Sep 12, 2022 at 18:19
  • $\begingroup$ We're you able to successfully add a custom Sensor and produce Text from it on the OSD ? If so, can you share your success details? $\endgroup$
    – user5555
    Commented Jun 14, 2023 at 23:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.