Using Modbus (RS485) storing sensor values

Hi everyone,

I am new to Arduino so just getting used to Arduino IDE and coding.

I have a little project and i need some help to code it, here is what i am trying to achieve:-

  • Connect a DS18B20 to a esp8266 and use as a Modbus slave

  • Using the Arduino Modbus library, store the value in to a register every 10 seconds
    so that the registers can be read by another device (not arduino or esp8266).

I have the code that allows me to read the data coming from the DS18B20 and i can see this on the serial monitor.

Can somebody help me with the code that writes the values into a register so that they can be read by a different device please.

I am happy to offer some money if the project works.

Best Regards

Steve

Start with this..

Modbus RTU Server Kitchen Sink

It demonstrates writing to input registers..
good luck.. ~q

Hi Q,

many thanks, i will take a look and see how i go.

Regards

Steve

Hi,

I am using a Dallas DS18B20 temperature sensor and have the output connected to pin 6 of my arduino uno. I want to read the value every 5 seconds, convert it into Celsius and then store it in register 0.

My Arduino needs to be configured as a slave so that it appears to be a Modbus device that any master can read.

I am trying to join together two sketches:-

1 - Modbus RTU Slave, Simple Modbus Slave example
2 - Onewire, DS18x20 Temperature

I don't know too much about Modbus so if there is anybody out there who can help i would be very much appreciated and willing to donate some funds for a successful sketch.

Best Regards

Steve

Jobs and Paid Consultancy
I think you should post it here
You can edit your post and add it into this category

Post your best effort. Read the forum guidelines to see how to properly post code and some good information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Describe what the code actually does. Describe how that is different from what you want.

If the code has compile errors, please post the entire text of the error message(s). Paraphrasing the errors leaves out important information.

I have a little project that i need help with.

I have an arduino mini (Slave) with a DS18B20 connected to pin 6. I also have a MAX RS485 converter connected to pin 10, 11 & 12.

I want to read the Sensor every 10 seconds and store the value into a register so that another modus master can read the registers.

The arduino reading the sensor will be the slave device.

I want to then be able to read the registers with another Master Modbus device.

Anybody interested in helping me with the code, there are many examples out there but I'm new to modbus so would appreciate some help.

Please message me only if you are interested in working with me.

Thanks

Steve

Post an annotated schematic (the language of electronics) of what you have and how you have wired it. You have not given enough information to determine if your project is doable as you want it.

You’ve started four topics on virtually the same subject and didn’t receive any help because you don’t seem to want to adhere to the forum guidelines. Do you really expect the results to be any different this time?

1 Like

probably look something like this..

/*

*/
#include <DS18B20.h>
#include <SoftwareSerial.h>
#include <ModbusRTUSlave.h>



const byte slave_Id = 1;
const unsigned long baud = 9600;
const unsigned int bufSize = 256;

//serial comm pins
const byte rxPin = 10;
const byte txPin = 11;
const byte dePin = 12
 const byte dsPin = 6;


byte buf[bufSize];
//registers
byte numInputs = 8;
word inputRegs[numInputs] = {0, 0, 0, 0, 0, 0, 0, 0};

unsigned long lastSample = 0;
int sampleDelay = 10000;

SoftwareSerial modSerial(rxPin, txPin);
ModbusRTUSlave modbus(modSerial, buf, bufSize, dePin);
DS18B20 ds(dsPin);
bool dsGood = false;

void setup() {

  while (!Serial) {
    delay(10);
  }
  Serial.begin(9600);
  Serial.println("Modbus RTU booting..");
  modSerial.begin(baud);
  modbus.begin(slave_Id, baud);
  modbus.configureInputRegisters(numInputs, inputRegRead);
  Serial.println("Modbus RTU Ready");
  if (ds.getNumberOfDevices() > 0) {
    dsGood = true;
    Serial.println("DS Online..");
  }
}

void loop() {
  modbus.poll();
  if (dsGood) {
    if (millis() - lastSample >= sampleDelay) {
      lastSample = millis();
      inputRegs[0] = ds.getTempF();
    }
  }
}


long inputRegRead(unsigned int address) {
  return inputRegs[address];
}


completely untested..

have fun.. ~q

Hi Q,

This is great, I will test over the next few days.

If you would like to help me finish it off then I will donate some money to you, I will either way because of your willingness to help.

I really appreciate your time and efforts.

Regards

Steve

not expected or required but if you feel compelled then please donate to Arduino.cc to keep this lovely place alive..
didn't notice this was in paid section, maybe someone will offer a proper solution..
otherwise of course, I will try to help if I can..
recommend you get a 485 adapter for your pc if you haven't already..
there's a test app in my git..
Modbus Test App
then you can use your pc to test..

Modbus stuff should fly, not sure of the sensor..
I did read through the lib to assemble what I wrote..

let me know how it goes..

~q

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.