Friday, February 1, 2013

Building an Arduino dual-joystick module from the freebox Gamepad


The freebox Gamepad
A nice dual-joystick for Arduino

After beginning the discovery of the freebox controller internal parts (See my previous post: Inside the Freebox V6 controller), I just remembered that I needed a joystick shield for my Arduino. I found a a plenty of shields available (eBay search: Joystick Arduino ShieldSparkfun and Adafruit also sell some nice ones)  but tonight I decided to quickly build one from the freebox gamepad.


So I grabbed an USB freebox gamepad that was stored nearby and never used. Then I took it apart.


I cut the ribbon connector and separated the dual-joystick from the main board.


I then soldered the 9 pins of the ribbon cable to a single row Female Pin Header.

Pinout:
From Left to right:

  • Pin1: Left Joystick Vertical potentiometer
  • Pin2: Left Joystick Horizontal potentiometer
  • Pin3: Right Joystick Horizontal potentiometer
  • Pin4: Right Joystick Horizontal potentiometer
  • Pin5: Left Push button
  • Pin6: Right Push button
  • Pin7: Ground (-)
  • Pin8: Vcc (+)
  • Pin9: Center LED

I attached a Male to Male Dupont wire to te header female pins.


Then snapped everything to my breadboard.
The four LEDs are connected to pins 11, 10, 9 and 6 (PWM pins).


I then modified Tom Igoe's Arduino code for Analog input/output and tested it.

Now the dual-joysticks are working perfectly and their values are mapped correctly. The LEDs are lit depending on the position of the joystick's internal Left/Right potentiometers.

Here is the Arduino Code:
 /*  
  Dual Joystick (Analog input, analog output, serial output)  
  Used for the freebox V6 dual joystick  
    
  Reads four analog input pins, maps the result to a range from 0 to 255  
  and uses the result to set the pulsewidth modulation (PWM) of four output pins.  
  Also prints the results to the serial monitor.  
    
  The circuit:  
  * four potentiometers connected to analog pins 0, 1, 2 and 3.  
   Center pin of the potentiometer goes to the analog pin.  
   side pins of the potentiometer go to +5V and ground  
  * LED connected from digital pins 11, 10, 9, and 6 to ground  
    
 Modified by Omar Cherif from the original (single pin) version by Tom Igoe.  
    
  This example code is in the public domain.  
    
  */  
   
 // These constants won't change. They're used to give names  
 // to the pins used:  
 const int analogInPin0 = A0; // Analog input pin that the left vertical potentiometer is attached to  
 const int analogInPin1 = A1; // Analog input pin that the left horizontal potentiometer is attached to  
 const int analogInPin2 = A2; // Analog input pin that the right horizontal potentiometer is attached to  
 const int analogInPin3 = A3; // Analog input pin that the right vertical potentiometer is attached to  
 
 const int analogOutPin0 = 11; // Analog output pin that the LED0 is attached to  
 const int analogOutPin1 = 10; // Analog output pin that the LED1 is attached to  
 const int analogOutPin2 = 9; // Analog output pin that the LED2 is attached to  
 const int analogOutPin3 = 6; // Analog output pin that the LED3 is attached to  
   
 int sensorValue0 = 0;    // value read from the pot  
 int sensorValue1 = 0;    // value read from the pot  
 int sensorValue2 = 0;    // value read from the pot  
 int sensorValue3 = 0;    // value read from the pot  
 int outputValue0 = 0;    // value output to the PWM (analog out)  
 int outputValue1 = 0;    // value output to the PWM (analog out)  
 int outputValue2 = 0;    // value output to the PWM (analog out)  
 int outputValue3 = 0;    // value output to the PWM (analog out)  
   
 void setup() {  
  // initialize serial communications at 9600 bps:  
  Serial.begin(9600);   
 }  
   
 void loop() {  
  // read the analog in value:  
  sensorValue0 = analogRead(analogInPin0);        
  sensorValue1 = analogRead(analogInPin1);        
  sensorValue2 = analogRead(analogInPin2);        
  sensorValue3 = analogRead(analogInPin3);        
  // map it to the range of the analog out:  
  outputValue0 = map(sensorValue0, 0, 1023, 0, 255);   
  outputValue1 = map(sensorValue1, 0, 1023, 0, 255);   
  outputValue2 = map(sensorValue2, 0, 1023, 0, 255);   
  outputValue3 = map(sensorValue3, 0, 1023, 0, 255);   
  // change the analog out value:  
  analogWrite(analogOutPin0, outputValue0);        
  analogWrite(analogOutPin1, outputValue1);        
  analogWrite(analogOutPin2, outputValue2);        
  analogWrite(analogOutPin3, outputValue3);        
   
  // print the results to the serial monitor:  
  Serial.print("S1 = " );              
  Serial.print(sensorValue0);     
  Serial.print(" / out1 = ");     
  Serial.print(outputValue0);    
  Serial.print("\t");    
    
  Serial.print("S2 = " );              
  Serial.print(sensorValue1);     
  Serial.print(" / out2 = ");     
  Serial.print(outputValue1);    
  Serial.print("\t");    
   
  Serial.print("S3 = " );              
  Serial.print(sensorValue2);     
  Serial.print(" / out3 = ");     
  Serial.print(outputValue2);    
  Serial.print("\t");  
   
  Serial.print("S4 = " );              
  Serial.print(sensorValue3);     
  Serial.print(" / out4 = ");     
  Serial.println(outputValue3);    
   
  // wait 2 milliseconds before the next loop  
  // for the analog-to-digital converter to settle  
  // after the last reading:  
  delay(2);             
 }  

