Python GPIOs module for A20-OLinuXino-MICRO

Image

pyA20 GPIO module is uploaded yesterday to Pypi https://pypi.python.org/pypi/pyA20/0.1.0

The use is same as the Python modules for imx233, A10S, A13 OLinuXino:

#!/usr/bin/env python
import A20_GPIO as GPIO
#init module
GPIO.init()
#configure module
GPIO.setcfg(GPIO.PIN#, GPIO.OUTPUT)
GPIO.setcfg(GPIO.PIN#, GPIO.INPUT)
#read the current GPIO configuration
config = GPIO.getcfg(GPIO.PIN#)
#set GPIO high
GPIO.output(GPIO.PIN#, GPIO.HIGH)
#set GPIO low
GPIO.output(GPIO.PIN#, GPIO.LOW)
#read input
state = GPIO.input(GPIO.PIN#)
#cleanup
GPIO.cleanup()

this is initial release so if you find some bugs please report back to us 🙂

A10S-OLinuXino ANDROID GPIO control LED toggle app

Image

We got lot of requests on our forum how to control GPIOs from Android.

With the new A10S Android image we decided to play a bit and it appear to be not hard to implement.

We found two ways to do GPIO control running Android.

GPIO using ADB

1. Boot android (from nand or sdcard)

2. Connect USB-to-Serial cable on UART1

3. Open terminal at speed 115200

4. When loading is ready in the terminal type “sh” and enter

5. “ls /sys/class/gpio_sw” will give you a list of all accessable GPIOs.

The GPIOs name is according to the chip ports. For example PE3 is LED1.

6. To set PE3 as output:

#echo 1 > /sys/class/gpio_sw/PE3/mul_sel

or as input

#echo 0 > /sys/class/gpio_sw/PE3/mul_sel

7. To turn on LED:

#echo 1 > /sys/class/gpio_sw/PE3/data

and to turn off:

#echo 0 > /sys/class/gpio_sw/PE3/data

8. If GPIO is as input to read state:

#cat /sys/class/gpio_sw/PE3/data

GPIO using Android SDK

Basicly you should read and write to the filesys. Make sure that your app is running as root, or else nothing will happen.

The demo program toggle LED1 on every button press.  The sources are at GitHub: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A10S/A10S-ANDROID-GPIO

All read/write methods are realized in GPIO.java file.

The application is with single button and each time you press it it toggles the green LED on the board.

TOGGLE

You can see ToggleLED.apk running at this video: http://www.youtube.com/watch?v=8kTUkJx2TgQ

A10S-OLinuXino-MICRO Python GPIO module

Image

pyA10S GPIO ports module is available at: https://pypi.python.org/pypi/pyA10S/0.1.2

iMX233-OLinuXino GPIO Python Libraries

Image

Soon after we released A13-GPIO for Python https://olimex.wordpress.com/2013/03/08/a13-olinuxino-gpio-python-libraries/ we got requests to do same for iMX233.

iMX233_GPIO is released on PyPi now https://pypi.python.org/pypi/iMX233_GPIO/0.1.0
it works identical to pyA13 you can use same commands:

import iMX233_GPIO as GPIO
#init module
GPIO.init()
#configure module
GPIO.setinput(GPIO.PIN#)
GPIO.setoutput(GPIO.PIN#)
#set GPIO high
GPIO.output(GPIO.PIN#, 1)
#set GPIO low
GPIO.output(GPIO.PIN#, 0)
#read input
state = GPIO.input(GPIO.PIN#)

due to the GPIO multiplexing we add only these GPIOs in the base package:

PIN9, PIN10, PIN11, PIN12, PIN13, PIN14, PIN15, PIN16, PIN17, PIN18, PIN23, PIN24, PIN25, PIN26, PIN27, PIN28, PIN29, PIN31

you can use this as template, and if you for instance disable LCD in your linux image you can have access to all LCD pins too.

After you download the package from PyPi do as follows to install it:

#tar -zxvf iMX233_GPIO-0.1.0.tar.gz
#cd iMX233_GPIO-0.1.0.tar.gz
#sudo python setup.py install

after the installation you can use it this way:

#sudo python
>>> import iMX233_GPIO as GPIO
>>> GPIO.init() #init GPIOs
>>> GPIO.getcfg(GPIO.PIN31) #config PIN31 as GPIO
>>> GPIO.setcfg(GPIO.PIN31, GPIO.OUTPUT) #config PIN31 as output
>>> GPIO.output(GPIO.PIN31, GPIO.HIGH) #set PIN31 high
>>> GPIO.output(GPIO.PIN31, GPIO.LOW) #set PIN31 low
>>> GPIO.setcfg(GPIO.PIN31, GPIO.INPUT) #config PIN31 as input
>>> GPIO.input(GPIO.PIN31) #read PIN31

PINxx assignments is exactly as per imx233-OLinuXino-MAXI schematic

Maximum iMX233 GPIO toggle speed via Python is 15,6 kHz, which is kind of dissapointing, as /dev/mem C approach achieve about 5.7 6 Mhz, but Python is running slow on imx233 so this probably cause the slow GPIOs access.

On A13 is opposite /dev/mem is running slower at 1Mhz but pyA13 GPIO achieve up to 100 kHz as Python is running faster on A13.

Scratch + A13-OLinuXino-WIFI Physical Computing

Image

Scratch is great visual environment very easy to understand by children.

I already blogged that Scratch is running fine on OLinuXino here https://olimex.wordpress.com/2013/03/12/a13-olinuxino-wifi-running-scratch-ide-perfect-platform-for-kids-programming-education/

What bothered us though was that we can’t use all GPIOs and hardware resource which OLinuXino offers and Scratch basic installation can only play music and make cool animations.

So we start searching info how to implement this.

Soon we found SNAP http://snap.berkeley.edu/ which is based BYOB (Build your own Blocks) which is based on Scratch but adds ability to make your own blocks, recursion etc new features.

SNAP is implemented with JavaScript so even better it runs on your Browser without need of installation. Based on SNAP there are few cool projects made by Technoboy10 (https://github.com/Technoboy10) interfacing Wii Nunchuk , Arduino and NXT-Lego robots.

I asked Technoboy10 is there documentation how to connect Hardware to SNAP and soon he published this info in the Wiki: https://github.com/Technoboy10/snap-server/wiki/How-to-create-a-Snap!-Extension which is very detailed.

So How cool is this? Kids are able to program robots with visual IDE!

Looking at Technoboy10 GitHub repository we figured out how to do this, but SNAP basic installation have no such great choice of sprites and animation examples, so I decided for the beginning to try to implement OLinuXino hardware features to SCratch.

So I posted question on Scratch forum and start to wait for reply http://scratch.mit.edu/forums/viewtopic.php?id=115821 . After few days waiting, 30+ views and none reply I did what I had to do at the beginning: searched github for “scratch c” then for “scratch python” and found what we needed:
https://github.com/pilliq/scratchpy.

This is cool python client for Scratch. When you enable remote sensors in Scratch it creates server, then with scratchpy you can pool for given variables and take their values or change them, this way you can connect sensors or actuators.

As opposite to SNAP (where SNAP i client and snap-server is made with pyton, so SNAP connects to the server) here Scratch makes server and the scratchpy client connects to it and interact through variables.

So here is our first “Hello World” blinking LED with Scratch: http://www.youtube.com/watch?v=qbTNWTa5tXQ

Instruction how to install the OLinuXino GPIO interface to Scratch is on GitHub: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A13/A13-GPIO%2BSCRATCH

Our second project animate GPIO connector with Scratch based on real buttons inputs and LED outputs:

Image

Here is video on the GPIO interaction with SCRATCH http://www.youtube.com/watch?v=DzmvqlQodac

Now when we have this powerful tool: scratchpy to interface Scratch to anything via python, just imagine what would happend if we connect Scratch to … OpenCV 🙂

From my previous blog I show you some videos which demonstrate the power of OpenCV: face recognition, face expression recognition, color objects tracking.  You can make SCRATCH script for instance which recognize the face of the person in the fron of the web cam and run some animation to welcome it by name.

Or you can program your robot to chase this yellow pong ball which is in the front of it.

Or you can make different animations depend on the face expression of the person in the front of the camera… the applications and the fun will be endless!

A13-OLinuXino GPIO Python libraries

Image

Python is one of the most popular languages in the last years, it’s used by Google for their search engine and many other apps like game designs, databases etc.

Python combines the easy of use of the interpretive languages with powerful datastructures, so it replaces the old days BASIC but opens up lot of new possibilities.

If you want to learn more about Python you can read http://www.learnstreet.com/lessons/study/python or the official Python language web site http://python.org/

The best of all are the Python libraries you can see thousands of these at https://pypi.python.org/pypi

A13-OLinuXino as any Linux platform can run Python language, what we were missing was GPIO library which to allow Python users to have access to A13-OLinuXino GPIOs.

Now this library is done! You can download is from https://pypi.python.org/pypi/pyA13/ or from GitHub: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/A13/PYTHON-A13-GPIO

then install it:

#tar -zxvf pyA13-0.1.7.tar.gz
#cd pyA13-0.1.7.tar.gz
#sudo python setup.py install

after the installation you can use it this way:

#sudo python

>>> import A13_GPIO as GPIO
>>> GPIO.init()                           #init GPIOs
>>> GPIO.getcfg(GPIO.PIN37)               #config PIN37 as GPIO
>>> GPIO.setcfg(GPIO.PIN37, GPIO.OUTPUT)  #config PIN37 as output
>>> GPIO.output(GPIO.PIN37, GPIO.HIGH)    #set PIN37 high
>>> GPIO.output(GPIO.PIN37, GPIO.LOW)     #set PIN37 low
>>> GPIO.setcfg(GPIO.PIN37, GPIO.INPUT)   #config PIN37 as input
>>> GPIO.input(GPIO.PIN37)                #read PIN37

PINxx assignments is exactly as per A13-OLinuXino schematic

EDIT: Maximum GPIO toggle speed via Python is 101 kHz

Friday Free Board Quiz issue #25 is RPI-UEXT + MOD-IO2

Image

Image

RPI-UEXT allow Raspberry Pi to have access to different modules see original blog post we made about it: https://olimex.wordpress.com/2012/11/21/raspberry-pi-gpio-to-breadboard-and-uext-adapter/

MOD-IO2 allow RaspberryPi to control 2 relays and to read/write 7 additional GPIOs, including Analog inputs. On top of this MOD-IO2 is stackable and addressable so you can stack and connect to Raspberry Pi as many relays as you need for your project.

You have chance to win RPI-UEXT + CABLE26-pin + MOD-IO2 today if you answer correctly our quiz question!

Today at 17.00 o’clock our local Bulgarian time (GMT+2) we will post on Twitter our questions.

You have one hour to reply to our tweet with the correct answer.

At 18.00 o’clock we will count the correct answers and ask random.org to generate random number in range then announce the winner and ship the board by airmail in Monday.

Good Luck!

Previous Older Entries Next Newer Entries