Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

SensorModbusMaster

Home Forums Miscellaneous SensorModbusMaster

Viewing 3 reply threads
  • Author
    Posts
    • #17490
      Chuck Weaver
      Participant

        Hi, I am trying to  use the library SensorModbusMaster.  I have but some questions on the Git repository but have not received any answers.
        <p dir=”auto”>I want to pull floating point data and trying to figure this out.  My sensor simulator is set up for sensor address 1 and register 2 to send out floating point data on two registers, little endian. The debugging shows the response from the slave is right for decimal value 1000.5, reg 2 = 2000, reg 3 = 447A. But the answer from the function is “ovf” why am i not seeing 1000.5?  Any help is appreciated.</p>
        <p dir=”auto”>// —————————————————————————
        // Include the base required libraries
        // —————————————————————————
        #include <Arduino.h>
        #include <SensorModbusMaster.h></p>
        <p dir=”auto”>// —————————————————————————
        // Set up the sensor specific information
        // ie, pin locations, addresses, calibrations and related settings
        // —————————————————————————</p>
        <p dir=”auto”>// Define the sensor’s modbus address
        byte modbusAddress = 0x01; // The sensor’s modbus address, or SlaveID
        long modbusBaudRate = 9600; // The baud rate the sensor uses</p>
        <p dir=”auto”>// Define pin number variables
        const int sensorPwrPin = -1; // The pin sending power to the sensor
        const int adapterPwrPin = -1; // The pin sending power to the RS485 adapter
        const int DEREPin = -1; // The pin controlling Recieve Enable and Driver Enable
        // on the RS485 adapter, if applicable (else, -1)
        // Setting HIGH enables the driver (arduino) to send text
        // Setting LOW enables the receiver (sensor) to send text</p>
        <p dir=”auto”>// Construct software serial object for Modbus
        // This is just a assigning another name to the same port, for convienence
        // Unless it is unavailable, always prefer hardware serial.
        HardwareSerial* modbusSerial = &Serial1;</p>
        <p dir=”auto”>// Construct the modbus instance
        modbusMaster modbus;</p>
        <p dir=”auto”>// —————————————————————————
        // Main setup function
        // —————————————————————————
        void setup()
        {
        // Set various pins as needed
        if (DEREPin >= -1)
        {
        pinMode(DEREPin, OUTPUT);
        }
        if (sensorPwrPin >= 0)
        {
        pinMode(sensorPwrPin, OUTPUT);
        digitalWrite(sensorPwrPin, HIGH);
        }
        if (adapterPwrPin >= 0)
        {
        pinMode(adapterPwrPin, OUTPUT);
        digitalWrite(adapterPwrPin, HIGH);
        }</p>

        <div class=”snippet-clipboard-content notranslate position-relative overflow-auto”>

        </div>
        <p dir=”auto”>}</p>
        <p dir=”auto”>// —————————————————————————
        // Main setup function
        // —————————————————————————
        void loop()
        {
        // Get data values from read-only input registers (0x04)
        // Just for show, we will do the exact same thing 2 ways
        // All values will be read as bigEndian</p>

        <div class=”snippet-clipboard-content notranslate position-relative overflow-auto”>

        <div class=”zeroclipboard-container position-absolute right-0 top-0″></div>
        </div>
        <p dir=”auto”>} end main</p>
        Monitor output =
        <div>

        </div>
        <div>

        </div>
        <div>

        </div>

      • #17491
        Chuck Weaver
        Participant

          BTW I am using a teensy 4.1 module

        • #17492
          Chuck Weaver
          Participant

             

          • #17493
            Sara Damiano
            Moderator

              I also responded on GitHub (https://github.com/EnviroDIY/SensorModbusMaster/issues/25), but the endian-ness of your sensor simulator is not compatible. You simulator seems to be sending CDAB mixed-endian.  SensorModbusMaster only supports ABCD or DCBA.

          Viewing 3 reply threads
          • You must be logged in to reply to this topic.