Have you ever interfaced a MAX44009 sensor with a uC

Hey all Programming Gurus!

Right, before you all swear at me: I already asked this question on the MikroC forum, and they can’t help. The reason I am posting here, is because I have seen far more examples of interfacing a MAX44009 lux sensor using Arduino than I have seen any other uC and IDE, and so I’m hoping that someone here may have seen or worked with this sensor in the past.

I need to interface a MAX44009 to a PIC24FJ64GB002 microcontroller and display the lux reading, continuously (at a refresh rate of 100ms), in real-time, on an LCD. I am coding the system using the dsPIC MikroC IDE.

Now before you all swear at me again - I am not expecting anyone to learn a new library, I suspect that there is an issue with the C code and this question is aimed specifically at people who have worked with this sensor before.

I do not want to enable the interrupt setting of the sensor IC, I just want to read the lux value on the LCD every 100ms.

The code compiles without error or warning, I am just concerned that I have configured it incorrectly. The sensor package is the GY-49, and I suspect that the address pin is high (A0) thus you will note different slave address to the typical MAX44009 code already available on Github. I have tried the slave address with A0 low, and still no response. If you are familiar with the GY-49package, you will know that only the VCC, GND, SDA, SCL pins are labelled, and the INT and A0 pins are not. So I have no idea which pin is A0. So it’s a bit of a guess, but both slave addresses don’t work.

I’m worried that I have coded register 0x02 and register 0x03 incorrectly. I think this is a code issue, not a library issue, and so anyone who’s worked with this sensor might be able to spot the error quickly.

Please could you take a look at the code attached. I have included the datasheet for quick reference.

I measured the SCL and SDA lines on the oscilloscope, and both pins are just high all the time (3.3V) and yes, there are pull-up resistor attached. But it seems like there is no communication.

I would really appreciate any and all assistance.

Much love peeps, and thanks for reading.

MAX44009 code.zip (517 KB)

If you are familiar with the GY-49package, you will know that only the VCC, GND, SDA, SCL pins are labelled, and the INT and A0 pins are not.

Correct but the traces are clearly visible and show that the pin near the mounting whole is the A0 pin.

So I have no idea which pin is A0. So it's a bit of a guess, but both slave addresses don't work.

If the resistor on the PCB side where the MAX is mounted is not populated the pin is floating which might leave it in an undefined state.

Please could you take a look at the code attached.

You're posting to an Arduino forum. I think it's not demanded to high to expect you to convert your code to the Arduino IDE if you ask for help here.
In the Arduino world I would tell you to check the return value of Wire.EndTransmission(). If you get an error there you have a wiring problem (which is currently my bet).

I measured the SCL and SDA lines on the oscilloscope, and both pins are just high all the time (3.3V) and yes, there are pull-up resistor attached. But it seems like there is no communication.

Sounds like a problem with your MCU. Try with an Arduino, then we may help you.

All in all, I think you have a hardware and not a software problem. I may be wrong but based on the information you provided (you failed to provide a wiring diagram or a link to the schematics of the GY-49) that's the most probable conclusion.

I unfortunately don’t have access to an Arduino, and can’t get my hands on one very easily at all. Did you have a look at the code? With regards to the A0 pin connection - its a little hard to tell how the pin is configured, or which pin it is for that matter, as the chip is so small. Can’t make out which pin is which. But either way, Neither address works.

Does the code look right?

I use the module you describe on Arduino and the default address as delivered is 0x4A.

I'm not familiar with PIC C code so don't know the I2C commands needed but I seems your MAX44009 init code looks correct but I'm not sure about the MAX44009_getvalue() function.

With regards to the A0 pin connection - its a little hard to tell how the pin is configured, or which pin it is for that matter, as the chip is so small. Can't make out which pin is which.

There is one pin nearest to the mounting hole, that's the A0 pin. Check if it is connected to either GND or to 3.3V. My guess is that it isn't connected at all which leaves the pin floating and the chip won't work.

The other possibility is to use an I2C scanner (I'm sure such code is also available for the PIC platform). As long as the I2C scanner doesn't return a result, you have to fix the hardware.