Adding the library
#include <SD.h>
Causes the serial output to stop (but gets partial output and then stops)
-The arduino compiler doe not note that is out of memory
-using a different serial output monitor results in the same issue
- The code gets to
i have tried these programs separately , both working correctly . i have tried both the SD.h and Sdfat.h libraries with no avail .
/*
* SD card to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
//
//*/
#include <MemoryFree.h>
#define BUTTON_PIN 2
//
//#include "SdFat.h"
#include <SPI.h>
//#include <SD.h>
//SdFat SD;
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Adafruit_SSD1306 display(OLED_RESET);
//
const int chipSelect = 10;
int sonicdata[3];
int sonicAdd;
int sonicFinal;
long S =0;
long A =0;
long J =0;
long duration, inches, cm;
String currentUser = "S"; //sets the current user to s (When started)
int changeUser = 0; //what user is currently active in number form
int cmint =0; // centimetres in int
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
//for the ultrasonic
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
int ThermistorPin = A0;
int Vo;
float R1 = 10000; // value of R1 on board
float logR2, R2, T;
float c1 = 0.001129148, c2 = 0.000234125, c3 = 0.0000000876741; //steinhart-hart coeficients for thermistor
void setup()
{
Serial.begin(9600);
// Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop() {
//
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
changeUser++;
if (changeUser==3)
{
changeUser=0;
}
} else {
// do nothing
}
Serial.print("freeMemory()=");
Serial.println(freeMemory());
Serial.print("button unknown");
Serial.print('\n');
Serial.print("freeMemory()=");
Serial.println(freeMemory());
Serial.println("here1 ");
Serial.print('\n');
Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" C");
delay(500);
Serial.print("freeMemory()=");
Serial.println(freeMemory());
// end of temp
// ultra sonic Code to ping and output the current length to the serial.
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(currentUser);
Serial.print("cm");
Serial.print("freeMemory()=");
Serial.println(freeMemory());
Serial.println();
delay(100);
display.setCursor(0,0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(currentUser);
display.setCursor(0,20);
// display.println("lol");
Serial.print("freeMemory()=");
Serial.println(freeMemory());
display.display();
delay(50);
Serial.print(S);
display.clearDisplay();
delay(100);
for (int i=0; i<3; i++)
{
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
cmint = microsecondsToCentimeters(duration);
sonicdata[i] = cm;
Serial.print("sonic data");
Serial.print(sonicdata[i]);
Serial.print('\n');
delay(200);
}
Serial.print("sonic data total / 3 ");
Serial.print('\n');
sonicAdd = (sonicdata[0]+sonicdata[1]+sonicdata[2]);
sonicFinal = sonicAdd / 3 ;
Serial.print('\n');
Serial.print("Sonic Final");
Serial.print(sonicFinal);
Serial.print('\n');
if (sonicFinal < 30) {
if ( currentUser == "S")
{
S++;
}
if ( currentUser == "J")
{
J++;
}
if ( currentUser == "A")
{
A++;
}
}
}
//ultrasonic functions
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
output from the serial monitor when #include <SD.h> is used
20:25:25.291 -> freeMemory()=752
20:25:25.324 -> button unknown
20:25:25.324 -> freeMemory()=752
20:25:25.358 -> freeMemory()2=752
20:25:25.358 -> here1
20:25:25.391 ->
20:25:25.391 -> Temperature: 0.00 C
20:25:25.830 -> freeMemory()=752
20:25:25.930 -> 0in, ScmfreeMemory()=752
20:25:25.963 ->