Components and supplies
Arduino Nano R3
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Horizon_Avionics.ino
c_cpp
1//RocketryUniverse2019// 2 3 4#include "Wire.h" // This library allows you to communicate with I2C devices. 5int bluePin = 3; 6 7const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69. 8int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data 9int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data 10int16_t temperature; // variables for temperature data 11char tmp_str[7]; // temporary variable used in convert function 12char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor. 13 sprintf(tmp_str, "%6d", i); 14 return tmp_str; 15} 16void setup() { 17 Serial.begin(9600); 18 pinMode(bluePin, OUTPUT); 19 digitalWrite(bluePin, LOW); 20 21 Wire.begin(); 22 Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board) 23 Wire.write(0x6B); // PWR_MGMT_1 register 24 Wire.write(0); // set to zero (wakes up the MPU-6050) 25 Wire.endTransmission(true); 26} 27void loop() { 28 Wire.beginTransmission(MPU_ADDR); 29 Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40] 30 Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active. 31 Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers 32 33 // "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable 34 accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L) 35 accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L) 36 accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L) 37 temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L) 38 gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L) 39 gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L) 40 gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L) 41 42 // print out data 43 Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x)); 44 Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y)); 45 Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z)); 46 // the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30] 47 Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53); 48 Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x)); 49 Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y)); 50 Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z)); 51 Serial.println(); 52 53 if (accelerometer_x < 1000 && accelerometer_y < -8000) { 54 digitalWrite(bluePin, HIGH); 55 56 } else if (accelerometer_x < 1000 && accelerometer_y > 8000) { 57 digitalWrite(bluePin, HIGH); 58 59 } else if (accelerometer_x > 8000 && accelerometer_y < 1000) { 60 digitalWrite(bluePin, HIGH); 61 62 } else if (accelerometer_x < -8000 && accelerometer_y < 1000) { 63 digitalWrite(bluePin, HIGH); 64 65 } else { 66 digitalWrite(bluePin, LOW); 67 68 } 69 // delay 70 delay(200); 71} 72
Horizon_Avionics.ino
c_cpp
1//RocketryUniverse2019// 2 3 4#include "Wire.h" // This library 5 allows you to communicate with I2C devices. 6int bluePin = 3; 7 8const int 9 MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the 10 I2C address will be 0x69. 11int16_t accelerometer_x, accelerometer_y, accelerometer_z; 12 // variables for accelerometer raw data 13int16_t gyro_x, gyro_y, gyro_z; // variables 14 for gyro raw data 15int16_t temperature; // variables for temperature data 16char 17 tmp_str[7]; // temporary variable used in convert function 18char* convert_int16_to_str(int16_t 19 i) { // converts int16 to string. Moreover, resulting strings will have the same 20 length in the debug monitor. 21 sprintf(tmp_str, "%6d", i); 22 return tmp_str; 23} 24void 25 setup() { 26 Serial.begin(9600); 27 pinMode(bluePin, OUTPUT); 28 digitalWrite(bluePin, 29 LOW); 30 31 Wire.begin(); 32 Wire.beginTransmission(MPU_ADDR); // Begins 33 a transmission to the I2C slave (GY-521 board) 34 Wire.write(0x6B); // PWR_MGMT_1 35 register 36 Wire.write(0); // set to zero (wakes up the MPU-6050) 37 Wire.endTransmission(true); 38} 39void 40 loop() { 41 Wire.beginTransmission(MPU_ADDR); 42 Wire.write(0x3B); // starting 43 with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions 44 Revision 4.2, p.40] 45 Wire.endTransmission(false); // the parameter indicates 46 that the Arduino will send a restart. As a result, the connection is kept active. 47 48 Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers 49 50 51 // "Wire.read()<<8 | Wire.read();" means two registers are read and stored 52 in the same variable 53 accelerometer_x = Wire.read()<<8 | Wire.read(); // reading 54 registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L) 55 accelerometer_y = Wire.read()<<8 56 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L) 57 58 accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) 59 and 0x40 (ACCEL_ZOUT_L) 60 temperature = Wire.read()<<8 | Wire.read(); // reading 61 registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L) 62 gyro_x = Wire.read()<<8 63 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L) 64 65 gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) 66 and 0x46 (GYRO_YOUT_L) 67 gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 68 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L) 69 70 // print out data 71 Serial.print("aX 72 = "); Serial.print(convert_int16_to_str(accelerometer_x)); 73 Serial.print(" 74 | aY = "); Serial.print(convert_int16_to_str(accelerometer_y)); 75 Serial.print(" 76 | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z)); 77 // the following 78 equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, 79 p.30] 80 Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53); 81 82 Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x)); 83 Serial.print(" 84 | gY = "); Serial.print(convert_int16_to_str(gyro_y)); 85 Serial.print(" | gZ 86 = "); Serial.print(convert_int16_to_str(gyro_z)); 87 Serial.println(); 88 89 90 if (accelerometer_x < 1000 && accelerometer_y < -8000) { 91 digitalWrite(bluePin, 92 HIGH); 93 94 } else if (accelerometer_x < 1000 && accelerometer_y > 8000) 95 { 96 digitalWrite(bluePin, HIGH); 97 98 } else if (accelerometer_x 99 > 8000 && accelerometer_y < 1000) { 100 digitalWrite(bluePin, HIGH); 101 102 103 } else if (accelerometer_x < -8000 && accelerometer_y < 1000) { 104 digitalWrite(bluePin, 105 HIGH); 106 107 } else { 108 digitalWrite(bluePin, LOW); 109 110 } 111 // 112 delay 113 delay(200); 114} 115
Downloadable files
Schematic
Schematic
Documentation
Omega Flight Computer Holder
Omega Flight Computer Holder
Omega Flight Computer Holder
Omega Flight Computer Holder
Comments
Only logged in users can leave comments
UniverseRobotics
0 Followers
•0 Projects
Table of contents
Intro
7
0