Problem with Trinket and Wire.h and TSL2561 sensor

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
woollyjumperjon
 
Posts: 3
Joined: Wed Jul 06, 2016 1:03 am

Problem with Trinket and Wire.h and TSL2561 sensor

Post by woollyjumperjon »

I'm trying to get a TS2561 sensor to work with Trinket. I have been sucessful in the past (mid 2016) but i see theres been some changes in the source code of Adafruit_TSL2561_U and Adafruit_Sensor since then and now I can't get it to compile for Trinket 5V 8MHz.

As per the previous software and the suggestions i've seen for using i2c with Trinket I just directly include the Wire library along with the TSL2561 and Adafruit_Sensor. If i understand right it should then be using the TinyWireM.h transparently in the background for all the calls to Wire.

Code: Select all

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
But theres a compiler error from the Adafruit_TSL2561_U.h line 171 and 186.
'TwoWire' has not been declared
and
'TwoWire' does not decalre a type
Basically the same error seems to come up if you try to compile the sensorapi Example for the TSL2561 for Trinket 5V 8MHz. Note that both the sensorapi Example and my source code both compile fine for the Arduino Uno so i'm sure the issue is with the board definition or the way that Wire and WireTinyM are defined for the Trinket.

As i mentioned before i had it working a coupelof years ago. In that case I also had to make some manual hack to the Adafruit_TSL2561_U.h file in order to comment out the references to TinyWireM and make sure to include Wire.h. But it looks like in the newer version of Adafruit_TSL2561_U.h already used Wire.h only.

Code: Select all

46//ifdef __AVR_ATtiny85__
47//  #include "TinyWireM.h"
48//  #define Wire TinyWireM
49//#else
50  #include <Wire.h>
51//#endif
Any suggestion how to get i2c working with Trinket through the normal Wire library?

User avatar
56skif
 
Posts: 1
Joined: Sat Mar 31, 2018 11:27 pm

Re: Problem with Trinket and Wire.h and TSL2561 sensor

Post by 56skif »

I run into the same error while trying to connect Trinket with VL6180x distance sensor which also uses I2C.

RESOVLED BY:

In the sensor library I removed all references (there were 3 or 4 of them) to TwoWire class and replaced them with TinyM_USI_TWI, so that it matches the class definition in the TinyWireM.h library. Apparently Trinket is still using it instead of regular Wire.h. And I did update the board definition to the latest version 1.4.12 before doing so.

I am sure there is a better way to resolve it, but at least I got my project to work :)

Hope this helps.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”