The Trill library currently uses the Wire
library for I2c communication, so whether that one does any initialisation pertaining the functionality of the pins under the hood, I am not sure. As SDA0/SCL0 are the same signals used normally by Wire on the Teensy 3.6 - and without any specific knowledge of the library or of the board - I can try to make a guess. My guess is that while Wire may do some pin initialisation, it won't care if someone changes that afterwards, as long as you keep using the same bus (0). So, I'd recommend that you ensure that all of the Trill
objects' begin()
method (which in turn calls Wire.begin()
) are called before you construct the u8x8 object, so that the latter will override any pin setting done by Wire.begin()
. Now, that may be a bit tricky as your u8x8
object is probably global at the moment, and so any call to Trill::begin()
will only take place after that.
A few possible workarounds:
- have a global pointer and a static
variable in setup()
: the fact that it is static
will make it exist forever, so you can take a pointer to it and use it even after the function returns
U8X8_SSD1306_128X32_UNIVISION_HW_I2C* u8x8;
...
void setup() {
... // Trill initialisation here ....
static U8X8_SSD1306_128X32_UNIVISION_HW_I2C myU8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ 7, /* data=*/ 8);
u8x8 = &myU8x8;
...
}
....
void loop() {
...
u8x8->doSomething();
...
}
...
- create a wrapping class for Trill
which calls Trill::begin()
in the constructor, then declare your InitTrill objects before u8x8:
class InitTrill : public Trill {
InitTrill(Device device, uint8_t i2c_address=255) {
begin(device, address);
}
};
...
InitTrill myTrillOne(Trill::TRILL_BAR);
U8X8_SSD1306_128X32_UNIVISION_HW_I2C myU8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ 7, /* data=*/ 8);
- (perhaps the best, cleaner): add an overloaded constructor to Trill
which does that:
// in Trill.h
class Trill : public Touches2D
{
public:
Trill();
Trill(Device device, uint8_t i2c_address = 255);
...
};
// in Trill.cpp
Trill::Trill(Device device, uint8_t i2c_address = 255)
: device_type_(TRILL_NONE), firmware_version_(0),
mode_(AUTO), last_read_loc_(0xFF), raw_bytes_left_(0)
{
begin(device, address);
}
(ultimately it would be cleaner moving that initialisation list to begin()
)
However, before you do any of the above, see if it "just works" without any of that