rename arduino directory stempayload

pull/100/head
Alan Johnston 5 years ago
parent 375e55021a
commit 4574295029

@ -1,78 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13
*/
/* Pro Micro Test Code
by: Nathan Seidle
modified by: Jim Lindblom
SparkFun Electronics
date: September 16, 2013
license: Public Domain - please use this code however you'd like.
It's provided as a learning tool.
This code is provided to show how to control the SparkFun
ProMicro's TX and RX LEDs within a sketch. It also serves
to explain the difference between Serial.print() and
Serial1.print().
*/
int RXLED = 17; // The RX LED has a defined Arduino pin
// Note: The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
// (We could use the same macros for the RX LED too -- RXLED1,
// and RXLED0.)
// the setup function runs once when you press reset or power the board
void setup() {
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
// initialize digital pin PB1 as an output.
pinMode(PC13, OUTPUT);
#endif
#if defined __AVR_ATmega32U4__
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
#endif
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
#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)
#endif
#if defined __AVR_ATmega32U4__
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
#endif
Serial.println("LED is on!");
delay(1000); // wait for a second
#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
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED1; //TX LED macro to turn LED ON
#endif
Serial.println("LED is off!");
delay(1000); // wait for a second
}

@ -1,45 +0,0 @@
/* Pro Micro Test Code
by: Nathan Seidle
modified by: Jim Lindblom
SparkFun Electronics
date: September 16, 2013
license: Public Domain - please use this code however you'd like.
It's provided as a learning tool.
This code is provided to show how to control the SparkFun
ProMicro's TX and RX LEDs within a sketch. It also serves
to explain the difference between Serial.print() and
Serial1.print().
*/
int RXLED = 17; // The RX LED has a defined Arduino pin
// Note: The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
// (We could use the same macros for the RX LED too -- RXLED1,
// and RXLED0.)
void setup()
{
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
Serial.begin(9600); //This pipes to the serial monitor
Serial.println("Initialize Serial Monitor");
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
Serial1.println("Initialize Serial Hardware UART Pins");
}
void loop()
{
Serial.println("Hello world!"); // Print "Hello World" to the Serial Monitor
Serial1.println("Hello! Can anybody hear me?"); // Print "Hello!" over hardware UART
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
delay(1000); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED1; //TX LED macro to turn LED ON
delay(1000); // wait for a second
}

