Post by sgraber on Oct 14, 2014 13:37:03 GMT -5
Ok, I need your collective Arduino help!
I want to use more than one of the same sensor in a project and they all need the SDA and SCL pins (A4, A5) to communicate. Based on what I see, I need to modify the sensor library to allow the creation of multiple SDA and SCL pins. Here is the sensor library in question:
github.com/adafruit/Adafruit_TCS34725
In my search, I found the SoftI2CMaster library on github:
github.com/todbot/SoftI2CMaster/
which allows me to specify which pins I want to use for SDA and SCL by using:
Ok, so I now have a path forward. I need to modify the Adafruit library to use the SoftI2CMaster library instead of the Wire.h library and I need to modify the Adafruit_TCS34725 class to accept SDA and SCL pin declarations.
For arguments sake, let's use two of the same sensor in the project. In my sketch I want to do the following:
TCS34725_INTEGRATIONTIME_700MS and TCS34725_GAIN_1X were originally the only two values passed in the library. I've now included two pin numbers after that with the first being SDA and the second SCL.
So I've now created two instances of the Adafruit_TCS34725 class using two different sets of SDA and SCL pins.
Now, in Adafruit_TCS34725.h, I replace LINE 53 with these lines, which comments out the Wire.h library and adds in default pins for SDA and SCL communication (in case nothing is called):
Now in the same file, I need to add SDA_PIN and SCL_PIN to Adafruit_TCS34725 class declaration, around LINE 133, so each time I create an instance of the Adafruit_TCS34725 class, I can specify my sda and scl pins:
Do I need to do anything further with this file??? I'm not sure, but I might need to make a public and/or private method that sets the SDA and SCL pins???
Now, on to the Adafruit_TCS34725.cpp file...which is where I'm extremely stuck. I *think* I need to do something around LINE 145 and 162 where the Constructor and Begin functions are declared, but since I've never written a library before, I'm completely at a loss.
Help!
I want to use more than one of the same sensor in a project and they all need the SDA and SCL pins (A4, A5) to communicate. Based on what I see, I need to modify the sensor library to allow the creation of multiple SDA and SCL pins. Here is the sensor library in question:
github.com/adafruit/Adafruit_TCS34725
In my search, I found the SoftI2CMaster library on github:
github.com/todbot/SoftI2CMaster/
which allows me to specify which pins I want to use for SDA and SCL by using:
SoftI2CMaster i2c = SoftI2CMaster(SDA_PIN, SCL_PIN);
Ok, so I now have a path forward. I need to modify the Adafruit library to use the SoftI2CMaster library instead of the Wire.h library and I need to modify the Adafruit_TCS34725 class to accept SDA and SCL pin declarations.
For arguments sake, let's use two of the same sensor in the project. In my sketch I want to do the following:
/* Initialise with specific integration time, gain, sda, and scl pins for RGB-IR filtered sensor */
Adafruit_TCS34725 tcs1 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X, 2, 3);
Adafruit_TCS34725 tcs2 = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X, 4, 5);
TCS34725_INTEGRATIONTIME_700MS and TCS34725_GAIN_1X were originally the only two values passed in the library. I've now included two pin numbers after that with the first being SDA and the second SCL.
So I've now created two instances of the Adafruit_TCS34725 class using two different sets of SDA and SCL pins.
Now, in Adafruit_TCS34725.h, I replace LINE 53 with these lines, which comments out the Wire.h library and adds in default pins for SDA and SCL communication (in case nothing is called):
// START CUSTOMIZATION
// #include <Wire.h>
// replace Wire.h with SoftI2CMaster from https://github.com/todbot/SoftI2CMaster
#include <SoftI2CMaster.h>
#define SDA_PIN 2
#define SCL_PIN 3
// END CUSTOMIZATION
Now in the same file, I need to add SDA_PIN and SCL_PIN to Adafruit_TCS34725 class declaration, around LINE 133, so each time I create an instance of the Adafruit_TCS34725 class, I can specify my sda and scl pins:
class Adafruit_TCS34725 {
public:
Adafruit_TCS34725(tcs34725IntegrationTime_t = TCS34725_INTEGRATIONTIME_2_4MS, tcs34725Gain_t = TCS34725_GAIN_1X, SDA_PIN, SCL_PIN);
Do I need to do anything further with this file??? I'm not sure, but I might need to make a public and/or private method that sets the SDA and SCL pins???
Now, on to the Adafruit_TCS34725.cpp file...which is where I'm extremely stuck. I *think* I need to do something around LINE 145 and 162 where the Constructor and Begin functions are declared, but since I've never written a library before, I'm completely at a loss.
Help!