While we’re waiting for the first interface boards to arrive we’ve been checking out our libraries against the new Raspbian distro.
The latest Raspbian kernel supports I2C and SPI, and today we got all our loopback tests passing. This means we have working Python libraries on Raspbian for GPIO, I2C and SPI.
Raspbian is now the official recommended kernel, so we’re fast approaching the point where a new Pi user can plug in our hardware, install our libraries, run an example and expect everything to work.
At the moment the Python GPIO library needs our gpio-admin library as well as the Python code. Soon we’ll package the two together as a .deb file, which will make things even easier. The gpio-admin and Quick2Wire Python libraries are on github so if you feel like experimenting, clone away and let us know how you get on! The libraries have examples and test code included.
If you want to try out the SPI code, you’ll need to upgrade to the latest Raspbian firmware. The kernel in the current Raspbian image (2012-07-15-wheezy-raspbian) supports I2C but not SPI; you can use Hexxeh’s firmware updater to get a later kernel, which supports both.
There are a couple of other things you’ll need to do: uncomment the two lines in /etc/modprobe.d/raspi-blacklist.conf which stop needed modules from loading, and add a line i2c-dev to /etc/modules to ensure that the relevant i2c module is loaded on boot-up.
Your raspi-blacklist.conf should then look like this:
# don't blacklist spi and i2c by default
# blacklist spi-bcm2708 # blacklist i2c-bcm2708
and /etc/modules should look like this:
# /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. # Parameters can be specified after the module name.
snd-bcm2835 i2c-dev
PS Things are moving fast. If you want to keep up-to-date with what’s happening here at Quick2Wire, sign up for our free newsletter. Just fill in your email at the top of the page and click sign up. We won’t spam you, and you can unsubscribe at any time.

Sounds like good news, but I am a total RPi newbie and have no idea what I’m doing. So how do I edit those lines?
I get the impression that there are a lot of enthusiasts out there all experimenting and doing great things, and chatting among themselves and all assuming that everyone has their level of knowledge. It ain’t necessarily so! Newcomers – even those with good Windows knowledge – don’t know which way is up when getting their first RPi.
@Ben Yes, we realise that a lot of RPi users will be new to Linux. The (very brief) instructions in the post are aimed at experienced users; not only would they need to edit the files we mentioned, but they’d also need to update the firmware on the RPi’s SD card. Most newcomers wont’ feel confident doing that.
We expect that there will be a new Raspbian image out fairly soon; at that point, we’ll be publishing some easy-to-follow tutorials aimed at newcomers.
to edit those lines go to the lxt terminal and write “sudo nano /etc/modprobe.d/raspi-blacklist.conf” (without the quote marks) and then the same for the other filename. ( its always sudo nano filename) in some places sudo isn’t necessary but if you just go nano filename and do a huge amount of editing only to be denied permissions to save changes its a pain.
following as per instructions above from robert(thanks robert for pointing out what no one else did that you can only do this through lxterminal(i was trying to edit via leaf pad and getting access denied…), anyway follwing proceedure in lxterminal two files called raspi-blacklist.conf.save and raspiblacklist.conf.save are created(looking via file manager). does this mean the original files actually got edited? why cant it just overwrite the original file? sorry but im assuming ive done something wrong?? was i suppost to save somehow when in the nano command thing…..Thanks if anyone can help
This is really good stuff! The instructions are clear and it works for me! I know linux, but this was my first go at python. I have been trying to get my RPi to read temperature and humidity from a Honeywell HIH-6131 (to add the data to my remote webcam server). Fortunately Raspian has uvcvideo and watchdog support as well as i2c – so I don’t need my home brew kernel any more :)
So here it is – my first few lines of python! Thanks to you at quick2wire!
#!/usr/bin/env python3
import quick2wire.i2c as i2c
import time
address = 0×27
with i2c.I2CMaster() as bus:
bus.transaction(i2c.writing_bytes(address))
time.sleep(0.05)
read_results = bus.transaction(i2c.reading(address,4))
temp = (64*int(read_results[0][2]) + int(read_results[0][3])/4)/(2**14 – 1) *165 -40
print(round(temp,2))
hum = ((256*int(read_results[0][0]) + int(read_results[0][1]))/(2**14 – 1) % 1) * 100
print(round(hum,2))
So for my second go at Python, I got my RPi to read the HMC6343 digital compass. Still impressed with how easy it is to use the Quick2Wire i2c libraries. Thanks!
#!/usr/bin/env python3
import quick2wire.i2c as i2c
import time
address = 0×19
with i2c.I2CMaster() as bus:
bus.transaction(i2c.writing_bytes(address, 0×72))
time.sleep(0.1)
while True:
bus.transaction(i2c.writing_bytes(address, 0×50))
time.sleep(0.1)
read_results = bus.transaction(i2c.reading(address,6))
heading = (256*int(read_results[0][0]) + int(read_results[0][1]))/10
pitch = (256*int(read_results[0][2]) + int(read_results[0][3]))/10
roll = (256*int(read_results[0][4]) + int(read_results[0][5]))/10
if pitch > 100: pitch = pitch – 6553.5
if roll > 100: roll = roll – 6553.5
print(heading)
print(round(pitch,2))
print(round(roll,2))
time.sleep(0.5)
And also the 2 axis compass HMC6352 :)
#!/usr/bin/env python3
import quick2wire.i2c as i2c
import time
address = 0×21
with i2c.I2CMaster() as bus:
while True:
bus.transaction(i2c.writing_bytes(address, 0×41))
time.sleep(0.1)
read_results = bus.transaction(i2c.reading(address,2))
heading = (256*int(read_results[0][0]) + int(read_results[0][1]))/10
print(heading, end=’ \r’)
time.sleep(0.5)
I get an exception when I try to read from the I2C bus using the new RasPi kernel versions (3.6.x). The command line tool “i2cget” works fine. I get an exception “OverflowError: Python int too large to convert to C long”. Can you help?
Thanks
Andrew.
Same here, I have several python scripts reading the I2C bus. All were working fine until I upgraded to the new kernel 3.6.11. I’ve also performed apt-get dist-upgrade, so I’m not sure if the fault is with the new kernel or with an updated python module. Any help would be greatly appreciated.
Thanks,
Zn
It appears that our API is incompatible with kernel 3.6. We’re not sure why yet. We’re investigating and hope to have a fix soon.
We’ve opened a GitHub issue to let you track our progress on this issue: https://github.com/quick2wire/quick2wire-python-api/issues/20
–Nat
OK, thanks for the update.
Andrew.