Introduction: HackerBoxes 0010: Phython Pi

Python Pi: This month, HackerBox Hackers are exploring Single Board "Pi" Computers as well as the Python Programming Language. This Instructable contains information for working with HackerBoxes #0010. If you would like to receive a box like this right to your mailbox each month, now is the time to subscribe at HackerBoxes.com and join the revolution!

Topics and Learning Objectives for this HackerBox:

  • Setting up and working with Single Board Computers (SBCs)
  • Exploring the Python Programming Language
  • Interfacing to General Purpose I/O signals from Python
  • Porting software projects between similar SoC platforms
  • Configuring advanced Audio/Video applications on an SBC

HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters.

Hack the Planet!

Step 1: HackerBoxes #0010: Box Contents

  • HackerBox #0010 Collectible Reference Card
  • Orange Pi Lite (with WiFi Antenna)
  • Power Cable (USB to 1.7mm Barrel Connector)
  • 16GB Sandisk Class 10 microSD Card
  • Cobbler T with 40pin Ribbon Cable
  • 400 point Solderless Breadboard
  • Jumper wires for Solderless Breadboard
  • 680 ohm resistors
  • 16x2 Character LCD Module
  • 4x4 Matrix Membrane Keypad
  • Pin Header for Keypad
  • SNES Game Controller (USB)
  • USB Card Reader for microSD Card
  • HDMI Cable (1 meter)

Some other things that will be helpful:

  • Soldering Tools
  • HDMI Display (monitor or TV)
  • USB Keyboard
  • USB Mouse

Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Setting up an Orange Pi Computer can be a bit more challenging than working with simple microcontroller boards. This type of hobby electronics isn't always easy, but when you persist and enjoy the adventure, a great deal of satisfaction may be derived from persevering and making things work!

Step 2: Orange Pi Lite

The Orange Pi Lite is an open-source single-board computer measuring only 69mm × 48mm. It runs the AllWinner H3 system-on-chip (SoC) with a quad-core ARM Cortex-A7. (datasheet)

The Orange Pi Lite has an HDMI video port driven by a Mali400MP2 GPU running at 600MHz. The GPU is capable of 4K video output.

For memory, the Orange Pi Lite has 512MB of DDR3 SDRAM and supports a TF (microSD) card up to 64GB for nonvolatile storage.

Ready to interface to pretty much anything, the Orange Pi Lite has two USB 2.0 host ports, one USB 2.0 OTG port, and a 40 Pin I/O header. It also features on-board WiFi networking and a Camera Serial Interface (CSI) for video capture up to 1080p@30fps.

The Orange Pi Lite can run Android or various Linux OS Images.

While the Orange Pi is similar to a Raspberry Pi, keep in mind that it is not exactly the same. Check out this impressive list comparing the various Single Board Computers.

Step 3: Set Up a MicroSD Card for the Orange Pi Lite

Just as a desktop or laptop computer boots up by loading operating system (OS) code from a hard drive, a single board computer (like the Orange Pi) generally boots up from a nonvolatile memory like a ROM or Flash Memory. In this case, we will set up the boot image of an OS onto a micro SD card (Flash Memory). We will be using Armbian, which is based on Debian Linux and is made specifically for ARM development boards.

From a computer, download the Armbian Image for the Orange Pi Lite. Currently, we recommend the Jessie Desktop version.

The file will download as a .7z compressed file which will have to be decompressed on your computer. If none of the decompression programs on your computer support .7z files, Google will help you find a free one for your operating system. The Armbian team suggests 7-Zip for Windows, Keka for Mac OSX, and 7z for Linux.

The decompressed file will contain a large .raw image file. This .raw file is the file that needs to be burned onto your microSD card to create the boot image for the Orange Pi Lite. Google can also help you find a free program for writing a raw image to a microSD card. The Armbian team suggests Rufus for Windows and dd for OSX or Linux.

Step 4: Booting the Orange Pi Lite

Once you have the boot image on the card, insert the card into the Orange Pi, hook up a keyboard, mouse, and HDMI display (monitor or TV).

