Go Down

Topic: Member lcd.init not found error (Read 1 time) previous topic - next topic

multimedia

code

#include "ESP8266WiFi.h"
#include <Wire.h>  // This library is already built in to the Arduino IDE
#include <LiquidCrystal_I2C.h> //This library you can add via Include Library > Manage Library >

 
LiquidCrystal_I2C lcd(0x38, 16, 2);
 
void setup()
{
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  // lcd.init();   // initializing the LCD
  lcd.backlight(); // Enable or Turn On the backlight
  lcd.print("Please Wait!");
  if (Serial.available()) {
    // Wait a bit for the entire message to arrive
    delay(100);
    // Clear the screen
    lcd.clear();

    // Write all characters received with the serial port to the LCD.
    while (Serial.available() > 0) {
      lcd.write(Serial.read());
    }
  }
  delay(1000);


}
 
void loop()
{
 int n = WiFi.scanNetworks();
 if (n == 0)
 {
 

  lcd.setCursor(0, 0);
  lcd.print("no networks found"); // Start Print text to Line 1
  lcd.setCursor(0, 1);     
  lcd.print("--------"); // Start Print Test to Line 2
}
 
  else
  {
    lcd.setCursor(0, 0);
    lcd.print(n);
    lcd.setCursor(0, 1);
    lcd.print(" networks found ");
    delay(2000);
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 0);
      lcd.print(i + 1);
      lcd.print(": ");
      lcd.setCursor(0, 1);
      lcd.print("                ");
      lcd.setCursor(0, 1); 
      lcd.print(WiFi.SSID(i));
      /*
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");*/
      delay(2000);
    }
  }


  // Wait a bit before scanning again
  delay(5000);
 
 
}


error

if i dont remove the lcd.init line i get member init not found
if i comment out the line it compiles but nothing on screen or serial monitor, only garbeled letters and
chars on serial monitor, i need help, i2c esp 8266.

bperrybap

#1
Aug 09, 2017, 05:41 am Last Edit: Aug 09, 2017, 05:44 am by bperrybap
The example code you are showing here and the example code you showed here: http://forum.arduino.cc/index.php?topic=372286.msg3369786#msg3369786
are different and are for different libraries.

While the "libraries" may have the same name, and provide a LiquidCrystal_I2C.h header file, different LiquidCrystal_I2C classes are initialized differently, have different functionality and have different API functions.

It appears that  you may have installed multiple libraries with a LiquidCrystal_I2C.h header and LiquidCrystal_I2C class.


If you have done this, then things can get very strange since the IDE can end up picking up portions of both libraries or portions of more than one at different points during the compilation/link process.


I would recommend using my hd44780 library package instead.
It is available in the IDE library manager so it can quickly and easily be installed from the IDE gui using the library manager.
With other i2c LCD libraries you must specify the i2c address. Most libraries are also hard coded to work with backpacks that use a specific pin mapping between the PCF8574 and the hd44780 LCD display and if your backpack doesn't use that pin mapping, it won't work.
A few libraries allow the sketch to configure the PCF8574 pin mappings and backlight control.
If the pin mappings are not specified correctly, it will not work.
The hd44780 library can auto detect everything, the i2c address, the pin mappings, and the backlight control.
You can read more about it here: https://github.com/duinoWitchery/hd44780

The hd44780 github page contains information about the library including installation instructions.
Use the IDE library manager to install it as it is easier and faster than trying to do it manually or using the zip install.
Also, by using the IDE library manager it ensures that the library is installed properly not to mention that you will also get the latest tested version of the library.

The library package includes support for several different h/w i/o interfaces used to communicate with the LCD module.

Each i/o interface has its own i/o class and its own set of examples.
The examples for each i/o class are grouped together in a directory by the name of the i/o class.
While all the examples are always available regardless of which h/w you actually have, using an example for an i/o class that is for different h/w will not work.
It will compile but obviously will not work.
The i/o class you will want to use for a PCF8574 i2c backpack which contains an i2c i/o expander chip is hd44780_I2Cexp
That i/o class includes a diagnostic sketch (I2CexpDiag) which will test the i2c signals and internal RAM of the LCD module to verify that the the library is properly communicating with the LCD module.
It is useful to first run this sketch to verify that the library is properly talking to your backpack and LCD module.
Read the instructions in the sketch for how to run it and what to expect on the serial monitor.

