Environment - DeeEmm/DIY-Flow-Bench GitHub Wiki
The ESP32 code is developed in VSCode using the PlatformIO plugin, this is the recommended way to compile and upload the code. However it should also be possible to compile and upload the code using the Arduino editor.
ESP32 support is not provided automatically within the either editor, you will need to install some additional components for ESP32 support to work.
There are many benefits to using VSCode as the ESP32 integration is a lot better and it offers more advanced features, however the Arduino editor is perhaps simpler and less daunting to the newcomer.
Below we will outline how to set up both environments.
Setting up the VSCode environment
If you are a VSCode user or want to use VSCode instead of the Arduino editor then the following step by step outline should help you get up and running. Essentially this is a four stage process
- Installing VSCode
- Installing the PlatformIO plugin
- Compiling and uploading the firmware
- Transferring the webserver files to the board
Installing VSCode & PlatformIO
VSCode is a free download and is available from https://code.visualstudio.com/ Download and install the application as you would any other app.
Once you have installed VSCode, open the app up and on the left hand side of the screen you will see a number of icons. If you click on the 'extensions' icon a sidebar will open up. At the top of the side bar is a search box, type 'PlatformIO' in to it. You are looking for the 'PlatformIO IDE' extension by 'PlatformIO'. Click on the install button to install it. Once installed you will get a neat alien head icon appear below the 'Extensions' icon. You will also get some additional icons added to the status bar at the bottom of the screen.
Next open the DIY-Flow-Bench project that you have previously downloaded by browsing to the project folder. Once opened you should be able to view the project file tree by clicking the 'Explorer' icon in the left sidebar.
One of the great things with VSCode and PlatformIO is that all project dependencies and compile-time settings are stored in a file called 'platformIO.ini' This file is read by PlatformIO whenever you open or compile the project and it will automagically download any missing dependencies into a folder called 'libdeps' that it will create in the project tree. It also sets the board type and environment. platformIO.ini is already provided in the project root and should be automatically detected when you open the project.
Compiling and uploading the firmware
To compile the software you can either use the link within the PlatformIO sidebar (Project Tasks > release > Build) or use the 'tick' icon in the status bar at the bottom of the screen. The editor will then open a dialog up at the bottom of the screen and you should see the compilers verbose output as it compiles and links each dependency.
When compiling for the first time the process will likely fail as it has to download the missing dependencies, but simply re-run the build process until it compiles.
Uploading the firmware is pretty straightforwards as PlatformIO will automatically try to locate the boards USB port. If it does not automatically find the port you can try power cycling the board and trying again. If this fails you can also manually set the port using the link in the status bar.
It is worth noting that clicking on the 'home' icon in the status bar will open up the PlatformIO home page where you can view a list of automatically detected ports by clicking on the 'Devices' icon.
Running the app
The first time you run the app it will create a WiFi access-point called DIYFB. Connect to this Wifi Network using the following password
123456789
Once connected you should be able to type the following address into your browser
If your computer does not support Multicast DNS (mDNS) you may have to access the application using its IP address. To find the IP address, open up the serial monitor and reboot the board. It will report system info including the IP address in the serial monitor.
You should then be able to access the application. When accessing the application for the first time it does not have a Web-UI file installed, you will need to upload the index.html.gz page manually. This can be found in the data folder of the repository. The application provides an upload dialog to do this via the browser.
Once uploaded you can refresh the page to view the application.
Baseline configuration and calibration data is automatically created. Configuration data can be viewed and edited from the configuration tab in the Web-UI.
NOTE: If the data in the configuration tab looks like capitalised text instead of valid values, then either the config.json file has not been created or is corrupt. Rebooting the ESP32 will force the creation of the config.json and cal.json files if they do not exist.
Connecting to local WiFi
Once done you have the application running you can edit the 'WiFi SSID' and 'WiFi Password' credentials on the configuration page so that the ESP32 will connect to the nominated WiFi network. Simply edit and and save the data. When you reboot the board it will automatically attempt to connect to your local WiFi network using the credentials supplied. If it does not establish a connection within the time period defined by 'WiFi Timeout' then it will default back to creating a WiFi access point (AP Mode) that can be accessed by using the credentials stored in the 'WiFi AP SSID' and 'WiFi AP Password' Fields.
A note for those working with code from a development branch
As the committed code has not been configured for release the environment may not be set up for the correct board. To check / alter which board is set up you will need to check both platformIO and configuration.h
In platformIO you need to make sure that the board is NOT set to ESP-WROVER-KIT and the upload speed is reduced to 460800. This is the fastest tested speed that the WemosD1 was able to achieve in tests.
platformIO
[env:esp32dev]
board = esp32
upload_speed = 460800
...
[env:esp-rover-kit]
board = esp32
upload_speed = 460800
Similarly in pins.json you need to ensure that the correct board is selected
"BOARD_TYPE" : "WEMOS_D1_R32",
Additionally other configuration settings may be disabled or altered.
NOTE: The above ONLY applies to development branches, it does not apply to official releases where all settings are pre-configured to work with the WemosD1 / DIY-Flow-Bench shield.
Setting up the Arduino editor
If you are already familiar with the Arduino editor, or perhaps already have it installed then you might like to set it up for the ESP32.
Essentially there's three parts to installing the ESP32 firmware using the Arduino editor.
- Setting up the Arduino Editor to recognise the ESP32 board
- Compiling and uploading the firmware
- Transferring the webserver files to the board
I'm going to cheat here and send you to another website as the methods to set up the Arduino Editor are already well covered and whilst I will eventually update the Wiki with more ESP32 specific instructions, at the moment I'm tied up with programming. ;)
You need to set up the editor...
https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
Dependencies
The following dependencies are used in the project and should be installed via the library manager.
- Wire.h https://github.com/espressif/arduino-esp32/blob/master/libraries/Wire/src/Wire.h (Wire is part of the arduino-esp32 Library)
- WiFi.h https://github.com/espressif/arduino-esp32 (WiFi is part of the arduino-esp32 Library)
- AsyncTCP.h https://github.com/esphome/AsyncTCP (This version is used in preference to original me-no-dev code)
- ESPAsyncWebServer.h https://github.com/esphome/ESPAsyncWebServer.git (This version is used in preference to original me-no-dev code)
- SPIFFS.h https://github.com/espressif/arduino-esp32 (SPIFFS is part of the arduino-esp32 Library)
- ArduinoJson.h https://arduinojson.org/ (Note V6.19.4 used)
- ESPmDNS.h https://github.com/espressif/arduino-esp32 (ESPmDNS is part of the arduino-esp32 Library)
- ADS1115-lite.h https://github.com/terryjmyers/ADS1115-Lite.git
- Tiny_BME280_Arduino_Library https://github.com/fabyte/Tiny_BME280_Arduino_Library.git
Compiling and uploading the firmware
First you need to Rename DIY-Flow-Bench.cpp to DIY-Flow-Bench.ino for Arduino IDE compatibility
Next you need to set up the Arduino environment. In the Arduino Editor go to Tools > Boards > ESP32 and select the 'ESP32 Dev Module'.
NOTE: Selecting this specific board will expose some additional settings to you which allows you to configure the following parameters.
Next you need to set up the storage partitions, go to Tools > Partition Scheme and select 'No OTA 2MB APP / 2MB SPIFFS' this will allocate 2mb to application storage and 2mb for the SPIFFS partition.
Then you can select your upload port and compile and upload the firmware using the buttons in the top left of the editor.
Running the app
The first time you run the app it will create a WiFi access-point called DIYFB. Connect to this Wifi Network using the following password
123456789
Once connected you should be able to type the following address into your browser
If your computer does not support Multicast DNS (mDNS) you may have to access the application using its IP address. To find the IP address, open up the serial monitor and reboot the board. It will report system info including the IP address in the serial monitor.
You should then be able to access the application. When accessing the application for the first time it does not have a Web-UI file installed, you will need to upload the index.html.gz page manually. This can be found in the data folder of the repository. The application provides an upload dialog to do this via the browser.
Once uploaded you can refresh the page to view the application.
Baseline configuration and calibration data is automatically created. Configuration data can be viewed and edited from the configuration tab in the Web-UI.
NOTE: If the data in the configuration tab looks like capitalised text instead of valid values, then either the config.json file has not been created or is corrupt. Rebooting the ESP32 will force the creation of the config.json and cal.json files if they do not exist.
Connecting to local WiFi
Once done you have the application running you can edit the 'WiFi SSID' and 'WiFi Password' credentials on the configuration page so that the ESP32 will connect to the nominated WiFi network. Simply edit and and save the data. When you reboot the board it will automatically attempt to connect to your local WiFi network using the credentials supplied. If it does not establish a connection within the time period defined by 'WiFi Timeout' then it will default back to creating a WiFi access point (AP Mode) that can be accessed by using the credentials stored in the 'WiFi AP SSID' and 'WiFi AP Password' Fields.