Accelerometer or Hall Switch

Ok, so further to my comment above, the missing piece is that pin 9 on the ioexpander is an disable pin for the RBG sensor. It needs to be configured for output and set to 0 before the sensor will respond.

This seems to do the trick. It reads in the pin 9 values, tweaks them to set the direction and the level and then writes them back.
i2c.write(i2c_ioexp, format("%c%c", 0x0E, i2c.read(i2c_ioexp, “\x0E”, 1)[0] & ~0x2));
i2c.write(i2c_ioexp, format("%c%c", 0x10, i2c.read(i2c_ioexp, “\x10”, 1)[0] & ~0x2));

A.

Not really working for me, just getting the same constants even when I cover up the sensor or shine a light on it.

From what I can tell, that code is supposed to work for reading the red sensor, and they tried to loop it for other colors, but I’m getting constants for the other values.

Also, where do those two lines go?

What about all the calibration and setup code from the original Arduino example? At first I only wanted something basic like on or off with threshold, but after waiting for a year there’s still nothing like the original that can measure colors?

Oops, I forgot to add those two lines to the gist, which I have now done. They are addressing the io expander, so I put them just after the reset on line 25/26.

As for tuning it, thats for you guys to do. Ammaree just wanted to get over the hump.

@aron thanks for the contribution.

TYPO: the ( color < 1) should have been (color << 1) because the color intensity value is 12 bits wide (ie 2 registers) hence for any color > RED we need to adjust the register index by value of 2 not 1.

Value of color steps 0-1-2-3 but register index must step 0-2-4-6

Have fixed that now values start to make sense. Will continue on the calibration bit.

@sbright. Rather than continuing to complain in forums topics all over about the lack of RGB code (1 year later), why not take Hugo’s suggestion and start writing some…

Thanks @aron and @ammaree. I fixed a bug (the last gist had the read blue function reading green), and copied the sensor read function from the init into the main loop, because, as @ammaree said, we need to adjust the register index by a value of 2, not 1.

Also, do you guys know what units the readings are in? It’s intensity of R,G,B colors, I’m guessing, but what’s clear? Is it overall brightness?

So theoretically, if I put a bright red light against the sensor, it’d be R:300,G:0,B:0,C:300?

That would be silly since you’re doing such a great job all of you! I’m in the middle of another project I’ll get back to this shortly. The point I was trying to make was so that you don’t duplicate the effort of the existing Arduino code from 2012.