somebody correct me if im wrong connection of 9dof imu sensor stick ( sparkfun ) , arduino micro board..
my connection:
imu : arduino
scl : digital pin 3
sda : digital pin 2
gnd : gnd
vcc : 3v
with 2 4.7k ohms pull-up resistor each of sda scl pin 3v.
i need confirmation here please.
thank in advance!
my connection:
imu : arduino
scl : digital pin 3
sda : digital pin 2
gnd : gnd
vcc : 3v
with 2 4.7k ohms pull-up resistor each of sda scl pin 3v.
i need confirmation here please.
thank in advance!
code: [select]
#include <adafruit_sensor.h>
#include <wire.h>
#define adxl345_address (0xa6 >> 1)
#define adxl345_register_xlsb (0x32)
#define adxl_register_pwrctl (0x2d)
#define adxl_pwrctl_measure (1 << 3)
#define itg3200_address (0xd0 >> 1)
#define itg3200_register_xmsb (0x1d)
#define itg3200_register_dlpf_fs (0x16)
#define itg3200_fullscale (0x03 << 3)
#define itg3200_42hz (0x03)
#define hmc5843_address (0x3c >> 1)
#define hmc5843_register_xmsb (0x03)
#define hmc5843_register_measmode (0x02)
#define hmc5843_measmode_cont (0x00)
int accelerometer_data[3];
int gyro_data[3];
int magnetometer_data[3];
char c;
void setup() {
wire.begin();
serial.begin(9600);
for(int = 0; < 3; ++i) {
accelerometer_data[i] = magnetometer_data[i] = gyro_data[i] = 0;
}
init_adxl345();
init_hmc5843();
init_itg3200();
}
void loop() {
read_adxl345();
serial.print("accel: ");
serial.print(accelerometer_data[0]);
serial.print("\t");
serial.print(accelerometer_data[1]);
serial.print("\t");
serial.print(accelerometer_data[2]);
serial.print("\t");
read_hmc5843();
serial.print("mag: ");
serial.print(magnetometer_data[0]);
serial.print(",");
serial.print(magnetometer_data[1]);
serial.print(",");
serial.print(magnetometer_data[2]);
serial.print("\t");
read_itg3200();
serial.print("gyro: ");
serial.print(gyro_data[0]);
serial.print("\t");
serial.print(gyro_data[1]);
serial.print("\t");
serial.print(gyro_data[2]);
serial.print("\n");
delay(100);
}
void i2c_write(int address, byte reg, byte data) {
wire.begintransmission(address);
wire.write(reg);
wire.write(data);
wire.endtransmission();
}
void i2c_read(int address, byte reg, int count, byte* data) {
int = 0;
wire.begintransmission(address);
wire.write(reg);
wire.endtransmission();
wire.begintransmission(address);
wire.requestfrom(address,count);
while(wire.available()){
c = wire.read();
data[i] = c;
i++;
}
wire.endtransmission();
}
void init_adxl345() {
byte data = 0;
i2c_write(adxl345_address, adxl_register_pwrctl, adxl_pwrctl_measure);
i2c_read(adxl345_address, adxl_register_pwrctl, 1, &data);
serial.println((unsigned int)data);
}
void read_adxl345() {
byte bytes[6];
memset(bytes,0,6);
i2c_read(adxl345_address, adxl345_register_xlsb, 6, bytes);
for (int i=0;i<3;++i) {
accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
}
}
void init_itg3200() {
byte data = 0;
i2c_write(itg3200_address, itg3200_register_dlpf_fs, itg3200_fullscale | itg3200_42hz);
i2c_read(itg3200_address, itg3200_register_dlpf_fs, 1, &data);
serial.println((unsigned int)data);
}
void read_itg3200() {
byte bytes[6];
memset(bytes,0,6);
i2c_read(itg3200_address, itg3200_register_xmsb, 6, bytes);
for (int i=0;i<3;++i) {
gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
}
void init_hmc5843() {
byte data = 0;
i2c_write(hmc5843_address, hmc5843_register_measmode, hmc5843_measmode_cont);
i2c_read(hmc5843_address, hmc5843_register_measmode, 1, &data);
serial.println((unsigned int)data);
}
void read_hmc5843() {
byte bytes[6];
memset(bytes,0,6);
i2c_read(hmc5843_address, hmc5843_register_xmsb, 6, bytes);
for (int i=0;i<3;++i) {
magnetometer_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
}
correct..
connect scl pin on breakout scl pin on arduino. on uno & '328 based arduino, known a5, on mega known digital 21 , on leonardo/micro, digital 3
connect sda pin on breakout sda pin on arduino. on uno & '328 based arduino, known a4, on mega known digital 20 , on leonardo/micro, digital 2
connect vin pin on breakout 3.3v or 5v on uno (5v preferred if have 3v logic arduino 3v best)
connect gnd pin on breakout gnd pin on uno
that's it! 4 wires, should able talk of i2c chips on board , run of example sketches.
https://learn.adafruit.com/adafruit-9-dof-imu-breakout/connecting-it-up
connect scl pin on breakout scl pin on arduino. on uno & '328 based arduino, known a5, on mega known digital 21 , on leonardo/micro, digital 3
connect sda pin on breakout sda pin on arduino. on uno & '328 based arduino, known a4, on mega known digital 20 , on leonardo/micro, digital 2
connect vin pin on breakout 3.3v or 5v on uno (5v preferred if have 3v logic arduino 3v best)
connect gnd pin on breakout gnd pin on uno
that's it! 4 wires, should able talk of i2c chips on board , run of example sketches.
https://learn.adafruit.com/adafruit-9-dof-imu-breakout/connecting-it-up
Arduino Forum > Using Arduino > Project Guidance > IMU 9Dof with Arduino Micro
arduino
Comments
Post a Comment