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