Home › Forums › Mayfly Data Logger › Mayfly Stops Logging and Other Issues
- This topic has 6 replies, 4 voices, and was last updated 2019-09-22 at 6:47 PM by Drew.
-
AuthorPosts
-
-
2019-09-15 at 10:38 AM #13138
Hello,
I had deployed several Mayfly loggers last week to collect data from a turbidity sensor, and they would log data to the SD card in the lab and for a short time in the field but at some random point they stop logging. Some would log for a few hours while others would log for a few days before stopping. The Mayflys were still running, as we programmed them to flash lights every time they are supposed to collect data, so it isn’t them just switching off as far as we can tell. It also isn’t them running out of space on the SD card, as they are fairly large and the files are small. We missed several storm events already with this issue, but I would like to get them back out soon once this issue is resolved.
Two of the other loggers we bought have been unusable so far. One does not log to an SD card at all, even though it is the exact same sketch that is on the other Mayflys that have been logging. I have tried several different SD cards, and none have worked. When monitoring the serial monitor when hooked up to this Mayfly, it says it is logging to the SD card but when checking the card, there is nothing there. The other Mayfly does nothing when hooked to my computer, and the bottom of the board near the SJ11 USB Proq location starts heating up, making us think there is a short in this area of the board.
Any information that could resolve these issues would be greatly appreciated. I added my code snippet below.
Arduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315#include <Wire.h>#include <avr/sleep.h>;#include <avr/wdt.h>;#include <SPI.h>;#include <SD.h>;#include <RTCTimer.h>;#include <Sodaq_DS3231.h>;#include <Sodaq_PcInt.h>;#include <SeeedGrayOLED.h>;#include <avr/pgmspace.h>;#include <Adafruit_ADS1015.h>;Adafruit_ADS1115 ads; /* Use this for the Mayfly because of the onboard 16-bit ADS1115 */RTCTimer timer;//RTC Interrupt pin#define RTC_PIN A7#define RTC_INT_PERIOD EveryMinute//Digital pin 12 is the MicroSD slave select pin on the Mayfly#define SD_SS_PIN 12//The data log file#define FILE_NAME "Sensor5.txt"//Data header (these lines get written to the beginning of a file when it's created)#define LOGGERNAME "Sensor Five"#define DATA_HEADER "SampleNumber, Battery_volts, TurbSens_volts, intT_degC, date_Time"int currentminute;long currentepochtime = 0;int sampleinterval = 3; //time between samples, in secondsint delayTime = 500; //milliseconds, used for green LED flash at sample timeint samplenum = 1; // declare the variable "samplenum" and start with 1int batteryPin = A6; // on the Mayfly board, pin A6 is connected to a resistor divider on the battery inputint batterysenseValue = 0; // variable to store the value coming from the analogRead function at pin A6float batteryvoltage; // the battery voltage as calculated by the formula belowfloat voltage;//int TurbSens; // variable to store the value coming from the analogRead function at pin A0//float turbvoltage; // the turbidity sensor voltage as calculated by the formula belowvoid setDisplayToOriginalState(){SeeedGrayOled.init(SH1107G);}void setup(){pinMode(22, OUTPUT); //pin D22 is the enable line for the Mayfly's switched 3.3/5v power lines//digitalWrite(22, HIGH); //set this pin high and leave it on for the rest of the sketchpinMode(8, OUTPUT); // declare the Green ledPin as an OUTPUTrtc.begin(); // read internal temperature//Initialise the serial connectionSerial.begin(57600);ads.begin();//Initialise log filesetupLogFile();setupTimer(); //Setup timer eventssetupSleep(); //Setup sleep mode//Echo the data header to the serial connectionSerial.println(DATA_HEADER);Wire.begin();}void loop(){//Update the timertimer.update();if(currentminute % 5 == 0) // change "2" to "5" to wake up logger every 5 minutes instead{ Serial.println("Multiple of 5! Initiating sensor reading and logging data to SDcard....");digitalWrite(8, HIGH); // turn the Green ledPin on//delay(delayTime);//digitalWrite(8, LOW);digitalWrite(22, HIGH); //set this pin highdelay(delayTime);digitalWrite(22, LOW);digitalWrite(8, LOW);String dataRec = createDataRecord();//Save the data record to the log filelogData(dataRec);//Echo the data to the serial connectionSerial.println(dataRec);}setDisplayToOriginalState();SeeedGrayOled.clearDisplay(); //Clear Display.SeeedGrayOled.setNormalDisplay(); //Set Normal Display ModeSeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying textfor(char i=0; i < 16 ; i++)SeeedGrayOled.setGrayLevel(15); //Set Grayscale level. Any number between 0 - 15.SeeedGrayOled.setTextXY(0,0); //Set the cursor to 0th line, 0th ColumnSeeedGrayOled.putNumber(samplenum); //Print numberSeeedGrayOled.setTextXY(1,0); //Set the cursor to 1st line, 0th ColumnSeeedGrayOled.putNumber(batteryvoltage); //Print numberSeeedGrayOled.setTextXY(2,0); //Set the cursor to 2nd line, 0th ColumnSeeedGrayOled.putNumber(voltage); //Print numberdelay(10000);delay(sampleinterval*1000); //multiply by 1000 to convert from milliseconds to seconds//SleepsystemSleep();}void showTime(uint32_t ts){//Retrieve and display the current date/timeString dateTime = getDateTime();Serial.println(dateTime);}void setupTimer(){//Schedule the wakeup every minutetimer.every(1, showTime);//Instruct the RTCTimer how to get the current time readingtimer.setNowCallback(getNow);}void wakeISR(){//Leave this blank}void setupSleep(){pinMode(RTC_PIN, INPUT_PULLUP);PcInt::attachInterrupt(RTC_PIN, wakeISR);//Setup the RTC in interrupt modertc.enableInterrupts(RTC_INT_PERIOD);//Set the sleep modeset_sleep_mode(SLEEP_MODE_PWR_DOWN);}void systemSleep(){//This method handles any sensor specific sleep setupsensorsSleep();//Wait until the serial ports have finished transmittingSerial.flush();Serial1.flush();//The next timed interrupt will not be sent until this is clearedrtc.clearINTStatus();//Disable ADCADCSRA &= ~_BV(ADEN);//Sleep timenoInterrupts();sleep_enable();interrupts();sleep_cpu();sleep_disable();//Enbale ADCADCSRA |= _BV(ADEN);//This method handles any sensor specific wake setup// sensorsWake();}void sensorsSleep(){//Add any code which your sensors require before sleep}//void sensorsWake()//{// //Add any code which your sensors require after waking//}String getDateTime(){String dateTimeStr;//Create a DateTime object from the current timeDateTime dt(rtc.makeDateTime(rtc.now().getEpoch()));currentepochtime = (dt.get()); //Unix time in secondscurrentminute = (dt.minute());//Convert it to a Stringdt.addToString(dateTimeStr);return dateTimeStr;}uint32_t getNow(){currentepochtime = rtc.now().getEpoch();return currentepochtime;}void setupLogFile(){//Initialise the SD cardif (!SD.begin(SD_SS_PIN)){Serial.println("Error: SD card failed to initialise or is missing.");//Hang// while (true);}//Check if the file already existsbool oldFile = SD.exists(FILE_NAME);//Open the file in write modeFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Add header information if the file did not already existif (!oldFile){logFile.println(LOGGERNAME);logFile.println(DATA_HEADER);}//Close the file to save itlogFile.close();}void logData(String rec){//Re-open the fileFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Write the CSV datalogFile.println(rec);//Close the file to save itlogFile.close();}String createDataRecord(){//Create a String type data record in csv format//SampleNumber, Battery, TurbSens, Temp degCString data = "";data += samplenum; //creates a string called "data", put in the sample numberdata += ", "; //adds a comma between valuesbatterysenseValue = analogRead(batteryPin); // reads the analog voltage on the batteryPin, reported in bitsbatteryvoltage = (3.3/1023.) * 4.7 * batterysenseValue; // converts bits into volts (for Mayfly v0.5 and v0.5b)data += batteryvoltage; //adds the battery voltage to the data string//TurbSens = analogRead(A0); // read the input on analog pin 0// turbvoltage = (TurbSens * 5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5.0V):// addFloatToString(data, batteryvoltage, 4, 2);// data += ", ";// addFloatToString(data, turbvoltage, 6, 4);int16_t adc2 = ads.readADC_SingleEnded(2); //reads Mayfly aux analog channel 2 (AA2), returns number of bitsvoltage = adc2 * 0.1875; //converts bits to millivolts; default resolution of ADS1115 is 0.1875mv/bitdata += ", ";data += voltage; //adds the turbidity sensor voltage to the data stringrtc.convertTemperature(); //convert current temperature into registersdata += ", ";data += (rtc.getTemperature()); //read registers and add temperature to data string//Create a String type data record in csv format//SampleNumber, BatteryDateTime now = rtc.now(); //get the current date-time//data += samplenum; //creates a string called "data", put in the sample numberdata += ", ";data += now.month(), DEC;data += "/";data += now.date(), DEC;data += "/";data += now.year(), DEC;data += " ";data += now.hour(), DEC;data += ":";data += now.minute(), DEC;data += ":";data += now.second(), DEC;data += " ";samplenum++; //increment the sample numberreturn data;}//static void addFloatToString(String & str, float val, char width, unsigned char precision)//{// char buffer[10];// dtostrf(val, width, precision, buffer);// str += buffer;//} -
2019-09-15 at 11:48 AM #13139
Drew-
I can’t offer any specific suggestions for your problems but I recognize some of the code that I used for a similar project to gather Electrical Conductivity (EC) data. I have attached my writeup on this project which includes my code. I have several of these stations deployed and some for almost a year and have not experienced any of the problems that you have had. The only issues I had is with J1:- Note: The code uses the D10 hardware interrupt therefor SJ1 must be cut from A7 and connected to D10.
Hope this helps
-jimAttachments:
-
2019-09-16 at 11:13 AM #13143
It’s possible that there is a short-circuit in the Mayfly, but this sounds more like a problem with your code or sensors.
When you’re posting code, please use the “Add Code Snippet” button. It adds coloring and formatting which makes the code much easier to read.
When you’re troubleshooting the boards, make sure to check the position of all of your switches and jumpers. If the small switch at the top of the board is set to “4-12V” instead of LiPo, the board will not be powered by the computer and thus will not respond when plugged into the computer. Also check all the settings of the jumpers near your Grove ports. Most of then can be changed between 3.3V switched and 5V switched power and the I2C can be changed between 3.3V switched and 3.3V continuous power. Some I2C devices have internal pull-up resistors which can cause the I2C bus to go low if the power is switched off. If the I2C bus is held low for any reason, the Arduino core I2C (Wire) library will crash and the board will completely stop responding. Both the RTC and the auxiliary ADC use I2C to communicate, so the crash might happen when you’re talking to one of them instead of when you’re talking to a sensor.
I am not familiar with the particular OLED screen you are using, but I wouldn’t recommend any screen for field deployments because they require a fair amount of power. If you do not have one attached, you should probably remove the code for it to help make troubleshooting easier.
-
2019-09-16 at 3:09 PM #13144
Hello,
Thank you for the information. I removed the unnecessary parts in my code, as we currently were not using the OLED screen. Since we are not using the screen any longer, I2C is also no longer being used. All switches on the two boards that were not working as well as the boards in the field are where they need to be, so that is likely not the issue. I also was using the code snippet button, but it posts my code into this exactly like it did above in my original post.
I tested the twos boards that we had issues with again, and the one that we believe has a short is still acting like it did before, where my computer can tell it is there but cannot upload anything to it and it starts to heat up. The second one that we had a logging issue with appears to be working now, so that has been resolved.
-
2019-09-16 at 4:39 PM #13145
Since we are not using the screen any longer, I2C is also no longer being used.
No. If you are using either the DS3231 real time clock or the TI1115 analog-to-digital converter built into the Mayfly, you are using I2C. Both of those are I2C chips.
-
2019-09-16 at 5:01 PM #13146
I edited your original post to put the code into the Code Snippet tool.
I check every one of the Mayfly boards thoroughly before they get sent out to Amazon, so it’s possible that one with an FTDI or USB jack issue slipped by since that’s the only part of it that I don’t check. Send me an email to mayfly@envirodiy.org and I’ll see what I can do about addressing the overheating board issue.
-
2019-09-22 at 6:47 PM #13157
Hello,
Thank you everyone for your help. These issues have been resolved.
-
-
AuthorPosts
- You must be logged in to reply to this topic.