Switching from Wire.h (Uno/Leonardo) to TinyWireM.h (ATTINY85 or digispark)

Hello!

with help of Sonal Pinto's great tutorial (GitHub - SonalPinto/Arduino_SSD1306_OLED: Interfacing the Arduino with an SSD1306 driven OLED Display) I got my I2C-OLED-display running with a Genuino Micro/Leonardo (SDA=Pin2, SCK=Pin3).

Now I would like to run Sonal's simple example code (oled_test.ino) with an ATTINY85 or digispark (SDA=Pin5, SCK=Pin7).

Beside changing the pin connections I changed the appropriate code from:

#include <Wire.h>
Wire.begin
Wire.beginTransmission
Wire.write
Wire.endTransmission

to:

#include <TinyWireM.h>
TinyWireM.begin
TinyWireM.beginTransmission
TinyWireM.send
TinyWireM.endTransmission

But it doesn't work ... the display remains dark.

What did I miss or missunderstand?
Thanks for every hint.

Regards
deetee

Please provide a link to the TinyWireM library you're using (there are several versions on the Net).

Please provide more information about your hardware. The original TinyWireM library is designed to work with a 1MHz ATtiny, so you may have to adapt it to work with an 8MHz ATtiny.

Thanks for the reply.

So far I am testing on a digispark-clone (URL see later) or on a "naked" ATTINY85 (flashed with an Uno).
The digispark-clone runs with 16.5MHz (default) and the ATTINY with 8MHz (thanks for this hint).

The library was loaded via Arduino-IDE:

Regards
deetee

https://www.aliexpress.com/item/Digispark-Kickstarter-ATTINY85-For-Arduino-General-Micro-USB-Development-Board/32665015051.html?spm=2114.search0104.3.1.43f75ea7G5dyvc&ws_ab_test=searchweb0_0,searchweb201602_2_10152_10065_10709_10151_10344_10068_10342_10547_10343_10340_5722611_10341_10548_10697_10696_5722911_5722811_10084_5722711_10083_10618_10304_10710_10307_10302_5711211_10059_308_100031_10103_441_10624_10623_10622_10621_10620_5711311_5722511,searchweb201603_19,ppcSwitch_2&algo_expid=d0b7ea2e-6ae2-4dad-9f69-842219c538e3-0&algo_pvid=d0b7ea2e-6ae2-4dad-9f69-842219c538e3&transAbTest=ae803_2&priceBeautifyAB=0

If using a naked ATTiny85, with my ATTinyCore you can just use Wire.h as if it were an Uno/Leo/etc - my core includes a version of Wire.h that selects the appropriate implementation for the hardware and presents a compatible interface, so that libraries that include Wire.h can also be used without modification.

The library was loaded via Arduino-IDE:

That version uses the write() method and not send(). So you might just use a #define to change between the two versions.

Thanks for all hints.

So far I tried:

  • I played with T2_TWI and T4_TWI in USI_TWI_Master.h. I changed the default values of 5/4 (1MHz) to 0.625/0.5 (divided by 8 for 8MHz) and 0.3/0.42 (divided by 16.5 for 16.5MHz).
  • I tried with TinyWireM.write (instead of TinyWireM.send).
  • I tried with DrAzzy's ATTinyCore AVR-Wire-library - but gave up in an early state because of so many compiler errors.

... unfortunately without success :frowning:

Regards
deetee

I played with T2_TWI and T4_TWI in USI_TWI_Master.h. I changed the default values of 5/4 (1MHz) to 0.625/0.5 (divided by 8 for 8MHz) and 0.3/0.42 (divided by 16.5 for 16.5MHz).

These values are used for a call to _delay_us(), so you don't have to divide them by 8 for the 8MHz version. I would try to modify them only slightly. In my understanding you would have to increase them and not decrease them as they control the SCL speed. The sum of them plus the time needed for the few statements in the transfer routine should be around 10µs, so you might want to try 5.5 and 4.5.

I tried with DrAzzy's ATTinyCore AVR-Wire-library - but gave up in an early state because of so many compiler errors.

What core do you use?

Hello Pylon - thank you for not giving up.

As you saw I don't really know what I'm doing when changing the delay values. But I saw many other guys who divided these values to adapt from 1 to 8 MHz.
Now I tried to raise these values in 0.5 us steps up to 12/10 - but without success.

Your other hint:
I found some info about this library (name=wire, version=1.0, author=Arduino) in a file named "library.properties" - but I took the latest version from github. I decided to go on with Sonal Pinto's code which is very simple and straight and works (with Wire.h) on my Genuino.

Regards
deetee

I asked what core you use. The Arduino IDE doesn't support the ATtiny family out of the box. So you have to install a new core (you can call it board support package) to get support for it. For the Tinys there are several incompatible cores available. So we have to know which one you're using.