aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Sanson <jamie.sanson@outlook.com>2016-06-18 13:39:18 +1200
committerJamie Sanson <jamie.sanson@outlook.com>2016-06-18 13:39:18 +1200
commit8488d2370b93ee374faf9a5e75c7ed16ce1a75f8 (patch)
treef92a551fe19bec10fbada0bbc6f303796d29ea5b
parentd096e492cbab403dcd2a6b6041a0a65735b06ede (diff)
downloadmetis-1-onboard-8488d2370b93ee374faf9a5e75c7ed16ce1a75f8.tar.gz
metis-1-onboard-8488d2370b93ee374faf9a5e75c7ed16ce1a75f8.tar.bz2
metis-1-onboard-8488d2370b93ee374faf9a5e75c7ed16ce1a75f8.zip
Add naive radio functionality and rearrange some fields
-rw-r--r--test_flight_basic_logging/test_flight_basic_logging.ino87
1 files changed, 68 insertions, 19 deletions
diff --git a/test_flight_basic_logging/test_flight_basic_logging.ino b/test_flight_basic_logging/test_flight_basic_logging.ino
index 7c9f06c..552ba30 100644
--- a/test_flight_basic_logging/test_flight_basic_logging.ino
+++ b/test_flight_basic_logging/test_flight_basic_logging.ino
@@ -44,6 +44,17 @@
#include <SPI.h>
#include <MPU9250_helper.h>
#include <TinyGPS++.h>
+#include <RF22.h>
+
+// REGION RFM22B
+#define RCS 9
+#define radioIntPin 0
+
+RF22 rf22(RCS, radioIntPin);
+
+
+uint8_t radioDataBuffer[64];
+// END REGION
// REGION GPS
#define gpsSerial Serial3
@@ -52,19 +63,6 @@ TinyGPSPlus gps;
boolean gpsLocked = false;
// END REGION
-// REGION CONFIGURATION
-uint8_t OSR = ADC_8192;
-int8_t Ascale = AFS_16G;
-int8_t Gscale = GFS_250DPS;
-int8_t Mscale = MFS_16BITS; // Choose either 14-bit or 16-bit magnetometer resolution
-int8_t Mmode = 0x02; // 2 for 8Hz, 6 for 100Hz continuous
-
-boolean serialDebug = true;
-
-const int sdChipSelect = 10;
-const int radioChipSelect = 9;
-// END REGION
-
// REGION SENSOR FIELDS
uint16_t Pcal[8]; // calibration constants from MS5637 PROM registers
unsigned char nCRC; // calculated check sum to ensure PROM integrity
@@ -102,11 +100,28 @@ int writeCount = 0;
String dataBuffer = "";
// END REGION
+// REGION CONFIGURATION
+uint8_t OSR = ADC_8192;
+int8_t Ascale = AFS_16G;
+int8_t Gscale = GFS_250DPS;
+int8_t Mscale = MFS_16BITS; // Choose either 14-bit or 16-bit magnetometer resolution
+int8_t Mmode = 0x02; // 2 for 8Hz, 6 for 100Hz continuous
+
+boolean serialDebug = false;
+
+const int sdChipSelect = 10;
+const int radioChipSelect = 9;
+// END REGION
+
MPU9250_helper helper(Ascale, Gscale, Mscale, Mmode);
void setup() {
gpsSerial.begin(9600);
+ pinMode(radioIntPin, INPUT);
+ pinMode(9, OUTPUT);
+ pinMode(10, OUTPUT);
+
Wire1.begin(I2C_MASTER, 0x00, I2C_PINS_29_30, I2C_PULLUP_EXT, I2C_RATE_400);
if (serialDebug) {
@@ -119,6 +134,7 @@ void setup() {
setupMPU9250();
setupAK8963();
setupMS5637();
+ setupRFM22B();
// Block if not initialised properly (Also set LED state)
while (!initialiseOK);
@@ -181,10 +197,14 @@ void loop() {
printData(String(millis()) + ",\n");
if (gps.location.isUpdated()) {
- // TODO: Change this to utilise radio
+ sendViaRadio(getGPSString());
}
}
+// -------------------------------------------------
+// Setup functions
+// -------------------------------------------------
+
void setupMPU9250() {
printData("Reading who-am-i byte of MPU9250\n");
byte c = helper.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); // Read WHO_AM_I register for MPU-9250
@@ -238,7 +258,7 @@ void setupSD() {
} else {
// Detect init file on card
// Same number of init files as there are data files
- Serial.println("Initialising card");
+ printData("Initialising card");
int fileCount = 1;
(initFileName + String(fileCount) + ".txt").toCharArray(fileNameBuffer, 20);
while(SD.exists(fileNameBuffer)) {
@@ -284,6 +304,19 @@ void setupMS5637(){
altInit = true;
}
+void setupRFM22B() {
+ if (!rf22.init()) {
+ initialiseOK = false;
+ printData("\nRFM22B failed to initialise\n");
+ } else {
+ printData("\nRFM22B initialisation success\n");
+ }
+}
+
+// -------------------------------------------------
+// Data processing functions
+// -------------------------------------------------
+
float getAltitude(){
if (!altInit || altitudeCount == 256) {
D1 = helper.MS5637Read(ADC_D1, OSR); // get raw pressure value
@@ -329,6 +362,13 @@ float getAltitude(){
return altitudeBuffer;
}
+String getLogString(float x, float y, float z) {
+ return (String(x, DEC) + "," + String(y, DEC) + "," + String(z, DEC) + ",");
+}
+
+String getGPSString() {
+ return (String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + "," + String(gps.altitude.meters()) + ",");
+}
// -------------------------------------------------
// Utility functions
@@ -356,11 +396,20 @@ void printData(String data) {
}
}
-String getLogString(float x, float y, float z) {
- return (String(x, DEC) + "," + String(y, DEC) + "," + String(z, DEC) + ",");
+boolean sendViaRadio(String dataString) {
+ getArrayFromString(dataString, radioDataBuffer);
+ boolean success = rf22.send(radioDataBuffer, sizeof(radioDataBuffer));
+ if (success) {
+ rf22.waitPacketSent();
+ }
+ return success;
}
-String getGPSString() {
- return (String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + "," + String(gps.altitude.meters()) + ",");
+void getArrayFromString(String in, uint8_t * dest) {
+ uint8_t out[in.length()];
+ for (uint8_t i = 0; i < in.length(); i++) {
+ out[i] = (uint8_t) in.charAt(i);
+ }
+ dest = out;
}