@ -1,32 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PB1 as an output.
pinMode(PC13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

@ -1,46 +0,0 @@
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
long timer = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop() {
mpu6050.update();
if(millis() - timer > 1000){
Serial.println("=======================================================");
Serial.print("temp : ");Serial.println(mpu6050.getTemp());
Serial.print("accX : ");Serial.print(mpu6050.getAccX());
Serial.print("\taccY : ");Serial.print(mpu6050.getAccY());
Serial.print("\taccZ : ");Serial.println(mpu6050.getAccZ());
Serial.print("gyroX : ");Serial.print(mpu6050.getGyroX());
Serial.print("\tgyroY : ");Serial.print(mpu6050.getGyroY());
Serial.print("\tgyroZ : ");Serial.println(mpu6050.getGyroZ());
Serial.print("accAngleX : ");Serial.print(mpu6050.getAccAngleX());
Serial.print("\taccAngleY : ");Serial.println(mpu6050.getAccAngleY());
Serial.print("gyroAngleX : ");Serial.print(mpu6050.getGyroAngleX());
Serial.print("\tgyroAngleY : ");Serial.print(mpu6050.getGyroAngleY());
Serial.print("\tgyroAngleZ : ");Serial.println(mpu6050.getGyroAngleZ());
Serial.print("angleX : ");Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");Serial.println(mpu6050.getAngleZ());
Serial.println("=======================================================\n");
timer = millis();
}
}

@ -1,51 +0,0 @@
//#define TESTING // Uncomment to test code on Serial Monitor
int counter = 0;
int RXLED = 17; // The RX LED has a defined Arduino pin
void setup() {
#ifdef TESTING
Serial.begin(9600);
#endif
Serial1.begin(9600);
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
}
void loop() {
#ifdef TESTING // ? is sent over Serial Monitor for testing
if (Serial.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial.read();
// Serial1.println(result);
Serial.println("OK");
// Serial1.println(counter++);
}
#else // ? is sent by Pi UART
if (Serial1.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial1.read();
// Serial1.println(result);
Serial1.println("OK");
// Serial1.println(counter++);
}
#endif
delay(100);
}

@ -1,28 +0,0 @@
// code for STM32F104C on the CubeSat Simulator STEM Payload board
// answers "OK" on the serial port when queried by the Pi
int counter = 0;
void setup() {
Serial1.begin(9600);
pinMode(PC13, OUTPUT);
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
}
void loop() {
if (Serial1.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial1.read();
// Serial1.println(result);
Serial1.println("OK");
// Serial1.println(counter++);
}
delay(100);
}

@ -1,256 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
#define SEALEVELPRESSURE_HPA (1013.25)
//#define TESTING // Define to test on Serial Monitor
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
int counter = 0;
int RXLED = 17; // The RX LED has a defined Arduino pin
long timer = 0;
int bmePresent;
int greenLED = 9;
int blueLED = 8;
int Sensor1 = 0;
int Sensor2 = 0;
float Sensor3 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(9600); // Pi UART
Serial.println("Starting!");
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
{
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1))/100.0;
float yOffset = ((float)eeprom_word_read(2))/100.0;
float zOffset = ((float)eeprom_word_read(3))/100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
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(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
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(3))/100.0, DEC);
}
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
digitalWrite(greenLED, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(blueLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(greenLED, LOW); // turn the LED off by making the voltage LOW
digitalWrite(blueLED, LOW); // turn the LED on (HIGH is the voltage level)
}
void loop() {
#ifdef TESTING
if (Serial.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial.read();
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
}
if (result == '?')
{
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" ");
Serial.print(mpu6050.getAccX());
Serial.print(" ");
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
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 (acceleration > 1.2)
digitalWrite(greenLED, HIGH);
else
digitalWrite(greenLED, LOW);
if (rotation > 5)
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
// Serial1.println(counter++);
}
}
#else
if (Serial1.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial1.read();
// Serial1.println(result);
if (result == 'R') {
Serial1.println("OK");
delay(500);
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());
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.println(Sensor3);
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 (acceleration > 1.2)
digitalWrite(greenLED, HIGH);
else
digitalWrite(greenLED, LOW);
if (rotation > 5)
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
// Serial1.println(counter++);
}
}
#endif
delay(100);
}
void eeprom_word_write(int addr, int val)
{
EEPROM.write(addr * 2, lowByte(val));
EEPROM.write(addr * 2 + 1, highByte(val));
}
short eeprom_word_read(int addr)
{
return((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}

@ -1,246 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
#define SEALEVELPRESSURE_HPA (1013.25)
//#define TESTING // Define to test on Serial Monitor
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
int counter = 0;
long timer = 0;
int bmePresent;
int greenLED = 9;
int blueLED = 8;
int Sensor1 = 0;
int Sensor2 = 0;
float Sensor3 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(9600); // Pi UART
Serial.println("Starting!");
pinMode(PC13, OUTPUT);
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
{
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
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(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
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(3)) / 100.0, DEC);
}
}
void loop() {
#ifdef TESTING
if (Serial.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial.read();
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
}
if (result == '?')
{
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" ");
Serial.print(mpu6050.getAccX());
Serial.print(" ");
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
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 (acceleration > 1.2)
digitalWrite(greenLED, HIGH);
else
digitalWrite(greenLED, LOW);
if (rotation > 5)
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
// Serial1.println(counter++);
}
}
#else
if (Serial1.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial1.read();
// Serial1.println(result);
if (result == 'R') {
Serial1.println("OK");
delay(500);
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());
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.println(Sensor3);
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 (acceleration > 1.2)
digitalWrite(greenLED, HIGH);
else
digitalWrite(greenLED, LOW);
if (rotation > 5)
digitalWrite(blueLED, HIGH);
else
digitalWrite(blueLED, LOW);
// Serial1.println(counter++);
}
}
#endif
delay(100);
}
void eeprom_word_write(int addr, int val)
{
EEPROM.write(addr * 2, lowByte(val));
EEPROM.write(addr * 2 + 1, highByte(val));
}
short eeprom_word_read(int addr)
{
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}

