Bluetooth Low-Power Learning

So…I have a project I’m developing that requires Bluetooth. Basically, it’s an app to control some hardware I built.

I had an old HC-06 Bluetooth module lying around and it worked great. Was easy to get setup and connected to my Teensy microcontroller…but it only worked with Android. My iOS devices could not even see it. I later found out is was working on Bluetooth 2.0 and NOT the required 4.0 (BLE – Bluetooth Low Energy) required by iOS.

First of all, why do you need a BLE with iOS? Because they want a cut of the Bluetooth market and have specific requirements that are NOT part of the standard Bluetooth spec (what? Apple is doing their own thing? Say it ain’t so!!!!) However, BLE seems to get around this requirement. Ok, no big deal.

I found a device advertised as an HM-10 BLE module for Arduino that would connect to Android and iOS. Great! And it was inexpensive. Even better! It arrived after a few days and I was excited to hook it up and start testing my app on iOS.

However…

My iPad Mini could not see it. What?

My Android could see it, but could not connect to it. Double what??

I decided to hook up the module to the Arduino and wrote a quick little sketch to let me put it in AT mode (programming mode) and see if I needed to change any settings. That worked fine. Could communicate with it, but for some reason some of the AT commands would not work. So I typed in

AT+HELP
********************************************************************
* Command             Description			           *
* ---------------------------------------------------------------- *
* AT                  Check if the command terminal work normally  *
* AT+RESET            Software reboot				   *
* AT+VERSION          Get firmware, bluetooth, HCI and LMP version *
* AT+HELP             List all the commands		           *
* AT+NAME             Get/Set local device name                    *
* AT+PIN              Get/Set pin code for pairing                 *
* AT+PASS             Get/Set pin code for pairing                 *
* AT+BAUD             Get/Set baud rate		                   *
* AT+LADDR            Get local bluetooth address		   *
* AT+ADDR             Get local bluetooth address		   *
* AT+DEFAULT          Restore factory default			   *
* AT+RENEW            Restore factory default			   *
* AT+STATE            Get current state				   *
* AT+PWRM             Get/Set power on mode(low power) 		   *
* AT+POWE             Get/Set RF transmit power 		   *
* AT+SLEEP            Sleep mode 		                   *
* AT+ROLE             Get/Set current role.	                   *
* AT+PARI             Get/Set UART parity bit.                     *
* AT+STOP             Get/Set UART stop bit.                       *
* AT+START            System start working.			   *
* AT+IMME             System wait for command when power on.	   *
* AT+IBEA             Switch iBeacon mode.	                   *
* AT+IBE0             Set iBeacon UUID 0.            	           *
* AT+IBE1             Set iBeacon UUID 1.            	           *
* AT+IBE2             Set iBeacon UUID 2.            	           *
* AT+IBE3             Set iBeacon UUID 3.            	           *
* AT+MARJ             Set iBeacon MARJ .            	           *
* AT+MINO             Set iBeacon MINO .            	           *
* AT+MEA              Set iBeacon MEA .            	           *
* AT+NOTI             Notify connection event .                    *
* AT+UUID             Get/Set system SERVER_UUID .            	   *
* AT+CHAR             Get/Set system CHAR_UUID .            	   *
* -----------------------------------------------------------------*
* Note: (M) = The command support slave mode only. 		   *
* For more information, please visit http://www.bolutek.com        *
* Copyright@2013 www.bolutek.com. All rights reserved.		   *
********************************************************************

A help screen came back…and a lot of AT commands were not listed. At the bottom was “bolutek.com.” Crap.

After some more research, I found out I have a CC41A, NOT an HM-10. Then I read all about the “Clone Wars” regarding the HM-10 and all the manufacturers ripping it off. That research also yielded ways to tell if you have the original HM-10 (based on the TI CC2540 or CC2541 chipset.) The CC41A is also missing a crystal oscillator (the HM-10 has 2.)

In the meantime, I found an original HM-10 (at 3X the price of the clone, of course…but…worth it!)

However, when I hooked it up…SAME THING! Android could see but not connect, iOS could not even see it! WTH?!

After some digging around, I learned that BLE works differently from Bluetooth 2.0. First of all, no contracts. That means I don’t have to pair it to a device ahead of time. It’s all done “on-the-fly” so to speak.

