Stream Guaging Sensor/datalogging project

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BFORSYTHE
 
Posts: 14
Joined: Tue Aug 11, 2015 9:16 am

Stream Guaging Sensor/datalogging project

Post by BFORSYTHE »

I will be leading a university class and looking for a good idea on what is compatible and suitable for a university. The goal is to have students work on a data logging system that will be placed in remote areas (no cell signal, etc...) that will be log data to a SD card with accurate time stamps. The primary sensor we are looking to use is a Decagon CTD electrical conductance, tempurature, depth sensor that operates via serial TTL 3.6V or SDI-12.

I have been looking at the Arduino Leonardo and Adafruit Ultimate GPS Logger Shield but not exactly sure of it compatibility with the sensor and what other shields would be needed for the solar panel to power the system in the remote areas.

I appreciate the help and any type of package or other ideas.
BForsythe

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

Re: Stream Guaging Sensor/datalogging project

Post by adafruit_support_bill »

The Leonardo and data logger shield should be able to talk over TTL serial @3.6v.

User avatar
BFORSYTHE
 
Posts: 14
Joined: Tue Aug 11, 2015 9:16 am

Re: Stream Guaging Sensor/datalogging project

Post by BFORSYTHE »

Obviously I am fairly new to these platforms as well so thank you for your prompt response. Would I need to purchase another shield for the power supply(battery and solar power charging system)?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Stream Guaging Sensor/datalogging project

Post by Franklin97355 »

You don't need a shield for power, you could use the solar charger with a battery and solar panel

User avatar
BFORSYTHE
 
Posts: 14
Joined: Tue Aug 11, 2015 9:16 am

Re: Stream Guaging Sensor/datalogging project

Post by BFORSYTHE »

I am having trouble coming with the right code for my little project. I am using a Mega 2650, Adafruit SD Logger Shield, and a waterproof temp sensor(DS18B20). I have attached what I came up with so far using several tutorials but just can't get it. Could someone please help me out some?

Thanks
Attachments
templogger.txt
(6.86 KiB) Downloaded 161 times

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

Re: Stream Guaging Sensor/datalogging project

Post by adafruit_support_bill »

If you can describe the problem in more detail we might be able to help. What works? what doesn't work? What error messages or other problem symptoms are you seeing?

User avatar
BFORSYTHE
 
Posts: 14
Joined: Tue Aug 11, 2015 9:16 am

Re: Stream Guaging Sensor/datalogging project

Post by BFORSYTHE »

I am sure the problem(s) is my lack of knowledge on how to program these(first project). Here is what I copied from the error messages bar:



Arduino: 1.6.5 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Build options changed, rebuilding all

templogger:170: error: 'Wire' does not name a type
templogger.ino: In function 'void setup()':
templogger:172: error: redefinition of 'void setup()'
templogger:47: error: 'void setup()' previously defined here
templogger.ino: In function 'void loop()':
templogger:176: error: redefinition of 'void loop()'
templogger:111: error: 'void loop()' previously defined here
templogger.ino: In function 'float getTemp()':
templogger:191: error: 'ds' was not declared in this scope
templogger:197: error: 'OneWire' has not been declared
templogger:207: error: 'ds' was not declared in this scope
templogger.ino: At global scope:
templogger:233: error: 'tempReading' was not declared in this scope
templogger:233: error: 'aref_voltage' was not declared in this scope
templogger:237: error: 'logfile' does not name a type
templogger:238: error: 'logfile' does not name a type
templogger:239: error: 'logfile' does not name a type
templogger:240: error: 'logfile' does not name a type
templogger:242: error: 'Serial' does not name a type
templogger:243: error: 'Serial' does not name a type
templogger:244: error: 'Serial' does not name a type
templogger:245: error: 'Serial' does not name a type
templogger:249: error: expected constructor, destructor, or type conversion before '(' token
templogger:250: error: expected constructor, destructor, or type conversion before '(' token
templogger:251: error: 'BANDGAPREF' was not declared in this scope
templogger:252: error: 'bandgap_voltage' was not declared in this scope
templogger:254: error: 'logfile' does not name a type
templogger:255: error: 'logfile' does not name a type
templogger:257: error: 'Serial' does not name a type
templogger:258: error: 'Serial' does not name a type
templogger:261: error: 'logfile' does not name a type
templogger:263: error: 'Serial' does not name a type
templogger:266: error: expected constructor, destructor, or type conversion before '(' token
templogger:270: error: expected unqualified-id before 'if'
templogger:271: error: 'syncTime' does not name a type
templogger:274: error: expected constructor, destructor, or type conversion before '(' token
templogger:275: error: 'logfile' does not name a type
templogger:276: error: expected constructor, destructor, or type conversion before '(' token
templogger:278: error: expected declaration before '}' token
'Wire' does not name a type

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

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

