FRIENDz

FAILURE IS THE SIGN OF SUCCESS!!

Detecting Rotation Using a Gyroscope

Arduino-Detecting Rotation Using a Gyroscope:
         Most low-cost gyroscopes use an analog voltage proportional to rotation rate, although some also  output using I2C. This recipe works with a gyro with an analog output proportional to rotation rate. Figure 6-16 shows an LISY300AL breakout board from SparkFun. Many low-cost gyros, such as the one used here, are 3.3V devices and must not be plugged into the 5V power pin.The Gyro OUT connection is the analog output and is connected to Arduino analog input 0. The PD connection enables the gyro to be switched into low power mode and is connected to analog pin 1 (in this sketch, it is used as a digital output pin). You can connect PD to any digital pin; the pin used here was chosen to keep the wiring neater. If you don’t need to switch the gyro into low-power mode, you can connect the PD line to Gnd.


This sketch sets the powerDownPin to LOW to get the gyro running in normal mode.The loop code reads the gyro value on analog pin 0 and displays this on the Serial Monitor.

Gyro sketch displays the rotation rate on the Serial Monitor

const int inputPin = 0; // analog input 0
const int powerDownPin = 15; // analog input 1 is digital input 15
int rotationRate = 0;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
pinMode(powerDownPin, OUTPUT);
digitalWrite(powerDown, LOW); // gyro not in power down mode
}
void loop()
{
rotationRate = analogRead(inputPin); // read the gyro output
Serial.print("rotation rate is ");
Serial.println(rotation rate);
delay(100); // wait 100ms for next reading
}

The sketch uses the Serial Monitor to show which button is pressed:

PSX sketch Display joystick and button values uses PSX library written by Kevin Ahrendt
http://www.arduino.cc/playground/Main/PSXLibrary

#include <wProgram.h>
#include <Psx.h> // Includes the Psx Library
Psx Psx; // Create an instance of the Psx library
const int dataPin = 5;
const int cmndPin = 4;
const int attPin = 3;
const int clockPin = 2;
const int psxDelay = 50; // determine the clock delay in microseconds
unsigned int data = 0; // data stores the controller response
void setup()
{
// initialize the Psx library
Psx.setupPins(dataPin, cmndPin, attPin, clockPin, psxDelay);
Serial.begin(9600); // results will be displayed on the Serial Monitor
}
void loop()
{
data = Psx.read(); // get the psx controller button data
// check the button bits to see if a button is pressed
if(data & psxLeft)
Serial.println("left button");
if(data & psxDown)
Serial.println("down button");
if(data & psxRight)
Serial.println("right button");
if(data & psxUp)
Serial.println("up button");
if(data & psxStrt)
Serial.println("start button");
if(data & psxSlct)
Serial.println("select button");
delay(100);
}
        Game controllers provide information in many different ways. Most recent controllers contain chips that read the switches and joystick in the controller and communicate the information using a protocol depending on the game platform. Older controllers are more likely to give direct access to switches and joysticks using connectors with many connections. The latest wave of game platforms uses USB as the connection. These are more difficult to work with using Arduino.

2 comments:

  1. Can any one help me to implement the code without the use of hardware that means any software tool...please help me...

    ReplyDelete
  2. You can check your code (.hex /.elf) by using proteus software.

    ReplyDelete