@ -1,287 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
long timer = 0;
int bmePresent;
int RXLED = 17; // The RX LED has a defined Arduino pin
int greenLED = 9;
int blueLED = 8;
int Sensor1 = 0;
float Sensor2 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
int first_time = true;
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(115200); // Pi UART faster speed
Serial.println("Starting!");
blink_setup();
blink(500);
delay(250);
blink(500);
delay(250);
led_set(greenLED, HIGH);
delay(250);
led_set(greenLED, LOW);
led_set(blueLED, HIGH);
delay(250);
led_set(blueLED, LOW);
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
{
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
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(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
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(3)) / 100.0, DEC);
}
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
}
void loop() {
if ((Serial.available() > 0)|| first_time == true) {
blink(50);
char result = Serial.read();
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
}
if ((result == '?') || first_time == true)
{
first_time = false;
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" ");
Serial.print(mpu6050.getAccX());
Serial.print(" ");
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.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 (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(500);
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());
Serial1.print(" XS ");
Serial1.print(Sensor1);
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 (acceleration > 1.2)
led_set(greenLED, HIGH);
else
led_set(greenLED, LOW);
if (rotation > 5)
led_set(blueLED, HIGH);
else
led_set(blueLED, LOW);
}
}
// delay(100);
}
void eeprom_word_write(int addr, int val)
{
EEPROM.write(addr * 2, lowByte(val));
EEPROM.write(addr * 2 + 1, highByte(val));
}
short eeprom_word_read(int addr)
{
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}
void blink_setup()
{
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
// initialize digital pin PB1 as an output.
pinMode(PC13, OUTPUT);
pinMode(PB9, OUTPUT);
pinMode(PB8, OUTPUT);
#endif
#if defined __AVR_ATmega32U4__
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
pinMode(greenLED, OUTPUT);
pinMode(blueLED,OUTPUT);
#endif
}
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)
digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level)
#endif
#if defined __AVR_ATmega32U4__
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
#endif
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)
digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED0; //TX LED macro to turn LED ON
#endif
}
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 (ledPin == greenLED)
digitalWrite(PB9, state);
else if (ledPin == blueLED)
digitalWrite(PB8, state);
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(ledPin, state);
#endif
}

@ -1,313 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
#include <TinyGPS.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
TinyGPS gps;
long timer = 0;
int bmePresent;
int RXLED = 17; // The RX LED has a defined Arduino pin
int greenLED = 9;
int blueLED = 8;
int Sensor1 = 0;
int Sensor2 = 0;
float Sensor3 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(9600); // Pi UART
Serial2.begin(9600); // GPS on STM32 pins PA2, PA3
Serial.println("Starting!");
blink_setup();
blink(500);
delay(250);
blink(500);
delay(250);
led_set(greenLED, HIGH);
delay(250);
led_set(greenLED, LOW);
led_set(blueLED, HIGH);
delay(250);
led_set(blueLED, LOW);
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
{
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
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(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
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(3)) / 100.0, DEC);
}
}
void loop() {
if (Serial.available() > 0) {
blink(50);
char result = Serial.read();
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
}
if (result == '?')
{
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" ");
Serial.print(mpu6050.getAccX());
Serial.print(" ");
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
Serial.print(" XS ");
Serial.print(Sensor1);
Serial.print(" ");
Serial.print(Sensor2);
Serial.print(" ");
Serial.println(Sensor3);
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 (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(500);
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());
Serial1.print(" XS ");
Serial1.print(Sensor1);
Serial1.print(" ");
Serial1.print(Sensor2);
Serial1.print(" ");
Serial1.println(Sensor3);
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 (acceleration > 1.2)
led_set(greenLED, HIGH);
else
led_set(greenLED, LOW);
if (rotation > 5)
led_set(blueLED, HIGH);
else
led_set(blueLED, LOW);
}
}
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 100;) // 1000;)
{
while (Serial2.available())
{
char c = Serial2.read();
Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
if (newData)
{
float flon, flat;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Sensor1 = flat * 100;
Sensor2 = flon * 100;
Sensor3 = (float) gps.altitude()/100.0;
}
// delay(100);
}
void eeprom_word_write(int addr, int val)
{
EEPROM.write(addr * 2, lowByte(val));
EEPROM.write(addr * 2 + 1, highByte(val));
}
short eeprom_word_read(int addr)
{
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}
void blink_setup()
{
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
// initialize digital pin PB1 as an output.
pinMode(PC13, OUTPUT);
pinMode(PB9, OUTPUT);
pinMode(PB8, OUTPUT);
#endif
#if defined __AVR_ATmega32U4__
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
pinMode(greenLED, OUTPUT);
pinMode(blueLED,OUTPUT);
#endif
}
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)
digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level)
#endif
#if defined __AVR_ATmega32U4__
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
#endif
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)
digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
#endif
}
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 (ledPin == greenLED)
digitalWrite(PB9, state);
else if (ledPin == blueLED)
digitalWrite(PB8, state);
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(ledPin, state);
#endif
}

