Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site



Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: Conexión Arduino - Shield 4-20 mA
PostPosted: Thu Apr 05, 2018 11:13 am 

Joined: Tue Nov 04, 2014 11:03 pm
Posts: 8
Estamos haciendo una prueba de concepto para conectar sensores de tipo 4-20mA a una arduino con el shield de cooking-hacks de 4-20mA y esta Arduino es interrogada por una raspberry que recoge los datos de las lecturas de los sensores.

El problema que tenemos es que haciendo pruebas con un sensor de temperatura de tipo 2, sí tenemos los 24V en la salida de los pines Vout del Shield, pero en los canales no tenemos los 24 V. y la medida que obtenemos siempre es 0. Tenemos los jumpers puestos.

Alguna idea de qué puede ser.

Se adjuntan fotos del montaje:

https://1drv.ms/u/s!An-Wc_eGPy9rh4UCza-N9kjhSMhu-g
https://1drv.ms/u/s!An-Wc_eGPy9rh4R_y7KikHqrlOSG4g
https://1drv.ms/u/s!An-Wc_eGPy9rh4UAaPQojO8FTycXBw
https://1drv.ms/u/s!An-Wc_eGPy9rh4UBhVhloeki254zug

Y el programa que estamos ejecutando, sigue el ejemplo del tutorial, pero hemos incluido la parte de interpretar unos comandos que enviamos desde la Rapsberry a la Arduino:

#include <currentLoop.h>

String readString;
#define CHANNEL CHANNEL4
//currentLoop sensor(CHANNEL1);

void setup()
{
sensorBoard.ON();
Serial.begin(9600);
delay(100);
}

void loop() {

while (Serial.available()) {
delay(5);
if (Serial.available() >0) {
char c = Serial.read();
readString += c;

}
}

//SE LEE UN COMANDO/ORDEN/VALOR1/VALOR2/VALOR3/VALOR4
if (readString!="") {
char *dup = strdup(readString.c_str());
String comando = strtok(dup, "/");
String orden = strtok(NULL,"/");
String value1 = strtok(NULL,"/");
String value2 = strtok(NULL,"/");
String value3 = strtok(NULL,"/");
String value4 = strtok(NULL,"/");
free(dup);

readString="";

if (comando=="424A")
{
//int value = sensorBoard.readChannel(orden.toInt());
int value = sensorBoard.readChannel(CHANNEL);
Serial.println(value);

}
else if (comando=="424B")
{

float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(current);

}
else if (comando=="421A")
{
//int value = sensorBoard.readChannel(orden.toInt());
int value = sensorBoard.readChannel(CHANNEL1);
Serial.println(value);

}
else if (comando=="421B")
{

float current = sensorBoard.readCurrent(CHANNEL1);
Serial.println(current);

}
else if (comando=="422A")
{
//int value = sensorBoard.readChannel(orden.toInt());
int value = sensorBoard.readChannel(CHANNEL2);
Serial.println(value);

}
else if (comando=="422B")
{

float current = sensorBoard.readCurrent(CHANNEL2);
Serial.println(current);

}
else if (comando=="423A")
{
//int value = sensorBoard.readChannel(orden.toInt());
int value = sensorBoard.readChannel(CHANNEL3);
Serial.println(value);


}
else if (comando=="423B")
{

float current = sensorBoard.readCurrent(CHANNEL3);
Serial.println(current);

}

else{
Serial.println("COMANDO DESCONOCIDO");
}


readString="";
Serial.flush();


}

}


Top
 Profile  
 
 Post subject: Re: Conexión Arduino - Shield 4-20 mA
PostPosted: Thu Apr 05, 2018 1:45 pm 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hola,

Para un sensor tipo 2 tienes que conectar uno de los cables al pin de alimentación (24v) y el otro a un pin de canal+. Aqui puedes ver un esquema de como conectar cada tipo de sensor
http://www.libelium.com/downloads/docum ... df#page=25

Asegurate que tu sensor admite 24 voltios.

Un saludo


Top
 Profile  
 
 Post subject: Re: Conexión Arduino - Shield 4-20 mA
PostPosted: Thu Apr 05, 2018 8:22 pm 

Joined: Tue Nov 04, 2014 11:03 pm
Posts: 8
Muchas gracias, no había entendido bien y pensaba que generar los 24V se replicaba en todos los canales para alimentar los sensores de tipo 2 y medir.

Ya hemos conectado el sensor (funciona en el rango de 9 a 36V) bien al shield:

https://1drv.ms/u/s!An-Wc_eGPy9rh4UKdvhhImj6ZglRCg

Ahora nos encontramos en que no conseguimos que el shield mida lo mismo que mide cuando lo conectamos a una fuente externa y medimos con el polímetro.

El comportamiento que detectamos es el siguiente:

a) Cuando conectamos el shield al sensor da siempre un valor entre 9 - 10 mA independientemente de si el sensor esta a una temperatura u otra (La gráfica se corresponde con la entrada 420C/1/ en el código . Se está leyendo con la función que te da los mA en el canal 1)

https://1drv.ms/u/s!An-Wc_eGPy9rh4UFYTh4tI41G0fcMA

b) Si quitamos el sensor del shield medimos entorno a un valor de 24:

https://1drv.ms/u/s!An-Wc_eGPy9rh4UIhDO8JJj7ycI7-w

c) Si medimos el sensor conectado a una fuente externa y medimos con el polimetro sí obtenemos un comportamiento normal:

- Medida sensor fuera del agua: https://1drv.ms/u/s!An-Wc_eGPy9rh4UG3SYjd4QIZ8BA4Q
- Medida sensor en agua caliente: https://1drv.ms/u/s!An-Wc_eGPy9rh4UH6e2VFv0BeHWzqg

