AAU CanSat Shield v7,8
Koden er også i src mappe
Src folder list: here
//(C)JDN 2025
//Disclaimer for disse sider
//Det du finder, læser og bruger her er på eget ansvar og uden garanti for at det virker
//Så burde det være klart
/*
Jens Dalsgaard Nielsen
Aalborg Denmark
//-----------------------------------
// 20Hz sampling for sdcard
// 5 Hz sampling for radio due to lower comm capacity
// change it in line 35 below tStep: sdcard, tStep2: radio
#include
#include
#include
#include
#define MPU 0x68
#define BMP 0x76
BMP280 bmp280(BMP);
// uncomment below if program shall configure radio during startup
// remember jumpers
//1 ON
// 2 ON CLOSET TO RADIO
// 3 ON CLOSET TO RADIO
// 4 IN FAREST AWAY FROM RADIO: does say openlog from hw serial port
//#define RADIOCONFIG
#ifdef RADIOCONFIG
#define RADIOSTR "438500 2 9 3 0"
#endif
SoftwareSerial softSer01(4, 5); // RX, TX
apc220cfg soft01(&softSer01, 7);
char xStr[35];
unsigned long nextT, tStep = 50, nextT2, tStep2 = 200;
// APC220
/*
Configuration parameters
See in datasheet for how to configure the radio It consists of a simple textstring with the following format:
config string: example: FFFFFF R P B C
FFFFFF - Frequency
434000 is 434,000 MHz
R: radio link baudrate in kHz
1/2/3/4 equals 2400(1km)/4800/9600/19200bps
P: Radio output power
0 .. 9 where 9(highest) equals 13dBm(20mW)
B UART baudrate (between radio and you
UART baudrate - 0/1/2/3/4/5/6 equals 1200/2400/4800/9600/19200/38400/57600bps
C: UART parity check
Byte Check Parity - 0/1/2 equals NoCheck(8N1)/EvenParity(8E1)/OddParity(8O1)
config string: example:
415000 MHz 9600 baud-in-air full radiopower uart baudrate 57600 no parity
415000 3 9 6 0
https://jensd.dk/doc/wless/apc220-radio/apc220code.html
*/
// GYRO ACC ETC
// max for acc and gyro is an integer: -32768 -> 32767
//
// so acc config to +-8G means that -327678 == -8G etc
// accelerometer config
// 0x18 +- 16G
// 0x10 +-8 G
// 0x08 +-4
// 0x00 +-2
// gyro config
// Full scale range = 2000 dpsSerial.print(" \t");
// 0x18 +- 2000 degr/sec
// 0x10 +- 1000 gr/sec
// 0x08 +- 500 gr/Sec
// 0x00 +- 250 gr/sec
uint32_t press;
int x, y, z, gx, gy, gz;
float temp, tryk, hojde;
unsigned long mls;
float todayPres = 103300.00;
void setup() {
Serial.begin(38400);
helloInfo();
softSer01.begin(9600); // til apc220 radio
delay(100);
cfgRadio();
delay(2000);
softSer01.end();
delay(1000);
softSer01.begin(9600);
Wire.begin();
delay(100);
mpu606xInit(MPU);
mpu606xConfigAcc(0x08); // + - 4G
// max G (4) is read as +- 32767
mpu606xConfigGyro(0x08); // + - 500 gr/sek
// and rot the same scaling
bmp280.begin();
nextT = millis() + tStep;
nextT2 = millis() + tStep2;
}
void loop() {
// dump til sd kort
mls = millis();
// this if block control log to openlog runs at tStep time
if (nextT <= mls) {
nextT += tStep;
mpu606XgetAcc(&x, &y, &z); // gem acceleration i x,y,z
mpu606XgetGyro(&gx, &gy, &gz); // rotation gx,gy,gz
hojde = bmp280.calAltitudeF(press, todayPres);
press = bmp280.getPressure();
temp = bmp280.getTemperature();
Serial.print(millis()); Serial.print(" \t");
Serial.print(x); Serial.print(" \t");
Serial.print(y); Serial.print(" \t");
Serial.print(z); Serial.print(" \t");
Serial.print(gx); Serial.print(" \t");
Serial.print(gy); Serial.print(" \t");
Serial.print(gz); Serial.print("\t");
Serial.print(temp); Serial.print(" \t");
Serial.print(press); Serial.print(" \t");
Serial.print(hojde); Serial.print(" \t");
Serial.println();
}
// this block runs every tStop millisec
if (nextT2 <= mls) {
nextT2 += tStep2;
softSer01.print(mls); softSer01.print(" \t");
softSer01.print(x); softSer01.print(" \t");
softSer01.print(y); softSer01.print(" \t");
softSer01.println(z);
}
}
void helloInfo() {
delay(100);
Serial.println(__FILE__);
Serial.println(__DATE__);
Serial.println(" mpu606x, bmp280");
Serial.println(todayPres);
Serial.println("time(msec)accx accy accz temp tryk hojde finish time(msec)");
Serial.print("tPeriod(msec) ");
Serial.println(tStep);
Serial.print("mpu 0x");
Serial.print(MPU,HEX);
Serial.print(" BMP 0x");
Serial.println(BMP,HEX);
Serial.print("tPeriod sd card(msec) ");
Serial.println(tStep);
Serial.print("tPeriod radio(msec) ");
Serial.println(tStep2);
}
void cfgRadio() {
int res;
#ifdef RADIOCONFIG
soft01.wrCfg(RADIOSTR); //xxx,000 Mhz, full power,4800 baud in air, 9600 baud to Arduino, no parity
#endif
delay(100);
res = soft01.rdCfg(xStr);
if (res == 0) {
Serial.print("Radio freq: ");
Serial.println(xStr);
} else {
Serial.print("No radio found");
Serial.println(res);
}
}
// ende
LICENSE
The Beerware Licence (Revision 42): borrowed from creator
<jensd@jensd.dk> aka Jens Dalsgaard Nielsen> wrote this file.
As long as you retain this notice you can do whatever you want with this stuff.
/Jens
DISCLAIMER
Det du finder, læser og bruger her er på eget ansvar og uden garanti for at det virker
Der er helt sikkert huller og mangler hist og her
Så burde det være klart
Take theses pages for what it is - no guarantee for all is correct - you are on your own risk
Jens Dalsgaard Nielsen
---oOo---
Minds are like parachutes - they only function when open.
Thomas Dewar
Jens
|