@w3asa
Active 4 months agoForum Replies Created
-
AuthorPosts
-
Hi
I have built a low cost EC sensor using the Atlas Scientific probe. The EZO board for the pH sensor has the same interface so if you look on my recent blog I give all the details you should need. I assume you want to deploy this with battery power and solar recharge so the Mayfly will sleep most of the time. Setup code is included in my blog and you will want this initially to set up the Atlas EZO interface board which provides serial comm to the Mayfly.Hope this helps
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:
I noticed that Atlas Scientific sensors are not in the ModularSensors list. I have built two EC sensor stations that are currently deployed in Great Marsh primarily to monitor stormwater runoff from the Pa Tpk. Scott Ensign has suggested I write this project up in more detail. Sara, are you interested in adding these sensors to ModularSensors if so I can give the code and details for this project?
Currently these EC stations are storing the data on a sd card only. Access to these stations can be a bit challenging to say the least especially in this weather!
I recently purchased some XBee’s from Sparkfun and have been able to get them talking to each other using the serial passthrough example code loaded on a Mayfly. I have checked out the range of the XBee Pro (60 mW) and I think they have the range to talk to a central location using the XBee’s ‘out of the box’ configuration.
I am looking for any code examples for using XBee for end to end comm. Basically I want to send data to a central station station when ever the mayfly wakes up and takes
EC and temperature data.On the hardware side has anyone had experience connecting an SMA conector to the XBee board with the attached whip antenna? The distances involved are about 1 KM LOS so will probably need some gain antennas since I am quite sure the little whip antennas wont quite cut it.
I attached a dropbox link to brief report on the deployment of the EC/temp stations
I can feel your pain, Cal. I am going to face the problem of data upload to the the cloud or whatever on some projects that I am contemplating. I have a Mayfly water sensor on my property and the 2G is working fine. Shannon has a small box that does a 2G site survey that we used before installation of SL149
I think the larger concern will be how to upgrade all the existing Mayfly’s using 2G when that service goes the way of the dot-matrix printer!
I got some input on this question from some colleagues and in summary 3G and 4G will be overkill in terms of data rate so it would be expensive. The other option might be ORBCOMM which is a low data rate store and forward system which might be more affordable.
Hi Stephen-
Generally all you need is a diode (1n914) and clamp resister, 10 K, to the 3.3 Volt bus. This will isolate the higher rs232 voltage from the Mayfly. This is not totally spec (the diode drop gets added to your logic levels) but should work.
Shannon can probably add to this in case he has tried the cheap and dirty solution and it doesn’t work. If not try it since these parts are less than a dollar or floating around in your electronic scrap box. Or Radio Shack if you can find a store that isn’t selling exclusively cell phones!I have been trying to setup the new rev 0.5 boards to run my Atlas Scientific sensors and I have been using the Mayfly_sleep example. I changed J1 to use D10 as the interupt and it didn’t work till I used attachInterrupt(2, wakeISR,CHANGE)
This didn’t work reliably until I added the pinMode(RTC_PIN, INPUT_PULLUP) back into the example code.I now have the example code working on my rev 0.5 board but the battery voltage is 1.5.
Multiple of 2! Initiating sensor reading and logging data to SDcard….
Data Record: 2017-05-14 22:28:00,548116080,23.8,1.52
showTime = 2017-05-14 22:29:00
showTime = 2017-05-14 22:30:00
Multiple of 2! Initiating sensor reading and logging data to SDcard….
Data Record: 2017-05-14 22:30:00,548116200,23.8,1.52
This code read the battery voltage correctly on the rev 0.3 board.
Is the correct pin still A6?Thanks Shannon-
I got my mayfly boards today and just ordered some protoboards.I just ordered two Mayfly boards so they seem to be in stock. I could not find the protoshields however. Are they in stock?
Any estimate when mayfly proto boards will be available?
I finally solved the never-sleep problem. The problem seems to be related to the slow decay of the power to the Grove connector. With the sensor connected the decay is approximately 50ms. In the senosrSleep() function the power and rx/tx are turned off but the Vcc voltage doesn’t get a chance to decay before this function is exited which seems to cause an immediate wakeup. I added a 100ms delay to that function and now seems to work as planned.
I am not sure what causes the immediate wake up but must be related to the residual voltage on the pwr pin. With the sensor disconnected the code works with out the delay probably because there is no capacitance to hold up the voltage.
I cleaned up the code a bit and here is rev 1.0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318/*This example sketch puts the Mayfly board into sleep mode. It wakes up at specific timesto turn on the Atlas Scientific EZO sensors. The EZO sensor is configured to output sensordata once per second (c,1 command)which is logged to the SD card along with time stamp,board temp, and battery voltage. Note: if sleep time is greater than 1 minute the board willstill wake for 100ms which is less than the turn on time of the sensor.JOM 2/9/17 added power on/off to EZO boardJOM 2/12/17 downloaded ...Mod.h libraries to fix RTC interupt conflicts. Need to turn offrx and tx when putting to sleep otherwise rx/tx powers the sensor after Vcc is turned offJOM 2/13/17 Problem sensor on most of time.JOM 3/18/17 The never-sleep problem was fixed by adding a 100ms delay to the sensorsSleep()function. This allows Vcc to the sensor to decay to zero which is ~50 ms. The pwr on takes only ~5us.*/#include <Wire.h>#include <avr/sleep.h>#include <avr/wdt.h>#include <SPI.h>#include <SD.h>#include <SoftwareSerialMod.h>#include <RTCTimer.h>#include <Sodaq_DS3231.h>#include <Sodaq_PcInt_Mod.h>RTCTimer timer;#define rx 11 //D11 to Tx on EZO (white on Grove conn)#define tx 10 //D10 to Rx on EZO (yellow on Grove conn)SoftwareSerialMod myserial(rx, tx); //define how the soft serial port is going to work.String dataRec = "";String sensorstring = "EZO data"; //a string to hold the data from the EZO productint currentminute;int n = 0;int nMax = 20;int sleepMinutes = 5; //total minutes the Mayfly is in sleep modelong currentepochtime = 0;float boardtemp;int batteryPin = A6; // to read battery voltageint batterysenseValue = 0; // variable to store the value coming from the sensorfloat batteryvoltage;boolean sensor_stringcomplete = false; //have we received all the data from the EZO product//RTC Interrupt pin#define RTC_PIN A7#define RTC_INT_PERIOD EveryMinute#define SD_SS_PIN 12 //orig had pin 11//The data log file#define FILE_NAME "datafile.txt"//Data header#define LOGGERNAME "SampleLogger"#define DATA_HEADER "DateTime_EST,Loggertime,BoardTemp_C,Battery_V"void setup(){//Initialise the serial connectionSerial.begin(9600);myserial.begin(9600); //set baud rate for software serial port_3 to 9600//if myserial active sleep doesn't workrtc.begin();pinMode(8, OUTPUT);pinMode(9, OUTPUT);pinMode(22, OUTPUT); //Power to Grove connectorssensorstring.reserve(30); //set aside some bytes for receiving data from EZO productgreenred4flash(); //blink the LEDs to show the board is onsetupLogFile();setupTimer(); //Setup timer eventssetupSleep(); //Setup sleep modedigitalWrite(10, false); //Turn off tx to EZO cktdigitalWrite(11, false); //Turn off rx to EZO cktdigitalWrite(22, true); //Turn on power to EZO cktSerial.println("Power On, running: mayfly_sleep_sample1.ino");showTime(getNow());}void loop(){//Update the timertimer.update();if (currentminute % sleepMinutes == 0) //will wake every minute for set delay untill condition//is satisfied{while (!sensor_stringcomplete && (n < nMax)){recieveSensorData();}n = 0;}delay(100); //should be less than sensor turnon time which is ~1sec//SleepsystemSleep();} //end loopvoid sensorsSleep(){Serial.println("..going to sleep!");digitalWrite(22, false); //Turn off power to EZO cktdigitalWrite(10, false); //Turn off tx to EZO cktdigitalWrite(11, false); //Turn off rx to EZO cktdelay(100); //adding delay fixed the never-sleep problem}void sensorsWake(){digitalWrite(22, true); //Turn on power to EZO cktSerial.println("..I'm awake!");}void recieveSensorData(){if (myserial.available() > 0) { //if we see that the EZO product has sent a character.char inchar = (char)myserial.read(); //get the char we just receivedsensorstring += inchar;if (inchar == '\r') {sensor_stringcomplete = true; //if the incoming character is a <CR>, set the flagn++;}}if (sensor_stringcomplete) { //if a string from the EZO product has been received//in its entiretydataRec = createDataRecord();if (n >= 3) //don't log sensor startup response{logData(dataRec); //Save the data record to the log file}Serial.print(" ");Serial.println(dataRec);Serial.print("n= ");Serial.println(n);sensorstring = ""; //clear the string:sensor_stringcomplete = false; //reset the flag used to tell if we have received a}}String createDataRecord(){//Create a String type data record in csv format//TimeDate, Loggertime,Temp_DS, Diff1, Diff2, boardtempString data = getDateTime();data += ",";rtc.convertTemperature(); //convert current temperature into registersboardtemp = rtc.getTemperature(); //Read temperature sensor valuebatterysenseValue = analogRead(batteryPin);batteryvoltage = (3.3 / 1023.) * 1.47 * batterysenseValue;data += currentepochtime;data += ",";addFloatToString(data, boardtemp, 3, 1); //floatdata += ",";addFloatToString(data, batteryvoltage, 4, 2);data += " , "; //adds a comma between valuesdata += sensorstring; //adds pH to the data stringreturn data;}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 setupsensorsWake();}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 greenred4flash(){for (int i = 1; i <= 4; i++) {digitalWrite(8, HIGH);digitalWrite(9, LOW);delay(50);digitalWrite(8, LOW);digitalWrite(9, HIGH);delay(50);}digitalWrite(9, LOW);}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();}static void addFloatToString(String & str, float val, char width, unsigned char precision){char buffer[10];dtostrf(val, width, precision, buffer);str += buffer;} -
AuthorPosts