Low memory available
i'm getting warning, low memory available, stability problems may occur. have hc-sr04 sensor, adafruit ultimate gps module, , sd card reader on uno. should switch mega? i'll post code. thanks!
code: [select]
#include <newping.h>
#include <adafruit_gps.h>
#include <softwareserial.h>
#include <sd.h>
#include <spi.h>
softwareserial myserial(3,2);
adafruit_gps gps(&myserial);
char c;
string nmea1;
string nmea2;
#define trigger_pin 6
#define echo_pin 7
#define max_distance 200
#define pingspeed 1000
#define chipselect 4
unsigned long pingtimer1, pingtimer2, pingtimer3;
newping sonar(6,7,65);
file myfile;
void setup() {
serial.begin(115200);
pingtimer1 = millis() + pingspeed;
pingtimer2 = pingtimer1 + (pingspeed/2);
pingtimer3= pingtimer2 + pingspeed;
gps.begin(9600);
gps.sendcommand("$pgcmd,33,0*6d");
gps.sendcommand(pmtk_set_nmea_update_1hz);
gps.sendcommand(pmtk_set_nmea_output_rmcgga);
if(!sd.begin(4)) {
serial.println("not beginning");
return;
}
serial.println("its working");
pinmode(10,output);
sd.remove("ultrad.txt");
if(!sd.remove("ultrad.txt")){
serial.println("ultra not working");
return;
}
sd.remove("gps.txt");
if(!sd.remove("gps.txt")){
serial.println("gps not working");
return;
}
}
void loop() {
if(millis()>= pingtimer1) {
pingtimer1 += pingspeed;
ping();
}
if (millis() >= pingtimer2) {
pingtimer2 = pingtimer1 + (pingspeed/2);
gpsdata();
}
if (millis() >= pingtimer3) {
pingtimer3 = pingtimer2 + pingspeed;
sdcard();
}
}
void ping(){
delay(50);
int us=sonar.ping();
serial.print("ping: ");
serial.print(us/us_roundtrip_cm);
serial.println("cm");
}
void gpsdata() {
cleargps();
while(!gps.newnmeareceived()) { //loop until have nmea sentence
c=gps.read();
}
gps.parse(gps.lastnmea()); //parse last nmea sentence
nmea1=gps.lastnmea();
while(!gps.newnmeareceived()) { //loop until have nmea sentence
c=gps.read();
}
gps.parse(gps.lastnmea()); //parse last nmea sentence
nmea2=gps.lastnmea();
serial.print(gps.latitude);
serial.print(",");
serial.println(gps.longitude);
serial.print(gps.hour, dec);serial.print(':');
serial.println(gps.minute, dec);
}
void cleargps() {
while(!gps.newnmeareceived()) { //loop until have nmea sentence
c=gps.read();
}
gps.parse(gps.lastnmea()); //parse last nmea sentence
while(!gps.newnmeareceived()) { //loop until have nmea sentence
c=gps.read();
}
gps.parse(gps.lastnmea()); //parse last nmea sentence
while(!gps.newnmeareceived()) { //loop until have nmea sentence
c=gps.read();
}
}
void sdcard(){
int us=sonar.ping();
myfile = sd.open("ultrad.txt", file_write);
myfile.print(us/us_roundtrip_cm);
myfile.print(",");
myfile.println("cm");
myfile.println(millis());
myfile.close();
myfile = sd.open("gps.txt", file_write);
myfile.print(gps.latitude);
myfile.print(",");
myfile.print(gps.longitude);
myfile.print(",");
myfile.print(gps.hour, dec);myfile.print(':');
myfile.println(gps.minute, dec);
myfile.close();
}
or '1284p 16k sram.
two hardware serial ports software serial not needed. offer boards in several form factors.
http://www.crossroadsfencing.com/bobuinorev17/
this one's little more decked out - onboard or offboard usb/serial adapter, sd card, battery backed rtc, rs232 buffer available 2nd serial port. lots of signal, power, gnd connections available , prototyping area too.
two hardware serial ports software serial not needed. offer boards in several form factors.
http://www.crossroadsfencing.com/bobuinorev17/
this one's little more decked out - onboard or offboard usb/serial adapter, sd card, battery backed rtc, rs232 buffer available 2nd serial port. lots of signal, power, gnd connections available , prototyping area too.
Arduino Forum > Using Arduino > Programming Questions > Low memory available
arduino
Comments
Post a Comment