I fired up my app and had it scan for BLE devices. Voila! It was there! On both iOS and Android. Lesson learned.

Here are two major ways to tell the clones from the righteous HM-10:

1. Second oscillator missing. This is a dead give away.  The image below shows two metallic rectangles above the black chip.  Those are the oscillators.  You’ll notice in the other two boards, the second one is missing.

2. Large chip on the board should say CC2541 or CC2540 (I know, this can be faked as well, but so far have not had that experience.)  Even if the chip DOES say CC2541 or CC2540, if the other oscillator is missing…it’s a clone.

HM-10-comparison

So, if you ever find yourself in need of something like this…beware. ALL of them are advertised as HM-10 with the CC2541/CC2540 chipsets. So far both have worked fine for me. If I ever have a more complicated project, I may stick with the HM10 as it has more capabilities.

Reporting for Duty

Well…notkt really….almost, though…

I have been working on my Stormtrooper armor (also known as a TK) for quite a while now and FINALLY got it finished in time for Halloween.

Why build Stormtrooper armor?  Is that even a question?  Do you event KNOW me?!!?!

Ultimately, I will be joining the 501st, a charitable organization….”Bad guys doing good.”  Check them out.

Meanwhile, Halloween was a blast (pun intended)!  Walking around the neighborhood, I can see why everyone tells me how fulfilling it will be to be in the 501st and bringing joy and smile to kids and adults alike.  Lots of photos were taken….lots of smiles on kids’ faces.  It was a blast.  Plus I was with Princess Leia and Rey..so…SCORE.

halloweenIt also was a great way to road test the TK Talkie system I designed.  It’s a cool vocal effects board that makes your voice sound like it’s coming over a radio and adds the obligatory sound effects when you stop talking (clicks and static bursts and such.)  It’s an open source project and highly customizable.  It worked wonderfully and really adds to the character of the costume.

 

 

A Little Election Fun with Lasers and Candidates

20161024_003006
I won’t waste a lot of time going in to how much everyone, no matter which party you support, has just about had it with the elections.  It’s gotten to the point that it’s unbearable.

I decided to have a little fun by offering up something to let people take out their frustrations in a fun way.  I dusted off the old Internet-controlled paintball gun system and swapped it with a laser and put up a website where you could control it and have fun shooting targets!

Last year I worked with a German artist on a project called 11Days that allowed people to control a paintball gun in a rat enclosure.  Needless to say it caused quite a stir (don’t worry, the rat was perfectly safe) and made its point.  I used the same technology stack (again, with lots of modifications) and built an enclosure in my house.

The basic premise was this:

  • Allow people to control the “gun” via their browser
  • The laser would shoot targets and elicit soundbites from the candidate
  • Their eyes would flash each time a target of theirs was hit.
  • It kept high scores and had a leaderboard
  • It had the ability to record someone’s session and play it back in real-time (auto-pilot for the gun)
  • Videos of the user session could also be recorded and downloaded by the user

20161024_003052

The basic setup is this:

  • Local NodeJS server that controls the gun.  It attaches to a remote NodeJS server that handles the user interaction, queuing system, etc.
  • Local instance of FFMpeg that provides the camera stream.  It connects to a remote NodeJS server that handles the distribution of the stream to multiple clients.

All-in-all, three (3) NodeJS servers were used.  The website itself was built using Silex, which is a stripped-down version of the Symfony PHP framework.  There was an Arduino Uno controlling the servos (pan and tilt) for the gun and camera setup, and an Arduino Mega used to control the photoresistors embedded into each target as well as the LEDs used for the candidates eyes.  The soundbites were pulled from the interwebs and the music that played was a circus theme that I played with to make it sound all bent out of shape.

The video below was made and put on Facebook (via Youtube) and shows the setup in action.

TK Talkie – Custom Stormtrooper Voice Effects Version 2

NOTICE: This tutorial is out-of-date! The updated tutorial can be found at http://www.tktalkie.com/tutorial

.

Version 1 on the left (20mm high), Version 2 on the right (7.5mm high)

Version 1 on the left (20mm high), Version 2 on the right (7.5mm high)

Not long after putting up the original TK Talkie tutorial I ordered another set of Teensy boards from pjrc.com.  This time, however, I ordered the pre-pinned Teensy and, well, the pins are soldered on differently (on the other side of the board from the way I did it…don’t know why I didn’t notice this the first time…)

