-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDP_RGB.py
More file actions
30 lines (26 loc) · 862 Bytes
/
UDP_RGB.py
File metadata and controls
30 lines (26 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import smbus
import time
bus = smbus.SMBus(1)
def readRGB():
# I2C address 0x29
# Register 0x12 has device ver.
# Register addresses must be OR'ed with 0x80
bus.write_byte(0x29,0x80|0x12)
ver = bus.read_byte(0x29)
# version # should be 0x44
if ver == 0x44:
print "Device found\n"
bus.write_byte(0x29, 0x80|0x00) # 0x00 = ENABLE register
bus.write_byte(0x29, 0x01|0x02) # 0x01 = Power on, 0x02 RGB sensors enabled
bus.write_byte(0x29, 0x80|0x14) # Reading results start register 14, LSB then MSB
while True:
data = bus.read_i2c_block_data(0x29, 0)
clear = clear = data[1] << 8 | data[0]
red = data[3] << 8 | data[2]
green = data[5] << 8 | data[4]
blue = data[7] << 8 | data[6]
crgb = "C: %s, R: %s, G: %s, B: %s\n" % (clear, red, green, blue)
print crgb
time.sleep(1)
else:
print "Device not found\n"