@ -1,302 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
long timer = 0;
int bmePresent;
int RXLED = 17; // The RX LED has a defined Arduino pin
int greenLED = 9;
int blueLED = 8;
int Sensor1 = 0;
float Sensor2 = 0;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
int first_time = true;
float T2 = 26.3; // Temperature data point 1
float R2 = 167; // Reading data point 1
float T1 = 2; // Temperature data point 2
float R1 = 179; // Reading data point 2
int sensorValue;
float Temp;
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(115200); // Pi UART faster speed
Serial.println("Starting!");
blink_setup();
blink(500);
delay(250);
blink(500);
delay(250);
led_set(greenLED, HIGH);
delay(250);
led_set(greenLED, LOW);
led_set(blueLED, HIGH);
delay(250);
led_set(blueLED, LOW);
if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
bmePresent = 0;
}
mpu6050.begin();
if (eeprom_word_read(0) == 0xA07)
{
Serial.println("Reading gyro offsets from EEPROM\n");
float xOffset = ((float)eeprom_word_read(1)) / 100.0;
float yOffset = ((float)eeprom_word_read(2)) / 100.0;
float zOffset = ((float)eeprom_word_read(3)) / 100.0;
Serial.println(xOffset, DEC);
Serial.println(yOffset, DEC);
Serial.println(zOffset, DEC);
mpu6050.setGyroOffsets(xOffset, yOffset, zOffset);
}
else
{
Serial.println("Calculating gyro offsets and storing in EEPROM\n");
mpu6050.calcGyroOffsets(true);
eeprom_word_write(0, 0xA07);
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(3, (int)(mpu6050.getGyroZoffset() * 100.0) + 0.5);
Serial.println(eeprom_word_read(0), HEX);
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(3)) / 100.0, DEC);
}
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
}
void loop() {
if ((Serial.available() > 0)|| first_time == true) {
blink(50);
char result = Serial.read();
// Serial.println(result);
if (result == 'R') {
Serial.println("OK");
delay(500);
setup();
}
if ((result == '?') || first_time == true)
{
first_time = false;
if (bmePresent) {
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update();
Serial.print(" MPU6050 ");
Serial.print(mpu6050.getGyroX());
Serial.print(" ");
Serial.print(mpu6050.getGyroY());
Serial.print(" ");
Serial.print(mpu6050.getGyroZ());
Serial.print(" ");
Serial.print(mpu6050.getAccX());
Serial.print(" ");
Serial.print(mpu6050.getAccY());
Serial.print(" ");
Serial.print(mpu6050.getAccZ());
sensorValue = analogRead(A3);
//Serial.println(sensorValue);
Temp = T1 + (sensorValue - R1) *((T2 - T1)/(R2 - R1));
Serial.print(" XS ");
Serial.print(Temp);
Serial.print(" ");
Serial.println(Sensor1);
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 (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(500);
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 (acceleration > 1.2)
led_set(greenLED, HIGH);
else
led_set(greenLED, LOW);
if (rotation > 5)
led_set(blueLED, HIGH);
else
led_set(blueLED, LOW);
}
}
// delay(100);
}
void eeprom_word_write(int addr, int val)
{
EEPROM.write(addr * 2, lowByte(val));
EEPROM.write(addr * 2 + 1, highByte(val));
}
short eeprom_word_read(int addr)
{
return ((EEPROM.read(addr * 2 + 1) << 8) | EEPROM.read(addr * 2));
}
void blink_setup()
{
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
// initialize digital pin PB1 as an output.
pinMode(PC13, OUTPUT);
pinMode(PB9, OUTPUT);
pinMode(PB8, OUTPUT);
#endif
#if defined __AVR_ATmega32U4__
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
pinMode(greenLED, OUTPUT);
pinMode(blueLED,OUTPUT);
#endif
}
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)
digitalWrite(PC13, LOW); // turn the LED on (HIGH is the voltage level)
#endif
#if defined __AVR_ATmega32U4__
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
#endif
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)
digitalWrite(PC13, HIGH); // turn the LED off by making the voltage LOW
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(RXLED, HIGH); // set the RX LED OFF
TXLED0; //TX LED macro to turn LED ON
#endif
}
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 (ledPin == greenLED)
digitalWrite(PB9, state);
else if (ledPin == blueLED)
digitalWrite(PB8, state);
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(ledPin, state);
#endif
}

