Inhaltsverzeichnis
Mit dem NodeMCU Board ESP32 Impulse zählen um den Durchfluß messen
Ablauf:
- Firmware konfigurieren
- Lua Script erstellen
- Board anschließen und konfigurieren
In der ESP32 Lua Lib gibt es eine eigene Implementierung für einen Zähler ⇒ https://nodemcu.readthedocs.io/en/dev-esp32/modules/pulsecnt/
Alternativ ist das auch mit dem ESP32 möglihch ⇒ Mit dem NodeMCU Board ESP8266 Impulse zählen - Durchfluß messen, suche aber nach einer einfachen Lösung das in einem eignen Thread durchzuführen, möglichst unabhängig von der Last auf der CPU.
Technik
Der Sensor verwendet den Hall Effekt um die Drehzahl eines Rades zu bestimmen.
Flowmeter anschließen
- Schwarz ⇒ GND
- Rot ⇒ 3,3V
- Gelb ⇒ D1 ⇒ Daten
Firmware erstellen
Um die LUA Firmware zu erstellen gibt es 3 Möglichkeiten
- Unter Windows mit Hilfe eines fertigen Docker Images
- Linux Installation mit alle notwendigen Libraries und dort übersetzen
- Online Cloud Service
Auf Windows 10 mit Docker Image unter VMWare 16 übersetzen
Mit der VMware Workstation 16 kann auch ein Docker Container gestartet werden, d.h. es muss Docker gar nicht erst installiert werden.
NodeMCU Code von Git laden
Git Bash im gewählten Ober-Ordern wie „c:\entwicklung\es32\firmware“ öffnen:
git clone --branch dev-esp32 --recurse-submodules https://github.com/nodemcu/nodemcu-firmware.git nodemcu-firmware-esp32
Docker Image Anleitung ⇒ https://hub.docker.com/r/marcelstoer/nodemcu-build
Docker Image laden:
vctl pull marcelstoer/nodemcu-build
Starten:
vctl system start
Konfigurieren:
vctl run -c 4 -m 16g --rm -it -v C:/entwicklung/esp32/firmware/nodemcu-firmware-esp32:/opt/nodemcu-firmware marcelstoer/nodemcu-build configure-esp32
Über das Konfigurations Menü können nun alle benötigten Eigenschaften eingestellt werden.
Bauen:
vctl run -c 4 -m 16g --rm -it -v C:/entwicklung/esp32/firmware/nodemcu-firmware-esp32:/opt/nodemcu-firmware marcelstoer/nodemcu-build build
Alternativ - In einer eigenen Linux VM
tool Chain aufbauen: Siee ⇒ https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-setup-scratch.html
Repos einrichten:
# Repos einrichten cd /etc/yum.repos.d vi oraclelinux-codeready-ol8.repo [OL8_codeready_builder] name= checkmk dependencies baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/x86_64 enabled=1 gpgcheck=0 dnf install oracle-epel-release-el8.x86_64 dnf install oraclelinux-developer-release-el8.x86_64
Tools installieren:
# Tool Chain aufsetzen dnf group install "Development Tools" dnf install gcc dnf install git wget make flex bison -- debian libncurses-dev dnf install ncurses-devel dnf install gperf -- debain --python python-serial dnf install python3 python3-pip dnf install python3-pyserial dnf install readline-devel.x86_64
ESP32 Build:
mkdir -p /srv/esp32/nodemcu cd srv/esp32/nodemcu git clone --branch dev-esp32 --recurse-submodules https://github.com/nodemcu/nodemcu-firmware.git nodemcu-firmware-esp32 cd nodemcu-firmware-esp32 make menuconfig # python3 einstellen! # Dependencies /usr/bin/python3 -m pip install --user -r /srv/esp32/nodemcu/nodemcu-firmware-esp32/sdk/esp32-esp-idf/requirements.txt # -- ================================ make #prüfen cd /srv/esp32/nodemcu/nodemcu-firmware-esp32/build esptool.py --chip esp32 image_info NodeMCU.bin esptool.py v3.0 Entry point: 40081364 7 segments Segment 1: len 0x25840 load 0x3f400020 file_offs 0x00000018 [DROM] ........ Checksum: b3 (valid) Validation Hash: 9ac08378580465978690d5cf5a69725ab94c2fe43e2d2ef62fd650055484d09a (valid) # -- ================================ # falls der Kontroller angeschloßen ist und erkannt wird make flash
Siehe ⇒ https://www.microdev.it/wp/en/2018/08/17/esp32-nodemcu-firmware-compiling/
Problem:
Connecting........_____....._____....._____....._____....._____....._____....._____ /dev/ttyUSB0 failed to connect: Failed to connect to Espressif device: Invalid head of packet (0x08)
Beim Flaschen über die rechte Taste Controller in den richtigen Status setzen!
Online Firmware Image erstellen lassen
Über ⇒ https://nodemcu-build.com/
Auf ESP32 Beta Build achten!
Gewählte Module:
file gpio net node pulsecnt spi tmr uart wifi.
Firmware auf den Controller einspielen
Python Setup
Python 3.8 installieren (z.b. nach C:\python38)
cd C:\python38 -- upgrade pip cd C:\python38> .\python.exe -m pip install --upgrade pip -- ESP Tools installieren C:\python38> .\python.exe -m pip install --upgrade esptool
ESP Tool Setup
Clone von https://github.com/espressif/esptool.git
cd c:\entwicklung\esp32 mkdir esptool cd esptool # über Git Bash falls nicht im Pfad git clone https://github.com/espressif/esptool.git
Chip ID auslesen:
cd c:\entwicklung\esp32\esptool C:\Python38\python.exe .\esptool.py chip_id esptool.py v3.1-dev Found 2 serial ports Serial port COM4 Connecting........_____... Detecting chip type... ESP32 Chip is ESP32-D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None Crystal is 40MHz MAC: 24:0a:c4:30:f7:ec Uploading stub... Running stub... Stub running... Warning: ESP32 has no Chip ID. Reading MAC instead. MAC: 24:0a:c4:30:f7:ec Hard resetting via RTS pin...
Image auf den Controller schreiben
Altes Image zuvor löschen:
C:\Python38\python.exe .\esptool.py --chip esp32 -p COM4 erase_flash
Nun den das Firmware Image auf den Kontroller schreiben mit „esptool.py –chip esp32 -p <USB-to-Serial Port> write_flash -z 0x1000 <path to .bin>“
C:\Python38\python.exe .\esptool.py --chip esp32 -p COM4 write_flash -z 0x1000 C:\entwicklung\esp32\firmware\nodemcu-firmware-esp32\nodemcu_dev-esp32_20210304-1641.bin esptool.py v3.1-dev Serial port COM4 Connecting........_ Chip is ESP32-D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None Crystal is 40MHz MAC: 24:0a:c4:30:f7:ec Uploading stub... Running stub... Stub running... Configuring flash size... Compressed 1448768 bytes to 926007... Wrote 1448768 bytes (926007 compressed) at 0x00001000 in 82.6 seconds (effective 140.4 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin...
Per ESPlorer auf den Controller zugreifen
ESPlorer
cd /c/entwicklung/nodeMCU git clone https://github.com/4refr0nt/ESPlorer.git
Oder einfacher direkt als lauffähige Version über https://esp8266.ru/esplorer/ Dokumentation siehe http://esp8266.ru/download/esp8266-doc/Getting%20Started%20with%20the%20ESPlorer%20IDE%20-%20Rui%20Santos.pdf
Nach dem Start (doppel Click auf ESPlorer.jar) haben wir das erste Problemchen, leider habe ich ärgerlicher Weise ein 4K Display ⇒ alles viel zu klein …..
In der Bat Datei den direkten Pfad zur Java Exe angeben und die „Java dpi awarene“ ausschalten:
Find java.exe and/or javaw.exe likely found in C:\Program Files\Java\jre(version#)\bin. Right click on it and select -> Properties. Go to Compatibility tab. Check Override high DPI scaling behavior. Choose System for Scaling performed by: Click OK.
Quelle Google
Nun kann auch ohne Lupe mit dem Tool gearbeitet werden.
Probleme …
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) flash read err, 1000 ets_main.c 371
Laut Dokumentation „The „flash read err, 1000“ indicates that the ESP32 didn't find a bootloader binary at offset 0x1000.“
Image testen:
cd C:\entwicklung\esp32\esptool\esptool> C:\Python38\python.exe .\esptool.py --chip esp32 image_info C:\entwicklung\esp32\firmware\nodemcu-firmware-esp32\nodemcu_dev-esp32_20210304-16 41.bin esptool.py v3.1-dev A fatal error occurred: Invalid firmware image magic=0xff
Wie aber muss nun das Image gebaut werden damit es funktioniert? Ein Image aus der Cloud zeigt das gleiche Probem! Zwei Kontroller nun mit einem fertigen MicroPython Image getestet, beide funktionieren!
Test ich jetzt diese Image:
PS C:\entwicklung\esp32\esptool\esptool> C:\Python38\python.exe .\esptool.py --chip esp32 image_info C:\entwicklung\esp32\esp32-idf4-20210202-v1.14.bin esptool.py v3.1-dev Image version: 1 Entry point: 40080630 4 segments Segment 1: len 0x00004 load 0x3fff0018 file_offs 0x00000018 [BYTE_ACCESSIBLE,DRAM,DIRAM_DRAM] Segment 2: len 0x0141c load 0x3fff001c file_offs 0x00000024 [BYTE_ACCESSIBLE,DRAM,DIRAM_DRAM] Segment 3: len 0x03250 load 0x40078000 file_offs 0x00001448 [CACHE_APP] Segment 4: len 0x00d9c load 0x40080400 file_offs 0x000046a0 [IRAM] Checksum: d7 (valid) Validation Hash: dfeac035b8b1dd1bb9600420c3939abadee18510b74c897d409c6686e0df195e (valid)
Pulse Zähler Code
pinPulseInput = 2 llim = -32768 hlim = 32767 pcnt = pulsecnt.create(7) -- Use unit 7 (0-7 are allowed) pcnt:chan0Config( pinPulseInput, --pulse_gpio_num pulsecnt.PCNT_PIN_NOT_USED, --ctrl_gpio_num If no control is desired specify PCNT_PIN_NOT_USED pulsecnt.PCNT_COUNT_INC, --pos_mode PCNT positive edge count mode pulsecnt.PCNT_COUNT_DIS, --neg_mode PCNT negative edge count mode pulsecnt.PCNT_MODE_KEEP, --lctrl_mode Ctrl low PCNT_MODE_KEEP, PCNT_MODE_REVERSE, PCNT_MODE_DISABLE pulsecnt.PCNT_MODE_KEEP, --hctrl_mode Ctrl high PCNT_MODE_KEEP, PCNT_MODE_REVERSE, PCNT_MODE_DISABLE llim, --counter_l_lim [Range -32768 to 32767] hlim --counter_h_lim [Range -32768 to 32767] ) -- Clear counting pcnt:clear() -- Poll the pulse counter print("Current pulse counter val:" .. pcnt:getCnt())
⇒ https://nodemcu.readthedocs.io/en/dev-esp32/modules/pulsecnt/
Display anschließen
Display Anzeige ⇒ http://www.robertprice.co.uk/robblog/using-an-i2c-128x64-oled-display-with-lua-on-a-nodemcu/