SDI-12 library for Waspmote

Everything about programming the platform and using the Waspmote API
jhh
Posts: 9
Joined: Tue Nov 24, 2015 2:49 pm

SDI-12 library for Waspmote

Post by jhh » Fri Mar 03, 2017 1:10 pm

I’m struggling to adapt the Arduino-SDI-12 library to run on Waspmote. I’m curious if anyone has successfully used SDI-12 protocol on Waspmote, and if so, how did you do? I would be very happy if someone already have a working library and are willing to share that.

This is the sensor I’m experimenting with:
http://www.decagon.com/en/hydrology/wat ... ure-depth/

Link to Ardiuino-SDI-12
https://github.com/EnviroDIY/Arduino-SDI-12

niomike
Posts: 17
Joined: Fri Jun 24, 2016 9:52 pm

Re: SDI-12 library for Waspmote

Post by niomike » Sat Mar 04, 2017 9:00 pm

Hi, I have successfully implemented an SDI-12 project with a Waspmote. The probe we used was an AquaCheck soil moisture probe: http://www.aquachecktech.com/probes which supported SDI-12 at 3.3V. I'm not sure if the Waspmote supports a 5V interface, so hopefully your sensor works at 3.3V as well. For the physical interface we used the same pins as the DS18B20 which is a 1-Wire temperature sensor. I forget the exact pins on the connector, but it shouldn't be too hard to test them and find the power, ground, and data lines.

For the library, I modified the Arduino SDI-12 library that you mentioned. Here is our repo: https://github.com/nioinnovation/Arduin ... e/waspmote. There were two main modifications that needed to happen, first the waspmote doesn't have a micros() function like the arduino does, and second (if I remember correctly) is that the pin used with the DS18B20 doesn't support interrupts so the code needed to be modified to poll.

For the micros() issue, I used a timer available in the AVR1281 to count at about 1ms. This is specific to the processor and could be broken if a different processor/clock is used. But it works well enough for us. For the polling issue, I added a listen() function that simply polls for a reply. I also blocked out the interrupt routines with a preprocessor directive.

The code works well for our sensor, though every once in while it doesn't report the correct value for some reason. It works well enough that we haven't worked to track down any bugs, but feel free to submit any improvements you might make.

Unfortunately I don't have a copy of the sensor code online but the class declaration looks like this:

Code: Select all

#include "SDI12.h"              // SDI12 library to communicate

class AquaCheck {
private:
  SDI12 aquaCheckSDI12;
  
  char sdiCommand[6], sdiResponse[41];
  char dataResponse0[9], dataResponse1[9], dataResponse2[9], dataResponse3[9], dataResponse4[9], dataResponse5[9];
  char sdiAddress;
  int sdiTimeToCheck, sdiMeasurements;
  
public:
  char sdiMoisture[60], sdiTemperature[60];
  float dataMoisture[6], dataTemperature[6];

  AquaCheck(uint8_t dataPin);		// constructor

  int pollProbe(int readingType);                 // Address defaults to '0'
  int pollProbe(int readingType, int address);    
  int pollProbe(int readingType, char address);
}
and the waspmote code looks something like so:

Code: Select all

#define DATAPIN 17                  // pin that is connected to SDI12 moisture probe (17 = Analog4)
AquaCheck aquaCheck(DATAPIN);       // Moisture Probe sensor method

void loop() {
  SensorAgrv20.ON();	                        // Enable sensor board power
  SensorAgrv20.setSensorMode(SENS_ON, SENS_AGR_TEMP_DS18B20);  //Enable aquaCheck
  delay(1000);
  aquaCheck.pollProbe(0,0);  // Capture moisture data from SDI-12 Device
  USB.print("SoilMoisture: ");
  USB.print(aquaCheck.sdiMoisture); //write the response to the screen
  SensorAgrv20.setSensorMode(SENS_OFF, SENS_AGR_TEMP_DS18B20);  //Disable AquaCheck
  PWR.deepSleep("00:00:15:00",RTC_OFFSET,RTC_ALM1_MODE1,ALL_OFF);
}

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SDI-12 library for Waspmote

Post by libelium-dev » Tue Mar 07, 2017 10:11 am

Hi,

Thank you very much for your contribution with the forum, niomike. We hope your explanation helps jhh.

Regards

jhh
Posts: 9
Joined: Tue Nov 24, 2015 2:49 pm

Re: SDI-12 library for Waspmote

Post by jhh » Tue Mar 07, 2017 6:20 pm

Thanks alot!

I got it up and running with this simple code:

Code: Select all

void setup() {
  USB.ON();
  PWR.setSensorPower(SENS_5V, SENS_ON); // (JH)
  delay(500); // Sensor exitation delay

  mySDI12.begin();
}

void loop()
{
  // -'-'-'-'-'-'-INFO COMMAND-'-'-'-'-'-'-
  mySDI12.sendCommand("0I!");
  // delay(300);                  // wait a while for a response
  while (mySDI12.available())  // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  delay(1000);
  mySDI12.flush();

  // -'-'-'-'-MEASUREMENT COMMAND-'-'-'-'-
  mySDI12.sendCommand("0M!");
  // delay(300);                   // let the data transfer
  while (mySDI12.available())   // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  delay(1000);
  mySDI12.flush();

  // -'-'-'-'-'-'-DATA COMMAND-'-'-'-'-'-'- // (JH) Working examle
  mySDI12.sendCommand("0D0!");

  // delay(300);                  // let the data transfer
  while (mySDI12.available())  // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  mySDI12.flush();

  USB.println("- - - - - - - - - - - - - - - -");

  delay(3000);
}

