hello guys hope you are doing well.
well am trying to read data from pH soil sensor using arduino uno and MAX485(MODBUS COMMUNICATION) hopefully it work and i can see the measure of the PH soil in serial monitor but it show me some weird characters and i want to eliminate it but i don't now how, please can anyone could help me.
//the code
#include <ModbusMaster.h>
#define MAX485_DE 3
#define MAX485_RE_NEG 2
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
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);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 9600 baud
Serial.begin(9600);
// Modbus slave ID
node.begin(6, Serial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop()
{
uint8_t result;
uint16_t data[8];
// Toggle the coil at address (Manual Load Control)
result = node.writeSingleCoil(0x03, state);
state = !state;
// Read 16 registers starting at 0x3100)
result = node.readInputRegisters(0x40000, 2);
if (result == node.ku8MBSuccess)
{
Serial.print("La valuer du PH: ");
Serial.println(node.getResponseBuffer(0x00)/10.0f,DEC);
}
delay(1000);
}
