/*
* This program suports the RHElectronics Radiation Detector Arduino Compatable version 3.1
* Computer components;
* Arduino Mega 256 (needed two Serial ports for debugger and GPS)
* Adafruit GPS Shield
* Adafruit 2.8 TFT display
* All of the operations in the main loop are fit into less than 900ms allowing the processing to
finish before the next
* GPS message is received.
* GPS is set up to sent locations at a 1 second rate. This works well since it has a good clock.
*
*This program appears to work but no clame is made for its accuracy.
*Anyone may use it but no responsibility is assumed for its use.
*Its a good place to start if you want to build your own code
*/
#include <SPI.h>
#include <SD.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#include <Adafruit_GPS.h>
#define _cs 10
#define _dc 9
#define _rst 2
// SPI bus uses MOSI - pin 11, ISO - 12, CLK - 13
// SD chipselect - 4
// Display chipselect - 10
// Display data - 9
// Display rst -8
// Use hardware SPI for display
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
int i = 0;
int j = 0;
int k = 0;
int x = 0;
int y = 0;
int z = 0;
int p = 0;
int q = 0;
int r = 0;
long int time;
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
// Giger Counter Support Values
const byte interruptPin = 21;
int timeAdjustment;
volatile int pointer = 0;
volatile int counts[61];
int sum;
float sieverts;
File myFile;
// set up read/write function
char Alpha[] = ("");
String WriteDataRecord = "Null Record";
String ReadDataRecord = "Read Data Record";
String WriteFileName = "[Link]";
String ReadFileName = "[Link]";
String RemoveFileName = "[Link]";
int records = 0;
int writeSDflag = 0;
int displayDataflag = 0;
int hours = 0;
int minutes = 0;
int seconds = 0, ms = 0;
int days = 0;
int months = 0;
int years = 0;
int signalLock = 0;
int signalQual = 0;
float Latitude = 0;
float Longitude = 0;
char LatEW = 0;
char LonNS = 0;
int Speed = 0;
int Angle = 0;
int Altitude = 0;
int Satellites = 0;
//GPS TX to Arduino Due Serial1 RX pin 19
//GPS RX to Arduino Due Serial1 TX pin 18
#define mySerial Serial1
Adafruit_GPS GPS(&mySerial);
// Set to 'true if you want to debug and listen to the raw GPS sentences.
#define GPSECHO false
// this keeps track of whether we're using the interrupt - off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean);
// this keeps track of whether we're using the interrupt - off by default!
//boolean usingInterrupt = false;
//void useInterrupt(boolean);
void setup() {
// put your setup code here, to run once:
// Open serial communications and wait for port to open:
[Link](9600);
// while (!Serial) {};
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
[Link](9600);
[Link](9600);
while (!Serial1) {};
delay(1000);
// Initialize the Giger Counter Interrupts
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), tick, LOW);
[Link]();
[Link](ILI9340_BLACK);
//uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including
altitude
[Link](PMTK_SET_NMEA_OUTPUT_RMCGGA);
// [Link](PMTK_SET_NMEA_OUTPUT_RMCONLY);
// Set the update rate
[Link](PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// [Link](PMTK_SET_NMEA_UPDATE_200_MILLIHERTZ); // 0.5Hz update
rate
// [Link](PMTK_SET_NMEA_UPDATE_100_MILLIHERTZ); // 0.1Hz update rate
//Request updates on antenna status, comment out to keep quiet
//[Link](PGCMD_ANTENNA);
[Link]("");
[Link]("Initialization Completed");
int S = SSDDiscoverFunction();
S = SSDStartSSDFunction();
S = SSDListDirFunction();
S = SSDRemoveFunction();
if(S > 0) [Link]("Remove Error");
}
void loop() {
// put your main code here, to run repeatedly:
time=micros();
char c = [Link]();
//if a sentence is received, we can check the checksum, parse it...
if ([Link]()) {
// WriteDataRecord = [Link]();
if ()) return;
hours = [Link] - 5;
if(hours < 0) hours += 24;
minutes = [Link];
seconds = [Link];
ms = [Link];
days = [Link];
months = [Link];
years = [Link];
signalLock = [Link];
signalQual = [Link];
if (signalLock) {
Latitude = [Link];
LatEW = [Link];
Longitude = [Link];
LonNS = [Link];
Speed = [Link];
Angle = [Link];
Altitude = [Link] * 3.280839895;
Satellites = [Link];
}
displayDataflag = displayDataflag + 1;
}
while(displayDataflag > 1){
[Link](3);
[Link](ILI9340_WHITE);
[Link](2);
for (i=10;i<26;i++){[Link](70,i,150,ILI9340_BLACK);}
[Link](0, 10);
[Link]("Time: ");
[Link](hours, DEC); [Link](':');
[Link](minutes, DEC); [Link](':');
[Link](seconds, DEC); [Link](':');
[Link](ms, DEC);
for (i=26;i<42;i++){[Link](70,i,150,ILI9340_BLACK);}
[Link]("Date: ");
[Link](months, DEC); [Link]('/');
[Link](days, DEC); [Link]("/20");
[Link](years, DEC);
for (i=42;i<58;i++){[Link](150,i,60,ILI9340_BLACK);}
[Link]("Signal Lock: "); [Link](signalLock);
for (i=58;i<74;i++){[Link](150,i,60,ILI9340_BLACK);}
[Link]("Signal Qual: "); [Link](signalQual);
if (signalLock) {
for (i=74;i<90;i++){[Link](50,i,220,ILI9340_BLACK);}
int z = int(Latitude);
int x = int(z/100);
int y = z - int((x*100));
z = int(((Latitude - float(z)))*60);
[Link]("LAT: "); [Link](x); [Link]("deg "); [Link](y); [Link]("min "); [Link](z); [Link]("sec
"); [Link](LatEW);
WriteDataRecord = "LOC = ";
itoa(x, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "Deg ";
itoa(y, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "min " ;
itoa(z, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "sec " + LatEW +" ";
for (i=90;i<106;i++){[Link](50,i,220,ILI9340_BLACK);}
z = int(Longitude);
x = int(z/100);
y = z - int((x*100));
z = int(((Longitude - float(z)))*60);
[Link]("LON: "); [Link](x); [Link]("deg "); [Link](y); [Link]("min "); [Link](z);
[Link]("sec "); [Link](LonNS);
itoa(x, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "Deg ";
itoa(y, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "min " ;
itoa(z, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "sec " + LonNS +" ";
for (i=106;i<122;i++){[Link](75,i,60,ILI9340_BLACK);}
[Link]("Speed: "); [Link](Speed);
for (i=122;i<138;i++){[Link](75,i,60,ILI9340_BLACK);}
[Link]("Angle: "); [Link](Angle);
for (i=138;i<154;i++){[Link](110,i,80,ILI9340_BLACK);}
[Link]("Altitude: "); [Link](Altitude);
for (i=154;i<170;i++){[Link](135,i,50,ILI9340_BLACK);}
[Link]("Satellites: "); [Link](Satellites);
}
[Link]("\nTime: ");
[Link](hours, DEC); [Link](':');
[Link](minutes, DEC); [Link](':');
[Link](seconds, DEC); [Link]('.');
[Link](ms);
[Link]("Date: ");
[Link](months, DEC); [Link]('/');
[Link](days, DEC); [Link]("/20");
[Link](years, DEC);
[Link]("Fix: "); [Link](signalLock);
[Link](" quality: "); [Link](signalQual);
if (signalLock) {
[Link]("Location: ");
[Link](Latitude, 4); [Link](LatEW);
[Link](", ");
[Link](Longitude, 4); [Link](LonNS);
[Link]("Speed (knots): "); [Link](Speed);
[Link]("Angle: "); [Link](Angle);
[Link]("Altitude: "); [Link](Altitude);
[Link]("Satellites: "); [Link](Satellites);
}
// Giger Counter Code
noInterrupts();
if (pointer < 60) { pointer = pointer + 1; }
else { pointer = 0; }
counts[pointer] = 0;
interrupts();
sum = 0;
for (i=0; i <= 60; i++){ if(i != pointer){ sum = sum + counts[i]; }}
[Link]("Count = ");
[Link](sum);
sieverts = sum * 0.0057; // Convert Counts to Micro Sieverts per Hour
[Link](" Dose = ");
[Link](sieverts);
[Link](" uSieverts/Hr");
[Link]("");
for (i=186;i<202;i++){[Link](190,i,60,ILI9340_BLACK);}
[Link]("Counts/Minute = "); [Link](sum);
for (i=202;i<218;i++){[Link](75,i,60,ILI9340_BLACK);}
[Link]("Dose = "); [Link](sieverts); [Link](" uSieverts/Hr");
WriteDataRecord = WriteDataRecord + "Counts ";
itoa(sum, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + " Dosage = ";
x = int(sieverts*1000);
ltoa(x, Alpha, 10);
WriteDataRecord = WriteDataRecord + Alpha + "*10E-9 Sieverts EOR";
[Link](WriteDataRecord);
int S = SSDWriteFunction();
if(S > 0) [Link]("Write Error");
S = SSDReadFunction();
if(S > 0) [Link]("Read Error");
[Link](ReadDataRecord);
records += 1;
[Link]("Record Number Written to Disk = "); [Link](records);
time=micros()-time;
[Link]("Process Time = "); [Link](time); [Link]("us");
displayDataflag = 0;
}
}
// Interrupt Routine for the Giger Counter
void tick() { counts[pointer] = counts[pointer] + 1; }
// Check to see if the SD card is there and Initialize the File System
int SSDDiscoverFunction() {
int R = 1;
[Link]("\nSD card - ");
if () {
[Link]("Initialization failed");
[Link](" Things to check:");
[Link](" Is a card inserted?");
[Link](" Is your wiring correct?");
[Link](" Does the chipSelect PIN match your Shield?");
return R; }
[Link]("Recognized");
// print the type of card
[Link](" Card type: ");
switch ([Link]()) {
case SD_CARD_TYPE_SD1:
[Link]("SD1");
break;
case SD_CARD_TYPE_SD2:
[Link]("SD2");
break;
case SD_CARD_TYPE_SDHC:
[Link]("SDHC");
break;
default:
[Link]("Unknown");}
// Open the 'volume'/'partition' - it should be FAT16 or FAT32
if () {
[Link](" Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return R;}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
[Link](" Volume type is FAT");
[Link]([Link](), DEC);
volumesize = [Link](); // clusters are collections of blocks
volumesize *= [Link](); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
[Link](" Volume size (bytes): ");
[Link](volumesize);
[Link](" Volume size (Kbytes): ");
volumesize /= 1024;
[Link](volumesize);
[Link](" Volume size (Mbytes): ");
volumesize /= 1024;
[Link](volumesize);
R = 0;
return R; }
// Start up the SD card file system
int SSDStartSSDFunction() {
int R = 1;
[Link]();
[Link](" SD card...");
if () {
[Link]("initialization failed!");
return R; }
[Link]("initialization done.");
R = 0;
return R; }
// List the SC card directory
int SSDListDirFunction() {
int R = 0;
[Link]("Files found on the card (name, date and size in bytes): ");
[Link](volume);
//list all files in the card with date and size
[Link](LS_R | LS_DATE | LS_SIZE);
[Link]("");
return R; }
//Write to the SD card File System
int SSDWriteFunction() {
int R = 1;
if () {
//if file does not exist create it
[Link]("\nData File Created - " + WriteFileName);
} else {
[Link]("\nData Append to - " + WriteFileName);
}
myFile = [Link](WriteFileName, FILE_WRITE);
if () {
[Link]("Not able to Create File");
return R; }
// if the file is available, write to it:
if ([Link]()) {
[Link](WriteDataRecord);
// Close the file after writing
[Link](); }
[Link]("Data Written to File - ");
[Link](WriteDataRecord);
R = 0;
return R; }
// Read from the SD card
int SSDReadFunction() {
int R = 1;
ReadDataRecord = "";
if () {
[Link]("File Not Available");
return R; }
myFile = [Link](ReadFileName);
[Link]("Data Read from File - ");
[Link](ReadFileName);
while ([Link]()) {
ReadDataRecord += char([Link]()); }
[Link](ReadDataRecord);
[Link]();
R = 0;
return R; }
//Remove a File from the SD card File System
int SSDRemoveFunction(){
int R = 1;
if () {
[Link]("No File to Remove");
return R; }
[Link](RemoveFileName);
[Link]("Removed - " + RemoveFileName);
R = 0;
return R; }