|
|
|
@ -1,14 +1,16 @@
|
|
|
|
|
|
|
|
// code for Pro Micro or STM32 on the CubeSat Simulator STEM Payload board
|
|
|
|
|
|
|
|
// answers "OK" on the serial port Serial1 when queried by the Pi
|
|
|
|
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
#include <Adafruit_BME280.h>
|
|
|
|
#include <Adafruit_BME280.h>
|
|
|
|
#include <MPU6050_tockn.h>
|
|
|
|
#include <MPU6050_tockn.h>
|
|
|
|
#include <EEPROM.h>
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
|
|
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
|
|
|
|
|
|
|
|
|
|
|
Adafruit_BME280 bme;
|
|
|
|
Adafruit_BME280 bme;
|
|
|
|
MPU6050 mpu6050(Wire);
|
|
|
|
MPU6050 mpu6050(Wire);
|
|
|
|
|
|
|
|
|
|
|
|
long timer = 0;
|
|
|
|
long timer = 0;
|
|
|
|
int bmePresent;
|
|
|
|
int bmePresent;
|
|
|
|
int RXLED = 17; // The RX LED has a defined Arduino pin
|
|
|
|
int RXLED = 17; // The RX LED has a defined Arduino pin
|
|
|
|
@ -20,24 +22,35 @@ void eeprom_word_write(int addr, int val);
|
|
|
|
short eeprom_word_read(int addr);
|
|
|
|
short eeprom_word_read(int addr);
|
|
|
|
int first_time = true;
|
|
|
|
int first_time = true;
|
|
|
|
int first_read = true;
|
|
|
|
int first_read = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
float T2 = 26.3; // Temperature data point 1
|
|
|
|
float T2 = 26.3; // Temperature data point 1
|
|
|
|
float R2 = 167; // Reading data point 1
|
|
|
|
float R2 = 167; // Reading data point 1
|
|
|
|
float T1 = 2; // Temperature data point 2
|
|
|
|
float T1 = 2; // Temperature data point 2
|
|
|
|
float R1 = 179; // Reading data point 2
|
|
|
|
float R1 = 179; // Reading data point 2
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
|
|
|
|
float T2 = 25; // Temperature data point 1
|
|
|
|
|
|
|
|
float R2 = 671; // Reading data point 1
|
|
|
|
|
|
|
|
float T1 = 15.5; // Temperature data point 2
|
|
|
|
|
|
|
|
float R1 = 695; // Reading data point 2
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
int sensorValue;
|
|
|
|
int sensorValue;
|
|
|
|
float Temp;
|
|
|
|
float Temp;
|
|
|
|
float rest;
|
|
|
|
float rest;
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
|
|
|
|
|
|
|
|
Serial.begin(9600); // Serial Monitor for testing
|
|
|
|
Serial.begin(9600); // Serial Monitor for testing
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.begin(115200); // Pi UART faster speed
|
|
|
|
Serial1.begin(115200); // Pi UART faster speed
|
|
|
|
|
|
|
|
// Serial1.begin(9600); // Pi UART faster speed
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Starting!");
|
|
|
|
Serial.println("Starting!");
|
|
|
|
|
|
|
|
|
|
|
|
blink_setup();
|
|
|
|
blink_setup();
|
|
|
|
|
|
|
|
|
|
|
|
blink(500);
|
|
|
|
blink(500);
|
|
|
|
delay(250);
|
|
|
|
delay(250);
|
|
|
|
blink(500);
|
|
|
|
blink(500);
|
|
|
|
@ -48,70 +61,143 @@ void setup() {
|
|
|
|
led_set(blueLED, HIGH);
|
|
|
|
led_set(blueLED, HIGH);
|
|
|
|
delay(250);
|
|
|
|
delay(250);
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
|
|
|
|
|
|
|
|
if (bme.begin(0x76)) {
|
|
|
|
if (bme.begin(0x76)) {
|
|
|
|
bmePresent = 1;
|
|
|
|
bmePresent = 1;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
|
|
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
|
|
|
bmePresent = 0;
|
|
|
|
bmePresent = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mpu6050.begin();
|
|
|
|
mpu6050.begin();
|
|
|
|
|
|
|
|
|
|
|
|
if (eeprom_word_read(0) == 0xA07)
|
|
|
|
if (eeprom_word_read(0) == 0xA07)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Serial.println("Reading gyro offsets from EEPROM\n");
|
|
|
|
Serial.println("Reading gyro offsets from EEPROM\n");
|
|
|
|
|
|
|
|
|
|
|
|
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
|
|
|
|
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
|
|
|
|
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
|
|
|
|
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
|
|
|
|
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
|
|
|
|
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println(xOffset, DEC);
|
|
|
|
Serial.println(xOffset, DEC);
|
|
|
|
Serial.println(yOffset, DEC);
|
|
|
|
Serial.println(yOffset, DEC);
|
|
|
|
Serial.println(zOffset, DEC);
|
|
|
|
Serial.println(zOffset, DEC);
|
|
|
|
|
|
|
|
|
|
|
|
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
|
|
|
|
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
|
|
|
|
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
|
|
|
|
|
|
|
|
|
|
|
|
mpu6050.calcGyroOffsets(true);
|
|
|
|
mpu6050.calcGyroOffsets(true);
|
|
|
|
|
|
|
|
|
|
|
|
eeprom_word_write(0, 0xA07);
|
|
|
|
eeprom_word_write(0, 0xA07);
|
|
|
|
eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5);
|
|
|
|
eeprom_word_write(1, (int)(mpu6050.getGyroXoffset() * 100.0) + 0.5);
|
|
|
|
eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5);
|
|
|
|
eeprom_word_write(2, (int)(mpu6050.getGyroYoffset() * 100.0) + 0.5);
|
|
|
|
eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
|
|
|
|
eeprom_word_write(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println(eeprom_word_read(0), HEX);
|
|
|
|
Serial.println(eeprom_word_read(0), HEX);
|
|
|
|
Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC);
|
|
|
|
Serial.println(((float)eeprom_word_read(1)) / 100.0, DEC);
|
|
|
|
Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC);
|
|
|
|
Serial.println(((float)eeprom_word_read(2)) / 100.0, DEC);
|
|
|
|
Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC);
|
|
|
|
Serial.println(((float)eeprom_word_read(3)) / 100.0, DEC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pinMode(greenLED, OUTPUT);
|
|
|
|
/**/
|
|
|
|
pinMode(blueLED, OUTPUT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Serial1.available() > 0) {
|
|
|
|
|
|
|
|
blink(50);
|
|
|
|
|
|
|
|
char result = Serial1.read();
|
|
|
|
|
|
|
|
// Serial1.println(result);
|
|
|
|
|
|
|
|
// Serial1.println("OK");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (result == '?')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bmePresent) {
|
|
|
|
|
|
|
|
Serial1.print("OK BME280 ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readTemperature());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readPressure() / 100.0F);
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readHumidity());
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mpu6050.update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" MPU6050 ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroX());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroY());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroZ());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccX());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccY());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccZ());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sensorValue = read_analog();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Serial.println(sensorValue);
|
|
|
|
|
|
|
|
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" XS ");
|
|
|
|
|
|
|
|
Serial1.print(Temp);
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.println(Sensor2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
|
|
|
|
|
|
|
|
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
|
|
|
|
|
|
|
|
// Serial.print(rotation);
|
|
|
|
|
|
|
|
// Serial.print(" ");
|
|
|
|
|
|
|
|
// Serial.println(acceleration);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (first_read == true) {
|
|
|
|
|
|
|
|
first_read = false;
|
|
|
|
|
|
|
|
rest = acceleration;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (acceleration > 1.2 * rest)
|
|
|
|
|
|
|
|
led_set(greenLED, HIGH);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
led_set(greenLED, LOW);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rotation > 5)
|
|
|
|
|
|
|
|
led_set(blueLED, HIGH);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((Serial.available() > 0)|| first_time == true) {
|
|
|
|
if (Serial.available() > 0) {
|
|
|
|
blink(50);
|
|
|
|
blink(50);
|
|
|
|
char result = Serial.read();
|
|
|
|
char result = Serial.read();
|
|
|
|
// Serial.println(result);
|
|
|
|
// Serial.println(result);
|
|
|
|
|
|
|
|
// Serial.println("OK");
|
|
|
|
if (result == 'R') {
|
|
|
|
// Serial.println(counter++);
|
|
|
|
Serial.println("OK");
|
|
|
|
|
|
|
|
|
|
|
|
if (result == 'R') {
|
|
|
|
|
|
|
|
Serial1.println("OK");
|
|
|
|
delay(100);
|
|
|
|
delay(100);
|
|
|
|
first_time = true;
|
|
|
|
first_read = true;
|
|
|
|
setup();
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result == 'C') {
|
|
|
|
else if (result == 'C') {
|
|
|
|
Serial.println("Clearing stored gyro offsets in EEPROM\n");
|
|
|
|
Serial.println("Clearing stored gyro offsets in EEPROM\n");
|
|
|
|
eeprom_word_write(0, 0x00);
|
|
|
|
eeprom_word_write(0, 0x00);
|
|
|
|
first_time = true;
|
|
|
|
first_time = true;
|
|
|
|
setup();
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((result == '?') || first_time == true)
|
|
|
|
|
|
|
|
|
|
|
|
if ((result == '?') || first_time == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
first_time = false;
|
|
|
|
first_time = false;
|
|
|
|
if (bmePresent) {
|
|
|
|
if (bmePresent) {
|
|
|
|
@ -128,113 +214,44 @@ void loop() {
|
|
|
|
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
|
|
|
|
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mpu6050.update();
|
|
|
|
mpu6050.update();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(" MPU6050 ");
|
|
|
|
Serial.print(" MPU6050 ");
|
|
|
|
Serial.print(mpu6050.getGyroX());
|
|
|
|
Serial.print(mpu6050.getGyroX());
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(mpu6050.getGyroY());
|
|
|
|
Serial.print(mpu6050.getGyroY());
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(mpu6050.getGyroZ());
|
|
|
|
Serial.print(mpu6050.getGyroZ());
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(mpu6050.getAccX());
|
|
|
|
Serial.print(mpu6050.getAccX());
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(mpu6050.getAccY());
|
|
|
|
Serial.print(mpu6050.getAccY());
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(mpu6050.getAccZ());
|
|
|
|
Serial.print(mpu6050.getAccZ());
|
|
|
|
|
|
|
|
|
|
|
|
sensorValue = analogRead(A3);
|
|
|
|
|
|
|
|
//Serial.println(sensorValue);
|
|
|
|
|
|
|
|
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sensorValue = read_analog();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print(" XS ");
|
|
|
|
Serial.print(" XS ");
|
|
|
|
Serial.print(Temp);
|
|
|
|
Serial.print(Temp);
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.print(" ");
|
|
|
|
Serial.println(Sensor1);
|
|
|
|
Serial.print(Sensor2);
|
|
|
|
|
|
|
|
Serial.print(" (");
|
|
|
|
|
|
|
|
Serial.print(sensorValue);
|
|
|
|
|
|
|
|
Serial.println(")");
|
|
|
|
|
|
|
|
|
|
|
|
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
|
|
|
|
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
|
|
|
|
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
|
|
|
|
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
|
|
|
|
// Serial.print(rotation);
|
|
|
|
// Serial.print(rotation);
|
|
|
|
// Serial.print(" ");
|
|
|
|
// Serial.print(" ");
|
|
|
|
// Serial.println(acceleration);
|
|
|
|
// Serial.println(acceleration);
|
|
|
|
|
|
|
|
|
|
|
|
if (acceleration > 1.2)
|
|
|
|
|
|
|
|
led_set(greenLED, HIGH);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
led_set(greenLED, LOW);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rotation > 5)
|
|
|
|
|
|
|
|
led_set(blueLED, HIGH);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Serial1.available() > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blink(50);
|
|
|
|
|
|
|
|
char result = Serial1.read();
|
|
|
|
|
|
|
|
// Serial1.println(result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result == 'R') {
|
|
|
|
|
|
|
|
Serial1.println("OK");
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
first_read = true;
|
|
|
|
|
|
|
|
setup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result == '?')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bmePresent) {
|
|
|
|
|
|
|
|
Serial1.print("OK BME280 ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readTemperature());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readPressure() / 100.0F);
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(bme.readHumidity());
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mpu6050.update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" MPU6050 ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroX());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroY());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getGyroZ());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccX());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccY());
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.print(mpu6050.getAccZ());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sensorValue = analogRead(A3);
|
|
|
|
|
|
|
|
//Serial.println(sensorValue);
|
|
|
|
|
|
|
|
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial1.print(" XS ");
|
|
|
|
|
|
|
|
Serial1.print(Temp);
|
|
|
|
|
|
|
|
Serial1.print(" ");
|
|
|
|
|
|
|
|
Serial1.println(Sensor2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float rotation = sqrt(mpu6050.getGyroX()*mpu6050.getGyroX() + mpu6050.getGyroY()*mpu6050.getGyroY() + mpu6050.getGyroZ()*mpu6050.getGyroZ());
|
|
|
|
|
|
|
|
float acceleration = sqrt(mpu6050.getAccX()*mpu6050.getAccX() + mpu6050.getAccY()*mpu6050.getAccY() + mpu6050.getAccZ()*mpu6050.getAccZ());
|
|
|
|
|
|
|
|
// Serial.print(rotation);
|
|
|
|
|
|
|
|
// Serial.print(" ");
|
|
|
|
|
|
|
|
// Serial.println(acceleration);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (first_read == true) {
|
|
|
|
if (first_read == true) {
|
|
|
|
first_read = false;
|
|
|
|
first_read = false;
|
|
|
|
rest = acceleration;
|
|
|
|
rest = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (acceleration > 1.2 * rest)
|
|
|
|
if (acceleration > 1.2 * rest)
|
|
|
|
led_set(greenLED, HIGH);
|
|
|
|
led_set(greenLED, HIGH);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@ -245,22 +262,21 @@ void loop() {
|
|
|
|
else
|
|
|
|
else
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
led_set(blueLED, LOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
// delay(100);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void eeprom_word_write(int addr, int val)
|
|
|
|
void eeprom_word_write(int addr, int val)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
EEPROM.write(addr * 2, lowByte(val));
|
|
|
|
EEPROM.write(addr * 2, lowByte(val));
|
|
|
|
EEPROM.write(addr * 2 + 1, highByte(val));
|
|
|
|
EEPROM.write(addr * 2 + 1, highByte(val));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
short eeprom_word_read(int addr)
|
|
|
|
short eeprom_word_read(int addr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
|
|
|
|
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void blink_setup()
|
|
|
|
void blink_setup()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
@ -269,7 +285,7 @@ void blink_setup()
|
|
|
|
pinMode(PB9, OUTPUT);
|
|
|
|
pinMode(PB9, OUTPUT);
|
|
|
|
pinMode(PB8, OUTPUT);
|
|
|
|
pinMode(PB8, OUTPUT);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
pinMode(RXLED, OUTPUT); // Set RX LED as an output
|
|
|
|
pinMode(RXLED, OUTPUT); // Set RX LED as an output
|
|
|
|
// TX LED is set as an output behind the scenes
|
|
|
|
// TX LED is set as an output behind the scenes
|
|
|
|
@ -277,30 +293,30 @@ void blink_setup()
|
|
|
|
pinMode(blueLED,OUTPUT);
|
|
|
|
pinMode(blueLED,OUTPUT);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void blink(int length)
|
|
|
|
void blink(int length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level)
|
|
|
|
digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
digitalWrite(RXLED, LOW); // set the RX LED ON
|
|
|
|
digitalWrite(RXLED, LOW); // set the RX LED ON
|
|
|
|
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
|
|
|
|
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
delay(length); // wait for a lenth of time
|
|
|
|
delay(length); // wait for a lenth of time
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW
|
|
|
|
digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
digitalWrite(RXLED, HIGH); // set the RX LED OFF
|
|
|
|
digitalWrite(RXLED, HIGH); // set the RX LED OFF
|
|
|
|
TXLED0; //TX LED macro to turn LED ON
|
|
|
|
TXLED0; //TX LED macro to turn LED ON
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void led_set(int ledPin, bool state)
|
|
|
|
void led_set(int ledPin, bool state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
@ -309,8 +325,20 @@ void led_set(int ledPin, bool state)
|
|
|
|
else if (ledPin == blueLED)
|
|
|
|
else if (ledPin == blueLED)
|
|
|
|
digitalWrite(PB8, state);
|
|
|
|
digitalWrite(PB8, state);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
digitalWrite(ledPin, state);
|
|
|
|
digitalWrite(ledPin, state);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int read_analog()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int sensorValue;
|
|
|
|
|
|
|
|
#if defined __AVR_ATmega32U4__
|
|
|
|
|
|
|
|
sensorValue = analogRead(A3);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
|
|
|
|
|
|
|
|
sensorValue = analogRead(PA7);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return(sensorValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|