Connecting Power: The Orange Pi Lite cannot be powered up through the USB OTG port. You have to apply power to the barrel connector using the supplied USB power cable. This cable should be connected to a heavier duty (2A or more) 5V USB power supply, not the smaller type that are generally used with mobile phones. Many problems encountered with Orange Pi boards are eventually traced back to using a weak or noisy power supply.

Power Button: Once everything is connected, press the tiny power button on the Orange Pi. After a few seconds, the green light will come on and a long boot process will begin. At the prompt, you will have to provide the default name and password (root, 1234) and then you will have to change it to your own password. Eventually, the GUI Desktop will appear and you can set up WiFi and use your new Orange Pi Lite just like any other SUPER TINY computer system.

Green Power LED: If the green "power LED" does not come on, the boot image on the micro SD card is not correct. It is actually code running from the card that turns the green power LED on, so if the image is not in order, it will appear as though the board is not operating. In a sense, it is not operating, because the processor is not running.

Using a DVI monitor: If you are using an HDMI to DVI cable, take a look at this tutorial and note the use of the '-d' switch for the h3disp program.

Encrypted Wi-Fi: Upon first connection, WPA sometimes does not engage. If you encounter this, go to preferences in Wicd. Under advanced settings, change the WPA supplicant to "nl80211" or to “none”. For some reason, just changing it a time or two seems to usually force WPA to engage perfectly.

Step 5: The Python Programming Language

Python, according to Wikipedia, is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. The language provides constructs intended to enable clear programs on both a small and large scale. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.

Open up a terminal window on your Armbian desktop, and let's start by grabbing python-dev which includes the header files and a static library for building Python programs. Type this at the terminal prompt:

sudo apt-get install python-dev

The video above shows some simple examples on how to try out lines of code directly within the Python interpreter and also now to use the editor nano to create a Python program file and then run the program right on your Orange Pi.

If you wish to delve deeper into programming with Python, which of course you do, there are a great number of free Python tutorials online. You can even enroll in the MIT course "Introduction to Computer Science and Programming Using Python" through EdX.

Step 6: Orange Pi GPIO

The 40 pin header on the Orange Pi Lite exposes numerous General Purpose Input/Output (GPIO) lines that can be used to get signals into and out of the processor. Note that the GPIO pins are 3.3V inputs and we must be careful not to inject 5V signals into them.

We will be using the pyH3 package, which provides methods for controlling the Orange Pi's GPIO pins, I2C and SPI buses. This package was modified from pyA20, which was created for the very similar A20 SoC. The reference information for using pyA20 is still quite useful.

From the Orange Pi Lite, follow the pyH3 link above and download the package. Extract the folder and place it as /home/pi using the file manager. Go into the terminal at that pi folder and install the package using:

python setup.py install

Now that the library is installed, cd into examples and execute this example:

sudo python blink_POWER_STATUS_PL10.py

This will blink the red LED next to the green power LED. Take a look at the code to see what is going on:

more blink_POWER_STATUS_PL10.py

Step 7: T-Cobbler for Orange Pi Lite

The T-Cobbler is an expansion board that connects to the Orange Pi's 40 pin GPIO connector and breaks the pins out to a breadboard-friendly format.

The T-Cobbler was originally intended to be used with the Raspberry Pi boards, so using it with the Orange Pi is a bit of a hack. There are two things to keep in mind:

1. The power and ground pins are all the same between the RPis and the OPis, but the GPIO signal names are totally different. Accordingly, the signal name markings on the T-Cobber are useful for the power and ground pins, but the signal names for the GPIO lines have different names. Check the pin chart shown here (or on the handy, collectible reference card) to identify the correct H3 / Orange Pi signal names.

2. Note that the 40 pin connector on the OPi is ROTATED 180 degrees from that of the RPi. Pay very close attention to the "pin 1 indicator" on the ribbon cable's connector, or you could short some pins out. You will find that may require some creative routing and/or origami work with the ribbon cable when connecting between the OPi and the T-Cobbler.

Step 8: LCD Display

