Read Sensor trought UART

Everything about programming the platform and using the Waspmote API
Post Reply
pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Read Sensor trought UART

Post by pablo_chumacero » Tue May 09, 2017 10:22 am

Hi,

I'm trying read a sensor of Decagon Devices (GS3) trought UART. The problem I have is that the sensor sends me a character string via serial communication (UART) and I can't read this data. When excitation voltage is applied, the GS3 makes a measurement. Within about 50 ms of excitation three measurement values are transmitted as a serial stream of ASCII characters. The serial out is 1200 baud asynchronous with 8 data bits, no parity, and one stop bit. The voltage levels are 0 to 3.6 V and the logic levels are TTL (active low). The power must be removed and reapplied for a new set of values to be transmitted.

The string of characters you send is like this:

<09> 22.0 21.2 1302 <0D> w8 <0D> <0A>

However what I get is this:

Code: Select all

E#
Lectura Sensor GS3
Conecte Sensor

Conecte Sensor

Conecte Sensor

Conecte Sensor

Conecte Sensor

Conecte Sensor

Conecte Sensor

Conecte Sensor
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Conecte Sensor
0
0
0
0
0
0
0
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

I don't know if I'm using the correct functions, attach my code here:

Code: Select all

char dato[28];
int i;

void setup()
{
  USB.ON();
  USB.println(F("Lectura Sensor GS3"));
  PWR.setSensorPower(SENS_5V,SENS_ON); //my sensor need this voltatge
  Utils.setMuxAux1(); // check the manual to find out where you connect the sensor                                                                                                                                             
  beginSerial(1200,1); //it may be that you need other baut rate
  delay(2000);

}

void loop()
{
  USB.println("Conecte Sensor");
  delay(500);
  if (serialAvailable(1))
  {
    for(int i=0;i<28;i++)
    {
      dato[i]=serialRead(1);
      USB.println(serialRead(1));
    }
  }
  
  USB.println((char*)dato);
  delay(1000);

  
}
I have even tried to send a similar message from another microcontroller: "<09> 22.0 21.2 1302 <0D> w8 <0D> <0A>"

And I have received this:

Code: Select all

E#
Lectura Sensor GS3
Conecte Sensor
48
62
50
48
50
46
32
51
50
48
62
56
48
62
48
62
48
62
50
48
50
46
32
51
50
48
62
56
<92. 1210<Dw<D<A<92. 1210<Dw 8
Conecte Sensor
48
62
48
62
48
62
50
48
50
46
32
51
50
48
62
56
48
62
48
-1
-1
-1
-1
-1
-1
-1
-1
-1
<D<A<92. 1210<Dw<D<ÿAÿÿ>ÿÿÿÿ `
Conecte Sensor
48
62
50
48
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
<92.ÿÿ ÿÿ2ÿ1ÿÿ.ÿ2ÿÿ ÿ1ÿÿ3ÿ0ÿ q
Conecte Sensor
60
68
119
60
68
60
65
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
20>80>0>ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ €
Conecte Sensor
48
62
50
48
50
46
32
51
50
48
62
56
48
62
48
62
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
<92. 1210<Dw<D<Aÿÿÿÿÿÿÿÿÿÿÿÿ  
Attach an image of my connections. The sensor is powered at 5V so I connected it to the 5V output of the Waspmote, in addition to the ground. The data arrives at the auxiliary UART Rx 1.Image


Thanks in advance.

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

Re: Read Sensor trought UART

Post by libelium-dev » Tue May 09, 2017 2:32 pm

Hi,

Is the second output you posted the correct output?

Please try with this code

Code: Select all

WaspUART UART;

int i;

void setup()
{
  USB.ON();
  USB.println(F("Lectura Sensor GS3"));
  PWR.setSensorPower(SENS_5V,SENS_ON); //my sensor need this voltatge
  UART.setBaudrate(9600);
  UART.setUART(1);
  UART.beginUART();
  Utils.setMuxAux1();                                                                                   
  
  delay(2000);

}

void loop()
{
  USB.println("Conecte Sensor");
  delay(500);
  if (serialAvailable(1))
  {
      UART.readBuffer(28);
      USB.println(UART._buffer,UART._length);

  }
 delay(5000);
}
Regards

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

Re: Read Sensor trought UART

Post by pablo_chumacero » Thu May 11, 2017 6:32 pm

Thanks for your reply.

My second output is the one I tried sending a similar message from another microcontroller to waspmote. I tried the code you attached and it worked when I sent a message from another microcontroller, however, it didn't work when I tried the sensor, I think the sensor is not responding well. Thanks for the help.

I have another question, can I try to implement SDI-12 communication in Waspmote?

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

Re: Read Sensor trought UART

Post by niomike » Thu May 11, 2017 7:52 pm

I have successfully implemented an SDI-12 sensor with the waspmote. I talk about the process here: viewtopic.php?f=54&t=23450

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

Re: Read Sensor trought UART

Post by libelium-dev » Mon May 15, 2017 1:06 pm

Thanks for your contribution @niomike!!

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

Re: Read Sensor trought UART

Post by pablo_chumacero » Mon May 15, 2017 7:03 pm

niomike wrote:I have successfully implemented an SDI-12 sensor with the waspmote. I talk about the process here: viewtopic.php?f=54&t=23450
Thank you so much niomike. I will try with my sensor and then I'll tell you

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

Re: Read Sensor trought UART

Post by pablo_chumacero » Fri May 19, 2017 7:32 pm

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:

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);

 
}

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

Re: Read Sensor trought UART

Post by libelium-dev » Wed May 24, 2017 12:17 pm

Hi Pablo,

We are sorry but don't have experience working with that library. We hope that some forum user can help you.

Regards

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

Re: Read Sensor trought UART

Post by niomike » Wed May 24, 2017 7:20 pm

Hi pablo_chumacero,

Assuming the hardware setup is correct, one issue I see is that you are calling the probe on address 2:

Code: Select all

mySDI12.sendCommand("2I!");


The default value for most sensors is 0:

Code: Select all

mySDI12.sendCommand("0I!");
and I confirmed that the sensor you are using defaults to address 0 unless you have changed it.

I hope this helps.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest