Compare commits

...

14 commits

Author SHA1 Message Date
Justin Lewis Salmon
f59f562b53 Merge pull request #3 from jlsalmon/master
Rename packet variables to be human-readable
2016-05-10 16:38:46 +02:00
Justin Lewis Salmon
fc797e1dda Removed unnecessary packets 2016-05-09 23:58:05 +02:00
Justin Lewis Salmon
63b5a38302 Updated documentation 2016-05-09 23:55:22 +02:00
Justin Lewis Salmon
b12b953106 Rename packet variables to be human-readable 2016-05-09 23:45:10 +02:00
Justin Lewis Salmon
71d58103f1 Update README.md 2016-05-06 19:34:36 +02:00
e47a1fe05b Renamed geo_cosmic_pi.ino -> cosmicpi-arduino.ino, removed python code that now lives in the cosmicpi-daq repo 2016-05-06 19:30:22 +02:00
Justin Lewis Salmon
9d19a102b7 Update README.md 2016-05-06 19:26:18 +02:00
Justin Lewis Salmon
a27f481795 Create README.md 2016-05-06 19:24:01 +02:00
Justin Lewis Salmon
e4682e8aac Delete pi-server.py 2016-05-06 19:20:41 +02:00
Julian Lewis
d36099db37 Added this file, you need it. GPS check 2016-05-06 19:12:03 +02:00
Julian Lewis
af3e44c522 Added GPS check 2016-05-06 19:11:10 +02:00
d18a147ba5 Create pinout.text
pinouts for arudino
2016-05-06 18:55:57 +02:00
198021db5a updated files for main arduino programme, uses new SerialUSB method.
Still porting functionality from Julian's code
Needs more work and testing!
2016-04-24 21:38:25 +02:00
a3a422fd41 Updated the event timing functionality to remove the need for a diode.
Summary of new functionality:
Upon event interrupt, the current value of the TC0 counter is pushed to the counter buffer.
The TC2 status (interrupt unlatch) is reset at the end of the interrupt call.
Running it to test the GPS accuracy, we've got a fixed offset of 54 clock counts, variation up to +2 counts.
2016-04-23 17:02:48 +02:00
5 changed files with 1189 additions and 59 deletions

6
README.md Normal file
View 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

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
cosmicpi-arduino.ino

View file

@ -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
View 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)