Pilot your own Starship with Artemis (and make it better with Arduino)

Artemis screenshot from artemis.eochu.comIf you are a gamer and a Star Trek fan and haven’t heard about Artemis yet, hold on to your socks, ’cause here it is. Artemis is a Spaceship Bridge Simulator; more than just a kill-all-the-bad-guys video game, it’s an immersive, social gaming experience where you and a bunch of buddies get to romp around the galaxy protecting the defenseless and smiting the invaders with torpedoes and beams and warp drive on a grander scale than a PC and a headset. It’s been around for a few years (and gets better all the time with free upgrades), and is even getting fresh national exposure
on Penny Arcade.

The basic gameplay requires a server machine (can be a PC running Windows or Linux/MacOS and Wine or an iOS device) and at least two, but up to five bridge stations. Each player picks a role from Captain, Navigator, Weapons Officer, Science Officer, Comms, and Engineering/Damage Control (Nav and Weapons are required stations to “win” the game, the rest are optional), and the team flies around the universe defending civilian vessels, shooting bad guys, avoiding minefields and asteroid belts, and performing the occasional side-mission to collect upgrades and scan anomalies. For even more fun, multiple ships can fly around the same universe, cooperatively satisfying the same victory conditions (ship-vs-ship is coming with the next version). There’s a lot of community support including a place to talk about building your own bridge complete with touchscreens and DMX lighting.

It’s in implementing DMX lighting that Arduino makes its appearance. You can just go out and buy a $70 DMX USB controller and an $80 LED spotlight, or you can build your own Arduino-based lighting rig for a lot less.

Out of the box, Artemis has an XML file that is configured to send DMX events out when red alert is engaged, when the shields are raised or lowered, while docking, when docked, and when your ship is hit or damaged, so I’m going to focus on how to build a device to pick up those events. The key element of the standard DMX USB controllers is a standard FTDI USB serial interface chip, used in a wide variety of products, including older Arduinos. Applications sending DMX events don’t open COM3: or /dev/ttyUSB0, they traverse the tree of attached USB devices and look for the vendor/product pair for an FDTI chip and send packets directly to the system USB drivers. As a result, with the right sketch loaded on an FTDI-equipped Arduino, you can bypass the RS-485 drivers/receivers and make an all-in-one USB LED controller that the application (Artemis.exe in this case) can’t tell from $150 of “real” DMX equipment. If you don’t have an old Duemilanove lying around or can’t find one used, you can pick up an FTDI dongle or FTDI cable and connect the Tx/Rx leads from the FDTI chip to D0 and D1 of any Arduino and you’ll be fine. If you happen to already have or have access to a DMX light, you can also take that same FTDI dongle/cable and connect it to either a MAX485 or 75176 RS-485 transceiver chip to end up with a functional equivalent to the Enttec Open DMX USB for about 1/3 the cost.

The FTDI on the Duemilenove takes care of the host end of your lighting rig. The LEDs themselves can be inexpensively bought by the reel or by the piece. These are typically 12V strips/modules, so you’ll need three N-channel MOSFETs (one for R, one for G, one for B) and you’ll want to attach them to an Arduino digital output pin that supports PWM (so you can vary the brightness of each color not just turn them full-on and full-off). For the ATmega168 or ATmega328 in the older Arduinos, that means three from D3, D5, D6, D9, D10, D11. By convention, the preferred wiring arrangement is Red on D11, Blue on D10, Green on D9, but as long as you keep track of which outputs control which color, it’ll work out fine.

Once you have the hardware wired up, the final element is the software. Fortunately there is an excellent DMXSerial library. The example code provided in DMXSerialRecv.pde will run an RGBY light strip, but since Artemis itself is already configured for a 3-channel RGB light and since it’s easier to purchase and wire one RGB strip than one R, one G, one B, and one Y strip, the simplest solution is to modify the provided DMXSerialRecv.pde like so:

// - - - - -
// DmxSerialRecv.pde: Sample DMX application for retrieving 3 DMX values:
//
// address 1 (green)  -> PWM Port 9
// address 2 (blue)   -> PWM Port 10
// address 3 (red)    -> PWM Port 11
// 
// Copyright (c) 2011 by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// Modified for use with  Artemis Spaceship Bridge Simulator
// 
// Documentation and samples are available at http://www.mathertel.de/Arduino
// 25.07.2011 creation of the DmxSerial library.
// 10.09.2011 fully control the serial hardware register
//            without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
// 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
// 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
// 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
// 30.04.2013  removed Yellow to act like a simple 3-channel DMX light and moved writes to bottom of loop() <ethan.dicks@gmail.com>
// 
// - - - - -

#include <DMXSerial.h>

// Constants for demo program

const int GreenPin  =  9;  // PWM output pin for Green Light.
const int BluePin   = 10;  // PWM output pin for Blue Light.
const int RedPin    = 11;  // PWM output pin for Red Light.

