Soft I2C / 1602 display error

I am trying to use todbot's Soft I2C library to drive a 1602 LCD / I2C ..
The LCD functions correctly with the standard wire.h and NewLiquidCrystal libraries..

And using the SoftI2c example to scan for i2C devices works, and returns the address 0x27 as expected ..
However there is no characters showing on the LCD

You are probably doing something wrong. That’s about all we can offer with the information that we have at this point.

Don

Actually, it is somewhat difficult and often impossible to make many 3rd party libraries with a software based i2c library.
It depends on how the library code that uses i2c is written whether or not it will work with a software i2c library.
Even when it does work, there can be limitations - more on that later.

In terms of software I2C libraries I prefer SoftwareWire over SoftI2CMaster for these reasons:

  • SoftwareWire is in the library manager so it is easier to install

  • SoftwareWire uses a nice clean GPL v3.0 license.

  • The licensing is a problem with SoftI2CMaster.
    SoftI2CMaster is claiming to use CC-BY-SA 3.0 - which is a TERRIBLE license for s/w.
    CC-BY-SA 3.0 is not compatible with anything but itself. So technically it is not legal to mix it with anything but other CC-BY-SA 3.0 code. This means that it can’t be linked with any LGPL, GPL, BDS, apatchie, … etc. It can only be linked with other CC-BY-SA 3.0
    So while you can use it for personal use it can never be used in a real project.
    CC-BY-SA 4.0 was created to resolve this by allowing the license to convert into LGPL or GPL if linked against other code with those licenses. But once it converts, any updates made to that code must remain LGPL or GPL.
    Looking deeper, these two libraries share some original code it isn’t clear that CC-BY-SA 3.0 is even possible.

  • SoftwareWire works with my hd44780 library
    I haven’t tracked down why but SoftI2CMaster doesn’t work properly with hd44780.

In terms of using a 3rd party library with a software library there are several issues the main one being that many hard code using the Wire library and include <Wire.h> which means that there is no way to change this.
hd44780_I2Cexp does not do this so you can use a software i2c library.
However… At this point in time the i2c object must compatible with the Wire library and be called Wire.
So to use SoftwareWire with hd44780_I2Cexp all you have to do is change this in your sketch:

#include <Wire.h>

to

#include <SoftwareWire.h>
SoftwareWire Wire(your-sdapin, your-sclpin);

And it will work.

It is useful if you want to use the existing i2c pins for something else but not very useful if you want to use the software wire bus and the hardware wire bus.
The issue is that currently hd44780_I2Cexp assumes an object named Wire.
Because of this it creates the limitation that you can’t use both the Wire library and SoftwareWire in the same sketch.

At some point I plan on updating the hd44780_I2Cexp code to use a template so that you can pass in the name of the i2c object but that is not there today.

— bill

bperrybap:
In terms of software I2C libraries I prefer SoftwareWire over SoftI2CMaster
all you have to do is change this in your sketch:

#include <Wire.h>

to

#include <SoftwareWire.h>

SoftwareWire Wire(your-sdapin, your-sclpin);




And it will work.

I--- bill

Thanks for for suggestion on the SoftwareWire library, I have d/l and installed it…
Looking at the examples it would seem that I should use myWire.write instead of lcd.print?
and I didn’t see any reference similar to lcd.backlight() for turning the backlight on??
thanks :slight_smile:

wvg_ca:
Looking at the examples it would seem that I should use myWire.write instead of lcd.print?
and I didn't see any reference similar to lcd.backlight() for turning the backlight on??

What examples?
I don't understand what you asking.

In order to use hd44780 and the hd44780_I2Cexp class to run your i2c lcd backpack, all you have to do is what I stated above to switch from using the Wire library to using the SoftwareWire library.
Nothing else changes.

--- bill

bperrybap:
What examples?
I don’t understand what you asking.

He probably refer to examples for SoftwareWire library :wink:

I use SoftI2CMaster , not todbot but felias-fogg adaptation of Peter Fleury’s software I2C library ( It’s really fast and small size ) and it is on GPL licence.

I made modification on LiquidCrystal_I2C with SoftI2CMaster and SCL and SDA pins are predefined in LiquidCrystal_I2C_BitBang.cpp and can be changed in that file only.

