Jump to content

Recommended Posts

Posted

I'm working on a Duo project that needs SPI and this is how I configured and tested it without the mini shield.

 

Requirements:

  • NanoPi Duo with test Armbian image
  • 1 female to female jumper wire

Enable SPI on boot:

  • sudo nano /boot/armbianEnv.txt
  • Add spi-spidev to overlays=
  • Add line param_spidev_spi_bus=1
  • sudo reboot

If everything worked you should have /dev/spidev1.0. Check with ls /dev/spi*. Now we can test with a C program:

cd
wget http://www.raspibo.org/renzo/spidev_test.c 
gcc -o spidev_test spidev_test.c
sudo ./spidev_test -D /dev/spidev1.0

spi device: /dev/spidev1.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

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 00 00 00 00 
00 00

shutdown now -h then wire up MO and MI pins with jumper to create loop back and power up

sudo ./spidev_test -D /dev/spidev1.0

spi device: /dev/spidev32766.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

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 
DE AD BE EF BA AD 
F0 0D

OK, let's try some Python now:

sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-pip
sudo -H pip install --upgrade pip setuptools
sudo -H pip install --upgrade spidev
nano spitest.py

import spidev

input = [1 ,2 ,3, 4, 5]
print "input: %s" % input
spi = spidev.SpiDev()
spi.open(1,0)
output = spi.xfer2(input)
print "output: %s" % output

Save code and run program:

sudo python spitest.py

input: [1, 2, 3, 4, 5]
output: [1, 2, 3, 4, 5]

 

 

IMG_20171220_185220.jpg

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines