Wednesday, June 26, 2013

pcDuino - Blink Tutorial

This tutorial will show you how to program the pcDuino to flash an LED on a connected breadboard.

It assumes you have a basic working knowledge of the pcDuino and Linux.

For this tutorial you will need the following items:

  1. A pcDuino running the 20130531 Ubuntu image with ssh.
  2. A breadboard.
  3. An LED.
  4. A 100ohm resistor
  5. Two wire jumpers.
  6. The source code below for blink.c


Hardware Setup

The hardware setup for this tutorial is pretty easy. 

Take the LED and plug the negative or cathode lead into the ground strip on you breadboard.  This lead is the shorter of the two leads and comes from the side if the LED that is flat.

Plug the positive or anode lead into a row on the body of the breadboard.

Take the resistor and plug on end into the same row as the positive lead of the LED and plug the other lead into another row on the body of the breadboard.

You should end up with something that is close to the picture below but without the jumpers.


Take your two jumpers and connect one into the ground strip and the other into the row as the resistor lead (and only the resistor lead) in it.  I used a black jumper for the ground and a green one for the signal.

Next you will need to connect the other ends of the jumpers to the pcDuino.  This should be done before power the pcDuino on.


At the bottom of the pcDuino board there are two rows of pins.  One row of pins is right next to the edge of the board and the other is on the other side of the first row.  We are going to be using pins in the row right next to the edge of the board.

With the board oriented so that the host usb ports are to the left and the hdmi / ethernet jack are to the left we want to connect the ground jumper to the fourth (4th) in from the right and the signal jumper to the fifth (5th) pin.  This will connect the ground jumper to a ground pin and the signal jumper to the pin assigned to gpio13.

At this point you are ready to power up your pcDuino to get the program loaded and compiled.

blink Program

Blinking an LED with the pcDuino is pretty simple.  On the pcDuino the pin we connected our signal jumper to is known as a gpio pin.  This stands for “general purpose IO”.

On the pcDuino the gpio pins are accessed using two pseudo files. 

The first “file” is /sys/devices/virtual/misc/gpio/mode/gpio13.  This “file” is used to set the mode of the pin.  There are three possible modes: input, output, and input with pull up resistor.  We will be using the output mode.

The second “file” is /sys/devices/virtual/misc/gpio/pin/gpio13.  This “file” is used to set the value of the pin.  Pins can be set to low or zero by writing a “0” to this “file”.  Pins can be set to high or one by writing a “1” to this “file”.

With our blink example writing a “1” to the value pin will light the LED and writing a “0” will turn off the LED.

The program below turns the LED on, waits two seconds, turns the LED off, waits two seconds and then starts the whole process over until it has been done 10 times.


#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define pinModePath "/sys/devices/virtual/misc/gpio/mode/gpio13"
#define pinDataPath "/sys/devices/virtual/misc/gpio/pin/gpio13"

