PlatformIO Community

LiquidCrystal Library: include error

I do not understand why #include <LiquidCrystal.h> is not found.
I follow the quick start and set the platformio.ini. Then include the corresponding header in main.cpp

image

When it’s not working the quick start guide indicate to run this command:

 “Menu: View > Command Palette… > PlatformIO: Rebuild C/C++ Project Index”

But it does not exist, I found only : Platformio: Rebuild Intellisense Index Which I run.

Still same result.

EDIT:
The program build and can be download to the arduino. With hazardous behaviour. Sometimes, the screen stay blank, sometimes the letter “w” fill the screen.

The same program copy and past to the “Arduino IDE”, without the include <Arduino.h>, works perfectly.

Does the project build?

Yes, it builds. I update my answer to add more information. Thanks for the question.

If it builds the headers must be found. Try executing Ctrl+Shift+P → Rebuild IntelliSense again.

Also, the version of the LiquidCrystal library you’re using comes from author fmalpartida, which doesn’t seem to be the ‘official’ one and may behave differently. You may want the standard Arduino one via

lib_deps =
   arduino-libraries/LiquidCrystal @ ^1.0.7

as per this.

I tried with the version you proposed too. The one I show at first is the one proposed by vscode when looking for “LiquidCrystal” Library.

It is still not working. Here all the steps done starting with a new project:

  1. new project from PIO Home
  2. Choose:
    • Board: Arduino Uno
    • Framework: Arduino
    • Location: Use default location selected
  3. Search libraries from PIO HOme
    • do not choose the first library
    • choose: “LiquidCrystal” by Arduino
    • click on “Add to Project”
    • which install the same library used within Arduino IDE
  4. Executing Ctrl+Shift+P →PlatformIO: Rebuild C/C++ Project Index
  5. add #include <LiquidCrystal.h> in main.cpp => error rise
  6. try to get ride off this error with no success:
    • restart vscode
    • Executing Ctrl+Shift+P →PlatformIO: Rebuild C/C++ Project Index
  7. add “hello world” code:

#include <Arduino.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the number of columns and rows on the LCD
lcd.begin(16, 2);

// Print a message to the LCD.
lcd.print(“Hello World”);
}

void loop() {
}

  1. build successful:

>Executing task in folder Theremine Lumineux: platformio run

Processing uno (platform: atmelavr; board: uno; framework: arduino)


Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR (3.3.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- framework-arduino-avr 5.1.0
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder → http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies…
No dependencies
Building in release mode
Checking size .pio/build/uno/firmware.elf
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [= ] 10.2% (used 208 bytes from 2048 bytes)
Flash: [= ] 12.2% (used 3940 bytes from 32256 bytes)
==================== [SUCCESS] Took 0.81 seconds============

Terminal will be reused by tasks, press any key to close it.

  1. upload successful:

Configuring upload protocol…
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port…
Auto-detected: /dev/ttyACM0
Uploading .pio/build/uno/firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file “.pio/build/uno/firmware.hex”
avrdude: writing flash (3940 bytes):

Writing | ################################################## | 100% 0.64s

avrdude: 3940 bytes of flash written
avrdude: verifying flash memory against .pio/build/uno/firmware.hex:
avrdude: load data flash data from input file .pio/build/uno/firmware.hex:
avrdude: input file .pio/build/uno/firmware.hex contains 3940 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.51s

avrdude: verifying …
avrdude: 3940 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done. Thank you.

===================== [SUCCESS] Took 3.20 seconds =================

  1. result on arduino: only “w” letters and few “PI” letters
  2. load the same program from arduino IDE: “Hello world” appears on the LCD screen
  3. reload from vscode: the letter “w” is writen after “Hello world” and then recover it!!!
  4. tried with differents text loading from “arduino IDE” and then from vscode. Loading from vscode will always result by some “w” filling the screen. Sometime it also erase the previous message.

I just realize that the compilation is not done for the current opened project but for another one!

I also manage to “solve” the issue on “include” doing the following:

  1. copy/past the LiquidCrystal library in include folder
  2. add in the code :

#include “LiquidCrystal/src/LiquidCrystal.h”

Now, I’m looking for how to build the current opened file. And check if that could have solved the “include ussue” here without having to copy/past the library.

Aha okay thath sounds more likely, I was just about to test this on my own hardware.

Please use the project environment switcher to select the project + environment. Building is not done on the currently opened file and cannot be set to do so.

Thanks for your time and apologize. I just discover the “project environment switcher”, minutes ago. A petty I did not see your answer earlier.
Pointing at the correct project solve all the issues. I removed the library from the include folder.
Thanks again.