Category Archives: Bluetooth

iCade Mobile controller for $5 on Amazon

I just used some points I earned on Swagbucks to order a discontinued iCade Mobile controller for less than $5 (with Amazon Prime shipping). Currently, the price has gone up to $9, but either way, it’s a deal if you want an iCade circuit to mess with:

Yes. It's pink. Pink was cheaper.

Yes. It’s pink. Pink was cheaper.

iCade Game Controller (Pink) – Amazon link

I chose the pink one because it was a buck less than the other color. Of course, now it’s going to seem mean to dissect something that “cute.”

The iCade devices, which I have written about before, started out as an April Fool’s joke at Think Geek in 2010. They act like a Bluetooth (or USB) keyboard and some games were written to interpret certain key presses as joystick buttons. Ever since iOS 7, Apple has added official support for game pads so the iCade format is pretty much dead. Still, there are a ton of old apps (over 100) that still support iCade (including Atari’s Greatest Hits and a few other retro emulators).

I plan to dissect mine and use it inside a cheap arcade-style joystick I have, thus allowing me to have something like a Tankstick for iOS (for games that support it), without having to spend any money. I am especially interested in using it for Pinball Arcade and plan to add some buttons on the sides to act as flipper buttons.

I just thought I’d share this, since it’s cheaper to buy this and gut it than to get a cheap Arduino Leonardo type device to hook up via USB adapter cables like my Atari joystick project.

If you get one and hack it in to something, let me know. I’d love to see what you come up with.

P.S. Since 4/15/2014, I have earned over $1419 in Amazon gift cards (and PayPal cash)! Sign up using my link and I get credit: http://swagbucks.com/refer/allenhuffman (Ask me for the tip/howto doc.)

iOS MFI game controller bluetooth protocol

Starting with iOS 7, Apple added official support for game controllers on an iPhone, iPad or iPod touch. Previously, the iCade standard was used, acting as a keyboard device sending key presses for button up and button down.

I have yet to find any place the discusses how these new controllers work. Has anyone reverse engineered it? Does it have digital rights management so you can’t pair using regular devices? Does anyone know?

Adafruit Bluefruit EZ-Key response messages

NOTE: This page will be updated as I have time to do some more tests, but I wanted to get something posted so Google could begin indexing it…

The $20 Adafruit Bluefruit EZ-Key module sends a variety of status messages back through it’s serial port. Here is a list:

Power Up, unpaired:

Adafruit Bluefruit HID v1.2 11/30/2013
 No devices, making discoverable
Discoverable

When being paired:

Connecting to host xxxx,xx,xxxxxx
Exit discoverable
Connected

Power Up, paired – device not present:

Adafruit Bluefruit HID v1.2 11/30/2013
 Attempt to connect to xxxx,xx,xxxxxx
Failed to connect

Power Up, paired – device present:

Adafruit Bluefruit HID v1.2 11/30/2013
 Attempt to connect to xxxx,xx,xxxxxx
Connected

Pair Button Depressed to enter pairing mode:

Reset paired devices
Disconnected
Reset paired devices
Discoverable
Reset paired devices
Exit discoverable
Discoverable

* It appears to repeat those messages each time.

Power Up in remap mode (holding down PAIR button):

Adafruit Bluefruit HID v1.2 11/30/2013
Remap ready!

After sending remap HEX string:

OK
Set Mapping:64

* The tutorial on the Adafruit site indicates the number should be 128. As of yet, I do not know what the 64 and 128 represent, but I assume it’s some kind of bit mapped status.

Resending the HEX string:

OK
 Mapping:

* Not the missing “Set” but the space in front of “Mapping” is still there, and no status number. Maybe I dropped some data (it happens every time) or maybe it’s some missing stuff in the EZ-Key firmware.

At this point, I reset the EZ-Key if I wish to remap again. I am not sure (yet) if the second remapping takes effect (I will test and update this page).

When a switch is used, a key down message is sent, and then a key up message is sent when the switch is released. I’ll go through this when I get a moment and document the bits (I think I have a typo in this initial list).

K 0xFEF ... input 0 (1111 1110 1111) pressed
K 0xFFF ... input 0 (1111 1111 1111) released

K 0xFDF ... input 1 (1111 1101 1111)
K 0xFFF

K 0xFFB ... input 2 (1111 1111 1011)
K 0xFFF

K 0xF7F ... input 3 (111 0111 1111)
K 0xFFF

K 0xFEF ... input 4 (1111 1110 1111)
K 0xFFF

K 0xFDF ... input 5 (1111 1101 1111)
K 0xFFF

