ESP8266 & LiquidCrystal_I2C

Hi.

I’m running an Arduino Uno with a 20x4 Alphanumeric Display via I2C and the LiquidCrystal_I2C.h library.

This works fine with the Arduino Uno.

Now I want to replace the Arduino Uno with a ESP8266 (Wemos D1 Mini v2), but compiling the same sketch just won’t work.

A a testfile I am using the Arduino sketch “HelloWorld” .

The sketch compiles and runs Ok for the Arduino Uno but compiling it for the D1 Mini ends up with compilation errors.

Anybody that knows how to fix this ??

Here is the code and the output :

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <LCD.h>

LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address & pinout

void setup() {

// The begin call takes the width and height. This
// Should match the number provided to the constructor.
lcd.begin(20,4);
lcd.clear();

// Turn on the backlight.
lcd.backlight();

// Move the cursor characters to the right and
// zero characters down (line 1).
lcd.setCursor(5, 0);

// Print HELLO to the screen, starting at 5,0.
lcd.print(“HELLO”);

// Move the cursor to the next line and print
// WORLD.
lcd.setCursor(5, 1);
lcd.print(“WORLD”);
}

void loop() {
}

And here is the compiler output from the D1 Mini :

Build options changed, rebuilding all
In file included from C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:35:0:

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp: In member function ‘uint8_t LiquidCrystal_SR1W::clearSR()’:

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:77:24: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

SR1W_ATOMIC_WRITE_LOW(srRegister, srMask);

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.h:293:79: note: in definition of macro ‘SR1W_ATOMIC_WRITE_LOW’

#define SR1W_ATOMIC_WRITE_LOW(reg, mask) ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *reg &= ~mask; }

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:86:22: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

fio_bit reg_val = *srRegister;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:95:5: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

*srRegister = bit_high;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:96:5: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

*srRegister = bit_low;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:101:4: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

*srRegister = bit_high;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp: In member function ‘uint8_t LiquidCrystal_SR1W::loadSR(uint8_t)’:

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:139:24: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

fio_bit reg_val = *srRegister;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:144:6: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

*srRegister = bit_low;

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:145:6: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

*srRegister = bit_high;

^

In file included from C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:35:0:

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:151:26: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

SR1W_ATOMIC_WRITE_LOW(srRegister, srMask);

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.h:293:79: note: in definition of macro ‘SR1W_ATOMIC_WRITE_LOW’

#define SR1W_ATOMIC_WRITE_LOW(reg, mask) ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *reg &= ~mask; }

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.cpp:158:27: error: invalid type argument of unary ‘*’ (have ‘fio_register {aka unsigned char}’)

SR1W_ATOMIC_WRITE_HIGH(srRegister, srMask);

^

C:\Program Files (x86)\Arduino\libraries\NewliquidCrystal\LiquidCrystal_SR1W.h:294:80: note: in definition of macro ‘SR1W_ATOMIC_WRITE_HIGH’

#define SR1W_ATOMIC_WRITE_HIGH(reg, mask) ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *reg |= mask; }

I remember having this problem. Did you select Wemos D1 D2 & mini from the boards menu? Are you using the latest version of the library? If so, there is some part of the library which is not written correctly and will not compile on non-AVR based Arduinos. The parts that do not compile should have been protected with #ifdef.

I can’t remember how I fixed the problem, but I think I may have found an alternative version of the library in which this fault had been fixed. Google for a version of the liquid_crystal_i2c library which says it works with esp8266.

Also please read the forum guidance post so you know how to post code and error messages correctly.

Hello PaulRB

Googled & found a LiquidCrystal_I2C that “should” work with ESP8266. (ESP8266-I2C-LCD1602-master.zip).

I removed the old LiquidCrystal_I2C library, downloaded & installed the “8266”-library.

I had to komment out the line lcd.init() to get a successful compile&upload, but I don’t get anything on the display.

I’m using D1 for SCL & D2 for SDA…

Anything else I can test ??

Sketch HelloWorld :

#include <LiquidCrystal_I2C.h>

//Original line for LiquidCrystal_I2C.h (that compiles & works with Arduino Uno)
//LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address & pinout

// Line that works with the “ESP8266”-library that compiles & uploads
LiquidCrystal_I2C lcd(0x3f, 20,4); // Set the LCD I2C address & pinout

void setup() {

// The begin call takes the width and height. This
// Should match the number provided to the constructor.
lcd.begin(20,4);
lcd.init();

// Turn on the backlight.
lcd.backlight();

// Move the cursor characters to the right and
// zero characters down (line 1).
lcd.setCursor(5, 0);

// Print HELLO to the screen, starting at 5,0.
lcd.print(“HELLO”);

// Move the cursor to the next line and print
// WORLD.
lcd.setCursor(5, 1);
lcd.print(“WORLD”);
}

void loop() {
}

*** Please read the forum guidance post so you know how to post code and error messages correctly. This is your second and final warning ***

Try running the Arduino i2c scanner test. This should detect the display if it is correctly wired.