Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
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.
body[data-twttr-rendered="true"] {background-color: transparent;}.twitter-tweet {margin: auto !important;}
Worked on a small hack over the holidays. Nice break from dockerized Node microservices. Hitting 2018 running. #BeastMode
— @cjus
function notifyResize(height) {height = height ? height : document.documentElement.offsetHeight; var resized = false; if (window.donkey && donkey.resize) {donkey.resize(height); resized = true;}if (parent && parent._resizeIframe) {var obj = {iframe: window.frameElement, height: height}; parent._resizeIframe(obj); resized = true;}if (window.location && window.location.hash === "#amp=1" && window.parent && window.parent.postMessage) {window.parent.postMessage({sentinel: "amp", type: "embed-size", height: height}, "*");}if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.resize) {window.webkit.messageHandlers.resize.postMessage(height); resized = true;}return resized;}twttr.events.bind('rendered', function (event) {notifyResize();}); twttr.events.bind('resize', function (event) {notifyResize();});if (parent && parent._resizeIframe) {var maxWidth = parseInt(window.frameElement.getAttribute("width")); if ( 500 < maxWidth) {window.frameElement.setAttribute("width", "500");}}
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.
Part One
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.
Rodrigja via wikimedia
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.
Device fits perfectly on the Katana’s handle
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.
Device positioned with charging port facing out for easy charging
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.
Part two
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.
Hardware
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.
Software
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”.
Captured using the awesome DU Recorder for Android
What the video shows is the app connecting to a Bluetooth enabled device called eKatana.
Wirelessly!
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.
Closing
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.
Resources
All of the necessary parts can be purchased online. Since technology moves quickly - make sure to check for updated components.
- Polypropylene training sword from BladesUSA via Amazon
- Adafruit Feather 32u4 Bluefruit LE
- Lithium Ion Polymer Battery — 3.7v 100mAh
- Adafruit 9-DOF Accel/Mag/Gyro+Temp Breakout Board — LSM9DS0
- BlueFruit LE mobile app: iOS or Android
- Adafruit AHRS tutorial
- Forging a Katana — documentary on the history and traditional process of crafting a genuine Katana.
—
Thanks for reading! If you like what you read, hold the clap button below so that others may find this. You can also follow me on Twitter.
IoT for Ninjas was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.