While designing a 3-D printed case for what I’m now calling Version 1, I noticed to get everything to fit the case needed to be around 25mm high.  That really bothered me because I wanted this project to be as compact as possible.  The boards with the sockets and headers stacked together (see Version 1 tutorial) are about 20mm high.  With the pre-pinned version just soldered directly onto the Audio Shield, the overall height is around 7.5mm!  That’s great for something really compact!

Of course this new design precludes you from being able to swap out the Teensy or Audio Shield by pulling them apart, but since this is a purpose-built project, that’s probably way down on the list of priorities. You trade convenience for compactness.  If you still want that capability, you can build Version 1.  Also, you can desolder the boards for Version 2 if you really need to take them apart.

In order to build Version 2, follow the Version 1 tutorial, but when you get to the part about attaching the boards together, skip it and solder the pre-pinned Teensy directly to the Audio shield (see pic) AFTER soldering lead wires for the microphone, being careful (as always) to make sure the pins are properly aligned.

There is not much clearance between the boards, so solder the mic wires FIRST and leave room.

There is not much clearance between the boards, so solder the mic wires FIRST and leave room.

Once again, since there is hardly any clearance between the Teensy and the Audio shield, solder the lead wires for the microphone BEFORE attaching the Teensy and Audio Shield together.  There is very little clearance, so make sure the wires do not stick up very far or you could cause a short.

Since I don’t have an enclosure designed for this version, just make sure you have at least 2.5 inches of lead wire in order for the microphone jack to fit anywhere in the enclosure.

I’ll be designing a 3-D printed case for Version 2 as well.  Stay tuned!

TK Talkie – Custom Stormtrooper Voice Effects

NOTICE: This tutorial is out-of-date! The updated tutorial can be found at http://www.tktalkie.com/tutorial

.

This tutorial is for Version 1 of this project.  There is now a Version 2 available.  In order to build Version 2, follow the tutorial below, and the alternate steps for Version 2 are marked below.

It’s been a lifelong dream of mine (as well as many, many others out there) to own my own set of Stormtrooper armor. I, like may others, was finally able to do this when Anovos offered up their kits last year and made them super affordable.  Cue dream montage in 3…2…

20160806_193439I’ve had a blast building my kit and helping and being helped in the process by so many great people that are so ready to offer up their knowledge via the Anovos Facebook group and of course WhiteArmor.net.

So here’s my attempt at giving back.  I purchased a wireless mic system from Wireless Trooping Systems and an Aker 10 watt speaker off eBay, but wanted to add the really cool voice effects.  You can buy effects boxes, and they are all great, but I, like so many, am on a budget (putting 2 kids through college with a 3rd on the way is NOT cheap lol…)

I love to tinker with Arduinos and such, and stumbled across a video for the Teensy 3.2 and the Teensy Audio Shield and was blown away by what it could do.  And it’s inexpensive.  I started thinking…”what if…”

Fast-forward about a week later and I have a pretty decent working voice-effects box for around 50.00 (not including the speaker or the wireless microphone system…which is awesome btw..)  It was not very difficult.  I built on the plethora of examples and tutorials that come the Teensy software.  And to date, it has the following features:

  • Is voice-activated (no Push-To-Talk…but it could be added pretty easily)
  • Is fully customizable – From the startup sound to the effects, you can use pretty much whatever you want (though honestly, there are only a few TK voice effects to realistically use)
  • Did I mention it is FULLY customizable? Since you have the source code you can do pretty much whatever you want with it!

You can get the source  code and instructions from my Github repository.

Ok, enough chatter (see what I did there?) Let’s get to it!

Stuff You’ll Need

I built my effects box using a Teensy 3.2 and Teensy Audio Shield, although you can actually use other boards if you want.  Teensy is pretty powerful and just makes it easy!

If you are building Version 2, you’ll need to get the pre-pinned Teensy, or else solder your pin headers the same as the pre-pinned Teensy. YOU WILL NOT NEED THE SOCKET SET OR THE HEADER PIN SET LISTED BELOW.

The following are optional, but I recommend grabbing them:

Tools You’ll Need

  • Soldering iron and solder
  • Magnifying headset if you’re over 40 like me and can’t see anything within a foot of your face 😉
  • Wire
  • Wire strippers

