New product: The Yocto-3D

New product: The Yocto-3D

Have you ever wished to measure a tilt angle by USB ? To detect when an object starts moving or falling ? To measure the position of a nearby magnet ? To determine where a vehicle is heading to ? Be happy, the Yocto-3D can do all that, and even more. Let us introduce our newest sensors...

From the outside, the Yocto-3D looks like most of our small USB devices. It has two inertial MEMS sensors: a 3D accelerometer (to measure linear accelerations) and a 3D gyroscope (to measure angular speed). The accelerometer includes a 3D magnetometer as well (to measure magnetic fields). The MEMS sensors themselves are located on a 2cm by 2cm square PCB that can be affixed on a moving mechanical part if needed, connected only by a flex wires rather than the a bulky USB cable.

Le Yocto-3D
Le Yocto-3D

Let's have a look at a few typical use cases.

Tilt sensor (electronic spirit level)

When at rest, the accelerometer on the Yocto-3D indirectly measures the standard gravity. To make it simple, imagine that the accelerometer works by measuring the displacement of a body hanging between springs. During a free fall, the body would stay at the center. But when the system is pushed on one side, or when sitting on a surface, the body moves in the direction opposite to the force applied to the enclosure. By measuring this displacement, one can compute the external acceleration applied to the system.

Working principle of an MEMS accelerometer
Working principle of an MEMS accelerometer

Based on this principle, the Yocto-3D can measure the force countering standard gravity. By measuring the angle of this force, one can precisely determine the inclination with regards to the earth surface, up to a few tenth of degrees, like a bubble level. As the sensor works in 3D, the device can provide separate measures for both roll (tilt1) and pitch (tilt2) angles:

YTilt roll = YTilt.FindTilt("myYocto3D.tilt1");
YTilt pitch = YTilt.FindTilt("myYocto3D.tilt2");
Console.WriteLine("Roll: " + roll.get_currentValue() + " deg");
Console.WriteLine("Pitch: " + pitch.get_currentValue() + " deg");

Electronic compass

The magnetometer in the Yocto-3D is primarily intended to be used as a compensated compass. In opposition to a simple compass, which only works when sitting exactly flat, this electronic can even works when the device is tilted: leveraging the measured inclination, the device automatically computes the horizontal projection of the magnetic field to compute the magnetic heading (tilt-compensated compass).

YCompass compass = YCompass.FindCompass("myYocto3D.compass");
Console.WriteLine("Heading: " + compass.get_currentValue() + " deg");


You can also use this device to detect a nearby magnet, by measuring the magnetic field. The earth's magnetic field is approx 0,5 gauss, so any larger value reveals the presence of an external magnetic source. As an example, the magnets used by our standard enclosures produce a magnetic field of about 1 gauss at a distance of 50mm.

YMagnetometer mag = YMagnetometer.FirstMagnetometer();
Console.WriteLine("Magnetic field: " + mag.get_currentValue() + " gauss");

Accelerometer and gyroscope

If you need to detect when a door or another moving part starts moving, you can directly use the accelerometer (for linear moves) and the gyroscope (for rotations):

YAccelerometer acc = YAccelerometer.FirstAccelerometer();
YGyro gyro = YGyro.FirstGyro();
Console.WriteLine("Acceleration: " + acc.get_currentValue() + " g");
Console.WriteLine("Rotation: " + gyro.get_currentValue() + " deg/s");

Real-time 3D attitude

The most sophisticated feature of the Yocto-3D is its ability to estimate in real time its own 3D attitude by combining the data provided by all sensors. The integration of gyroscopic measurements provides a very reactive estimate of the device orientation (almost 100 estimates per second) during a move, which highly improves the slower, less precise but absolute tilt and magnetic orientation measurements. The Yocto-3D perform itself this sophisticated mathematical combination, and provides directly the attitude estimate as a quaternion. The Yoctopuce library can also provide the corresponding ready-cooked aeronautical angles (roll, pitch and heading), by polling or by callback.

As an example, we will transform a Yocto-3D into a game controller. Starting from an example illustrating Google Earth Javascript API named "Mini Flight Sim", we will see how to replace the keyboard controls by a 3D game controller.

Play the The Mini Flight Sim using a Yocto-3D
Play the The Mini Flight Sim using a Yocto-3D

Using a Yocto-3D as an HTML game controller

Let's start by adding to the HTML page the code needed to access the Yocto-3D. We include the Yoctopuce library files, and setup the callback function that will automagically be invoked each time the device is moved:

<script type="text/javascript" src="yocto_api.js"></script>
<script type="text/javascript" src="yocto_gyro.js"></script>

var gyro = YGyro.FirstGyro();
if(gyro) {

The handleGyro function is just an asynchronous entry point to the Yoctopuce API to handle the events generated by the device:

function handleGyro()
{ YAPI.SetTimeout(handleGyro, 1000); }

The callback itself stores the estimated device orientation into global variables, that's it.

var yoctoSteerAngle = 0;
var yoctoPitchAngle = 0;

function gyroCallback(gyro, roll, pitch, heading)
    yoctoSteerAngle = -roll;
    yoctoPitchAngle = pitch;

The physics for the tiny simulator are handled in the Truck.prototype.tick method (don't be surprised by the name, this flight simulator is just a variation on Google's "Monster Milk Truck" example). The plane heading is handled by the variable steerAngle, which is originally updated according to keystrokes. We wipe out that code and replace it directly with the value provided by the Yocto-3D:

steerAngle = yoctoSteerAngle * dt * Math.PI / 180.0;

Similarly, we add support for changing altitude, which is missing in the example. We add a pitch property to the truck object, and we update it by integrating the game controller pitch:

me.pitch += yoctoPitchAngle * dt;
if(me.pitch > 30) me.pitch = 30;
if(me.pitch < -70) me.pitch = -70;

We can then compute the vertical speed using the plane pitch, and also update the plane displayed orientation accordingly:

me.vel[2] = 25 * absSpeed * Math.sin(me.pitch * Math.PI/180.0) * dt;
me.orientation.set(newhtr[0], newhtr[1]-me.pitch, absRoll);

Pretty easy, isn't it ? You will find the full code here. And here is the demo:


Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.