This is an out of tree kernel driver for Microchip's MCP3422, MCP3423, MCP3424 high resolution ADC.
This driver supports only kernel release less than 3.12, for 3.13 onward this driver is in kernel tree.
To use the driver on Linux <= 3.11 stay on master branch, if you have a kernel >= 3.12 switch to 3.12 branch.
This driver can be used on Raspberry Pi with ADC Pi v2 or DeltaSigma Pi extensions boards from Abelectronics.
-
Download this repository
~/$ git clone https://github.com/angeloc/linux_iio_mcp3422.git
-
Download latest 3.10 kernel for the Raspberry Pi from here 3.10.y and unzip it somewhere.
-
Make a new default config for the Raspberry Pi:
~/linux-rpi-3.10.y$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make bcmrpi_defconfig
-
Enable IIO subsystem:
~/linux-rpi-3.10.y$ ./scripts/config --enable I2C; \ ./scripts/config --enable IIO; \ ./scripts/config --enable I2C_BCM2708; \ ./scripts/config --set-val I2C_BCM2708_BAUDRATE 400000; \ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make prepare scripts
Press Enter for each unsetted option until the kernel begins to compile.
-
Recompile your kernel:
~/linux-rpi-3.10.y$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make
-
Replace the raspberry pi kernel /media/sdcardp1/kernel.img with your new kernel file arch/arm/boot/Image.
-
Install kernel modules you compiled with:
~/linux_iio_mcp3422$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make modules_install INSTALL_MOD_PATH=/media/sdcardp2/
-
Compile mcp3422 driver:
~/linux_iio_mcp3422$ KERNELDIR=~/linux-rpi-3.10.y ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make
-
Copy mcp3422.ko file into /media/sdcardp2/lib/modules/3.10.y/drivers/iio/adc
-
Boot your Raspberry Pi and enable your MCP3422 device (replace 0x68 with the address of your chip on the bus):
~/# insmod /lib/modules/3.10.y/drivers/iio/adc/mcp3422.ko ~/# echo mcp3424 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
-
Use your new device reading files in:
~/# cd /sys/bus/i2c/devices/0-0068/iio\:device0/ ~/iio:device0# ls in_voltage0_raw in_voltage0_scale in_voltage1_raw in_voltage1_scale in_voltage2_raw in_voltage2_scale in_voltage3_raw in_voltage3_scale in_voltage_sampling_frequency in_voltage_scale_available ~/iio:device0# cat in_voltage0_raw 2047 ~/iio:device0# cat in_voltage0_scale 0.001000000