I am designing a device with several different sensors on a single I2C, including the TCS34725 and TMP006.
The problem is it doesn't seem like you can use both TCS and TMP006 libraries at the same time, since they both affect wire. And if you want to use another device that uses wire, it doesn't work anymore because wire is affected by tcs or tmp006.
I know that I could combine the libraries by rewriting them, but that's a bit of a pain. Just wondering if anyone has any experience making these things all work together without lots of recoding.
Thanks,
Greg
Use of TCS34725, TMP006 in a single sketch using Teensy 3.0
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- gbathree
- Posts: 4
- Joined: Sat Jan 28, 2012 6:41 pm
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
I'm not sure what you mean by "affect wire". I2C is a bus - you can have multiple I2C devices attached to the same two pins.
- gbathree
- Posts: 4
- Joined: Sat Jan 28, 2012 6:41 pm
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
Sorry... yes I'm aware I can have multiple devices on the same data and clock pins. I mean when you try to use Wire.begin and tcs.begin and tmp006.begin all in the same file, the Teensy 3.0 locks up during void setup() (see code below, the serial statements are just for debugging). I know that you can use tmp and tcs without adafruit's libraries (that is, just using wire instead), but they make things particularly easy. So has anyone else had this experience on this or suggestions on how to utilize all of these libraries at the same time? Is there some other workaround I'm not thinking of?
Code: Select all
delay(3000);
Serial.begin(115200); // set baud rate for Serial communication to computer via USB
Serial.println("Serial works");
Serial1.begin(115200); // set baud rate for bluetooth communication on pins 0,1
Serial.println("Serial1 works");
Serial3.begin(9600);
Serial.println("Serial3 works");
Wire.begin(); // This causes the actinic light not to flash, and
Serial.println("Wire works");
tcs.begin(); // tcs.begin put here causes teensy 3.0 to lock up
Serial.println("TCS works");
tmp006.begin();
Serial.println("tmp works");
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
First of all, there's no need to call Wire.begin, as tcs.begin() and tmp006.begin() both also call Wire.begin.
And that's where I'm guessing the problem is. tcs.begin does some wire writes, which will complete asynchronously. Meanwhile, tmp006.begin reinitializes everything by calling Wire.begin again.
Try putting a delay in between tcs.begin() and tmp006.begin(). If that doesn't help, then try editing the begin function in the TMP006 library to comment out the call to Wire.begin.
And that's where I'm guessing the problem is. tcs.begin does some wire writes, which will complete asynchronously. Meanwhile, tmp006.begin reinitializes everything by calling Wire.begin again.
Try putting a delay in between tcs.begin() and tmp006.begin(). If that doesn't help, then try editing the begin function in the TMP006 library to comment out the call to Wire.begin.
- gbathree
- Posts: 4
- Joined: Sat Jan 28, 2012 6:41 pm
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
Yep ok - that makes sense. I probably could have figured that it but it would have taken hours and hours. I'll try it out tomorrow and report back -
Thanks!
Greg
Thanks!
Greg
- paulstoffregen
- Posts: 444
- Joined: Sun Oct 11, 2009 11:23 am
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
One other thing to check is that you have pullup resistors. On Teensy 3.0, real pullup resistors are required on SDA and SCL. 4.7K is recommended, but 10k to 1K works fine. With AVR-based Arduino, you can get away with no real pullup resistors because weak pullups on the chip are used. On Teensy 3.0, real pullup resistors are required.
If the pullup resistors are missing, either SDA or SCL can remain low, which indicates a bus busy condition. The Wire library will wait forever, which appears as a lockup similar to what you've described.
If that doesn't fix this problem, please post it as a bug report here:
http://forum.pjrc.com/forums/4-Suggesti ... ug-Reports
Your bug report MUST include a complete program and direct links to the exact libraries you're using, and any other details needed to exactly reproduce the problem.
If the pullup resistors are missing, either SDA or SCL can remain low, which indicates a bus busy condition. The Wire library will wait forever, which appears as a lockup similar to what you've described.
If that doesn't fix this problem, please post it as a bug report here:
http://forum.pjrc.com/forums/4-Suggesti ... ug-Reports
Your bug report MUST include a complete program and direct links to the exact libraries you're using, and any other details needed to exactly reproduce the problem.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
The TMP006 has pullups, and I believe the TCS34725 does as well.
You should also make sure your jumper connections are good. How long are your jumper wires?
You should also make sure your jumper connections are good. How long are your jumper wires?
- gbathree
- Posts: 4
- Joined: Sat Jan 28, 2012 6:41 pm
Re: Use of TCS34725, TMP006 in a single sketch using Teensy
Just wanted to follow up to close this out. I still need to include all of the relevant libraries at the top of the file, but just opening wire through tmp006.begin() works - so you don't need to also call tcs.begin() or wire.begin(). See code below for example:
We also learned something else pretty interesting about the tmp006. We're installing the chip directly onto our board, but we bought a few Adafruit versions so we had a known control to compare to. Well, we found that without silk screen directly beneath the tmp006 (ie just using copper proto boards) you get nonsense answers (see the discussion on the TI forum here: http://e2e.ti.com/support/other_analog/ ... 00344.aspx). So it's important, because the tmp006 uses a comparator sensor on the bottom of the chip, that the material beneath the chip has high emissivity.
Thanks everyone for your help -
Greg
We also learned something else pretty interesting about the tmp006. We're installing the chip directly onto our board, but we bought a few Adafruit versions so we had a known control to compare to. Well, we found that without silk screen directly beneath the tmp006 (ie just using copper proto boards) you get nonsense answers (see the discussion on the TI forum here: http://e2e.ti.com/support/other_analog/ ... 00344.aspx). So it's important, because the tmp006 uses a comparator sensor on the bottom of the chip, that the material beneath the chip has high emissivity.
Thanks everyone for your help -
Greg
Code: Select all
void setup() {
delay(3000);
Serial.begin(115200); // set baud rate for Serial, used for communication to computer via USB
Serial.println("Serial works");
Serial1.begin(115200); // set baud rate for Serial 1 used for bluetooth communication on pins 0,1
Serial.println("Serial1 works");
Serial3.begin(9600); // set baud rate for Serial 3 is used to communicate with the CO2 sensor
Serial.println("Serial3 works");
delay(500);
tmp006.begin(); // this opens wire.begin as well, and initializes tmp006, tcs light sensor, and htu21D. by default, contactless leaf temp measurement takes 4 seconds to complete
Please be positive and constructive with your questions and comments.