You can use the T-Cobbler to interface all manner of buttons, LEDs, and so forth to the Orange Pi in a similar fashion as you might with an Arduino. For example, let's hook up a 16x2 Character LCD Display that uses the Hitachi HD44780 LCD controller chip (datasheet).

Twelve of the 16 pins on the LCD module will be used in this project. You can make a "cable" for the module using twelve of the breadboard jumper wires. Solder one pin of each jumper into the appropriate hole in the LCD module and then the other end of the jumper can be inserted into the solderless breadboard. Of course, if you have a row of single header pins and some female-to-male DuPont jumpers, you can use those instead (as shown in one of the photos).

Wire the LCD to the T-Cobber like so:

LCD <--> OPi
001 <--> GND
002 <--> +5V
003 <--> GND
004 <--> PA19
005 <--> GND
006 <--> PA7
007 <--> NO CONNECT
008 <--> NO CONNECT
009 <--> NO CONNECT
010 <--> NO CONNECT
011 <--> PA8
012 <--> PA9
013 <--> PA10
014 <--> PA20
015 <--> +5V (via resistor)
016 <--> GND

Pin 5: The R/W pin allows the LCD module to be put into read or write mode. We want to send data from the OPi to the LCD module, but we DO NOT want the LCD module attempting to send data to the OPi. Among other reasons, the 5V signals from the LCD module might damage the 3.3V pins of the H3 SoC. We can ground pin 5 to keep the LCD module from driving the data lines.

Pin 3: You can control the contrast of the display by varying pin 3 between 0V and 5V (e.g. with a potentiometer). For simplicity, grounding pin3 to 0V works well enough for a demo.

Pins 15 and 16: These are the 5V supply to drive the backlight LED. Everything seems to work fine to just hook these up to 5V and GND, but it can't hurt to include a current limiting resistor inline. One of the included 680 ohm resistors will work fine.

Once everything is wired up, try out the Python program included here to test your LCD display.

(Adapted from the Raspberry Pi version HERE.)

Step 9: Keypad Inputs

Now that we are getting the hang of using the GPIO functions, we can read inputs from a 4x4 membrane keypad matrix.

The video example shows a Raspberry Pi setup, but working with the Orange Pi is exactly the same. We just substitute in the pyH3 GPIO package for the RPi GPIO calls Note the use of internal pullup/pulldown resistors instead of physical external resistors. This is an important technique to know.

Want a challenge? Leverage both the LCD display and the keypad to create a four-function calculator. Yes, this is overkill, but it is a great academic exercise. Can you think of anything else exciting to do with these peripherals?

Step 10: Retro Gaming and Media Center

RetrOrangePi is a gaming and media center distribution for the Orange Pi, based on Armbian.

RetrOrangePi includes RetroArch, which is an open source, multi-platform frontend for the libretro API. It is designed to be a fast, lightweight, and portable multi-system emulator. RetroArch provides a slick, all-in-one interface on your Orange Pi for any retro game you can imagine combining emulators for video game systems like the Nintendo, Super Nintendo, Genesis, and others.

RetrOrangePi also includes Kodi, which is formerly known as the XBMC Media Center. Kodi is an award-winning free and open source cross-platform software media player and entertainment hub for digital media. It uses a 10-foot user interface designed to be a media player for the living-room, using a remote control as the primary input device. Its graphical user interface (GUI) allows the user to easily browse and view videos, photos, podcasts, and music from a harddrive, optical disc, local network, and the internet using only a few buttons.

Step 11: Pi Everywhere

Here are some great Pi projects. Many Raspberry Pi projects either already have an Orange Pi version or can be easily adapted...

Physical Computing with Pi

Analog Inputs

Jasper (an open source platform for developing voice-controlled systems)

Sonic Pi (the Live Coding Music Synth)

Step 12: Hack the Planet

We hope you are enjoying your time working with the Orange Pi Lite single board computer. If you dig this Instrucable and would like to have a box like this delivered right to your mailbox each month, please join us by SUBSCRIBING HERE.

Please share your success in the comments below and/or on the HackerBoxes Facebook page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of the HackerBoxes adventure. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!