K 0xFBF ... input 6 (1111 1011 1111)
K 0xFFF

K 0xF7F ... input 7 (1111 0111 1111)
K 0xFFF

K 0xEFF ... input 8 (1110 1111 1111)
K 0xFFF

K 0xDFF ... input 9 (1101 1111 1111)
K 0xFFF

K 0xBFF ... input 10 (1011 1111 1111)
K 0xFFF

K 0x7FF ... input 11 (0111 1111)
K 0xFFF

Others – to be documented next update:

Adafruit Bluefruit HID v1.2 11/30/2013
No devices, making discoverable
Discoverable

…or…

Adafruit Bluefruit HID v1.2 11/30/2013
No devices, making discoverable
Discoverable
Connecting to host xxxx,xx,xxxxxx
Exit discoverable
Connected

And…

Adafruit Bluefruit HID v1.2 11/30/2013
Attempt to connect to xxxx,xx,xxxxxx
Failed to connect

Arduino-based Adafruit EZ-Key Remapper

Previously, I discussed the Adafruit Bluefruit EZ-Key module. This device comes factory-programmed to send specific key sequences via Bluetooth when one of the 12 inputs is selected. Software is available to change these key sequences, but this software runs on a host computer and requires installing an older version of a development environment called Processing.

Since it appears that the remapping is done simply by sending a text HEX sequence with a checksum to the EZ-Key, I thought it might be easier to just do this on an Arduino with a simple text user interface – no special installs needed.

I did a bit of work on this, and wanted to share my work-in-progress and maybe get some feedback on the interface.

Basically, for each of the 12 inputs you can specify a modifier (SHIFT, CTRL, ALT, etc.) plus up to 6 keycodes which will be sent out (with a Keys-Down) via Bluetooth. When the input is released, a matching Keys-Up message is sent.

To customize, you simply need to specify an input (0-11) and then a modifier (8 available choices) and then up to 6 keycodes (about 112 options available, such as ARROW UP or “k” or numeric keypad minus). I put together a very quick user interface, and here is a sample session, with comments on what is going on:

Adafruit Bluefruit EZ-Key Remapper 0.00 by Allen C. Huffman (alsplace@pobox.com)

Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: L

* Here, I select "L" to list the current input config.
Input Key Codes:
----- ----------
 0.   ARROW_UP
 1.   ARROW_DOWN
 2.   ARROW_LEFT
 3.   ARROW_RIGHT
 4.   RETURN
 5.   SPACE
 6.   1
 7.   2
 8.   W
 9.   A
10.   S
11.   D

Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: 6

* I select "6" to change input 7 (currently sends "1").
Editing Input 6 Configuration:

Modifier: NONE - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: L

* To see a list of available modifiers, I select "L".
  0. NONE             3. ALT_LEFT         6. SHIFT_RIGHT  
  1. CTRL_LEFT        4. GUI_LEFT         7. ALT_RIGHT    
  2. SHIFT_LEFT       5. CTRL_RIGHT       8. GUI_RIGHT      
Modifier: NONE - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: 1
Setting new modifier value to: CTRL_LEFT

* By selecting "1", I am choosing the modifier to be "CTRL_LEFT".
Modifier: CTRL_LEFT - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: 

* It shows the Modifier line again, and by pressing ENTER, it skips and moves to the next item - Keycodes 0-5:
Keycode0: 1 - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 0

* By entering "0", I am selecting "KEY_NONW" - no key. In this example, I am making this input simply send the left CTRL key.
Setting new keycode value to: NONE

Keycode0: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

* By pressing ENTER five more times, it skips over key codes 1, 2, 3, 4 and 5, leaving them to their current values of "NONE".
Keycode1: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode2: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode3: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode4: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode5: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: L

* Now I use "L" to list the input config again, and can see that input 6 is now set to send the left CTRL key:
Input Key Codes:
----- ----------
 0.   ARROW_UP
 1.   ARROW_DOWN
 2.   ARROW_LEFT
 3.   ARROW_RIGHT
 4.   RETURN
 5.   SPACE
 6.   CTRL_LEFT
 7.   2
 8.   W
 9.   A
10.   S
11.   D

Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: 7

* I then change input 7:
Editing Input 7 Configuration:

Modifier: NONE - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: L

* I want to make this input send ALT-Q, but I forgot what modifiers are available so I "L" to list them again.
  0. NONE             3. ALT_LEFT         6. SHIFT_RIGHT  
  1. CTRL_LEFT        4. GUI_LEFT         7. ALT_RIGHT    
  2. SHIFT_LEFT       5. CTRL_RIGHT       8. GUI_RIGHT      
