sgjava Posted December 30, 2017 Posted December 30, 2017 The Luma library allows you to display text, graphics, animation, etc. on multiple display types. Here I will describe the easiest one to configure which is Luma.OLED and the I2C version of the SSD1306. You can find these displays on EBay and Amazon for less than $10 US each (you can get them for less than $3 US if you order from China, but it might not show up). I've configured Luma on many SBCs and it's my go to library if I need a small display for projects. Requirements NanoPi Duo (I used V1.0 board with 512 MB RAM) flashed with Armbian image. This will work with or without the mini shield. Small nylon nuts, bolts and standoffs if you want to mount display I2C OLED display (check http://luma-oled.readthedocs.io/en/latest/hardware.html) 4 female to female jumper wires If you want to configure wifi the easy way just edit the following file on the SD sudo nano /media/username/43296f0d-fc9e-4cec-b3bf-f335fc72f371/etc/network/interfaces and add: allow-hotplug wlan0 iface wlan0 inet static address 192.168.1.69 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.1 wpa-ssid your_ssid wpa-psk your_password Comment out the eth0 stuff. You can do it the hard way with the debug serial interface though if you want When I ordered my Duos I forgot to order the USB dongle, so I would have been out of luck otherwise. Boot up and configure the Duo the way you like, power off and wire up the display as follows: VCC to either 5Vin or 3V3 GND to GND SCL to SCL SDA to SDA Power up Duo and configure I2C: sudo nano /boot/armbianEnv.txt and add i2c0 to overlays= sudo apt-get install i2c-tools sudo usermod -a -G i2c username (non-root user you created) sudo i2cdetect -y 0 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- If you see the 3c on i2c0 then you are in business. Let's install Luma.OLED: sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev sudo -H pip install --upgrade pip sudo apt-get purge python-pip sudo -H pip install --upgrade pip setuptools sudo -H pip install --upgrade luma.oled sudo -H pip uninstall RPi.GPIO (this will not work on Duo and is not needed for I2C) OK, let's create a simple demo program to make sure things are working nano i2chello.py: import time from luma.core.interface.serial import i2c from luma.core.render import canvas from luma.oled.device import ssd1306 serial = i2c(port=0, address=0x3C) device = ssd1306(serial) with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") draw.text((3, 3), "Hello", fill="white") time.sleep(10) And you should see (screen shot from the Luma emulator): Now we can install the Luma examples: sudo apt-get install git-core libsdl-dev libportmidi-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev libsdl-image1.2-dev git clone https://github.com/rm-hull/luma.examples.git cd luma.examples sudo -H pip install -e . Let's run an example: sudo python examples/invaders.py -d ssd1306 --i2c-port 0 --i2c-address 0x3c 2
Recommended Posts