IMU wiring 5vVIN Gnd SCL-A5, SDA-A4 From UNO to servos Signal to servos 9,11,13
Again I dont know how to do this but thought it could be done one of two ways or both
1. Transmit the servo signals via xBee then have an UNO receive the signals and move the servos
2. Transmit the IMU data via xBee then have the UNO utilize the data and move the servos
Here is the code which works OK standalone
Code: Select all#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_10DOF.h>
#include <Servo.h>
/* Assign a unique ID to the sensors */
Adafruit_10DOF dof = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(18001);
/* Update this with the correct SLP for accurate altitude measurements */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
/**************************************************************************/
/*!
@brief Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
if(!accel.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
while(1);
}
if(!mag.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
while(1);
}
if(!bmp.begin())
{
/* There was a problem detecting the BMP180 ... check your connections */
Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
while(1);
}
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
int servoPin = 9;
Servo servo;
int pos = 0;
int servoPin2 = 13;
Servo servo2;
int pos2 = 0;
int servoPin3 = 11;
Servo servo3;
int pos3 = 0;
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Adafruit 10 DOF Pitch/Roll/Heading Example")); Serial.println("");
servo.attach(9);
servo2.attach(13);
servo3.attach(11);
/* Initialise the sensors */
initSensors();
}
/**************************************************************************/
/*!
@brief Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
sensors_event_t accel_event;
sensors_event_t mag_event;
sensors_event_t bmp_event;
sensors_vec_t orientation;
/* Calculate pitch and roll from the raw accelerometer data */
accel.getEvent(&accel_event);
if (dof.accelGetOrientation(&accel_event, &orientation))
{
/* 'orientation' should have valid .roll and .pitch fields */
Serial.print(F("Roll: "));
Serial.print(orientation.roll);
Serial.print(F("; "));
Serial.print(F("Pitch: "));
Serial.print(orientation.pitch);
Serial.print(F("; "));
/* Calculate the heading using the magnetometer */
mag.getEvent(&mag_event);
if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
/* 'orientation' should have valid .heading data now */
Serial.print(F("Heading: "));
Serial.print(orientation.heading);
Serial.println(F(""));
delay(1);
{
int cameraPos = orientation.roll + 90;
servo.write(cameraPos);
int cameraPos2 = orientation.pitch + 90;
servo2.write(cameraPos2);
int cameraPos3 = orientation.heading - 180;
servo3.write(cameraPos3);
}}}