Datalogger Bandgap

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Datalogger Bandgap

Postby NitroxDM » Sun Jun 24, 2012 12:53 pm

I'm using this data logger https://www.adafruit.com/products/243 to record three temperatures.

How is the bandgap, in relation to the temp sensor, being measured?
How can I read it for all three sensors?


Relevant bits of code:
Code: Select all
// The analog pins that connect to the sensors
#define tempPinRef 0              // analog 0
#define tempPin1 1                 // analog 1
#define tempPin2 2                 // analog 2
#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
 
float ReadBandGap(){
  // Log the estimated 'VCC' voltage by measuring the internal 1.1v ref
  analogRead(BANDGAPREF);
  delay(10);
  int refReading = analogRead(BANDGAPREF);
  return supplyvoltage = (bandgap_voltage * 1024) / refReading;
  }


Thanks for looking.
-- NitroxDM
NitroxDM
 
Posts: 5
Joined: Thu May 03, 2012 10:21 pm

Re: Datalogger Bandgap

Postby adafruit_support_rick » Sun Jun 24, 2012 4:26 pm

I'm not sure i understand your question.
The voltage reference is the same for all analog inputs.
The ADC on the chip uses the voltage reference as the comparison standard for any analog input.
User avatar
adafruit_support_rick
 
Posts: 3152
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Datalogger Bandgap

Postby john444 » Sun Jun 24, 2012 6:00 pm

Hi NitroxDM,

The 'band-gap' referred to in the code is the Arduino's internal voltage reference.
This 1.1-V voltage reference uses the 'band-gap' technique to produce a stable voltage.

I think the code means that you may use the internal voltage reference or instead
you may connect the Arduino's 3.3-V external voltage to Aref for the A/D to use.

You may have different reasons for using different references.
I have found the 1.1-V internal reference to be somewhat noisy. (makes stable inputs seem to jump around)
The 3.3-V is handy and double regulated so fairly quiet when there is nothing else on it.
The 5-V supply is the noisiest with all the digital circuitry connected to it.

John
john444
 
Posts: 418
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Datalogger Bandgap

Postby adafruit_support_rick » Sun Jun 24, 2012 7:25 pm

You might find the discussion of the Arduino analogReference() function useful.

The adafruit tutorial recommends tying 3.3V to AREF because it is a more stable reference on 5V Arduino boards.

What are you trying to do with the code you posted?
User avatar
adafruit_support_rick
 
Posts: 3152
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Datalogger Bandgap

Postby NitroxDM » Thu Jun 28, 2012 9:14 pm

I tied the 3.3V to AREF. The way I understand it I'm measuring bandgap of the temp sensor.

Here is what I don't get.

Right now the output of ReadBandGap only changes with the value of the analog 0 pin.
The sensors on analog 1,2 don't have any effect. I just don't see the connection between the ReadBandGap() method and analog pin 0.
NitroxDM
 
Posts: 5
Joined: Thu May 03, 2012 10:21 pm

Re: Datalogger Bandgap

Postby adafruit_support_bill » Fri Jun 29, 2012 5:04 am

The way I understand it I'm measuring bandgap of the temp sensor.

No. What you are reading is the internal bandgap reference voltage. It has nothing at all to do with your sensor. With a 3.3v AREF, you should be getting a refReading of around 340. The return value from ReadBandGap should be pretty close to 3.3.

How much does the bandgap reading vary with changes in A0?
User avatar
adafruit_support_bill
 
Posts: 16638
Joined: Sat Feb 07, 2009 9:11 am

Re: Datalogger Bandgap

Postby NitroxDM » Fri Jun 29, 2012 4:13 pm

Here a some results... I'll post some more extreme examples when I have a better source of heat.

Code: Select all
datetime,tempRef,temp2,vcc
2012/6/28 19:59:41", 76.58, 71.94, 4.86
2012/6/28 19:59:51", 76.58, 82.96, 4.86
2012/6/28 20:00:01", 76.58, 86.44, 4.86
2012/6/28 20:00:11", 78.32, 82.38, 4.79
2012/6/28 20:00:21", 78.90, 77.16, 4.77
2012/6/28 20:00:31", 81.22, 74.84, 4.67
2012/6/28 20:00:31", 81.80, 74.84, 4.67
2012/6/28 20:00:41", 84.12, 73.68, 4.60
2012/6/28 20:00:51", 85.86, 73.68, 4.54
2012/6/28 20:01:01", 84.70, 73.68, 4.58
2012/6/28 20:01:11", 81.22, 74.26, 4.69
2012/6/28 20:01:21", 80.06, 75.42, 4.73
2012/6/28 20:01:31", 78.90, 74.84, 4.77
2012/6/28 20:01:41", 77.74, 74.84, 4.81
2012/6/28 20:01:51", 78.32, 76.00, 4.79
NitroxDM
 
