It contains just simple and quickly examples written in Python using the ablib module available on github.
An in-deep explanation on how the GPIO lines work and how to manage them faster is available on:
Using this basic example of wiring:
it is possible to define the W9 line as an output and turn on/off the red led with the following code:
from ablib import Pin led = Pin('W9','OUTPUT') led.on() led.off()
to read the button state it is possible to follow two methods:
This mode consists to check the actual state of the line calling the get_value() method.
from ablib import Pin PB=Pin('W15','INPUT') #Never ending loop while True: if (PB.digitalRead()==0): print "Pressed" while digitalRead()==0: pass
This mode consists to register a callback function with the set_edge() method that will call when the GPIO lines changes its state.
from ablib import Pin from time import sleep def pressed(): print "Pressed" PB=Pin('W15','INPUT') PB.set_edge("falling",pressed) #Never ending loop i=0 while True: print i i=i+1 sleep(0.5)
One of three conditions can be checked:
Using this basic example of wiring:
it is possible to refere to the pair connector/pin using this code to setup a GPIO as output and drive a led:
from ablib import Pin led = Pin('J7.3','OUTPUT') led.on() led.off()
If you are using a FOX Board G20 with the DAISY-1 adapter mounted on top the GPIO lines are available on the Daisy connectors (pinout).
In is possible to get a GPIO line using for example a DAISY-12 protoboard and set the GPIO line using the on() and off() methods of Pin class:
from ablib import Pin led = Pin('D5.2','OUTPUT') led.on() led.off()
On the TERRA Board the GPIO lines are available on the Daisy connectors (see the Terra pinout).
It is possible to access directly the GPIO lines using for example the DAISY-12 protoboard and set the GPIO line using the on() and off() methods of Pin class:
from ablib import Pin led = Pin('D11.2','OUTPUT') led.on() led.off()
to read the line state it is possible to follow two methods:
This mode consists to check the actual state of the line calling the get_value() method.
from ablib import Pin PB=Pin('D11.3','INPUT') #Never ending loop while True: if (PB.digitalRead()==0): print "Pressed" while PB.digitalRead()==0: pass
This mode consists to register a callback function with the set_edge() method that will call when the GPIO lines changes its state.
from ablib import Pin from time import sleep def pressed(): print "Pressed" PB=Pin('D11.3','INPUT') PB.set_edge("falling",pressed) #Never ending loop i=0 while True: print i i=i+1 sleep(0.5)
If you are using a Daisy module with leds, relays or other output devices you can use directly the name of the devices written on the PCB silk screen.
Following is an example to turn on a led on the DAISY-11 eight leds module:
from ablib import Daisy11 led = Daisy11('D11','L1') led.on() led.off()
This is an example with a Daisy-8 relay board plugged on D12 connector
from ablib import Daisy8 relay = Daisy8('D12','first','RL0') relay.on() relay.off()
The 'first' parms indicated that the Daisy8 used is plugged as first board on the flat cable. Up to board can be wired on the same daisy cable: 'first' and 'second'.
On FOX Board G20 only the both condition is available.
The Atmel CPUs used on the Acme boards arranges the GPIO in ports of 32 lines each called Port A, Port B, Port C, etc.
Most of the CPU pins are muxed with other peripherals (UART, I2C, SPI, etc.) and can be configured as simple GPIO line changing the Kernel configuration at boot time.