Hi all, in this code I'm trying to upload this code below and whenever uploading the code in Arduino IDE, error compiling for board Arduino Uno. That's because the sketch is too big. I don't know how to reduce the sketch. Please help me. The error message is: Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno
In file included from C:\Users\user\Documents\Arduino\libraries\UIPEthernet\utility\mempool.cpp:22:0:
C:\Users\user\Documents\Arduino\libraries\UIPEthernet\utility\logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp] #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
^~~~~~~
text section exceeds available space in boardSketch uses 34772 bytes (107%) of program storage space. Maximum is 32256 bytes.
Global variables use 2512 bytes (122%) of dynamic memory, leaving -464 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
Error compiling for board Arduino Uno.
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
#include <UIPEthernet.h>
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE8 };
byte mac[] = {0x00, 0x01, 0x02, 0x03,0x04, 0x05};
IPAddress ip(192,168,11,13);
//Ethernet.begin(mac); //Configure IP address via DHCP
EthernetClient client;
ModbusTCPClient modbusTCPClient(client);
IPAddress server(192,168,11,3);
void setup() {
Serial.begin(19200);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address :
Ethernet.begin(mac, ip);
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.print("connecting to ");
Serial.print(server);
Serial.println("...");
// if you get a connection, report back via serial:
if (client.connect(server, 502)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println("Modbus TCP Client Toggle");
Ethernet.begin(mac, ip);
delay(1000);
float P_DC;
}
void loop() {
long regStatus[10];
long regRaw[10];
long ID,I_DC,I_AC,V_DC,V_AC,P_DC,P_AC,F_Hz;
String readString;
long Address;
if (!modbusTCPClient.connected()) {
// client not connected, start the Modbus TCP client
Serial.println("Attempting to connect to Modbus TCP server");
if (!modbusTCPClient.begin(server)) {
Serial.println("Modbus TCP Client failed to connect!");
} else {
Serial.println("Modbus TCP Client connected");
}
} else {
while (Serial.available()) {
delay(2);
char c = Serial.read();
readString += c;
}
if (readString.length() > 0) {
Serial.println(readString);
Address = atol(readString.c_str());
Serial.println(Address);
}
ID = modbusTCPClient.holdingRegisterRead(40070);
Serial.print("ID = ");
Serial.println(ID);
F_Hz= modbusTCPClient.holdingRegisterRead(40086) /100;
Serial.print("F_Hz = ");
Serial.println(F_Hz);
I_DC = modbusTCPClient.holdingRegisterRead(40097) /10;
Serial.print("I_DC = ");
Serial.println(I_DC);
I_AC = modbusTCPClient.holdingRegisterRead(40072) /10;
Serial.print("I_AC = ");
Serial.println(I_AC);
V_DC = modbusTCPClient.holdingRegisterRead(41124) /10;
Serial.print("V_DC = ");
Serial.println(V_DC);
V_AC = modbusTCPClient.holdingRegisterRead(40080) /10;
Serial.print("V_AC = ");
Serial.println(V_AC);
float ar = (float)modbusTCPClient.holdingRegisterRead(40101)/1000;
Serial.println(ar);
Serial.print("P_DC = ");
Serial.println(P_DC);
P_AC = modbusTCPClient.holdingRegisterRead(40084) /10;
Serial.print("P_AC = ");
Serial.println(P_AC);
delay(1000);
}
}
use the EthernetENC library. if you use a fixed IP address you can turn off UDP with UIP_CONF_UDP set to 0 and save 4 kB of flash. you can tune the parameters of the library.
The error message is: Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno
In file included from C:\Users\user\Documents\Arduino\libraries\UIPEthernet\utility\mempool.cpp:22:0:
C:\Users\user\Documents\Arduino\libraries\UIPEthernet\utility\logging.h:24:2: warning: #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage." [-Wcpp] #warning "You can configure LogObject and ACTLOGLEVEL in 'utility/logging.h'. More verbosity more memory usage."
^~~~~~~
text section exceeds available space in boardSketch uses 34772 bytes (107%) of program storage space. Maximum is 32256 bytes.
Global variables use 2512 bytes (122%) of dynamic memory, leaving -464 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
Error compiling for board Arduino Uno.
You've run out of program space (the "text section") and RAM (the "dynamic memory").
Follow the suggestion by @Juraj in #4 to reduce the amount of program space. That might leave you enough room to put the constant text strings into FLASH (aka program space) using my suggestion in #3.
Report back the complier results again if your code still won't fit. And upload your latest code as well.
I'm still struggling with error compiling even though defining UIP_CONF_UDP 0 in utility/uipethernet-conf.h header file. The error message is: C:\Users\User\AppData\Local\Temp\ccylDivv.ltrans0.ltrans.o: In function setup': C:\Users\User\Desktop\nn\modbus_ok1/modbus_ok1.ino:17: undefined reference to UIPEthernetClass::begin(unsigned char const*)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.
begin(mac) uses DHCP to get the IP address. DHCP uses UDP. so begin(mac) is not available if you turn off UDP.
I wrote that you must use a static IP address with begin(mac, ip)
and you didn't switch to EthernetENC? you still use UIPEthernet?
Hello, I have tried to reduce flash memory using UIP_CONF_UDP 0 in ethernetENC header file.
Now Im trying to use 90 or 91% of dynamic memory.
After I upload the code below that message comes out: Sketch uses 25708 bytes (79%) of program storage space. Maximum is 32256 bytes.
Global variables use 1987 bytes (97%) of dynamic memory, leaving 61 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.
Help me to reduce more memory on Arduino UNO
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
#include <EthernetENC.h>
byte mac[] = {0x28, 0x16, 0xAD, 0x89,0x96, 0x49};
IPAddress ip(192,168,0,111);
EthernetClient client;
ModbusTCPClient modbusTCPClient(client);
IPAddress server(192,168, 0, 129);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
delay(1000);
Serial.print(server);
if (client.connect(server, 502)) {
Serial.print("connected to ");
Serial.println(client.remoteIP());
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
Serial.println("Modbus TCP Client Toggle");
Ethernet.begin(mac, ip);
delay(1000);
}
void loop() {
int ID;
String readString;
long Address;
if (!modbusTCPClient.connected()) {
//client not connected, start the Modbus TCP client
Serial.println("Attempting to connect to Modbus TCP server");
if (!modbusTCPClient.begin(server)) {
Serial.println("Modbus TCP Client failed to connect!");
} else {
Serial.println("Modbus TCP Client connected");
}
} else {
while (Serial.available()) {
delay(2);
char c = Serial.read();
readString += c;
}
if (readString.length() > 0) {
Serial.println(readString);
Address = atol(readString.c_str());
Serial.println(Address);
}
ID = modbusTCPClient.holdingRegisterRead(40070);
// Serial.print("ID = ");
Serial.println(ID);
//F_Hz= modbusTCPClient.holdingRegisterRead(40086)/100;
// Serial.print("F_Hz = ");
//Serial.println(F_Hz);
//I_DC = modbusTCPClient.holdingRegisterRead(40097)/10;
//Serial.print("I_DC = ");
//Serial.println(I_DC);
// V_AC = modbusTCPClient.holdingRegisterRead(40080) /10;
//Serial.print("V_AC = ");
//Serial.println(V_AC);
delay(1000);
}
}
Unrelated to the code size problem, are you sure the calls to holdingRegisterRead are corrrect? That function takes an int as an argument, which has a maximum value of 32767 on an UNO.