Modifier: NONE - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: 3

* "3" is the left ALT key.
Setting new modifier value to: ALT_LEFT

Modifier: ALT_LEFT - Enter new modifier # (0-8), [L)ist, [ENTER)Skip or [Q)uit: 

* Then I press ENTER, and it goes to key code 0, which is currently the "2" key. I want to change that.
Keycode0: 2 - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: L

* But since I don't know what key codes are available, I choose "L" to get a huge list of all of them.
  0. NONE            28. 2               56. F2              84. KEYPAD_PLUS    
  1. A               29. 3               57. F3              85. KEYPAD_ENTER   
  2. B               30. 4               58. F4              86. KEYPAD_1       
  3. C               31. 5               59. F5              87. KEYPAD_2       
  4. D               32. 6               60. F6              88. KEYPAD_3       
  5. E               33. 7               61. F7              89. KEYPAD_4       
  6. F               34. 8               62. F8              90. KEYPAD_5       
  7. G               35. 9               63. F9              91. KEYPAD_6       
  8. H               36. 0               64. F10             92. KEYPAD_7       
  9. I               37. RETURN          65. F11             93. KEYPAD_8       
 10. J               38. ESCAPE          66. F12             94. KEYPAD_9       
 11. K               39. BACKSPACE       67. PRINT_SCREEN    95. KEYPAD_0       
 12. L               40. TAB             68. SCROLL_LOCK     96. KEYPAD_PERIOD  
 13. M               41. SPACE           69. PAUSE           97. EUROPE_2       
 14. N               42. MINUS           70. INSERT          98. APPLICATION    
 15. O               43. EQUAL           71. HOME            99. POWER          
 16. P               44. BRACKET_LEFT    72. PAGE_UP        100. KEYPAD_EQUAL   
 17. Q               45. BRACKET_RIGHT   73. DELETE         101. F13            
 18. R               46. BACKSLASH       74. END            102. F14            
 19. S               47. EUROPE_1        75. PAGE_DOWN      103. F15            
 20. T               48. SEMICOLON       76. ARROW_RIGHT    104. CONTROL_LEFT   
 21. U               49. APOSTROPHE      77. ARROW_LEFT     105. SHIFT_LEFT     
 22. V               50. GRAVE           78. ARROW_DOWN     106. ALT_LEFT       
 23. W               51. COMMA           79. ARROW_UP       107. GUI_LEFT       
 24. X               52. PERIOD          80. NUM_LOCK       108. CONTROL_RIGHT  
 25. Y               53. SLASH           81. KEYPAD_SLASH   109. SHIFT_RIGHT    
 26. Z               54. CAPS_LOCK       82. KEYPAD_*       110. ALT_RIGHT      
 27. 1               55. F1              83. KEYPAD_MINUS   111. GUI_RIGHT      

Keycode0: 2 - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 17

* Since I want to send a "q" key, that is 17.
Setting new keycode value to: Q

Keycode0: Q - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

* Above, it confirms that key code 0 is now "Q". I can then press ENTER to skip the next five optional key codes for this input.
Keycode1: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode2: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode3: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode4: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 

Keycode5: NONE - Enter new key code # (0-111), [L)ist, [ENTER)Skip or [Q)uit: 
Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: L

* Back to the main menu, I do an "L" to list the current input config.
Input Key Codes:
----- ----------
 0.   ARROW_UP
 1.   ARROW_DOWN
 2.   ARROW_LEFT
 3.   ARROW_RIGHT
 4.   RETURN
 5.   SPACE
 6.   CTRL_LEFT
 7.   ALT_LEFT + Q
 8.   W
 9.   A
10.   S
11.   D

Enter input to configure (0-11), [L)ist, [U)pdate or [Q)uit: U

* And they look good. Input 6 is now left CTRL, and input 7 is now left ALT + the Q key. Cool. Selecting "U" will update the EZ-Key to use this new config.

...update device here...

…and there you have it. A very simple and easy-to-use “BIOS-like” interface to remap the Adafruit EZ-Key directly from an Arduino, without touching a line of source code or installing anything special.

Does this seem useful? Should I polish it up and post it? I just created it because I was too lazy to download stuff and writing my own seemed more fun.

Let me know what you think in the comments…

Adafruit Bluefruit EZ-Key

Last year, my friend Mike tipped me off to a new Bluetooth product that had been released by Adafruit. The tiny EZ-Key device…

http://www.adafruit.com/products/1535

