Running a circular display on a Raspberry Pi
This page is the hands on guide for getting the display running, for the background you can find this in the blog post.
This page describes setting up a C library to do low level I/O on a Raspberry Pi and then writing a control application in Python to use the functions. In particular this is for the Round SPI display.
- Install BCM low level library
- Create a custom C library with the functions needed
- Write a Python control application to use the C library
I will go through the basics first so you can see if it works for you, then will go over the details of the code.
Installing the BCM low level library
Note: You only need this stage if you are planning to (re)compile the custom C Library yourself.
Download the BCM package from here but if you want to find out more about this package, the main page is here. It’s well written and has decent documentation, so if you want to do something new, this is a good place to start.
With the code downloaded as .gz file, extract this to the underlying .tar file (I did this in windows after downloading). The .tar file can then be extracted with:
tar -xf bcm2835-1.68.tar
sudo make install
This has the library installed and the relevant header files.
Create a custom C library with the functions needed
Here is where the majority of my time was spent as I had to write and debug the various functions needed. Outcome however are the 3 files:
- The bcm_direct_c2py.c main C file
- The bcm_direct_c2py.h header file, used for both the C and Python applications
- The bcm_direct_c2py.so the standalone shared library
If you are just going to use the code as it is, then you just need the .h and .so files.
If you want to re-compile and possible edit the code yourself, then get the .c and .h files.
To recompile the line needed is:
gcc -shared -o bcm_direct_c2py.so -fPIC bcm_direct_c2py.c -l bcm2835
This will create you the new .so file.
Write a Python control application to use the C library
For reference I have 2 sample Python applications, one doing a few screen updates and some basic line drawing called test.py and a simple clock.py application. There is also 2 support files a book image for the test.py application and the watch face for the clock.py application.
Before you run this, you will need to connect the Pi to the display, for the code as written, wiring needed is:
|Display Connection Name||Raspberry Pi pin number||Raspberry Pi pin name|
|GND||25 (original 9)||GND|
|VCC||17 (original 1)||3.3V|
|SCL||23||GPIO 11 / SPIO SCLK|
|SDA||19||GPIO 10 / SPIO MOSI|
|CS||24||GPIO 8 / SPIO CE0|
Note I have updated the pin numbers above as these new values keep all the wiring in one area of the Pi’s connector, and hence makes for a tidier connection.
Now we can copy these files to the relevant directory on your Pi and run them with:
sudo python3 test.py
sudo python3 clock.py
Note you do need to run as root (sudo) as these rely on the low level driver and that doesn’t seem to initialise unless run as root.
That’s it for the basic setup guide.
Next steps, adding better line and graphics primitives to the C code and then tidying the code for general use.
Details of my exploration into 2D line drawing can be found here:
As ever, any questions or think of any specific functions that would be helpful then drop me a line or add a comment below and I will try to help.
Get new content delivered directly to your inbox.