Orange Pi I2C & SPI Setup

08/27/18

Categories: Computers Tags: Orange Pi

~/contents

Of the two, SPI is faster but more troublesome to set up.

Enabling I2C

Enable the hardware through config:

sudo armbian-config

Info on i2cTools.

sudo apt-get install python-smbus python-dev
sudo apt-get install i2c-tools
sudo apt-get install libi2c-dev

Update /etc/modules to include the following line:

i2c-dev

Test like so:

sudo i2cdetect -y 0
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00: – – – – – – – – – – – – – 10: – – – – – – – – – – – – – – – – 20: – – – – – – – – – – – – – – – – 30: – – – – – – – – 38 – – – – – – – 40: – – – – – – – – – – – – – – – – 50: – – – – – – – – – – – – – – – – 60: – – – – – – – – – – – – – – – – 70: – – – – – – – –

Enabling SPI

Enable the hardware through config:

sudo armbian-config

Update /etc/modules to include the following line:

spi-dev

Update /boot/armbianEnv.txt to include the following:

param_spidev_spi_bus=0
param_spidev_max_freq=100000000

You may need to update the device-tree overlay as well. (Info for H5.) [I don’t think I needed this for OP0 which is H2, just the OP PC2] Additionally, if you reset you’ll want to check and make sure the changes are still there.

The commands to verify the SPI bus should return output like:

$ ls /dev/spi*
/dev/spidev0.0

$ ls -l /dev/spi* crw——- 1 root root 153, 0 Aug 25 11:05 /dev/spidev0.0

$ lsmod | grep -i spi spidev 20480 0

If you are still having issues, you can perform a loopback test with spidev-test. I was never able to get past the spidev-test on either of my boards, the Orange Pi Zero throws an “No such file or directory/abort” error message, presumably because the status LED is mapped to PA15. The Orange Pi PC 2 always returns -null- and I was never sure if there was an issue with the pins/board or with spidev-test.

spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D | ......@....�..................�.
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................................

RPi users can use pigpiod to test MISO/MOSI, but I did not find something similar for OP. (This was around the time I decided my next board would definitely be a Raspberry Pi, haha.)