I'm trying to finish my a project for school (due at 5pm today)
My adruino UNO keeps rebooting for some unknow reason....
power supply is a lab supply 12v set to 1.1amps (DVRs need ~350mA ea) total running is 500-600mA
Binary sketch size: 15758 bytes (of a 32256 byte maximum)
#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <LiquidCrystal.h>
TinyGPS gps;
NewSoftSerial GPS(9, 8);
NewSoftSerial mDVRRec(12, 13); //serial for unit that records ***correct
NewSoftSerial mDVROverlay(10, 11); //serial for unit that draws data on screen *** correct
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;
int Time_Zone = 7;
int timer;
int i;
void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
int byteGPS=-1;
int k=0;
int Flag =0; //Rec triggering
long Time_Alive =0;
long Time_Check;
int SPEED=0;
int Altitude=0;
int incomingByte=0; //for serial command passing
int serIn;;// for serial command passing
int j =0;
byte index = 0; // Index into array; where to store the character
//=========================================================================================
void setup() {
// put your setup code here, to run once:
Serial.begin(4800); // Serial to PC
GPS.begin(4800);
mDVRRec.begin(115200); // Serial to mDVR that records -rev 0.10
// mDVRRec.begin(57600); // revs 0.20 +
mDVROverlay.begin(57600); // Serial to mDVR Overlay generator
lcd.begin(16, 2);
Serial.println("booting....");
Serial.println("Sofware build date: 12/16/2011");
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
Overlay_boot();
RecBoot();
delay(450); // need to get the mDVRs powered up in time to take commands
OSD_Setup();
Serial.println("Booting Complete...");
digitalWrite(A0, HIGH); // turns off red LED
}
//=========================================================================================
void RecBoot(){
Serial.println("Booting Recording unit");
digitalWrite(A4,HIGH); //boot mdvr
delay(1500);
digitalWrite(A4,LOW); //boot mdvr
}
//=========================================================================================
void Overlay_boot(){
Serial.println("Booting Overlay Generator");
digitalWrite(A5,HIGH); //boot mdvr
delay(1500);
digitalWrite(A5,LOW); //boot mdvr
}
//=========================================================================================
void OSD_Setup(){
int Delay=180; //200 was start, 150 works every time// will effect boot up time
delay(Delay);
Serial.println("OSD start");
mDVROverlay.print(" \r"); // clears any invalid data in the input string
delay(Delay);
mDVROverlay.print(" \r");// clears any invalid data in the input string
delay(Delay);
mDVROverlay.print(" \r");// clears any invalid data in the input string
delay(Delay);
mDVROverlay.print("t4 4 42 00\r"); //
delay (Delay);
mDVROverlay.print("embtxtoffset 0 400 400\r"); // sets overlay top row (x,y) Real Time clock
delay(Delay);
mDVROverlay.print("embtxtoffset 0 400 400\r"); // sets overlay top row (x,y) Real Time clock
delay(Delay);
mDVROverlay.print("osdtxtoffset 1 30 25\r"); // sets overlay top row (x,y) Latitude
delay(Delay);
mDVROverlay.print("osdtxtoffset 2 30 50\r"); // sets overlay bottom row (x,y) longatude
delay(Delay);
mDVROverlay.print("osdtxtoffset 3 30 400\r"); // sets ovelay bottom row (x,y) speed
delay(Delay);
mDVROverlay.print("osdtxtoffset 4 30 75\r"); // sets ovelay bottom row (x,y) Alt
delay(Delay);
mDVROverlay.print("osdtxtenable 0 1\r"); // turns overlay string 0 on
delay(Delay);
mDVROverlay.print("osdtxtenable 1 1\r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtenable 2 1\r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtenable 3 1\r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtenable 4 1\r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtsize 0 20 20 \r"); // turns overlay string 0 on
delay(Delay);
mDVROverlay.print("osdtxtsize 1 20 20 \r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtsize 2 20 20 \r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtsize 3 20 20 \r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtsize 4 20 20 \r"); // turns overlay sting 1 on
delay(Delay);
mDVROverlay.print("osdtxtcolor 0 3\r"); // sets sting 1 to blue
delay (Delay);
mDVROverlay.print("osdtxtcolor 1 3\r"); // set sting 0 on to blue
delay (Delay);
mDVROverlay.print("osdtxtcolor 2 3\r"); // set sting 0 on to blue
delay (Delay);
mDVROverlay.print("osdtxtcolor 3 3\r"); // set sting 0 on to blue
delay (Delay);
mDVROverlay.print("osdtxtcolor 4 3\r"); // set sting 0 on to blue
delay (Delay);
//mDVROverlay.print("vcallback 1\r"); //
delay (Delay);
mDVROverlay.print("embtxtrtcauto 1 \r"); //
delay (Delay);
mDVROverlay.print("t4 4 42 00\r"); //
delay (Delay);
mDVROverlay.print("embtxtenable 0 1\r"); //
delay (Delay);
mDVRRec.print(" \r");
delay(Delay);
mDVRRec.print(" \r");
delay(Delay);
mDVRRec.print("overlay \r");
Serial.println("OSD End");
delay(Delay);
}
//=========================================================================================
void mDVR_Print(long lat, long lon, int Altitude, int SPEED)
{
int Delay=100;
// int k =0;
if (k == 0){
mDVROverlay.print("osdtxtload 1 "); mDVROverlay.print("Latitude: ");mDVROverlay.print(lat);mDVROverlay.print("\r");//load DATA into string
++k;
}
//delay(Delay);
else if(k==1){
mDVROverlay.print("osdtxtload 2 ");mDVROverlay.print("Longatude: ");mDVROverlay.print(lon);mDVROverlay.print("\r");
++k;
}
//delay(Delay);
else if (k==2){
mDVROverlay.print("osdtxtload 3 "); mDVROverlay.print("Speed: "); mDVROverlay.print(SPEED); mDVROverlay.print(" MPH\r");
++k;
}
// delay(Delay);
else if (k==3){
mDVROverlay.print("osdtxtload 4 "); mDVROverlay.print("Altitude: ");mDVROverlay.print(Altitude); mDVROverlay.print("Ft\r");
++k;
}
else
{
k=0;
}
// delay(Delay);
}
//=========================================================================================
void loop() {
if (Serial.available()) { //direct to arduino
incomingByte = Serial.read(); // wait a bit for the entire message to arrive
delay(100); // read all the available characters
if(incomingByte==49){ //1 command
while (Serial.available() > 0) {
serIn = Serial.read(); //read Serial
Serial.print(serIn, BYTE); //eco commands
mDVRRec.print(serIn, BYTE); //pass commands
}
}
if (incomingByte==50){ //2comand
while (Serial.available() > 0) {
serIn = Serial.read(); //read Serial
Serial.print(serIn, BYTE); //eco commands
mDVROverlay.print(serIn, BYTE); //pass commands
}
}
mDVRRec.print("\r");
Serial.println("");
}
// end pass through
digitalWrite(A1, HIGH); // turns orange LED off
//digitalWrite(A0, HIGH); // turns red LED off
byteGPS=GPS.read();
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
}
//ssdigitalWrite(A0, LOW); // turns redLED on
bool newdata = false;
unsigned long start = millis();
// Every 5 seconds we print an update
while (millis() - start < 20)
{
if (feedgps())
newdata = true;
}
if (newdata)
{
Serial.print("Acquired Data \n");
Serial.println("-------------");
gpsdump(gps);
digitalWrite(A1, LOW); // turns orangeLED on
mDVR_Print(lat, lon, Altitude, SPEED);
Serial.println("-------------");
Serial.println();
}
Altitude=(gps.altitude()*0.03281);
//SPEED=gps.f_speed_mph();
SPEED = gps.speed()*1.1507;
//---------function ---------------------------------
//=====================================================================
//===== Trigger section ===============================================