Problem in rs485 connection between a temperature sensor and two arduinos

Hi guys
I'm not very good at English, sorry if I have typing problems
I ran into a problem in my project
I have an rs485 temperature module that I monitor the temperature with the following code, a default code from internet sites


#include <ModbusMaster.h>
#include <SoftwareSerial.h>

#define RE_PIN 4
#define DE_PIN 5

SoftwareSerial Serial2(9, 3); // RX, TX

ModbusMaster node;
void preTransmission() {
  digitalWrite(RE_PIN, 1);
  digitalWrite(DE_PIN, 1);
}

void postTransmission() {
  digitalWrite(RE_PIN, 0);
  digitalWrite(DE_PIN, 0);
}

void setup() {
  pinMode(RE_PIN, OUTPUT);
  pinMode(DE_PIN, OUTPUT);
  digitalWrite(RE_PIN, 0);
  digitalWrite(DE_PIN, 0);

  Serial1.begin(9600);
  Serial2.begin(9600);

  // Modbus slave ID 1
  node.begin(1, Serial2);
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop() {
    uint8_t result;
    uint16_t data;
  result = node.readInputRegisters(1,2);
  if (result == node.ku8MBSuccess) {
  
    Serial1.println("Data Requested Successfully");

   
    Serial1.print("Register 1: ");
    Serial1.println(node.getResponseBuffer(0));

    Serial1.print("Register 2: ");
    Serial1.println(node.getResponseBuffer(1));
    
 
  } else {
    Serial1.println("Error in Data Request");
  }
  delay(1000);
}

The problem is that
I want to send an int value with another arduino to the arduino master that reads the temperature
With rs485 module
I don't know how to do this

First question would be which board you're using with the given code. Seeing that you have Serial1, I guess it's e.g. a Micro or Leonardo.

What don't you know? How to send with the other Arduino or how to receive a second serial input with the current one?

Thank you for your time

master:nanoevery 4808
slave:nano 328p(old)
I have tested many codes, but I think that sending data fails

Please show the sending code.

Further, you're using Serial1 for communication with the other Arduino ad far as I understand your code. In which case you still have the USB available on the Every for debugging.

Serial port 1 is only for displaying my information and in Arduino every serial for printing should be serial 1
But in Nano I use serial
And the sending code, for example, the last code for the test is as shown below

#include <ModbusMaster.h>               //Library for using ModbusMaster
#include <SoftwareSerial.h>
SoftwareSerial Serial2(9, 3); // RX, TX
#define MAX485_DE      4
#define MAX485_RE_NEG  5

ModbusMaster node;                    //object node for class ModbusMaster

void preTransmission()            //Function for setting stste of Pins DE & RE of RS-485
{
  digitalWrite(MAX485_RE_NEG, 1);             
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
  Serial2.begin(9600);             
  Serial.setTimeout(50);
  node.begin(1, Serial2);           
  node.preTransmission(preTransmission);      
  node.postTransmission(postTransmission);
}

void loop()
{
  node.writeSingleRegister(1,123);        
  
}

Can you post a wiring diagram showing how everything is connected?

Are you using the boards package for the Thinary Nano Every, since you appear to have the third-party version of the board and not the official Nano Every with the atmega4809.
If you use MCUdude's MegaCoreX you will be able to use all three hardware serial ports on that board.

1 Like

Please draw a wiring diagram; it's getting confusing. Photo of hand drawn one is fine. It should at least contain all communication paths.

2 Likes

I am in the network rs485 I can send or receive data normally, but it cannot be modbus

I am using the PCB that I designed, but I can describe the pins that I connected as below
de---> D4
re--->D5
ro---->D9
di---->D3
All pins a Connected

All pins b Connected
And GND Common to all

I am not seeing enough wiring information to understand the situation or issue.

1 Like

I connected the pins as shown above to the rs485 module and Arduino nano every, of course I receive data from the module, but I can't receive information from the second Arduino, the two Arduinos are connected the same way

This post is no improvement from the previous wiring description. For the second Arduino, which pins are used and where do those wires connect elsewhere in the circuit. For a better explanation of the information necessary to understand your project and provide you with help instead of just questions, please refer to this article:

When we see the circuit diagram, we will be more helpful. Thank you for your understanding.

2 Likes

I think I see the problem but without an annotated schematic I will decline to take a SWAG. KiCad is a great CAD (Computer Aided Design) package that is so inexpensive it is free for the download. A donation is requested but not required.

1 Like

Is the 2nd Arduino connected to the RS485 bus, or are you attempting to connect the 2nd Arduino directly to the 1st Arduino on the same pins as the RS485 module?

1 Like

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