#include <SimpleModbusMaster.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
SoftwareSerial mySerial(10, 11); // RX, TX
SimpleTimer timer;
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
// If the packets internal retry register matches
// the set retry count then communication is stopped
// on that packet. To re-enable the packet you must
// set the "connection" variable to true.
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2
#define LED 9
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
PACKET1,
PACKET2,
PACKET3,
PACKET4,
PACKET5,
PACKET6,
PACKET7,
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
packetPointer packet1 = &packets[PACKET1];
packetPointer packet2 = &packets[PACKET2];
packetPointer packet3 = &packets[PACKET3];
packetPointer packet4 = &packets[PACKET4];
packetPointer packet5 = &packets[PACKET5];
packetPointer packet6 = &packets[PACKET6];
packetPointer packet7 = &packets[PACKET7];
// Data read from the arduino slave will be stored in this array
// if the array is initialized to the packet.
unsigned int cont=0;
unsigned int control=2050;
unsigned int readRegs[2];
unsigned int readRegs1[1];
unsigned int readRegs2[6];
unsigned int AV1[5];
unsigned int AV2[5];
unsigned int AV3[5];
unsigned int VFloat[2];
void setup()
{
mySerial.begin(9600);
timer.setInterval(2000, RepeatTask);
modbus_construct(packet1, 17, READ_HOLDING_REGISTERS, 0x130, 2, readRegs);
modbus_construct(packet2, 17, READ_HOLDING_REGISTERS, 0x400, 1, readRegs1);
modbus_construct(packet3, 17, READ_HOLDING_REGISTERS, 0x184, 6, readRegs2);
modbus_construct(packet4, 17, READ_HOLDING_REGISTERS, 0x406, 5, AV1);
modbus_construct(packet5, 17, READ_HOLDING_REGISTERS, 0x40B, 5, AV2);
modbus_construct(packet6, 17, READ_HOLDING_REGISTERS, 0x410, 5, AV3);
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
}
void loop()
{
modbus_update();
timer.run();
}
void RepeatTask() {
//fecha
mySerial.print(int(readRegs2[0]));mySerial.print("/"); //año
mySerial.print(int(readRegs2[1]));mySerial.print("/"); //mes
mySerial.print(int(readRegs2[2]));mySerial.print(" "); //dia
mySerial.print(int(readRegs2[3]));mySerial.print(":"); //hora
mySerial.print(int(readRegs2[4]));mySerial.print(":"); //minuto
mySerial.println(int(readRegs2[5]));
//mySerial.println(int(readRegs2[6])); //semana
mySerial.print("F=");
mySerial.print(float(readRegs[0])/100);
mySerial.print(" ");
mySerial.print("V1=");
mySerial.println(float(readRegs[1])/10);
mySerial.print("THD1=");
mySerial.print(float(readRegs1[0])/100);
mySerial.println(" ");
mySerial.println("Contenido Armonico Voltage");
mySerial.print("% V2=");mySerial.print(float(AV1[0])/100);
mySerial.print(" % V3=");mySerial.print(float(AV1[1])/100);
mySerial.print(" % V4=");mySerial.print(float(AV1[2])/100);
mySerial.print(" % V5=");mySerial.print(float(AV1[3])/100);
mySerial.print(" % V6=");mySerial.println(float(AV1[4])/100);
mySerial.print("% V7=");mySerial.print(float(AV2[0])/100);
mySerial.print(" % V8=");mySerial.print(float(AV2[1])/100);
mySerial.print(" % V9=");mySerial.print(float(AV2[2])/100);
mySerial.print(" % V10=");mySerial.print(float(AV2[3])/100);
mySerial.print(" % V11=");mySerial.println(float(AV2[4])/100);
mySerial.print("% V12=");mySerial.print(float(AV3[0])/100);
mySerial.print(" % V13=");mySerial.print(float(AV3[1])/100);
mySerial.print(" % V14=");mySerial.print(float(AV3[2])/100);
mySerial.print(" % V15=");mySerial.print(float(AV3[3])/100);
mySerial.print(" % V16=");mySerial.println(float(AV3[4])/100);
}
this code is not working with arduino uno please can you share the working code .
it is showing the error "invalid conversion from "unsigned int* " to "unsigned int* " [-fparmissive]