FitPC, GPIO and Python

Post Reply
Posts: 5
Joined: Thu Oct 29, 2015 10:21 am

FitPC, GPIO and Python

Post by DaveLangstaff »

Having spent a little while getting Python to talk to the GPIO on a Fitlet, I thought I'd share.

The first thing is to make sure the kernel is up to date. I downloaded and installed fitlet_kernel_3.19_2015-12-16 following the instructions on this site.

A user needs superuser privileges in order to talk to the hardware, so you need to launch the development environment as a super user, so I started with the desktop, brought up a terminal prompt and type "sudo spyder" to get editing.

The following code turns on and off an LED connected between pin gpio89 and ground via a 300 ohm resistor. All interaction with the gpio driver is done by writing (and reading) files as shown in the example. Unfortunately the forum seems to strip indentation before display, so the for loop in the example will need fixing before you try and run the code.

I'd be interested to know how other people get on and if anyone has success in getting interrupts etc working from within Python.


# -*- coding: utf-8 -*-
@author: Dave Langstaff
Turn LED on gpio89 on and off
import time # needed for time.sleep to time loop
import os # needed for permissions fudge on files

# first set up gpio pin 89

# fudge to get write permission
# This fudge could/should be fixed in a future driver release
os.system('chmod a+rw /sys/class/gpio/gpio89/*')

# define pin 89 as output

# open file to write values to pin

# turn LED on
f.write('1') # note it is the character 1 we are writing
f.flush() # need to use flush() or close() after each write

# now loop around to flash off and on
for i in range(10):
f.write('0'); f.flush() # LED off.
f.write('1'); f.flush() # LED on
# end of loop

# turn LED off at end

# close file

# release gpio line

# Enjoy!!


Re: FitPC, GPIO and Python

Post by mbirger »

Thanks for sharing. Your example is shared on fitlet FAQ page: ... der_Python

Post Reply

Return to “General fitlet questions”