Compare commits
14 commits
cosmicpi-j
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f59f562b53 | ||
|
|
fc797e1dda | ||
|
|
63b5a38302 | ||
|
|
b12b953106 | ||
|
|
71d58103f1 | ||
| e47a1fe05b | |||
|
|
9d19a102b7 | ||
|
|
a27f481795 | ||
|
|
e4682e8aac | ||
|
|
d36099db37 | ||
|
|
af3e44c522 | ||
| d18a147ba5 | |||
| 198021db5a | |||
| a3a422fd41 |
5 changed files with 1189 additions and 59 deletions
6
README.md
Normal file
6
README.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# cosmicpi-arduino
|
||||
|
||||
The firmware must be in a file called `cosmicpi-arduino.ino` in this directory in order to
|
||||
make the Arduino IDE happy.
|
||||
|
||||
The Adafruit libraries here have been modified.
|
||||
1107
cosmicpi-arduino.bak
Normal file
1107
cosmicpi-arduino.bak
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1 +0,0 @@
|
|||
cosmicpi-arduino.ino
|
||||
|
|
@ -27,43 +27,35 @@
|
|||
// All fields in all output strings conform to the json standard
|
||||
|
||||
// Here is the list of all records where 'f' denotes float and 'i' denotes integer ...
|
||||
// {'HTU':{'Tmh':f,'Hum':f}}
|
||||
// HTU21DF record containing Tmh:temperature in C Hum:humidity percent
|
||||
// {'temperature':{'temperature':f,'humidity':f}}
|
||||
// HTU21DF record
|
||||
//
|
||||
// {'BMP':{'Tmb':f,'Prs':f,'Alb':f}}
|
||||
// BMP085 record containing Tmb:temperature Prs:pressure Alb:Barrometric altitude
|
||||
// {'barometer':{'temperature':f,'pressure':f,'altitude':f}}
|
||||
// BMP085 record
|
||||
//
|
||||
// {'VIB':{'Vax':i,'Vcn':i}}
|
||||
// Vibration record containing Vax:3 bit xyz direction mask Vcn:vibration count
|
||||
// This record is always immediatly followed by 3 more records, TIM, ACL, and MAG
|
||||
// {'vibration':{'direction':i,'count':i}}
|
||||
// Vibration record containing "direction":3 bit xyz direction mask "count":vibration count
|
||||
// This record is always immediatly followed by 3 more records, "timing", "accelerometer", and "magnetometer"
|
||||
//
|
||||
// {'MAG':{'Mgx':f,'Mgy':f,'Mgz':f}}
|
||||
// LSM303DLH magnatometer record containing Mgx:the x field strength Mgy:the y field Mgz:ther z field
|
||||
// {'magnetometer':{'x':f,'y':f,'x':f}}
|
||||
// LSM303DLH magnetometer record containing "x":the x field strength "y":the y field "z":the z field
|
||||
//
|
||||
// {'MOG':{'Mox':f,'Moy':f,'Moz':f}}
|
||||
// LSM303DLH magnatometer record containing Mox:x orientation Moy:y orientation Moz:z orientation
|
||||
// This record is optional, by default its turned off (it can always be calculated later - Python)
|
||||
// {'accelerometer':{'x':f,'y':f,'z':f}}
|
||||
// LSM303DLH accelerometer record
|
||||
// If this record immediately follows a "vibration" record the fields were hardware latched when the g threshold was exceeded
|
||||
//
|
||||
// {'ACL':{'Acx':f,'Acy':f,'Acz':f}}
|
||||
// LSM303DLH acclerometer record containing Acx:the x acceleration Acy:the y acceleration Acz:the z acceleration
|
||||
// If this record immediatly follows a VIB record the fields were hardware latched when the g threshold was exceeded
|
||||
// {'location':{'latitude':f,'longitude':f,'altitude':f}}
|
||||
// GPS location record containing "latitude":latitude in degrees "longitude":longitude in degrees "altitude":altitude in meters
|
||||
//
|
||||
// {'AOL':{'Aox':f,'Aoy':f,'Aoz':f}}
|
||||
// LSM303DLH accelerometer record containing Aox:x orientation Aoy:y orientation Aoz:z orientation
|
||||
// This record is optional, by default its turned off (it can always be calculated later - Python)
|
||||
// {'timing':{'uptime':i,'counter_frequency':i,'time_string':i}}
|
||||
// Time record containing "uptime":up time seconds "counter_frequency":counter frequency "time_string":time string
|
||||
//
|
||||
// {'LOC':{'Lat':f,'Lon':f,'Alt':f}}
|
||||
// GPS location record containing Lat:latitude in degrees Lon:longitude in degrees Alt:altitude in meters
|
||||
// {'status':{'queue_size':i,'missed_events':i,'buffer_error':i,'temp_status':i,'baro_status':i,'accel_status':i,'mag_status':i, 'gps_status':i}}
|
||||
// Status record
|
||||
//
|
||||
// {'TIM':{'Upt':i,'Frq':i,'Sec':i}}
|
||||
// Time record containing Upt:up time seconds Frq:counter frequency Sec:time string
|
||||
//
|
||||
// {'STS':{'Qsz':i,'Mis':i,'Ter':i,'Htu':i,'Bmp':i,'Acl':i,'Mag':i}}
|
||||
// Status record containing Qsz:events on queue Mis:missed events Ter:buffer error Htu:status Bmp:status Acl:status Mag:status
|
||||
//
|
||||
// {'EVT':{'Evt':i,'Frq':i,'Tks':i,'Etm':f,'Adc':[[i,i,i,i,i,i,i,i][i,i,i,i,i,i,i,i]]}}
|
||||
// Event record containing Evt:event number in second Frq:timer frequency Tks:ticks since last event in second
|
||||
// Etm:event time stamp to 100ns Adc:[[Channel 0 values][Channel 1 values]]
|
||||
// {'event':{'event_number':i,'timer_frequency':i,'ticks':i,'timestamp':f,'adc':[[i,i,i,i,i,i,i,i][i,i,i,i,i,i,i,i]]}}
|
||||
// Event record containing "event_number":event number in second "ticks":ticks since last event in seconds
|
||||
// "timestamp":event time stamp to 100ns adc:[[Channel 0 values][Channel 1 values]]
|
||||
|
||||
// N.B. These records pass the data to a python monitor over the serial line. Python has awsome string handling and looks them up in
|
||||
// associative arrays to build records of any arbitary format you want. So this is only the start of the story of record processing.
|
||||
|
|
@ -74,7 +66,6 @@
|
|||
|
||||
#include <time.h>
|
||||
#include <Wire.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "Adafruit_BMP085_U.h" // Barrometric pressure
|
||||
|
||||
|
|
@ -128,6 +119,7 @@
|
|||
// Instantiate external hardware breakouts
|
||||
|
||||
Adafruit_GPS gps(&Serial1); // GPS Serial1 on pins RX1 and TX1
|
||||
boolean gps_ok = false; // Chip OK flag
|
||||
|
||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF(); // Humidity and temperature measurment
|
||||
boolean htu_ok = false; // Chip OK
|
||||
|
|
@ -795,7 +787,7 @@ void PushHtu(int flg) { // If flg is true always push
|
|||
if ((flg) || ((htu_ok) && ((ppcnt % humtmp_display_rate) == 0))) {
|
||||
temph = htu.readTemperature();
|
||||
humid = htu.readHumidity();
|
||||
sprintf(txt,"{'HTU':{'Tmh':%5.3f,'Hum':%4.1f}}\n",temph,humid);
|
||||
sprintf(txt,"{'temperature':{'temperature':%5.3f,'humidity':%4.1f}}\n",temph,humid);
|
||||
PushTxt(txt);
|
||||
}
|
||||
}
|
||||
|
|
@ -816,7 +808,7 @@ void PushBmp(int flg) { // If flg is true always push
|
|||
bmp.getTemperature(&tempb);
|
||||
altib = bmp.pressureToAltitude((float) SENSORS_PRESSURE_SEALEVELHPA,
|
||||
presr,tempb);
|
||||
sprintf(txt,"{'BMP':{'Tmb':%5.3f,'Prs':%5.3f,'Alb':%4.1f}}\n",tempb,presr,altib);
|
||||
sprintf(txt,"{'barometer':{'temperature':%5.3f,'pressure':%5.3f,'altitude':%4.1f}}\n",tempb,presr,altib);
|
||||
PushTxt(txt);
|
||||
}
|
||||
}
|
||||
|
|
@ -837,7 +829,7 @@ uint32_t old_icount = 0;
|
|||
PushTim(1); // Push these first, and then vib
|
||||
PushAcl(1); // This is the real latched value
|
||||
PushMag(1);
|
||||
sprintf(txt,"{'VIB':{'Vax':%d,'Vcn':%d}}\n",accl_flag,accl_icount);
|
||||
sprintf(txt,"{'vibration':{'direction':%d,'count':%d}}\n",accl_flag,accl_icount);
|
||||
PushTxt(txt);
|
||||
}
|
||||
}
|
||||
|
|
@ -854,19 +846,11 @@ void PushMag(int flg) { // Push the mago stuff
|
|||
|
||||
// Micro Tesla
|
||||
|
||||
sprintf(txt,"{'MAG':{'Mgx':%f,'Mgy':%f,'Mgz':%f}}\n",
|
||||
sprintf(txt,"{'magnetometer':{'x':%f,'y':%f,'z':%f}}\n",
|
||||
mag_event.magnetic.x,
|
||||
mag_event.magnetic.y,
|
||||
mag_event.magnetic.z);
|
||||
PushTxt(txt);
|
||||
|
||||
// Orientation (Easy to calculate later in Python - dont waste resources)
|
||||
#ifdef ORIENTATION
|
||||
if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &xyz)) {
|
||||
sprintf(txt,"{'MOG':{'Mox':%f,'Moy':%f,'Moz':%f}}\n",xyz.x,xyz.y,xyz.z);
|
||||
PushTxt(txt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -881,19 +865,11 @@ void PushAcl(int flg) { // Push the accelerometer and compass stuff
|
|||
|
||||
// Meters per second squared
|
||||
|
||||
sprintf(txt,"{'ACL':{'Acx':%f,'Acy':%f,'Acz':%f}}\n",
|
||||
sprintf(txt,"{'accelerometer':{'x':%f,'y':%f,'z':%f}}\n",
|
||||
acl_event.acceleration.x,
|
||||
acl_event.acceleration.y,
|
||||
acl_event.acceleration.z);
|
||||
PushTxt(txt);
|
||||
|
||||
// Orientation (Easy to calculate later in Python - dont waste resources)
|
||||
#ifdef ORIENTATION
|
||||
if (dof.accelGetOrientation(&acl_event, &xyz)) {
|
||||
sprintf(txt,"{'AOL':{'Aox':%f,'Aoy':%f,'Aoz':%f}}\n",xyz.x,xyz.y,xyz.z);
|
||||
PushTxt(txt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -902,7 +878,7 @@ void PushAcl(int flg) { // Push the accelerometer and compass stuff
|
|||
void PushLoc(int flg) {
|
||||
|
||||
if ((flg) || ((ppcnt % latlon_display_rate) == 0)) {
|
||||
sprintf(txt,"{'LOC':{'Lat':%f,'Lon':%f,'Alt':%f}}\n",latitude,longitude,altitude);
|
||||
sprintf(txt,"{'location':{'latitude':%f,'longitude':%f,'altitude':%f}}\n",latitude,longitude,altitude);
|
||||
PushTxt(txt);
|
||||
}
|
||||
}
|
||||
|
|
@ -912,7 +888,7 @@ void PushLoc(int flg) {
|
|||
void PushTim(int flg) {
|
||||
|
||||
if ((flg) || ((ppcnt % frqutc_display_rate) == 0)) {
|
||||
sprintf(txt,"{'TIM':{'Upt':%4d,'Frq':%7d,'Sec':%s}}\n",ppcnt,rega0,rdtm);
|
||||
sprintf(txt,"{'timing':{'uptime':%4d,'counter_frequency':%7d,'time_string':%s}}\n",ppcnt,rega0,rdtm);
|
||||
PushTxt(txt);
|
||||
}
|
||||
}
|
||||
|
|
@ -923,8 +899,8 @@ void PushSts(int flg, int qsize, int missed) {
|
|||
uint8_t res;
|
||||
|
||||
if ((flg) || ((ppcnt % status_display_rate) == 0)) {
|
||||
sprintf(txt,"{'STS':{'Qsz':%2d,'Mis':%2d,'Ter':%d,'Htu':%d,'Bmp':%d,'Acl':%d,'Mag':%d}}\n",
|
||||
qsize,missed,terr,htu_ok,bmp_ok,acl_ok,mag_ok);
|
||||
sprintf(txt,"{'status':{'queue_size':%2d,'missed_events':%2d,'buffer_error':%d,'temp_status':%d,'baro_status':%d,'accel_status':%d,'mag_status':%d,'gps_status':%d}}\n",
|
||||
qsize,missed,terr,htu_ok,bmp_ok,acl_ok,mag_ok,gps_ok);
|
||||
PushTxt(txt);
|
||||
terr = 0;
|
||||
}
|
||||
|
|
@ -969,8 +945,8 @@ void PushEvq(int flg, int *qsize, int *missed) {
|
|||
// Build string and push it out to the print buffer
|
||||
|
||||
sprintf(txt,
|
||||
"{'EVT':{'Evt':%1d,'Frq':%8d,'Tks':%8d,'Etm':%s%s,"
|
||||
"'Adc':[[%d,%d,%d,%d,%d,%d,%d,%d],[%d,%d,%d,%d,%d,%d,%d,%d]]}}\n",
|
||||
"{'event':{'event_number':%1d,'timer_frequency':%8d,'ticks':%8d,'timestamp':%s%s,"
|
||||
"'adc':[[%d,%d,%d,%d,%d,%d,%d,%d],[%d,%d,%d,%d,%d,%d,%d,%d]]}}\n",
|
||||
eb.Count, eb.Frequency, eb.Ticks, eb.DateTime, index(stx,'.'),
|
||||
eb.Ch0[0],eb.Ch0[1],eb.Ch0[2],eb.Ch0[3],eb.Ch0[4],eb.Ch0[5],eb.Ch0[6],eb.Ch0[7],
|
||||
eb.Ch1[0],eb.Ch1[1],eb.Ch1[2],eb.Ch1[3],eb.Ch1[4],eb.Ch1[5],eb.Ch1[6],eb.Ch1[7]);
|
||||
|
|
@ -1098,8 +1074,15 @@ void loop() {
|
|||
#if PPS_PIN
|
||||
digitalWrite(PPS_PIN,LOW); // Reset PPS
|
||||
#endif
|
||||
displ = 0; // Clear flag for next PPS
|
||||
displ = 0; // Clear flag for next PPS
|
||||
gps_ok = true; // Its OK because we got a PPS
|
||||
}
|
||||
|
||||
if (gps_ok == false) {
|
||||
delay(1000); // One second sleep
|
||||
PushSts(0,qsize,missed); // Push bad hardware status
|
||||
}
|
||||
|
||||
PutChar(); // Print one character per loop !!!
|
||||
ReadOneChar(); // Get next input command char
|
||||
}
|
||||
|
|
|
|||
35
pinout.text
Normal file
35
pinout.text
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
Accelerometer:
|
||||
VIN > 5V
|
||||
GND > GND
|
||||
SCL > SCL 21
|
||||
SDA > SDA 20
|
||||
GINT> Digital 10
|
||||
|
||||
GPS:
|
||||
FIX > Digital 2 if there is no GPS coverage
|
||||
TX > RX1 19
|
||||
RX > TX1 18
|
||||
GND > GND
|
||||
VIN > 5V
|
||||
PPS > Digital 2 if there is GPS coverage
|
||||
|
||||
Humidity:
|
||||
VIN > 5V
|
||||
GND > GND
|
||||
SDA > SDA1
|
||||
SCL > SCL1
|
||||
|
||||
Maxim evaluation board:
|
||||
VIN > 3.3V
|
||||
GND > GND
|
||||
CL > N/C
|
||||
DIN > SPI 4 (dot is 1, counting left to right)
|
||||
SCLK> SPI 3
|
||||
CS > Digital 52
|
||||
|
||||
ADC in:
|
||||
CHA > Analog 6
|
||||
CHB > Analog 7
|
||||
|
||||
Trigger:
|
||||
TRG > Digital 5 (can be connected to PPS or FIX if there is no trigger signal available)
|
||||
Loading…
Reference in a new issue