DHT11/22 Lib on STM32
Jackson009 Sun Aug 30, 2015 2:28 pm
I try to us it in STM32 but seems compile passed but not working.
i did move my work to use in Arduino UNO. Then.. code size more than 32kB.
Thanks.
Jackson009 Sun Aug 30, 2015 2:28 pm
RogerClark Sun Aug 30, 2015 9:22 pm
From what I recall, that device has a custom communications protocol, and i suspect as you are running on a 108MHz GD32, that speed may be the problem, i.e you are going too fast.
PS. If you are using the GD32, I presume you read the other thread..
I have mine running ok at 120Mhz
Jackson009 Mon Aug 31, 2015 4:21 am
https://github.com/adafruit/DHT-sensor- … tester.ino
Well, i love speed in GD32 but i am not good in Coding. So, i am working in STM32F103C8T6(RED board).
Thanks,
RogerClark Mon Aug 31, 2015 4:42 am
It uses a function that is not in the STM32 or GD32 core
called
microsecondsToClockCycles
I looked in the Due (SAM) core and it has these defines
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
nulldragon Fri Sep 18, 2015 1:20 pm
Please find the library attatched https://github.com/nullydragon/Adafruit_DHT.
Note.
Line 16 of DHT.cpp has maxcycles hard coded at 72000L which works for my maple mini (at 72mhz that should be somewhere in the field of 1-5ms
Line 15 is commented out as there is a type issue (its also redundant with the following change)
Line 240 portInputRegister is passed the output from digitalPinToPort(pin) instead of having it set at the pervious line.
Let me know how it goes.
Jackson009 Sat Sep 26, 2015 2:26 pm
RogerClark Sat Sep 26, 2015 2:56 pm
It may be better to use F_CPU/1000 instead of 72000 as processor clock on some boards is faster e.g GD32 is 120Mhz and on F4 the clock frequency can be up to 180Mhz I think
martinayotte Sat Sep 26, 2015 3:07 pm
RogerClark Sat Sep 26, 2015 3:12 pm
I thought there was a 180Mhz variant. I only have the 168Mhz F4 Discovery board, but I thought there was a faster one.
Anyway, the main reason for using F_CPU is that the GD32F1 runs at 96Mhz in stable operation, or 120Mhz in overclocked (without any issues) but also some people want to run the STM32F103 at 48Mhz to save power.
I personally dont like hard coded arbitrary values, especially ones that are a derivative of the clock freq.
I recently did a load of tidying up of the STM32F103 after I’d done work on the GD32 core, to try to remove some of the same sort of hard coded values.
There may still be a few references to 72000000 or 72 or 72000 but I think I have replaced most of them with F_CPU derivatives ![]()
nulldragon Mon Oct 12, 2015 6:56 am
bookerh Thu May 12, 2016 1:54 pm
—————————————————————————————————————————————————-
C:\Users\booker\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib –param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10605 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/stm32f1/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/stm32f1 -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/usb_lib -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\cores\maple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\variants\generic_stm32f103c -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master r:\TEMP\build3874439298577829562.tmp\DHTtester.cpp -o r:\TEMP\build3874439298577829562.tmp\DHTtester.cpp.o
C:\Users\booker\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib –param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10605 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/stm32f1/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/stm32f1 -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/usb_lib -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\cores\maple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\variants\generic_stm32f103c -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\utility C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp -o r:\TEMP\build3874439298577829562.tmp\DHT sensor library\DHT.cpp.o
C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp: In constructor ‘DHT::DHT(uint8_t, uint8_t, uint8_t)’:
C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp:18:46: error: ‘microsecondsToClockCycles’ was not declared in this scope
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
^
Error compiling.
———————————
I don’t know why ? I find the library attatched https://github.com/nullydragon/Adafruit_DHT.
zoomx Thu May 12, 2016 2:10 pm
RogerClark Thu May 12, 2016 7:34 pm
However, I dont know if the library would work even if that function was added, because I am not entirely sure how the code is going to be able to count processor cycles.
LOL.
as far as I can tell, that function is only used for debugging
try just commenting out that line.
RogerClark Thu May 12, 2016 8:21 pm
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (F_CPU / 1000000L) )
zmemw16 Sun May 15, 2016 4:42 pm
this is header of the DHT.cpp
/******************************************************************
DHT Temperature & Humidity Sensor library for Arduino.
Features:
- Support for DHT11 and DHT22/AM2302/RHT03
- Auto detect sensor model
- Very low memory footprint
- Very small code
http://www.github.com/markruys/arduino-DHT
Written by Mark Ruys, [email protected].
BSD license, check license.txt for more information.
All text above must be included in any redistribution.
Datasheets:
- http://www.micro4you.com/files/sensor/DHT11.pdf
- http://www.adafruit.com/datasheets/DHT22.pdf
- http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
- http://meteobox.tk/files/AM2302.pdf
Changelog:
2013-06-10: Initial version
2013-06-12: Refactored code
2013-07-01: Add a resetTimer method
******************************************************************/
ozolive Thu Oct 20, 2016 6:37 am
For my DHT22, this lib from Mark Ruys at http://www.github.com/markruys/arduino-DHT was giving only temperature, but humidity was far off.
I like this lib as as advertised, it is very small, and i would add very reliable IME.
The issue was in the different size of “word” type between avr and arm. Changing it to explicit type “uint16_t” solved the issue.
I contacted the author who updated his repo. So current version works out of the box, thanks all !
RogerClark Thu Oct 20, 2016 7:08 am
And_Ru Thu Nov 10, 2016 1:24 pm
And_Ru Thu Nov 10, 2016 6:13 pm
stevestrong Thu Nov 10, 2016 6:59 pm
danieleff Thu Nov 10, 2016 7:07 pm