Output from DS-2 sonic anemometer:
- - - - - - - - - - - - - - - -
013DECAGON SONIC13941021702220
00013
0+0.04+19+23.6
- - - - - - - - - - - - - - - -

..and from the CTD:
- - - - - - - - - - - - - - - -
013DECAGON CTD-103991059303521
00013
0+4+21.9+0
- - - - - - - - - - - - - - - -

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SDI-12 library for Waspmote

Post by libelium-dev » Thu Mar 09, 2017 2:43 pm

Hi jhh,

Thanks for sharing your code with the community! :D

Regards

Robert_HL
Posts: 28
Joined: Mon Jun 06, 2016 11:43 pm

Re: SDI-12 library for Waspmote

Post by Robert_HL » Wed Mar 22, 2017 10:38 pm

niomike - you LEGEND!
Thanks for sharing this!!

bogdanpaduraru
Posts: 6
Joined: Wed Feb 03, 2016 3:55 pm

Re: SDI-12 library for Waspmote

Post by bogdanpaduraru » Tue Apr 18, 2017 2:59 pm

Thank you very much niomike for the library. Working perfect with a CS476 water level sensor.

Excellent work!

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SDI-12 library for Waspmote

Post by libelium-dev » Wed Apr 19, 2017 11:24 am

Glad to hear users contribution helps to other people!

pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Re: SDI-12 library for Waspmote

Post by pablo_chumacero » Wed May 17, 2017 7:18 am

Hi guys,

I'm trying use the library with GS3 sensor: https://www.decagon.com/en/soils/volume ... c-temp-ec/

But i don't recibe any data for my data line. I don't know if is my code or any conexion. I power my sensor with 5V and use the DIGITAL8 pin of Waspmote. My code is below:

Code: Select all

#include <SDI12.h>

#define DATAPIN DIGITAL8
SDI12 mySDI12(DATAPIN);


void setup()
{
  USB.ON();
  USB.println(F("Lectura Sensor GS3"));
  PWR.setSensorPower(SENS_5V, SENS_ON);
  delay(500);
  mySDI12.begin();
  
}

void loop()
{
  // -'-'-'-'-'-'-INFO COMMAND-'-'-'-'-'-'-
  mySDI12.sendCommand("2I!");
  // delay(300);                  // wait a while for a response
  while (mySDI12.available())  // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  delay(1000);
  mySDI12.flush();

  // -'-'-'-'-MEASUREMENT COMMAND-'-'-'-'-
  mySDI12.sendCommand("2M!");
  // delay(300);                   // let the data transfer
  while (mySDI12.available())   // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  delay(1000);
  mySDI12.flush();

  // -'-'-'-'-'-'-DATA COMMAND-'-'-'-'-'-'- // (JH) Working examle
  mySDI12.sendCommand("2D0!");

  // delay(300);                  // let the data transfer
  while (mySDI12.available())  // write the response to the screen
  {
    USB.printf("%c", mySDI12.read());
  }
  mySDI12.flush();

  USB.println("- - - - - - - - - - - - - - - -");

  delay(3000);

 
}

rekhamanoj
Posts: 57
Joined: Tue May 26, 2015 1:03 pm

Re: SDI-12 library for Waspmote

Post by rekhamanoj » Fri Feb 09, 2018 5:32 am

Hi

I would like to connect a sensor to vegetronic board (https://www.vegetronix.com/Products/SDI ... ranslator/) and read the data from the sensor using waspmote. Since waspmote rs 232 board and vegetronix board has female connectors, we used a male to male null modem to connect these two. Following is the code that I have used. But I am not getting any output. Kindly help
/*
* AUM AMRITESWARYAI NAMAHA
Read data from a sensor which is connected to the RS-232 interface on waspmote
*/

//Include always this library when you are using the Wasp232 functions
#include <Wasp232.h>


void setup() {

// Power on the USB for viewing data in the serial monitor
// Note : if you are using the socket 0 for communication,
// for viewing data in the serial monitor, you should open
// the USB at the same speed
USB.ON();
delay(100);

// Powers on the module and assigns the UART in socket0
W232.ON(SOCKET0);
delay(100);


// Configure the baud rate of the module
W232.baudRateConfig(9600);

// Configure the parity bit as disabled
W232.parityBit(NONE);

// Use one stop bit configuration
W232.stopBitConfig(1);

delay(100);

// Hello message
USB.println("AUM AMMA\n RS-232 Communication ");
USB.println("RS-232 serial communication properly initialized.");
W232.send("ADD 0:0,15,0,0") ;
//W232.send("H") ;

delay(100);

}

void loop() {

char readCmd[] = "READ 0:1\n" ;// Specify the address of the sensor to be read

{
//USB.print("\navailable status ") ;
if (W232.available())
{

while (W232.available())
{

//USB.print(W232.available()) ;
char data = W232.read();
USB.print(data);

}
}
W232.send(readCmd) ;
//USB.print("H") ;
}
delay(2000); // interval between consecutive reads

}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest