In this post we’ll build a DIY device to transform a Japanese Katana into a smart fitness device. Say what? Stay with me… the first part of this post will address the why for doing this, while the second part focuses on the how. In this way, you’re free to read the entire post or jump to the part that most interests you.
I’ve had a long-standing interest in distributed communication in the context of internet connected devices. In an earlier post I shared my brief personal journey in IoT which has been revived during the past few years. So while I don’t consider myself as having an extensive IoT background, there’s enough of a backstory to explain what lead me to this post.
Last December I set out to explore wearable devices in the context of fitness. My employer, Flywheel Sports, offers time-off during the holiday season — so that seemed like a good opportunity for a year-end hack. By January, I completed a prototype using an Arduino-based device which measures angular momentum.
Almost six months later I’m finally getting around to publishing this work. The reason is due to my super busy schedule at Flywheel supporting our FlyAnywhere product and our open source projects — sprinkled with outside consulting and speaking engagements.
Although my fitness related interest at the time didn’t involve martial arts — it quickly became apparent that would be a good use case for the initial prototype. The idea came to me as I was testing the prototype and found I had to make extreme motions in order to measure the effects of speed and rotation. That turned out to be an issue in the programming regarding sensor sensitivity. While testing, the motions reminded me of wielding a sword — which lead to a project code name: eKatana or electronic katana.
I studied martial arts for much of my youth — mostly as a side interest — so I guess that the measurement of angular momentum wasn’t a new concept, although that wasn’t how we referred to it in the Dojo. A quick search on YouTube for the term katana sword exhibition will give you a sense of the extreme dedication, precision and overall mastery involved. To say it’s awe-inspiring would be an understatement.
But, alas I digress. What if one could take a practice sword and retrofit it with sensors to track the quality of motion? And what if one could build a mobile application to analyze that data in realtime? Would that be useful? While we’re seeing rapid advancements in AI — a Siri-like trainer is still some time away. And we’re even further away from replacing a human Sensei. Singularity notwithstanding. That’s just my bet. However, since science fiction has a way of becoming science fact, it isn’t difficult for one to imagine a Jedi knight training sword, complete with holographic Sensei.
So adding tracking capabilities to a sword allows it to become a smart device. Which presumably has fitness and training implications. That offers us our first “why”. And perhaps for someone — successful execution of such a product could lead to potential financial rewards, which offers us a second “why”. But it’s the third “why” that’s most important to me… hacking is about exploring — often without monetary motives and for many of us, that’s often enough of a “why”.
Let’s have a closer look at the tech behind such a smart device before getting into the “how” that makes it possible. Referring back to my twitter post in January, we see a prototype of a Bluetooth enabled device which is capable of tracking motion. It’s also powered by a tiny battery making it highly portable. Think of that device as the brains of our sword.
Naturally, we still need an actual sword. It didn’t take long to track down a $16 polypropylene training sword on Amazon— it’s the one shown in the next series of photos.
After numerous layout considerations, I managed to get the device down to one inch by two inches, with a height of just over a quarter inch. Further size reductions are certainly possible. I suspect that a near 50% reduction in size and lower costs at scale — but those are re-engineering and mass production challenges.
Sadly, the practice sword I purchased does not have a hollow base, so the module can’t easily fit inside the handle. But clearly, it’s small enough to do so. Potential solutions include 3D printing an extended base. That said, I suspect that an ideal location for the sensors would be at the tip of the blade — but that discussion is outside the scope of this post.
Once the Katana charges (in just under an hour) the practitioner would then pair it with a mobile phone or tablet. An mobile app receive the emitted Bluetooth data. A full-featured app could provide practice motions and measure force and accuracy. Data could then be sent to a cloud-hosted service for longer term storage and or deeper analysis.
In the next part, we’ll have an in-depth look at the tech.
The eKatana is a wireless smart sword consisting of both hardware and software components. The software in question lives on the microcontroller as well as in a phone or tablet device by way of a mobile app. The key to a successful product would be in the richness of a mobile app and service.
The hardware consist of easily attainable components specifically designed with hobbyists in mind. Outside of some basic soldering skills, which you can obtain on youtube, there really isn’t a lot required to build the prototype.
In this section we’ll take a closer look at the tiny module but suffice it to say that it packs a punch:
A low power Arduino-based microcontroller
Bluetooth LE (for wireless connectivity)
9-DOF sensor with 3-axis accelerometer, 3-axis magnetometer and 3-axis gyroscope
A tiny, rechargeable 3.7v Lithium Ion Polymer Battery
Our eKatana module consists of a microcontroller shown on the left and a 9DOF set of sensors shown on the right. The two are powered via a 100mAh+ battery.
As you can see from this diagram, the wiring is really quite simple. Power and Ground are routed via the red and black wires and the green and yellow ones aid in data transfer. The Bluetooth LTE transmitter is the gray colored rectangle with a red backing and gold connector shown below the yellow and green wires.
Both components are small but it’s tricky to solder them together so that they stack. An easier layout is to attach them to a flat board and place them side by side as shown in the diagram above. That would allow for longer wires and easier soldering.
Before we dive into the actual code let’s take a brief look at a video of the demo app we’ll use. The mobile app is called BlueFruit LE and it’s running on my Samsung Note8.
As we love to say in the open source community, “running code speaks volumes”.
What the video shows is the app connecting to a Bluetooth enabled device called eKatana.
When launched we select the UART option in order to view the data being emitted from the device.
We see values for RO (Rotation), PI (Pitch) and HD (Heading).
As I move the sword the values change to reflect the sensor data being captured.
This allows us to determine whether the sword is rotating, whether it’s facing up or down and the direction it’s facing. Combined these values would allow for detecting how a practitioner is progressing through a Kata (form).
Let’s have a look at the actual code that’s generating that output. The code we’ll examine is first flashed onto the device using the Arduino IDE, version 1.8.5. I won’t get into how to flash the code onto the device — since that’s a fairly standard Arduino development process. See this video if you’re curious.
Some quick highlights:
Lines 1–8 are the headers for the libraries the code requires. Here we see that they’re all Adafruit libraries, some for Bluetooth functionality, SPI and UART interfaces, one for the all-important LSM9DS0 motion sensor breakout board and a Simple_AHRS library (attitude and heading reference system) which considerably simplifies our demo.
Lines 26 through 41 set the default sensor range values.
Lines 46 through 76 configure the onboard Bluetooth device.
Lines 78 through 99 constructs a loop that polls the ahrs.getOrientation function to pull sensor data.
Lines 96 and 97 output sensor data using the Bluetooth library.
The trick to getting the code compiled is in ensuring that you’ve located and downloaded all the necessary libraries. But you’ll find the latest documentation on the Adafruit site.
In this post, I’ve tried to offer an overview rather than an in-depth tutorial. This, unfortunately, limits how much I can share in a single post. If you venture to create this or a similar device please feel free to reach out.
A special thanks goes out to the IoT working group at Flywheel Sports for their interests in this and other far reaching projects.