Now that the joysticks are working, I can easily do some experiments with X and Y axis. The controller also have two push buttons (Activated by pushing down the sticks), i didn't use them for now. They are connected to Pin 5 and 6.

Here are some videos of the joysticks working:


These joysticks enable me to do some further experiments on Servo and Stepper motors, which are just the beginning of a long journey inside the joyful world of robotics...

Inside the Freebox V6 controller

Freebox controller module
(Zigbee + Gyroscope + 3-Axis Accelerometer)

It's been a while since I've blogged, so tonight I decided to share again the hacks and stuff I'm currently working on. I will do my best to write more often about the builds and the experiments I make.

Tonight while I was watching TV, I accidentally dropped the remote controller and the battery cover fell beside. So I decided to take it apart and have a quick look inside.

I thought about this wireless controller almost each time I used it. It has some interesting really interesting capabilities that i would love to hack and use them for my future projects.

The most interesting features this controller have are the built in gyroscopic capabilities and the accelerometer . I couldn't resist the temptation to take it apart to discover what it actually look like inside.

I was very pleased to see how tiny and clever the board was designed. This little PCB was simply clipped to the back of the keypad using some header pins. (I will post some pictures later).

I discovered three interesting chips inside:

  1. CC2530 Zigbee chip offernig 2.4GHz RF capabilities 
    • CC2530 Key Features
    • THE FREEBOX V6 CONTROLLER INTERNAL PCB
      ZIGBEE RF, GYROSCOPE & ACCELEROMETER
      • Up to 256 KB Flash/8 KB of RAM
      • Excellent link budget (102 dBm)
      • 49 dB adjacent channel rejection (best in class)
      • Four flexible power modes for reduced power consumption
      • Powerful five-channel DMA
    • Key Applications
      • RF remote controls
      • 2.4 GHz IEEE 802.15.4 systems
      • Home and building automation
      • Industrial control and monitoring
      • Set-top boxes
      • Consumer electronics
      • Smart Energy
  2. The STMicro 2128 33DH, a three-axis accelerometer.
    • This is the same accelerometer used by Apple for the iPhone 4S.
  3. A mysterious chip labeled "8130 33DH 08M38"
    • Maybe it's the keypad chip, or a controller... I haven't found anything about it for now.
I was very pleased to discover the Zigbee module because I was plannig to buy one next week, and this one was just sitting here all the time waiting for someone to use it. What a coincidence as I just ordered two books about XBEE from Amazon: 
  1. The Hands-on XBEE Lab Manual: Experiments that Teach you XBEE Wirelesss Communications (By Jonathan A Titus)
  2. Building Wireless Sensor Networks (By Robert Faludi)
Well, i'll leave you there for now, but i'll be back very soon after some further reading about those chips.