Homepage Wiki Forum Buy

Python

From GNUBLIN

Contents

Python Skripts

hello.py

#!/usr/bin/python
# Hello world python program

print "Hello World!";


Run:

python hello.py

application examples

LED BLINK

The following script flashes the LED on GPIO3.

 #!/usr/bin/python
 import sys, time, os

 GPIO = "3"
 gpio_unexport = open('/sys/class/gpio/unexport','w')
 gpio_unexport.write(GPIO)
 gpio_unexport.close() 

 gpio_export = open('/sys/class/gpio/export','w')
 gpio_export.write(GPIO)
 gpio_export.close()


 tmp = "/sys/class/gpio/gpio" + GPIO + "/direction"
 gpio_direction = open('tmp','w')
 gpio_direction.write("out")
 gpio_direction.close()

 
 tmp1 = "echo 1 > " + "/sys/class/gpio/gpio" + GPIO + "/value"
 tmp0 = "echo 0 > " + "/sys/class/gpio/gpio" + GPIO + "/value"
 while 1:
    os.system(tmp1)
    time.sleep(1)
    os.system(tmp0)
    time.sleep(1)

 

PWM

PWM Example

In other languages