Hi
I am working on a project to and my uno ran out of resources so I moved to a mega 2560.
I did not know the pins and everything is different.
my code was working on the uno but now it is not doing anything that I can tell on the mega.
I downloads but I get no output
I have an " Adafruit Ultimate GPS","Adafruit BMP085", and an SD card to write to.
my code is shown below.
can I get some help?
also, there are all types of tutorials on the uno. can I get a good tutorial on the Arduino mega 2560 so I don't have to bother you when I add my servo and rangefinder
//include for SD card
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
// arduino uno pin 13(SCK),12(MISO),11(MOSI)
//arduno mega pin SPI: 50 (MISO), 51 (MOSI), 52 (SCK),
//include for Adafruit_BMP085
#include <Wire.h>
#include <Adafruit_BMP085.h>//Load BMP085 Library
//#include <Adafruit_GPS.h> //Install the adafruit GPS library
// see parse example for more objects to read
#include <Adafruit_GPS.h> //Load gps Library
#include <SoftwareSerial.h> //Load the Software Serial library
//SoftwareSerial mySerial(3, 2); Uno code
SoftwareSerial mySerial(18,19); //Initialize the Software Serial port using Serial 1: 19 (RX) and 18 (TX);
//Object setup
Adafruit_GPS GPS(&mySerial); //Create the GPS Object
File mySensorData; //Data object you will write your sesnor data to
Adafruit_BMP085 bmp; //Create the Temp/Pres Object
// Variables setup
float tempC; // Variable for holding temp in C
float tempF; // Variable for holding temp in F
float pressure; //Variable for holding pressure reading
float altitude; //Variable for holding altitude
String NMEA1; //Variable for first NMEA sentence
String NMEA2; //Variable for second NMEA sentence
char c; //to read characters coming from the GPS
int chipSelect = 4; //chipSelect pin for the SD card Reader
boolean test = true ; // true or false; used for SD test print
boolean test1 = true ; // true or false; used for NMEA test print
float mpsConvertion = 1.15077945; //used to convert from knots to MPS 1 knot = 1.15077945 mph
float MPS =0.0; //sets mph
void setup() {
if (!bmp.begin()) {//checks for BMP085 is responding
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}else{
Serial.println("valid BMP085 sensor!");
}
Serial.begin(115200); //Turn on serial monitor
GPS.begin(9600); //Turn on GPS at 9600 baud
GPS.sendCommand("$PGCMD,33,0*6D"); //Turn off antenna update nuisance data
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Request RMC and GGA Sentences only
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //Set update rate to 1 hz
delay(1000);
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it to keep SD card happy
SD.begin(chipSelect); //Initialize the SD card reader
if (SD.exists("NMEA.txt")) { //Delete old data files to start fresh
SD.remove("NMEA.txt");
}
if (SD.exists("GPSData.txt")) { //Delete old data files to start fresh
SD.remove("GPSData.txt");
}
}
void loop() {
getTEMP();
readGPS();
if(GPS.fix==1) { //Only save data if we have a fix
mySensorData = SD.open("NMEA.txt", FILE_WRITE); //Open file on SD card for writing
mySensorData.println(NMEA1); //Write first NMEA to SD card
mySensorData.println(NMEA2); //Write Second NMEA to SD card
mySensorData.close(); //Close the file NMEA.txt
mySensorData = SD.open("GPSData.txt", FILE_WRITE);
mySensorData.print(GPS.latitude,4); //Write measured latitude to file
mySensorData.print(GPS.lat); //Which hemisphere N or S
mySensorData.print(",");
mySensorData.print(GPS.longitude,4); //Write measured longitude to file
mySensorData.print(GPS.lon); //Which Hemisphere E or W
mySensorData.print(",");
mySensorData.print(GPS.altitude);
mySensorData.print(",");
mySensorData.print(MPS);
mySensorData.println(",");
mySensorData.print(bmp.readTemperature());
mySensorData.print("C");
mySensorData.print(",");
mySensorData.print(pressure);
mySensorData.println("Pa.");
mySensorData.println("");
mySensorData.close(); //Close the file GPSData.txt
if(test){ //if test is set to true then test code will print to monitor
//Serial.print("Pressure = ");
//Serial.print(bmp.readPressure());
//Serial.print(" Pa");
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println("C");
Serial.print(GPS.latitude,4); //Write measured latitude to file
Serial.print(GPS.lat); //Which hemisphere N or S
Serial.print(",");
Serial.print(GPS.longitude,4); //Write measured longitude to file
Serial.print(GPS.lon); //Which Hemisphere E or W
Serial.print(",");
Serial.print(GPS.altitude);
//Serial.print(",");
//Serial.print(GPS.speed); //displays speed in knots
Serial.print(",");
Serial.print(MPS); //displays speed in Miles per-hour
Serial.print(",");
Serial.print(bmp.readTemperature());
//Serial.print(tempC, 1);
Serial.print("C");
} else{ //if test
Serial.println("Not in test mode. will not display print lines");
}
} //if(GPS.fix==1)
//delay(500);
}
void readGPS() {
clearGPS();
while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
c=GPS.read();
}
GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
NMEA1=GPS.lastNMEA();
while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
c=GPS.read();
}
GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
NMEA2=GPS.lastNMEA();
//Serial.println(NMEA1);
//Serial.println(NMEA2);
//Serial.println("");
}
void clearGPS() { //Clear old and corrupt data from serial port
while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
c=GPS.read();
}
GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
c=GPS.read();
}
GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
while(!GPS.newNMEAreceived()) { //Loop until you have a good NMEA sentence
c=GPS.read();
}
GPS.parse(GPS.lastNMEA()); //Parse that last good NMEA sentence
}
void getTEMP() {// Read Temperature
tempC = bmp.readTemperature(); //read temp in C
tempF = (tempC * 1.8 ) + 32.0; //convert temp in C to f
}