~ajk/GeliTripping

35e0b112df82c96d04bf760ad077d57a2726366e — Andrew Kay a month ago master
Initial commit
5 files changed, 250 insertions(+), 0 deletions(-)

A README.md
A UNLICENSE
A firmware/.gitignore
A firmware/platformio.ini
A firmware/src/main.cpp
A  => README.md +3 -0
@@ 1,3 @@
# GeliTripping

Yes, Gottfried was in the rocket, but Geli Tripping is just such a fantastic name.

A  => UNLICENSE +24 -0
@@ 1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>

A  => firmware/.gitignore +1 -0
@@ 1,1 @@
.pio

A  => firmware/platformio.ini +7 -0
@@ 1,7 @@
[env]
framework = arduino
lib_deps = 124, 684, 1825

[env:adafruit_feather_m0]
platform = atmelsam
board = adafruit_feather_m0

A  => firmware/src/main.cpp +215 -0
@@ 1,215 @@
#include <RHDatagram.h>
#include <RH_RF69.h>
#include <SparkFunBME280.h>
#include <SparkFunLSM9DS1.h>

#define LOG_SERIAL SERIAL_PORT_HARDWARE

#define RF69_CS_PIN 8
#define RF69_INT_PIN 3
#define RF69_RST_PIN 4
#define RF69_FREQUENCY 915.0
#define RF69_ADDRESS 2

bool rf69Connected = false;
RH_RF69 rf69(RF69_CS_PIN, RF69_INT_PIN);
RHDatagram rf69Manager(rf69, RF69_ADDRESS);

bool imuConnected = false;
LSM9DS1 imu;
bool bmeConnected = false;
BME280 bme;

void setupLog()
{
    LOG_SERIAL.begin(115200);

    LOG_SERIAL.println("SYS#GELI TRIPPING");
}

bool setupRF69()
{
    Serial.println("[INFO] RF69 setup...");

    // Configure reset pin.
    pinMode(RF69_RST_PIN, OUTPUT);
    digitalWrite(RF69_RST_PIN, LOW);

    // Reset.
    digitalWrite(RF69_RST_PIN, HIGH);
    delay(10);
    digitalWrite(RF69_RST_PIN, LOW);
    delay(10);

    if (!rf69Manager.init()) {
        Serial.println("[ERROR] Error initializing RF69 radio and manager");
        return false;
    }

    if (!rf69.setFrequency(RF69_FREQUENCY)) {
        Serial.println("[ERROR] Error setting RF69 frequency");
        return false;
    }

    rf69.setTxPower(20, true);

    Serial.println("[INFO] RF69 setup complete");

    return true;
}

bool setupIMU()
{
    Serial.println("[INFO] IMU setup...");

    if (!imu.begin()) {
        return false;
    }

    Serial.println("[INFO] Calibrating IMU...");

    imu.calibrate();
    imu.calibrateMag();

    Serial.println("[INFO] IMU setup complete");

    return true;
}

bool setupBME()
{
    Serial.println("[INFO] BME setup...");

    if (!bme.begin()) {
        return false;
    }

    Serial.println("[INFO] BME setup complete");

    return true;
}

struct {
    uint32_t index = 0;
    uint32_t tempTime = 0;
    float tempF = 0;
    uint32_t pressureTime = 0;
    float pressure = 0;
    uint32_t gyroTime = 0;
    float gyroX = 0;
    float gyroY = 0;
    float gyroZ = 0;
    uint32_t accelTime = 0;
    float accelX = 0;
    float accelY = 0;
    float accelZ = 0;
    uint32_t magTime = 0;
    float magX = 0;
    float magY = 0;
    float magZ = 0;
} sensorReadings;

void logTask()
{
    sensorReadings.index++;

    // Read temperature and pressure.
    if (bmeConnected) {
        sensorReadings.tempTime = millis();
        sensorReadings.tempF = bme.readTempF();

        sensorReadings.pressureTime = millis();
        sensorReadings.pressure = bme.readFloatPressure();
    }

    // Read gyroscope and accelerometer.
    if (imuConnected) {
        sensorReadings.gyroTime = millis();

        imu.readGyro();

        sensorReadings.accelTime = millis();

        imu.readAccel();

        sensorReadings.magTime = millis();

        imu.readMag();

        sensorReadings.gyroX = imu.calcGyro(imu.gx);
        sensorReadings.gyroY = imu.calcGyro(imu.gy);
        sensorReadings.gyroZ = imu.calcGyro(imu.gz);

        sensorReadings.accelX = imu.calcAccel(imu.ax);
        sensorReadings.accelY = imu.calcAccel(imu.ay);
        sensorReadings.accelZ = imu.calcAccel(imu.az);

        sensorReadings.magX = imu.calcMag(imu.mx);
        sensorReadings.magY = imu.calcMag(imu.my);
        sensorReadings.magZ = imu.calcMag(imu.mz);
    }

    LOG_SERIAL.print(sensorReadings.index);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.tempTime);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.tempF);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.pressureTime);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.pressure);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.gyroTime);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.gyroX);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.gyroY);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.gyroZ);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.accelTime);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.accelX);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.accelY);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.accelZ);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.magTime);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.magX);
    LOG_SERIAL.print(",");
    LOG_SERIAL.print(sensorReadings.magY);
    LOG_SERIAL.print(",");
    LOG_SERIAL.println(sensorReadings.magZ);

    LOG_SERIAL.flush();
}

void setup()
{
    Serial.begin(115200);

    Serial.flush();

    delay(2000);

    Serial.println("> GELI TRIPPING");
    Serial.println();

    setupLog();

    //rf69Connected = setupRF69();

    imuConnected = setupIMU();
    bmeConnected = setupBME();

    Serial.println("[INFO] Logging...");
}

void loop()
{
    logTask();

    delay(50);
}