Introduction
I purchased a GY-30 light sensor recently, this model is also known as “BH1550FVI”. There seems no sample for this sensor on Windows 10 yet, so I tried to make one. The light sensor looks like this:
My board is a Raspberry Pi 3, the GPIO layout is shown in this table:
GPIO and pin connections
Because GY-30 is an I2C device, so we can not use GPIO to drive it directly, we must use the I2C ports. In addition, because of it’s an I2C device, it does not support hot plug. We should power off the Raspberry Pi, connect the sensor and then power on the Raspberry Pi, so that the system can identify the sensor.
The physical connections are:
- VCC – PIN01 – 3.3V
- ADO – [NONE] – Not using
- SDA – PIN 03- SDA1 I2C
- SCL – PIN 05 – SCL1 I2C
- GND – PIN 06 – Ground
Programming it all
And then we could start coding. The official sample of I2C operations on Windows 10 IoT website is this:
I2C
Pin 3 - I2C1 SDA
Pin 5 - I2C1 SCL
using Windows.Devices.Enumeration;
using Windows.Devices.I2c;
public async void I2C()
{
// Get a selector string for bus "I2C1"
string aqs = I2cDevice.GetDeviceSelector("I2C1");
// Find the I2C bus controller with our selector string
var dis = await DeviceInformation.FindAllAsync(aqs);
if (dis.Count == 0)
return; // bus not found
// 0x40 is the I2C device address
var settings = new I2cConnectionSettings(0x40);
// Create an I2cDevice with our selected bus controller and I2C settings
using (I2cDevice device = await I2cDevice.FromIdAsync(dis[0].Id, settings))
{
byte[] writeBuf = { 0x01, 0x02, 0x03, 0x04 };
device.Write(writeBuf);
}
}
There’s one thing interesting in the code, that is:
// 0x40 is the I2C device address
var settings = new I2cConnectionSettings(0x40);
So how do we get this address of “0x40”? I did some research and found every I2C devices are using different addresses. Generally, you will find it in their product manual. If you can not find it, you can use this method in Raspbian system:
Read More: GY-30 (BH1750FVI) Light Sensor with Windows 10 IoT