Git Product home page Git Product logo

u8g2-rpi-demo's Introduction

Introduction

ST7920 using U8G2 on Raspberry Pi Demo

This project serves as an example of how to build and compile a C++ project using U8G2 and Wiring Pi library on the Raspberry Pi. CMake is used as the primary build tool with support for cross-compilation.

The display used for this demo is ST7920. If you would like to use a different display, you could easily modify the source and replace the setup/constructor definitions.

This project uses a custom SPI library for communication with the display, if you are wondering why that is considering Wiring Pi already provides such methods, please read the issue here.

Project Dependencies

Build Instructions

The project comes with a utility script for compiling on the Raspberry Pi or for cross-compiling from a Linux operating system. Cross-compilation will automatically take place if the script has detected it is not running on the target platform.

To compile on the Raspberry Pi, simply run the compile script.

./compile.sh

CMake will automatically download the required libraries (wiring pi and u8g2) if it is not found on the target system.

If you are compiling from the Linux platform, you need the Raspberry Pi toolchain (See Project Dependencies). If this is not yet installed in your system then CMake will try and download them for you. If you happen to have the toolchain already installed, then you can pass the existing path to the compile script.

./compile.sh -t <path-of-the-rpi-toolchain>

By default, the cmake builds the binaries with debug information. If you need to compile without debug information then you can specify the build type it in the compile script (release or debug)

./compile.sh -b<release/debug>

The binary output can be found in the following path:

<project_dir>/build/arm/<debug|release>/bin

Supported Features

  • SPI Hardware/Software implementations
  • I2C

Sample Usage

u8g2_t u8g2;

int main() {
    //1) Initialize the Struct containing SPI PIN details
    u8g2_rpi_hal_t u8g2_rpi_hal = {14 /*CLOCK/EN*/, 12 /*MOSI/RW*/, 10 /*CS/RS*/};
    u8g2_rpi_hal_init(u8g2_rpi_hal);

    //2) Pass the byte and gpio callbacks to the display setup procedure
    u8g2_Setup_st7920_s_128x64_f(&u8g2, U8G2_R2, cb_byte_spi_hw, cb_gpio_delay_rpi);

    //3) Initialize the display
    u8g2_InitDisplay(&u8g2);
    u8g2_SetPowerSave(&u8g2, 0);
    u8g2_ClearDisplay(&u8g2);


    //4) Do whatever you want
    u8g2_DrawStr(u8g2, 10, 32, "Hello");

    //Flush the buffer
    u8g2_SendBuffer(u8g2);

    return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.