Posts: 5
Joined: Thu May 03, 2012 10:21 pm

Re: Datalogger Bandgap

Postby NitroxDM » Fri Jun 29, 2012 11:29 pm

More data:

Code: Select all
datetime,tempRef,temp1,vcc
"2012/6/29 22:20:25", 81.22, 79.48, 4.69
"2012/6/29 22:20:31", 81.22, 79.48, 4.69
"2012/6/29 22:20:37", 81.22, 79.48, 4.69
"2012/6/29 22:20:43", 81.80, 100.36, 4.67
"2012/6/29 22:20:49", 82.38, 115.44, 4.64
"2012/6/29 22:20:55", 84.70, 112.54, 4.58
"2012/6/29 22:21:01", 84.12, 102.68, 4.60
"2012/6/29 22:21:07", 80.64, 80.06, 4.71
"2012/6/29 22:21:13", 80.64, 77.74, 4.71
"2012/6/29 22:21:19", 84.70, 78.32, 4.58
"2012/6/29 22:21:25", 100.94, 78.90, 4.11
"2012/6/29 22:21:31", 119.50, 81.22, 3.67
"2012/6/29 22:21:37", 131.11, 83.54, 3.46
"2012/6/29 22:21:43", 125.88, 84.12, 3.55
"2012/6/29 22:21:49", 114.28, 78.90, 3.79
"2012/6/29 22:21:55", 107.32, 77.74, 3.95
"2012/6/29 22:22:01", 100.94, 77.16, 4.11
"2012/6/29 22:22:07", 94.56, 77.16, 4.28
"2012/6/29 22:22:13", 84.70, 77.74, 4.58
"2012/6/29 22:22:19", 76.58, 78.90, 4.86
"2012/6/29 22:22:25", 72.52, 79.48, 5.01
"2012/6/29 22:22:31", 69.62, 79.48, 5.12
"2012/6/29 22:22:37", 67.88, 79.48, 5.19
"2012/6/29 22:22:43", 66.72, 78.90, 5.24
"2012/6/29 22:22:49", 65.56, 77.74, 5.29
"2012/6/29 22:22:55", 66.72, 77.16, 5.24
"2012/6/29 22:23:01", 70.78, 76.58, 5.07
"2012/6/29 22:23:07", 71.36, 76.00, 5.05
"2012/6/29 22:23:13", 73.10, 75.42, 4.98
"2012/6/29 22:23:19", 74.26, 75.42, 4.94
"2012/6/29 22:23:25", 73.68, 69.04, 4.96
"2012/6/29 22:23:31", 73.68, 63.82, 4.96
"2012/6/29 22:23:37", 74.26, 61.50, 4.94
"2012/6/29 22:23:43", 74.26, 61.50, 4.94
"2012/6/29 22:23:49", 74.84, 61.50, 4.92
"2012/6/29 22:23:55", 75.42, 66.14, 4.92
"2012/6/29 22:24:01", 75.42, 70.78, 4.90
"2012/6/29 22:24:07", 76.00, 73.68, 4.88
NitroxDM
 
Posts: 5
Joined: Thu May 03, 2012 10:21 pm

Re: Datalogger Bandgap

Postby adafruit_support_bill » Sat Jun 30, 2012 4:48 am

Can you post the code that generated that? I don't know what all the columns represent.
User avatar
adafruit_support_bill
 
Posts: 16638
Joined: Sat Feb 07, 2009 9:11 am

Re: Datalogger Bandgap

Postby NitroxDM » Sat Jun 30, 2012 6:50 pm

I've done some refactoring.

Code: Select all

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

//#define LOG_INTERVAL  600000
#define LOG_INTERVAL    600
#define ECHO_TO_SERIAL   1 // echo data to serial port

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

// The analog pins that connect to the sensors
#define tempPinRef 0             // analog 0
#define tempPin1 1               // analog 1
#define tempPin2 2               // analog 2
#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;

// 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)
{
#if ECHO_TO_SERIAL
   Serial.print("error: ");
   Serial.println(str);
#endif
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);
  while(1);
}