The following are for making an optional case:

  • X-acto knife (for fine trimming)
  • Drill and various size drill bits
  • Some type of work mat (if you are working on your kitchen table like me)
  • Needle (or small) files

Getting Started

NOTICE:  The link to the Arduino software below is the general downloads page…the current version of the TeensyDuino software DOES NOT work with the latest version of Arduino (1.6.9 as of this writing) so you’ll need to grab an older version.

Once you have your Teensy and Audio Shield in hand, you’ll need to install the Arduino software as well as the Teensy software, called TeensyDuino.  Take some time and familiarize yourself with the examples and tutorials under File > Examples > Audio and File > Examples > Audio > Tutorial.  There is a lot of great stuff there.  Additionally, watch the Teensy Audio Tutorial and Workshop video on Youtube to get an idea of what you can do with this awesome piece of tech!

If you are impatient, then just keep reading 🙂

Install the Software

Once you have downloaded the Arduino and TeensyDuino software, install the Arduino software FIRST.  Then, install the TeensyDuino software (you’ll need to tell it where the Arduino software is located.)

Soldering and Connecting the Boards

If you are building Version 2 using the pre-pinned Teensy (or soldering the pins on the same way as the pre-pinned version), skip the steps regarding the header pins and sockets and just solder the Teensy directly to the Audio Shield according to the directions in the Version 2 tutorial, being careful to align the pins correctly. (See Version 2 for reference.)

I actually soldered mine backwards, with the sockets on the Teensy and the header pins on the Audio Shield

I actually soldered mine backwards, with the sockets on the Teensy and the header pins on the Audio Shield

If you did not get the pre-pinned Teensy, then you’ll need to solder the header pins on the Teensy.  Then solder the sockets on the Audio Shield.  Put the short end of the header pins on the “top” of the Teensy…that is, the side that has the micro USB connector and the programming button.  The long part of the pins should point up and away from the side with the usb connector and button.  On the Audio Shield, solder the short end of the socket pins to the underside…or the side that has the SD card reader and headphones jack.  The long end of the sockets should be on the opposite side.  It’s important to get these right so that the connections are correct when you put these together!

Once you have everything soldered up, connect the shield to the Teensy, being careful that the pins are lined up correctly.  Check the 4 corner pins on each board and make sure they will line up with you connect the boards together.  They are (clockwise, holding the Audio Shield looking at the side opposite the SD Card reader and headphone jack)

  • GND (ground)
  • 12
  • 13
  • 5V

If everything is lined up, the micro USB of the Teensy and the headphone jack of the Audio Shield should be facing the same direction.

Sound Files

You can make your own WAV files, or you can download a zip file with WAV files to get started.   Be sure to read the READ.me file listed in the repo regarding WAV files, but here’s the short of it:

  • WAV files can be 16-bit mono or stereo at 44,100Khz.  You can try other bit rates, but those are the ones that seem work best
  • The SD card reader expects the files to be in old-school 8.3 format and all UPPERCASE.  That is, the file name can have up to 8 characters and the extension has 3.
  • The way the software is CURRENTLY written (remember, you can change it however you want) it looks for a file named STARTUP.WAV when it first boots up and plays that, then reads all files that start with “TKT_” and loads them into a list that it will randomly select from each time an effect is played.
  • Try to keep all your WAV files at the same volume level.  If they are not, you’ll have weirdness where some effects are louder than others. There are lots of free WAV file editors out there that will let you add or remove gain from your WAV files.

If you have downloaded the zip file, go ahead and unzip and load these files onto your micro SD card and then insert into into the SD card reader on the audio shield.

Status Check

Teensy and Audio Shield with headers and sockets soldered and connected together

Teensy and Audio Shield with headers and sockets soldered and connected together

See how easy this is so far?  By now, you should have

  • Arduino and TeensyDuino installed
  • Sockets and header pins soldered onto Teensy and Audio Shield and boards connected
  • Sound files loaded on micro USB card and card installed in SD card reader of Audio Shield

Loading the Software

Connect the Teensy with the USB to micro USB cable.  Plug the micro USB end to the Teensy and the USB end to your computer.  You should see the on-board LED light up.  This means you have power 🙂  Next:

  • In the Arduino software, go to Tools > Board and make sure to select the correct board (in this case, Teensy 3.2/3.1).
  • Go to Tools > Port and select the correct serial port (the one your Teensy is connected to)
  • Download the tktalkie.ino file from the Github repo (remember where you download it!)
  • Go to File > Open in the Arduino software and open up the tktalkie.ino file

