We've updated our popular "Raspberry Pi SPI and I2C Tutorial" with some Python examples.
One of our more popular tutorials shows how to use the SPI and I2C buses available on the Raspberry Pi GPIO header. It seems that people are interested in connecting hardware to the Raspberry Pi, which is definitely a good use for the tiny computer.
The original tutorial showed how to use the WiringPi library with C++ to talk to a SPI 7-segment display and an I2C digital-to-analog converter (DAC). While I do thoroughly enjoy C/C++, I figured giving Python examples alongside the C/C++ ones would give readers more options.
As might be expected, the C/C++ examples are faster and more efficient. However, since Python seems to be a popular way for writing quick scripts or prototyping, knowing how to use SPI and I2C protocols might help with your next Raspberry Pi project. The updated tutorial can be found here:
I used the smbus Python package in the tutorial, as that seems to be the de facto package for communicating over an I2C bus. However, it is lacking some of the lower level I2C functions, such as clock stretching, which limits its usefulness with some sensors that require it (like the Si7021). If you can recommend any I2C Python packages that are easy to use and can handle clock stretching, please let us know in the comments!
Hi Shawn!
I apologize that I don't have time at the moment to read the updated tutorial in detail, but it looks interesting. One thought, though, that came to mind, is a "spin-off" from the "Bark back" project for those of us who don't have a canine sharing our homes: have some motion detectors (maybe including the door bell switch?) to play recorded barks from actual dogs... might scare off someone who has "malitious intent"... ;-)
Anyway, thanks for the efforts! I'm hoping it won't be too long before I have time to tinker a bit more with I2C and/or SPI from a Pi.
No worries, and I definitely appreciate the time you take to look at the tutorials! There really wasn't much added to the tutorial, as it's been around for a while. All I did was add a couple of Python examples to give people options when it comes to using SPI and I2C on the Pi.