Uncategorized

rgb sensor board testing notes

 Can’t read RGBC data from TCS34725 RGB Sensor using AVR and Atmega16

nowsqwhatFor my project, I need to read the RGBC data from a TCS34725 RGB Sensor using the Atmega16 and AVR. It should be able to classify between the colors Red, Green, Blue and Clear light. Therefore I made a TCS library, with routines to enable and init the gain and integration time of the sensor, as w…

sensor avr embedded atmega rgb

tlfong01

tlfong01

7520

may be the sensor is defective.

Are you playing with the bare chip, or a completely assembled module? Chip reference: TCS3472 COLOR LIGHT-TO-DIGITAL CONVERTER with IR FILTER Datasheet- TAOS cdn-shop.adafruit.com/datasheets/TCS34725.pdf

If you are using a module, is it a high quality AddAfruit, or a not always reliable cheapie eBay? AdaFruit reference: RGB Color Sensor with IR filter and White LED module (Discontinued) – TCS34725 AdaFruit US$8 adafruit.com/product/1334

nowsqwhat

nowsqwhat

I am doing it with the full assembled TCS34725 module like from Adafruit.

I am using a bad board (from my school) with no I2C PullUps, could it be that?

tlfong01

tlfong01

@nosqwhar: Thanks a lot for your confirmation. (1) It is good that that you are using the AdaFruit’s fully assembled (and usually well test) module. (2) Question: Have you used any utility or short test program to confirm that the I2C module can be detected?

nowsqwhat

nowsqwhat

@tlfong01 I used an Oscilloscope and measured both the SCL and SDA signals. They don’t look that good because of the missing pullUps. I tried reading from the Sensor with a Raspberry Pi Pico, which worked extremely well. However, I don’t get it working the Atmega16.

tlfong01

tlfong01

7520

@nosqwhar: If the module can be detected then, (3) have you used your read/write function to confirm you can read any register and read it back? (4) I would suggest to first test the 0x00 Enable Register. You can write any random value, say 0x5b to it and see if you can then read it back, (5) If above test is OK, you can enable the detect operation and perhaps also the interrupt thing. (6) If your school has a osciiloscope, you can then see if the module output any interrupt signal if you (a) power on module, (b) switch on any clear LED.

@nowsqwhat Ah, how nice you have a scope and also a Rpi Pico. I also have a PicoW and a very old version of RGBC sensor, lying in my junk box collecting dust. But I think we first test your current setup and only go to PicoW. Question: are you OK using Thonny python?

I am not using the expensive AdaFruit color sensor but the cheapy AliExpress like Tao version:

(1)
TCS34725 Low Power IR Blocking Filter RGB Light Color Sensor Recognition – AliExpress, HK$16
aliexpress.com/item/…

(2)

TCS34725 I2C RGB Color Sensing Module – TaoBao ¥8
item.taobao.com/…

(3)
RGB Color Sensor with IR filter and White LED – TCS34725 AdaFruit US$8
adafruit.com/product/1334

