Hi, everyone.
I could really need your help.
There's an error when I want to verify my code.
Which is [processing.app.debug.RunnerException: Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint]
Could someone help me to solve this matter?
Most of the codes are useful to me. If I delete one line of the code, especially the library and #define, many errors will come out.
Here is my code.
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
#include <TimeAlarms.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define THERMISTORPIN A0
#define NUMSAMPLES 5
#define SERIESRESISTOR 30000
#define A 0.0008447572316
#define B 0.0002195170370
#define C 0.0000001061307230
AlarmId id;
const int buzzer = 12;
int pinCS = 4;
int samples[NUMSAMPLES];
File dataFile;
void setRtc()
{
if (timeStatus() != timeSet)
{
Serial.println("Unable to sync with the RTC");
}
else
{
Serial.println("RTC has set the system time");
}
// create the alarms, to trigger at specific times
Serial.println("RTC create the alarms, to trigger at specific times");
Alarm.alarmRepeat(10, 33, 0, MorningAlarm); // 8:30am every day
// create timers, to trigger relative to when they're created
Serial.println("RTC create timers, to trigger relative to when they're created");
Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
id = Alarm.timerRepeat(2, Repeats2); // timer for every 2 seconds
Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds
}
void setOled()
{
// by default, generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("TempIoT1.0");
display.display();
delay(2000);
display.clearDisplay();
pinMode(pinCS, OUTPUT);
delay(2000);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
// Create/Open file
dataFile = SD.open("test.txt", FILE_WRITE);
if (dataFile)
{
Serial.println("Done.");
}
// if the file didn't open, print an error:
else
{
Serial.println("error opening test.txt");
}
}
void setup()
{
Serial.begin(9600);;
analogReference(EXTERNAL);
setSyncProvider(RTC.get); // the function to get the time from the RTC
while (!Serial); //wait for serial
pinMode(buzzer, OUTPUT);
setRtc();
setOled();
delay(2000);
processD();
}
void loop() {}
void processD()
{
int i;
//int data;
double average;
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
// take N samples in a row, with a slight delay
for (i = 0; i < NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
delay(50); //50 5 bacaan
}
// average all the samples out
average = 0;
for (i = 0; i < NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
double steinhart1, steinhart2, steinhart3, steinhart4, steinhart5;
Serial.println("start");
steinhart1 = log(average); // (ln R)
steinhart2 = C * steinhart1 * steinhart1 * steinhart1; // C * (ln R)***
steinhart3 = (B * steinhart1) + steinhart2; // B*(ln R) + C * (ln R)***
steinhart4 = 1.0 / (A + steinhart3); // 1/(A + B*(ln R) + C * (ln R)***)
steinhart5 = steinhart4 - 273.15; // convert to C
Serial.print("Temperature ");
display.print("Body Temp = ");
Serial.print(steinhart5);
display.print(steinhart5);
Serial.println(" *C");
display.println(" *C");
display.display();
dataFile.println(steinhart5);
dataFile.close();
// Reading the file
dataFile = SD.open("test.txt");
if (dataFile) {
Serial.println("Read:");
// Reading the whole file
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
}
else {
Serial.println("error opening test.txt");
}
delay(5000);
//display.clearDisplay();
}
//~~~~~~~~~~~~~~~~~~~~~~~~ TIME SETTING ~~~~~~~~~~~~~~~~~~~~~~~~~~
void MorningAlarm() {
Serial.println("Alarm: - turn lights off");
buzz();
}
void ExplicitAlarm() {
Serial.println("Alarm: - this triggers only at the given date and time");
}
void Repeats() {
Serial.println("15 second timer");
}
void Repeats2() {
Serial.println("2 second timer");
}
void OnceOnly() {
Serial.println("This timer only triggers once, stop the 2 second timer");
// use Alarm.free() to disable a timer and recycle its memory.
Alarm.free(id);
// optional, but safest to "forget" the ID after memory recycled
id = dtINVALID_ALARM_ID;
// you can also use Alarm.disable() to turn the timer off, but keep
// it in memory, to turn back on later with Alarm.enable().
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(' ');
Serial.print(day());
Serial.print(' ');
Serial.print(month());
Serial.print(' ');
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(':');
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}
void buzz() {
tone(buzzer, 2000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(500); // ...for 1sec
tone(buzzer, 2000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(500); // ...for 1sec
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(500); // ...for 1sec
}
Please, everyone. I appreciate all your kindness.
Thanks.