Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kerero committed May 30, 2019
2 parents c38189a + 9f38410 commit e31fac2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arduino/calibration_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
center: 17100 750 -1500
fwd: -5000
aft: 5000
left: -6000
right: 3500
5 changes: 5 additions & 0 deletions arduino/calibration_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
center: 17100 750 -1500
fwd: -5000
aft: 5000
left: -6000
right: 3500
68 changes: 68 additions & 0 deletions arduino/src/gyroboard_v2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// (c) Michael Schoeffler 2017, http://www.mschoeffler.de

#include "Wire.h" // This library allows you to communicate with I2C devices.

//-----------------bluetooth----------------------
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
//-----------------bluetooth----------------------

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.
const int NUM_OF_VARS = 3;

int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data

char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
sprintf(tmp_str, "%6d", i);
return tmp_str;
}

void setup() {
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);

//-----------------bluetooth----------------------
BTserial.begin(9600);
//-----------------bluetooth----------------------
}
void loop() {
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
Wire.requestFrom(MPU_ADDR, NUM_OF_VARS * 2, true); // request a total of 7*2=14 registers

// "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)

// print out data
Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));

Serial.println();


//-----------------bluetooth----------------------
BTserial.print(convert_int16_to_str(accelerometer_x));
BTserial.print(",");
BTserial.print(convert_int16_to_str(accelerometer_y));
BTserial.print(",");
BTserial.print(convert_int16_to_str(accelerometer_z));
BTserial.print(";");
//-----------------bluetooth----------------------

/* if(Serial.available()){
Serial.print("chicka is best girl");
} */

// delay
delay(20);
}

0 comments on commit e31fac2

Please sign in to comment.