Pine or Pi?

The absence of analog interface features and incompatible GPIO interface preventing use of the Pi software modules hamper use of the Pine for casual IoT hacking.

Another nuisance is the lack of Wifi onboard.

Given that the processor and memory specs on the Pine exceed those of the Raspberry Pi 3 B+ these weaknesses mean it will be hard to find a good use case for the Pine over the Pi.

Deeper into GPIO and the A64

Let’s see what the kernel thinks we have configured for the gpio interface that is letting us use the virtual filesystem driver. Using the kernel’s built in debug filesystem interface we ask it what the config is
root@pine64:/tmp# cat /sys/kernel/debug/gpio
GPIOs 0-255, platform/1c20800.pinctrl, 1c20800.pinctrl:
gpio-80 (sysfs ) out lo
gpio-166 (1c0f000.sdmmc cd ) in lo

GPIOs 352-383, platform/1f02c00.pinctrl, 1f02c00.pinctrl:
gpio-354 (wlan_regon ) out hi
gpio-355 (wlan_hostwake ) in lo
gpio-356 (bt_rst ) out hi

GPIOs 1024-1027, platform/pinctrl.1, axp-pinctrl:

So we see that gpio-80, our LED from the prior post is ‘owned’ by sysfs since I didn’t unexport it, and is an output and currently logic low or 0v

Looking deeper into the kernel config we find many more config files in the filesystem tree in these locations
/sys/kernel/debug/pinctrl/ and /sys/kernel/debug/gpio/

To find out what the kernel is really talking about on these interfaces we shuold go to the source and read the documentation.

Our A64 ia also known as a sunxi50i

Using GPIO on Pine64 from node.js

We can use a module already built that leverages the file system driver to run our LED and make it blink.

One such module is called ‘onoff’ which can be installed with npm

Here is a brief node program that blinks the LED at 1 hz ( 500 ms on / 500 off )
var Gpio=require('onoff').Gpio;
var led = new Gpio(80,'out');



var LED=false;
function ticktock(){
// turn on LED
else {
// turn off LED

Simple and functional although it must be run as root, if you don’t need anything too fancy this will be sufficient.

PineA64+ nodejs and npm installation

I like the event driven programming paradigm used by node.js, it is well suited to embedded control and many real world problems.  The version of node included in the previous post’s image does not have a working node package manager npm so we will need to install one that has access to the world of node packages.

First go and download the node.js sources from chose the Source Code option.

Open your terminal window. We then unpack the sources, configure and build node which included npm. If the build works, we remove the existing one and install the update. Build does take quite a while. If it fails, check for and install any missing packages.

node -v
cd /tmp
tar -xzf /home/debian/node-v6.9.1.gz
cd node-v6.9.1
make test
node -v
./node -v
sudo apt-get remove nodejs
sudo make install
node -v

The result should be node running the current version instead of the oddball obsolete version.

You can now start installing the node packages you like using npm as usual nodejs installation method fails on pine64

As of November 22nd, 2016, this method does NOT work on the Pine64 as the nodesource repository does not have entries for arm64.

The commonly posted method for installing node on the Raspberry Pi is to run the script located here piped directly to bash from the command line.

I do not consider this pattern to be safe or sane from a security perspective as you do not have control over what is in that script, even if you preview it in your browser as they could serve different versions of the script for wget versus Chrome. If you want to use their automated script, and I do generally think that it is reputable and safe, download the script to your /tmp directory and review it before running it.

That said, until they add the binary-arm64 builds it will fail with the following error.  Use the manual compile method described in my other post.

  Unable to find expected entry 'main/binary-arm64/Packages' in Release file

Blinking lights on the PineA64+

Now that we have a running Linux system on our Pine64 we will want to do something fun with it.  As a hardware hacker, one of the first things we do is to make an LED blink, the equivalent to “Hello World” in straight coding.

The PineA64 uses a System on a Chip SOC from AllWinner which contains an absurd amount of complexity and more features than you will likely ever use.  Thanks to the abstraction layers in Linux we have a somewhat simple route to access the General Purpose Input Output GPIO pins, the System Class virtual filesystem drivers.

We will use a T-Cobbler board to bring the Raspberry Pi connector out to a breadboard.


Now we do have a bit of complexity here, the mapping between the connectors on the board and the pins on the SOC are not direct or obvious and they differ from the Raspberry Pi locations, even though they make an RPi port available.  We are going to use the Pi pin labeled #26 for our LED.  To map this to the Pine64 we can refer to this page’s chart: and see that this pin is number 80 on the Pine.


Wire the LED with a resistor in series between pin #26 and 3.3v.  I used a 1k resistor.  This will make ‘0’ on and ‘1’ off.

sys/class/gpio is the virtualized file based access mechanism we will use for our initial LED on/off test.

Sending the pin number you wish to activate to /sys/class/gpio/export will enable that pin and expose the virtual control files in the directory /sys/class/gpio/gpio80

From out trusty console we can type these lines to make the value at pin 80 change from floating to output and then set the values, toggling the LED connected there.

ll /sys/class/gpio
echo 80 > /sys/class/gpio/export
ll /sys/class/gpio
echo out > /sys/class/gpio/gpio80/direction
echo 0 > /sys/class/gpio/gpio80/value
echo 1 > /sys/class/gpio/gpio80/value
echo 80 > /sys/class/gpio/unexport

You should see the LED light when you issue the command to set this pin to 0.

We are half way there.  This interface can be scripted or even used in node programs as these ‘files’ can just be read or written to using fopen and fwrite.

A quick script to blink the led ( which must be run as root, ugh )

while (true)
echo 0 > /sys/class/gpio/gpio80/value
echo 1 > /sys/class/gpio/gpio80/value

The wise will note that there are no waits in this code. Running in this way pulses the LED about 280 times per second.

Probably fast enough for many things but I want to get this working with node.js

Exploring the Pine A64+QuickStart

This board, while a bit larger than the RPi 3 has a much faster processor and double the RAM at a lower price point.  I have the 2GB model costing $29 which shipped on time and arrived quite fast from China.

Linux gurus, lenny.raposo and longsleep along with help from many others have gotten fairly solid Linus builds ready to burn on SD card and available here:  I am using the Debian Jessie image 20160701 to start with.

Follow their directions to install the image on a fast microSD, I used a 32gb card freebie from microcenter that h2wtest rated at 16Mb/s write and 33Mb/s read.  Faster is better.

Insert burned SD and connect a powered hub to one of the USB host ports with a keyboard, mouse and wifi dongle ( or ethernet ) before booting then attach a 2.5a micro USB power supply.

Without adding drivers, certain net cards will work, come will not. The Alfa AWUS036H does work out of the box but has occasional freezes.  The Alfa AWUS036NHA does not work.  others will work, the more common in Linux the better chances it will be trouble free.

Boot the system creds are debian:debian

If you used an SD card larger than 8GB you will want to resize the filesystem to use the whole card. There is a supplied script to do it but I had to run the commands manually to get them to take effect.

sudo su
df -h
# If this does not show the full capacity do the following after reading the script
less /usr/local/sbin/
partx -u /dev/mmcblk0
resize2fs /dev/mmcblk0p2
df -h

setup your net connection and verify you have access to the outside.

You now have a working Linux mini-PC.

Normal next step is to update any packages to get fixes.

Open a terminal window and we will get started:

sudo apt-get update
sudo apt-get upgrade –fix-missing

You now have a current and ready to run system.

In the next post we will blink and LED then install nodejs and npm.


Exploring the IoT landscape

I have always used bare chip micro-controllers for little projects as the price point and features were a good fit.  Recently, alright, for the past few years, maker boards have been dropping in price to be competitive with single chip options while offering a much more capable feature set.

I realize that you really don’t need a full featured web browser and 4k output on your toaster but when the Pi Zero is $5.00 and a bare PIC32 in DIP is $3.41 with far less of everything it’s no longer easy to select the more ‘appropriate’ solution.

I’m going to write up my experiences with a few of these devices and their adapters as I go along but only where the current information is weak or confusing as is often the case with less mainstream options.