Accessing I2C and SPI from userland

December 17, 2016 — 9 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.




9 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?

    • 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

  3. Greetings,

    I have a python library that requires spidev, please enlighten me how can I have this device on FreeBSD 11.

    thx in advance

    • spigen module hasn’t been merged to FreeBSD 11 yet, so you have two options: either recompile kernel with “device spigen” or copy sys/modules/spigen to FreeBSD-11 tree and build module.

      I’ll look into backporting spigen module to 11

      • Hi,

        Sorry for the late response.

        Cool, I will try to compile a new Kernel.

        If you can please keep us posted with porting the spigen module


  4. Hi,

    I have compiled the kernel with spigen device and I am still having issues to use max7219 lib

    All examples are shown for Linux, is it possible to make this working on FreeBSD ?


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=""> <s> <strike> <strong>