@ -1,80 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
//#define TESTING // Define to test on Serial Monitor
Adafruit_BME280 bme;
int counter = 0;
int RXLED = 17; // The RX LED has a defined Arduino pin
void setup() {
Serial.begin(9600); // Serial Monitor for testing
Serial1.begin(9600); // Pi UART
Serial.println("Starting!");
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
#ifdef TESTING
if (Serial.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial.read();
// Serial1.println(result);
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.println(bme.readHumidity());
// Serial1.println(counter++);
}
#else
if (Serial1.available() > 0) {
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
delay(50); // wait for a second
digitalWrite(RXLED, HIGH); // set the RX LED ON
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
char result = Serial1.read();
// Serial1.println(result);
// Serial1.println("OK ");
/**/
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.println(bme.readHumidity());
/**/
// Serial1.println(counter++);
}
#endif
delay(100);
}

@ -1,28 +0,0 @@
This code is for the STM32 or Pro Micro acting as a payload to the CubeSatSim.
Code includes (in rough order of testing):
Blink_STM32_PC13.ino and Blink_Pro_Micro.ino The usual Arduino "Hello World" application that blinks the LED for each board.
i2c_scanner.ino A handy utility for scanning the I2C bus that displays the results in the Serial Monitor at 9600 baud. If the sensors are installed and the jumpers set to the correct position, the two sensors should be displayed.
STEM_Payload_Test_STM32.ino and STEM_Payload_Test_Pro_Micro.ino Blinks the Blue and Green LEDs on the STEM Payload Board and also reads the Temperature and Voltage sensors.
bme280test.ino Displays the results of reading the BME280 sensor: Temperature, Pressure, Altitude, and Humidity and displays on Serial Monitor 9600 baud. Requires the following libraries: Adadruit Unified Sensor (specify version 1.0.3), Adafruit_BME280 (specify version 1.1.0)
GetAllData.ino Displays the results of reading the MPU6050 sensor: Temperature, X, Y, and Z Axes: Acceleration, Gyor (Rotation Rate), and Angle. Requires the following libraries: MPU6050_tockn.
PayloadOK_STM32_PC13.ino and PayloadOK_Pro_Micro.ino This code answers the query from the Raspberry Pi CubeSatSim software over the UART so that the STEM Payload is marked "OK" in the FoxTelem CubeSatSim-FSK Health tab.
Payload_BME280_MPU6050_Pro_Micro.ino and Payload_BME280_MPU6050_STM32.ino This code answers the query from the Raspberry Pi CubeSatSim software over the UART so that the STEM Payload is marked "OK" in the FoxTelem CubeSatSim-FSK Health tab and also replies withe BME280 and MPU6050 sensor data. In FoxTelem, this is displayed as the X, Y, and Z Gyro (dps) and in AFSK mode, it is appended to the telemetry string.
The STM32 can be programmed using the Arduino IDE with the Generic STM32F103C series board and STM32duino bootloader, Maple Mini port.
The Sparkfun Pro Micro can also be programed using the Arduino IDE with the Sparkfun Pro Micro board and AVRISP mkII Programmer.
See the Wiki page for more information:
See https://github.com/alanbjohnston/CubeSatSim/wiki/Arduino-Payload

