hello friend can you guys help me i have problem with program what i want to achieve is display autonics tk4s temperature value to arduino ide serial monitor
here I use the following settings
the board I'm using is esp32, using the rs485 module,
then thermocontrol autonics tk4s,
where the settings are:
autonics baudrate = 9600
parity = none
data bits = 8
stop bit = 1
id autonics = 1
address autonics = 301001
when the program is successfully uploaded, it is unable to display the temperature value, where is my error,
I hope someone here can help, I would be very grateful for that,
below is the program I made:
//=============================================
#include "SimpleModbusMaster.h"
#define LED 2
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 15
enum
{
PACKET1,
//PACKET2,
// leave this last entry
TOTAL_NO_OF_PACKETS
};
// Create an array of Packets for modbus_update()
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
//packetPointer packet1 = &packets[PACKET2];
unsigned int temp[2]; // variabel temp dg jumlah register yang mau dibaca adalah 2
unsigned long timer;
float f_2uint_float(unsigned int uint1, unsigned int uint2) { //konversi integer ke float // reconstruct the float from 2 unsigned integers
union f_2uint {
float f;
uint16_t i[2];
};
union f_2uint f_number;
f_number.i[0] = uint1;
f_number.i[1] = uint2;
return f_number.f;
}
void setup()
{
Serial.begin(115200);
// read 3 registers starting at address 0
packet1->id = 1; //address id tk4s/slave nomor 1
packet1->function = READ_HOLDING_REGISTERS;
packet1->address = 301001; //manual di tk4s autonics //1001
packet1->no_of_registers = 1;
packet1->register_array = temp;
modbus_configure(baud, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
timer = millis();
}
void loop()
{
unsigned int connection_status = modbus_update(packets);
if (connection_status != TOTAL_NO_OF_PACKETS)
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
long newTimer = millis();
if(newTimer - timer >= 1000){
Serial.println();
Serial.print("Suhu : ");
// Serial.println(temp[0]);
// Serial.print("REGISTER 3028 : ");
// Serial.println(temp[1]);
Serial.println(temp[0]);
Serial.print("Suhu konversi int to float : ");
Serial.println(f_2uint_float(temp[1],temp[0]));
timer = newTimer;
}
}
//==========================================================
[ini adalah link library yang saya pakai]