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.

Thursday, June 10, 2010

Getting my Vaio SD card reader working

SD

root@vaio ~$
lspci |grep Ricoh
03:00.0 SD Host controller: Ricoh Co Ltd Device e822
03:00.1 System peripheral: Ricoh Co Ltd Device e230
03:00.3 FireWire (IEEE 1394): Ricoh Co Ltd Device e832
03:00.4
SD Host controller: Ricoh Co Ltd Device e822
root@vaio ~$ lspci -v
03:00.0 SD Host controller: Ricoh Co Ltd Device e822
Subsystem: Sony Corporation Device 9072
Flags: bus master, fast devsel, latency 0, IRQ 17
Memory at e6603000 (32-bit, non-prefetchable) [size=256]
Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
Capabilities: [78] Power Management version 3
Capabilities: [80] Express Endpoint, MSI 00
Capabilities: [100] Virtual Channel
Capabilities: [800] Advanced Error Reporting
Kernel driver in use: sdhci-pci
Kernel modules: sdhci-pci

03:00.4 SD Host controller: Ricoh Co Ltd Device e822
Subsystem: Sony Corporation Device 9072
Flags: bus master, fast devsel, latency 0, IRQ 19
Memory at e6600000 (32-bit, non-prefetchable) [size=256]
Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
Capabilities: [78] Power Management version 3
Capabilities: [80] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Kernel driver in use: sdhci-pci
Kernel modules: sdhci-pci
root@vaio ~$ lsmod | egrep 'mmc|ricoh|sdhci'
sdhci_pci 6910 0
sdhci 17430 1 sdhci_pci
mmc_core 59134 1 sdhci



SD

Sunday, June 6, 2010

Orange 3G+ on Fedora Linux 13 (Orange Tunisie)

Ce dimanche, je passe ma journee avec ma nouvelle cle 3G+ Orange que j'ai gagne la semaine derniere au Barcamp.
Comme tout bon geek qui se respecte, je commence naturellement par la demonter afin d'examiner de plus pres l'interieur. Au fait, j'ai pense que je pourrai bien l'integrer a l'interieur de mon pc portable afin de gagner plus d'espace et d'ergonomie. (je detaillerai ceci avec des photos tres prochainement dans un post). A ma grande surprise (Et en meme cela ne m'etonne guere), je me rends compte que le guide d'installation n'affiche pas du tout GNU/Linux dans la liste des OS compatibles... Commence alors une belle journee :)

Je commence par brancher la cle 3G, celle-ci s'allume et la diode commence a clignotter en vert (2 fois toutes les 3 secondes).
J'effectue un lsusb afin de verifier l'etat de la cle, puis je lance un cat /proc/bus/usb/devices afin d'avoir plus de details sur notre cle. Ceci nous confirme que notre cle est a comme Vendor et ProdID 12d1:141b Maintenant que j'ai les ID, je debranche la cle et j'installe usb_modeswitch en effectuant un yum install usb_modswitch*

USB_ModeSwitch est un outil de switch (changement) de mode pour des clefs USB à fonctions multiples.

Plusieurs nouvelles clefs USB contiennent leur propre driver MS Windows; quand on les insère pour la première fois, ces périphériques agissent comme un périphérique de stockage et installent leur driver. Après cela (et ceci à chaque nouvelle insertion de la clef) ce driver commute (switch) le mode interne, le périphérique de stockage disparait (dans la majorité des cas), et un nouveau périphérique (tel un modem USB) apparaît. Le fabriquant de clés WWAN Option appelle ce dispositif "ZeroCD (TM)".

C'est d'ailleurs pour cette raison que lorsqu'on branche notre cle 3G, l'OS la reconnait en tant que peripherique de stockage. Il est ensuite necessaire de verifier la presence du fichier 12d1:1466 dans le dossier /etc/usb_modeswitch.d/ Pour cela on effectue un ls /etc/usb_modeswitch.d/ Ce fichier devrait etre present suite a l'installation de usm_modeswitch par yum, s'il n'est pas la, il suffit de le creer et d'y ajouter le code suivant:

########################################################
# Huawei, newer modems
DefaultVendor= 0x12d1
DefaultProduct=0x1446
TargetVendor= 0x12d1TargetProductList="1001,1406,140c,141b,14ac"
CheckSuccess=20

MessageContent="55534243123456780000000000000011060000000000000000000000000000"

Maintenat je rebranche ma cle, cette fois-ci elle n'est plus detectee comme Disk, mais plutot comme un modem 3G/HSDPA. Une fois la sim inseree, la cle passe d'un clignottement vert a un clignottement bleu toutes les 3 secondes indiquant que la cle est prete a se connecter au reseau UMTS.

Il ne nous reste plus qu'ajouter une novelle connexion Mobile Broadband.




















Une fois la connexion cree, revenir dans ses proprietes afin de specifier l'APN (l'offre Orange que vous avez souscrit). Celle ci a comme valeur 'keygp' si vous avez souscrit a l'offre l'internet Everywhere, et 'keypro' si vous avez souscrit l'offre Internet everywhere Premium.
Note: Ces valeurs sont mentionnees dans le fichier 'Offres_Lang0009.xml' se trouvant dans le dossier d'installation de la cle (il faut decompresser le setup.exe pour voir le contenu, ou regarder dans le dossier /Program files/InternetEverywhere ).

Il est preferable de specifier aussi le code pin de la sim (0000 par defaut)
Il ne nous reste plus qu'essayer de connecter notre cle. Une fois la connexion etablie, notre clee s'allume d'une jolie couleur bleue continue.


Et pour finir, juste pour le plaisir, voici quelques details interessants:
root@vaio ~$ lsusb -v

Bus 002 Device 024: ID 12d1:141b Huawei Technologies Co., Ltd.
Device Descriptor: bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x12d1 Huawei Technologies Co., Ltd. idProduct 0x141b
bcdDevice 0.00
iManufacturer 3 HUAWEI Technology
iProduct 2 HUAWEI Mobile
iSerial 4 1234567890ABCDEF
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2 wTotalLength 85
bNumInterfaces 3
bConfigurationValue 1
iConfiguration 1 Huawei Configuration
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 500mA
Interface Descriptor: bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0 Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes
bInterval 5
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 32
Endpoint Descriptor: bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 32
Interface Descriptor:
bLength 9
bDescriptorType 4 bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7 bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 32
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 32
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk (Zip)
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x03 EP 3 OUT
bmAttributes 2
Transfer Type Bulk Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84 EP 4 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes bInterval 0

Contenu d'un snooping du port USB, effectue par wireshark.

Fichier1: snoop1_plain.txt
Fichier2: snoop2_pdml.xml
Fichier3: snoop3_psml.xml