Temperature read out PTA8D08

Hi my name is Merel,I am working on my graduation project and now I am stocked :frowning:

I bought PTA8D08 and a arduino UNO and a RS485/TTL (Dollatec) converter. This is how I connected the wires:

  • external power supply to the PTA8D08 ground and VIN
  • PTA8D08 A+ B- to RS485 A and B respectively
  • RS485 VCC and GND to Arduino 5V and GND
  • RS485 DI to Arduino pin RX
  • RS485 DE to Arduino pin 2
  • RS485 RE to Arduino pin 4
  • RS485 R0 to Arduino pinTX

I tried with ChatGPT to generate the code. It uses the library ModbusMaster.h but it gives an 'error reading data!'
Can anybody help me with the code.

This is the code I now have:

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

#define DE_PIN 2 // Pin voor Driver Enable op RS485-converter
#define RE_PIN 4 // Pin voor Receiver Enable op RS485-converter
#define RS485_BAUD_RATE 9600 // Baudrate van RS485-communicatie
#define PTA8D08_ADDRESS 1 // Adres van de PTA8D08-sensor op het RS485-netwerk

SoftwareSerial rs485Serial(2, 4); // RX, TX

// Create a ModbusMaster object
ModbusMaster node;

void setup() {
  Serial.begin(9600); // Begin seriële communicatie met de computer
  rs485Serial.begin(RS485_BAUD_RATE); // Begin seriële communicatie met RS485-converter
  pinMode(DE_PIN, OUTPUT); // DE_PIN instellen als uitgang
  pinMode(RE_PIN, OUTPUT); // RE_PIN instellen als uitgang
  
  // Initialize Modbus communication
  node.begin(PTA8D08_ADDRESS, rs485Serial); // Modbus-adres van de sensor is 1, RS485-communicatie
}

void loop() {
  // Wissel naar de transmissiemodus (TX)
  digitalWrite(DE_PIN, HIGH);
  digitalWrite(RE_PIN, HIGH);

  // Stuur verzoek om temperatuurgegevens naar PTA8D08-sensor
  uint8_t result = node.readHoldingRegisters(0, 1); // Commando om temperatuur te lezen (verander dit naar het juiste commando)

  // Check if the request was successful
  if (result == node.ku8MBSuccess) {
    // Wissel naar ontvangsmodus (RX)
    digitalWrite(DE_PIN, LOW);
    digitalWrite(RE_PIN, LOW);

    // Lees temperatuurgegevens van de sensor
    float temperatureCelsius = node.getResponseBuffer(0); // Assuming temperature is in the first register

    // Print de temperatuur naar de seriële monitor
    Serial.print("Temperatuur: ");
    Serial.print(temperatureCelsius);
    Serial.println(" °C");
  } else {
    Serial.println("Error reading data!");
  }

  // Wacht voordat je opnieuw verzoekt naar temperatuurgegevens
  delay(5000); // Wacht 5 seconden voordat je opnieuw gegevens aanvraagt
} 

You used the same pins for DE and RX and RE and TX

Set the RX pin to 5 and the TX pin to 6: rs485Serial(5, 6); // RX, TX

Connect RO to RX (pin5) and DI to TX (pin6)

I connected it like you said, and changed line nine to:
SoftwareSerial rs485Serial(5, 6); // RX, TX

However, it still gives the same error: "Error reading data!"

Print out result so we can see what the error code was.

Also, you need to connect the RS485 converter ground to the PTA8D08 ground if not already connected.

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