I2C libraries for ATTiny85? SoftI2CMaster VS. TinyWire VS. ?

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to transmit I2C data, using a Digispark ATTiny85 board:

 

I've found the following I2C libraries. Which one is more lightweight, stable, bug-free, efficient, powerful, and easy to use?

  • Adafruit's TinyWireM has not been updated in 2 years. 
  • felias-fogg's SoftI2CMaster has been updated within days of this post. 
  • lucullusTheOnly's TinyWire represents some years of improvements, "based on the TinyWireM and TinyWireS libraries". This version is recommended by BroHogan, co-creator of TinyWireM:
    https://playground.arduino.cc/Co...

 

Wire seems under-featured:

"the default Arduino Wire() library does not support changes in bus speed or feature proper clock stretching support. This makes the default library only marginally functional"
https://www.maxbotix.com/article...

What other I2C libs are available for ATTiny? In the IDE i see Digispark SoftSerial, OneWire, and VirtualWire. 

How do they all compare? 

 

thx

Last Edited: Wed. Jan 3, 2018 - 08:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2c is fairly trivial, so i wouldn’t be getting too picky as to which one you choose. Do you really need clock stretching and changing bus speed? I2c pretty well determines how things work, so all these libraries are just a variation on a theme. If you’re not happy with them, writing your own is, again, trivial.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

johnyradio wrote:

  • Adafruit's TinyWireM has not been updated in 2 years. 
  • felias-fogg's SoftI2CMaster has been updated within days of this post. 

Some would say that the fact that a library has not been updated in 2 years shows that it is stable ...

 

The I2C specification hasn't changed since 2014: https://www.nxp.com/docs/en/user-guide/UM10204.pdf

 

EDIT

 

typo

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You ask:

johnyradio wrote:
Which one is more lightweight, stable, bug-free, efficient, powerful

Then state:

johnyradio wrote:
Wire seems under-featured

 

What do you want? lightweight or full featured?    Reminds me of the engineering question -  Good / Cheap / Fast,  pick any two, you can't have all three.

 

More important is what do you want to do with your T85? 

 

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
What do you want? lightweight or full featured?

 

i realized one lib may be more lightweight, another have more features, another have the biggest online community, etc. I'm not necessarily expecting to find ONE lib that has it all. My question is shorthand for multiple questions:

  • Which is most minimal?
  • Which has best performance?
  • Which has most features?
  • etc.

 

Another possible way to read it is:

  • "which one has the best tradeoff between size, performance, features, etc?"

 

 

awneil wrote:
Some would say that the fact that a library has not been updated in 2 years shows that it is stable ...

Great point! Or, maybe it's neglected because people got busy with other things. 

 

 

Kartman wrote:
i wouldn’t be getting too picky as to which one you choose. If you’re not happy with them, writing your own is, again, trivial.
 

  • i'm not considering writing my own I2C lib. When several exist, what's the point? Trying to save time by using existing best tools, not give myself more work. I want to get things done, not reinvent the wheel. 
  • if one offers clock stretching and changing bus speed, and another doesn't, that seems a non-trivial difference. 
  • Seems reasonable to assume that if the existing lib was sufficient, people would not have gone to the trouble of making new ones (unless they like to reinvent the wheel). 
  • if you can offer insight into the differences between libs, great! Do share. If not, no problem. 

Last Edited: Thu. Jan 4, 2018 - 05:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We understand what you are asking, but it seems you don’t fully grasp the question!

Try one. The investment is minimal.
1. Which one is minimal? Hard to say as the compiler will most likely throw out the stuff you don’t use.
2. Performance - largely dictated by the I2C spec.
3. Features? I2c is pretty minimal, there’s only about 5 functions you need.

With the tiny85 you’ve got a choice of using the usi hardware or bitbashing for i2c/twi. Usi can only use fixed pins, whereas bitbashing can use any available gpio pin.
Since we have no idea of your requirements, it is difficult to guide you apart from - choose one, get your project working then look to optimise (if at all required).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
With the tiny85 you’ve got a choice of using the usi hardware or bitbashing for i2c/twi. Usi can only use fixed pins, whereas bitbashing can use any available gpio pin.

 

thx for info.

Are you saying some I2C libs are usi, and others are i2c/twi?

Btw, which of these libs have you used?

thx

Last Edited: Thu. Jan 4, 2018 - 06:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally, I’d just use the wire lib. Rarely would i need clock stretching or the need to change the speed. Most i2c devices don’t need this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

If you are using a regular Arduino,  your sketches include Wire.h.   The regular Arduino uses the TWI hardware

 

If you port a regular Arduino sketch to a Tiny85 you have to install a compatible Core

Then replace Wire.h references with TinyWireM or TinyWireS as appropriate.

 

Although the third party Tiny Cores work reasonably well,   you must be aware that the Tinys are less endowed than a Uno.

e.g. the TX buffer with TinyWireM is smaller than the regular Wire library.   There is no hardware USART.

 

I suggest that you always test your sketches on a Uno before porting to a Tiny85

If your program works on the Uno but the "ported" sketch has a problem on the Tiny85,  you can post the working sketch with your "problem port" sketch.

 

I strongly recommend that you stick with Cores supported by the IDE Board Manager and libraries supported by the IDE Library Manager.

Quote the version numbers reported by the Board Manager and Library Manager with your question(s).

 