@ -1,105 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13
Added CubeSatSim Payload tests for STM32 and Pro Micro by Alan Johnston, KU2Y
*/
int sensorValue = 0;
int greenLED = 9;
int blueLED = 8;
// Calibration data for diode temperature sensor
float T1 = 25; // Temperature data point 1
float R1 = 373; // Reading data point 1
float T2 = 17; // Temperature data point 2
float R2 = 405; // Reading data point 2
// the setup function runs once when you press reset or power the board
void setup() {
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
// initialize digital pin PB1 as an output.
pinMode(PB9, OUTPUT);
pinMode(PB8, OUTPUT);
pinMode(PA0, INPUT_ANALOG);
pinMode(PA1, INPUT_ANALOG);
pinMode(PA2, INPUT_ANALOG);
T2 = 25; // Temperature data point 1
R2 = 2111; // Reading data point 1
T1 = 23; // Temperature data point 2
R1 = 2097; // Reading data point 2
#endif
#if defined __AVR_ATmega32U4__
pinMode(greenLED, OUTPUT);
pinMode(blueLED,OUTPUT);
#endif
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
ledWrite(greenLED, HIGH); // turn the LED on (HIGH is the voltage level)
ledWrite(blueLED, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
ledWrite(greenLED, LOW); // turn the LED off by making the voltage LOW
ledWrite(blueLED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
sensorValue = readAnalog(0);
// Serial.println(sensorValue);
sensorValue = readAnalog(1);
float temp = T1 + (sensorValue - R1) *(T2 - T1)/(R2 - R1);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
sensorValue = readAnalog(2);
// Serial.println(sensorValue);
}
void ledWrite(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 (ledPin == greenLED)
digitalWrite(PB9, state);
else if (ledPin == blueLED)
digitalWrite(PB8, state);
#endif
#if defined __AVR_ATmega32U4__
digitalWrite(ledPin, state);
#endif
}
int readAnalog(int pin)
{
int value = 0;
#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)
if (pin == 0)
value = analogRead(PA0);
else if (pin == 1)
value = analogRead(PA1);
else if (pin == 2)
value = analogRead(PA2);
#endif
#if defined __AVR_ATmega32U4__
value = analogRead(pin);
#endif
return(value);
}

@ -1,56 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13
Added CubeSatSim Payload tests by Alan Johnston, KU2Y
*/
int sensorValue = 0;
int D9 = 9;
int D8 = 8;
// Calibration data for diode temperature sensor
float T1 = 25; // Temperature data point 1
float R1 = 373; // Reading data point 1
float T2 = 17; // Temperature data point 2
float R2 = 405; // Reading data point 2
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PB1 as an output.
pinMode(D9, OUTPUT);
pinMode(D8, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(D9, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(D8, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(D9, LOW); // turn the LED off by making the voltage LOW
digitalWrite(D8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
sensorValue = analogRead(A0);
// Serial.println(sensorValue);
sensorValue = analogRead(A1);
float temp = T1 + (sensorValue - R1) *(T2 - T1)/(R2 - R1);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
sensorValue = analogRead(A2);
// Serial.println(sensorValue);
}

@ -1,50 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PC13
Added CubeSatSim Payload tests by Alan Johnston, KU2Y
*/
int sensorValue = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PB1 as an output.
pinMode(PB9, OUTPUT);
pinMode(PB8, OUTPUT);
pinMode(PA0, INPUT_ANALOG);
pinMode(PA1, INPUT_ANALOG);
pinMode(PA2, INPUT_ANALOG);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(PB9, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(PB8, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PB9, LOW); // turn the LED off by making the voltage LOW
digitalWrite(PB8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
sensorValue = analogRead(PA0);
Serial.println(sensorValue);
sensorValue = analogRead(PA1);
Serial.println(sensorValue);
sensorValue = analogRead(PA2);
Serial.println(sensorValue);
}

@ -1,37 +0,0 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println("*C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println("hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println("m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println("%");
Serial.println();
delay(1000);
}

@ -1,70 +0,0 @@
/*
* EEPROM Write
*
* Stores values into the EEPROM.
* These values will stay in the EEPROM when the board is
* turned off and may be retrieved later by another sketch.
*
* Writes 8 values.
*
*/
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;
void setup() {
// initialize serial
Serial.begin(9600);
}
void loop() {
/***
Need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
value from 0 to 255.
***/
// int val = analogRead(0) / 4;
/***
Write the value to the appropriate byte of the EEPROM.
these values will remain there when the board is
turned off.
***/
Serial.println("\nEEPROM Write/Read test and Reset\n\n");
for (int i=0; i < 9; i++)
{
EEPROM.write(i,i);
delay(500);
Serial.println(EEPROM.read(i));
}
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
// addr = addr + 1;
// if (addr == EEPROM.length()) {
// addr = 0;
// }
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++addr &= EEPROM.length() - 1;
***/
// delay(100);
}

@ -1,79 +0,0 @@
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 0x43; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
Serial.print(address, HEX);
byte error = Wire.endTransmission();
if (error == 0) {
Serial.print("\nI2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
++nDevices;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("\ndone\n");
}
delay(5000); // Wait 5 seconds for next scan
}
Loading…
Cancel
Save

Powered by TurnKey Linux.