Using videos and displays in projects

It's one thing to just plug an HDMI monitor into the mini HDMI port on your BBB and get a picture. In many cases, this is may be all you care about for a project. However, for bona fide embedded or mobile scenarios where you need a display, using the HDMI option can be overkill; your needs are low power, small form factor, and just enough display to convey basic information.

In this section, we will take a look at two other options for display: a mini OLED display available as a breadboard-able PCB and a custom BBB cape designed with a very small LCD panel.

Hooking up a mini OLED

In this recipe, we will take a look at a very small 1.3 inch OLED display with a resolution of 128 x 64 pixels. It has a monochrome screen, which means that we will not be watching Lawrence of Arabia on this device. Instead, we will explore some methods for basic control and input and take a preliminary peek at typical design choices for embedded devices.

The nice thing about experimenting with a device like this is that we can make use of another set of pins available on BeagleBone Black: the Serial Peripheral Interface or SPI pins. The BBB packs two SPI ports, and we will use one of these. Some of the advantages of this interface include higher throughout and lower power consumption than I2C, which we used in an earlier recipe in this chapter.

Tip

To be clear, this recipe will not result in an alternative desktop display. Instead, it is the basis for building a more robust—albeit considerably smaller—low-powered display option for your customized prototyping requirements and tests. To demo the screen, we will run Python scripts as they are an easier entrée into the hardware.

Getting ready

You'll need the following items:

  • OLED PCB: We will use the SSD1306 driver chip version, which is available (mostly) preassembled at Adafruit https://www.adafruit.com/product/938). The board requires only a minor soldering job to attach the pins and costs around USD $25.00.
  • The BBB, both powered and remote SSH called, via the USB cable: Let's go headless… no cheating! There's also a practical reason to eschew an external monitor in this recipe: we will be disabling the HDMI port, so you would lose the signal anyway.
  • 6x jumper wires
  • A breadboard

Adafruit's OLED comes with its own tutorial and Python example scripts. Although we will rely on the Adafruit Python BBIO library, we will actually use an additional Python library developed by Guy Carpenter and modified by Ethan Zonca along with our own custom example code.

How to do it…

Now that you're ready, let's get started:

  1. Wire up your board and breadboard in the following manner:
    How to do it…

    To be clear, here is the hookup in table form:

    OLED Screen

    BBB pin

    Function

    GND

    GND: P9_1

    Ground

    VIN

    VDD_3V3: P9_3

    Power

    CS

    CSO: P9_28

    Slave connector

    RST

    GPIO: P9_24

    Reset display

    DC

    GPIO: P9_16

     

    CLK

    P9_31

    Clock

    Data

    P9_30

     
  2. In order to use SPI pins, we need to enable a Device Tree overlay, which is easy to do as it is already compiled on the system and most efficient to load at bootup. So, first call SSH into your BBB, open a terminal window, and then browse to the following directory:
    $ cd /boot
    
  3. Now, open the file, uEnv.txt:
    $ sudo nano uEnv.txt
    
  4. Then, add the following lines at the very end of the document:
    ##This line added to enable device tree overlay for SPIDEV
    optargs=capemgr.enable_partno=BB-SPIDEV1
    
  5. Save and close the file, and then reboot your BBB as follows:
    # reboot 
    
  6. Log back in as the root user and confirm that the /dev/spidev1.0 and /dev/spidev1.1 files are visible, indicating that the SPI drivers are available for access:
    $ sudo -i
    # ls -l /dev/spidev*
    

    You should get an output similar to this:

      crw-rw---T 1 root spi 153, 1 Mar  1 20:46 /dev/spidev1.0
      crw-rw---T 1 root spi 153, 0 Mar  1 20:46 /dev/spidev1.1
    
  7. Next, we need to install a number of Python libraries and their dependencies. Some of them may already be available on your system, but run the following commands just to be certain:
    # apt-get update
    # apt-get install build-essential python-dev python-pip python-imaging python-smbus python-dateutil
    # pip install spidev
    # pip install pil
    # pip install Adafruit_BBIO
    

    Note

    You could run all the pip install commands off one line; however, for clarity's sake, we will show each individual package install.

  8. Next, we want to actually do something with the display and all these libraries. So, download a GitHub repo with sample code:
    # git clone https://github.com/HudsonWerks/OLED-SSD1306.git
    
  9. Browse to a subdirectory of example in the directory of code we just downloaded and take a look at what is inside:
    # /OLED-SSD1306/samples
    # ls
    
  10. Before looking at what is inside the code, let's run the main example to see if all of the hardware wiring is correct:
    # python oled-test1.py
    

    If all went well, you will see text cycling on the screen with messages from ground control.

  11. We want to take a brief look at the Python code, so we will now run the following command:
    # nano oled-test1.py
    
  12. Finally, open up the Cloud9 IDE (http://192.168.7.2:3000/ide.html), create a new .py file called oled-test1.py, and then copy and paste the code from your nano window into the IDE file window. From here, you can begin customizing the code, starting with the messages displayed on the screen.
  13. Once appended, save the file and click on the RUN button in the IDE. An updated scrolling text message will appear on your OLED display.

Note

Before running a Python script in the Cloud9 IDE, remember to save the document each time. Otherwise, the IDE may run a cached version that does not contain your new changes.

There's more…

The following is some supporting information:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.119.199