Millenium Falcon HID: Get Unity To Talk To Teensy

Here’s one that proves a hardware project can go beyond blinking LEDs and dumping massive chunks of data onto a serial console. Those practices are fine for some, but [dimtass] has found a more elegant hack for a more civilized age. His 3D Millennium Falcon model gets orientation data from his IMU as an an HID device.

The hardware involved is an MPU6050 6-axis sensor that is interfaced with a Teensy 3.2 board. [dimtass] documents his approach to calibrating the IMU going a bit further by using a Python script to generate offsets. We’ve advocated using Jupyter notebooks in the past and this is a good example of Jupyter plotting the data and visualizing the effect of the offsets in a second pass.

When in action, the Teensy reads IMU data and sends it over a USB RAW HID interface. For the uninitiated, HID transfers are more reliable than USB CDC transfers (virtual serial port) because they use smaller data chunks per event/transaction and usually don’t require special driversOn the computer side, [dimtass] has written a small application that gets the IMU values over the RAW HID and then provides it to the visualization application.

A 3D Millennium Falcon model is rendered in Unity, the popular open source game development engine. Even though Unity has an API, this particular approach is more OS specific using a shared-memory technique. The HID application writes to a file (/tmp/hid-shared-buffer) which is then read by Unity to make orientation changes to the rendered model.

[dimtass] provides lots of details on the tools used to bring his project to life and it can be a great starting point for more projects that need interfacing sensors with a visualization system. We have seen ways to turn a person’s head into a joystick and if you need a deeper dive into Unity, look no further.

9 thoughts on “Millenium Falcon HID: Get Unity To Talk To Teensy

    1. If you are doing a USB HID joystick why not do a custom application?
      Maybe it’s a POC for something more complicated.
      A joystick doesn’t exactly give orientation information, although I can see how it could (by convention only) transfer that kind of data.

  1. “Unity, the popular open source game development engine”

    Umm, what now?

    Unity3d might make use of many FOSS components, but is far from being Open Source.
    They DID however put some stuff on github[1] and publish the code for the editor and some components under a reference style license[2]. They even wrote a post about how this wasn’t open source[3].

    [1] https://github.com/Unity-Technologies/UnityCsReference
    [2] https://unity3d.com/legal/licenses/Unity_Reference_Only_License
    [3] https://blogs.unity3d.com/2018/03/26/releasing-the-unity-c-source-code/

    (Full Disclosure; long time Unity3D licensee, and I help manage the Unity Wiki/IRC channel – though my attentions have been elsewhere for a while now.)

    1. Anything with links is under heavy moderation. But you are right, what was the HaD writer smoking when he wrote that unity is open source. It’s popular, it’s a limited form of free. But it’s by no means open source…

      1. They have released a certain amount of code. But the license is a “look but don’t touch” reference license.

        Google “is unity3d open source” … And you get the blog post clearly stating that it’s not in the top three links.

        So not even a basic fact checking pass was made.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.