Se os ocurre qué puede pasar? Este es el programa que estamos utilizando para medir los mA.

Muchas gracias, Alberto
_____________________________-
Se adjunta código utilizado:

#include <currentLoop.h>

String readString;
#define CHA1 CHANNEL1
#define CHA2 CHANNEL2
#define CHA3 CHANNEL3
#define CHA4 CHANNEL4
//currentLoop sensor(CHANNEL1);


void setup()
{
sensorBoard.ON();

Serial.begin(9600);
delay(100);
}

void loop() {

while (Serial.available()) {
delay(5);
if (Serial.available() >0) {
char c = Serial.read();
readString += c;

}
}

//SE LEE UN COMANDO/ORDEN/VALOR1/VALOR2/VALOR3/VALOR4
if (readString!="") {
char *dup = strdup(readString.c_str());
String comando = strtok(dup, "/");
String orden = strtok(NULL,"/");
String value1 = strtok(NULL,"/");
String value2 = strtok(NULL,"/");
String value3 = strtok(NULL,"/");
String value4 = strtok(NULL,"/");
free(dup);

readString="";

if (comando=="421A")
{
//int value = sensorBoard.readChannel(orden.toInt());
//int value = sensorBoard.readChannel(CHANNEL);
Serial.println(sensorBoard.readChannel(CHA1));


}
else if (comando=="421B")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readVoltage(CHA1));

}
else if (comando=="421C")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readCurrent(CHA1));

}
else if (comando=="421D")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.isConnected(CHA1));

}


//CANAL2

else if (comando=="422A")
{
//int value = sensorBoard.readChannel(orden.toInt());
//int value = sensorBoard.readChannel(CHANNEL);
Serial.println(sensorBoard.readChannel(CHA2));


}
else if (comando=="422B")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readVoltage(CHA2));

}
else if (comando=="422C")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readCurrent(CHA2));

}
else if (comando=="422D")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.isConnected(CHA2));

}

//CANAL3

else if (comando=="423A")
{
//int value = sensorBoard.readChannel(orden.toInt());
//int value = sensorBoard.readChannel(CHANNEL);
Serial.println(sensorBoard.readChannel(CHA3));


}
else if (comando=="423B")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readVoltage(CHA3));

}
else if (comando=="423C")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readCurrent(CHA3));

}
else if (comando=="423D")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.isConnected(CHA3));

}


//CANAL4

else if (comando=="424A")
{
//int value = sensorBoard.readChannel(orden.toInt());
//int value = sensorBoard.readChannel(CHANNEL);
Serial.println(sensorBoard.readChannel(CHA4));


}
else if (comando=="424B")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readVoltage(CHA4));

}
else if (comando=="424C")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readCurrent(CHA4));

}
else if (comando=="424D")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.isConnected(CHA4));

}

else if (comando=="420A")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readChannel(orden.toInt()));

}


else if (comando=="420B")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readVoltage(orden.toInt()));

}

else if (comando=="420C")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.readCurrent(orden.toInt()));

}
else if (comando=="420D")
{

//float current = sensorBoard.readCurrent(CHANNEL);
Serial.println(sensorBoard.isConnected(orden.toInt()));

}






else{
Serial.println("COMANDO DESCONOCIDO");
}


readString="";
Serial.flush();


}

}


Top
 Profile  
 
 Post subject: Re: Conexión Arduino - Shield 4-20 mA
PostPosted: Fri Apr 06, 2018 10:24 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hola,

Ejecuta el ejemplo basico para leer la placa 4-20mA y copia aqui a salida

Code:
/*
 *  Explanation: This sketch shows how to use the most important
 *  features of the 4-20mA current loop board in Arduino. This
 *  standard is used to transmit information of sensor over long
 *  distances. Arduino uses analog inputs for reading the sensor
 *  values.
 *
 *  Copyright (C) 2014 Libelium Comunicaciones Distribuidas S.L.
 *  http://www.libelium.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version:          0.1
 *  Design:           David Gascon
 *  Implementation:   Ahmad Saad
 */

// Include this library for using current loop functions.
#include <currentLoop.h>

#define CHANNEL CHANNEL1

void setup()
{
 
  // Switch ON the 24V DC-DC converter
  sensorBoard.ON();

  // Inits the Serial for viewing data in the serial monitor
  Serial.begin(115200);
  delay(100);
  Serial.println("Arduino 4-20mA board switched ON...");
}


void loop()
{
  // Get the sensor value in int format (0-1023)
  int value = sensorBoard.readChannel(CHANNEL);
  Serial.print("Int value read from channel 1 : ");
  Serial.println(value);

  // Get the sensor value as a voltage in Volts
  float voltage = sensorBoard.readVoltage(CHANNEL);
  Serial.print("Voltage value rad from channel 1 : ");
  Serial.print(voltage);
  Serial.println("V");

  // Get the sensor value as a curren in mA
  float current = sensorBoard.readCurrent(CHANNEL);
  Serial.print("Current value read from channel 1 : ");
  Serial.print(current);
  Serial.println("mA");


  Serial.println("***************************************");
  Serial.print("\n");

  delay(2000);
}


Un saludo


Top
 Profile  
 
 Post subject: Re: Conexión Arduino - Shield 4-20 mA
PostPosted: Sat Apr 14, 2018 10:14 pm 

Joined: Tue Nov 04, 2014 11:03 pm
Posts: 8
Muchas gracias, ya hemos conseguido que funcione. Era un tema con el programa.


Top
 Profile  
 
 Post subject: Re: Conexión Arduino - Shield 4-20 mA
PostPosted: Mon Apr 16, 2018 10:08 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Nos alegra saber que solucionaste el problema :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.