You have already changed the sensor declarations to TCA34725. Now you need to write the code to read from the sensors.
Before each sensor read, you must call tcaselect(n); where 'n' is the channel of the multiplexor that sensor is connected to.
Help, TCS34725
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TCS34725.h"
#define TCAADDR 0x70
Adafruit_TCS34725 tcs1 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Adafruit_TCS34725 tcs2 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
boolean getEvent(sensors_event_t*);
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
/* Initialise the 1st sensor */
tcaselect(2);
if(!tcs1.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor */
tcaselect(6);
if(!tcs2.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS detected ... Check your wiring!");
while(1);
}
}
void loop(void)
{
uint16_t r, g, b, c, colorTemp, lux;
uint16_t r2, g2, b2, c2, colorTemp2, lux2;
/* Get a new sensor event */
sensors_event_t event;
tcaselect(2);
tcs1.getEvent(&event);
tcs1.getRawData(&r, &g, &b, &c);
colorTemp = tcs1.calculateColorTemperature(r, g, b);
lux = tcs1.calculateLux(r, g, b);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #1 - ");
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
tcaselect(6);
tcs2.getEvent(&event);
tcs2.getRawData(&r2, &g2, &b2, &c2);
colorTemp2 = tcs2.calculateColorTemperature(r2, g2, b2);
lux2 = tcs2.calculateLux(r2, g2, b2);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #2 - ");
Serial.print("Color Temp: "); Serial.print(colorTemp2, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux2, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r2, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g2, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b2, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c2, DEC); Serial.print(" ");
Serial.println(" ");
delay(500);
}
Code: Select all
boolean getEvent(sensors_event_t*);
void getSensor(sensor_t*);
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Help, TCS34725
There is no getEvent for the color sensor. The color sensor library reference is here: https://learn.adafruit.com/adafruit-col ... lculations
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TCS34725.h"
#define TCAADDR 0x70
Adafruit_TCS34725 tcs1 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Adafruit_TCS34725 tcs2 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
boolean getEvent(sensors_event_t*);
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
/* Initialise the 1st sensor */
tcaselect(2);
if(!tcs1.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor */
tcaselect(6);
if(!tcs2.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS detected ... Check your wiring!");
while(1);
}
}
void loop(void)
{
uint16_t r, g, b, c, colorTemp, lux;
uint16_t r2, g2, b2, c2, colorTemp2, lux2;
/* Get a new sensor event */
tcaselect(2);
tcs1.getRawData(&r, &g, &b, &c);
colorTemp = tcs1.calculateColorTemperature(r, g, b);
lux = tcs1.calculateLux(r, g, b);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #1 - ");
tcaselect(6);
tcs2.getRawData(&r2, &g2, &b2, &c2);
colorTemp2 = tcs2.calculateColorTemperature(r2, g2, b2);
lux2 = tcs2.calculateLux(r2, g2, b2);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #2 - ");
delay(500);
}
- Attachments
-
- IMG_0814.JPG (745.35 KiB) Viewed 484 times
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Help, TCS34725
I can't see all the connections in your photo, so I don't know if it is correct.
What output do you get when you run the example code from the tutorial?
https://learn.adafruit.com/adafruit-tca ... ltiplexing
What output do you get when you run the example code from the tutorial?
https://learn.adafruit.com/adafruit-tca ... ltiplexing
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TCS34725.h"
#define TCAADDR 0x70
Adafruit_TCS34725 tcs1 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Adafruit_TCS34725 tcs2 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
boolean getEvent(sensors_event_t*);
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
/* Initialise the 1st sensor */
tcaselect(2);
if(!tcs1.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS 1 detected ... Check your wiring!");
while(1);
}
/* Initialise the 2nd sensor */
tcaselect(6);
if(!tcs2.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("Ooops, no TCS 2 detected ... Check your wiring!");
while(1);
}
}
void loop(void)
{
uint16_t r, g, b, c, colorTemp, lux;
uint16_t r2, g2, b2, c2, colorTemp2, lux2;
/* Get a new sensor event */
tcaselect(2);
tcs1.getRawData(&r, &g, &b, &c);
colorTemp = tcs1.calculateColorTemperature(r, g, b);
lux = tcs1.calculateLux(r, g, b);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #1 - ");
// Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
// Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
// Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
// Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
// Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
// Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
// Serial.println(" ");
tcaselect(6);
tcs2.getRawData(&r2, &g2, &b2, &c2);
colorTemp2 = tcs2.calculateColorTemperature(r2, g2, b2);
lux2 = tcs2.calculateLux(r2, g2, b2);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("Sensor #2 - ");
//
// Serial.print("Color Temp: "); Serial.print(colorTemp2, DEC); Serial.print(" K - ");
// Serial.print("Lux: "); Serial.print(lux2, DEC); Serial.print(" - ");
// Serial.print("R: "); Serial.print(r2, DEC); Serial.print(" ");
// Serial.print("G: "); Serial.print(g2, DEC); Serial.print(" ");
// Serial.print("B: "); Serial.print(b2, DEC); Serial.print(" ");
// Serial.print("C: "); Serial.print(c2, DEC); Serial.print(" ");
// Serial.println(" ");
delay(500);
}
I have ran the example you sent and it gives me the output that the picture i sent shows.
I think that the connections are properly made, my problem is in the code, because the arduino doesn´t detect any sensor
- Attachments
-
- FullSizeRender.jpg (737.93 KiB) Viewed 479 times
-
- FullSizeRender (1).jpg (463.61 KiB) Viewed 479 times
-
- Capture.JPG (67.21 KiB) Viewed 479 times
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Help, TCS34725
Have you tested the sensors separately without the multiplexer to make sure they are working?
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
I got it to work without the multiplexer.
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TCS34725.h"
#define TCAADDR 0x70
/* Assign a unique ID to this sensor at the same time */
Adafruit_TCS34725 tcsesquerda = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Adafruit_TCS34725 tcsdireita = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
Serial.println("TCS34725 TESTE"); Serial.println("");
/* Initialise the 1st sensor */
tcaselect(2);
if(!tcsesquerda.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("NÃO DETECTA O SENSOR DA ESQUERDA!");
while(1);
}
/* Initialise the 2nd sensor */
tcaselect(6);
if(!tcsdireita.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println("NÃO DETECTA O SENSOR DA DIREITA");
while(1);
}
/* Display some basic information on this sensor */
tcaselect(2);
tcaselect(6);
}
void loop(void)
{
uint16_t resquerda, gesquerda, besquerda, cesquerda;
uint16_t rdireita, gdireita, bdireita, cdireita;
tcsesquerda.getRawData(&resquerda, &gesquerda, &besquerda, &cesquerda);
tcsdireita.getRawData(&rdireita, &gdireita, &bdireita, &cdireita);
tcaselect(2);
if ((gesquerda > besquerda) && (gesquerda > resquerda))
{
Serial.println("VERDE esquerda");
}
else if ((resquerda > besquerda) && (resquerda > gesquerda))
{
Serial.println("VERMELHO esquerda");
}
else if ((besquerda > gesquerda) && (besquerda > resquerda))
{
Serial.println("AZUL esquerda");
}
delay(200);
tcaselect(6);
if ((gdireita > bdireita) && (gdireita > rdireita))
{
Serial.println("VERDE direita");
}
else if ((rdireita > bdireita) && (rdireita > gdireita))
{
Serial.println("VERMELHO direita");
}
else if ((bdireita > gdireita) && (bdireita > rdireita))
{
Serial.println("AZUL direita");
}
delay(200);
}
- adafruit2
- Posts: 22144
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Help, TCS34725
thats odd, but no we have no idea why it wouldnt work...if you have a logic analyzer you could try looking at the traces, see if data is passing back & forth
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Help, TCS34725
Can you post some pictures of your wiring and soldering?
- SkillezZ
- Posts: 16
- Joined: Tue Dec 22, 2015 11:06 am
Re: Help, TCS34725
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TCS34725.h"
#define TCAADDR 0x70
/* Assign a unique ID to this sensor at the same time */
Adafruit_TCS34725 tcsesquerda = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
Adafruit_TCS34725 tcsdireita = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
Serial.println("TCS34725 TESTE"); Serial.println("");
/* Initialise the 1st sensor */
tcaselect(2);
if(!tcsesquerda.begin())
{
Serial.println("DETECTA O SENSOR DA ESQUERDA!");
//while(1);
}
/* Initialise the 2nd sensor */
tcaselect(6);
if(!tcsdireita.begin())
{
/* There was a problem detecting the HMC5883 ... check your connections */
Serial.println(" DETECTA O SENSOR DA DIREITA");
//while(1);
}
}
void loop(void)
{
uint16_t resquerda, gesquerda, besquerda, cesquerda;
uint16_t rdireita, gdireita, bdireita, cdireita;
tcsesquerda.getRawData(&resquerda, &gesquerda, &besquerda, &cesquerda);
tcsdireita.getRawData(&rdireita, &gdireita, &bdireita, &cdireita);
tcaselect(2);
if ((gesquerda > besquerda) && (gesquerda > resquerda))
{
Serial.println("VERDE esquerda");
}
else if ((resquerda > besquerda) && (resquerda > gesquerda))
{
Serial.println("VERMELHO esquerda");
}
else if ((besquerda > gesquerda) && (besquerda > resquerda))
{
Serial.println("AZUL esquerda");
}
delay(200);
tcaselect(6);
if ((gdireita > bdireita) && (gdireita > rdireita))
{
Serial.println("VERDE direita");
}
else if ((rdireita > bdireita) && (rdireita > gdireita))
{
Serial.println("VERMELHO direita");
}
else if ((bdireita > gdireita) && (bdireita > rdireita))
{
Serial.println("AZUL direita");
}
delay(200);
}
We were alredy able to detect both sensors, but when we put for example a green color under 1 sensor, the other one automatically detects the same color. Our goal is to detect colors independently, in other words, we want for example the right sensor to detect green, and the left nothing or vice versa.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Help, TCS34725
You need to switch between the sensors when you get the raw data:
Code: Select all
tcaselect(2);
tcsesquerda.getRawData(&resquerda, &gesquerda, &besquerda, &cesquerda);
tcaselect(6);
tcsdireita.getRawData(&rdireita, &gdireita, &bdireita, &cdireita);
Please be positive and constructive with your questions and comments.