As the title says... Chat on...

User avatar
By Robert1968
#58634 Hi,

AM2320 connected to ESP01
VCC to AM2320 1
GPIO2 to AM2320 2
GND to AM2320 3
GPIO0 to AM2320 4

Sample code on ESP:

Code: Select allam2320.init(4,3)
rh,t=am2320.read()
print(string.format("RH: %s%%", rh / 10))
print(string.format("Temperature: %s degrees C", t / 10))


But error message is only:

> dofile("a1.lua")
a1.lua:2: transmission error
stack traceback:
[C]: in function 'read'
a1.lua:2: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk
>


Modules are built in
Code: Select allNodeMCU custom build by frightanic.com
   branch: master
   commit: 7b83bbb2ea134cd85ac9d63108603cc02c4e20f7
   SSL: false
   modules: am2320,dht,file,gpio,i2c,net,node,tmr,uart,wifi


Any suggestion?
User avatar
By Thomas Jakober
#59762 This version works on my ESP-01:

Code: Select allmodel, version, serial = am2320.init(3, 4)
print(string.format("AM2320: MODEL %s, VERSION %s, SN %s.",model,version,serial))
tmr.alarm(1, 2000, tmr.ALARM_SINGLE, function()
    tmr.alarm(1, 2000, tmr.ALARM_AUTO, function()

        rh, t = am2320.read()
        print(string.format("RH: %s%%", rh / 10))
        print(string.format("Temperature: %s degrees C", t / 10))
    end);
end);


Unfortunately I could not find out why the example out of the documentation does not work.
User avatar
By marcelstoer
#59775
Thomas Jakober wrote:Unfortunately I could not find out why the example out of the documentation does not work.


Are you suggesting the sample in the docs is wrong? The only real difference with your code is that you wait 2x2s after init() before reading from the sensor. Is this essential?
User avatar
By marcelstoer
#59776
Robert1968 wrote:
Code: Select allam2320.init(4,3)
rh,t=am2320.read()
print(string.format("RH: %s%%", rh / 10))
print(string.format("Temperature: %s degrees C", t / 10))


But error message is only:

> dofile("a1.lua")
a1.lua:2: transmission error
stack traceback:
[C]: in function 'read'
a1.lua:2: in main chunk
[C]: in function 'dofile'
stdin:1: in main chunk
>


The error message doesn't relate to the code you showed. There must be more to it. Can you create a MCV example in init.lua?