Problem Modbus Comunication Between Waspmote and Computer

Everything about programming the platform and using the Waspmote API
Post Reply
Chenao
Posts: 20
Joined: Tue Mar 28, 2017 4:49 pm

Problem Modbus Comunication Between Waspmote and Computer

Post by Chenao » Wed Aug 21, 2019 5:45 pm

Hi!

At the moment, I'm working with Waspomote board, trying to do to work the Modbus bus with my computer. I use the next code for Waspomote Board:

Code: Select all

/*
    ------ [RS-485_10] Modbus Slave ACC and Battery level --------

    This sketch shows the use of the Modbus communication protocol over
    RS-485 standard, and the use of the main functions of the library.
  . Modbus allows for communication between many devices connected
    to the same network. There are many variants of Modbus protocols,
    but Waspmote implements the RTU format. Modbus RTU is the most
    common implementation available for Modbus.

    This example shows how to configure the Waspmote as a Modbus
    slave  device. The Waspmote stores the ACC values and the battery
    level in  the Modbus register, and sends these values to the
    Master when  a request is received.

    Note: See the example RS-485_11_modbus_master_acc_battery_level

    Copyright (C) 2017 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:          3.1
    Implementation:   Ahmad Saad
*/

// Include these libraries for using the RS-485 and Modbus functions
#include <ModbusSlave.h>
#include <WaspSensorXtr.h>
#include <Wasp485.h>

// Modbus slave ID and baudrate
//////////////////////////////////////////
const uint8_t slave_id = 1;
const uint32_t baud = 19200;
//////////////////////////////////////////

// Create new mbs instance
ModbusSlave mbs(RS485_COM);


// Slave registers
enum {
  MB_0 = 0,   // Register 0
  MB_1 = 1,   // Register 1
};

// number of registers
#define MB_REGS 2

// define array
int regs[MB_REGS];

uint8_t answer;

//******************************************************
//          SELECT THE RIGHT SOCKET & SENSOR
//******************************************************

/* 
  Possible sockets are:
  - XTR_SOCKET_A
  - XTR_SOCKET_B
  - XTR_SOCKET_C
  - XTR_SOCKET_D

  Example: a CTZN sensor on socket A
  Aqualabo_CTZN mySensor(XTR_SOCKET_A);

*/
Aqualabo_OPTOD mySensor(XTR_SOCKET_B);


void setup()
{
  // Power on the USB
  USB.ON();
  USB.println(F("Modbus Slave example over RS-485"));
  USB.println(F("-----------------------------------------------"));
  USB.println(F("Waspmote simulates a sensor device"));
  USB.println(F("which returns acceleration and battery"));
  USB.println(F("level via Modbus over RS-485"));
  USB.println(F("-----------------------------------------------"));

  // Power on the ACC
  ACC.ON();

  // Configure msb
  answer = mbs.configure(slave_id, baud);

  if (answer == 0)
  {
    USB.println(F("RS-485 module started successfully"));
    USB.println(F("\n\n-----------------------------------------------"));
    USB.println(F("Waspmote will continuously update the "));
    USB.println(F("library structures so a master device can read them"));
    USB.println(F("Please refer to the example RS485_11"));
    USB.println(F("-----------------------------------------------"));
  }
  else
  {
    USB.println(F("RS-485 did not initialize correctly"));
  }
}

void loop()
{
  // 1. Turn ON the sensor
  mySensor.ON();
  // Read and store the values in the Modbus registers
  // 2. Read the sensor
  /*
    Note: read() function does not directly return sensor values.
    They are stored in the class vector variables defined for that purpose.
    Values are available as a float value */
 
  mySensor.read();
  //regs[MB_0] = mySensor.sensorOPTOD.temperature;
  //regs[MB_1] = mySensor.sensorOPTOD.oxygenPPM;

  regs[MB_0] = 1;
  regs[MB_1] = 7;
  USB.println(regs[MB_0]);
  
  //regs[MB_0] = ACC.getX();  // X Value
  //regs[MB_1] = ACC.getY();  // Y Value
  //regs[MB_2] = ACC.getZ();  // Z Value
  //regs[MB_3] = PWR.getBatteryLevel(); // Battery level

  // Update current register values to mbs
  mbs.update(regs, MB_REGS);
  mySensor.OFF();
  delay(1000);

}
On the my computer side I use MbPoll software to create an link RS485 between my computer and Waspomote, the configurations are the next.

Image

The electrical conections are the next

Image

When I run the code Waspmote I obtain the next

Image

Apparently it works, but I don't have response on MbPoll Software. I clarify that on the side on computer I use a USB/RS485 converter.

Image

I don't have idea the problem. I'm thankful for any kind of help to put work the Modbuss bus.

Regards!

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

Re: Problem Modbus Comunication Between Waspmote and Computer

Post by libelium-dev » Thu Aug 22, 2019 7:21 am

Hi,

Which USB/485 converter are you using?

Which model of P&S! do you have? Please share with us an image of the sticker at the backside of the node.

Regards

Chenao
Posts: 20
Joined: Tue Mar 28, 2017 4:49 pm

Re: Problem Modbus Comunication Between Waspmote and Computer

Post by Chenao » Fri Aug 23, 2019 5:04 am

Hi!

Thanks for your reply. Ok I use the next USB/485 converter.

Image

The main features can be consulted in:

https://articulo.mercadolibre.com.co/MC ... quantity=1

Now share with you image of the node libelium that I'm using

Image

Image

I'm attentive. Regards!

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

Re: Problem Modbus Comunication Between Waspmote and Computer

Post by libelium-dev » Fri Aug 23, 2019 8:54 am

Hi,

Could you please share with us an image of the full assembly? We want some details to know how did you connect the cables.

We have seen that some converters have issues to work with our module but your converter seems ok. Did you try with another software? Some time ago we tested using QModMaster software and it worked fine.

Regards

Chenao
Posts: 20
Joined: Tue Mar 28, 2017 4:49 pm

Re: Problem Modbus Comunication Between Waspmote and Computer

Post by Chenao » Wed Aug 28, 2019 3:22 am

Hi,


My apologies for answering late. I share an image of the full assembly:

Image

I tested using QModMaste software, but it did not work, I share an image

Image


Thanks for the support.

Regards!

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

Re: Problem Modbus Comunication Between Waspmote and Computer

Post by libelium-dev » Wed Aug 28, 2019 8:54 am

Hi,

The connection is correct.

Could you please test uploading the example code to create a Modbus slave? So we will make sure there isn't any bug in the code.
http://www.libelium.com/development/was ... ery-level/

Make sure that you configure in the software slave address 1 and baud 9600.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest