Skip to content

Commit efdda2c

Browse files
committed
stm32: Add support for DHT11/DHT22 sensors.
1 parent a40ce1d commit efdda2c

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

drivers/dht/dht.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# DHT11/DHT22 driver for MicroPython on ESP8266
22
# MIT license; Copyright (c) 2016 Damien P. George
33

4-
import esp
4+
try:
5+
from esp import dht_readinto
6+
except:
7+
from pyb import dht_readinto
58

69
class DHTBase:
710
def __init__(self, pin):
@@ -10,7 +13,7 @@ def __init__(self, pin):
1013

1114
def measure(self):
1215
buf = self.buf
13-
esp.dht_readinto(self.pin, buf)
16+
dht_readinto(self.pin, buf)
1417
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
1518
raise Exception("checksum error")
1619

ports/stm32/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ EXTMOD_SRC_C = $(addprefix extmod/,\
186186

187187
DRIVERS_SRC_C = $(addprefix drivers/,\
188188
memory/spiflash.c \
189+
dht/dht.c \
189190
)
190191

191192
SRC_C = \

ports/stm32/modpyb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "lib/utils/pyexec.h"
3535
#include "lib/oofatfs/ff.h"
3636
#include "lib/oofatfs/diskio.h"
37+
#include "drivers/dht/dht.h"
3738
#include "gccollect.h"
3839
#include "stm32_it.h"
3940
#include "irq.h"
@@ -168,6 +169,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
168169
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) },
169170
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
170171

172+
// This function is not intended to be public and may be moved elsewhere
173+
{ MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) },
174+
171175
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&pyb_timer_type) },
172176

173177
#if MICROPY_HW_ENABLE_RNG

ports/stm32/modules/dht.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../drivers/dht/dht.py

0 commit comments

Comments
 (0)