{"id":22253925,"url":"https://github.com/mcauser/micropython-esp8266-dht-nokia-5110","last_synced_at":"2025-07-28T05:32:55.516Z","repository":{"id":150620642,"uuid":"66797028","full_name":"mcauser/MicroPython-ESP8266-DHT-Nokia-5110","owner":"mcauser","description":"MicroPython example using a DHT12, AM2320 and a Nokia 5110 with an ESP8266","archived":false,"fork":false,"pushed_at":"2018-08-07T16:05:52.000Z","size":3927,"stargazers_count":43,"open_issues_count":1,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T15:50:43.675Z","etag":null,"topics":["am2320","dht12","esp8266","micropython","nokia5110","wemos-d1-mini"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcauser.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-28T23:58:39.000Z","updated_at":"2021-08-14T22:58:25.000Z","dependencies_parsed_at":"2023-05-06T09:32:18.888Z","dependency_job_id":null,"html_url":"https://github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mcauser/MicroPython-ESP8266-DHT-Nokia-5110","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2FMicroPython-ESP8266-DHT-Nokia-5110","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2FMicroPython-ESP8266-DHT-Nokia-5110/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2FMicroPython-ESP8266-DHT-Nokia-5110/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2FMicroPython-ESP8266-DHT-Nokia-5110/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcauser","download_url":"https://codeload.github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2FMicroPython-ESP8266-DHT-Nokia-5110/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267468386,"owners_count":24092334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["am2320","dht12","esp8266","micropython","nokia5110","wemos-d1-mini"],"created_at":"2024-12-03T07:21:04.723Z","updated_at":"2025-07-28T05:32:55.508Z","avatar_url":"https://github.com/mcauser.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MicroPython ESP8266 DHT Nokia 5110\n\nWeMos D1 mini + AM2320 + DHT12 + Nokia 5110 (PCD8544)\n\n![DHT Nokia](https://raw.github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110/master/photos/dht-nokia.jpg)\n\n## Parts\n\n* [WeMos D1 Mini](http://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html) $4.00 USD\n* [Nokia 5110 module](http://www.aliexpress.com/item/1pc-Lowest-Price-84-48-84x84-LCD-Module-White-backlight-adapter-PCB-for-Nokia-5110-Newest/32401396134.html) $2.10 USD\n* [Breadboard 400 point](http://www.aliexpress.com/item/Quality-mini-bread-board-breadboard-8-5CM-x-5-5CM-400-holes/32347239015.html) $1.02 USD\n* [Jumper wire](http://www.aliexpress.com/item/Free-Shipping-140pcs-in-one-package-convenient-New-Solderless-Flexible-Breadboard-Jumper-wires-Cables-HOT-Sale/2044172287.html) $1.72 USD\n* [DHT12](http://www.aliexpress.com/item/DHT12-Digital-Temperature-and-Humidity-Sensor-Fully-compatible-with-DHT11/32654795239.html) $0.92 USD\n* [AM2320](http://www.aliexpress.com/item/AM2320-Digital-Temperature-and-Humidity-Sensor-Original-authentic-Can-replace-SHT20-SHT10/32653665528.html) $1.65 USD\n\n## Pinouts\n\nThe DHT12 and AM2320 sensors have the same pins:\n\n* 1 VDD\n* 2 SDA\n* 3 GND\n* 4 SCL\n\n(left to right, grill facing you)\n\nUsing D1 + D2 for I2C on the WeMos D1 Mini.\n\n* D1 = GPIO5 = SCL\n* D2 = GPIO4 = SDA\n\n\n## Installation\n\nStart by cloning this repo.\n\n```\n$ git clone git@github.com:mcauser/MicroPython-ESP8266-DHT-Nokia-5110.git\n```\n\n* [Install MicroPython on your ESP8266 device](#install-micropython-on-your-esp8266-device)\n\t* [Install python](#install-python)\n\t* [Download latest MicroPython firmware](#download-latest-micropython-firmware)\n\t* [Flash firmware with esptool](#flash-firmware-with-esptool)\n\t* [Verify firmware](#verify-firmware)\n* [Install scripts with WebREPL](#install-scripts-with-webrepl)\n\t* [Configure Access Point](#configure-access-point)\n\t* [Start WebREPL](#start-webrepl)\n\t* [Connect to Access Point](#connect-to-access-point)\n\t* [Upload files with WebREPL](#upload-files-with-webrepl)\n* [Setup and test Nokia 5110 display](#setup-and-test-nokia-5110-display)\n* [Setup and test DHT12](#setup-and-test-dht12)\n* [Setup and test AM2320](#setup-and-test-am2320)\n\n\n## Install MicroPython on your ESP8266 device\n\nI am using a [WeMos D1 Mini](http://www.wemos.cc/Products/d1_mini.html), but you can use any ESP8266 device.\n\nThe WeMos D1 Mini features an ESP-12F with 4MB flash.\n\nIf you already have [MicroPython](http://micropython.org/) [v1.8.x](https://github.com/micropython/micropython/releases) installed on your device, you can skip down to [installing the scripts](#install-scripts-with-webrepl).\n\n### Install Python\n\nIf you are using [brew](http://brew.sh/), installing Python 2.7 is a one-liner. Install [pip](https://pip.pypa.io/en/stable/) to manage python packages.\n\n```\n$ brew install python\n$ pip install --upgrade pip setuptools\n```\n\nYou can use pip to install Python packages. eg.\n\n```\n$ pip search SomePackage\n$ pip install SomePackage\n$ pip install --upgrade SomePackage\n$ pip uninstall SomePackage\n```\n\nInstall [esptool](https://github.com/themadinventor/esptool/) with pip\n\n```\n$ pip install esptool\n```\n\n### Download latest MicroPython firmware\n\nOpen [http://micropython.org/download/#esp8266](http://micropython.org/download/#esp8266)\n\nDownload the latest firmware, currently v1.8.3-61\n\n```\n$ wget http://micropython.org/resources/firmware/esp8266-20160827-v1.8.3-61-g531217a.bin\n```\n\n### Flash firmware with esptool\n\nThe WeMos D1 mini uses a [CH340G](http://www.wch.cn/download/CH341SER_MAC_ZIP.html) USB-TTL driver, which shows up on my MacBook Pro as either `/dev/tty.wchusbserial1410` or `/dev/tty.wchusbserial1420`.\n\nIf you are using another device, you may find yours to be `/dev/ttyUSB0`. Find yours with:\n\n```\n$ ls /dev/tty*\n```\n\nWhen deploying new firmware, it's best to completely erase all previous versions. The first run executes suspiciously quick, so I run it twice.\n\n```\n$ esptool.py -p /dev/tty.wchusbserial1420 erase_flash\nesptool.py v1.1\nConnecting...\nErasing flash (this may take a while)...\n```\n\nUpload the new MicroPython firmware.\n\n```\n$ esptool.py -p /dev/tty.wchusbserial1420 write_flash -fm dio -fs 32m 0 esp8266-20160827-v1.8.3-61-g531217a.bin\nesptool.py v1.1\nConnecting...\nRunning Cesanta flasher stub...\nFlash params set to 0x0240\nWriting 532480 @ 0x0... 43008 (8 %)\n...\nWriting 532480 @ 0x0... 316416 (59 %)\n...\nWriting 532480 @ 0x0... 532480 (100 %)\nWrote 532480 bytes at 0x0 in 46.0 seconds (92.6 kbit/s)...\nLeaving...\n```\n\nMore info in the [MicroPython docs](http://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html#deploying-the-firmware) on flashing the firmware.\n\n### Verify firmware\n\n```\n$ screen /dev/tty.wchusbserial1420 115200\n```\n\nClick your hardware Reset button or `Control+D` in screen.\n\n```python\n(lots of funny characters) ets_task(40100390, 3, 3fff6300, 4)\ncould not open file 'main.py' for reading\n\nMicroPython v1.8.3-61-g531217a on 2016-08-27; ESP module with ESP8266\nType \"help()\" for more information.\n\u003e\u003e\u003e\n```\n\nCheck the firmware md5 matches. You should see True. If not, `erase_flash` and `write_flash` again, or try different `write_flash` arguments after reading the [esptool](https://github.com/themadinventor/esptool/) readme.\n\n```python\n\u003e\u003e\u003e import esp\n\u003e\u003e\u003e esp.check_fw()\nsize: 531032\nmd5: f54e36598b104f8c5dec883181080aaa\nTrue\n```\n\nTo exit screen run: `Control+A` then `Control+\\`.\n\n## Install scripts with WebREPL\n\nI was receiving `MemoryErrors` when trying to upload the scripts via REPL paste mode.\n\nUsing WebREPL `Send a file`, I'm able to upload the scripts successfully, but with WebREPL enabled, not enough ram to run them.\n\nReboot with WebREPL disabled and the scripts has enough resources to run.\n\n### Configure Access Point\n\nThe default settings will give your device the ip 192.168.4.1\n\n```python\n\u003e\u003e\u003e import network\n\u003e\u003e\u003e ap_if = network.WLAN(network.AP_IF)\n\u003e\u003e\u003e ap_if.active(True)\n```\n\nYep, it's 192.168.4.1. (ip,netmask,gateway,dns)\n\n```python\n\u003e\u003e\u003e ap_if.ifconfig()\n('192.168.4.1', '255.255.255.0', '192.168.4.1', '208.67.222.222')\n```\n\n### Start WebREPL\n\n```python\n\u003e\u003e\u003e import webrepl\n\u003e\u003e\u003e webrepl.start()\nWebREPL daemon started on ws://192.168.4.1:8266\nStarted webrepl in setup mode\n```\n\n### Connect to Access Point\n\nBefore leaving your working internet connection, open the WebREPL http://micropython.org/webrepl/ but don't connect yet.\n\nJoin the MicroPython-xxxxxx network. Password is `micropythoN`. Uppercase N is not a typo.\n\nYou should see something like this in the REPL:\n\n```python\n\u003e\u003e\u003e add 1\naid 1\nstation: 78:31:c1:bb:cc:dd join, AID = 1\n```\n\nSwitch back to WebREPL tab in your browser and click `Connect`.\n\nIt will ask you to set a password.\n\n```\nWelcome to MicroPython!\nWelcome to MicroPython WebREPL!\n\nThis is the first time you connect to WebREPL, so please set a password\nto use for the following WebREPL sessions. Once you enter the password\ntwice, your board will reboot with WebREPL running in active mode. On\nsome boards, you may need to press reset button or reconnect power.\n\nNew password:\n```\n\nEnter a password twice and it will save the password and reboot.\n\n```\nNew password: ********\nConfirm password: ********\nPassword successfully set, restarting...\nDisconnected\n```\n\nWebREPL will be disabled when it reboots, so you will need to start it again.\n\nLater, to make it always on, you can add the start command to boot.py. In this case, we do not want it started by default.\n\nSwitch back to your terminal and start WebREPL again\n\n```python\n\u003e\u003e\u003e import webrepl\n\u003e\u003e\u003e webrepl.start()\nWebREPL daemon started on ws://192.168.4.1:8266\nStarted webrepl in normal mode\n```\n\nNotice this time, it says `normal mode`. FYI - the WebREPL password you entered is saved in `port_config.py` in the root.\n\n```python\n\u003e\u003e\u003e import os\n\u003e\u003e\u003e os.listdir()\n['boot.py', 'port_config.py']\n```\n\nClick `Connect` and enter your password.\n\n```python\nWelcome to MicroPython!\nPassword:\nWebREPL connected\n\u003e\u003e\u003e\n```\n\n### Upload files with WebREPL\n\nUnder `Send a file` on the right, choose the file `pcd8544.py`. It will list the file as `pcd8544.py - 9787 bytes`.\n\nClick `Send to device`. At the bottom it should say `Sent pcd8544.py, 9787 bytes`.\n\nRepeat for the files `dht12.py`, `dht12_nokia.py`, `am2320.py` and `am2320_nokia.py`.\n\nClick `Disconnect`. Click your hardware Reset button, or use `machine.reset()`.\n\n```python\n\u003e\u003e\u003e import machine\n\u003e\u003e\u003e machine.reset()\n```\n\nAfter rebooting, if you do not need the Access Point anymore, you can disable it with:\n\n```python\n\u003e\u003e\u003e import network\n\u003e\u003e\u003e ap_if = network.WLAN(network.AP_IF)\n\u003e\u003e\u003e ap_if.active(False)\nstation: 78:31:c1:bb:cc:dd leave, AID = 1\nrm 1\nbcn 0\ndel if1\nusl\nmode : null\n```\n\n### Setup and test Nokia 5110 display\n\nConnections:\n\nWeMos D1 Mini (ESP8266) | Nokia 5110 PCD8544 LCD | Description\n----------------------- | ---------------------- | ----------------------------------------------\nD3 (GPIO0)              | 0 RST                  | Output from ESP to reset display\nD4 (GPIO2)              | 1 CE                   | Output from ESP to chip select/enable display\nD8 (GPIO15)             | 2 DC                   | Output from display data/command to ESP\nD7 (GPIO13)             | 3 Din                  | Output from ESP SPI MOSI to display data input\nD5 (GPIO14)             | 4 Clk                  | Output from ESP SPI clock\n3V3                     | 5 Vcc                  | 3.3V from ESP to display\nD6 (GPIO12)             | 6 BL                   | 3.3V to turn backlight on, or PWM\nG                       | 7 Gnd                  | Ground\n\nTest the display:\n\n```python\n\u003e\u003e\u003e from machine import Pin, SPI\n\u003e\u003e\u003e import time\n\u003e\u003e\u003e import pcd8544\n\n\u003e\u003e\u003e spi = SPI(1, baudrate=80000000, polarity=0, phase=0)\n\n\u003e\u003e\u003e cs = Pin(2)\n\u003e\u003e\u003e dc = Pin(15)\n\u003e\u003e\u003e rst = Pin(0)\n\n\u003e\u003e\u003e bl = Pin(12, Pin.OUT, value=1)\n\u003e\u003e\u003e lcd = pcd8544.PCD8544(spi, cs, dc, rst)\n```\n\nSwitch off the backlight:\n\n```python\n\u003e\u003e\u003e bl.value(0)\n```\n\nSwitch on the backlight:\n\n```python\n\u003e\u003e\u003e bl.value(1)\n```\n\nUse a framebuffer to store the 4032 pixels (84x48):\n\n```python\n\u003e\u003e\u003e import framebuf\n\u003e\u003e\u003e buffer = bytearray((lcd.height // 8) * lcd.width)\n\u003e\u003e\u003e framebuf = framebuf.FrameBuffer1(buffer, lcd.width, lcd.height)\n```\n\nLight every pixel:\n\n```python\n\u003e\u003e\u003e framebuf.fill(1)\n\u003e\u003e\u003e lcd.data(buffer)\n```\n\nClear screen:\n\n```python\n\u003e\u003e\u003e framebuf.fill(0)\n\u003e\u003e\u003e lcd.data(buffer)\n```\n\nPrint `Hello, World!` using the 8x8 font:\n\n```python\n\u003e\u003e\u003e framebuf.text(\"Hello,\", 0, 0, 1)\n\u003e\u003e\u003e framebuf.text(\"World!\", 0, 9, 1)\n\u003e\u003e\u003e lcd.data(buffer)\n```\n\nIf all this works, let's try the sensors.\n\n![Test](https://raw.github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110/master/photos/test.jpg)\n\n## Setup and test DHT12\n\n![DHT12](https://raw.github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110/master/photos/dht12.jpg)\n\nSensor pinout:\n\n* 1 VDD\n* 2 SDA\n* 3 GND\n* 4 SCL\n\nConnections:\n\nWeMos D1 Mini (ESP8266) | DHT12  | Description\n----------------------- | ------ | ------------\n3V3                     | 1 VDD  | 3.3V\nD2 (GPIO4)              | 2 SDA  | Serial data\nD1 (GPIO5)              | 3 SCL  | Serial clock\nG                       | 4 GND  | Ground\n\nConnect two pull-up resistors for I2C between 3V3-SDA and 3V3-SCL.\n\nTest the DHT12 sensor:\n\n```python\n\u003e\u003e\u003e from machine import I2C, Pin\n\u003e\u003e\u003e import dht12\n\n\u003e\u003e\u003e i2c = I2C(scl=Pin(5), sda=Pin(4), freq=20000)\n\u003e\u003e\u003e i2c.scan()\n```\n\nYou should see sensor at [92]\n\n```python\ndht = DHT12(i2c)\ndht.measure()\ndht.temperature()\ndht.humidity()\n```\n\nDisplay the temperature and humidity on the Nokia 5110 display, updated every 4 seconds:\n\n```python\n\u003e\u003e\u003e import dht12_nokia\n```\n\n## Setup and test AM2320\n\n![AM2320](https://raw.github.com/mcauser/MicroPython-ESP8266-DHT-Nokia-5110/master/photos/am2320.jpg)\n\nSensor pinout:\n\n* 1 VDD\n* 2 SDA\n* 3 GND\n* 4 SCL\n\nConnections:\n\nWeMos D1 Mini (ESP8266) | AM2320 | Description\n----------------------- | ------ | ------------\n3V3                     | 1 VDD  | 3.3V\nD2 (GPIO4)              | 2 SDA  | Serial data\nD1 (GPIO5)              | 3 SCL  | Serial clock\nG                       | 4 GND  | Ground\n\nConnect two pull-up resistors for I2C between 3V3-SDA and 3V3-SCL.\n\nTest the AM2320 sensor:\n\n```python\n\u003e\u003e\u003e from machine import I2C, Pin\n\u003e\u003e\u003e import am2320\n\n\u003e\u003e\u003e i2c = I2C(scl=Pin(5), sda=Pin(4), freq=20000)\n\u003e\u003e\u003e i2c.scan()\n```\n\nYou should see sensor at [92]\n\n```python\n\u003e\u003e\u003e dht = AM2320(i2c)\n\u003e\u003e\u003e dht.measure()\n\u003e\u003e\u003e dht.temperature()\n\u003e\u003e\u003e dht.humidity()\n```\n\nDisplay the temperature and humidity on the Nokia 5110 display, updated every 4 seconds:\n\n```python\n\u003e\u003e\u003e import am2320_nokia\n```\n\n## Links\n\n* [MicroPython PCD8544 Driver](https://github.com/mcauser/micropython-pcd8544)\n* [MicroPython DHT12 Driver](https://github.com/mcauser/micropython-dht12)\n* [MicroPython AM2320 Driver](https://github.com/mcauser/micropython-am2320)\n* [WeMos D1 Mini](http://www.wemos.cc/Products/d1_mini.html)\n* [micropython.org](http://micropython.org)\n* [Hardware SPI docs](http://docs.micropython.org/en/latest/esp8266/esp8266/quickref.html#hardware-spi-bus)\n* [micropython issue](https://github.com/micropython/micropython/issues/2290)\n* [hackaday project](https://hackaday.io/project/13363-dht12-am2320-nokia-5110)\n\n## License\n\nLicensed under the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-esp8266-dht-nokia-5110","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcauser%2Fmicropython-esp8266-dht-nokia-5110","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-esp8266-dht-nokia-5110/lists"}