Now that I have a rudimentary I²C implementation up and running on my PIC, it’s time to figure out how I’ll control it from code running on a Raspberry Pi. Which means it’s time for this novice to go bumping around in the dark looking for a place to start.
The first thing I looked at was the Raspberry Pi Sense HAT. I bought one along with my Raspberry Pi and it was a fun little thing to play with, learning some basic Python along the way. The Sense HAT communicates with the Pi via I²C. I found the Github repository where the source code for the SenseHat module is published, but my Python knowledge is too thin to trace to their low-level I²C communications code.
The next thing I thought of was the Adafruit PWM/Servo HAT, which I also purchased for experimentation. Looking at that HAT’s tutorial and the Adafruit I²C tutorial, I found their I²C library which worked well enough for me to do rough tests of my I²C code running on the PIC. Adafruit code seem to be Python 2 specific with no Python 3 version. This is not an immediate problem because I intend to use ROS which is also on Python 2, but I wanted something with broader (more than Adafruit) support and more future-proofing.
On the logic of “If there’s something on Adafruit, there’s probably also something on Sparkfun.” I found the SparkFun Raspberry Pi I²C tutorial which uses the wiringPi library to access the Pi’s GPIO pins. This library looks pretty popular, and it includes an I²C library. The downside is that wiringPi is focused on C programs. A Python interface layer exists but not maintained by the owner.
I felt there must be another way since the Raspberry Pi is focused on education and making technology accessible. A little more web searching paid off: The pigpio library. It is the default option for GPIO control in Raspberry Pi documentation. Built into recent builds of Raspbian so it is a part of the stock Raspberry Pi. I can interface with it in C, Python 2, Python 3, or even the command line utility. Source code is public if I ever wanted to dig deeper.
This looks like the best option. I’ll start using it and see how far I get.