SCIboard(TM): mbed base board data logger - Altimeter: MPL3115A2 - Accelerometer: LSM303DLHC - Gyro: L3G4200D - 4 High Current MOSFET switches

Dependencies:   mbed

/media/uploads/AstrodyneSystems/sciboard_top.jpg

/media/uploads/AstrodyneSystems/sciboard_bottom.jpg

Product Description

SCIboard will take your model rocketry, science, or engineering project to new heights with a complete 10-Degree-Of-Freedom (10-DOF) Inertial Measurement Unit (IMU), 4 high current MOSFET switches, PWM interface (RC servos), USB (memory sticks or BlueTooth) and interfaces for GPS and an XBee® RF module. The SCIboard is an mbed base board ideal for use in college and high school science labs, science fair projects, high power model rocketry, model airplanes, and near space balloon projects. SCIboard is also designed for Open Source software so you can customize the application. Example applications include high power model rocketry, near space balloon projects, and R/C airplanes/quadcopters. While SCIboard requires some basic electronics and software knowledge, it combines multiple breakout boards into a single base board which improves reliability, especially in high g environments such as in model rocketry. Available on Amazon. Search on "SCIboard".

  • Dimensions: 1.5 x 3.8 inches (3.8 x 9.7 cm)
  • Weight: 0.8 ounces (24 g)

10-DOF Inertial Measurement Unit

Going beyond just the 6 degrees of freedom afforded by a 3-axis accelerometer and 3-axis gyro, SCIboard includes an additional 3-axis magnetometer, and highly accurate altimeter / atmospheric pressure sensor. Sensors provide digital measurements over an I2C shared bus (p27 and p28).

Precision Altimeter

(Freescale Semiconductor – MPL3115A2) MEMS pressure sensor with 24-bit Analog-to-Digital Converter (ADC) employs temperature compensation resulting in fully compensated 20-bit pressure/altitude measurements (resolution down to 1 foot).

  • Pressure range: 50 – 110 kPa.
  • Pressure reading noise: 1.5 Pa RMS over -10 to +70° C. Conversion rate: up to 100 Hz.
  • 12-bit temperature sensor measurement range: -40 to +85° C.

3-Axis MEMS Accelerometer

(STMicroelectronics – LSM303DLHC) The sensor measures linear acceleration. Pointing any axis to the earth will apply 1 g in that axis when stationary.

  • Selectable full scale range: +/-2 g to +/-16 g.
  • Sensitivity: 1 – 12 mg/LSB depending on full scale range.
  • Zero-g level offset: +/-60 mg.
  • Acceleration noise density: 220 micro-g/sqrt(Hz).
  • Operating temp range: -40 to +85° C.
  • Conversion rate up to 400 Hz.

3-Axis Ultra-Stable MEMS Gyroscope

(STMicroelectronics – L3G4200D) A gyroscope is an angular rate sensor.

  • Selectable full scale ranges: 250/500/2000 degrees per second (DPS).
  • Resolution: 16-bit.
  • Bandwidth: user selectable.
  • Sensitivity: 8.75/17.50/70 milli-degrees per second/LSB.
  • Nonlinearity: 0.2% full scale
  • Rate noise density: 0.03 DPS/sqrt(Hz).
  • Operating temp range: -40 to +85°C.

Digital I/O

4 MOSFET switches are included. They provide 6-amperes momentary current sinking. Example uses include high power strobes, and lights for night launches or buzzers for location. Switches can be activated at apogee or prior to landing for model rocketry. A continuity check through an analog to digital converter allows verification of circuit continuity before launch. A piezoelectric buzzer provides software control for audible alert and low battery voltage measurement.

/media/uploads/AstrodyneSystems/mosfet.jpg

Host USB Type-A with 5.0 Vdc regulator

USB Type-A connector wired as a host controller provides regulated 5 volt power from a battery. A variety of USB devices from memory sticks, Bluetooth, and Wi-Fi can be used with multiple software projects from the mbed web site.

XBee® and XBee-PRO® Modules

The XBee-PRO® interface supports multiple different XBee and XBee-PRO modules such as Wi-Fi, ZigBee, 802.15.4, Bluetooth, and longer range 900 MHz RF Modules. Compatible modules are Roving Networks and Digi-International. SCIboard provides dual 10 pin headers with regulated 3.3 volt power (from p40) and serial UART (Tx=p9/Rx=p10). Alternatively if the headers are not installed, the serial port may be connected to a SMS cell phone evaluation module. Since the 3.3 volt provided to XBee modules is from the mbed regulator, the user is responsible for power calculations. Testing was done with RN-XV and a 9-volt battery but higher battery voltages or higher current XBee modules could overheat the 3.3 volt regulator on the mbed. When using XBee modules, the user may need to perform hard/soft iron calibration if using the magnetometer.

Interface for GPS

SCIboard provides a serial UART interface for GPS receivers. It also provides 3.3 and 5.0 Vdc for power and Vbat (battery not included). PCB has 0.1” holes for soldered cable or header of your choice. This provides flexibility to use a variety of GPS modules.

/media/uploads/AstrodyneSystems/gps.jpg