Once the file is opened, click the “Upload” button (the one that looks like an arrow pointing right.)  If everything is connected correctly, the sketch should compile and load onto your Teensy.  Then the board should restart and you should hear the STARTUP.WAV file play (oh yeah don’t forget to either connect your speaker to the headphone jack on the audio shield or plug in some headphones…)

If the sketch doesn’t load (i.e. you get an error in the Arduino window), make sure your pins are connected correctly and that you have selected the correct board and serial port (see above.) Also make sure the volume is turned up on your speaker 🙂

Then unplug everything because you have some more soldering to do…

About the Software

I used the BitCrusher component to compress the voice and lower the pitch just a tad so it sounds like a crappy old walkie talkie.  The software sketch is commented pretty heavily so that you know what’s going on.  Feel free to play around with it and tweak to your liking! Again, take a look at the READ.me file on the Github repo.

Connecting the Microphone

20160806_211633

Panel mount 1/8″ stereo input jack soldered to Audio Shield. Note the jumper between the left and right input channels on the jack since the microphone input on the Audio Shield is mono.

You can either use the microphone input on the audio shield or the line-in.  It’s easier to use the microphone (IMO), but feel free to use the line-in if you want (that just means you’ll need to use some type of powered input signal.)  The microphone is mono with a single positive lead and a ground, and I used a stereo input jack, so I just jumped a wire between the left and right pins on the jack and then soldered the microphone to the board.  Make sure you solder the ground on the input jack to the ground on the audio shield.

Once this is done, you have a “complete” system.  You should be able to connect everything back up, including connecting a microphone, fire up the board (you can use the 5V power supply at this point or just keep using your computer’s USB port,) hear the STARTUP.WAV file, then start talking and hearing voice effects!

Now It Needs a Box…

The last part of this project is putting it in a protective box so that you can troop with it without worrying about it getting damaged.  I went to the local Fry’s and looked for a project enclosure and actually bought a few to try out, but they were all to big or not tall enough or too tall (and as you know, you have limited room in the TK outfit…)

As luck would have it, I had recently upgraded my phone to a Galaxy S7 and as it turns out the plastic box that the headphones come it is almost perfect for the job!  The boards can squeeze in there and be held pretty safely in place!  Yay!

So in the last part of this tutorial I’ll show you how I mounted it in the headphones case 🙂

Make a Base

In order to prevent the board from rattling around inside the box once it was closed, I took the sticky foam pads from inside the TK helmet (if you’ve done any helmet upgrades you know what I’m talking about 😉 ) and cut out a rectangle shape and stuck it to the bottom of the case.

Trimmed down sticky pad from inside the TK helmet.

Trimmed down sticky pad from inside the TK helmet.

The only bad thing about the case is that it curved on the sides, so in order to get the board to sit flush I would have to make openings a little larger in order to get to the connections.  Not a big deal, I need this to work, not look pretty (although…to be honest…I would like it to look SOMEWHAT pretty) since it will be mounted behind my chest plate.

Next, I test fitted the boards and marked where I would have to make openings for the micro USB, headphone and microphone jack connections.  Since this case has a top and a bottom, I would have to make cuts in both.

Make Some Holes

After test fitting and marking where to cut, I got out the trusty Dremel with a cutting wheel and some needle files (if you don’t have needle files….bro? Do you even cosplay?)  Also an X-acto knife comes in handy for some finer trimming.

I cut the opening for the micro USB first since it was on the bottom and I needed to make sure it went low enough so that when the boards are resting on the bottom of the case I could plug in the micro USB cable.

Cutting the opening for the micro USB connection.

Cutting the opening for the micro USB connection.

Next, I marked where the headphone jack would need to be accessible through the top part of the case and started by drilling a 1/16″ pilot hole, then eventually ended up using a 1/4″ drill bit and widening the opening to make sure the speaker connector could be plugged in.  Each time I cut an opening, I used the needle files to smooth it out and the x-acto knife for fine trimming as the plastic was soft enough that it started to melt from the Dremel or drill if I went too fast.

At first the opening was too small, so I had to go back with a larger bit to open it up more and then use the files to smooth it out so the entire connector would fit.