int main(void) {

  int pinMode = open(pinModePath, O_RDWR);
  int pinData = open(pinDataPath, O_RDWR);

  // "0" - pin INPUT
  // "1" - pin OUTPUT
  // "8" - pin INPUT with pull-up resistor
  write(pinMode, "1", 1);
  // "0" - LOW
  // "1" - HIGH
  write(pinData, "1", 1);
  int i;
  for (i=0; i < 10; i++) {
    write(pinData, "1", 1);
    write(pinData, "0", 1);

Program Setup

Start by connecting to your pcDuino via ssh. I am connecting from a PC running Windows 7 Pro 64bit and using a KiTTY as my ssh program. KiTTY is a form of PuTTY v0.62 which has some added features I like. Any ssh program should work.

Login into any user on your pcDuino.  I used the default ubuntu user which if you haven’t changed it (which you should have) has a default password of ubuntu.


I would suggest making a subdirectory to build your program in.  This isn’t required but is a nice way when you get to more complicated programs of keeping everything together.  I used tutorial and then changed directory to tutorial.

The next step we will do will allow you to copy the source code from this post and paste it into a file on the pcDuino.  Start by copying the source code for blink.c posted above.  The go back to your ssh windows type “cat > blink.c” and return.  This will leave you with a blinking cursor one line below the cat command.


Next move your mouse pointer into the ssh window and paste the source code into the window.  Once the source code has finished “typing” into your window press control-D (while holding down the control key press and release the D).  This will bring you back to the prompt.  Most ssh programs I have used will automatically paste what is in the paste buffer into the window if you select the right mouse button.



If this process of entering the source code doesn’t work you can always manually type the source code into a file using a text editor on the linux system.  This isn’t that difficult to do but is beyond the scope of this tutorial.

Next you should make sure that the gpio drivers are loaded on your system.  This is done by running the “lsmod” command.  As shown in the window below there should be a line for hardwarelib followed by gpio.  If that line doesn’t exist you can use the privileged modprobe command to load the driver.  This is done by typing “sudo modprobe gpio”.  Once this has been done you can rerun the lsmod command and you should see the gpio’s listed.


You are now ready to compile your program and run it.  To compile and link you program you should use “gcc blink.c –o blink”.  The system will compile your program in file blink.c and save the executable in a file called blink.  To run the program you enter ./blink and the LED on your breadboard should begin to blink.


Thanks to the folks at Sparkfun and their great Getting Started with pcDuino for getting me started with putting this tutorial together.  Also thanks to the folks on the pcDuino website for their support.  Check out the website and forums for more information.

Wednesday, June 19, 2013

openFrameworks / pcDuino

After a couple of months of on and off again work building on what was started by bakercp and others I have had some success in getting openFrameworks running on the pcDuino.

I am able to compile the openFrameworks library, compile openFrameworks programs and run them.

With the steps below you should be able to compile a pcDuino Hello World application similar to the one for the Raspberry Pi.

Setup the pcDuino to use Mali Framebuffer

git clone
cd sunxi-mali
git submodule init
git submodule update
make config VERSION=r3p0 ABI=armhf EGL_TYPE=framebuffer
make install
make test
stop lightdm

At this point you should see something that looks like this


Setup openFrameworks

git clone
cd RaspberryPi-openFrameWorks
cd scripts/linux/ubuntu_pcduino/

Compile and run the pcDuino Hello World Program

cd ../apps/devApps/pcDuino_hello_world_gles2
sudo ./bin/pcDuino_hello_world_gles2

At this point you should see a spinning pcDuino board on a yellow background.

I haven't had time for much testing. Besides the Hello World program I have successfully tested several of the examples. I hope to have some time for more testing over the next couple of days.

Saturday, June 1, 2013

It Worked For Me - pcDuino

The March 1st Sparkfun New Product Friday post included a linux development board that peaked my interest.  The pcDuino was described in the post as something that folks who were looking at the Raspberry Pi but wanted a bit more should check out.  The post went on to say that besides running Ubuntu and Android you could connect Arduino shields to it.  I was hooked and by the end of the day had placed my order. A week later a red Sparkfun box showed up at my doorstep.

After unboxing it I connected a keyboard, a mouse, an HDMI cable and my ethernet switch and applied power. I was rewarded a few moments later with an Ubuntu 12.10 LXDE window on my monitor. Getting this far was a no brainer.

My next step was to get it to connect to my home network using the wireless dongle that I had ordered with the board. Unfortunately, this didn't go as well. At the time the image loaded in NAND didn't support the chipset used on the wifi dongle.

Fast forward...

I have been working with the pcDuino for about three months. For me the pcDuino has been very DIY and therefore has been an interesting (sometimes frustrating) learning experience.

To aid with the DIY process there is a lot of good information. Sparkfun has tutorials. There is a support website for the pcDuino that contains informational posts, software images, a wiki and forums. Finally there is a pcDuino repository on github.

Sparkfun Tutorials
pcDuino website
pcDuino on github

When I got my pcDuino these sites were much less mature than they are now and didn't have a whole lot of information. However, I found that there are a number of Allwinner A10 based development boards and a number of inexpensive A10 based tables made in China. As a result there is a small (compared to the RPi community) but very active user community.

Googling around the internet I found a number of sources of detailed information and source code:

Forums at - these forums are a treasure trove of information. The information is a bit dated but still very useful.

rhombus-tech - this is another site that has a lot of good A10 based information.

linux-sunxi - this site is the heart of the community and along with the linux-sunxi google group is the best source of information and software.

The lack of out of the box support for the wifi dongle led me to attempt to load the driver source and compile it. Unfortunately, the pcDuino image didn't contain the necessary header files to be able to compile the driver so I was stuck.

After looking a bit further it appeared that if I compiled my own kernel I could include the needed wifi driver. It also looked like there were several other options that I was looking for that were available from the repositories at linux-sunxi. I ended up setting up a cross compile environment on Ubuntu and building my own kernels. Building my own kernels enabled me to finally get the wifi card working and to get bluetooth working.

Over the past three months the pcDuino community has grown. The community, along with the folks that developed the pcDuino, continue to move things forward. There have been several new software images released by the pcDuino folks, some software ported to the platform, a number of tutorials developed and informational posts that apply specifically to the pcDuino.

Below is setup I I have been using. I attached my pcDuino to a piece of plexiglass with rubber feet on it to keep it from sliding around. I am using an older Sparkfun 3.3v FTDB Basic board to connect to the pcDuino's serial console and a Manahattan USB hub to connect the wifi card, an IOGear Bluetooth dongle and a keyboard and mouse as well as to supply power to the pcDuino.


One area that has been challenging is the ability to integrate some of the features that come in the stock software working with custom kernels. There is a lot of discussion as to the cause of this on various websites. It appears that some of the problem is the level of support Allwinner is providing the open source community. However, even with these challenges things have come a long way thanks to a core of very dedicated people.

My experience with the pcDuino has been positive. I would recommend it to anyone who is looking for a moderately powered linux development board for DIY projects as long as they are comfortable with a product that is slightly rough around the edges.

More to come...