…was a $19.95 “ready to go” switches-to-Bluetooth board. All you had to do was feed it power (3V-16V) and then hook switches (say, joysticks or arcade buttons) to the 12 input pins and ground and you were set. Power it up, hold down the pair button for a few moments, and let it connect to your computer. After that, any press of those switches would send a preprogrammed character. By default, they were:

  • #0 – Up Arrow
  • #1 – Down Arrow
  • #2 – Left Arrow
  • #3 – Right Arrow
  • #4 – Return
  • #5 – Space
  • #6 – the number ‘1’
  • #7 – the number ‘2’
  • #8 – lowercase ‘w’
  • #9 – lowercase ‘a’
  • #10 – lowercase ‘s’
  • #11 – lowercase ‘d’

You can find a full tutorial here:

http://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard/overview

And the online user manual (with pinouts, wiring examples, etc.) here:

http://learn.adafruit.com/introducing-bluefruit-ez-key-diy-bluetooth-hid-keyboard/user-manual

If the default keys are not good for you, the device can be reprogrammed to send a different single character when a switch is pressed. This seems to involve using an adapter to hook the EZ-Key’s TX/RX pins to the PC, then running a special program that sends sequences to the EZ-Key to remap it.

The device can also be remapped over Bluetooth, which sounds like an easier option since you probably have Bluetooth (if you are using a Bluetooth adapter like this) and probably don’t have a TTL-to-Serial USB adapter. (Okay, some of you reading this probably do, but I don’t…) ((Actually, maybe I do. That may be the thing I use to program BASIC Stamps, though I didn’t know that at the time I bought it.)) (((But I digress…)))

For simple projects, the EZ-Key and a power supply is all you would need, provided whatever you are hooking to (like the MAME emulator) uses simple key presses. One emulator I have on my Mac uses the CTRL key for the FIRE button, so I would at the very least have to remap the EZ-Key to send a CTRL press.

For things like the iCade, which uses dual keypresses (one key for “press button down” and another for “release button”), this will not work. The EZ-Key only does single key presses.

Fortunately, the EZ-Key can also act as a Bluetooth gateway. You can hook it up to a serial port on an Arduino (or Teensy, or anything else with a UART) and write data to it at 9600 baud. This data is either sent out as a simple key down/key up press, or you can do more advanced things like send modifier keys (CTR+ALT+DEL) or even mouse movement and button clicks.

Using four wires, I connected an Arduino up to the EZ-Key:

Arduino hooked to EZ-Key

Arduino hooked to EZ-Key

I was using the Software Serial Arduino library to turn pins 10 and 11 in to TX and RX:

http://arduino.cc/en/Reference/SoftwareSerial

This let me open the EZ-Key just like I would open the console and read/write data to it:

#define RX_PIN         10
#define TX_PIN         11

// Initialize the Software Serial port.
SoftwareSerial EZKey(RX_PIN, TX_PIN); // RX, TX

// We talk to the EZ-Key at 9600 baud.
EZKey.begin(9600);

EZKey.write('x'); // send 'x'

It would be very easy to make a sketch that read data through the Arduino serial console port, and sent that out via Bluetooth:

#include <SoftwareSerial.h>

#define RX_PIN         10
#define TX_PIN         11

// Initialize the Software Serial port.
SoftwareSerial EZKey(RX_PIN, TX_PIN); // RX, TX

void setup()
{
  Serial.begin(9600);

  // We talk to the EZ-Key at 9600 baud.
  EZKey.begin(9600);
}

void loop()
{
  char ch;

  // If data is available from the USB serial console...
  while(Serial.available()>0)
  {
    // Read a character from the Serial console.
    ch = Serial.read();

    // If nothing was read, it returns -1...
    if (ch>=0)
    {
      // Write that character out to the EZKey via UART.
      EZKey.write(ch);
      // Echo back to the serial console.
      Serial.write(ch);
    }
  }
}

I paired the EZ-Key to my iPad, then opened the Serial Monitor on the Arduino IDE and was able to type things there and see them show up on the iPad (inside of Notepad, or anything else that accepted keyboard input).

The next step, for me, will be to integrate EZ-Key support in my iCade interface. Right now, I support reading digital inputs and writing out iCade commands as USB keyboard presses. With just a few lines of code, I should be able to expand this to use the EZ-Key and support Bluetooth as well.

Eventually, I will roll this in to my experimental USB Host Shield version, so it can also read USB joysticks (rather than just digital input switches) and output them as iCade USB keyboard or Bluetooth messages.

My EZ-Key sample program is now on GitHub:

https://github.com/allenhuffman/EZKeyTest

Stay tuned…