[Lib] Testato_SoftI2CMaster

Piccolo regalo natalizio :smiley:
Libreria I2C Software, per usare dispositivi I2C su qualsiasi pin.

Partendo da una libreria che non risultava funzionare sui miei LCD, ho strumentalmente constatato che il problema era nella forma d'onda generata in bitbanging.
Ho sistemato la forma d'onda, ma era lentissima. L'ho quindi ulteriormente modificata prima per andare ai classici 100kHz, e poi per poter manualmente selezionare la velocita' voluta tra i 30Hz ed i 140kHz

Esempi di velocita' settabili:
// 0=maxspeed=140kHz (tested on 328P@16MHz)
// 1=120kHz
// 2=100kHz (default)
// 7=50kHz
// 47=10kHz
// 97=5kHz
// 500=1kHz
// 5000=100Hz
// 16383=minspeed=30Hz - delayMicroseconds() max value reference arduino

Ver 1.2

  • Aggiunto file keywords.txt (grazie leo72)
    Ver 1.1
  • Velocita' bus I2C selezionabile (30Hz-140kHz)
    Ver 1.0
  • Funzionamento su LCD con controller ST7032i
  • modificata la forma d'onda di uscita per aderire maggiormente allo standard I2C
  • modificata velocita' standard a 100kHz

Downloads precedenti: 7

Testato_SoftI2CMaster_ver1.2.zip (4.95 KB)

primo :grin:

Quindi rispetto alla SoftI2CMaster la tua permette velocità più elevate? Bene, ottimo.
Può tornarmi utile.

Ah, ti allego il file keywords.txt da mettere nella cartella dellal libreria, per la colorazione delle parole chiave da parte dell'IDE di Arduino, spero tu gradisca :stuck_out_tongue:

keywords.txt (573 Bytes)

grazie leo del keyword, mi scocciavo di farlo :smiley:

ci sono tre differenze importanti, la prima e' proprio la ricostruzione della forma d'onda, l'originale era talmente raffazonata che (fortunatamente) sui miei lcd cog non funzionava. se avesse funzionato, per questioni di tolleranza, non me ne sarei accorto.
La seconda e' la velocita' superiore, ma di molto non ricordo a quanto fosse inizialmente, ma qui siamo di default a 100kHz, come nella Wire.
La terza e' la possibilia' di selezionare manualmente la velocita' direttamente dalla API, quindi utile quando ad esempio si hanno dubbi su problemi saltuari dovuti alla velocita', in un click la cambi.

L'estensione della scelta, a partire da 30Hz, cioe' talmente lenta da poter seguire quasi ad occhio l'andamento del bus, fino al massimo di 170kHz puo' essere utile in fase di test.

Ver 1.2 :wink:

Ha il timeout?

Non ne ha bisogno perché non è bloccante

Ho utilizzato la nuova libreria Testato_SoftI2CMaster e la libreria Testato_ST7032i_LCD_I2C v.2.0 per pilotare un LCD MIDAS MCCOG21605C6W-SPTLYI utilizzando diversi pin oltre a quelli standard previsti per la I2C.
Il tutto funziona perfettamente anche con diverse velocità come indicato negli esempi e nei files README contenuti nelle librerie:

  • LCD pilotato da Arduino UNOR3 da pin A4 e A5 con libreria Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD pilotato da Arduino UNOR3 da pin D6 e D7 con libreria Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD pilotato da Arduino MICRO da pin D2 e D3 con libreria Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD pilotato da Arduino MICRO da pin D6 e D7 con libreria Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
    Grazie a Testato per tutte le modifiche che hanno reso possibile l'impiego di diversi pin per collegare l'LCD

I used the new library Testato_SoftI2CMaster and the new library Testato_ST7032i_LCD_I2C v.2.0 to drive an LCD MIDAS MCCOG21605C6W-SPTLYI using alternative pins instead of those provided for the standard I2C. Everything works perfectly even with different speeds, as shown in the examples and in README files content in the library folders:

  • LCD controlled by Arduino UNOR3 pin A4 and A5 with library Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD controlled by Arduino UNOR3 pin D6 and D7 with library Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD controlled by Arduino MICRO pin D2 and D3 with library Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
  • LCD controlled by Arduino MICRO pin D6 and D7 with library Testato_ST7032i_LCD_I2C + Testato_SoftI2CMaster
    Thanks to "Testato" for all the changes that have made possible the use of alternative pins to connect the LCD