Interface for Ethernet Cable

PCB has 0.1” interface for an Ethernet cable of your choice of Ethernet magnetics interface with LEDs. For Ethernet direct wire, use RD-, RD+, TD+, and TD-. For magnetics, several 3.3 Vdc and Grounds are provided allowing easy interfacing. For both LEDs a 160 ohm resistor is provided. Both LEDs share the 2 PWMs out.

/media/uploads/AstrodyneSystems/ethernet.jpg

Interface for PWM RC Servos

SCIboard provides a Pulse Width Modulation (PWM) header for RC servo motors. Up to 6 PWM servos can be controlled. Terminal block is provided for separate servo power source if desired. If the user chooses to not install the headers, the PCB has 0.1” spacing thru-holes for 3-pin R/C servos. (Pins 21 – 26)

/media/uploads/AstrodyneSystems/pwm.jpg

Applications

A 10-Degree-Of-Freedom Inertial Measurement Unit (IMU) can be used to measure distance traveled, velocity, acceleration, attitude (yaw, pitch, and roll), and attitude rate. When combined with a GPS, SCIboard will provide a GPS aided inertial navigation solutions. The PWM can be used to control a camera attached to a servo motor. This enables near space projects to point the camera up at the weather balloon, horizontally at the earth’s horizon, and down directly at the earth.

  1. College and high school science labs
  2. Science Fairs
  3. High Power Model Rocketry
  4. Near Space Balloons
  5. Quadcopters
  6. R/C Airplanes
  7. R/C Helicopter

Processor Board Support (Direct Pin-Out compatible)

  • mbed LPC1768
  • mbed LPC11U24
  • Embedded Artists LPCexpresso LPC1769