Predefined pins are :

ATTINY 85
SDA 0
SCL 2

ATTINY 841
SDA PA7
SCL PA3

ATTMEGA 328
SDA 3
SCL 5

Unzip in sketchbook/libraries folder ( SoftI2CMaster is included in LiquidCrystal_I2C_BitBang )

Strong PullUp is required when using the soft I2C ( 4.7K ohm or less ).

use it like this :

#include <LiquidCrystal_I2C_BitBang.h>   // for LCD w/ GPIO MODIFIED for the ATtiny85
#define GPIO_ADDR     0x27               // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.

LiquidCrystal_I2C_BitBang lcd(GPIO_ADDR,16,2);    // set address & 16 chars / 2 lines

//----------------------------------
void setup() {
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.print("Fogg BitBangI2C");
}

//----------------------------------
void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis()/1000);
}

LiquidCrystal_I2C_BitBang.zip (13.6 KB)

bperrybap:
What examples?
I don't understand what you asking.

In order to use hd44780 and the hd44780_I2Cexp class to run your i2c lcd backpack, all you have to do is what I stated above to switch from using the Wire library to using the SoftwareWire library.
Nothing else changes.

--- bill

Sorry for not not being clear...
I was referring to the examples contained within the SoftwareWire library itself..

wvg_ca:
Sorry for not not being clear...
I was referring to the examples contained within the SoftwareWire library itself..

But those SoftwareWire examples have nothing to do with driving an LCD.
If you want to use a soft i2c library to run an LCD that is driven by a PCF8574 based backpack, you need a library that isn't tied to Wire that can use one of the soft i2c libraries.
Both common_ground and myself offered you solutions to do that.

--- bill

I finally some time to do a little more …
Installed SoftwareWire V1.41 … and using the simple “hello World” example,

#include <SoftwareWire.h>
#include <LiquidCrystal_I2C.h>
SoftwareWire Wire(4,5);
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

However I do get errors on compile …as follows…

Arduino: 1.8.0 (Windows 7), Board: “Arduino Nano, ATmega328”

libraries\Wire\Wire.cpp.o (symbol from plugin): In function `TwoWire::available()’:

(.text+0x0): multiple definition of `Wire’

sketch\hello_world_I2C_SoftwareWire.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

I suggest that you go back and carefully re-read posts #2 and #5

--- bill

common_ground:
I made modification on LiquidCrystal_I2C with SoftI2CMaster and SCL and SDA pins are predefined in LiquidCrystal_I2C_BitBang.cpp and can be changed in that file only.

Predefined pins are :

ATTINY 85
SDA 0
SCL 2

ATTINY 841
SDA PA7
SCL PA3

ATTMEGA 328
SDA 3
SCL 5

Unzip in sketchbook/libraries folder ( SoftI2CMaster is included in LiquidCrystal_I2C_BitBang )

Strong PullUp is required when using the soft I2C ( 4.7K ohm or less ).

use it like this :

#include <LiquidCrystal_I2C_BitBang.h>   // for LCD w/ GPIO MODIFIED for the ATtiny85

#define GPIO_ADDR     0x27               // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.

LiquidCrystal_I2C_BitBang lcd(GPIO_ADDR,16,2);    // set address & 16 chars / 2 lines

//----------------------------------
void setup() {
 lcd.begin(16, 2);
 lcd.backlight();
 lcd.print(“Fogg BitBangI2C”);
}

//----------------------------------
void loop() {
 lcd.setCursor(0, 1);
 lcd.print(millis()/1000);
}

I realize this thread is over a year old, but I could find no newer. I am hoping that the author of this post will notice.

I am using ProMicro and I would like to use Software I2C so I can use alternate pins.

Common_Ground suggests modifying the LiquidCrystal_I2C_BitBang.cpp for predefining the pins I need to use.
I would like to us A0 and A1 for my application.

I assume there is a designator for the micro type that I must have correct when adding the ProMicro. I don’t understand how to do that. I think I can figure out the rest if someone can help me here.

I would be happy to use the sample code above and I know I can make my own modifications once that works.

Thank You

Greg