Results 1 to 5 of 5

Thread: read GPIO output

  1. #1

    Unhappy read GPIO output

    Hello

    I just noticed that the fact of reading a GPIO output, made it go to 0 is this a bug where I did not understand something?
    * "Print (raspi read (24))" always gives as output regardless of the state of output 0.
    So scripting does not work.

    local raspi = require("raspi")
    raspi.export( 18 )
    raspi.direction( 18, true )
    raspi.read( 18 )

    local pin = raspi.read( 18 )
    if pin == 1 then
    raspi.write( 18, 0 )
    else
    raspi.write( 18, 1 )
    end


    Then i have help please?

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    Probably trying to read from a GPIO pin that is set to output doesn't produce what you expected. What are you trying to do?
    Ron
    No support through PM

  3. #3

    Default

    Hello Ron
    *
    I am learning lua and I want to change the state of output gpio 18.
    If gpio18 is set to 0 make it pass 1 and if to 1 pass to 0.
    Thank you for your reply.

    cordially

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    I see you wish to toggle the output. OK the problem you had is that calling export on a pin resets it's values. So only call export once per Girder session. Like so:

    Code:
    raspi = require("raspi") 
    
     if not raspi.pin18exported then
         raspi.export( 18 )
         raspi.direction( 18, true )
         raspi.pin18exported = true
     end
     
    
     local pin = raspi.read( 18 )
     print("Before Toggle", pin)
     
    
     if pin == 1 then
     raspi.write( 18, 0 )
     else
     raspi.write( 18, 1 )
     end
     
    
     print("After Toggle", raspi.read(18))
    Ron
    No support through PM

  5. #5

    Default

    Thank you Ron

    I will try as soon as possible.
    I still learn something about lua and girder.

    best regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •