Esempio n. 1
0
void getIMUReadings( ADXL345& a, BMP085& b, HMC5883L& c, L3G4200D& g)
{
	a.readAccel();  					// WORKING
	b.calculateAll(); 				// WORKING		
	g.computeValues();				// appears to be WORKING
	c.readCompassHeading();		// appears to be WORKING
}
Esempio n. 2
0
void getMotionData(Datum *datum) {
  
  acc.getAcceleration(&datum->acc.x, &datum->acc.y, &datum->acc.z);
  mag.getHeading(&datum->mag.x, &datum->mag.y, &datum->mag.z);
  gyr.getRotation(&datum->gyr.x, &datum->gyr.y, &datum->gyr.z);
  
}
Esempio n. 3
0
void MiniBeeV2::setupAccelleroTWI(void) {
#if MINIBEE_REVISION == 'B'
  //setup for ADXL345 Accelerometer
    accel.powerOn();
    accel.setJustifyBit( false );
    accel.setFullResBit( true );
    accel.setRangeSetting( 16 ); // 2: 2g, 4: 4g, 8: 8g, 16: 16g
#endif
    //set rate etc

#if MINIBEE_REVISION == 'A'
    setupTWI();

      //------- LIS302DL setup --------------
      Wire.beginTransmission(accel1Address);
      Wire.send(0x21); // CTRL_REG2 (21h)
      Wire.send(B01000000);
      Wire.endTransmission();
      
	//SPI 4/3 wire
	//1=ReBoot - reset chip defaults
	//n/a
	//filter off/on
	//filter for freefall 2
	//filter for freefall 1
	//filter freq MSB
	//filter freq LSB - Hipass filter (at 400hz) 00=8hz, 01=4hz, 10=2hz, 11=1hz (lower by 4x if sample rate is 100hz)   

      Wire.beginTransmission(accel1Address);
      Wire.send(0x20); // CTRL_REG1 (20h)
      Wire.send(B01000111);
      Wire.endTransmission();
      
	//sample rate 100/400hz
	//power off/on
	//2g/8g
	//self test
	//self test
	//z enable
	//y enable
	//x enable 

      //-------end LIS302DL setup --------------
#endif
}
Esempio n. 4
0
void Cfilterbegin(){
   //Turning on the accelerometer
  Accel.init(ADXL345_ADDR_ALT_LOW);
  Accel.set_bw(ADXL345_BW_12);

  gyro.reset();
  // Use ITG3200_ADDR_AD0_HIGH or ITG3200_ADDR_AD0_LOW as the ITG3200 address 
  // depending on how AD0 is connected on your breakout board, check its schematics for details
  gyro.init(ITG3200_ADDR_AD0_LOW);  
  Serial.print("zeroCalibrating...");
  gyro.zeroCalibrate(2500,2);
  Serial.println("done.");

  alpha = float(TIME_CONSTANT) / (float(TIME_CONSTANT) + float(SAMPLE_RATE)); // calculate the scaling coefficent
  Serial.print("Scaling Coefficent: ");
  Serial.println(alpha); 

  delay(100); 
}
Esempio n. 5
0
void getAccAngle() {

  float acc_data[3];
  Accel.get_Gxyz(acc_data);
  /* The correct calculation
   theta = atan(acc_data[0]/sqrt(acc_data[1]*acc_data[1] + acc_data[2]*acc_data[2]))*180/PI; 
   psi = atan(acc_data[1]/sqrt(acc_data[0]*acc_data[0] + acc_data[2]*acc_data[2]))*180/PI;
   phi=  atan(sqrt(acc_data[0]*acc_data[0] + acc_data[1]*acc_data[1])/acc_data[2])*180/PI; // Not needed since we only care bout x and y
   */
  theta = (acc_data[0]/sqrt(acc_data[1]*acc_data[1] + acc_data[2]*acc_data[2]))*180/PI; //drop atan for computation speed, small angle aproximation
  psi = (acc_data[1]/sqrt(acc_data[0]*acc_data[0] + acc_data[2]*acc_data[2]))*180/PI;
}
Esempio n. 6
0
int setupMotionSensors() {
  
  int error = 0;
  
  // Initialization
  Wire.begin();
  acc.initialize();
  mag.initialize();
  gyr.initialize();
  
  // Verification
  if (!acc.testConnection() ||
      !mag.testConnection() ||
      !gyr.testConnection())
      error = 1;
  
  // Configuration
  acc.setRange(ADXL345_RANGE_16G);
  mag.setMode(HMC5883L_MODE_CONTINUOUS);
    
  return error;
  
}
Esempio n. 7
0
void ExtendoHand::getAcceleration(Vector3D &a) {
    if (nineAxis) {
        int16_t ax, ay, az;
        accel.getAcceleration(&ax, &ay, &az);

        // approximate g values, per calibration with a specific sensor
        a.set(
            ax / 230.0 - 0.05,
            ay / 230.0,
            az / 230.0);
    } else {
#ifdef THREE_AXIS
        a.set(
            motionSensor.accelX(),
            motionSensor.accelY(),
            motionSensor.accelZ());
#endif // THREE_AXIS
    }
}
Esempio n. 8
0
/// reading LIS302DL
void MiniBeeV2::readAccelleroTWI( int dboff ){

  int accx, accy, accz;
  unsigned int accx2, accy2, accz2;
#if MINIBEE_REVISION == 'A'
    /// reading LIS302DL
    data[dboff]   = readTWI( accel1Address, accelResultX, 1 ) + 128 % 256;
    data[dboff+1] = readTWI( accel1Address, accelResultY, 1 ) + 128 % 256;
    data[dboff+2] = readTWI( accel1Address, accelResultZ, 1 ) + 128 % 256;
#endif

    /// reading ADXL345 Accelerometer
#if MINIBEE_REVISION == 'B'
    accel.readAccel( &accx, &accy, &accz );
    accx2 = (unsigned int) (accx + 4096); // from twos complement signed int to unsigned int
    accy2 = (unsigned int) (accy + 4096); // from twos complement signed int to unsigned int
    accz2 = (unsigned int) (accz + 4096); // from twos complement signed int to unsigned int
    dataFromInt( accx2, dboff );
    dataFromInt( accy2, dboff+2 );
    dataFromInt( accz2, dboff+4 );
#endif
}
Esempio n. 9
0
void ExtendoHand::setupOther() {
    if (nineAxis) {
        // adjust the power settings after you call this method if you want the accelerometer
        // to enter standby mode, or another less demanding mode of operation
        accel.setRange(1); // 4g
        accel.setFullResolution(1); // maintain 4mg/LSB scale factor (irrespective of range)
        accel.initialize();
        if (!accel.testConnection()) {
            osc.sendError("ADXL345 connection failed");
        } else {
            randomSeed(accel.getAccelerationX() - accel.getAccelerationY() + accel.getAccelerationZ());
        }

#ifdef ENABLE_GYRO
        gyro.initialize();
        if (!gyro.testConnection()) {
            osc.sendError("ITG3200 connection failed");
        }
#endif // ENABLE_GYRO

#ifdef ENABLE_MAGNETOMETER
        magnet.initialize();
        if (!magnet.testConnection()) {
            osc.sendError("HMC5883L connection failed");
        }
#endif // ENABLE_MAGNETOMETER
    } else {
#ifdef THREE_AXIS
        randomSeed(motionSensor.rawX() + motionSensor.rawY() + motionSensor.rawZ());

        // 1.5g constants, sampled 2014-06-21
        motionSensor.calibrateX(272, 794);
        motionSensor.calibrateY(332, 841);
        motionSensor.calibrateZ(175, 700);
#endif // THREE_AXIS
    }

    vibrateStart = 0;
    alertStart = 0;
}
Esempio n. 10
0
void ExtendoHand::onLoopTimeUpdated(double loopTime) {
    if (nineAxis) {
        // the sensor's sampling rate should exceed Extend-o-Hand's loop rate
        uint8_t sampleRate = loopTime <= 0.00125
            ? 0xe  // 1600 Hz
            : loopTime <= 0.0025
            ? 0xd  // 800 Hz
            : 0xc; // 400 Hz

        // uncomment only for development
        //osc.sendInfo("setting sensor sampling rate to %d based on loop time of %d micros",
        //    sampleRate, (int)(loopTime*1000000));

        // adjust the power settings after you call these methods if you want the sensors
        // to enter standby mode, or another less demanding mode of operation
        accel.setRate(sampleRate);
#ifdef ENABLE_GYRO
        gyro.setRate(sampleRate);
#endif // ENABLE_GYRO
#ifdef ENABLE_MAGNETOMETER
        magnet.setDataRate(sampleRate);
#endif // ENABLE_MAGNETOMETER
    }
}
Esempio n. 11
0
int main(int argc, char **argv)
{ 
 	const char *fileName = "/dev/i2c-1";
   	int 		countdown 		= 0;
   	int 		blink 			= 1;
   	float 		timeStep		= 83.33;	
   	int 		printTerminal 	= 1;
   	
    int 		fd;// File description
	string 		buttonInput;
	
	float lastBlink		= 0.0f;
	bool  isOnLED		= false;
		
	float 	timeStamp	= 0.0f;
	int		delay		= 0;
	
	CTimeClass timer;
	Logger logger;
	
   	ADXL345 	acc;
   	BMP085 		baro;
   	L3G4200D 	gyro;
   	HMC5883L 	compass;
   	    
   	GPIOClass 	gpioLED("17");
	GPIOClass 	gpioButton("4");

	// init GPIOs
	gpioLED.export_gpio();
	gpioButton.export_gpio();
	
	gpioLED.setdir_gpio("out"); //GPIO4 set to output
    gpioButton.setdir_gpio("in"); // GPIO17 set to input
    
    // switch off LED just in case
    gpioLED.setval_gpio("0");
    
	// parse input arguments
	if( argc > 1 ) {
		parseArgv( countdown, blink, timeStep, printTerminal, argc, argv );	
		
		printf("c = %d, b = %d, t = %f, p = %d\n", countdown, blink, timeStep, printTerminal);
	}
	
    // init i2c
   	if(!init(&fd, fileName)) {
		exit(1);
	}
   	
   	// wait for a little
   	usleep(100000);

    // init imu
   	acc.init(&fd, ((int) ((1000/timeStep)+0.5)), timeStep);
	baro.init(&fd);
	compass.init(&fd);
	gyro.init(&fd, ((int) ((1000/timeStep)+0.5)));
		
	if( countdown > 0 ) {
		waitUntilButton(gpioButton, gpioLED, countdown, blink );	
	}
	
	timer.init();
	
	if( logger.openLogFile( timeStep, timer ) == false ) {
		exit( 1 );
	}
			
	printf("GO\n");
	
	for(;;) {	
		// read current Time
		timer.computeStartTime();
		
		getIMUReadings( acc, baro, compass, gyro );

		timer.computeTime( timeStamp );
				
		// print data to file																						MATLAB:						    1		   2	  3 	  4            5             6                7                    8       			9					 10				 	  11			    12		      13			14			   15			16			  17		18		    19			   20			   21
		fprintf(logger.fp, "%d, %4d %4d %4d %.2f %.2f %.2f %.2f %5.3f %5.3f %5.3f %5.3f %5.3f %d %d %d %5.3f %5.3f %5.3f %5.3f %5.3f\n", ((int) timeStamp), gyro.x, gyro.y, gyro.z, compass.heading, baro.altitude, baro.pressure / 100, baro.temperature, acc.accKalman[ X ], acc.accKalman[ Y ], acc.accKalman[ Z ], acc.acc[ Z ], acc.magnitude, acc.zeroX[X], acc.zeroX[Y], acc.zeroX[Z], acc.pitch, acc.roll, acc.deriv2[X], acc.deriv2[Y], acc.deriv2[Z]);
	
		//fprintf(logger.fp, "%d %5d %5d %5d %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n", ((int) timeStamp), acc.raw[0], acc.raw[1], acc.raw[2], acc.acc[ 0 ], acc.acc[ 1 ], acc.acc[ 2 ], acc.accKalman[ 0 ], acc.accKalman[ 1 ], acc.accKalman[ 2 ]); //, acc.movingAverage[ 0 ], acc.movingAverage[ 1 ],acc.movingAverage[ 2 ]);
		
		if( printTerminal == 1 ) {
			printf("%d, %4d %4d %4d %.2f %.2f %.2f %.2f %5.3f %5.3f %5.3f %5.3f %5.3f %d %d %d %5.3f %5.3f\n", ((int) timeStamp), gyro.x, gyro.y, gyro.z, compass.heading, baro.altitude, baro.pressure / 100, baro.temperature, acc.accKalman[ X ], acc.accKalman[ Y ], acc.accKalman[ Z ], acc.acc[ Z ], acc.magnitude,acc.zeroX[X], acc.zeroX[Y], acc.zeroX[Z], acc.pitch, acc.roll);
		}
		
		// see if user wants to quit
		gpioButton.getval_gpio(buttonInput);
		
		// button pressed, so exit program
		if( buttonInput == "0" ) {
			printf("Exiting\n");	
			break;
		}
		
		timer.computeEndTime();
						
		// delay in microseconds
	  	delay = ( timeStep * 1000 ) - timer.getElapsedMilliseconds() * 1000;
		
		// sleep by 'delay' in order to have periodic readings
		if( delay > 0 ) {
			usleep(delay);
		}
		
		// sleep 1ms
		else {
			usleep(1000);
		}
		
		// if blink is set to ON
		if( blink == 1 ){ 
			static float endTime;
			
			endTime = timer.getEndTime();
			blinkLED( gpioLED, endTime, lastBlink, isOnLED, 888 );	    
		}
   	}
   	
   	gpioLED.setval_gpio("0");
   	
   	printf("bye bye\n");
   	
	return 0;
}
Esempio n. 12
0
/*
 * Main Loop 
 */
