|
1 | | -# esp32_example |
| 1 | +# AtomVM DHT Example Program |
2 | 2 |
|
3 | | -Welcome to the esp32_example AtomVM application. |
| 3 | +Welcome to the `dht_example` AtomVM application. |
4 | 4 |
|
5 | | -To build and flash this application to your ESP32 device, issue the `esp32_flash` target |
| 5 | +This example application will drive a DHT11 or DHT22 temperature and humidity sensor attached to an ESP32 device using a single data wire and print readings to the console. |
6 | 6 |
|
7 | | - shell$ rebar3 esp32_flash |
| 7 | +The `dht_example` program illustrates use of the DHT API by taking a temperature and humidity reading every 30 seconds, and displaying the result on the console. |
| 8 | + |
| 9 | +For this application, you will need: |
| 10 | + |
| 11 | +* An ESP32 device, flashed with the [AtomVM](https://github.com/bettio/AtomVM) image (including the VM and core libraries), and capable of connecting via UART to your development machine; |
| 12 | +* A DHT11 or DHT22 device, typically marketed as an integrated development board; |
| 13 | +* The [`esptool.py`](https://github.com/espressif/esptool) tool (for flashing); |
| 14 | +* The [`git`](https://git-scm.com) version control tool; |
| 15 | +* [Erlang/OTP 21](https://www.erlang.org) or higher, along with [`rebar3`](https://www.rebar3.org); |
| 16 | +* A serial monitor program of your choice (e.g, [`minicom`](https://en.wikipedia.org/wiki/Minicom)) |
| 17 | + |
| 18 | +While the [IDF SDK](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/) and required toolchains are not required, they may make life a little easier. |
| 19 | + |
| 20 | +## Getting Started |
| 21 | + |
| 22 | +### Connection |
| 23 | + |
| 24 | +To run this example program, connect the positive (+) lead on the DHT device to +3.3v power on the ESP32, the negative lead (-) to a ground pin on the ESP32, and the data pin to GPIO pin 22 on the ESP32 device. |
| 25 | + |
| 26 | + +-----------+ +-----------+ |
| 27 | + | o-------- +3.3v ------------o VCC | |
| 28 | + | DHT11 o-------- data -------------o IO21 | |
| 29 | + | or o-------- unused | | |
| 30 | + | DHT22 o-------- gnd --------------o GND | |
| 31 | + | | | | |
| 32 | + +-----------+ | | |
| 33 | + | ESP32 | |
| 34 | + +-----------+ |
| 35 | + |
| 36 | +### Build Instructions |
| 37 | + |
| 38 | +To build and flash this application to your ESP32 device, issue the `esp32_flash` target to the `rebar3` command, and optionally specify the device port and baud rate, if they do not match the defaults. |
| 39 | + |
| 40 | +> Note. For information about the `esp32_flash` target, see the [`atomvm_rebar3_plugin`](https://github.com/atomvm/atomvm_rebar3_plugin) instructions. |
| 41 | +
|
| 42 | + shell$ rebar3 esp32_flash -p /dev/ttyUSB0 -b 115200 |
| 43 | + ===> Fetching atomvm_rebar3_plugin |
| 44 | + ===> Fetching packbeam |
| 45 | + ===> Analyzing applications... |
| 46 | + ===> Compiling atomvm_rebar3_plugin |
| 47 | + ===> Compiling packbeam |
| 48 | + ===> Verifying dependencies... |
| 49 | + ===> App atomvm_lib is a checkout dependency and cannot be locked. |
| 50 | + ===> Analyzing applications... |
| 51 | + ===> Compiling atomvm_lib |
| 52 | + ===> Analyzing applications... |
| 53 | + ===> Compiling dht_example |
| 54 | + ===> AVM file written to : atomvm_lib.avm |
| 55 | + ===> AVM file written to : dht_example.avm |
| 56 | + ===> esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x210000 .../atomvm_lib/examples/dht_example/_build/default/lib/dht_example.avm |
| 57 | + |
| 58 | + esptool.py v2.1 |
| 59 | + Connecting........_____. |
| 60 | + Chip is ESP32D0WDQ6 (revision (unknown 0xa)) |
| 61 | + Uploading stub... |
| 62 | + Running stub... |
| 63 | + Stub running... |
| 64 | + Configuring flash size... |
| 65 | + Auto-detected Flash size: 4MB |
| 66 | + Wrote 16384 bytes at 0x00210000 in 1.4 seconds (91.4 kbit/s)... |
| 67 | + Hash of data verified. |
| 68 | + |
| 69 | + Leaving... |
| 70 | + Hard resetting... |
| 71 | + |
| 72 | +Connect to the device using the USB port (e.g., via `minicom`), and you should see something like: |
| 73 | + |
| 74 | + Found AVM partition: size: 1048576, address: 0x110000 |
| 75 | + Booting file mapped at: 0x3f430000, size: 1048576 |
| 76 | + Starting: dht_example.beam... |
| 77 | + --- |
| 78 | + Temperature: 21.3C Humidity: 41.6% |
| 79 | + Temperature: 21.4C Humidity: 41.4% |
| 80 | + Temperature: 21.3C Humidity: 41.3% |
| 81 | + ... |
0 commit comments