Here’s what I did:
Sorry folks, this is a long post. @monsterthews : Read it all please.
TL;DR
In summary, lib_deps
works perfectly when you set it up correctly and when you include the correct header file names in your source code!
Gory Details, Step by Step…
mkdir -p SourceCode/temp/Joe/Library_adding
cd SourceCode/temp/Joe/Library_adding
pio init --board wemos_d1_mini32
Next, I edited the platformio.ini
file in one shell session and left it in editing mode while I carried on with the following.
Opened the Chrome Browser and navigated to PlatformIO Registry.
Note: In all of the following, each individual library page holds details of the packages and frameworks which they are compatible with. I checked each of the libraries I chose for the “Arduino” framework - as that’s what’s you are using, and the “Espressif 32” platform. They are all compatible.
WIFI Library
WARNING: This library is apparently not needed as it is built in. See following post from @pfeerick …
Search for “wifi platform:espressif32” I get lots of hits. Scroll down until I find “Wifi by Arduino”. Right click the name, open in new tab.
On the new tab I see that the installation instructions are:
pio lib install "arduino-libraries/WiFi"
This tells me that the name of the library is “arduino-libraries/WiFi” so that’s what I put into the platformio.ini
file.
ESPAsyncWebServer Library
Search for “ESPAsyncWebServer platform:espressif32”. Again, lots of libraries so scroll down. I see this one “ESPAsyncWebServer-esphome by Hristo Gochkov” so I choose it ove his/her other one with a similar name as this one has more downloads. They can’t all be wrong?. Right click the name and open in new tab again.
On the new tab the instructions to install are:
pio lib install "ottowinter/ESPAsyncWebServer-esphome"
Yes, the packager’s name is different, but no worries. Copy the name “ottowinter/ESPAsyncWebServer-esphome” into platformio.ini
.
Adafruit_Sensor Library
You should be seeing a pattern developing? If not, then IT and micro controllers are not for you!
Do the search for “Adafruit_sensor platform:espressif32” and the first hit is this one “Adafruit Unified Sensor by Adafruit”. Right click, open in new tab as before.
The name is given as “adafruit/Adafruit Unified Sensor”, so that goes into the platformio.ini
file.
DHT Library.
You can probably guess that I searched for “DHT platform:espressif32”. The first hit is the library above, “Adafruit Sensor Library” so, it appears that we don’t need this library any more.
Delete DHT from the ini file.
After all that, your platformio.ini
looks like this:
[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
monitor_speed = 9600
lib_deps=
arduino-libraries/WiFi
ottowinter/ESPAsyncWebServer-esphome
adafruit/Adafruit Unified Sensor
Save the platformio.ini
changes, and exit from the editor.
First Compile.
I copied your code into the src
folder as main.cpp
, saved it, and ran a test build.
pio run
So, all went well at the start, I now have the various platform and framework files installed on my system, but the code compilation itself failed. Brief extracts of the first compilation follow. I’ve not shown the bumff about installing the tools etc, just the library dependency finder and compilation. First, libraries:
Processing wemos_d1_mini32 (platform: espressif32; board: wemos_d1_mini32; framework: arduino)
...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Library Manager: Installing arduino-libraries/WiFi
Library Manager: WiFi @ 1.2.7 has been installed!
Library Manager: Installing ottowinter/ESPAsyncWebServer-esphome
Library Manager: ESPAsyncWebServer-esphome @ 1.2.7 has been installed!
Library Manager: Installing dependencies...
Library Manager: Installing ESPAsyncTCP-esphome
Library Manager: ESPAsyncTCP-esphome @ 1.2.3 has been installed!
Library Manager: Installing AsyncTCP-esphome
Library Manager: AsyncTCP-esphome @ 1.1.1 has been installed!
Library Manager: Installing Hash
Warning! Could not find the package with 'Hash' requirements for your system 'linux_x86_64'
Library Manager: Installing adafruit/Adafruit Unified Sensor
Library Manager: Adafruit Unified Sensor @ 1.1.4 has been installed!
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WiFi> 1.2.7
| |-- <SPI> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
| |-- <AsyncTCP-esphome> 1.1.1
| |-- <FS> 1.0
| |-- <WiFi> 1.2.7
| | |-- <SPI> 1.0
|-- <Adafruit Unified Sensor> 1.1.4
I’m ignoring this one for now, I’ll fix it later if I need to. I’ve seen those warnings previoulsy, and everything has been fine:
Library Manager: Installing Hash
Warning! Could not find the package with 'Hash' requirements for your system 'linux_x86_64'
Then the build itself:
Building in release mode
Compiling .pio/build/wemos_d1_mini32/src/main.cpp.o
Generating partitions .pio/build/wemos_d1_mini32/partitions.bin
Compiling .pio/build/wemos_d1_mini32/libaae/SPI/SPI.cpp.o
src/main.cpp:11:38: fatal error: Adafruit/Adafruit_Sensor.h: No such file or directory
compilation terminated.
*** [.pio/build/wemos_d1_mini32/src/main.cpp.o] Error 1
========================= [FAILED] Took 25.20 seconds =========================
So, I can see this message fatal error: Adafruit/Adafruit_Sensor.h: No such file or directory
which is a dead giveaway, if you read it. That file does not exist and the reason is clear, the header file is not named `Adafruit/Adafruit_Sensor.h" it is named as it tells you on the library page we opened in a separate tab above. Look at the example code or click on the “headers” tab to see exactly what header file name you should be including:
Adafruit_Sensor.h
Fix the code:
#include "Adafruit_Sensor.h"
#include "DHT.h"
You will note double quotes - which I might have mentioned a number of times previously?
I’ve fixed the DHT header too.
Second Compile.
The second compile resulted in the following:
Processing wemos_d1_mini32 (platform: espressif32; board: wemos_d1_mini32; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/wemos_d1_mini32.html
PLATFORM: Espressif 32 (2.0.0) > WeMos D1 MINI ESP32
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 3.10004.200129 (1.0.4)
- tool-esptoolpy 1.20600.0 (2.6.0)
- toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WiFi> 1.2.7
| |-- <SPI> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
| |-- <AsyncTCP-esphome> 1.1.1
| |-- <FS> 1.0
| |-- <WiFi> 1.2.7
| | |-- <SPI> 1.0
|-- <Adafruit Unified Sensor> 1.1.4
Building in release mode
Compiling .pio/build/wemos_d1_mini32/src/main.cpp.o
Compiling .pio/build/wemos_d1_mini32/lib43e/WiFi/WiFiClient.cpp.o
src/main.cpp:12:17: fatal error: DHT.h: No such file or directory
*************************************************************
* Looking for DHT.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:DHT.h"
* Web > https://platformio.org/lib/search?query=header:DHT.h
*
*************************************************************
Hmmm, looks like the details of the Adafruit Sensor library may have been telling porkies, and a separate DHT library is required after all. Note this bit at the end though:
*************************************************************
* Looking for DHT.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:DHT.h"
* Web > https://platformio.org/lib/search?query=header:DHT.h
*
*************************************************************
Let’s try following the instructions. Copy the link and paste into the browser, which is still open.
The top hit is “DHT sensor library by Adafruit” and that looks to be what we are after. Follow the instructions above to open the details page in a new tab, and we can now edit our platformio.ini
file to look like this:
[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
monitor_speed = 9600
lib_deps=
arduino-libraries/WiFi
ottowinter/ESPAsyncWebServer-esphome
adafruit/Adafruit Unified Sensor
adafruit/DHT sensor library
Check the “headers” tab for the libray, and/or the example code provided, and we see that we need #include "DHT.H"
, so that’s lucky as we already have that in src/main.cpp
.
Third Compile.
The third compilation resulted in this output for the library dependency finder:
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Library Manager: Installing adafruit/DHT sensor library
Library Manager: DHT sensor library @ 1.3.10 has been installed!
Library Manager: Installing dependencies...
Library Manager: Adafruit Unified Sensor @ 1.1.4 is already installed
Found 31 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WiFi> 1.2.7
| |-- <SPI> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
| |-- <AsyncTCP-esphome> 1.1.1
| |-- <FS> 1.0
| |-- <WiFi> 1.2.7
| | |-- <SPI> 1.0
|-- <Adafruit Unified Sensor> 1.1.4
|-- <DHT sensor library> 1.3.10
| |-- <Adafruit Unified Sensor> 1.1.4
So, the DHT library is installed and it’s only known dependency is already there from the first compilation. We should be good to go now.
The the actual compilation, says otherwise though:
Building in release mode
Compiling .pio/build/wemos_d1_mini32/src/main.cpp.o
Generating partitions .pio/build/wemos_d1_mini32/partitions.bin
Compiling .pio/build/wemos_d1_mini32/libaae/SPI/SPI.cpp.o
Archiving .pio/build/wemos_d1_mini32/libaae/libSPI.a
Indexing .pio/build/wemos_d1_mini32/libaae/libSPI.a
Compiling .pio/build/wemos_d1_mini32/lib43e/WiFi/WiFi.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:151:28: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
WiFi.begin(ssid, password);
^
In file included from src/main.cpp:9:0:
.pio/libdeps/wemos_d1_mini32/WiFi/src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'
int begin(char* ssid, const char *passphrase);
^
*** [.pio/build/wemos_d1_mini32/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.87 seconds ==========================
No problem a simple error. The WiFi.begin()
function requires a password to be not const
, so we have to declare it or cast it as such. The function is, to my mind, incorrectly written as a WiFi password, and SSID, shouldn’t ever be changed, only used in a read-only manner. However, this isn’t my library, so we have to “unconst” your const
. Edit src/main.cpp
and change it to this:
// Replace with your network credentials
char *ssid = "Fishing24";
char *password = "Fishing$602";
Fourth Compile
Running another build, pio run
, compiled “cleanly”, but with a few warnings:
src/main.cpp:15:14: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
char *ssid = "Fishing24";
^
src/main.cpp:16:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
char *password = "Fishing$602";
^
These we can worry/ignore/fix later.
These, on the other hand, do worry me:
.pio/libdeps/wemos_d1_mini32/WiFi/src/utility/spi_drv.cpp: In static member function 'static char SpiDrv::spiTransfer(char)':
.pio/libdeps/wemos_d1_mini32/WiFi/src/utility/spi_drv.cpp:36:78: warning: integer overflow in expression [-Woverflow]
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < (X*F_CPU/16000000)); }
^
.pio/libdeps/wemos_d1_mini32/WiFi/src/utility/spi_drv.cpp:37:26: note: in expansion of macro 'DELAY_SPI'
#define DELAY_TRANSFER() DELAY_SPI(10)
These messages are warning of a potential integer overflow when the DELAY_TRANSFER
macro is expanded to become DELAY_SPI(10)
which expands to:
{
int ii = 0;
do {
asm volatile("nop");
} while (++ii < (10 * F_CPU / 16000000);
}
This is cr4p ( ) code as an int
isn’t going to get as high as that. It’s an operator precedence thing - the multiply gets done before the divide. Even on an Arduino Uno, the clock (F_CPU) is 16,000,000 and 10 times that is 160,000,000. If that doesn’t fit into sizeof(int)
on your device, it’s game over! I think it should be this instead:
{
int ii = 0;
do {
asm volatile("nop");
} while (++ii < (10 * (F_CPU / 16000000));
}
Which means that the define of DELAY_SPI(X)
should be:
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < (X*(F_CPU/16000000))); }
So that the division is done first, and results in 1 for an Uno, so 10 * 1 will fit into an int
whereas 10 * F_CPU will most likely not. (Uno int
s are 16 bits only. Wemos d1 mini might be different?).
Anyway, it is a warning and will either work or it won’t. If your SPI doesn’t work, this is a probable cause. Change to a better library or log a bug.
There are other concerning warnings that I’d like to get rid of before committing code to silicon, but as I don’t have a Wemos D1 Mini, It’s not my problem!
The end of the compilation says this:
...
Archiving .pio/build/wemos_d1_mini32/libFrameworkArduino.a
Indexing .pio/build/wemos_d1_mini32/libFrameworkArduino.a
Linking .pio/build/wemos_d1_mini32/firmware.elf
Retrieving maximum program size .pio/build/wemos_d1_mini32/firmware.elf
Checking size .pio/build/wemos_d1_mini32/firmware.elf
Building .pio/build/wemos_d1_mini32/firmware.bin
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 5.3% (used 17468 bytes from 327680 bytes)
Flash: [=== ] 29.2% (used 382542 bytes from 1310720 bytes)
esptool.py v2.6
========================= [SUCCESS] Took 25.87 seconds =========================
So, it works. Lib_deps
just works, that’s it’s job. If it doesn’t work for you then I’m afraid, as I have shown, you are doing something incorrectly.
Cheers,
Norm.