After running the diagnostic sketch, you can run and look at other sketches for the hd44780_I2Cexp i/o class like the HelloWorld sketch to see what header files need to be included and how to declare the lcd object.


The hd44780 library contains additional capabilities not available in other libraries like
- return status to tell if API functions are not working correctly (usually do to i2c communication issues)
- ability to enable automatic line wrapping
- ability to read the display RAM or LCD status
- faster than other libraries as Arduino can run in parallel with LCD commands/instructions

I would recommend first running the diagnostic skech I2CexpDiag to verify that everything is working, then you can run and look at the other examples included in the hd44780_I2Cexp i/o class (like HelloWorld) to see the what header files need to be included and how to declare the lcd object.

--- bill


bperrybap

Also, many if not most of the i2c lcd libraries out there will not work with the ESP8266 modules because of the way they are handling delays during initalization.
So even if the code compiles, it may end up getting watchdog timeouts and not work.

The hd44780 package has been tested and works with ESP8266 modules.

--- bill

multimedia

i  have tried all kinds and having issues with any lib and sketch but ppl on YT are getting it to work they are sometimes sharing there links to libs and code and sometimes not but i have tried the  code and had no luck, i just dont know what to do :/ btw what is hd44780 and have you got a link? and all these libraries with same name is the most annoying thing ever, they all need there own version number or something it makes a confusing subject even more confusing!

multimedia

and i know they are different i been trying everything so the code is going to be different on different examples! i cant try the same stuff expecting different results i am not crazy but this library nonsense is making me crazy :)

multimedia

Ok this is weird, i used the hd44780 library hello world i2c example uploaded it and it looked blank so i turned the contrast at the back and the previous wifi test script displayed even after reset button, no idea how that happened but seems it is working without the lcd.init line, i dont know why the hello world script didnt replace the old example though, i guess its half resolved, i will keep working onit and try and report back.

multimedia

#6
Aug 09, 2017, 03:33 pm Last Edit: Aug 09, 2017, 03:38 pm by multimedia
Got it working quite well now
thanks bill :)

<iframe width="560" height="315" src="https://www.youtube.com/embed/6G1_loGBvCs" frameborder="0" allowfullscreen></iframe> Video will be up at around 3pm youtu.be/6G1_loGBvCs

bperrybap

/ btw what is hd44780 and have you got a link? and all these libraries with same name is the most annoying thing ever, they all need there own version number or something it makes a confusing subject even more confusing!
When using embedded h/w and doing s/w at this level, it is important to slow down a bit and take time to read the information provided. I provided a link for more information about hd44780 in the post.

I do agree that many libraries having a LiquidCrystal_I2C.h and LiquidCrystal_I2C class is a real mess.
However, for better or worse, there is only one available in the Arduino IDE library manager.
So if you were using the one from the library manager as you comment says in your code, you would not be seeing multiple LiquidCrystal_I2C libraries.
But I would still recommend using hd44780 over any of the LiquidCrystal_I2C "libraries" as hd44780 has many benefits/features over them.


Ok this is weird, i used the hd44780 library hello world i2c example uploaded it and it looked blank so i turned the contrast at the back and the previous wifi test script displayed even after reset button, no idea how that happened but seems it is working without the lcd.init line, i dont know why the hello world script didnt replace the old example though, i guess its half resolved, i will keep working onit and try and report back.
But why did you not follow my recommendations for bringing up the library with your hardware?
You should have run the I2CexpDiag sketch first.

Keep in mind that a reset on the Arduino board (either from pressing it or from auto reset from doing an upload) does not reset the backpack or the LCD.
So if the hd44780 code initialized everything and then you run your example code using LiquidCrystal_I2C code it "might" work.
However, the sketch code you provided in the initial post will not work correctly since it does not make any API calls that would initialized the backpack and LCD. The LCD powers up in 8 bit mode and the initialization code puts the LCD into 4 bit mode to work with the PCF8574.
By not calling any initialization API function your sketch, the LCD will be in 8 bit mode after powering up and will not work.

When testing at this level, you must power cycle the board in order to make sure that the library code is able to properly initialize and communicate with the device.

I still highly recommend that you use the hd44780 library package and test your LCD device using the included diagnostic sketch.



Got it working quite well now
What is "it"?
Are you meaning the hd44780 library package with the hd44780_I2Cexp i/o class? or something else?

--- bill

multimedia

