Monday, December 21, 2020

LCD Display on RaspberryPI with Objective-C

Since many years there are ways to display Data on the Raspberry PI by using small LCD Displays connected to the GPIO pins. Most of these small projects however use Python, an interpreted language which I dislike. There are C projects using the wiringpi library and which are inspired by Arduino versions, I have looked at this nice work by binerry which concentrates on the PCD8544 (aka known as the Nokia 3310 display!).

I studied it but wanted to use the Objective-C language which I like much more and which will enable me in the near future to leverage existing Kits. I had some doubts about speed and interoperability, so I started by "wrapping" the C functions with an Objective-C class. The proof of concept worked fine, so I went on to write more native library.

SPIDisplayKit is thus born - requiring GNUstep Base only and providing an AppKit inspired interface to the Display - e.g. Coordinates to the methods are passed with a struct, similar to NSSize or NSRect, but simpler, since they are direct integer without any transformation, scaling or other support and thus eliminating the need of floating point:

Look in this video the result running on an original Raspberry PI 1:

Objective-C + GNUstep + Raspberry PI + PCD8544, the code of this trivial Pong example is full Objective-C and very easy too!

This opens the road to a lot of nice examples, since Data Management and Connection Management supplied by GNUstep Foundation is so convenient, but the speed of Objective-C (here with the GNU GCC runtime) are more than enough!

No comments: