Datalogging Shield Not Logging

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
narcoleptic_noah
 
Posts: 4
Joined: Mon Mar 17, 2014 11:41 pm

Datalogging Shield Not Logging

Post by narcoleptic_noah »

Adafruit,
I'm working on a project building an arduino-controlled chemical reactor. I've bought an UNO r3 and quite a few shields and they've all worked wonderfully, with the exception of the SD shield. I'm looking to log values from two analog temperature sensors (similar to the tmp36) to the SD card. After figuring out the offset formula, I was able to successfully get the temperatures to display correctly. I then tried to implement the light/temp logger sketch from github, it uploads fine using the 1.0.5 IDE except for a few cryptic hiccups in the verbose output.
The SD card and serial monitor are both reporting static values, even if I'm holding the temp sensor in my hand or trying to change the temp. I know that my sensors work fine as I'm able to display the values on an LCD and monitor the output with a multimeter. I attempted to use the shield without the LCD and I'm still not having any luck. I've even used the stock sketch to just report the raw values from the ADC, and I seem to be getting 1023 regardless. What should I try next? Any guidance or help is appreciated, and I would happily share any relevant details.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogging Shield Not Logging

Post by adafruit_support_bill »

So you are writing values to files, but the values are not what you expect? It sounds like the shield is working fine. The problem is in the software. Are you sure you are using the same sensor connections as in the example sketch?

If you can post a diagram of what sensors you have connected and your source code, we can take a look.

narcoleptic_noah
 
Posts: 4
Joined: Mon Mar 17, 2014 11:41 pm

Re: Datalogging Shield Not Logging

Post by narcoleptic_noah »

Here's what I'm working with:
https://www.dropbox.com/s/45c1sergzy8du ... .53.32.jpg
The sensors are AD22100s, which use +5 as the supply voltage. Unfortunately I didn't know how noisy the 5 volt line is until after receiving them. Oh well. The formula for the Vout is Vout=(V+/5V)*(1.375V + 0.0225 V/degree C * Temp), which I've solved for the Temp value in the code.

And here's the code:

Code: Select all

#include <SD.h>
#include <Wire.h>
#include <SPI.h>
#include "RTClib.h"

// A simple data logger for the Arduino analog pins

// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL  1000 // mills between entries (reduce to take more/faster data)

// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to 
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3

// The analog pins that connect to the sensors
#define tempPin1 0           // analog 0
#define tempPin2 1                // analog 1
#define BANDGAPREF 14            // special indicator that we want to measure the bandgap

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
#define bandgap_voltage 1.1      // this is not super guaranteed but its not -too- off

RTC_DS1307 RTC; // define the Real Time Clock object

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
  
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
  
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  

  logfile.println("millis,stamp,datetime,T1,T2,vcc");    
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,T1,T2,vcc");
#endif //ECHO_TO_SERIAL
 
  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}

void loop(void)
{
  DateTime now;

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  digitalWrite(greenLEDpin, HIGH);
  
  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif

  // fetch the time
  now = RTC.now();
  // log time
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL

   //temp sensor readings
  analogRead(tempPin1);
  delay(10); 
  int rawvalue1 = analogRead(tempPin1); 
  
  analogRead(tempPin2); 
  delay(10);
  int rawvalue2 = analogRead(tempPin2); 
  
  //convert raw values to temperatures 
  float voltage1 = rawvalue1 * 5.0 / 1024;
  float T1 = (voltage1 - 1.375) * 0.0225;     //22.5mV/*C
  
  //temp sensor 2 calculation 
  float voltage2 = rawvalue2 * 5.0 / 1024;
  float T2 = (voltage2 - 1.375) * 0.0225;
  
  logfile.print(", ");    
  logfile.print(T1);
  logfile.print(", ");    
  logfile.print(T2);
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(T1);
  Serial.print(", ");    
  Serial.print(T2);
#endif //ECHO_TO_SERIAL

  // Log the estimated 'VCC' voltage by measuring the internal 1.1v ref
  analogRead(BANDGAPREF); 
  delay(10);
  int refReading = analogRead(BANDGAPREF); 
  float supplyvoltage = (bandgap_voltage * 1024) / refReading; 
  
  logfile.print(", ");
  logfile.print(supplyvoltage);
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(supplyvoltage);
#endif // ECHO_TO_SERIAL

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  digitalWrite(greenLEDpin, LOW);

  // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(redLEDpin, HIGH);
  logfile.flush();
  digitalWrite(redLEDpin, LOW);
  
}


Oddly enough, I'm logging a constant value of 0.08 now to the card for T1 and T2.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogging Shield Not Logging

Post by adafruit_support_bill »

Your photo doesn't show any of the connections to the sensors.

narcoleptic_noah
 
Posts: 4
Joined: Mon Mar 17, 2014 11:41 pm

Re: Datalogging Shield Not Logging

Post by narcoleptic_noah »

Sorry about that, here's what the connections look like: https://www.dropbox.com/s/vb56kg46k3h55 ... ensors.jpg

I'm fairly confident that the issue isn't in the wiring, it's the code. I've more or less copied the syntax of the example light/temp logger, but it still isn't working as expected. Any ideas?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogging Shield Not Logging

Post by adafruit_support_bill »

You declare the analog reference as EXTERNAL, but I don't see any connection to the AREF pin.

narcoleptic_noah
 
Posts: 4
Joined: Mon Mar 17, 2014 11:41 pm

Re: Datalogging Shield Not Logging

Post by narcoleptic_noah »

D'oh. I commented it out but it didn't seem to change anything. Here's what I get when compiling:

Code: Select all

templogger_3_21_14.ino: In function 'void setup()':
templogger_3_21_14.ino:74: warning: deprecated conversion from string constant to 'char*'
templogger_3_21_14.ino:91: warning: deprecated conversion from string constant to 'char*'
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::readData(uint32_t, uint16_t, uint16_t, uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:438: warning: unused variable 'n'
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:571: warning: 'v' may be used uninitialized in this function
C:\Program Files (x86)\Arduino\libraries\SD\utility\SdFile.cpp: In static member function 'static uint8_t SdFile::make83Name(const char*, uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\SdFile.cpp:263: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\RTClib\RTClib.cpp:29: warning: only initialized variables can be placed into program memory area
C:\Program Files (x86)\Arduino\libraries\RTClib\RTClib.cpp: In constructor 'DateTime::DateTime(uint32_t)':
C:\Program Files (x86)\Arduino\libraries\RTClib\RTClib.cpp:63: warning: comparison between signed and unsigned integer expressions
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void store_char(unsigned char, ring_buffer*)':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:98: warning: comparison between signed and unsigned integer expressions
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void __vector_18()':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:127: warning: unused variable 'c'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'void HardwareSerial::begin(long unsigned int, byte)':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:368: warning: unused variable 'current_config'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'virtual size_t HardwareSerial::write(uint8_t)':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:467: warning: comparison between signed and unsigned integer expressions
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Print.cpp: In member function 'size_t Print::print(const __FlashStringHelper*)':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Print.cpp:44: warning: '__progmem__' attribute ignored
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Tone.cpp:119: warning: only initialized variables can be placed into program memory area

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Datalogging Shield Not Logging

Post by adafruit_support_bill »

Using a multimeter, what voltage do you measure at the analog pins?

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”