Committer:
AstrodyneSystems
Date:
Sun Apr 06 19:03:29 2014 +0000
Revision:
5:dc778a682d29
Parent:
4:09ffcb9bc1d3
Added ublox GPS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AstrodyneSystems 0:ab51d784ef36 1 /* SCIboard(TM) main.cpp
AstrodyneSystems 0:ab51d784ef36 2 Copyright (c) 2013 K. Andres
AstrodyneSystems 0:ab51d784ef36 3
AstrodyneSystems 0:ab51d784ef36 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AstrodyneSystems 0:ab51d784ef36 5 of this software and associated documentation files (the "Software"), to deal
AstrodyneSystems 0:ab51d784ef36 6 in the Software without restriction, including without limitation the rights
AstrodyneSystems 0:ab51d784ef36 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AstrodyneSystems 0:ab51d784ef36 8 copies of the Software, and to permit persons to whom the Software is
AstrodyneSystems 0:ab51d784ef36 9 furnished to do so, subject to the following conditions:
AstrodyneSystems 0:ab51d784ef36 10
AstrodyneSystems 0:ab51d784ef36 11 The above copyright notice and this permission notice shall be included in
AstrodyneSystems 0:ab51d784ef36 12 all copies or substantial portions of the Software.
AstrodyneSystems 0:ab51d784ef36 13
AstrodyneSystems 0:ab51d784ef36 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AstrodyneSystems 0:ab51d784ef36 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AstrodyneSystems 0:ab51d784ef36 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AstrodyneSystems 0:ab51d784ef36 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AstrodyneSystems 0:ab51d784ef36 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AstrodyneSystems 0:ab51d784ef36 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AstrodyneSystems 0:ab51d784ef36 20 THE SOFTWARE.
AstrodyneSystems 0:ab51d784ef36 21 */
AstrodyneSystems 0:ab51d784ef36 22
AstrodyneSystems 0:ab51d784ef36 23 /* OVERVIEW
AstrodyneSystems 1:a54c4a4f3b30 24 Displays on USB serial (9600 bps)
AstrodyneSystems 1:a54c4a4f3b30 25 MPL3115A2 ident 0xC4
AstrodyneSystems 1:a54c4a4f3b30 26 LSM303 ident 0x48 0x34 0x33
AstrodyneSystems 3:a0863e392562 27 L3G4200DTR ident 0xD3
AstrodyneSystems 5:dc778a682d29 28 then collects 20 seconds of data from accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 29
AstrodyneSystems 0:ab51d784ef36 30 Filename on Local: OUTxx.csv (csv format allows easy import into spreadsheets)
AstrodyneSystems 0:ab51d784ef36 31 Format: microseconds,record type, variable length data\r\n
AstrodyneSystems 1:a54c4a4f3b30 32 Rec type 1= altimeter data altitude (meters) and semiconductor temperature (deg C)
AstrodyneSystems 0:ab51d784ef36 33 Rec type 2= accelerometer data x, y, and z in g's
AstrodyneSystems 3:a0863e392562 34 Rec type 3= magnetometer data x, y, and z
AstrodyneSystems 3:a0863e392562 35 Rec type 4= gyro data x, y, z in degrees per second (dps)
AstrodyneSystems 5:dc778a682d29 36 Rec type 5= MOSFET switch events
AstrodyneSystems 0:ab51d784ef36 37
AstrodyneSystems 5:dc778a682d29 38 Items under development...
AstrodyneSystems 5:dc778a682d29 39 MOSFET switch
AstrodyneSystems 5:dc778a682d29 40 ublox GPS
AstrodyneSystems 0:ab51d784ef36 41 */
AstrodyneSystems 0:ab51d784ef36 42
AstrodyneSystems 0:ab51d784ef36 43 #include "mbed.h"
AstrodyneSystems 0:ab51d784ef36 44 #include "math.h"
AstrodyneSystems 0:ab51d784ef36 45
AstrodyneSystems 0:ab51d784ef36 46 #include "SCIboard_I2C.h"
AstrodyneSystems 1:a54c4a4f3b30 47 #include "SCIboard_MPL3115A2.h"
AstrodyneSystems 0:ab51d784ef36 48 #include "SCIboard_LSM303DLHC.h"
AstrodyneSystems 3:a0863e392562 49 #include "SCIboard_L3G4200DTR.h"
AstrodyneSystems 4:09ffcb9bc1d3 50
AstrodyneSystems 0:ab51d784ef36 51 #include "SCIboard_DataLogger.h"
AstrodyneSystems 2:6698a2433bfd 52 #include "SCIboard_ConfigFile.h"
AstrodyneSystems 4:09ffcb9bc1d3 53 #include "SCIboard_MOSFET.h"
AstrodyneSystems 0:ab51d784ef36 54
AstrodyneSystems 5:dc778a682d29 55 #include "SCIboard_ubloxGps.h"
AstrodyneSystems 5:dc778a682d29 56
AstrodyneSystems 0:ab51d784ef36 57 // LEDs
AstrodyneSystems 0:ab51d784ef36 58 DigitalOut led1(LED1);
AstrodyneSystems 0:ab51d784ef36 59 DigitalOut led2(LED2);
AstrodyneSystems 0:ab51d784ef36 60 DigitalOut led3(LED3);
AstrodyneSystems 0:ab51d784ef36 61 DigitalOut led4(LED4);
AstrodyneSystems 0:ab51d784ef36 62
AstrodyneSystems 0:ab51d784ef36 63 // PWM out
AstrodyneSystems 0:ab51d784ef36 64 PwmOut pwm1(p26);
AstrodyneSystems 0:ab51d784ef36 65 PwmOut pwm2(p25);
AstrodyneSystems 0:ab51d784ef36 66 PwmOut pwm3(p24);
AstrodyneSystems 0:ab51d784ef36 67 PwmOut pwm4(p23);
AstrodyneSystems 0:ab51d784ef36 68 PwmOut pwm5(p22);
AstrodyneSystems 0:ab51d784ef36 69 PwmOut pwm6(p21);
AstrodyneSystems 0:ab51d784ef36 70
AstrodyneSystems 5:dc778a682d29 71 Serial gps(p13, p14);
AstrodyneSystems 0:ab51d784ef36 72 // Serial Xbee(p9, p10);
AstrodyneSystems 0:ab51d784ef36 73
AstrodyneSystems 0:ab51d784ef36 74 // Buzzer
AstrodyneSystems 0:ab51d784ef36 75 DigitalOut alert(p29); // CAN_RD
AstrodyneSystems 0:ab51d784ef36 76
AstrodyneSystems 0:ab51d784ef36 77 // MOSFET controls
AstrodyneSystems 0:ab51d784ef36 78 DigitalOut fet_out1(p15); // ADC1
AstrodyneSystems 0:ab51d784ef36 79 DigitalOut fet_out2(p12); // SPI2_MISO
AstrodyneSystems 0:ab51d784ef36 80 DigitalOut fet_out3(p11); // SPI2_MOSI
AstrodyneSystems 0:ab51d784ef36 81 DigitalOut fet_out4(p8); // GPIO8
AstrodyneSystems 0:ab51d784ef36 82
AstrodyneSystems 0:ab51d784ef36 83 // ADC inputs
AstrodyneSystems 0:ab51d784ef36 84 AnalogIn batt_mon(p16); // ADC2
AstrodyneSystems 0:ab51d784ef36 85 AnalogIn fet_mon1(p17); // ADC3
AstrodyneSystems 0:ab51d784ef36 86 AnalogIn fet_mon2(p18); // ADC4
AstrodyneSystems 0:ab51d784ef36 87 AnalogIn fet_mon3(p19); // ADC5
AstrodyneSystems 0:ab51d784ef36 88 AnalogIn fet_mon4(p20); // ADC6
AstrodyneSystems 0:ab51d784ef36 89
AstrodyneSystems 0:ab51d784ef36 90 //
AstrodyneSystems 0:ab51d784ef36 91 Serial pc(USBTX, USBRX); // Default 9600 bps
AstrodyneSystems 0:ab51d784ef36 92
AstrodyneSystems 0:ab51d784ef36 93 // Timers
AstrodyneSystems 0:ab51d784ef36 94 Timer t;
AstrodyneSystems 0:ab51d784ef36 95 int time_ms;
AstrodyneSystems 0:ab51d784ef36 96
AstrodyneSystems 0:ab51d784ef36 97
AstrodyneSystems 0:ab51d784ef36 98 // I2C interface
AstrodyneSystems 0:ab51d784ef36 99 //#define sdaPin p9
AstrodyneSystems 0:ab51d784ef36 100 //#define sdcPin p10
AstrodyneSystems 0:ab51d784ef36 101 #define sdaPin p28
AstrodyneSystems 0:ab51d784ef36 102 #define sdcPin p27
AstrodyneSystems 0:ab51d784ef36 103
AstrodyneSystems 0:ab51d784ef36 104 SCIboard_I2C i2cBus(sdaPin, sdcPin);
AstrodyneSystems 0:ab51d784ef36 105
AstrodyneSystems 1:a54c4a4f3b30 106 // Altimeter
AstrodyneSystems 1:a54c4a4f3b30 107 SCIboard_MPL3115A2 alt(&i2cBus);
AstrodyneSystems 1:a54c4a4f3b30 108 InterruptIn MPL3115A2_INT1(p5);
AstrodyneSystems 1:a54c4a4f3b30 109 void MPL3115A2_INT1_INTERRUPT(void);
AstrodyneSystems 1:a54c4a4f3b30 110 //InterruptIn MPL3115A2_INT2();
AstrodyneSystems 1:a54c4a4f3b30 111
AstrodyneSystems 1:a54c4a4f3b30 112 const int accAltDecimate=5;
AstrodyneSystems 5:dc778a682d29 113 #define ALT_RATE 10
AstrodyneSystems 1:a54c4a4f3b30 114 int accCnt=0;
AstrodyneSystems 0:ab51d784ef36 115
AstrodyneSystems 3:a0863e392562 116
AstrodyneSystems 0:ab51d784ef36 117 // Accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 118 SCIboard_LSM303DLHC lsm303(&i2cBus);
AstrodyneSystems 0:ab51d784ef36 119 InterruptIn LSM303DLHC_DRDY(p7);
AstrodyneSystems 0:ab51d784ef36 120 void LSM303DLHC_DRDY_INTERRUPT(void);
AstrodyneSystems 0:ab51d784ef36 121 //InterruptIn LSM303DLHC_INT1(p6);
AstrodyneSystems 0:ab51d784ef36 122 //void LSM303DLHC_INT1_INTERRUPT(void);
AstrodyneSystems 0:ab51d784ef36 123 // INT2 n/c
AstrodyneSystems 0:ab51d784ef36 124
AstrodyneSystems 0:ab51d784ef36 125
AstrodyneSystems 3:a0863e392562 126 // Gyro
AstrodyneSystems 3:a0863e392562 127 SCIboard_L3G4200DTR l3g4200dtr(&i2cBus, GYR_DR_100HZ, GYR_BW_0, GYR_FS_250DPS);
AstrodyneSystems 3:a0863e392562 128 //InterruptIn L3G4200DTR_INT();
AstrodyneSystems 3:a0863e392562 129 //InterruptIn L3G4200DTR_DRDY(p24);
AstrodyneSystems 3:a0863e392562 130 //void L3G4200DTR_INTERRUPT(void);
AstrodyneSystems 3:a0863e392562 131
AstrodyneSystems 3:a0863e392562 132
AstrodyneSystems 2:6698a2433bfd 133 // Configuration data
AstrodyneSystems 2:6698a2433bfd 134 void ReadConfigfile(void);
AstrodyneSystems 5:dc778a682d29 135 float fMachDelay, fMainDeploymentAlt, fLowVoltageAlarm, fAltLog, fAccelLog, fMagLog, fGyroLog, fUBLOXlog;
AstrodyneSystems 2:6698a2433bfd 136
AstrodyneSystems 2:6698a2433bfd 137 char *cfgKeyStr[]={
AstrodyneSystems 2:6698a2433bfd 138 "MACH DELAY (s)",
AstrodyneSystems 2:6698a2433bfd 139 "MAIN DEPLOYMENT (ft)",
AstrodyneSystems 2:6698a2433bfd 140 "LOW VOLTAGE ALARM (v)",
AstrodyneSystems 2:6698a2433bfd 141 "ALT LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 142 "ACCEL LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 143 "MAG LOG (1|0)",
AstrodyneSystems 5:dc778a682d29 144 "GYRO LOG (1|0)",
AstrodyneSystems 5:dc778a682d29 145 "UBLOX LOG (1|0)",
AstrodyneSystems 2:6698a2433bfd 146 //"SSID",
AstrodyneSystems 2:6698a2433bfd 147 //"PASSWD",
AstrodyneSystems 2:6698a2433bfd 148 };
AstrodyneSystems 2:6698a2433bfd 149
AstrodyneSystems 2:6698a2433bfd 150 float *cfgFloatPtr[] = {
AstrodyneSystems 5:dc778a682d29 151 &fMachDelay, &fMainDeploymentAlt, &fLowVoltageAlarm, &fAltLog, &fAccelLog, &fMagLog, &fGyroLog, &fUBLOXlog};
AstrodyneSystems 2:6698a2433bfd 152
AstrodyneSystems 4:09ffcb9bc1d3 153 // MOSFET switchs and ADC
AstrodyneSystems 4:09ffcb9bc1d3 154 SCIboard_Mosfet mosfet;
AstrodyneSystems 4:09ffcb9bc1d3 155
AstrodyneSystems 5:dc778a682d29 156 // UBLOX GPS
AstrodyneSystems 5:dc778a682d29 157 SCIboard_ubloxGps ubloxGps;
AstrodyneSystems 5:dc778a682d29 158
AstrodyneSystems 0:ab51d784ef36 159 //---------------------------------------------------------------------
AstrodyneSystems 0:ab51d784ef36 160 int main() {
AstrodyneSystems 0:ab51d784ef36 161 unsigned char data[10];
AstrodyneSystems 0:ab51d784ef36 162 float f[3];
AstrodyneSystems 0:ab51d784ef36 163 char str[132];
AstrodyneSystems 0:ab51d784ef36 164 int currentTime;
AstrodyneSystems 0:ab51d784ef36 165 int lastTime=0;
AstrodyneSystems 3:a0863e392562 166 float gyro_store[3];
AstrodyneSystems 3:a0863e392562 167 bool bGyroDataStored=false;
AstrodyneSystems 0:ab51d784ef36 168
AstrodyneSystems 3:a0863e392562 169 // Ensure interrupts are off
AstrodyneSystems 1:a54c4a4f3b30 170 MPL3115A2_INT1.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 171 LSM303DLHC_DRDY.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 172 // LSM303DLHC_INT1.rise(NULL);
AstrodyneSystems 3:a0863e392562 173 // L3G4200DTR_DRDY.fall(NULL);
AstrodyneSystems 3:a0863e392562 174
AstrodyneSystems 5:dc778a682d29 175 // pc.baud(38400);
AstrodyneSystems 5:dc778a682d29 176
AstrodyneSystems 2:6698a2433bfd 177 ReadConfigfile();
AstrodyneSystems 2:6698a2433bfd 178
AstrodyneSystems 0:ab51d784ef36 179 // DataLogger
AstrodyneSystems 0:ab51d784ef36 180 nextFilename();
AstrodyneSystems 5:dc778a682d29 181 log_open();
AstrodyneSystems 0:ab51d784ef36 182
AstrodyneSystems 1:a54c4a4f3b30 183 // Get I2C device IDs
AstrodyneSystems 1:a54c4a4f3b30 184 sprintf(str, "MPL3115A2 Ident 0x%X\r\n", alt.getDeviceID());
AstrodyneSystems 5:dc778a682d29 185 // pc.printf(str);
AstrodyneSystems 1:a54c4a4f3b30 186 log_write(str);
AstrodyneSystems 1:a54c4a4f3b30 187
AstrodyneSystems 0:ab51d784ef36 188 lsm303.getDeviceID(data);
AstrodyneSystems 0:ab51d784ef36 189 sprintf(str, "LSM303DLHC Ident 0x%X 0x%X 0x%X\r\n", data[0], data[1], data[2]);
AstrodyneSystems 5:dc778a682d29 190 // pc.printf(str);
AstrodyneSystems 0:ab51d784ef36 191 log_write(str);
AstrodyneSystems 0:ab51d784ef36 192
AstrodyneSystems 3:a0863e392562 193 sprintf(str, "L3G4200DTR Ident 0x%X\r\n", l3g4200dtr.getDeviceID());
AstrodyneSystems 5:dc778a682d29 194 // pc.printf(str);
AstrodyneSystems 3:a0863e392562 195 log_write(str);
AstrodyneSystems 0:ab51d784ef36 196
AstrodyneSystems 0:ab51d784ef36 197 // Setup accelerometer and magnetometer
AstrodyneSystems 0:ab51d784ef36 198 lsm303.setAccMode(ACC_4G, ACC_50HZ);
AstrodyneSystems 0:ab51d784ef36 199 lsm303.setMagMode(MAG_1p3G, MAG_75HZ);
AstrodyneSystems 0:ab51d784ef36 200
AstrodyneSystems 1:a54c4a4f3b30 201 // Setup altimeter
AstrodyneSystems 1:a54c4a4f3b30 202 alt.setMode(ALT_MODE, OS4);
AstrodyneSystems 1:a54c4a4f3b30 203 alt.OST(); // initiate first conversion
AstrodyneSystems 1:a54c4a4f3b30 204 MPL3115A2_INT1.fall(MPL3115A2_INT1_INTERRUPT);
AstrodyneSystems 1:a54c4a4f3b30 205
AstrodyneSystems 5:dc778a682d29 206 if(fUBLOXlog) {
AstrodyneSystems 5:dc778a682d29 207 ubloxGps.gps_startup();
AstrodyneSystems 5:dc778a682d29 208 }
AstrodyneSystems 5:dc778a682d29 209
AstrodyneSystems 0:ab51d784ef36 210 t.start(); // start timer
AstrodyneSystems 0:ab51d784ef36 211
AstrodyneSystems 5:dc778a682d29 212 if(fMagLog) {
AstrodyneSystems 5:dc778a682d29 213 LSM303DLHC_DRDY.fall(LSM303DLHC_DRDY_INTERRUPT); // Magnetometer
AstrodyneSystems 5:dc778a682d29 214 }
AstrodyneSystems 5:dc778a682d29 215
AstrodyneSystems 0:ab51d784ef36 216 // LSM303DLHC_INT1.rise(LSM303DLHC_INT1_INTERRUPT); // Accelerometer
AstrodyneSystems 0:ab51d784ef36 217
AstrodyneSystems 0:ab51d784ef36 218
AstrodyneSystems 5:dc778a682d29 219 // Collect some data then close file system to allow mbed to be visible on USB connected PC for demo app only
AstrodyneSystems 5:dc778a682d29 220 while(t.read()<20) {
AstrodyneSystems 0:ab51d784ef36 221 time_ms = t.read_ms();
AstrodyneSystems 0:ab51d784ef36 222 currentTime = t.read();
AstrodyneSystems 0:ab51d784ef36 223 if(currentTime!=lastTime) {
AstrodyneSystems 0:ab51d784ef36 224 lastTime = currentTime;
AstrodyneSystems 0:ab51d784ef36 225 led2 = !led2; // slow blink led
AstrodyneSystems 0:ab51d784ef36 226 }
AstrodyneSystems 5:dc778a682d29 227
AstrodyneSystems 0:ab51d784ef36 228 __disable_irq();
AstrodyneSystems 5:dc778a682d29 229
AstrodyneSystems 0:ab51d784ef36 230 // Accelerometer
AstrodyneSystems 0:ab51d784ef36 231 if(lsm303.bAccDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 232 lsm303.getAccData(f);
AstrodyneSystems 5:dc778a682d29 233 if(fAccelLog) {
AstrodyneSystems 5:dc778a682d29 234 sprintf(str,"%u,2,%.3f,%.3f,%.3f\r\n", time_ms, f[0], f[1], f[2]);
AstrodyneSystems 5:dc778a682d29 235 log_write(str);
AstrodyneSystems 5:dc778a682d29 236 }
AstrodyneSystems 1:a54c4a4f3b30 237 if(++accCnt >= accAltDecimate) {
AstrodyneSystems 1:a54c4a4f3b30 238 accCnt = 0;
AstrodyneSystems 1:a54c4a4f3b30 239 alt.OST();
AstrodyneSystems 1:a54c4a4f3b30 240 }
AstrodyneSystems 0:ab51d784ef36 241 }
AstrodyneSystems 0:ab51d784ef36 242
AstrodyneSystems 0:ab51d784ef36 243
AstrodyneSystems 0:ab51d784ef36 244 #ifdef NON_DRDY_MAG
AstrodyneSystems 0:ab51d784ef36 245 // Magnetometer
AstrodyneSystems 0:ab51d784ef36 246 data[0] = lsm303.getMagStatus();
AstrodyneSystems 0:ab51d784ef36 247 pc.printf("MagStatus=%X\r\n", data[0]);
AstrodyneSystems 0:ab51d784ef36 248
AstrodyneSystems 0:ab51d784ef36 249 if(lsm303.bMagDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 250 lsm303.getMagData(f);
AstrodyneSystems 0:ab51d784ef36 251 pc.printf("MAG: %.3f %.3f %.3f %.0f\r\n", f[0], f[1], f[2], atan2(f[1],f[0])*180.0/PI);
AstrodyneSystems 0:ab51d784ef36 252 }
AstrodyneSystems 0:ab51d784ef36 253 #endif
AstrodyneSystems 3:a0863e392562 254
AstrodyneSystems 5:dc778a682d29 255 // Gyro
AstrodyneSystems 5:dc778a682d29 256 if(fGyroLog) {
AstrodyneSystems 5:dc778a682d29 257 if(l3g4200dtr.getStatus() & STATUS_REG_ZYXDA)
AstrodyneSystems 5:dc778a682d29 258 {
AstrodyneSystems 5:dc778a682d29 259 if(bGyroDataStored) {
AstrodyneSystems 5:dc778a682d29 260 l3g4200dtr.getData(f);
AstrodyneSystems 5:dc778a682d29 261 sprintf(str, "%u,4,%.3f,%.3f,%.3f\r\n", time_ms, f[0]+gyro_store[0], f[1]+gyro_store[1], f[2]+gyro_store[2]);
AstrodyneSystems 5:dc778a682d29 262 log_write(str);
AstrodyneSystems 5:dc778a682d29 263 bGyroDataStored = false;
AstrodyneSystems 5:dc778a682d29 264 }
AstrodyneSystems 5:dc778a682d29 265 else {
AstrodyneSystems 5:dc778a682d29 266 l3g4200dtr.getData(gyro_store);
AstrodyneSystems 5:dc778a682d29 267 bGyroDataStored = true;
AstrodyneSystems 5:dc778a682d29 268 }
AstrodyneSystems 3:a0863e392562 269 }
AstrodyneSystems 3:a0863e392562 270 }
AstrodyneSystems 3:a0863e392562 271
AstrodyneSystems 0:ab51d784ef36 272 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 273 }
AstrodyneSystems 3:a0863e392562 274
AstrodyneSystems 3:a0863e392562 275 // Ensure interrupts are off
AstrodyneSystems 1:a54c4a4f3b30 276 MPL3115A2_INT1.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 277 LSM303DLHC_DRDY.fall(NULL);
AstrodyneSystems 0:ab51d784ef36 278 // LSM303DLHC_INT1.rise(NULL);
AstrodyneSystems 3:a0863e392562 279 // L3G4200DTR_DRDY.fall(NULL);
AstrodyneSystems 3:a0863e392562 280
AstrodyneSystems 5:dc778a682d29 281 if(fUBLOXlog) {
AstrodyneSystems 5:dc778a682d29 282 ubloxGps.gps_close();
AstrodyneSystems 5:dc778a682d29 283 }
AstrodyneSystems 5:dc778a682d29 284
AstrodyneSystems 0:ab51d784ef36 285 wait(.1);
AstrodyneSystems 0:ab51d784ef36 286 log_close();
AstrodyneSystems 4:09ffcb9bc1d3 287
AstrodyneSystems 4:09ffcb9bc1d3 288 // Demo MOSFET
AstrodyneSystems 5:dc778a682d29 289 /* pc.printf("Battery voltage=%f\r\n", mosfet.getBattVoltage());
AstrodyneSystems 4:09ffcb9bc1d3 290 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 291 mosfet.setFet(4, 2.0);
AstrodyneSystems 4:09ffcb9bc1d3 292 pc.printf("MOSFET 4 on for 2 seconds.\r\n");
AstrodyneSystems 4:09ffcb9bc1d3 293 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 294 wait(3);
AstrodyneSystems 4:09ffcb9bc1d3 295 pc.printf("MOSFET voltage=%f\r\n", mosfet.getFetVoltage(4));
AstrodyneSystems 4:09ffcb9bc1d3 296
AstrodyneSystems 0:ab51d784ef36 297 pc.printf("Done.\r\n");
AstrodyneSystems 5:dc778a682d29 298 */
AstrodyneSystems 0:ab51d784ef36 299 led2=0;
AstrodyneSystems 0:ab51d784ef36 300
AstrodyneSystems 0:ab51d784ef36 301 // Signal program done
AstrodyneSystems 5:dc778a682d29 302 led1 = 1;
AstrodyneSystems 5:dc778a682d29 303 led4 = led3 = led2 =0;
AstrodyneSystems 0:ab51d784ef36 304 while(1) {
AstrodyneSystems 0:ab51d784ef36 305 wait(0.2);
AstrodyneSystems 5:dc778a682d29 306 data[0] = led4;
AstrodyneSystems 5:dc778a682d29 307 led4 = led3;
AstrodyneSystems 5:dc778a682d29 308 led3 = led2;
AstrodyneSystems 5:dc778a682d29 309 led2 = led1;
AstrodyneSystems 5:dc778a682d29 310 led1 = data[0];
AstrodyneSystems 0:ab51d784ef36 311 }
AstrodyneSystems 0:ab51d784ef36 312 }
AstrodyneSystems 0:ab51d784ef36 313
AstrodyneSystems 0:ab51d784ef36 314
AstrodyneSystems 1:a54c4a4f3b30 315 // Altimeter interrupt service ----------------------------------------
AstrodyneSystems 1:a54c4a4f3b30 316 void MPL3115A2_INT1_INTERRUPT(void)
AstrodyneSystems 1:a54c4a4f3b30 317 {
AstrodyneSystems 1:a54c4a4f3b30 318 float f[3];
AstrodyneSystems 1:a54c4a4f3b30 319 char str[80];
AstrodyneSystems 1:a54c4a4f3b30 320
AstrodyneSystems 1:a54c4a4f3b30 321 __disable_irq();
AstrodyneSystems 1:a54c4a4f3b30 322
AstrodyneSystems 1:a54c4a4f3b30 323 alt.getData(f);
AstrodyneSystems 5:dc778a682d29 324 if(fAltLog) {
AstrodyneSystems 5:dc778a682d29 325 sprintf(str, "%u,1,%.1f,%.1f\r\n", time_ms, f[0], f[1]);
AstrodyneSystems 5:dc778a682d29 326 log_write(str);
AstrodyneSystems 5:dc778a682d29 327 }
AstrodyneSystems 1:a54c4a4f3b30 328
AstrodyneSystems 1:a54c4a4f3b30 329 __enable_irq();
AstrodyneSystems 1:a54c4a4f3b30 330 }
AstrodyneSystems 1:a54c4a4f3b30 331
AstrodyneSystems 0:ab51d784ef36 332
AstrodyneSystems 0:ab51d784ef36 333 // Magnetometer interrupt service -------------------------------------
AstrodyneSystems 0:ab51d784ef36 334 void LSM303DLHC_DRDY_INTERRUPT(void)
AstrodyneSystems 0:ab51d784ef36 335 {
AstrodyneSystems 0:ab51d784ef36 336 float f[3];
AstrodyneSystems 0:ab51d784ef36 337 char str[80];
AstrodyneSystems 0:ab51d784ef36 338
AstrodyneSystems 0:ab51d784ef36 339 __disable_irq();
AstrodyneSystems 0:ab51d784ef36 340 lsm303.getMagData(f);
AstrodyneSystems 0:ab51d784ef36 341 sprintf(str, "%u,3,%.3f,%.3f,%.3f\r\n", time_ms, f[0], f[1], f[2]);
AstrodyneSystems 0:ab51d784ef36 342 log_write(str);
AstrodyneSystems 0:ab51d784ef36 343 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 344 }
AstrodyneSystems 0:ab51d784ef36 345
AstrodyneSystems 0:ab51d784ef36 346
AstrodyneSystems 0:ab51d784ef36 347 // Accelerometer interrupt service ------------------------------------
AstrodyneSystems 0:ab51d784ef36 348 /*void LSM303DLHC_INT1_INTERRUPT(void)
AstrodyneSystems 0:ab51d784ef36 349 {
AstrodyneSystems 0:ab51d784ef36 350 float f[3];
AstrodyneSystems 0:ab51d784ef36 351 unsigned char src;
AstrodyneSystems 0:ab51d784ef36 352 char str[80];
AstrodyneSystems 0:ab51d784ef36 353
AstrodyneSystems 0:ab51d784ef36 354 __disable_irq();
AstrodyneSystems 0:ab51d784ef36 355
AstrodyneSystems 0:ab51d784ef36 356 src = lsm303.getInt1Src();
AstrodyneSystems 0:ab51d784ef36 357 if(lsm303.bAccDataAvailable()) {
AstrodyneSystems 0:ab51d784ef36 358 lsm303.getAccData(f);
AstrodyneSystems 0:ab51d784ef36 359 sprintf(str,"%u,2,%.3f,%.3f,%.3f,%x\r\n", time_ms, f[0], f[1], f[2], src);
AstrodyneSystems 0:ab51d784ef36 360 log_write(str);
AstrodyneSystems 0:ab51d784ef36 361 if(++accCnt >= accAltDecimate) {
AstrodyneSystems 0:ab51d784ef36 362 accCnt = 0;
AstrodyneSystems 0:ab51d784ef36 363 alt.OST();
AstrodyneSystems 0:ab51d784ef36 364 }
AstrodyneSystems 0:ab51d784ef36 365 }
AstrodyneSystems 0:ab51d784ef36 366
AstrodyneSystems 0:ab51d784ef36 367 __enable_irq();
AstrodyneSystems 0:ab51d784ef36 368 }
AstrodyneSystems 0:ab51d784ef36 369 */
AstrodyneSystems 2:6698a2433bfd 370
AstrodyneSystems 2:6698a2433bfd 371
AstrodyneSystems 2:6698a2433bfd 372 // Read configuration file --------------------------------------------
AstrodyneSystems 2:6698a2433bfd 373 void ReadConfigfile(void) {
AstrodyneSystems 2:6698a2433bfd 374 ConfigFile cfgFile("/local/SCIbdCfg.txt");
AstrodyneSystems 2:6698a2433bfd 375 int n;
AstrodyneSystems 2:6698a2433bfd 376 float f;
AstrodyneSystems 2:6698a2433bfd 377
AstrodyneSystems 2:6698a2433bfd 378 for(n=0; n<sizeof(cfgKeyStr)/sizeof(char*); n++) {
AstrodyneSystems 2:6698a2433bfd 379 if(cfgFile.getValue(cfgKeyStr[n], &f))
AstrodyneSystems 2:6698a2433bfd 380 {
AstrodyneSystems 2:6698a2433bfd 381 if(f < 0) f = 0;
AstrodyneSystems 2:6698a2433bfd 382 *(cfgFloatPtr[n]) = f;
AstrodyneSystems 2:6698a2433bfd 383 pc.printf("Found: %s: %f\r\n", cfgKeyStr[n], f);
AstrodyneSystems 2:6698a2433bfd 384 }
AstrodyneSystems 2:6698a2433bfd 385 }
AstrodyneSystems 2:6698a2433bfd 386 cfgFile.closeFile();
AstrodyneSystems 2:6698a2433bfd 387
AstrodyneSystems 2:6698a2433bfd 388 if(fMachDelay > 15.0)
AstrodyneSystems 2:6698a2433bfd 389 fMachDelay = 15;
AstrodyneSystems 2:6698a2433bfd 390
AstrodyneSystems 2:6698a2433bfd 391 if(fMainDeploymentAlt < 300)
AstrodyneSystems 2:6698a2433bfd 392 fMainDeploymentAlt = 300;
AstrodyneSystems 2:6698a2433bfd 393 else if(fMainDeploymentAlt > 2000)
AstrodyneSystems 2:6698a2433bfd 394 fMainDeploymentAlt = 2000;
AstrodyneSystems 2:6698a2433bfd 395
AstrodyneSystems 2:6698a2433bfd 396 // save config file if not found?
AstrodyneSystems 2:6698a2433bfd 397
AstrodyneSystems 5:dc778a682d29 398 }