Accessing I2C and SPI from userland

December 17, 2016 — 3 Comments

Over years I accumulated fair number of devices I have no real use for. I ordered them either on impulse, or to add couple of $$$ to the bill to get free delivery. So in order to get at least some value from those purchases I put together goofy demo using two of such devices: I2C temperature sensor breakout from Sparkfun and 128×32 SPI OLED display from Adafruit.

I wrote two libraries to talk to TMP102 (chip in which temp sensor is based) over I2C and to SSD1306(OLED display chip) over SPI and several demos simple enough to put together in one day but flashy enough to excite my inner child and bring fond memories of MSDOS days. The SPI chip requires this fix in kernel. Userland SPI API provides only very basic functionality but luckily it was enough to talk to SSD1306.

TMP102 is I2C-only device but SSD1306 uses two signals in addition to standard SPI ones and GND/VCC: Data/Command switch and Reset. I connected them to GPIO pins 23 and 24 on my RPi. SSD1306 code is based on Adafruit’s Python library and supports only one model so far, but can easily be extended to support all three of them.

Code: https://github.com/gonzoua/freebsd-embedded-demos
Video:

gonzo

Posts

3 responses to Accessing I2C and SPI from userland

  1. Hi Gonzo
    It’s nice to see how the development of freebsd for Rpi advances.
    I have installed Freebsd STABLE (11.0-STABLE FreeBSD 11.0-STABLE # 0 r312817) but I can not see under / dev the device for SPI.
    I need to do something else?
    Regards

    • Unfortunately spidev is not available as a module, you need to compile custom kernel to use it. I’ll look into adding separate module for it though.

  2. thanks for your answer
    It would be great if you could publish it.
    Meanwhile I’ll try to compile a custom kernel by adding spigen support and see what happens.
    Best regards

Leave a Reply

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>