You will probably get good help on the Arduino.cc or Avrfreaks.net

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IIRC the USI h/w works best as an I2C slave than as an I2C master so master may be better implemented as bit bang master on a tiny,

the TWI h/w works better as a master, so that is one more criteria to add to your list.  With the very limited flash space on most tiny's a full featured implementation may not even fit, or limit what can be done in the rest of the project. 

I agree with David, use supported cores and lib's unless forced to seek other solutions due to limited code space.

AS with most "what's best" questions seen here, YMMV according to your needs at the time.

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

In my experience, the Tiny85 isn't good for anything useful.  Any company that makes a tiny85 board and sells it as a fully-functional general-purpose microprocessor development system is jiving its customers.    Sure, if you know all the theory, have a lot of quality electronic development equipment, are comfortable in assembly language and compiler operation, and are expert in all the details of the operation of the interface like I2C, you CAN use the tiny85 for applications that any normal person would use a mega328P-based Arduino Nano clone for.  And you have saved...wow, maybe $1 or two by using the Tiny85 instead of the 328P-based Nano.  And you have spent MANY hours trying to get the tiny85 to run bozo libraries like TinyWire effectively and reliably, instead of using a fully-functional, working, debugged, free, and documented/supported library like Arduino's Wire.h right out of the box.    So do yourself a favor,  write off the expenses that you have made on tiny85-based "systems" and get a ten-pack of Arduino Nanos.   In the 20th century, developers would spec the cheapest microprocessor that could stretched/caressed/bit-banged into doing the application because back then there was a direct linear relationship between CPU cost and its speed and internal peripheral set.  In the 21st century, complex CPUs that have way more capacity than you need for your present application are mass produced into standardized breakout PCB boards and sell for less than the cost of the parts purchased individually from component distributors.  The research and development effort goes into activating these internal peripherals that your app needs instead of finding the cheapest CPU that meets your minimum needs (and then buying all the tools and learning all the quirks of the IDE system needed to actually get productive work done on this cheapest CPU).  When a tiny85 with 8K/8MHz flash development board sells for $2 and a 32K/50MHz flash ARM board (with every peripheral you can imagine) sells for $2.50, the purchasing decision rests on the cost and ease-of-learning of the development system.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But, on that basis, why would you mess about on a mega328P with its piddling 2K of RAM ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
If you are using a regular Arduino,  your sketches include Wire.h.   The regular Arduino uses the TWI hardware

Thx for that. But i'm not using an Arduino, i'm using a Digispark, which is based on the ATTiny85. Not porting from Arduino. 

 

Simonetta wrote:
In my experience, the Tiny85 isn't good for anything useful.

Thx for the tip. That's a debate for another thread. 

Last Edited: Fri. Jan 5, 2018 - 10:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your Digispark "is" a poor man's Arduino.

 

It is far harder to learn how to do things on a Tiny85 (or even a Tiny25)

 

However,  the small Tinys might be appropriate for very small projects e.g. with only 5 GPIO pins.

Develop and debug on a Uno.   Port the working project to the Tiny target.

 

Yes,   I have used TinyWireM and regular Wire.   And followed my own advice i.e. develop on Uno.  Test on Tiny1634.

Other projects developed on Uno.  Tested on Tiny85.

 

Simonetta has very fixed views on the Nano.    Personally,  I do not share his opinion.

1.  the Nano can not run at 3.3V

2.  the Nano requires modification for debugWIRE

3.  the Nano does not receive standard shields.

 

However,   the Nano does make an excellent final target (for 5V external lectronics).   The Digispark makes an excellent target (for small Flash, small GPIO external electronics)

And you get a warm smug feeling when you are successful with limited resources.

 

David.

Last Edited: Fri. Jan 5, 2018 - 11:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

IIRC the USI h/w works best as an I2C slave than as an I2C master so master may be better implemented as bit bang master on a tiny,

the TWI h/w works better as a master, so that is one more criteria to add to your list. 

Thx for info that's relevant to my post! 

 

ki0bk wrote:
use supported cores and lib's

How do you define "supported".

 

thx

Last Edited: Fri. Jan 5, 2018 - 01:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

I strongly recommend that you stick with Cores supported by the IDE Board Manager and libraries supported by the IDE Library Manager.

Quote the version numbers reported by the Board Manager and Library Manager with your question(s).

 

I am sure that SpenceKonde would make his TinyCore compatible with the Board Manager shortly.   There is a "board_manager_114" Branch on GitHub.

 

There are several third party hacked arrangements.

 

It is unwise (tm) to rely on someone with a silly name and little idea of what she is doing.   Stick to the respected SpenceKonde. 

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Cores supported by the IDE Board Manager and libraries supported by the IDE Library Manager.

By "supported by the IDE Board Manager and IDE Library Manager", you simply mean the board and libs can be loaded and displayed in the Managers? Or you mean they are bundled in the IDE?

 

david.prentice wrote:
It is unwise (tm) to rely on someone with a silly name and little idea of what she is doing.

Who are you talking about? lucullusTheOnly? I think it's unwise to judge someone's code based on their name. How do you know they have little idea what they're doing? How do you know it's a she? 

 

Thx for recommendation to TinyCore, i see it includes I2C. 

Last Edited: Fri. Jan 5, 2018 - 03:34 PM