I dont understand half of what you mean by api calls and diag thing, all i know is its working but when i try putting a gsm module the lcd cut out and i had to re upload a hello world script to get it working again, esp 8266 really needs 5v pin as i thing having 2 x 5v devices on 3v pins is not good for the esp and it corrupts the uploaded code somehow. its working again but i wanted to have access to lat and long from gsm to a stand alone esp AP :/

dannable

LCD screen + GSM? How are you powering the setup? The GPRS/GSM shields are power hungry and typically need a separate 2 amp supply.
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

multimedia

#10
Aug 09, 2017, 04:22 pm Last Edit: Aug 09, 2017, 04:30 pm by multimedia
oh so it maybe the usb 3 that is not got enough amps :) that makes sense!

looking at the spec sheet it actually sais Power supply range: voltage is 4.6-5.2v; current is 1A or more (the current is very important).


bperrybap

#11
Aug 09, 2017, 04:52 pm Last Edit: Aug 09, 2017, 04:54 pm by bperrybap
I dont understand half of what you mean by api calls and diag thing, all i know is its working ...
Again what is IT ?

I think you may need to do some studying on C/C++ language and s/w and s/w development terminology in general.
It will likely make things easier moving forward.
More reading and less doing in some cases can be helpful.

About the diag sketch. Go back and have a read of post #1

I think I was pretty clear about the diag sketch in that post.
The hd44780 library package comes with a diagnostic sketch (I2CexpDiag) that will run tests to ensure that the library and h/w are properly working.

Also, when mixing 3v and 5v devices, you must be very careful how things are connected or you can damage things.
i.e. you can't hook up a 5v device output to a 3v only input device.
If you do, you can fry the 3v device.

That is why I have warnings about using using 3v modules such as the ESP & ARM based Arduino modules with 5v LCD backpacks in the sketch code.

Reading is your friend.
I suggest you spend some time reading about 3v and 5v interfacing and level shifters to educate yourself on the issues and to understand how to properly connect together these types of 3v and 5v devices.
It typically requires either using voltage level shifters or making modifications to the actual i2c backpack.


--- bill

multimedia

it was the other way round, the device (lcd) is 5v input and is in the esp 3v output pin, i should put into the vcc (5v) pin but it didnt work so put back onto the 3v pin.  and i like learning by doing, reading is not my strong point. i dont like c generally, i like things that are easy to remember like bash php not really python or c if i can help it, or i would definitely make my own libraries if i was into c :) thanks for you're help though i appreciate it.

bperrybap

#13
Aug 09, 2017, 05:17 pm Last Edit: Aug 09, 2017, 05:19 pm by bperrybap
it was the other way round, the device (lcd) is 5v input and is in the esp 3v output pin, i should put into the vcc (5v) pin but it didnt work so put back onto the 3v pin.  and i like learning by doing, reading is not my strong point. i dont like c generally, i like things that are easy to remember like bash php not really python or c if i can help it, or i would definitely make my own libraries if i was into c :) thanks for you're help though i appreciate it.
It is not the other way around. The backpack and LCD is a 5v device and the ESP is a 3v device.
Both devices output AND input on the i2c signals as the i2c bus is bidirectional.
i2c is still bidirectional even if you are only writing to a device.
i.e. each end the master and the slave will look at the i2c SDA and SCL pins as well as drive them even if the master is only writing to the slave.

The ESP will output 3v and expect no higher than 3v, on SDA and SCL.
While the backpack and LCD can typically run at 3v, the LCD and in particular the backlight typically are going to want more than 3v.
So if the backpack VCC is 5v, you have the EXACT scenario I described in post #11 a 5v device outputting 5v signals into a 3v device.
Here is a link to the i2c wikipedia page: https://en.wikipedia.org/wiki/I%C2%B2C
It is definitely worth reading to get an overview of how i2c works, to get a basic understanding of some of the electrical issues involved.

Because of all this, you have to take precautions when hooking up 3v and 5v devices.

I understand that you may like to jump right in and do trial and error type "doing" and experimentation, but you need to slow down a bit and do some reading in advance.
Reading is very critical to gaining knowledge especially in technical fields like h/w and embedded s/w programming so you need to start forcing yourself to slow down a bit and read more.
If you continue to skip over the step of reading, then you are likely to run into issues like getting stuck or burning up h/w.

--- bill

multimedia

I do understand what your saying but as i said it didnt work in 5v pin so put back onto 3 and it all seems to be more than fine running for hours now, if more current was in there it might be an issue which is why i wanted it to work on 5v pin but for some reason it didnt power up!

Go Up