I skimmed the AdaFruit tutorial (learn.adafruit.com/…) but did not see them mentioning adding I2C pullups. But you can add (extra) 4k7 pullups (it usually won’t harm the Arduino or Pico on board I2C hardware.

tlfong01

tlfong01

7520

Sun 16:05

My Tao RGBC sensor’s schematic (has on module 10k pullups).

user image

Suggestion: Perhaps you can try to detect any other I2C devices to make sure if your current setup can detect I2C devices.

Ah, I need to go now for weekend shopping. So see you tomorrow or day after tomorrow. Good luck to your project. Cheers.

2 hours later…

nowsqwhat

nowsqwhat

Sun 17:38

Thanks for the answers! The I2C Bus is defect on the Board, so I guess I will just go with the Pico for my Project. Just figured it out.

2 hours later…

tlfong01

tlfong01

7520

Sun 20:07

@nowsqwhat Good. So we can testing the RGB sensor together using Pico and python.

Let me refresh my memory by skimming through some old references.

# *** References ***
# (1) Using I2C devices with Raspberry PI Pico and MicroPython – peppe, 2021may30
#       peppe8o.com/…
# (2) Raspberry Pi Pico (RP2040) I2C Example with MicroPython – Digikey
#       digikey.hk/en/maker/projects/…
# (3) MicroPython I2C – Micropython.org
#       docs.micropython.org/en/…

(see full text)

And my old test program to scan i2c devices on i2c bus #1.

import machine

# *** Config ***

# Create I2C object for I2C#1

i2c1 = machine.I2C(1, scl = machine.Pin(7), sda = machine.Pin(6), freq = 100000)

# *** Functions ***

def scanI2c1():
    # Print out any addresses found
    devices = i2c1.scan()

    if devices:
        for d in devices:
            print(hex(d))
    return

# ***Sample output ***

'''
>>> %Run -c $EDITOR_CONTENT
0x60
>>>
'''

The color sensor module’s i2c address is 0x29. So the above scan program should return 0x29.

Now I am reading my old write/read device register functions and see if I can write a control byte to a register and read it back.

# ### Functions ###
def reg_write(i2c, addr, reg, data):
    msg = bytearray()
    msg.append(data)
    i2c.writeto_mem(addr, reg, msg)
    return

def reg_read(i2c, addr, reg, nbytes=1):
    data = i2c.readfrom_mem(addr, reg, nbytes)
    return data

Now I am googling the Waveshare’s user manual for some Rpi demo programs.

***TCS34725 Color Sensor User Manual*** – WaveShare
waveshare.com/w/upload/b/bb/…

Bad news. I found WaveShare’s user manual dated 2019 uses WiringPi is no longer supported, not to mention that it is not Pico Thonny microPython compatible. So we need to DIY our own functions: (1) scan i2c device, (2) read register, (3) write register, …

tlfong01

tlfong01

7520

Sun 20:53

Placing an order to TaoBao. I found one TaoBao shop selling a nicely looking toy. So I just placed an order. The toy should arrive in a couple of days.

TCS34725 Colour Sensor Module – TaoBao ¥10
item.taobao.com/…

tlfong01

tlfong01

7520

Sun 21:05

(removed)

The old one marked TCS3472 costs 8 Yuan. The new one marked TCS34725 costs 10 Yuan.

user image

tlfong01

tlfong01

7520

Sun 21:53

Now I am watching two YouTube tutorials.

(1) Colour Sensor Shoot-Out – Part 3 (Parts 1, 2 not for this module) – TCS34725 – Unexpected Msaker
youtube.com/…

(2) Adafruit TCS34725 Color Sensor with OLED Display Demo – Jon E. Froehlich
youtube.com/…

15 hours later…

tlfong01

tlfong01

7520

yst 12:50

TCS3472 Programming Cheat Sheet.

(1) TCS3472 COLOR LIGHT-TO-DIGITAL CONVERTER with IR FILTER Datasheet – TAOS, AdaFruit, 2012Aug
cdn-shop.adafruit.com/…

(2) TCS3472 Color Light-to-Digital Converter with IR Filter Product Sheet – AMS, Osram, 2020Apr10
ams.com/documents/20143/36005/…

user image

1 day later…

tlfong01

tlfong01

7520

14:25

TCS3742 Programming Cheat Sheet.

user image

user image

user image

user image

Initial test functions spec v0.1.

1. Scan I2C device functions.

2. Read/Write Device Register functions.

3. Setup device functions.

TCS3472 Color Light-to-Digital Converter with IR Filter Datasheet – AMS Osram, 2020apr10
ams.com/documents/20143/36005/…

tlfong01

tlfong01

7520

14:46

TCS3472 No Interrupt Functions. RGB functions can be divided into two kinds: with interrupts or without interrupts. I would first consider no interrupt functions.

user image

I would first test the basic registers: 0x00 Enable and 0x12 Device ID.

5 hours later…

tlfong01

tlfong01

7520

20:13

Now I have created a RGB test board CircuitLab schematic for everybody to use. The URL is: circuitlab.com/circuit/…

The following jpg image is extracted from the above CircuitLab schematic.

user image

tlfong01

tlfong01

7520

20:31

I ordered my RGB sensor TCS34725 at TaoBao on Jan29 evening, and the toy has already arrived today Jan31 afternoon. So I will go tomorrow to collect it.

SF ExpressDelivery tracking record (ShenZhen to HongKong takes two working days)

顺丰速运 SF1676667712977
01-31 待取件
今天 16:36 快件已投放至 [顺丰智能柜H852Dxxxx]
今天 16:03 快件到达 荔枝角時豐中心營業點(網點不對外開放)
今天 15:46 快件已发车
今天 14:35 快件到达 香港青衣中轉場
今天 10:59 快件已发车
今天 10:23 快件在 深圳后瑞集散点 完成分拣,准备发往 香港青衣中轉場,
今天 09:38 快件到达 深圳后瑞集散点
今天 06:44 快件已发车
昨天 23:54 快件在 深圳和记中转场 完成分拣,准备发往 深圳后瑞集散点,...
昨天 22:25 快件到达 深圳和记中转场
昨天 20:51 快件在 深圳龙岗华南城营业点 完成分拣,准备发往  深圳和记中转场
昨天 20:26 顺丰速运 已收取快件
昨天 18:52 顺丰速运 已收取快件
昨天 09:07 包裹正在等待揽收
昨天 09:07 您的包裹已出库
昨天 09:02 您的订单开始处理
01-29 21:57 商品已经下单

Now I have started writing the preliminary test function for the RGB sensor board.

tlfong01

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.