void setup(void)
{
#if ECHO_TO_SERIAL
  Serial.begin(9600);
  Serial.println();
  Serial.print("Initializing SD card...");
#endif
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
  pinMode(10, OUTPUT); // make sure that the default chip select pin is set to output, even if you don't use it:
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
#if ECHO_TO_SERIAL
  Serial.println("card initialized.");
  Serial.println("datetime,tempRef,temp1,temp2,vcc");
#endif

  // 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");
  }
#if ECHO_TO_SERIAL
  Serial.print("Logging to: ");
  Serial.println(filename);
#endif
  // 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("datetime,tempRef,temp1,temp2,vcc");   
  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}

void loop(void){
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  digitalWrite(greenLEDpin, HIGH);
  float temperatureRef = getTempFromVoltage(readPin(tempPinRef));
  float temperature1= getTempFromVoltage(readPin(tempPin1));
  float temperature2= getTempFromVoltage(readPin(tempPin2));
  int refReading = readPin(BANDGAPREF);   
  digitalWrite(greenLEDpin, LOW);
  logAndPrint(temperatureRef, temperature1, temperature2, (bandgap_voltage * 1024) / refReading);
  doneCheck(temperature1,temperature2);
}

void doneCheck(float temp1, float temp2){
  if(temp1>90 && temp2>90)
  {
    while(1)
    {
      digitalWrite(redLEDpin, 1);
      digitalWrite(greenLEDpin, 0);
      delay(400);
      digitalWrite(redLEDpin, 0);
      digitalWrite(greenLEDpin, 1);
      delay(400);
    }
  }
}

float getTempFromVoltage(int voltage){
  // converting that reading to voltage, for 3.3v arduino use 3.3, for 5.0, use 5.0
  return  ((((voltage * aref_voltage / 1024) - 0.5) * 100) * 9 / 5) + 32;
}
 
int readPin(int pin){
  analogRead(pin);
  delay(10);
  return analogRead(pin);
}

void logAndPrint(float tempRef,float temp1, float temp2, float supplyvoltage){
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(redLEDpin, HIGH);
  DateTime t = RTC.now();
  logfile.print(t.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(t.year(), DEC);
  logfile.print("/");
  logfile.print(t.month(), DEC);
  logfile.print("/");
  logfile.print(t.day(), DEC);
  logfile.print(" ");
  logfile.print(t.hour(), DEC);
  logfile.print(":");
  logfile.print(t.minute(), DEC);
  logfile.print(":");
  logfile.print(t.second(), DEC);
  logfile.print('"');
  logfile.print(", ");   
  logfile.print(tempRef);
  logfile.print(", ");   
  logfile.print(temp1);
  logfile.print(", ");   
  logfile.print(temp2);
  logfile.print(", ");
  logfile.print(supplyvoltage);
  logfile.println();
  logfile.flush();
  digitalWrite(redLEDpin, LOW);
#if ECHO_TO_SERIAL
  Serial.print(t.year(), DEC);
  Serial.print("/");
  Serial.print(t.month(), DEC);
  Serial.print("/");
  Serial.print(t.day(), DEC);
  Serial.print(" ");
  Serial.print(t.hour(), DEC);
  Serial.print(":");
  Serial.print(t.minute(), DEC);
  Serial.print(":");
  Serial.print(t.second(), DEC);
  Serial.print('"');
  Serial.print(", ");   
  Serial.print(tempRef);
  Serial.print(", ");   
  Serial.print(temp1);
  Serial.print(", ");   
  Serial.print(temp2);
  Serial.print(", ");   
  Serial.print(supplyvoltage);
  Serial.println();
#endif // ECHO_TO_SERIAL
}

NitroxDM
 
Posts: 5
Joined: Thu May 03, 2012 10:21 pm

Re: Datalogger Bandgap

Postby adafruit_support_bill » Sun Jul 01, 2012 5:10 am

Yes. The band-gap reference does move around a bit. We are not sure why, but we find the 3.3v reference to be more stabe, so that is what we recommend.
http://forums.adafruit.com/viewtopic.php?f=25&t=11597&p=83455&hilit=bandgap#p83455
User avatar
adafruit_support_bill
 
Posts: 16638
Joined: Sat Feb 07, 2009 9:11 am


Return to Other Arduino products from Adafruit

Who is online

Users browsing this forum: No registered users and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]