Close

Testing and calibration of accelerometer to angle conversion

A project log for Cheap underwater tilt current sensor.

Cheap (<$100) underwater current sensor that can be deployed at 70ft depth. Your thoughts, comments and advice are very welcome here!

max-kviatkouskiMax Kviatkouski 05/20/2018 at 07:310 Comments

The only angle I think I will be really interested in is the angle between current meter housing and true vertical (gravity force line). Z-axis on pyboard is one perpendicular to the surface of the board. I'll have to mount the board like thi


This type of mount has additional benefit that angles between Z and vertical less than 90 degrees mean left tilt, 90 to 180 degrees mean right tilt. That should be sufficient since I assume there is a line that current follows in either direction. It is possible that some downwell will occur pushing water in offshore direction. It will be possible to identify that later.

I'm going to log raw values of accelerometer. Two reasons to do that:

- No need to slow down logging and increase power consumption by doing computation that can be done afterwards

- Raw data will allow to compute any types of derived metrics: z-angle, other angles, etc.

I've already wrote some code that transforms raw accelerometer values into Z-angle. I've used pretty known formula for the angle between two vectors described here: https://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

Python numpy module is capable of operating with vectors.

Also I finally was able to write some utility code that would let me:

1. Upload python file into PyBoard and start executing it

2. Listen to PyBoard output and process that output in "live" mode

I need it to simplify calibration of PyBoard (to proof that code and formulas result in proper angle calculation).

For that I used ampy Python module from Adafruit: https://github.com/adafruit/ampy (cannot say it's extremely mature but it's certainly helpful and is certainly better than nothing).

Few tips for those who might need to do similar things:

- If you cannot connect to your PyBoard using ampy check if any process is using your PyBoard:

$ fuser /dev/ttyACM0

/dev/ttyACM0:        10980

In this case fuser tells that a process with PID 10980 is using my PyBoard. You can kill it by executing kill 10980 (that works in Ubuntu, not in Windows)

- Out of the box Pyboard class module from ampy doesn't allow you to upload a file for execution and start listening for PyBoard output. You can check sources and either submit a patch for them or read a file into a string and send for execution (you can see example here: https://github.com/max-kviatkouski/pyboard-current-meter-logger/blob/master/log-processing/calibration-util.py)

In the end a bit of video how it works all together now. I can submit file into pyboard to start printing accelerometer values and other python script will listen to the output, convert values into angles and print them on screen.

Discussions