Idea
My first little project with the Raspberry Pi Pico is to control a Electronic Assembly DOGM Graphic display. I have already adopted an arduino library for the display and used it in several projects. So I know the display and how to control it quite well. This project shouldn't be to complicated. Its purpose is more to get to know the Pico and how to program it.
Hardware
For previous projects I have already made an Arduino MKR shield with the display which I described here: NFC-Badge - Update your badge with your smartphone - Design data of the HMI shield The design data of the project is available on github: https://github.com/generationmake/ArduHMIShield
Additionally I have design an adapter to use Arduino MKR shields with the Pico: PicoMKRAdapter - connect Arduino MKR Shields to Raspberry Pi Pico
So the hardware was no big deal, just stacking the boards ontop of each other.
Software
I really like the Arduino ecosystem where there are lots of third party libraries available to control every peace of hardware you could imagine.
It would be nice if this is also the case with the Pico.
Unfortunately this seems not to be so at the moment. There exists a document how to get started ( https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf ) which shows you how to create your own projects. But as far as I have seen there is no concept how to use third party libraries.
The only way is to make your own directory along-side the examples directory and place all your project files in this directory.
I named my project DogGraphicDisplayPico. This screenshot shows where the project directory is located. If you use a raspberry pi as build system it should be in /home/pi/pico
The files are all in one directory and glued together and connected to the pico sdk by a cmake file.
This project is highly based on my library for the Arduino https://github.com/generationmake/DogGraphicDisplay
The adoption for the pico was quite simple. Just replace the functions to access the GPIO pins. So change from digitalWrite() to gpio_put() and the same for the hardware SPI access.
The programm itself doesn't do very much. It just displays a text and scrolls it to the left.
Source code
The main program is quite straight forward. Unlike the Arduino sketches it doesn't have a setup and a loop function but only one main function and the programm stays in an infinite loop there.
#include <stdio.h> #include "pico/stdlib.h" #include "hardware/gpio.h" #include "pico/binary_info.h" #include "DogGraphicDisplay.hpp" #include "ubuntumono_b_16.h" const uint LED_PIN=25; const uint BACKLIGHT_PIN=20; DogGraphicDisplay DOG; int main(){ bi_decl(bi_program_description("DogGraphicDisplayPico.")); stdio_init_all(); gpio_init(LED_PIN); gpio_set_dir(LED_PIN,GPIO_OUT); gpio_init(BACKLIGHT_PIN); gpio_set_dir(BACKLIGHT_PIN,GPIO_OUT); gpio_put(BACKLIGHT_PIN,1); // DOG.begin(14,7,6,0,1,DOGM128); //CS = 14, 7,6= use Software SPI, A0 = 0, RESET = 1, EA DOGM128-6 (=128x64 dots) DOG.begin(14,0,0,0,1,DOGM128); //CS = 14, 0,0= use Hardware SPI, A0 = 0, RESET = 1, EA DOGM128-6 (=128x64 dots) DOG.clear(); //clear whole display DOG.string(0,0,UBUNTUMONO_B_16,"RaspberryPi Pico", ALIGN_CENTER); // print text in line 0 at position center static int offset=DOG.display_width(); // static variable with the size of the display, so text starts at the right border while(1){ DOG.string(offset,3,UBUNTUMONO_B_16,"Hello to the scrolling World on Pico!"); // print "Hello World" in line 3 at position offset offset--; // decrasye offset so text moves to the left if(offset<-292) offset=DOG.display_width(); //our text is 232 pixels wide so restart at this value gpio_put(LED_PIN,0); sleep_ms(20); gpio_put(LED_PIN,1); sleep_ms(40); } }
The complete source code with the make file is available on github: https://github.com/generationmake/DogGraphicDisplayPico
Build process and programming
The build process is also very straight forward. Just create a build directory and generate the make files there.
mkdir build cd build cmake .. make
This generates a file DogGraphicDisplayPico.uf2 (amongst others). Then connect the Pico to your computer in the bootloader mode by holding the BOOTSEL switch while plugging in. The Pico will appear as a mass storage device. Just copy DogGraphicDisplayPico.uf2 to this device and it will be programmed and you are ready to go.
Video
Top Comments