We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Simple Python wrapper and demo



  • @Dan-L thanks this is great! Any chance you could show an example on how to turn on / off a led using the Arduino Dock?



  • @Romans-Bermans Hmm, not sure! I don't have that dock so I'm not sure how you go about interacting with it sorry.

    Perhaps @Lazar-Demin or @Boken-Lin have some ideas?



  • Boom! Works perfectly!

    Just for newbies like me (@Dan-L correct me if I am wrong but this is working for me):

    Make sure to nano and save pyhelper.py in this directory: /usr/lib/python2.7/importlib
    and
    change <from gpiohelper import GPIOHelper> to <from pyhelper import GPIOHelper>

    FYI, I named your files the same as the first line with the hash

    Thanks again, Dan!



  • @Nick-Bonifacio Ah, oops I meant for that to be "gpiohelper.py" rather than "pyhelper.py"! Have updated my original post.

    I'm not really a Python coder myself so no idea if putting stuff in /usr/bin/python2.7/importlib is best practice or not. But if it works it works! šŸ˜„šŸŗ



  • @Dan-L I don't think it is best practice haha. Hopefully, someone will chime in and tell us where it goes. What did you end up doing with it?



  • I just had both files as:

    /root/test/gpiohelper.py
    /root/test/gpiotest.py

    Written directly with Nano šŸ‘



  • @Dan-L. : thanks for sharing. šŸ‘
    how have you connected the LEDs? do you use any pull-up resistors or do you go directly from IO-pin to GND?
    thanks!!



  • Thanks @Dan-L Will give the Arduino Dock a go tonight and maybe will manage to figure it out.

    @gosch I have attached a photo of how I connected one LED (led pin 13) with one button (button pin 26) and used @Dan-L code to get it to work.FullSizeRender.jpg



  • Hi @gosch, I started off with this.

    Basically connecting a GPIO pin to a 330ohm resister, then the resister to the LED (longer leg), then the LED to ground. For my example code though, I was using 6 LEDs with 6 resisters, with the ground pin of each chained together and linked to a single ground pin on my expansion dock.

    I also set up a button using an Arduino guide I found here.

    šŸ˜Ž



  • Nice one @Romans-Bermans!



  • @Romans-Bermans: thanks for the picture!
    @Dan L.: thanks for the info & links!



  • Hey @Dan-L , finally got some components to play around with!

    Although I'm getting the following error when trying to read the input of a button using your helper, fast-gpio read 8 works perfectly though, any ideas?

    Traceback (most recent call last):
      File "script", line 19, in <module>
        button_input = helper.getPin(8)
      File "/root/first_script/gpiohelper.py", line 26, in getPin
        fd = open(self.pinDirectionPath.replace("$", str(pin)), 'w')
    IOError: [Errno 13] Permission denied: '/sys/class/gpio/gpio8/direction'


  • @Jamie-Street Know what? I have the same problem with pin 8. If you try a different pin does it work?

    I also have trouble with pin 13, but it doesn't actually give errors, it just doesn't do anything.



  • BTW You can test easily with the command line too.

    echo out > /sys/class/gpio/gpio5/direction
    echo 1 > /sys/class/gpio/gpio5/value

    echo in > /sys/class/gpio/gpio6/direction
    cat /sys/class/gpio/gpio6/value



  • Cheers for the heads up, upon inspection it looks like the direction file is missing for pin 8, pretty strange.. perhaps the helper should create the file if it doesn't already exist?



  • @Jamie-Street The helper doesn't specifically create those files individually, it triggers the export functionality. I'd say it's a bug with the Omega firmware...


  • administrators

    @Dan-L @Romans-Bermans we're still working on the drivers for the Arduino Dock, its a little more complicated than we anticipated. Should be out soon tho!

    As for pin 8, I'll be looking into that, we might have made it output only for some reason. I'll double check.



  • Thanks for the clear example.

    Is there a reason I can't access pins 15-17 (extension board RGB led)?
    I can update the values using (b)ash fast-gpio commands

    root@Omega1:~# ls /sys/class/gpio/
    export gpio1 gpio13 gpio18 gpio23 gpio6 gpio8 unexport gpio0 gpio12 gpio14 gpio19 gpio26 gpio7 gpiochip0



  • @Dan-L. Thank you for sharing that implementation.

    I used your implementation, then added support for pin 8 ( via fast-gpio ). I also set it up so it could run on my mac in a simulated way.

    Here is a link to a video showing it all work.

    https://www.youtube.com/watch?v=jDDq9D50wGo

    Thanks gain



  • @Romans-Bermans So for the pushbutton, how is that wired? It's hard to tell from the photo. It looks like the green leg is connected to 2V and the black leg is connected to RST? Please confirm. Thanks!


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.