Author Topic: Python and GPIO on Cubietruck  (Read 7914 times)

Offline Vyachez

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Python and GPIO on Cubietruck
« on: May 31, 2014, 03:57:05 am »
Hello, everyone!

I spent much time researching this issue but seems that it fits only for Cubbieboard2.
I am trying to make WiringCB-python working for Cubietruck/Cubieboard3.

The purpose of that is programming for GPIO using python language. So I need addressing GPIO with Python (not! shell or C).
The gobal goal of my project is to create intelligent robot able to recognize faces and voice and perform relevant dependant commands.

Here we have repository: https://github.com/gootoomoon/WiringCB-python
I dug it all aroung but did not find the way how to rebuilt it for Cubietruck.

What I've done to make GPIO working on Cubietruck from startup:

Added GPIO ports to script.bin
http://docs.cubieboard.org/tutorials/common/gpio_on_lubuntu

WARNING: do not change default pin PH20 PH10: http://www.cubieforums.com/index.php?topic=1537.msg9703#msg9703

-created group gpio
-added user to group
Code: [Select]
sudo groupadd gpio
sudo usermod -aG gpio <username>

Then modified (added lines of code without exit 0) rc.local file by setting up /sys/class/gpio group to gpio recursively and permissions to 775 on gpio recursively; exported pin 3 gpio folder; and changed permissions to 775 on gpio3_pi14 (I used GPIO pin no PI14: http://docs.cubieboard.org/a20-cubietruck_gpio_pin):

Code: [Select]
chgrp gpio -HR /sys/class/gpio
chmod -R 775 /sys/class/gpio
echo 3 > /sys/class/gpio/export
chgrp gpio -HR /sys/class/gpio/gpio3_pi14
chmod -R 775 /sys/class/gpio/gpio3_pi14

Tested GPIO pi14 with led running following sh. script right after reboot:
 
Code: [Select]
cd /sys/class/gpio/gpio3_pi_14
echo out > direction
echo 1 > value
sleep 1
echo 0 > value
sleep 1
echo 1 > value
sleep 1
echo 0 > value
sleep 1

led blinked.

But when I am running the code on Python, nothing happens (after all repositories and python installation obviously):

Code: [Select]
import wiringpi2
OUTPUT = 1
pin = 3
HIGH = 1
LOW = 0

wiringpi2.wiringPiSetupPhys()
wiringpi2.pinMode(pin,OUTPUT)

while 1:
    wiringpi2.digitalWrite(pin,HIGH)
    wiringpi2.delay(1000)
    wiringpi2.digitalWrite(pin,LOW) 
    wiringpi2.delay(1000)

I've reinstalled python and used 2.7.x and/or 3.x.x. It does not change the matter.
Everythin was done under instructions https://github.com/gootoomoon/WiringCB-python but no luck.

Maybe someone have any ideas how to use Python to work with Cubietruck GPIO?
Or maybe smeone have any ideas how to interact with GPIO for my global purpose. I guess I need to connect openCV libraries for that purpose. I am frustrated what right way to go.

EduardoIbarra

  • Guest
Re: Python and GPIO on Cubietruck
« Reply #1 on: June 02, 2014, 09:01:19 am »
I highly recommend you open-cv since it would be very hard to build your own library. Also, you may want to add a microphone attached to the LINEIN-L and LINEIN-R (24 and 26) GPIOs. But if you want to get your microphone to work, you'll have to build a pre-amplifier.

Offline Vyachez

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Python and GPIO on Cubietruck
« Reply #2 on: June 02, 2014, 02:03:57 pm »
Thank you, Eduardo!
You helped me much to get solution with GPIO and giving this advice. I will definitely use mic. But it will be a bit later. After playing around GPIO in/out I will go to PWM to operate 4 wheels smoothly. Then I will connect webcam and learn CT to recognize subjects with openCV. Adding unltrasonic or infared sensors I will make it scan premises and find path.

Thus second step is PWM and Video capturing/processing. BTW for video I found some interresting materials here: http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/