2DOF Flight Simulator Cockpit

I have been working on this moving ‘cockpit’ for MS Flight Sim.  It’s not done, but is starting to become real. 

It’s based on the Joyrider, but made out of aluminum as I was looking for a tig welding project.

The original Joyrider design uses a mechanical link between the seat, the frame, and a control stick to move the whole seat.  Then you attach a PC joystick to the seat, and have the joystick control the game.   My plan is to go a little bit fancier and add motors to both axes of the device, so that the PC (FSX) actually tells the seat how to move.   This kind of thing is partly what interested me about Arduino.  A physical computing platform is key to a project like this.

If you’re interested in this sort of thing, there are a lot of sites that go into more detail.  Two of my favorites:

http://www.x-simulator.de/forum/
http://buggies.builtforfun.co.uk/Sim/index.html

Early photos attached.  Don’t mind the mess.

Arduino Digital Compass

See the previous entry for details on hooking up and talking to the LCD.   This adds an HMC6352 heading sensor, and writes heading on the LCD (which was no small task, at least for me). 

Hooking up the compass:
VCC and GND go right to the bus on my breadboard (coming from the Arduino)
SDA -> Analog 4
SCL -> Analog 5

I read a lot about pull up resistors being required, but found someone’s sample where that was not done, so tried it just like specified above, and it worked.   We don’t need no stinkin’ resistors.  

It took me a lot of hacking to get the format of the heading number correctly left zero padded.   I’m sure there’s a better way than what I’ve got here, but this is the best I could do.   I’d kill for a String.format(); 

And the code:

   1:  // -- For the LCD (Though the newer LiquidCrystal library is much easier to use, IMHO)
   2:  #include  <LCD4Bit.h> 
   3:   
   4:  //create object to control an LCD.  
   5:  //number of lines in display=1
   6:  LCD4Bit lcd = LCD4Bit(2); 
   7:   
   8:  // -- For the Compass
   9:  #include <Wire.h>
  10:  int HMC6352Address = 0x42;
  11:   
  12:  // This is calculated in the setup() function
  13:  int slaveAddress;
  14:  int i, headingValue;
  15:   
  16:  void setup() { 
  17:   
  18:    lcd.init();
  19:    lcd.clear();
  20:    writeLcd("Initializing...", 2, 0, true);
  21:   
  22:    // set up the compass 
  23:    slaveAddress = HMC6352Address >> 1;   // This results in 0x21 as the address to pass to TWI
  24:   
  25:    Wire.begin();
  26:    
  27:    writeLcd("Reading...", 2, 0, true); 
  28:    writeLcd("Hdg: ", 1, 0, false);
  29:  }
  30:   
  31:  // Main loop
  32:  void loop() {  
  33:     updateDisplay();
  34:  }
  35:   
  36:  // write to the LCD at a defined position
  37:  void writeLcd(char data[], int line, int pos, bool clear)
  38:  {
  39:    // clear if desired
  40:    if(clear == true)
  41:    {
  42:      lcd.clear();
  43:    }
  44:   
  45:    lcd.cursorTo(line, pos);
  46:    lcd.printIn(data);
  47:    delay(10);
  48:  }
  49:   
  50:  // just keep going wherever the cursor was
  51:  void appendLcd(char data[])
  52:  {
  53:    lcd.printIn(data);
  54:  }
  55:   
  56:  void updateDisplay()
  57:  {
  58:    byte headingData[2];
  59:    
  60:    // ask the compass for a heading
  61:    Wire.beginTransmission(slaveAddress);
  62:    Wire.send("A");              // The "Get Data" command
  63:    Wire.endTransmission();
  64:    delay(10);             
  65:    
  66:    // The HMC6352 needs at least a 70us (microsecond) delay
  67:    // after this command.  Using 10ms just makes it safe
  68:    // Read the 2 heading bytes, MSB first
  69:    // The resulting 16bit word is the compass heading in 10th's of a degree
  70:    // For example: a heading of 1345 would be 134.5 degrees
  71:    
  72:    Wire.requestFrom(slaveAddress, 2);        // Request the 2 byte heading (MSB comes first)
  73:    i = 0;  
  74:    while(Wire.available() && i < 2)
  75:    { 
  76:      headingData[i] = Wire.receive();
  77:      i++;
  78:    }
  79:     
  80:    headingValue =  headingData[0]*256 + headingData[1];  // Put the MSB and LSB together
  81:        
  82:    int firstPart = headingValue / 10;
  83:    int secondPart = headingValue % 10;
  84:    char buffer[4];
  85:    
  86:    // first write to the LCD.  Set the cursor
  87:    lcd.cursorTo(1, 5); 
  88:   
  89:    // brute force zero padding 
  90:    if(headingValue <= 999)
  91:    {
  92:      appendLcd("0"); // pad with a leading zero
  93:    }
  94:    
  95:    if(headingValue <= 99)
  96:    {
  97:      appendLcd("0");
  98:    }
  99:    
 100:    appendLcd(itoa((firstPart), buffer, 10));  // convert the int to a string and write the degrees
 101:    appendLcd(".");    // decimal point
 102:    appendLcd(itoa((secondPart), buffer, 10));  // and the tenths
 103:   
 104:   delay (750);
 105:  }

Arduino_digitalCompass.wmv (12.66 mb)

 

Hooking up a parallel LCD to an Arduino

 

 

I have a little compass sensor, and what I want out of that is to make a hand held electronic compass, but I needed something to do some displaying.  Found some examples with parallel LCDs, so decided to give that a shot.  This doesn’t do much, but it will get you going with this LCD.

LCD: Newhaven NHD-0216K1Z-FSB-FBW-L
Datasheet: http://www.newhavendisplay.com/specs/NHD-0216K1Z-FSB-FBW-L.pdf

Here are all of the connections I made. 

LCD Pins

Assignment

Arduino Pins

Wire Color (That I Used)

1

GND

GND

Black

2

VDD

5V

Red

3

V0

10k Pot  (Contrast)

Blue

4

RS

11

Green

5

RW

GND

Black

6

E

12

Yellow

7

DB0

 

 

8

DB1

 

 

9

DB2

 

 

10

DB3

 

 

11

DB4

7

Green

12

DB5

8

Yellow

13

DB6

9

Green

14

DB7

10

Yellow

15

A

5V (Backlight)

Red

16

K

GND?

Black

Note that one side lead from the pot goes to ground, the other side to 5v, and the middle lead on the pot goes to the blue wire from the table above.  

The excellent tutorial on ladyada.net will get you through the code.  I won’t repeat that here. 

http://www.ladyada.net/learn/arduino/lcd.html

A very short video: 

Arduino-LCD.wmv (2.03 mb)