Travel, Technology, Health

Accessing The Chip GPIO Port Via Xojo

July 19, 2016 / Eddy / CHIP

Last November, I read about this $9 Computer called the CHIP and was intrigued. This was right after their Kickstarter campaign and was into the Pre-order stage. The Raspberry Pi 3 came out about that time but at $35, definitely costly more to try. So it such a no brainer to place an order for 5 CHIP during one of their pre-order special. Of course, knowing the fact that I will only get the CHIP many months later.

Jumping forward to last week, some 7 months later, my 5 CHIP arrived

The first thing I did was to flash one of the CHIP to headless as I didn’t intend to plug it directly to a monitor but to access it remotely. That’s one of the reason why I bought the Xojo Web License so I can control the CHIP remotely.

Today I’ve got some time so I thought I do the quintessential example to turn on and off a LED on the CHIP remotely from the web. Tested some of the command line codes to turn on and off a LED. Seems simple enough. I picked the GPIO 0 (XIO-P0) which is mapped to GPIO1016 under the v4.4 Firmware.


The basic codes are pretty simple

sudo sh -c ‘echo 1016 > /sys/class/gpio/unexport
sudo sh -c ‘echo 1016 > /sys/class/gpio/export’
sudo sh -c ‘echo out > /sys/class/gpio/gpio1016/direction’
sudo sh -c ‘echo 0 > /sys/class/gpio/gpio1016/value’

The first line of code just ensure that GPIO Port 0 is unmapped and the second line would map it. If not, I would not be able to access the /sys/class/gpio/gpio1016 folder. At this moment, all I see is a /sys/class/gpio/gpiochip1016 which I have no access to.

The third line of code sets the GPIO port to the output mode and the fourth switch the LED off by sending it a binary 0 code.

To turn the LED on, I just send the following code

sudo sh -c ‘echo 1 > /sys/class/gpio/gpio1016/value’

1 is On and 0 is Off. Pretty simple.


Since there isn’t any really made library for Xojo, I just make use of the command lines to get the same thing done.

On the Page Open event

dim k as new Shell

k.execute “sudo sh -c ‘echo 1016 > /sys/class/gpio/unexport”
k.execute “sudo sh -c ‘echo 1016 > /sys/class/gpio/export’”
k.execute “sudo sh -c ‘echo out > /sys/class/gpio/gpio1016/direction’”
k.execute “sudo sh -c ‘echo 0 > /sys/class/gpio/gpio1016/value’”

Same Codes as below but this time I run them as an individual shell execute command line.

Made a simple toggle to turn on and off the LED on the CHIP.

dim k as new shell

if Segmentindex = 0 then
k.execute “sudo sh -c ‘echo 0 > /sys/class/gpio/gpio1016/value’”
textarea1.appendtext “Turn LED Off”+EndOfLine
k.execute “sudo sh -c ‘echo 1 > /sys/class/gpio/gpio1016/value’”
textarea1.appendtext “Turn LED On”+EndOfLine
end if

Just some simple codes to turn on and off the LED when the user toggle the Segment Control.

Here’s the CHIP in action

All these is done via the web, okay in this case it’s via WIFI and the CHIP is only plugged into a power bank to power it. With the web interface and a xojo based web server running on the CHIP, I could get it to almost do anything. The LED experiment probably would not be a world shattering project but it shows what the CHIP is capable of doing.

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *