Enabling an Industrial I/O Driver on Raspberry Pi 3 running Arch Linux ARM
MPU9250 from TDK is a three in one Gyro + Accelerometer + Compass sensor with an I²C interface. Mainline Linux kernel has the source code for it's driver which reads values from the sensor via I²C and exposes it via the filesystem using the Industrial I/O subsystem. Arch Linux ARM for Raspberry Pi does not come with the driver for this pre-compiled and enabled. Here is how to compile and enable the driver on Raspberry Pi 3 Model B.
and a USB-Serial widget to access console over serial
Connections
Buy the MPU9250 Widget from Amazon and hook it up to your Raspberry Pi as per the table
Preparations
- Prepare and boot Arch Linux ARM from SD Card: instructions are here.
- Connect the Raspberry Pi to your home network using an ethernet cable.
- Look up the DHCP assigned IP address from your router’s configuration web interface, it will show as a new device named alarmpi.
-
Gain access to the console over SSH using
PuTTY or
MobaXterm
or physically using keyboard/mouse/monitor.
Login: alarm and Password: alarm - While following the instructions below, switch to root user whenever required using:
- su root
- Password: root
Enable Console over USB-Serial [Optional]
Follow instructions over at https://gist.github.com/yeokm1/d6c3ca927919c61257cd
Install required packages on Arch Linux ARM running on RPi3B
- pacman-key --init
- pacman-key --populate archlinuxarm
- pacman -Syu
- pacman -S curl bash ca-certificates nano i2c-tools jq iio-utils
- pacman -S base-devel
- pacman -S dtc git
- pacman -S linux-raspberrypi-headers
- pacman -S python python-pip
Enable I²C on Raspberry Pi 3 Model B running Arch Linux ARM
- su root
- nano /etc/modules-load.d/raspberrypi.conf
- Append:
- i2c-dev
- Save and Reboot
- nano /boot/config.txt
- Append:
- dtparam=i2c=on
- Save and Reboot
- Test (0x68 is MPU9250):
Python Library for reading from MPU9250 over I²C
- Install python packages (Latest version from its git repository, replace the version numbers with latest one)
-
python -m pip install
git+https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python.git@78e4da28e176a07cc1c22c2f61a5be7ffe6c2c28
- Clone the git repository to fetch the example code
-
git clone
https://github.com/FaBoPlatform/FaBo9AXIS-MPU9250-Python.git
-
First test in text mode using example from FaBo9AXIS-MPU9250-Python repo
(This uses raw I2C bus without the need for MPU9250 Industrial I/O Driver):
Enabling MPU9250 Industrial I/O interface on ArchLinux running on Raspberry Pi 3
- Fetch (from mainline kernel repository) the latest sources of inv-mpu6050 which has support for MPU9250 through shallow clone/sparse checkout, execute the following commands while in /root:
- su root
- mkdir linux_main_src
- cd linux_main_src
- git init
- git remote add origin https://github.com/torvalds/linux.git
- git config core.sparsecheckout true
- echo "drivers/iio/*" >> .git/info/sparse-checkout
- git pull --depth=3 origin master
- Create the Makefile for compiling the driver:
- Get into /root/linux_main_src/drivers/iio/imu/inv_mpu6050
- And modify the Makefile present there for the inv_mpu6080 driver to compile on and for Raspberry Pi 3 platform (lines in blue will be present already, lines in red are the ones that need to be appended, make sure to use a single tab and not spaces at the beginning of the lines below all: and clean:):
-
Makefile:
-
Change to /root
cd /root
-
Create an device tree overlay source file for MPU9250:
nano /root/mpu9250.dts
-
Add the contents and save:
-
Compile the device tree source and place it in overlays folder:
dtc -I dts -O dtb -o /boot/overlays/mpu9250.dtbo -b 0 -@ /root/mpu9250.dts
-
Update /boot/config.txt and add
the following lines to it, save it and reboot:
dtoverlay=mpu9250
-
Read the Accelerometer and Magnetometer values like so:
Python Bar Graph with Industrial I/O Driver
- Install python packages (Latest versions from its git repository, replace the version number with latest one)
- pacman -S libjpeg
-
python -m pip install
git+https://github.com/peterbrittain/asciimatics.git@476159c95c5b6e34a782ea97503785ad95683805
- Clone the git repository to fetch the example code
-
git clone https://github.com/peterbrittain/asciimatics.git
- Then run following code using python for live bar graph:
Enable WiFi on your Raspberry Pi 3 Running Arch Linux ARM [Optional]
- su root
- sudo pacman -S netctl
- nano /etc/netctl/wireless-home
-
Copy and paste the following contents and modify the SSID and passphrase to
match your WiFi network
- netctl enable /etc/netctl/wireless-home
- reboot
hello sir, please I have a problem on my raspberry I'm trying to enable iio but when I enter into sys/buy/iio/devices I didn't get iio file inside devices please help me thanks .
ReplyDeleteHi,
ReplyDeleteI did the same you for dtover mpu9250 on raspberry pi4, but I could not find the path /sys/bus/iio/devices/iio\:device1
what linux version are you using? I'm user version 5.15.26
Thanks