At first the opening was too small, so I had to go back with a larger bit to open it up more and then use the files to smooth it out so the entire connector would fit.

Also, once I had the openings for the micro USB and headphones cut out, I put the boards in the box and closed it up for another test fit and noticed that I didn’t actually have the clearance I though I had so the board kind of sat lop-sided.  Oops!  Oh well, like I said, this needs to work more than it needs to look pretty, plus it ended up holding the board pretty securely in place!

20160806_183920

Oops! Turns out the box was not as tall as I thought! I could still access the connections, though…so all good.

Microphone Jack

I chose a panel mount microphone jack because I knew that whatever I ended up using for an enclosure, I would want it accessible from the outside (as is normal.)  However, with this one, I would need to make cuts in both the bottom and top of the case in order to get it to fit.

Had to make an opening in the bottom of the case and then cut a notch out of the lid for the microphone jack.

Had to make an opening in the bottom of the case and then cut a notch out of the lid for the microphone jack.

Putting It All Together

Once I was done with the openings for the connections, I was able to close up the case, hook everything up and voila!  It works great!

Case closed.

Case closed.

I hope this tutorial was helpful, and I hope if you make this project you have as much fun as I did.  Like I said, there are LOTS of things you can do to this project (like add a PTT button if you want.)

For the Empire!

 

Custom CSS/JS Plugin for WordPress

We’ve recently released a simple and easy-to-use plugin for WordPress that allows you to easily add custom CSS (styles) and Javascripts in your pages and posts as well as on a global (sitewide) basis.

Our Custom CSS/JS plugin for WordPress means you don’t have to modify or override templates in your theme any longer.  Now you can easily add overriding styles, new styles, and custom Javascript in any page or post or in the entire site.

It’s pretty easy to use.  Just download and copy it to your plugins directory, then activate it through the admin and you’re ready to go!

11 Days – Shooting a Rat on the Interwebs!

From the art project "11 Days" by artist Florian Mehnert

From the art project “11 Days” by artist Florian Mehnert

The Beginning…

Last year I was contacted by an artist from Germany regarding the web-controlled paintball gun that I had built.  He said he wanted to use it in an art project he was planning and wanted to know if I would be willing to help him build his own paintball turret that could be controlled via the internet.

Since my original intent for building the paintball gun was to allow people to control it over the internet (but, alas…life and all that got in the way) I was excited to have the opportunity not only to provide assistance, but to finally see that vision realized.  I mean, how cool is it to be able to control something like that over the internet…but how much cooler to control it when it’s half-way around the world!

After several months of e-mails back and forth, we started in earnest around December of 2014.  I sketched out the basics of the design and gave him a hardware list.  He had constructed his own base for the turret which I thought was a very elegant and simple design.  I sent him wiring schematics and in short order he had a working paintball turret.

The Setup…

The next thing was for me to update the software that would be needed to control the gun.  I had written several versions of the software previously, including one that allows people to vote via hashtag on Twitter and have the paintball gun shoot some pre-programmed target based on the the tally, but I needed to make sure it would be robust enough to handle a LOT of traffic PLUS I had to add a queuing system and some other features.

I won’t go into all he boring details here (I’m more than happy to do that if you want to contact me to discuss the project, however…) so here is a summary of what was used and how it was setup.

The first thing to figure out was how all of the moving parts would fit together.  After a couple trials, I decided on a distributed approach that consisted of:

  • Local installation of FFMPEG on a computer with a webcam connected – This was used for live video streaming.  FFMPEG notes itself as being the “Swiss Army Knife” of video tools…and it’s true!
  • Local installation of Node JS on the same computer – this system was basically a pass-through from the web layer (explained later)…in other words, it had a minimal configuration that told it about the servos (min/max angles, etc.) and was responsible for communicating with the Arduino to control the servos for the paintball gun.
  • Remote installation of Node as a streaming server – the local video stream connected to the remote streaming server for video distribution.
  • Remote installation of Node as web server and socket server that would interpret client movement in the browser and translate coordinates appropriately and send them to the local Node server to control the paintball gun.
The rat's "cage"

The rat’s “cage”

This type of setup gives maximum flexibility and allows for variations in implementation…in other words, the “middleware”, so to speak, at the web server layer is responsible for making sure that the translated user movements fit within the limitations of the local configuration.  If you want to change the experience…say, the way the user can move the paintball gun, for example…you could do that by changing just the middleware layer and leave all of the other stuff alone.

