Syma S107 Linux Joystick
Posted: April 13, 2012
In this project I took a Syma S107 helicopter IR controller and using an MSP430G2553 dump all the data sent from the remote into the Linux kernel joystick module so it can be used in video games. So after doing the Syma S107 No-Fly Zone and the IR Car projects, I figured this would be a quick and easy little project to do one or two nights after work. I started by splicing up some the IR code from the IR Car and the UART code from the Android Bluetooth Thermometer project (although I had to change the value of the baud rate generator due to the MSP430 DCO .. I hate you DCO :( ). Last step was a Linux joystick kernel module to connect the 4 bytes coming over the serial port to the joystick module of the Linux kernel. As I was looking through the joystick drivers in drivers/input/joystick/ in the Linux source code for a good example, I noticed the zhenhua.c module which seemed to do pretty much what I wanted. I copied it and changed it for the syma_s107 firmware. In the part of the kernel module that defines the serial protocol, I left this as SERIO_ZHENHUA. The reason is if I wanted to add SERIO_SYMA, I would have to change include/linux/serio.h to include this enumeration and then patch the inputattach program to use it. So after inserting this module into the kernel the way to connect it to a serial port is:
sudo inputattach --daemon --baud 9600 --always -zhen /dev/ttyUSB0
For some reason this command gives some kind of error, but dmesg shows it worked and.. well the games work.. so I have no idea what inputattach is bitching about :).
So to test this, I had a small program which opens /dev/input/js0 and just outputs values as the joystick moves. The real test was playing Ms. Pacman with the Mame Emulator. So one odd thing about this controller which I experienced with the IR Car also, this controller doesn't send out any data unless the throttle stick is forward. So in order to play any games the left throttle stick must be forward and the right stick can be used to move. There's also no "fire" button and I ignored the A/B switch for now.
The MSP430 assembly source code below can be assembled with naken_asm assembler.
Related Projects @mikekohn.net
Here's a video of me using the joystick controller to play Ms. Pacman. https://youtu.be/aescfbjstCk
Copyright 1997-2023 - Michael Kohn