Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:emb9b_1 [2024/03/06 14:45] – [Suggested Readings and Knowledge Resources] pczekalskien:iot-open:practical:hardware:sut:esp32:emb9b_1 [2025/04/28 20:34] (current) – [FAQ] pczekalski
Line 1: Line 1:
 ====== EMB9B: Reading colour sensor ===== ====== EMB9B: Reading colour sensor =====
-A colour sensor (TCS 34725) can detect the brightness and colour of the light emitted. It works with the I2C; in our laboratory, each sensor has a fixed 0x29 address in the I2C bus. The sensor is in the black enclosure, ensuring no ambient light impacts readings. The only light source is an RGB LED, controlled as described in the scenario [[en:iot-open:practical:hardware:sut:esp32:emb9b_1|]]. This is another LED connected parallel to the one you can observe in the camera.+A colour sensor (TCS 34725) can detect the brightness and colour of the light emitted. It works with the I2C; in our laboratory, each sensor has a fixed 0x29 address in the I2C bus. The sensor is in the black enclosure, ensuring no ambient light impacts readings. The only light source is an RGB LED, controlled as described in the scenario [[en:iot-open:practical:hardware:sut:esp32:emb9a_1|]]. This is another LED connected parallel to the one you can observe in the camera.
  
 ===== Prerequisites ===== ===== Prerequisites =====
-To implement this scenario, it is necessary to get familiar with the following scenarios first:+To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:
   * [[en:iot-open:practical:hardware:sut:esp32:emb5_1|]],   * [[en:iot-open:practical:hardware:sut:esp32:emb5_1|]],
 +  * [[en:iot-open:practical:hardware:sut:esp32:emb6_1|]],
 +  * [[en:iot-open:practical:hardware:sut:esp32:emb7_1|]],
 +and obligatory:
   * [[en:iot-open:practical:hardware:sut:esp32:emb9a_1|]].   * [[en:iot-open:practical:hardware:sut:esp32:emb9a_1|]].
  
Line 47: Line 50:
  
 === Step 2 === === Step 2 ===
-Declare and instantiate TCS controller class and related variables for readings:+Declare and instantiate the TCS controller class and related variables for readings:
 <code c> <code c>
 +#define SCL 4
 +#define SDA 5
 +
 static Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_300MS, TCS34725_GAIN_1X); static Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_300MS, TCS34725_GAIN_1X);
 uint16_t r, g, b, c, colorTemp, lux; uint16_t r, g, b, c, colorTemp, lux;
Line 54: Line 60:
 </code> </code>
 A word of explanation regarding the parameters:  A word of explanation regarding the parameters: 
-  * ''TCS34725_INTEGRATIONTIME_300MS'' is time in ms while the TCS sensor is exposed for the light to grab readings,+  * ''TCS34725_INTEGRATIONTIME_300MS'' is the time in ms while the TCS sensor is exposed for the light to grab readings,
   * ''TCS34725_GAIN_1X'' is the sensor's gain - it helps reading in low light, but that is not true in our lab as our RGB LED light sensor is very bright, even in low duty cycle.   * ''TCS34725_GAIN_1X'' is the sensor's gain - it helps reading in low light, but that is not true in our lab as our RGB LED light sensor is very bright, even in low duty cycle.
  
Line 62: Line 68:
 Initialise the sensor (in ''void Setup()'') and check it is OK: Initialise the sensor (in ''void Setup()'') and check it is OK:
 <code c> <code c>
 +  Wire.begin(SDA,SCL);
 +  delay(100);
 +  ...
 +
   isTCSOk = tcs.begin();   isTCSOk = tcs.begin();
 </code> </code>
-You communicate with TCS sensor via I2C interface. In standard and typical configurations there is no need to instantiate ''Wire'' I2C communication stack explicitly, neither provide default I2C address of the TCS sensor (0x29) so ''begin'' is parameterless. Other overloaded functions for the ''begin'' let you provide all technical parameters.+You communicate with the TCS sensor via the I2C interface. In standard and typical configurationsthere is no need to instantiate the ''Wire'' I2C communication stack explicitly, nor provide default I2C address of the TCS sensor (0x29)so ''begin'' is parameterless. Other overloaded functions for the ''begin'' let you provide all technical parameters. 
 + 
 +<note important>You need to initialise the I2C bus only once. If you're using other I2C devices in parallel, do not call ''Wire.begin(...)'' multiple times.</note>
  
 === Step 4 === === Step 4 ===
-Besides reading raw values for channels R, G, B and C, the ''tcs'' controller class provides additional functions to calculate color temperature (in K) and color intensity in Luxes.+Besides reading raw values for channels R, G, B and C, the ''tcs'' controller class provides additional functions to calculate colour temperature (in K) and colour intensity in Luxes.
  
 To read, use the following code: To read, use the following code:
Line 84: Line 96:
  
 ===== FAQ ===== ===== FAQ =====
-**What is the range of the values for the integration time of the TCS sensor?**:+**What is the range of the values for the //integration time// of the TCS sensor?**:
 <code c> <code c>
 #define TCS34725_INTEGRATIONTIME_2_4MS                                         \ #define TCS34725_INTEGRATIONTIME_2_4MS                                         \
Line 126: Line 138:
 </code> </code>
  
-**What is the range of the values for the gain of the TCS sensor?**:+**What is the range of the values for the //gain// of the TCS sensor?**:
 <code c> <code c>
 typedef enum { typedef enum {
Line 136: Line 148:
 </code> </code>
  
-**C channel reading is 0 and R, G or B readings are not reasonable**It is possibly because overdrive of the sensor with a light source (too bright). Consider lowering the RGB LED's intensity or change sensor's integration time and gain (shorter time, lower gain).+**C channel reading is 0and R, G or B readings are unreasonable.** It is possibly because of overdriving the sensor with a light source (too bright). Consider lowering the RGB LED's intensity or changing the sensor's integration time and gain (shorter time, lower gain).
  
 +<WRAP noprint>
 ===== Project information ===== ===== Project information =====
 {{:en:iot-open:logo_iot_200_px.png?200|}}\\ {{:en:iot-open:logo_iot_200_px.png?200|}}\\
Line 154: Line 167:
 {{:en:iot-open:ccbync.png?100|}} {{:en:iot-open:ccbync.png?100|}}
 </figure> </figure>
 +</WRAP>
en/iot-open/practical/hardware/sut/esp32/emb9b_1.1709736302.txt.gz · Last modified: 2024/03/06 14:45 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0