grazie dell'esaustivo feedback :wink:

Interessante post da seguire, dove spiego ulteriori possibilità e sviluppi della libreria
http://forum.arduino.cc/index.php?topic=315898.new#new

I have done a few tests with version 1.2

Using Arduino IDE 1.6.3 with an Arduino Uno as Master and also a Arduino Uno as Slave.

  • The readBytes() is not implemented.
  • I prefer parameters with the SDA pin first, the SCL pin as second parameter and enabling the internal pullup resistors with boolean as third. The Wire.setClock() is a new function, perhaps setClock() can be used for the speed.
  • The endTransmission() does not return a value if the transfer was successful or not. That is needed for the i2c_scanner.
  • When transmitting 32 bytes, sometimes a complete transmission was missed.
  • When the Slave reads less bytes than the Master is transmitting, there is a lock up.
  • The requestFrom(address, length) does not support the 'length' parameter.
  • The requestFrom() does not return the amount of read bytes.
  • The available() is not yet implemented.
  • After requestFrom() I can not read valid data yet with read().

Do you think it is possible to implement all of that (and more) ?

Many is very simple to insert, i will put the lib on github do we can wirk on in togheter in a mutch simple way.

For now i used it on my other library for the ST7032i that you can find in my sign and it do not need the other method thst you explain, but i agree thst whit your request the lib can became very intetedting and profuctive.

Sorry for the damned android autocorrection featured :slight_smile:

I'm not on Github. You can keep it in this topic.
I would like to use the Stream class, but I'm not 100% confident that I can do that. I don't know for example what virtual inheritance is Virtual inheritance - Wikipedia .

1 ) Could you add a "begin()" function for compatibility, even if it is only a dummy function.

2 ) The return value (acknowledge) from beginTransmission() should be returned by endTransmission(). Using a TX buffer would make it more compatible, but without buffer, a variable should be added to the class to remember the acknowledge and that variable should be returned by endTransmission().
I also suggest to test in i2c_write for that variable and skip writing if the address was not found.

In the Arduino Wire library it is like this:
Wire.beginTransmission() returns nothing.
Wire.write() returns the number of bytes written to the buffer, regardless if the Slave is on the I2C bus or not.
Wire.endTransmission() returns a value that can be checked if there was an acknowledge.

thanks for the suggestion and the help.
now i working on another project so i do not know when i can made this modification.
when i do it i write here on the topic

I'm busy with the software I2C library. At this moment it detects clock pulse stretching and writing data works.

I'm still working on reading data and the repeated start. Reading data doesn't work at this moment.

Testato, I think you opened your library files in an external editor (with CR LF), when I open those files in the Arduino IDE, every new lines becomes two new lines, and that stopped the macros from working. So please use the Arduino IDE to save those files, or use another save setting in the editor.

The library has become slower, but I had to add extra checks. Once in a while an error occured, and I wanted the transmissions to be just as reliable as the Arduino Wire library. I think I have achieved that. At least with my tests, it is running fine now.

When not enough users test it, I will start a new topic in the normal English forum.

Could the library be added to the Library Manager ?

your is not my versione updated, it is a completely new version :slight_smile:
good work, for now i do not have time to test it sorry :cry:
But i will write here, or in the English topic that you will open, my future test results

For the Library Manager actually the official way for add a lib to the repository is open an Issue on the arduino GitHub account and ask to add it to Library Manager

Please may update in the files this note:
// 2014-2015, Testato updates the SoftI2CMaster library to make it faster
// and to make it compatible with the Arduino 1.x API
// Also changed I2C waveform and added speed selection

That text is now in the three files.
I decided that the english forum is a better place.
This topic continues here : SoftwareWire : Testers wanted for a software I2C library. - Networking, Protocols, and Devices - Arduino Forum
( see that new topic for the newer library version )