In a nutshell, it works like this:

  1. A configuration file (in JSON format) defining servos, min/max/home angles and communication settings is loaded by the local Node installation.
  2. The local Node instance then communicates to the Arduino and sends this configuration (the code on the Arduino is also basic in that it performs minimal checking of angle limits, etc.)
  3. The local Node instance then connects to the remote instance (defined in the config file) and sends these same settings.
  4. Users connect to the remote Node server, which acts as both web server and socket server.  The size of the video display area is sent to the web server which then calculates a movement ratio based on the settings received from the local Node instance.  This way, the user’s movements on screen are more accurately translated into the paintball turret’s movements.

The video server was a very simple setup:  FFMPEG running on the local computer connecting to a remote streaming server (also Node JS.)  When a user connects to the website, a video streaming socket is also opened so that they can watch as other people move the turret around.

One of the major benefits of this setup was that the artist’s internet connection at his studio did not have to be hugely robust (decent, but not super fast) as all the heavy lifting would be handled by the remote server. After all, it was only used for the video stream and basically-one way communication to the local Node controller (in, fact, if not for the video stream, the connection would not need to be very fast at all.)

The Premise…

The artist, Florian Mehnert, had caused some controversy with his previous art projects (just Google Florian Mehnert) and this project was not going to disappoint.

As a sort of protest against the use of drone strikes, he was going to allow people from all over the world to control a gun (no one knew is was a paintball gun at the time) and be able to shoot a rat at the end of an 11 day countdown.

Long story short, the project caused all kinds of commotion over in Europe, leading to extreme spikes in traffic on the website and news reports, even death threats.  In fact, the threats got so bad that the experiment ended early and the rat was removed from the experiment (don’t worry, the rat was never actually going to be shot.)

If you visit the site now, you’ll see the true intent and message of the project.

I had planned on posting all of the code to GitHub, but have not had the time to get it prepared for public use.  However, if you think you would like to experiment with the code in your own, project, just drop me a line.

Custom Mandalorian Costume – Part 2

20140605_200623

Face mask template glued onto helment form

After getting the dome glued on and sanded a bit, it’s time to glue on the face mask onto the underlying form.  This gives the helmet some of its depth.

This is where the spray bottle once again comes in handy.  Wetting the cardboard (but not too much!) allows you to more easily shape it.

Also, you can never have too many clamps!  If you don’t have at least 8 or 10 clamps in various sizes, I suggest getting some.  They are invaluable in making sure everything is glued up properly.

Once everything is dry, it’s time to cut out the cheeks. Go slow and take your time.

You can see that I had made initial cuts for the cheeks and visor in the cardboard before gluing it on.

You can never have too many clamps!

You can never have too many clamps!

I took a pencil and traced the initial cuts to make them easier to see while I was cutting them out.

TIP: Change your blade often, especially when you are about to make detailed cuts!

Once the cheeks are cut out, it’s time to trace and cut out the actual cheek inserts.  Again, take your time and go slow.  These can be tricky to attach just right.  I also recommend cutting at 45 degree angle along the edges of the cheek plate (angling from the edge of the insert up) to make them fit a little more flush.

After the cheeks are cut out, make sure that the facemask is securely attached to the underlying layer. I noticed some gaps so I applied some glue and clamped them back up for a bit. After that I took some 150 grit sand paper and smoothed the edges a bit so that the cheeks inserts would fit better.

Helmet with cheeks cut out.

Helmet with cheeks cut out.

Since the cardboard is 2mm thick, I cut a very light surface cut at an angle where the cheek inserts will bend.  Check reference photos of the Boba Fett helmet to see what I mean, but you can see them in the next picture.

TIP:  Use reference photos A LOT to make sure you are fitting parts together correctly and getting the right kinds of edges (if you want to stay somewhat true to original, that is…)

As you can see I did not get the 45 degree angle exact, so there is a little bit of a gap where the cheek attaches…but that’s ok. It’s pretty close and if you look at reference photos those are not “sharp” edges on the original helmet and the fiberglass/bondo application should help with that. The unsharp edges help contribute to the “used” look of the most of the costumes and props of the Star Wars galaxy.

