Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Trinket 3V I2C with VCNL4040
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket 3V I2C with VCNL4040

by MrDoodah on Mon Jun 08, 2020 1:52 pm

Hi!

I'm using the Trinket 3V as a test bed for developing a commercial product that will ultimately use an ATtiny85. I understand that it is deprecated, but my computer is old enough to work with it. Quite simply, the ATtiny is the right chip for the product, and its the right price.

I am trying to interface it with a VCNL4040 using I2C. From what I could tell, it seemed like it would work, but I am having issues with compiling it in with Aduino. I am using a Sparkfun board, as I didn't realize that Adafruit made one, but from what I can tell they are identical. Regardless, it seems the issues arise from the VCNL4040 library, and I can't compile either. There are considerable more errors when I complete the Adafruit library. There are only 3 with the Sparkfun library, so I guess I'll start there. If there is a better way for me to seek help with this issues, please let me know. I'm using the library from here:

https://github.com/sparkfun/SparkFun_VC ... no_Library

And the errors I'm getting are below. They seem to hinge on something called TwoWire, on which I couldn't find much information. Any help you can provide would be greatly appreciated.

Thanks!


C:\Users\...\Documents\Arduino\libraries\SparkFun_VCNL4040_Proximity_Sensor_Library\src/SparkFun_VCNL4040_Arduino_Library.h:133:19: error: 'TwoWire' has not been declared

boolean begin(TwoWire &wirePort = Wire);

^~~~~~~

C:\Users\...\Documents\Arduino\libraries\SparkFun_VCNL4040_Proximity_Sensor_Library\src/SparkFun_VCNL4040_Arduino_Library.h:198:5: error: 'TwoWire' does not name a type

TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware

^~~~~~~

C:\Users\...\Documents\Arduino\libraries\SparkFun_VCNL4040_Proximity_Sensor_Library\src/SparkFun_VCNL4040_Arduino_Library.h:133:39: error: 'Wire' was not declared in this scope

boolean begin(TwoWire &wirePort = Wire);

MrDoodah
 
Posts: 4
Joined: Mon Jun 08, 2020 1:28 pm

Re: Trinket 3V I2C with VCNL4040

by adafruit_support_bill on Mon Jun 08, 2020 2:03 pm

The Wire library does not work on the ATTiny. You would need to modify the library to use the TinyWireM library.
https://github.com/adafruit/TinyWireM

adafruit_support_bill
 
Posts: 78210
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 3V I2C with VCNL4040

by MrDoodah on Mon Jun 08, 2020 2:38 pm

OK. Thanks for the direction. I had included TinyWireM in my main sketch but it didn't help. You're saying that the VCN4040 library references Wire and I need to remove those references and replace them with TinyWireM. Can you help me understand the effort level? I'd like to use the VCNL4040, but might be able to get close with a simple IR LED Transmit/Receive system. I am comfortable in the Arduino environment, but not sure about modifying libraries, and I don't want to get in over my head when there is a viable alternative. Are there any other libraries that you know of that have been modified to work with TinyWireM that I can use as a guide?

Thanks again!

MrDoodah
 
Posts: 4
Joined: Mon Jun 08, 2020 1:28 pm

Re: Trinket 3V I2C with VCNL4040

by adafruit_support_bill on Mon Jun 08, 2020 3:14 pm

You would need to edit the library to specify TinyWireM instead of Wire. The API is pretty much identical to Wire and in many cases, no further changes are needed.

See the TinyRTCLib for an example. https://github.com/adafruit/TinyRTCLib/ ... RTClib.cpp

I believe that the only change needed were these lines:
Code: Select all | TOGGLE FULL SIZE
   #include <TinyWireM.h>
   #define WIRE TinyWireM

adafruit_support_bill
 
Posts: 78210
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 3V I2C with VCNL4040

by MrDoodah on Tue Jun 09, 2020 12:20 pm

No luck. Still getting the same error related to TwoWire. Any other suggestions? Here is a link to the library I'm using:

https://github.com/sparkfun/SparkFun_VC ... master/src

Sorry for linking to Sparkfun on an Adafruit forum. There are significantly less errors when I try to compile it though, so I figured it would be best to start there.

I'm not looking for you to do the work for me. I need to be able to use this sensor with this Trinket though. Do you have any suggestions on how to get it to work? Are there Trinket consultants out there?!

MrDoodah
 
Posts: 4
Joined: Mon Jun 08, 2020 1:28 pm

Re: Trinket 3V I2C with VCNL4040

by adafruit_support_bill on Tue Jun 09, 2020 12:39 pm

"TwoWire" is the class name for the i2c device in the Wire library. In TinyWire it is called "USI_TWI".

You can try adding this line:
Code: Select all | TOGGLE FULL SIZE
#define TwoWire USI_TWI

adafruit_support_bill
 
Posts: 78210
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 3V I2C with VCNL4040

by MrDoodah on Tue Jun 09, 2020 1:33 pm

It compiled! Thank you so much for your help. Now that I see what had to be done, it makes sense. My computer science intuition/skill set never would have produced that though.

I also had to change the line

Code: Select all | TOGGLE FULL SIZE
boolean begin(TwoWire &wirePort = Wire);


to

Code: Select all | TOGGLE FULL SIZE
boolean begin(TwoWire &wirePort = TinyWireM);


I have no idea if the hardware will actually work, but at least I can test. Thanks again!

MrDoodah
 
Posts: 4
Joined: Mon Jun 08, 2020 1:28 pm

Please be positive and constructive with your questions and comments.