LINUX AND RTOS
BSP DEVELOPMENT

 

emutex embedded sw

 

We work with embedded systems OEMs to enable Linux distributions and board support packages to run on their newly developed hardware platforms. We enable Ubuntu, Debian and Yocto-built distros for Intel and ARM based solutions.

EMBEDDED SOFTWARE
DEVELOPMENT

 

emutex embedded cpu

 

We work with semiconductor and embedded systems OEMs to “bring-up” their new microprocessors and boards. We adopt, modify and develop operating system kernels and device drivers for Linux, RTOS and bare-metal solutions.

NETWORK PACKET
PROCESSING ACCELERATION

 

emutex dpdk service

 

We work with IT/telecom OEMs and service providers to maximise network traffic throughput rates and enable VNF in their Linux based enterprise servers. We integrate DPDK and virtualization technologies including Docker containers.


Enabling Embedded Sytems in a Networked World


 

This tutorial introduces wiring-x86.

 

The Intel Edison Arduino and Intel Galileo Gen2 are new embedded development boards from Intel. They are both Arduino compatible which means you can run standard Arduino sketches using the provided Arduino IDE.

But what if you wanted to use the Arduino I/O devices like GPIO, PWM or ADC without having to go through the Arduino IDE at all? Emutex has created a simple and elegant Python module called wiring-x86 that provides you with an easy-to-use interface to access these devices.

What is Wiring-x86

wiring-x86 is a Python module that lets you use Arduino like functionality on an Arduino compatible board such as the Intel Edison Arduino or Intel Galileo Gen2. It provides a simple API (similar to the WiringPi module) to talk to the GPIO pins and other peripherals on the board.

At the moment the wiring-x86 module provides support for:

  • Writing to a GPIO pin configured as output.
  • Reading from a GPIO pin configured as high impedance input.
  • Reading from a GPIO pin configured as pullup input.
  • Reading from a GPIO pin configured as pulldown input.
  • Reading from a GPIO pin configured as analog input (ADC).
  • Writing to a GPIO pin configured as analog output (PWM).

The wiring-x86 module is available as a package on PyPI, the main Python repository, and as source code on GitHub. It is released under a BSD license.

How it works

The secret behind wiring-x86 is its direct access to the sysfs interface provided by the underlying Linux drivers like GPIO, PWM or ADC drivers.

The module "talks" to the drivers by reading/writing into these sysfs files. It takes care of all the configuration needed to set up the pins to make them work in a particular way, i.e., making pin 3 work as a PWM output.

This process can be tedious to the user since it is not well documented but wiring-x86 hides it all behind a simple function call like
gpio.pinMode(3, gpio.PWM) making it really easy to use.

wiring-x86 is written in pure Python and has no 3rd party modules dependencies.

How to install it

Currently wiring-x86 can run on the ubilinux and Yocto platforms described below. Both of these OSes contain the I/O drivers that the module needs to talk to. There is no other dependency.

In either case it is assumed that you have ssh access in to the board since both start a ssh daemon automatically. Just plug in your Ethernet cable and check what IP address the board was given. You can do this either by looking at your router status or by logging in to the board using a serial connection.

Installing on Ubilinux

ubilinux is an embedded Linux distribution based on Debian "Wheezy" developed and maintained by Emutex Ltd. It is targeted at embedded devices that have limited memory and storage capabilities. For more information and download links please visit the official ubilinux website.

If you are using ubilinux you have different ways to install the module.

 Using pip is easy as running:

  1. $ sudo pip install wiring-x86

    Follow this link for more information on how to install pip
    in case it is not available on your system.

  2. To install the module manually first grab the code from GitHub:

    $ curl -O -L http://github.com/emutex/wiring-x86/archive/master.tar.gz

    Then install it as follows:

    $ tar zxvf master.tar.gz
    $ cd wiring-x86-master/
    $ sudo python setup.py install

After using either installation method check that the everything went okay
by running the following command. It should have no errors:

python -c 'import wiringx86'

Installing on Yocto Linux

If you are using the standard Yocto Linux distribution for Edison or the one for Galileo provided by (Intel Makers) then no additional OS preparation is required.

On Yocto, wiring.py can be installed by following step 2 in the previous section.

Setting up the Hardware

The following section describe the hardware setup for an Intel Galileo Gen2.

At this point the software should be ready to use. We now need to configure the hardware and set up the board to get some LEDs blinking.

As a first example set up your board as shown in the image below. This is taken from the Arduino blink example.

 

 emutex Intro to wiring x86 1

 

This is what the real board should look like:

 emutex Intro to wiring x86 2

 

Test the circuit by unplugging the red cable from pin 13 and plugging it back into 5V. You should see your led turning on. Do not forgetto return the red cable to pin 13 after your circuit has beenverified to work.

Once the hardware has been set up and tested you can use the wiring-x86 module to make the LED blink. The source code shown below has been taken from the wiring.py examples folder on GitHub. Open your favourite editor and just copy and paste this code into a new file on your board.

# Import the time module enable sleeps between turning the LED on and off.
import time

# Import the GPIOGalileoGen2 class from the wiringx86 module.
from wiringx86 import GPIOGalileoGen2 as GPIO

# Create a new instance of the GPIOGalileoGen2 class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
state = gpio.HIGH

# Set pin 13 to be used as an output GPIO pin.
print 'Setting up pin %d' % pin
gpio.pinMode(pin, gpio.OUTPUT)


print 'Blinking pin %d now...' % pin
try:
    while(True):
        # Write a state to the pin. ON or OFF.
        gpio.digitalWrite(pin, state)

        # Toggle the state.
        state = gpio.LOW if state == gpio.HIGH else gpio.HIGH

        # Sleep for a while.
        time.sleep(0.5)

# When you get tired of seeing the LED blinking kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the LED turned off.
    print '\nCleaning up...'
    gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
    gpio.cleanup()

Save it as blink.py and run it as follows:

$ python blink.py

If everything went OK you should see the LED blinking.

 

Other examples

This is probably the simplest possible demo but there are more in the wiring.py examples folder on GitHub. Some of these require extra hardware setup but none are too difficult. Just follow the link on the header of each one to get more information about how to set up your board in each case.

The other examples are:

  • analog_input.py

    Reads an analog voltage from pin 14 using the ADC on the board and makes the pin 13 to blink. The higher the voltage read the faster the pin 13 blinks.

  • blink_all.py

    Makes all the 20 pins on the board blink.

  • button.py

    Reads a digital input generated by a button connected to pin 2 and turns on LED 13 when the button is pressed.

  • fade.py

    Fades up and down pin 5 using the PWM on the board.

 

Conclusion

wiring-x86 is a very simple to use and yet powerful tool to control most of the I/O devices available on Intel Arduino compatible boards like Intel Edison Arduino or Intel Galileo Gen2. It provides an unified and familiar API that makes it easy to use and saves the user from the tedious work of configuring the GPIO internals.

At Emutex we will keep working on this tool to add more cool features and support for more boards.

Check our GitHub site for more cool stuff and the full wiring-x86 documentation on Read the Docs.

 


Go To Top