Left here for archival purposes.

User avatar
By scoace
#4312 Hi

after setting gpio.mode(9,gpio.OUTPUT) and gpio.write(9,gpio.HIGH). A gpio.read(9) sets the gpio output to 0. Can anyone configm this:

> gpio.mode(9,gpio.OUTPUT)
> gpio.write(9,gpio.HIGH)
> print (gpio.read(9))
0

regards
User avatar
By zeroday
#4323
scoace wrote:Hi

after setting gpio.mode(9,gpio.OUTPUT) and gpio.write(9,gpio.HIGH). A gpio.read(9) sets the gpio output to 0. Can anyone configm this:

> gpio.mode(9,gpio.OUTPUT)
> gpio.write(9,gpio.HIGH)
> print (gpio.read(9))
0

regards


gpio.read() api put the pin into input mode.

gpio.mode() api now has a third para pullup, to set internal pullup of the pin.
gpio.mode(9,gpio.OUTPUT, 1 ) will enable internal pullup r.
default: pullup disabled( float)
User avatar
By scoace
#4401
zeroday wrote:
scoace wrote:Hi

after setting gpio.mode(9,gpio.OUTPUT) and gpio.write(9,gpio.HIGH). A gpio.read(9) sets the gpio output to 0. Can anyone configm this:

> gpio.mode(9,gpio.OUTPUT)
> gpio.write(9,gpio.HIGH)
> print (gpio.read(9))
0

regards


gpio.read() api put the pin into input mode.

gpio.mode() api now has a third para pullup, to set internal pullup of the pin.
gpio.mode(9,gpio.OUTPUT, 1 ) will enable internal pullup r.
default: pullup disabled( float)


Thanks for the quick answer, but that means I have to keep track of the pinstate by myself.

Regards
User avatar
By jtore
#4512 I have the same problem. A gpio.read() does pull down in hardware, but returns the right value in software (high/low).
And the gpio.mode(pin,gpio.OUTPUT,1) does nothing to fix that problem.

Will have to use a variable to save the state until gpio.read() is fixed..

This example script found on this site will crash the mcu when performing gpio.read().

Code: Select alls=net.createServer(net.TCP)
 s:listen(80,function(c)
 c:on("receive",function(c,pl)
  for v,i in pairs {8,9} do
   gpio.mode(i,gpio.OUTPUT,1)
   c:send("\ngpio("..i.."):"..gpio.read(i))
   if string.find(pl,"gpio"..i.."=0") then gpio.write(i,0) end
   if string.find(pl,"gpio"..i.."=1") then gpio.write(i,1) end
   c:send("\nnew_gpio("..i.."):"..gpio.read(i))
  end
  c:send("\nTMR:"..tmr.now().." MEM:"..node.heap().."\n")
 c:on("sent",function(c) c:close() end)
 end)
end)


To have this code run I must comment out the lines involving read.

Code: Select all>>  c:on("sent",function(c) c:close() end)
>>  end)
>> end)
> H????19@H?DHJ??@H?
NodeMcu 0.9.2 build 20141209  powered by Lua 5.1.4
lua: cannot open init.lua
>

Output from sending curl "10.0.xx.xx/gpio8=1" to module.