While uploading a file in arduino uno a problem occur if file size exceeds 6kb the warning logs appears
tells "that a memory is too low" is there a problem with ram or anything else do we need to make any
HEX File or do we need to make a seperate INO file for every function that we write in code.
Too vague.
Post the code, post the error message.
It's not the code size. It's the amount of RAM that you use. As AWOL says, post your code (using code tags).
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
#define DEBUG true
SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
display.clearDisplay();
delay(5000);
Serial.begin(9600);
esp8266.begin(9600); // your esp's baud rate might be different
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
pinMode(12,OUTPUT);
digitalWrite(12,LOW);
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,LOW);
sendCommand("AT+RST\r\n",2000,DEBUG); // reset module
sendCommand("AT+CWMODE=1\r\n",2000,DEBUG); // configure as access point
sendCommand("AT+CWJAP=\"RAJAHOME\",\"rama2869\"\r\n",3000,DEBUG);
delay(10000);
sendCommand("AT+CIFSR\r\n",3000,DEBUG); // get ip address
sendCommand("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
sendCommand("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
Serial.println("Server Ready");
}
void loop()
{
if(esp8266.available()) // check if the esp is sending a message
{
if(esp8266.find("+IPD,"))
{
delay(1000); // wait for the serial buffer to fill up (read all the serial data)
// get the connection id so that we can then disconnect
int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
// the ASCII decimal value and 0 (the first decimal number) starts at 48
esp8266.find("pin="); // advance cursor to "pin="
int pinNumber = (esp8266.read()-48); // get first number i.e. if the pin 13 then the 1st number is 1
int secondNumber = (esp8266.read()-48);
if(secondNumber>=0 && secondNumber<=9)
{
pinNumber*=10;
pinNumber +=secondNumber; // get second number, i.e. if the pin number is 13 then the 2nd number is 3, then add to the first number
}
digitalWrite(pinNumber, !digitalRead(pinNumber)); // toggle pin
// build string that is send back to device that is requesting pin toggle
String content;
content = "Pin ";
content += pinNumber;
content += " is ";
if(digitalRead(pinNumber))
{
content += "ON";
}
else
{
content += "OFF";
}
sendHTTPResponse(connectionId,content);
// make close command
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId; // append connection id
closeCommand+="\r\n";
sendCommand(closeCommand,1000,DEBUG); // close connection
}
}
}
/*
* Name: sendData
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
int dataSize = command.length();
char data[dataSize];
command.toCharArray(data,dataSize);
esp8266.write(data,dataSize); // send the read character to the esp8266
if(debug)
{
Serial.println("\r\n====== HTTP Response From Arduino ======");
Serial.write(data,dataSize);
Serial.println("\r\n========================================");
}
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
/*
* Name: sendHTTPResponse
* Description: Function that sends HTTP 200, HTML UTF-8 response
*/
void sendHTTPResponse(int connectionId, String content)
{
// build HTTP response
String httpResponse;
String httpHeader;
// HTTP Header
httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n";
httpHeader += "Content-Length: ";
httpHeader += content.length();
httpHeader += "\r\n";
httpHeader +="Connection: close\r\n\r\n";
httpResponse = httpHeader + content + " "; // There is a bug in this code: the last character of "content" is not sent, I cheated by adding this extra space
sendCIPData(connectionId,httpResponse);
}
/*
* Name: sendCIPDATA
* Description: sends a CIPSEND=<connectionId>,<data> command
*
*/
void sendCIPData(int connectionId, String data)
{
String cipSend = "AT+CIPSEND=";
cipSend += connectionId;
cipSend += ",";
cipSend +=data.length();
cipSend +="\r\n";
sendCommand(cipSend,1000,DEBUG);
sendData(data,1000,DEBUG);
}
/*
* Name: sendCommand
* Description: Function used to send data to ESP8266.
* Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
* Returns: The response from the esp8266 (if there is a reponse)
*/
String sendCommand(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response+=c;
}
}
if(debug)
{
delay(2000);
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print(response);
display.display();
// Clear the buffer.
display.clearDisplay();;
}
return response;
}
These is the code for our project after uploading these we get certain warning lke these
Sketch uses 17,640 bytes (54%) of program storage space. Maximum is 32,256 bytes.
Global variables use 2,017 bytes (98%) of dynamic memory, leaving 31 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur.
Our ESP8266 doesn't response to our commands and OLED also blinks and doesn't response
simply it hangs due to shortage of SRAM AND EEPROM of Arduino UNO
These problem may proceed further because we are using 12 DC MOTORS and One Gyroscopic sensor
these are requires coding and in ONE FILE it may take 300 to 400 lines of code at that time also we will suffer with the same problem
Please Suggest What can we do i these Situation....
Serial.println("\r\n====== HTTP Response From Arduino ======");
Serial.write(data,dataSize);
Serial.println("\r\n========================================");
Utter waste of RAM.
Use
Serial.println(F("\r\n====== HTTP Response From Arduino ======"));
Serial.write(data,dataSize);
Serial.println(F("\r\n========================================"));
etc, etc.
These code that you have given is Okk but what if we want to add 12 DC Motor and Gyroscopic sensor for these also we require some lines of Code. DO we need To make a hex Files for these
Can u explain me How to make a hex file from these code
Can u explain me How to make a hex file from these code
The compiler will make "hex file" for you.
can we make seperate .ino files for DC motors, esp8266,gyroscopic sensors. because SRAM of Arduino Uno is of 2kb
Arun645:
These code that you have given is Okk but what if we want to add 12 DC Motor and Gyroscopic sensor for these also we require some lines of Code. DO we need To make a hex Files for these
Can u explain me How to make a hex file from these code
Just put all of the code in one *.ino file, then as AWOL says, the compiler will generate the hex file.
Part of your problem is that the strings are using up too much RAM. Placing code in various files will not make a difference to RAM usage.
Another thing that's using a lot of RAM is the 'String' class. C strings, (char arrays), aren't as heavy on resources as the 'String' class.
Edit: Start by doing as suggested and storing string literals in program memory using the F() macro.
Yes, you can create as many programs as you like.
But it won't increase the amount of available RAM.
You need to rewrite the code you have to get rid of all the Strings, and make better use of flash memory.
is there is any replacement of String Class because we need these Class to send AT commands to esp8266
we need these Class to send AT commands to esp8266
No, you don't.
People have been using C strings for decades before the String class.
Arun645:
is there is any replacement of String Class because we need these Class to send AT commands to esp8266
Is that so? From your code:-
char data[dataSize];
command.toCharArray(data,dataSize);
esp8266.write(data,dataSize); // send the read character to the esp8266
char c = esp8266.read(); // read the next character.
Do some reading on C strings, as opposed to 'String'.
(As AWOL just said, you don't need the String class.)
thanx for the reply it helped me alot
httpHeader = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n";
httpHeader += "Content-Length: ";
httpHeader += content.length();
httpHeader += "\r\n";
httpHeader +="Connection: close\r\n\r\n";
httpResponse = httpHeader + content + " "; // There is a bug in this code: the last character of "content" is not sent, I cheated by adding this extra space
Do you know how much SRAM the above code is going to use? I don't know about the string content. The rest is about 100 bytes long. But the above code uses 200 bytes of memory instead. You need to use C-string.
can we use PROGMEM keyword to store the string in flash memory rather than SRAM by including the header
file
#include <avr/pgmspace.h>
Arun645:
can we use PROGMEM keyword to store the string in flash memory rather than SRAM by including the header
file
#include <avr/pgmspace.h>
Given that you've got five minutes between posts, wouldn't it be quicker to try it?
Hi,
What is your application that uses 12 motors, and stability sensors,
Is it a duodecacopter?
We need to know your application so we can help you rationalise your code and hardware.
Thanks.. Tom.. ![]()
If you don't use graphics on display, I strongly suggest to replace the Adafruit library with the new U8g2 library (can be downloaded by library manager in arduino ide), and use the U8x8 text only mode, in this way you will free half of the 2K ram (since 1024 bytes are used by the adafruit framebuffer).
Ciao, Ale.