Using a MCP3008 via SPI
Last week I connected a MCP3008 ADC to my omega2 via the SPI pins.
I thought I could read data but it was in fact rubbish.
Reading a tutorial on adafruit (https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi/script) and the mcp documentation (http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf), it seems the read procedure is simple : I just have to send a 4 bit word (1100) to ask for a reading on channel 0, and the MCP returns 10 bits.
However, using the python lib I have to give a one byte address during the read, which I assume would be the command word 1100 with a 0 padding, so 11000000. The value I read next is quite inconsistent, even with a fixed input voltage.
Has anyone any clue of what I am doing wrong ?
Read this thread HERE
Oh ok, thanks.
Everytime I try to use my omega 2 for something, I first need to wait for a fimware update.
Guess I'll have to build my own LEDE or something... Too bad, I needed the wifi
Is it possible to user other GPIO pins to bit bang the SPI protocol ?
@Pierre-Rossinès doing bit-banged SPI I/O would mean rebuilding the firmware image anyway, so you might as well just build the firmware with the patch (which is what I did). I'm building LEDE trunk with the addition of the Onion feed; the one real trick is to include the RAlink wifi driver from the onion feed and deselect all of the LEDE trunk wifi drivers. I can send you my SPI patch (derived from berniwa's patch and similar to @WereCatf) and .config file if you're interested.
@Dana-Myers114 That would be nice, thanks !
Is it not possible to do bit banging using python ? This is what is done on the RPi in the adafruit tutorial link I gave. It doesn't seem a very clean way to do it, but it works pretty well on the RPi.
@Dana-Myers114 As far as I know, there is already a kernel-module included in the Omega2-firmware for bitbanged SPI, called kmod-spi-gpio-custom or similar. THere's no need for rebuilding the image.
@Pierre-Rossinès If my memory serves right and kmod-spi-gpio-custom is, indeed, compiled for the official firmware these two links should get you going with bit-banged SPI: https://randomcoderdude.wordpress.com/2013/08/15/spi-over-gpio-in-openwrt/ https://dev.openwrt.org/browser/trunk/package/kernel/spi-gpio-custom/src/spi-gpio-custom.c
@WereCatf the only SPI package in b160:
unless I'm mistaken.
I suppose one could install it with opkg.
opkg find "kmod-spi-gpio*"
@WereCatf yeah I suppose one could install it and it might even work