Jump to content

Component: Colour Sensor (Grove 101020341) (101020341) (Light): Difference between revisions

From Flowcode Help
No edit summary
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(11 intermediate revisions by 2 users not shown)
Line 5: Line 5:
|-
|-
| width="20%" style="color:gray;" | Version
| width="20%" style="color:gray;" | Version
| 1.0
| 8.0
|-
|-
| width="20%" style="color:gray;" | Category
| width="20%" style="color:gray;" | Category
Line 15: Line 15:
Based on the color sensor TCS34725FN with digital output I2C.  Based on the 8*2 array of filtered photodiodes and 16-bits analog-to-digital converters, you can gain the color chromaticity of ambient light or the color of objects.  Of the 16 photodiodes, 4 have red filters, 4 have green filters, 4 have blue filters and 4 have no filter(clear).  With the synchronization input pin, external pulsed light source can provides precise synchronous conversion control.
Based on the color sensor TCS34725FN with digital output I2C.  Based on the 8*2 array of filtered photodiodes and 16-bits analog-to-digital converters, you can gain the color chromaticity of ambient light or the color of objects.  Of the 16 photodiodes, 4 have red filters, 4 have green filters, 4 have blue filters and 4 have no filter(clear).  With the synchronization input pin, external pulsed light source can provides precise synchronous conversion control.


==Component Source Code==
==Version information==


Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_I2C_Colour_Sensor.fcfx FC_Comp_Source_I2C_Colour_Sensor.fcfx]
Library Version, Component Version, Date, Author, Info
8, 0.0, 27-06-25, MW, Not working on ESP32, changed I2C to transaction functions
 


Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_I2C_Colour_Sensor.fcfx FC_Comp_Source_I2C_Colour_Sensor.fcfx]


==Detailed description==
==Detailed description==
Line 57: Line 58:


''<span style="color:red;">No additional examples</span>''
''<span style="color:red;">No additional examples</span>''




Line 63: Line 72:
==Macro reference==
==Macro reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===CalculateLux===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ControlInterrupt'''
| width="90%" class="mtx-class-macrohead" | '''CalculateLux'''
|-
|-
| colspan="2" | Enables or Disables the Interrupt pin to fire when the light levels are inside the interrupt limits.&nbsp;
| colspan="2" | Uses the RGB values stored in RAM from the last Sample to calculate the luminance in lux.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Enable
|-
| colspan="2" | Range: 0 to 1 - 0=Interrupt Off / 1=Interrupt On&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | LowLevel
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | HighLevel
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===CalculateTemp===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetGain'''
| width="90%" class="mtx-class-macrohead" | '''CalculateTemp'''
|-
|-
| colspan="2" | Controls the gain. 0x00 = 1X 0x01 = 4X 0x02 = 16X 0x03 = 60X&nbsp;
| colspan="2" | Uses the RGB values stored in RAM from the last Sample to calculate the colour temperature in degrees Kelvin.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Setting
|-
| colspan="2" | Range: 0 to 3&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ClearInterrupt===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ClearInterrupt'''
| width="90%" class="mtx-class-macrohead" | '''ClearInterrupt'''
|-
|-
| colspan="2" | Clears the interrupt flag allowing the device to interrupt again.&nbsp;
| colspan="2" | Clears the interrupt flag allowing the device to interrupt again.&nbsp;
Line 122: Line 114:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ControlInterrupt===
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''ControlInterrupt'''
|-
| colspan="2" | Enables or Disables the Interrupt pin to fire when the light levels are inside the interrupt limits.&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Enable
|-
| colspan="2" | Range: 0 to 1 - 0=Interrupt Off / 1=Interrupt On&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CalculateTemp'''
| width="90%" | LowLevel
|-
|-
| colspan="2" | Uses the RGB values stored in RAM from the last Sample to calculate the colour temperature in degrees Kelvin.&nbsp;
| colspan="2" | &nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | HighLevel
|-
|-
| colspan="2" | &nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===DisableSensor===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''EnableSensor'''
| width="90%" class="mtx-class-macrohead" | '''DisableSensor'''
|-
|-
| colspan="2" | Powers up the device ready for taking colour readings.&nbsp;
| colspan="2" | Powers down the device to save power.&nbsp;
|-
|-
|-
|-
Line 148: Line 157:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===EnableSensor===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CalculateLux'''
| width="90%" class="mtx-class-macrohead" | '''EnableSensor'''
|-
|-
| colspan="2" | Uses the RGB values stored in RAM from the last Sample to calculate the luminance in lux.&nbsp;
| colspan="2" | Powers up the device ready for taking colour readings.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===Initialise===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SampleSensor'''
| width="90%" class="mtx-class-macrohead" | '''Initialise'''
|-
|-
| colspan="2" | Reads the raw colour channels from the sensor and stores the readings into RAM to be collected by the ReadDataChannel macro.&nbsp;
| colspan="2" | Initialise the sensor configuration as set by the component properties. Sets the default intigration time and gain as well as enable the sensor.&nbsp;
|-
|-
|-
|-
Line 174: Line 185:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===ReadDataChannel===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadDataChannel'''
| width="90%" class="mtx-class-macrohead" | '''ReadDataChannel'''
|-
|-
| colspan="2" | Returns the value of the selected colour channel from the last sample. The Red, Green and Blue channels have a colour filter to remove light of other colours. The Clear channel has no filter allowing the ambient light level to be easily collected.&nbsp;
| colspan="2" | Returns the value of the selected colour channel from the last sample. The Red, Green and Blue channels have a colour filter to remove light of other colours. The Clear channel has no filter allowing the ambient light level to be easily collected.&nbsp;
Line 192: Line 204:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===SampleSensor===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''DisableSensor'''
| width="90%" class="mtx-class-macrohead" | '''SampleSensor'''
|-
|-
| colspan="2" | Powers down the device to save power.&nbsp;
| colspan="2" | Reads the raw colour channels from the sensor and stores the readings into RAM to be collected by the ReadDataChannel macro.&nbsp;
|-
|-
|-
|-
Line 205: Line 218:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===SetGain===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetIntegrationTime'''
| width="90%" class="mtx-class-macrohead" | '''SetGain'''
|-
|-
| colspan="2" | Controls the integration time. 0 = 700mS / 1 = 154mS / 2 = 101mS / 3 = 50mS / 4 = 24mS / 5 = 2.4mS&nbsp;
| colspan="2" | Controls the gain. 0x00 = 1X 0x01 = 4X 0x02 = 16X 0x03 = 60X&nbsp;
|-
|-
|-
|-
Line 216: Line 230:
| width="90%" | Setting
| width="90%" | Setting
|-
|-
| colspan="2" | Range: 0 to 5&nbsp;
| colspan="2" | Range: 0 to 3&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 223: Line 237:




{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===SetIntegrationTime===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
| width="90%" class="mtx-class-macrohead" | '''SetIntegrationTime'''
|-
|-
| colspan="2" | Initialise the sensor configuration as set by the component properties. Sets the default intigration time and gain as well as enable the sensor.&nbsp;
| colspan="2" | Controls the integration time. 0 = 700mS / 1 = 154mS / 2 = 101mS / 3 = 50mS / 4 = 24mS / 5 = 2.4mS&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Setting
|-
|-
| colspan="2" | Range: 0 to 5&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




==Property reference==
==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
|-
|-
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Sensor Settings
| width="90%" class="mtx-class-propfolder" | Sensor Settings
|-
|-
|-
|-
Line 260: Line 278:
| colspan="2" | Length of time period used to sample the sensor frequency (longer is more accurate)&nbsp;
| colspan="2" | Length of time period used to sample the sensor frequency (longer is more accurate)&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | I2C Settings
| width="90%" class="mtx-class-propfolder" | Connections
|-
|-
|-
|-
Line 270: Line 288:
|-
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | Baud Select
| width="90%" | Mode
|-
| colspan="2" | Baud rate option selector&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]]
| width="90%" | Baud Rate
|-
| colspan="2" | Baud rate to be used&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| colspan="2" | Defines if the component will be used for Master or Slave communications. Master mode supports a software bitbanged I2C channel. Slave mode requires a hardware I2C peripheral to catch the communications from the Master.&nbsp;
| width="90%" | Stop Delay
|-
| colspan="2" | On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not a 10ms delay between an I2C stop event and the next I2C start event. Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications. &nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
Line 288: Line 296:
|-
|-
| colspan="2" | Pin used for SDA (data signal)&nbsp;
| colspan="2" | Pin used for SDA (data signal)&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | SDA Remap Pin
|-
| colspan="2" | &nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
Line 294: Line 307:
| colspan="2" | Pin used for SCL (clock signal)&nbsp;
| colspan="2" | Pin used for SCL (clock signal)&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| width="90%" | SCL Remap Pin
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" class="mtx-class-propfolder" | Simulation
|-
|-
|-
|-
Line 303: Line 321:
| colspan="2" | Selects the simulation type for the component. Component GUI - Interacts with the panel to sense the colour of a object in close proximity to the sensor. I2C Injector - Performs the I2C commands allowing you to connect an injector component or view and debug the I2C communications.&nbsp;
| colspan="2" | Selects the simulation type for the component. Component GUI - Interacts with the panel to sense the colour of a object in close proximity to the sensor. I2C Injector - Performs the I2C commands allowing you to connect an injector component or view and debug the I2C communications.&nbsp;
|}
|}
==Component Source Code==
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx]
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx]

Latest revision as of 14:37, 13 July 2026

Author Matrix TSL
Version 8.0
Category Light


Colour Sensor (Grove 101020341) component

Based on the color sensor TCS34725FN with digital output I2C. Based on the 8*2 array of filtered photodiodes and 16-bits analog-to-digital converters, you can gain the color chromaticity of ambient light or the color of objects. Of the 16 photodiodes, 4 have red filters, 4 have green filters, 4 have blue filters and 4 have no filter(clear). With the synchronization input pin, external pulsed light source can provides precise synchronous conversion control.

Version information

Library Version, Component Version, Date, Author, Info
8, 0.0, 27-06-25, MW, Not working on ESP32, changed I2C to transaction functions
 


Detailed description

No detailed description exists yet for this component

Examples

No additional examples







Macro reference

CalculateLux

CalculateLux
Uses the RGB values stored in RAM from the last Sample to calculate the luminance in lux. 
- UINT Return


CalculateTemp

CalculateTemp
Uses the RGB values stored in RAM from the last Sample to calculate the colour temperature in degrees Kelvin. 
- UINT Return


ClearInterrupt

ClearInterrupt
Clears the interrupt flag allowing the device to interrupt again. 
- VOID Return


ControlInterrupt

ControlInterrupt
Enables or Disables the Interrupt pin to fire when the light levels are inside the interrupt limits. 
- BYTE Enable
Range: 0 to 1 - 0=Interrupt Off / 1=Interrupt On 
- UINT LowLevel
 
- UINT HighLevel
 
- VOID Return


DisableSensor

DisableSensor
Powers down the device to save power. 
- VOID Return


EnableSensor

EnableSensor
Powers up the device ready for taking colour readings. 
- VOID Return


Initialise

Initialise
Initialise the sensor configuration as set by the component properties. Sets the default intigration time and gain as well as enable the sensor. 
- VOID Return


ReadDataChannel

ReadDataChannel
Returns the value of the selected colour channel from the last sample. The Red, Green and Blue channels have a colour filter to remove light of other colours. The Clear channel has no filter allowing the ambient light level to be easily collected. 
- BYTE ColourChannel
Range: 0 to 3 - 0=Red, 1=Green, 2=Blue, 3=Clear 
- UINT Return


SampleSensor

SampleSensor
Reads the raw colour channels from the sensor and stores the readings into RAM to be collected by the ReadDataChannel macro. 
- VOID Return


SetGain

SetGain
Controls the gain. 0x00 = 1X 0x01 = 4X 0x02 = 16X 0x03 = 60X 
- BYTE Setting
Range: 0 to 3 
- VOID Return


SetIntegrationTime

SetIntegrationTime
Controls the integration time. 0 = 700mS / 1 = 154mS / 2 = 101mS / 3 = 50mS / 4 = 24mS / 5 = 2.4mS 
- BYTE Setting
Range: 0 to 5 
- VOID Return


Property reference

Properties
Sensor Settings
Integration Time
Length of time period used to sample the sensor frequency (longer is more accurate) 
Gain
Length of time period used to sample the sensor frequency (longer is more accurate) 
Connections
Channel
Channel selection 
Mode
Defines if the component will be used for Master or Slave communications. Master mode supports a software bitbanged I2C channel. Slave mode requires a hardware I2C peripheral to catch the communications from the Master. 
SDA
Pin used for SDA (data signal) 
SDA Remap Pin
 
SCL
Pin used for SCL (clock signal) 
SCL Remap Pin
 
Simulation
Simulation Type
Selects the simulation type for the component. Component GUI - Interacts with the panel to sense the colour of a object in close proximity to the sensor. I2C Injector - Performs the I2C commands allowing you to connect an injector component or view and debug the I2C communications. 

Component Source Code

Please click here to download the component source project: FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_Colour_Sensor_I2C_Grove.fcfx