void loop() {
	wdt_reset();
	mD.vals.uslCount++;									//Increment main datarecord count
	AccelerometerScaled Ascaled = accel.ReadScaledAxis();	//Get Scaled Accelerometer
	AccelerometerRaw Araw = accel.ReadRawAxis();			//Get Raw Accelerometer
	MagnetometerScaled Mscaled = compass.ReadScaledAxis();	//Get Scaled Magnetometer
	MagnetometerRaw Mraw = compass.ReadRawAxis();			//Get Raw Magnetometer
	LGgyro.read();											//Get Gyro

	// offset compass by hard iron
	Mraw.XAxis += 40;
	Mraw.YAxis += 261;
	Mraw.ZAxis += 54;

	//write Acc, Mag, & Gyro values to record
	float AxisGs = Ascaled.XAxis;
	mD.vals.AcXPayload = AxisGs * 100;
	AxisGs = Ascaled.YAxis;
	mD.vals.AcYPayload = AxisGs * 100;
	AxisGs = Ascaled.ZAxis;
	mD.vals.AcZPayload = AxisGs * 100;
	mD.vals.MgXPayload = Mscaled.XAxis;
	mD.vals.MgYPayload = Mscaled.YAxis;
	mD.vals.MgZPayload = Mscaled.ZAxis;
	mD.vals.GyXPayload = LGgyro.g.x;
	mD.vals.GyYPayload = LGgyro.g.y;
	mD.vals.GyZPayload = LGgyro.g.z;

	//Perform tilt compensation calculation save to record
	sixDOF.compCompass(Mraw.XAxis, -Mraw.YAxis, -Mraw.ZAxis, Araw.XAxis, Araw.YAxis, Araw.ZAxis, true);
	float compHeading = sixDOF.atan2Int(sixDOF.xAxisComp(), sixDOF.yAxisComp());
	compHeading = compHeading /100;
	if (compHeading < 0 ) {
		compHeading = abs(compHeading);
	} else {
		compHeading = 180 - compHeading + 180;
	}
	mD.vals.CmpssPayload = compHeading;
	
	//get BMP085 values save to record
	dps.getTemperature(&TmpPayloadFULL); 
	dps.getPressure(&mD.vals.PressurePayload);

 	mD.vals.TmpPayload = (int16_t)(TmpPayloadFULL);	
	mD.vals.TmpExternal = (int16_t)(sensors.getTempC(outsideThermometer)* 10);
	sensors.requestTemperaturesByAddress(outsideThermometer); // Send the command to get temperatures
	
	//get GPS data
	byte lcount = 0;									//reset a loop counter
	while (!NEWGPSDATA && lcount++ < 255) {				//Exit the loop if we have new data or have been round it a number of times
		NEWGPSDATA = feedgps();							
	}
	if (NEWGPSDATA) {									//We have new GPS data, get all of the fields we need.
		int tmp_year = 0;
		gps.crack_datetime(&tmp_year, &mD.vals.month, &mD.vals.day,&mD.vals.hour, &mD.vals.minute, &mD.vals.second, &mD.vals.hundredths, &mD.vals.age);
		mD.vals.year = tmp_year - 2000;
		
        if (gps.altitude() != TinyGPS_HJOE::GPS_INVALID_ALTITUDE && gps.altitude() >= 0) {
			gps.get_position(&mD.vals.iLat, &mD.vals.iLong, &mD.vals.age);
			mD.vals.iAlt = gps.altitude(); 
			mD.vals.iAngle = gps.course();
			mD.vals.iHspeed = gps.speed(); 
			mD.vals.bSats = gps.satellites();
			mD.vals.ihdop = gps.hdop();
		}
		SET_LED_Status(SET_LED_BLUE,0);					//Flash blue to show we are getting GPS data
	} else {
		SET_LED_Status(SET_LED_GREEN,0);				//Flash Green to show that we are looping but not getting GPS data
	}

	if(ETSerialIn.receiveData()){

	}
  
	//flip flop between I2C's to avoid both on one loop
	if (SENDWIRE && (millis() - elapseSIM900) > WAIT_SIM900) {
		mD.vals.tCount++;
		ETI2Cout.sendData(I2C_SLV_SIM900_ADDRESS);		
		elapseSIM900 = millis();
	}

	if (!SENDWIRE && (millis() - elapseNTXB) > WAIT_NTXB) {
		mD.vals.tCount++;
		ETI2Cout.sendData(I2C_SLV_NTXB_ADDRESS);
		elapseNTXB = millis();
		//get I2C_SLV_SIM900_ADDRESS data
	}

	writeSDData();										//Write the data record to the SD card
	SET_LED_Status(SET_LED_OFF,0);						//turn off the LED
	NEWGPSDATA = false;									//Reset the New GPS Data flag
	SENDWIRE = !SENDWIRE;								//Flipflop this 
}
Esempio n. 13
0
/*
 * Setup 
 */