#define GreenDefaultLevel 0
#define BlueDefaultLevel  0
#define RedDefaultLevel  80

int GreenValue  = GreenDefaultLevel;
int BlueValue   = BlueDefaultLevel;
int RedValue    = RedDefaultLevel;

void setup ()
{
  DMXSerial.init(DMXReceiver);

  // set some default values
  DMXSerial.write(1, GreenDefaultLevel);
  DMXSerial.write(2, BlueDefaultLevel);
  DMXSerial.write(3, RedDefaultLevel);
  
  // enable pwm outputs
  pinMode(GreenPin,  OUTPUT); // sets the digital pin as output
  pinMode(BluePin,  OUTPUT);
  pinMode(RedPin,   OUTPUT);
}

void loop()
{
  // Calculate how long no data packet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
  if (lastPacket < 5000) {
    // read recent DMX values and set pwm levels 
    GreenValue  = DMXSerial.read(1);
    BlueValue   = DMXSerial.read(2);
    RedValue    = DMXSerial.read(3);
  }
  else {
    // Show pure red color, when no data was received since 5 seconds or more.
    GreenValue  = GreenDefaultLevel;
    BlueValue   = BlueDefaultLevel;
    RedValue    = RedDefaultLevel;
  }

  analogWrite(GreenPin,  GreenValue);
  analogWrite(BluePin,   BlueValue);
  analogWrite(RedPin,    RedValue);
  
}

If you are waiting for your LED strips to arrive, you can hook up one red, one blue, one green LED to the appropriate digital outputs on your Duemillenove (with appropriate current limiting resistors), load the sketch, then fire up Artemis and watch the LEDs change as various events happen in the game (the easiest to fire off for testing are ‘Red Alert’ from the Comms station or ‘Raise Shields’ from the Weapons station).

If you are running Artemis from the same machine you uploaded the sketch from, you may need to disable the FTDI serial drivers to let Artemis directly send USB packets to your Arduino. Naturally, you would need to re-enable those same serial drivers if you use your Artemis server for your Arduino development.

In all my experimentation, I’ve only found one hitch: I’m primarily a Linux/Unix user. I did get Artemis running as a server and as a client under Wine on Ubuntu 10.04 and Ubuntu 11.04 (after some ordinary Wine registry tweaks to get 3D graphics fully working), but I have been unsuccessful so far in getting DMX lights working with an Artemis-on-Wine server. For that, it’s Windows-only. Perhaps in the future, when the Android version of Artemis is out, it will be possible to revisit this.

So just this week, I’ve demoed Artemis twice, at work and at the Columbus Idea Foundry, to rave audiences. I’m looking forward to receiving my already-ordered box of RGB LED modules from Holidaycoro.com and building some free-standing ambient lights. Once I get those built, I’ll post some build pictures and soon after, live action shots of Artemis + Arduino.

Now that you know what to do, go out and get the demo (or the full product) here!

Advertisements

7 responses to “Pilot your own Starship with Artemis (and make it better with Arduino)

    • Hi, David,

      I’m familiar with that adapter, and it’s fine if you are working with other Holidaycoro products that carry +12V and RS-485 data over an RJ-45 cable. Since I have no problem making my own devices, I’m much more likely to pick up some variety of FTDI Arduino dongle and attach it directly to a 75176 chip if I need to talk to commercially-made DMX lights (after figuring out how to inexpensively cable up to 5-pin XLR sockets). If you only need 3-6 channels of lights (RGB once-over or two sets of RGB lights that could respond differently to different game events, or even a mix of single-color LED strips), an FTDI-equipped Arduino lets you build an all-in-one device very inexpensively by skipping the RS-485 and associated cables.

  1. Hi, thanks for your helpful post! I’m a bit confused though – in your code you’ve changed the data order to GBR instead of RGB. And yet in the Artemis config it lists them in RGB order, like so:

    When I tested briefly in game this seemed to work, at least the shields were red as they were supposed to be – not quite sure about what other events are.

    So I can only think this is something special about DMX that I’m not getting?

    Thanks
    Joel

  2. Hi, Joel. My mods were to turn an RGBY DMX light (4 channels) into RGB (3 channels) because my LED modules only have dies for red, blue, and green. I retained the same color order that the project I worked from used, but I trimmed out yellow.

    There is nothing special about DMX that isn’t obvious. Your Artemis XML files have to refer to the same channels that the Arduino is wired to or you’ll get mismatched colors. You can start with unmodified XML for Artemis then hack the Arduino code to match. Shields up should be *blue*, Red Alert should be red, docking tractor beams should be yellow (red and green), and docked should be green. If your colors don’t match that, tweak either the Arduino code or your XML code to match up.

  3. Hi Ethan, well I’ve messed with the order now and have it all working nicely! I’ll take it to my session today to show it off :)
    Thanks
    Joel

  4. Pingback: Ringing in the New Year with Artemis | Ethan's Makerblog·

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s