The TCS3472 based color sensor GY-33 comes only with minimal public documentation, luckily QuirkyCort created the micropython-gy33 library from some chinese documentation.
from pupremote import PUPRemoteSensor
from machine import Pin, UART
from neopixel import NeoPixel
from gy33_uart import GY33_UART # copy from https://github.com/QuirkyCort/micropython-gy33/blob/main/gy33-uart/gy33_uart.py
np = NeoPixel(Pin(25), 1) # onboard neopixel
np[0] = (255, 255, 0); np.write() # yellow = int
# connect GY-33 DR pin to LMS-ESP32 tx, CT pin to rx, VCC to 5V or 3.3V
gy33 = GY33_UART(UART(1, baudrate=115200, rx=Pin(20), tx=Pin(19))) # or pin 4,5 or ...
# initially connect with baudrate=9600 and execute gy33.set_baudrate(115200) once.
# this switches the baud rate _permanently_ to 115k2 on next power on
#gy33.set_baudrate(115200)
gy33.set_integration_time(100) # raw values are proportional to integration time
gy33.set_output(raw=True, lcc=False, processed=False) # speed up by disabling other responses
gy33.set_led(10)
if not gy33.update(wait=1000): # connection check
np[0] = (255, 0, 0); np.write() # red = error
raise RuntimeError('gy33 not responding')
def gyGet():
return tuple(gy33.get_raw())
def gyLed(v):
gy33.set_led(v)
def gyTim(v):
gy33.set_integration_time(v)
rs = PUPRemoteSensor(power=True)
rs.add_command('gyGet', 'HHHH') # values 0~6000
rs.add_command('gyLed', '', 'B') # value 0-10
rs.add_command('gyTim', '', 'B') # value 24,100,...
np[0] = (0, 0, 255); np.write() # blue = wait for spike
rs.process()
np[0] = (0, 255, 0); np.write() # green = ready
while True:
rs.process()
gy33.update() # read raw value
from pybricks.pupdevices import ColorSensor
from pybricks.parameters import Port
from pybricks.tools import wait, StopWatch
from pupremote_hub import PUPRemoteHub # copy from https://github.com/antonvh/PUPRemote/blob/main/src/pupremote_hub.py
import gy33_color # copy from example folder
sw = StopWatch()
cs = ColorSensor(Port.F)
rh = PUPRemoteHub(Port.E)
rh.add_command('gyGet', 'HHHH')
rh.add_command('gyLed', '', 'B')
rh.add_command('gyTim', '', 'B')
rh.call('gyLed', 10)
while True:
gyRaw = rh.call('gyGet') # GY-33 color sensor
csHsv = cs.hsv() # Lego color sensor
csCol = cs.color()
gyHsv = gy33_color.rgbc_to_hsv_Color(*gyRaw)
gyCol = gy33_color.hsv_to_standard_Color(gyHsv)
print(sw.time(), csHsv, csCol, '--', gyRaw, gyHsv, gyCol, sep=', ')
and create gy33_color.py with content from this repo.
t.b.d.
QuirkyCort. This first communicates with the microcontroller on the back of the board which then communicates with the TCS3472. Could try the other pins to directly communicate with the TCS3472 with a different library