Sensors for the pinephone
Draft: Sensors for the pinephone with the sensors stk3310, mpu6050 and lis3mdl.
Please note that not all the pinephone starting from 2021 have the lis3mdl sensor.
This topic tries to give all the information you need if you want to work on the pinephone sensors.
Please note that in the worst case, your pinephone could crash and you need to reinstall the os on your phone and the data will be lost. Therefore use a separate sd card for development.
Using the sensors in combination with bash to get information:
This gives the result: lis3mdl
To set the sensor properties in bash you have to be root, hence:
echo 2 > /sys/bus/iio/devices/iio\:device3/sampling_frequency
This will set the sampling frequency to 2 Hz.
Sensorfw is started and stopped with upstart.
Restarting the service could be done with:
sudo service sensorfw restart
The log of sensorfw is given in /var/log/upstart/sensorfw.log
To remove the log before you restart it:
sudo rm /var/log/upstart/sensorfw.log*
Reading the log can be done with you favorite command line reader:
sudo cat /var/log/upstart/sensorfw.log
Location of the sensorfw upstart file:
To make the output more verbose, switch from
description "Sensorfw Services" start on started dbus respawn exec /usr/sbin/sensorfwd --device-info --log-level=test --no-magnetometer-bg-calibration
Location configuration file:
If the configuration file is updating correctly after a change in the file is not completely known. Investigation point.
[plugins] accelerometeradaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor alsadaptor = iiosensorsadaptor magnetometeradaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor proximityadaptor = iiosensorsadaptor [accelerometer] input_match=mpu6050 default_interval=500 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [als] input_match=stk3310 intervals = "200=>2000" default_interval=500 [gyroscope] input_match=mpu6050 default_interval=500 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [magnetometer] input_match=lis3mdl intervals = "12.5,25,50,100,200,333.3,500,1000" default_interval=500 #scale_coefficient = 1 needs_calibration = 1 #dataranges = "-4096=>4096" #interval_compensation = 16 ???? calibration_rate = 12.5 calibration_timeout = 60000 [proximity] input_match=stk3310 intervals = "200=>2000" default_interval=500 threshold=19
clone the git repository of you project which you would like to build
git clone https://github.com/wouter182/sensorfw.git
Go into the project directory
Build the package
crossbuilder --architecture=arm64 build
Create the deb package and deploy it on the pinephone
crossbuilder --architecture=arm64 --ssh=<Your IP> deploy
Please make sure that you prevent the automatic lock of the home screen. This prevents the phone going into sleep. If the phone is in sleep mode, the wifi connection is not stable anymore (this to reduce energy consumption).
Restart sensorfw or reboot the phone and check your work (not completely sure if this works correct with loading of the sensorfw config file)
For building the SensorStatus app:
Clone the sensorstatus repo from wouter182.
git clone https://gitlab.com/wouter182/SensorsStatus.git
Go inside the sensorstatus folder
clickable --ssh <Your IP>, this will generate the app in click format and will start it automatically.
clickable log --ssh <Your IP>you can check the log files from the app. In case of a crash or to check for errors.
Setting up ssh on the pinephone:
Setting up crossbuilder:
Download the crossbuilder script:
git clone https://github.com/wouter182/crossbuilder
For further instruction see https://docs.ubports.com/en/latest/systemdev/testing-locally.html
Read only rootfs:
sudo mount / -o remount,rwto make the rootfs temporary read and writable.
Note that after an system upgrade, the changed files will be overwritten.
Testing a merge request:
Testing a merge request can be done with ubports-qa, see https://docs.ubports.com/en/latest/systemdev/uploading-changes.html
Setting up clickable:
Links with the information you probably need.
Crossbuilder in combination with ssh and automatic delploy:
Sensorfw for the pinephone:
Please take note that the pinpehone uses the xenial-_edge repository at the moment.
Configuration file for sensorfw from deviceinfo:
Sensorfw plugin in Qt:
Information about the iio (industrial input and output) sensors in combination with linux:
Magnetometer driver in linux for reference:
Upstream sensorfw if you liked the gitlab search function like me:
QML information for sensors:
To be continued...
Thanks for the detailed instructions.
I was able to succesfully build Sensorstatus with clickable and deploy it via ssh. I cannot say the same about sensorfw and crossbuilder though.
I can build and generate the deb files with
but if I attempt to deploy them with the
--ssh=argument it fails. It asks for the ssh password several times at the beginning, then it builds everything, and it will ask for the password again at the end, several times. Always fails to accept it.
I have also tried to set up my ssh keys first. This prevents the password prompts, giving instead a wrong password error automatically at the end of the build process.
If not, perhaps I can instead deploy the deb files manually...
The recommended way is to use click packages and not .deb
The easiest way is to use clickable which will help to deploy it to the phone.
BTW the password for SSH is not enabled, setting the key was the right thing to do.
But the error is strange ?!
The deb packages are the recommended way for the middleware. Sensorfw is the software which connects the linux drivers of the sensors to Qt and does the calibration.
In this way all apps which use Qt could make use of the sensors.
For the SensorsStatus app clickable is the way to go.