Is there a C or C++ version of bh1745 library

Hi Pimoroni, and fellow Pirates.

Short version of the question for those that do not read long posts ;)
Is there a C version of bh1745 library?

Question with context:
I’m having a lot of fun with the Pimoroni Products for the Raspberry Pi.
the last couple of weeks I’ve been buidling stuff with the breakout sensors that fit on the Garden.
Although I think Python is great, I mainly code with the Haxe Programming Language.
To use the sensors I’m building libraries/extensions that can be used from Haxe.
These are basically wrappers around c-libraries.
I’ve already built an extension for the VL53L1X Time of Flight Sensor.
Now I want to do the same for the BH1745 Color Sensor.
So I’m wondering if there is a C-version of the library out there somewhere.


There might be a C library out there or code that’s easily portable from Arduino, but we’ve no plans to ship one of our own since I just don’t have the capacity to support another language properly.

The availability of C-code for the VL53L1X and MLX90640 is something of an anomaly, since both of these libraries are supplied by the manufacturer and then wrapped into Python.

If you wanted to write your own C library, the Python code is probably a good place to start since it uses a DSL for describing the device registers that makes it almost a translation of the datasheet-

Ok Thnx, I’ll have a look at the python code and search some more for an existing Aurduino lib.
I just didn’t want to make my own C-library if one already exists.
If I succeed I’l make it open source and post a link in a reply.


1 Like

Sorry to open up an ancient thread. Did you ever make/find a C/++ library for the bh1745 as I am trying to use it on an ESP32?

No I didn’t, couldn’t spare the time unfortunately…

Thanks for the speedy reply. If I get anywhere (which I think I have to) I will post some code here to help others. I doubt I will rebuild the library, but just use it as reference to get some basic functionality up and running.

Sorry about this being very, very late to reply, but honestly, I just got my Pimoroni BH1745 Breakout…

I was able to find an Arduino cpp library that appears to work. It was published on the Sunfounder GitHub collection of repositories under the title of sunfounder/arduino-lib-bh1745

Here is how I am using it. I am running it off an old-school ‘original’ Arduino Nano board (not the “every”, an old nano I had lying around for years). The SDA pin is A4 and the SCL pin is A5. Just use one of Adafruits JST QT to Male headers cable on your breadboard. Then I just downloaded the raw files individually from GitHub when setting up my sketch.

What is important to note is that the Sunfounder Arduino Library for this sensor presumes that the address is 0x39. However, the Pimoronin version of the breakout board for BH1745 is on address 38. So I had to modify the downloaded BH1745.h file to reference the correct address…

#define ADDR 0x38

I have been running a copy of the BH1745Detect.ino from the Arduinio sketch that is included in the Sunfounder Githup repository.

1 Like