void setup() {
	wdt_enable(WDTO_8S);
	wdt_reset();
	//Setup Ports
	Serial.begin(115200);				//Start Debug Serial 0
	Serial1.begin(9600); 				//Start GPS Serial 1
	Serial2.begin(9600);
 
	pinMode(PIN_LED_GREEN, OUTPUT);		//Blue GREEN
	pinMode(PIN_LED_RED, OUTPUT);		//Blue RED
	pinMode(PIN_LED_BLUE, OUTPUT);		//Blue LED
	pinMode(PIN_SPI_CS,OUTPUT);  		//Chip Select Pin for the SD Card
	pinMode(10, OUTPUT);				//SDcard library expect 10 to set set as output.
	
	// Initialise the GPS
	wdt_disable();
	gps.init();						
	gps.configureUbloxSettings();		// Configure Ublox for MY_HIGH altitude mode
	wdt_enable(WDTO_8S);
	// join I2C bus //start I2C transfer to the Module/Transmitter
	Wire.begin();
	//Set up the two EasyTransfer methods
	ETI2Cout.begin(details(mD.i2cOut), &Wire);	//setup the data structure to transfer out
	ETSerialIn.begin(details(vals), &Serial2);
	
	//Start up the LGgyro
    if (LGgyro.init()) {
		#ifdef DEBUG_ON	
			Serial.println("LGgyro OK");
		#endif
		LGgyro.enableDefault();
	} else {
		#ifdef DEBUG_ON	
			Serial.println("LGgyro not working");
		#endif
		SET_LED_Status(SET_LED_WHITE,500); 	//White LED
		SET_LED_Status(SET_LED_RED,1000); 	//Red LED 
	}

	//Start up the accelerometer
	accel = ADXL345(); 						// Create an instance of the accelerometer
	if(accel.EnsureConnected()) {			// Check that the accelerometer is connected.
		#ifdef DEBUG_ON	
			Serial.println("Connected to ADXL345.");
		#endif		
		accel.SetRange(2, true);				// Set the range of the accelerometer to a maximum of 2G.
		accel.EnableMeasurements();				// Tell the accelerometer to start taking measurements.		
	} else{
		#ifdef DEBUG_ON	
			Serial.println("Could not connect to ADXL345.");
		#endif
		SET_LED_Status(SET_LED_WHITE,500); 	//White LED
		SET_LED_Status(SET_LED_RED,2000); 	//Red LED 
	}

	//Start up the compass
	compass = HMC5883L(); 						// Construct a new HMC5883 compass.
	#ifdef DEBUG_ON	
		if(compass.EnsureConnected() == 1) {
			Serial.println("Connected to HMC5883L.");
		} else {
			Serial.println("Not Connected to HMC5883L.");
		}
	#endif
	error = compass.SetScale(1.3); 				// Set the scale of the compass.
	#ifdef DEBUG_ON	
		if(error != 0) {							// If there is an error, print it out.
			Serial.println("Compass Error 1");
			Serial.println(compass.GetErrorText(error));
		} else {
			Serial.println("Compass Ok 1");
		}
	#endif
	error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
	#ifdef DEBUG_ON	
		if(error != 0) {							// If there is an error, print it out.
			Serial.println("Compass error 2");
			Serial.println(compass.GetErrorText(error));
		} else {
			Serial.println("Compass Ok 2");
		}
	#endif	
	
	//Start up the Pressure Sensor
	dps = BMP085();
	dps.init(); 
	#ifdef DEBUG_ON
		Serial.print("BMP Mode ");
		Serial.println(dps.getMode());
	#endif	
	wdt_reset();
	// Start up the OneWire Sensors library and turn off blocking takes too long!
	sensors.begin();
	sensors.setWaitForConversion(false);
  	sensors.requestTemperaturesByAddress(outsideThermometer); // Send the command to get temperature
	
	//Initialise all of the record values
	mD.vals.tCount = 0;
	mD.vals.uslCount = 0;
	mD.vals.year = 0;
	mD.vals.month = 0;
	mD.vals.day = 0;
	mD.vals.hour = 0;
	mD.vals.minute = 0;
	mD.vals.second = 0;
	mD.vals.hundredths = 0;
	mD.vals.iLat = 0;
	mD.vals.iLong = 0;
	mD.vals.iAlt = 0;
	mD.vals.bSats = 0;
	mD.vals.iAngle = 0;
	mD.vals.iHspeed = 0;
	mD.vals.iVspeed = 0;
	mD.vals.age = 0;
	mD.vals.ihdop = 0;
	mD.vals.AcXPayload = 0;
	mD.vals.AcYPayload = 0;
	mD.vals.AcZPayload = 0;
	mD.vals.GyXPayload = 0;
	mD.vals.GyYPayload = 0;
	mD.vals.GyZPayload = 0;
	mD.vals.MgXPayload = 0;
	mD.vals.MgYPayload = 0;
	mD.vals.MgZPayload = 0;
	mD.vals.TmpPayload = 0;
	
	//Connect to the SD Card	
	if(!SD.begin(PIN_SPI_CS, SPI_HALF_SPEED)) {
		#ifdef DEBUG_ON	
			Serial.println("SD not working!!");
		#endif 
		SET_LED_Status(SET_LED_WHITE,500); 	//White LED
		SET_LED_Status(SET_LED_RED,3000); 	//Red LED 
	} else {
		#ifdef DEBUG_ON	
			Serial.println("SD OK");
		#endif 	
		dataFile.open(SD_LOG_FILE, O_CREAT | O_WRITE | O_APPEND);	    //Open Logfile
		if (!dataFile.isOpen()) {
			#ifdef DEBUG_ON	
				Serial.println("SD Data File Not Opened");
			#endif 	
			SET_LED_Status(SET_LED_WHITE,500);
			SET_LED_Status(SET_LED_RED,3000);
		}
	}

	//Cycle lights
	SET_LED_Status(SET_LED_OFF,0);  
	SET_LED_Status(SET_LED_RED,500);
	SET_LED_Status(SET_LED_GREEN,500);
	SET_LED_Status(SET_LED_BLUE,500);
	SET_LED_Status(SET_LED_OFF,0);  
	
	elapseSIM900 = millis();				//Elapse counter for data to SIM900
	elapseNTXB = millis();					//Elapse counter for data to NTXB
	NEWGPSDATA = false;
	wdt_enable(WDTO_2S);
	wdt_reset();
}
Esempio n. 14
0
void setup(void){
  int x, y, z, i;
  double xyz[3], gains[3], gains_orig[3];

  Serial.begin(57600);
  Serial.println("");
  accel.powerOn();
  
  accel.getAxisGains(gains_orig);
  Serial.println("gains_orig[]:");
  for(i = 0; i < 3; i++){
    Serial.print(gains_orig[i], 6);
    Serial.print(" ");
  }
  Serial.println("");
  
  gains[0] = .1;
  gains[1] = 1.1;
  gains[2] = 2.1;
  accel.setAxisGains(gains);
  accel.getAxisGains(gains);
  Serial.println("set gains[]:");
  for(i = 0; i < 3; i++){
    Serial.print(gains[i]);
    Serial.print(" ");
  }
  Serial.println("");

  accel.setAxisGains(gains_orig);
  accel.getAxisGains(gains);
  Serial.println("original gains?");
  for(i = 0; i < 3; i++){
    Serial.print(gains[i], 6);
    Serial.print(" ");
  }
  Serial.println("");
    
  accel.readAccel(&x, &y, &z);
  Serial.print("XYZ COUNTS: ");
  Serial.print(x, DEC);
  Serial.print(" ");
  Serial.print(y, DEC);
  Serial.print(" ");
  Serial.print(z, DEC);
  Serial.println("");

  accel.get_Gxyz(xyz);
  Serial.print("XYZ Gs: ");
  for(i = 0; i<3; i++){
    Serial.print(xyz[i], DEC);
    Serial.print(" ");
  }
  Serial.println("");

  accel.setTapThreshold(1);
  Serial.print("getTapThreshold(): ");
  Serial.println(accel.getTapThreshold(), DEC);
  
  accel.setAxisOffset(2, 3, 4);
  Serial.print("getAxisOffset(&x, &y, &z): ");
  accel.getAxisOffset(&x, &y, &z);
  Serial.print(x);
  Serial.print(" ");
  Serial.print(y);
  Serial.print(" ");
  Serial.print(z);
  Serial.println("");

  accel.setTapDuration(5);
  Serial.print("getTapDuration(): ");
  Serial.println(accel.getTapDuration(), DEC);

  accel.setDoubleTapLatency(6);
  Serial.print("getDoubleTapLatency(): ");
  Serial.println(accel.getDoubleTapLatency(), DEC);

  accel.setDoubleTapWindow(7);
  Serial.print("getDoubleTapWindow() ");
  Serial.println(accel.getDoubleTapWindow());

  accel.setActivityThreshold(8);
  Serial.print("getActivityThreshold() ");
  Serial.println(accel.getActivityThreshold(), DEC);

  accel.setInactivityThreshold(9);
  Serial.print("getInactivityThreshold() ");
  Serial.println(accel.getInactivityThreshold(), DEC);

  accel.setTimeInactivity(10);
  Serial.print("getTimeInactivity(): ");
  Serial.println(accel.getTimeInactivity());

  accel.setFreeFallThreshold(11);
  Serial.print("getFreeFallThreshold(): ");
  Serial.println(accel.getFreeFallThreshold());

  accel.setFreeFallDuration(12);
  Serial.print("getFreeFallDuration(): ");
  Serial.println(accel.getFreeFallDuration(), DEC);

  Serial.print("isActivityXEnabled(): ");
  Serial.println(accel.isActivityXEnabled(), DEC);

  Serial.print("isActivityYEnabled(): ");
  Serial.println(accel.isActivityYEnabled(), DEC);

  Serial.print("isActivityZEnabled(): ");
  Serial.println(accel.isActivityZEnabled(), DEC);

  Serial.print("isInactivityXEnabled(): ");
  Serial.println(accel.isInactivityXEnabled(), DEC);

  Serial.print("isInactivityYEnabled(): ");
  Serial.println(accel.isInactivityYEnabled(), DEC);

  Serial.print("isInactivityZEnabled(): ");
  Serial.println(accel.isInactivityZEnabled(), DEC);

  Serial.print("isActivityAc(): ");
  Serial.println(accel.isInactivityAc(), DEC);

  accel.setActivityAc(true);
  accel.setInactivityAc(true);

  accel.setSuppressBit(true);
  Serial.print("getSuppressBit(); true? ");
  Serial.println(accel.getSuppressBit());

  accel.setSuppressBit(false);
  Serial.print("getSuppressBit(); false? ");
  Serial.println(accel.getSuppressBit());
  
  accel.setTapDetectionOnX(true);
  Serial.print("isTapDetectionOnX(); true? ");
  Serial.println(accel.isTapDetectionOnX(), DEC);
  accel.setTapDetectionOnX(false);
  Serial.print("isTapDetectionOnX(); false? ");
  Serial.println(accel.isTapDetectionOnX(), DEC);

  accel.setTapDetectionOnY(true);
  Serial.print("isTapDetectionOnY(); true? ");
  Serial.println(accel.isTapDetectionOnY(), DEC);
  accel.setTapDetectionOnY(false);
  Serial.print("isTapDetectionOnY(); false? ");
  Serial.println(accel.isTapDetectionOnY(), DEC);

  accel.setTapDetectionOnZ(true);
  Serial.print("isTapDetectionOnZ(); true? ");
  Serial.println(accel.isTapDetectionOnZ(), DEC);
  accel.setTapDetectionOnZ(false);
  Serial.print("isTapDetectionOnZ(); false? ");
  Serial.println(accel.isTapDetectionOnZ(), DEC);

  accel.setActivityX(true);
  accel.setActivityY(true);
  accel.setActivityZ(true);

  accel.setInactivityX(false);
  accel.setInactivityY(false);
  accel.setInactivityZ(false);

  Serial.print("isActivitySourceOnX(): ");
  Serial.println(accel.isActivitySourceOnX(), DEC);

  Serial.print("accel.isActivitySourceOnY(): ");
  Serial.println(accel.isActivitySourceOnY(), DEC);

  Serial.print("accel.isActivitySourceOnZ(): ");
  Serial.println(accel.isActivitySourceOnZ(), DEC);

  Serial.print("accel.isTapSourceOnX(): ");
  Serial.println(accel.isTapSourceOnX(), DEC);

  Serial.print("accel.isTapSourceOnY(): ");
  Serial.println(accel.isTapSourceOnY(), DEC);

  Serial.print("accel.isTapSourceOnZ(): ");
  Serial.println(accel.isTapSourceOnZ(), DEC);

  Serial.print("accel.isAsleep(): ");
  Serial.println(accel.isAsleep(), DEC);

  Serial.print("accel.isLowPower(): ");
  Serial.println(accel.isLowPower(), DEC);
  accel.setLowPower(false);
  
  accel.setRate(3.14159);
  Serial.print("getRate(): 3.14159?");
  Serial.println(accel.getRate());

  Serial.print("getInterruptSource(): ");
  Serial.println(accel.getInterruptSource(), DEC);

  Serial.print("getInterruptSource(1): ");
  Serial.println(accel.getInterruptSource(1), DEC);
  
  Serial.print("getInterruptMapping(1): ");
  Serial.println(accel.getInterruptMapping(1), DEC);
  
  accel.setInterruptMapping(1, true);
  Serial.print("isInterruptEnabled(1): ");
  Serial.println(accel.isInterruptEnabled(1));
  
  accel.setInterrupt(1, true);

  accel.setSelfTestBit(false);
  Serial.print("getSelfTestBit(): ");
  Serial.println(accel.getSelfTestBit(), DEC);

  accel.printAllRegister();
  
}