Stephan NollerMatthias L. Jugel
Published © CC BY

Farbsensor über I2C/Grove auslesen

Mit dem ISL29125 RGB-Farbsensor können Farbwerte gelesen werden. Diese werden über die eingebaute RGB-LED wieder ausgegeben.

IntermediateProtip1 hour651
Farbsensor über I2C/Grove auslesen

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1
sparkfun isl29125 RGB Sensor
×1

Story

Read more

Code

ISL29125 RGB Sensor

JavaScript
let blue = 0
let green = 0
let red = 0
basic.forever(() => {
    serial.writeString("[")
    // read register 0x0c (RED)
    pins.i2cWriteNumber(68, 12, NumberFormat.UInt8BE)
    red = pins.i2cReadNumber(68, NumberFormat.UInt8BE)
    serial.writeNumber(red)
    serial.writeString(",")
    // read register 0x0a (GREEN)
    pins.i2cWriteNumber(68, 10, NumberFormat.Int8BE)
    green = pins.i2cReadNumber(68, NumberFormat.UInt8BE)
    serial.writeNumber(green)
    serial.writeString(",")
    // read register 0x0e (BLUE)
    pins.i2cWriteNumber(68, 14, NumberFormat.UInt8BE)
    blue = pins.i2cReadNumber(68, NumberFormat.UInt8BE)
    serial.writeNumber(blue)
    serial.writeLine("]")
    basic.setLedColor(basic.rgbw(
        red,
        green,
        blue,
        0
    ))
    basic.pause(1000)
})
serial.writeLine("I2C ISL 29125")
// send to 0x44, register 0x00, value 0x46 (RESET
// ISL29125)
pins.i2cWriteNumber(68, 70, NumberFormat.UInt16BE)
// send to 0x44, register 0x01, value 0x05 (GRB
// SAMPLING)
pins.i2cWriteNumber(68, 261, NumberFormat.UInt16BE)

Credits

Stephan Noller

Stephan Noller

7 projects • 10 followers
Contact
Matthias L. Jugel

Matthias L. Jugel

4 projects • 7 followers
Hacker, dad. I flash devices for fun. Mostly stuff works for me...
Contact

Comments