Hello!
I'm attempting to do this project, where I write data measured by an accelerometer & altimeter to a SD card. The output, however, is behaving very weirdly. Instead of writing, it repeats the setup. Nothing is written to the file.
/*############### VIRTUABOTIX BASIC ACCELEROMETER CODE #########################
This code is meant to serve as the most basic example of how to read out
from the X Y and Z axis as raw sensor readings.
######################################################
TO PIN A0 # # To 5 Volts
###### ######
# # X Axis 5 Volt # #
###### ######
TO PIN A1 # #
###### ######
# # Y Axis 3.3 Volt # #
###### ######
TO PIN A2 # # To Ground
###### ######
# # Z Axis Ground # #
###### ######
TO PIN 2
# #
###### ######
# # Sleep GS (Sensitivity Select) # #
###### ######
# #
###### ######
# # 0G ST (Self Test) # #
###### ######
# #
######################################################
* Find more free code, and great products at http://www.virtuabotix.com/
* ------------------------------------------------------------------------------
* $Author: Mr. Joe $
* $Date: 2011-11-5 $
* $Revision: 0 $
* ------------------------------------------------------------------------------
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
################################################################################*/
int sleepPin= 2; //Turning sleep high turns on the Accelerometer
int xpin= A0;
int ypin = A1;
int zpin = A2;
int gpin = A3;
#include <Wire.h>
#include "IntersemaBaro.h"
#include <SD.h>
Intersema::BaroPressure_MS5607B baro(true);
void setup() {
Serial.begin(9600);
baro.init();
pinMode(sleepPin, OUTPUT);
digitalWrite(sleepPin, HIGH);
delay(500);
pinMode(xpin, INPUT);
digitalWrite(xpin, HIGH);
delay(500);
pinMode(ypin, INPUT);
digitalWrite(ypin, HIGH);
delay(500);
pinMode(zpin, INPUT);
digitalWrite(zpin, HIGH);
delay(500);
pinMode(gpin, INPUT);
digitalWrite(gpin, HIGH);
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
return;
}
Serial.println("Complete!");
delay(2000);
}
void loop() {
Serial.println("Attempting to open file.");
File myFile = SD.open("datalogger.txt", FILE_WRITE);
Serial.println("File has opened");
int alt = baro.getHeightCentiMeters();
if (myFile) {
Serial.println("Writing to file");
myFile.print("Time: ");
myFile.print(millis()/1000);
delay(500);
myFile.print(", Centimeters: ");
myFile.print((float)(alt));
delay(500);
myFile.print(", Feet: ");
myFile.println((float)(alt) / 30.48);
delay(500);
myFile.print("X Reading: ");
myFile.println(analogRead(xpin), DEC);
delay(500);
myFile.print("Y Reading: ");
myFile.println(analogRead(ypin), DEC);
myFile.print("Z Reading: ");
delay(500);
myFile.println(analogRead(zpin), DEC);
myFile.print("0G Reading: ");
myFile.println(analogRead(gpin), DEC);
delay(500);
myFile.println("----------------------------");
myFile.close();
Serial.println("File has been closed");
}
delay(5000);
}
Here is my output,
Complete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
A´Complete!
A´Complete!
AtComplete!
AtComplete!
AtComplete!
A´Complete!
AtComplete!
A´Complete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
AtComplete!
A´Complete!
I'm completely unsure what I'm doing wrong. Any help would be greatly appreciated.
Thank you!