Re: Stream Guaging Sensor/datalogging project

Post by adafruit_support_bill »

It looks like you have parts of multiple sketches pasted into the same file. A major problem is that you have 2 setup() functions and 2 loop() functions. Each Arduino sketch needs to have exactly one setup() and exactly one loop().

These tutorials show you how to go about combining code from multiple sketches into one:

https://arduino-info.wikispaces.com/Com ... noSketches
https://en.wikiversity.org/wiki/Arduino_Sketch_Merge

User avatar
BFORSYTHE
 
Posts: 14
Joined: Tue Aug 11, 2015 9:16 am

Re: Stream Guaging Sensor/datalogging project

Post by BFORSYTHE »

That certainly helped get rid of a lot of errors and was compiled successfully now. However, after uploading to the Mega I get no data or messages of any kind in the Serial Monitor or on the SD card.

Can I put all the 'void setup' under one void setup, 'void loop' under one 'void loop' since I have them named separately now(ie...setupTemp, SetupSD, SetupRTC).

Thanks for the tutorials and assistance. I also copied my merged code again.

Code: Select all

#include <OneWire.h> 
#include <Wire.h> 
#include "RTClib.h" // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <SPI.h>
#include <SD.h>

int DS18S20_Pin = 10; //DS18S20 Signal pin on digital 10

//Temperature chip i/o
OneWire ds(10);  // on digital pin 9 - yellow wire

void setup(){
  setupTemp;
  setupRTC;
  setupSD;
  }

void loop() {
 loopTemp();
 loopRTC();
 loopSD();
}

void setupTemp(void) {
  Serial.begin(9600);
}

void loopTemp(void) {
  float temperature = getTemp();
  Serial.println(temperature);
  
  delay(3000); //just here to slow down the output so it is easier to read
  
}

float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -9999;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -9999;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -9999;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad

  
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
  
  ds.reset_search();
  
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  return TemperatureSum;
  
}


RTC_DS1307 rtc;

void setupRTC () {
  Serial.begin(9600);
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  rtc.begin();

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loopRTC () {
    DateTime now = rtc.now();
    
    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.println();
    
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now.unixtime() + 7 * 86400L + 30);
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

//SD card area
 
 const int chipSelect = 10;

File dataFile;

void setupSD()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  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(SS, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(10, 11, 12, 13)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  
  // Open up the file we're going to log to!
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
}

void loopSD()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }

  dataFile.println(dataString);

  // print to the serial port too:
  Serial.println(dataString);
  
  // The following line will 'save' the file to the SD card after every
  // line of data - this will use more power and slow down how much data
  // you can read but it's safer! 
  // If you want to speed up the system, remove the call to flush() and it
  // will save the file only every 512 bytes - every time a sector on the 
  // SD card is filled with data.
  dataFile.flush();
  
  // Take 1 measurement every 500 milliseconds
  delay(500);
}


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

Re: Stream Guaging Sensor/datalogging project

Post by adafruit_support_bill »

Structure-wise, that looks good. Keeping the separate parts in separate functions helps to keep things nice and organized. Now what you need to do is eliminate any redundancies. For example, all 3 of your setup functions call Serial.begin(9600). You should have only one Serial.begin(9600);

Also, all of your loop functions have calls to delay() in them. Since you call each loop in turn, all of those delays add up. If you are just trying to control the volume of serial ouput, you probably want to eliminate all but one delay.

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

Return to “For Educators”