Post your best Lua script examples here

User avatar
By cdrwolfe
#6157 I'm beginning to wonder if this is possible at all using lua.

For the life of me I can't get the chip to correctly control the gpio pins. With the DHT22 connected it is always set as high, calling gpio.write(pin, gpio.LOW) does nothing :(.

If anyone else has any luck feel free to post it :D.

Regards

Cdr
User avatar
By sancho
#6163
cdrwolfe wrote:I'm beginning to wonder if this is possible at all using lua.

For the life of me I can't get the chip to correctly control the gpio pins. With the DHT22 connected it is always set as high, calling gpio.write(pin, gpio.LOW) does nothing :(.

If anyone else has any luck feel free to post it :D.

Regards

Cdr

Which version of ESP do you have? The very first ESP-01 did not have GPIO pins connected to the output pins of the board - therefore doing anything with the code would result in absolutely nothing.
And, also, please check the version of nodeMCU - the mapping of pins to GPIO changed twice and therefore output something to pin 8 might no longer work as it is now different I/O pin...
I would suggest to get the latest nodeMCU firmware, set the GPIO2 (pin 4) to low and high and connect, let's say, LED with 330 ohm resistor to check the functionality.
User avatar
By Pigs Fly
#6164 When I take this from your code and put it on a ESP-07/12 module:

Code: Select allpin  = 4;
-- Initiliase bit data array
bitData = {}
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
tmr.delay(20000)
gpio.write(pin, 1)
gpio.mode(pin, gpio.INPUT)


I get this from a DHT11:

screenshot.35.png

Zoom of reply section:
screenshot.37.png


In the case of both DHT11/22 I see varying advice on the start pulse length. I went with 18ms+ based on some random data sheet. I have it on Pin 4 (GPIO2) with a 4.7k pullup. You have numerous cases of humidity spelling errors, so variables are not working correctly. Even after fixing that I can't get the checksum to work. At the beginning of your code during the start pulse, the Print functions were preventing the lines from changing levels. When removed I saw the proper pulsing of GPIO2. Can't explain that, just is my observation.

Edit: I want to point out that you have a good start with your code. I will continue messing with it as well as I'd like to see my DHT11's working.