Forum Replies Created
-
AuthorPosts
-
One more thing: If you’re going to use your Mayfly as a logger, make sure you set the real time clock first! I’ve written a sketch and tiny executable to synchronize the Mayfly with your computer clock. You can find it here: https://github.com/EnviroDIY/Sodaq_DS3231/tree/master/examples/PCsync
Yup, doing the soldering will make your 3.5mm jack connection much prettier and more secure than using the screw terminals. If you’re skilled with a soldering iron, it’s the way to go.
If you’re skill-less and solder-less like I am, the jacks with screw terminals are a solution.
If you would prefer, you can also look into the Modular Sensors library, which has functions already built into it for getting data from a Decagon CTD, a Decagon ES2, and a Decagon 5TM and then logging that data to a SD card.
If you downloaded the full package of libraries I mentioned in #2134, the Modular Sensors library is already included in it. If not, you download the zip at https://github.com/EnviroDIY/ModularSensors/archive/master.zip and unzip that for the Arduino IDE or install in PlatformIO using “pio lib -g install https://github.com/EnviroDIY/ModularSensors.git”.
Now that your sensor is connected and has an address set, you can get data from it using code like this:
C++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071SDI12 mySDI12(_dataPin);mySDI12.begin();delay(500); // allow things to settlemyCommand = "";myCommand += _SDI12address;myCommand += "M!"; // SDI-12 measurement myCommand format [address]['M'][!]mySDI12.sendCommand(myCommand);Serial.println(myCommand); // For debuggingdelay(30);// wait for acknowlegement with format [address][ttt (3 char, seconds)][number of measurments available, 0-9]sdiResponse = "";while (mySDI12.available()) // build response string{char c = mySDI12.read();if ((c != '\n') && (c != '\r')){sdiResponse += c;delay(5);}}mySDI12.flush();// find out how long we have to wait (in seconds).unsigned int wait = 0;wait = sdiResponse.substring(1,4).toInt();Serial.print(F("Waiting ")); // For debuggingSerial.print(wait); // For debuggingSerial.println(F(" seconds for measurement")); // For debugging// Set up the number of results to expectnumMeasurements = sdiResponse.substring(4,5).toInt();Serial.print(numMeasurements); // For debuggingSerial.println(F(" results expected")); // For debuggingunsigned long timerStart = millis();while((millis() - timerStart) < (1000 * wait)){if(mySDI12.available()) // sensor can interrupt us to let us know it is done early{Serial.println("Wait interrupted!"); // For debuggingmySDI12.flush();break;}}delay(30);mySDI12.flush();Serial.println(F("Requesting data")); // For debuggingmyCommand = "";myCommand += _SDI12address;myCommand += "D0!"; // SDI-12 command to get data [address][D][dataOption][!]mySDI12.sendCommand(myCommand);Serial.println(myCommand); // For debuggingdelay(30);Serial.println(F("Receiving data")); // For debuggingmySDI12.read(); // ignore the repeated SDI12 addressfloat sensorValues[numMeasurements] = {0}; // Create an array to receive datafor (int i = 0; i < numMeasurements; i++){float result = mySDI12.parseFloat();sensorValues[i] += result;Serial.print(F("Result #")); // For debuggingSerial.print(i); // For debuggingSerial.print(F(": ")); // For debuggingSerial.println(result); // For debugging}// Wait for and discard anything elsemySDI12.flush();Once you have an array of values from the sensor, you can save them to an SD card or anything you’d like.
The next step is to set the SDI-12 address of the sensor. Communication with the sensor depends on its 1-character alphanumeric address (1-9, A-Z, a-z). Unfortunately, Decagon ships all of its sensors programmed to an SDI-12 address of 0, which cannot be used to get measurements from the sensor.
Within the SDI-12 library on GitHub, there is an example with instructions for changing the address. Find it here: https://github.com/EnviroDIY/Arduino-SDI-12/tree/master/examples/b_address_change
Once you have physically connected your sensor to your Mayfly board, the next step is to download the library to communicate with the it from GitHub. If you are only interested in the SDI-12 library, download it here: https://github.com/EnviroDIY/Arduino-SDI-12/archive/master.zip. If you would like to download a collection of libraries that might be useful in communicating with and logging data from sensors, including the SDI-12 library, download this: https://github.com/EnviroDIY/Libraries/raw/master/libraries.zip.
To install the libraries into the Arduino IDE, follow the instructions for Manual Installation on the Arduino library guide: https://www.arduino.cc/en/guide/libraries. If you are using PlatformIO you can install only the SDI-12 library using the terminal prompt command: platformio lib -g install “Arduino-SDI-12” or the entire collection of libraries using the command: pio lib -g install https://github.com/EnviroDIY/Libraries.git#platformio. For another IDE, follow the installation instructions for that IDE.
If you have not yet downloaded any IDE or program to communicate with your Mayfly, I highly recommend PlatformIO over the IDE created by Arduino.cc
Up to 61 SDI-12 sensors can be connected to the same pin of the Mayfly. It is more stable to use the same pin for all the SDI-12 sensors you wish to connect rather than using different pins for each because this allows you to create only one instance of the SDI-12 object in your code. To connect multiple sensors to that pin, you can use a Grove branch cable (https://www.seeedstudio.com/Grove-Branch-Cable-%285PCs-pack%29-p-847.html) or a Grove hub (https://www.seeedstudio.com/Grove-I2C-Hub-p-851.html).
2017-03-28 at 4:21 PM in reply to: Custom Arduino-based sensor, off-the-shelf SDI-12 datalogger #2122I’d love any feedback you have on the modular sensors library! Feel free to post GitHub issues or post comments in the forums.
The Libraries repository doesn’t actually have anything new on its own, it’s just a bunch of links so anyone can download some of the more helpful libraries all at once. Do let me know if you think there are any crucial libraries that are missing!
The wonderful people at PlatformIO have now added native support for the Mayfly. Run “platformio update” in the PlatformIO terminal and you will then be able to find the Mayfly in the drop downs and call up the Mayfly as “mayfly” just like any other board.
2017-01-23 at 1:24 PM in reply to: Looking for a bare-bones 16 bit 0-5V dc data logger sketch to build off of #1937How are you trying to talk to the analog pins? To get the 16 bit ADD conversion you must use the auxiliary ADD converter/library for the Ti ADS 1115. Here’s a bit of code that may help you along. (Please note that this code is completely the work of Shannon Hicks!)
1234567891011121314#include <Adafruit_ADS1015.h> /* The library for the auxiliary ADD */Adafruit_ADS1115 ads; /* Use this for the 16-bit version */int16_t adc0, adc1; // adc2, adc3; /* Tells which channels are to be read */// Read Channelsadc0 = ads.readADC_SingleEnded(0);adc1 = ads.readADC_SingleEnded(1);// now convert bits into millivoltsfloat lowvoltage = (adc0 * 3.3) / 17585.0;float highvoltage = (adc1 * 3.3) / 17585.0; -
AuthorPosts