Plus, this is my first time making something like this so I’m trying to give myself some slack and turn off my OCD or I might never get anything done 🙂

Mandalorian Helmet for Halloween

I purchased a resin-cast helmet for my in-progress Mandalorian costume and managed to get it painted in time for the festivities (minus the weathering and battle damage.)

I have also been working on a wireless system to move the RF stalk up and down in the helmet.  I took a couple of Arduino Nano’s and a 315Mhz RF transmitter and receiver and concocted a setup (that I am in the process of perfecting) to facilitate this.

Since it was Halloween and I was going as “Mando on Vacation”, I bought some of those oversized sunglasses and attached them to the servo.  The video and pics below should give you an idea…

 

Integrating WordPress Into CodeIgniter

One of the sites I maintain was built using CodeIgniter.  If you don’t know CodeIgniter and you are a PHP developer, definitely check it out.  It is a lightweight, extensible framework (don’t they all claim that?).  It does not have an ORM (Object Relational Mapper) but you can easily integrate your favorite (Doctrine, for example.)

I have been building website in CodeIgniter for a while, however this one site is growing beyond scope (again…don’t they all?) and now is requiring more dynamic content.  It’s not quite to the phase where I would rebuild it using WordPress and in any event I don’t really have the motivation to build a custom theme to keep the same look and feel.

So, I’ll be using the tried and true methodology of integrating the “guts” of WordPress so that we can update pages and posts without having to do a major rewrite of the site.

To get started, I downloaded the latest version of WordPress (3.9.2 at the time of this writing) and installed it in a web-accessible sub-directory called “blog.”  I had read a few places online where people had some problems with the conflicting routing systems of WordPress and Codeigniter and went so far as to change the core code in CI and/or WordPress, but I found a much simpler method:  simply update the rewrite rule in your Apache config file:

RewriteEngine on
RewriteCond $1 !^(index\.php|blog|images|robots\.txt|css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]

The second line lists “pass-through” exclusions that are not routed via the index.php file and routing table for Codeigniter.  Now I can access WordPress directly and run the setup and enter and manage content.  The next step is to create/modify model files in Codeigniter to access WordPress instead of the original database.

I had a model call ‘Events’ that was used to obviously store upcoming events and seminars for this client.  I’m going to switch it to use WordPress to pull posts instead.

function getEvents($numPosts = 3) {
  $args = array( 
    'numberposts' => $numPosts, 
    'order_by' => 'date', 
    'category_name' => 'events' 
  );
  $myposts = get_posts( $args );
  return self::fillEvents($myposts);
}

The method “getEvents” formerly used the Codeigniter ActiveRecord system to query the db and was updated to use WordPress methods. As you can see, it uses the “get_posts” method to pull the last N posts from the Events category (with the slug “events.”)  The “fillEvents” method iterates through the records and returns an associative array.

private function fillEvent($post) {
    $event = false;
    $date = strtotime(Date("Y-m-d H:i:s"));
    $custom = get_post_custom($post->ID);
    if (isset($custom['start_date'])) {
      if (strtotime($custom['start_date'][0]) > $date) {
        $event = array(
          'id' => $post->ID,
          'title' => get_the_title(),
          'date' => get_the_date(),
          'start_date' => $custom['start_date'][0],
          'end_date' => $custom['end_date'][0],
          'location' => $custom['location'][0],
          'excerpt' => get_the_excerpt(),
          'content' => get_the_content(),
          'link' => get_the_permalink());
      }
    }
    return $event;
 }

 private function fillEvents($posts) {
    global $post;
    $events = array();
    foreach( $posts as $post ) {
      setup_postdata($post);
      $event = self::fillEvent($post);
      if ($event) {
        $events[] = $event;
      }
    }
    return $events;
 }

At this point I should note a couple of things:

  1. I do not use the templating system built-in to Codeigniter.  I replace it with Smarty as I believe it is a more extensible and versatile system.  Plus, I can upgrade the Smarty implementation without having to update Codeigniter.
  2. I usually return my data objects as associative arrays that are passed to my display templates.

The end result is that I do not have to change my controllers or my template (.tpl) files from their original design.  I just made sure that my model returned the same data in the same format 🙂

So far I have not run into any problems regarding routing or cookies, and my next step is to leverage the WordPress User system to create user accounts.  I’ll be sure to update this post (or create a new one) if I find anything.