Exodus
Projects · motion

Measuring the sea
with one chip.

A nine-axis sensor the size of a postage stamp, wired to a Raspberry Pi with four wires. It knows how far the boat is leaning, how hard she's pitching, and — the hard one — how big the waves are.

Six ways a boat moves

And why only three of them are usually measured

A floating thing has six degrees of freedom: three rotations and three translations. Most boats measure the rotations and ignore the rest.

MotionWhat it isMeasured aboard?
Roll (heel)Leaning side to side Yes
PitchBow up, bow down Yes
YawSwinging left and right — your heading Yes
HeaveRising and falling bodily on the water Nothing measured it
SwaySliding sideways No
SurgeSliding forward and back No

The autopilot's own motion sensor — a Raymarine EV-1 in this case — reports leaning and turning, because that is all an autopilot needs. It says nothing at all about heave.

Which is a shame, because heave is the sea. Roll tells you how the boat is reacting. Heave tells you what the water is actually doing underneath her.

The chip

BNO085, four wires, about the price of a meal out

A BNO085 is a nine-axis sensor: a three-axis accelerometer, a three-axis gyroscope and a three-axis magnetometer, with a small processor of its own that fuses all three into an orientation.

That on-board fusion is the reason to pay for this one rather than a bare accelerometer. Raw sensors drift and lie in predictable ways — a gyro drifts over time, an accelerometer can't tell real acceleration from gravity, a magnetometer is confused by any lump of steel. Fusing them cancels most of it, and the chip does that work itself so the Pi doesn't have to.

It connects over I2C: power, ground, and two data wires. That's the whole installation.

Heel and pitch are the easy part

Orientation comes straight out of the chip. Convert it to roll and pitch, publish it to Signal K, and every screen on the boat can show how far over she is.

It is immediately more useful than it sounds. A live heel angle tells you whether you're overpowered before the helm does. A logged one tells you what she was doing at three in the morning when you were asleep.

Heave is the hard one

Getting a distance out of an accelerometer

Nothing measures vertical position directly. What the chip gives you is vertical acceleration, and acceleration is two steps away from a distance.

Step one: work out which way is up

The chip reports linear acceleration — acceleration with gravity already removed — but it reports it in its own frame of reference, which tilts and rolls with the boat. That's no good: we want the world's vertical, not the boat's.

So the reading is rotated by the chip's own orientation into the world frame, where the Z axis genuinely points at the sky. Now Z is vertical acceleration regardless of what the boat is doing underneath it.

A detail that saved the whole project. The chip offers several fusion modes. The obvious one uses the magnetometer, and where this sensor is mounted the magnetic field reads about 76 microtesla — well above Earth's natural 25 to 65. Something nearby is magnetic.

That would poison any compass-referenced heading. But heave doesn't need a compass. It only needs to know which way is down, and that comes from gravity. So it uses the game rotation vector — gyroscope and gravity only, magnetometer ignored. The interference stops mattering entirely.

There's a bonus: it also means the mounting angle doesn't matter. The maths takes it out. You don't have to get the chip perfectly level, which on a boat is just as well.

Step two: integrate twice, and fight the drift

Integrate acceleration once and you get velocity. Integrate again and you get displacement — the actual up-and-down distance, in metres.

The catch is that integration accumulates error. The tiniest constant offset in the acceleration becomes a steadily growing velocity, which becomes a displacement that climbs towards infinity. Left alone, the boat appears to slowly ascend into orbit.

The fix is a high-pass filter at each stage. Waves are a few seconds long; drift is a slow creep. Filter out everything slower than a wave and the drift goes with it, leaving the oscillation you actually wanted.

That is the entire trick: rotate into the world frame, double-integrate, high-pass twice. Everything else is bookkeeping.

From heave to sea state

What oceanographers actually quote

Raw heave is a wiggly line. To say anything useful you have to turn a few minutes of that wiggle into numbers, and there are standard ones.

NumberWhat it means
Significant wave height (Hs) Roughly the average of the biggest third of the waves — computed here as four times the RMS of the heave signal. This is the number every forecast quotes. When a GRIB says "two metre seas", it means Hs.
Biggest crest to trough The single largest wave in the window. Always noticeably larger than Hs, which is why the sea looks worse than the forecast said.
Mean period Average seconds between crests. Height alone doesn't tell you much — two metres at twelve seconds is a comfortable swell, two metres at four seconds is miserable.
Why Hs is "significant". It was defined to match what an experienced observer reports when asked how big the waves are — people naturally ignore the small ones and describe the noticeable third. The statistic was built to agree with the eyeball, not the other way round.

What comes out of it

It also counts knocks — sharp vertical events that aren't part of the wave train. A boat slamming off the back of a sea does something a smooth swell doesn't, and counting those says more about how unpleasant the day was than the height alone.

And a settling guard

The filters need a little while to converge after a restart, and during that time the numbers are nonsense. So it refuses to publish until it has settled. No reading is better than a wrong one, especially for a figure that's going into a permanent log.

What it's for

Beyond a number on a screen

An honest record of the passage

"It was rough" is a feeling. Hs 2.4 metres, biggest 3.8, mean period 6 seconds, 14 knocks is a description. Written into the log automatically, every day, it becomes a record of what the boat and the crew actually went through — and a way to know, next time, whether the forecast was right.

Checking the forecast against the water

A forecast gives you Hs. Now so does the boat. Put them side by side over a season and you learn which models to trust where — which is worth more than any single forecast.

Deciding things

Is it getting worse or is that just the last hour feeling bad? Has the swell period lengthened, meaning the system has passed? Numbers answer that. Tiredness does not.

The source will be on GitHub. The heave service, the filter core and the calibration helpers. If you've got a BNO085 and a Pi, you've got everything else you need.

Where the numbers end up → The parts list Weather and routing