Skip to content

Instantly share code, notes, and snippets.

@sticilface
sticilface / PROGMEM.md
Last active July 23, 2023 11:38
PROGMEM

Guide to PROGMEM on ESP8266 and Arduino IDE

Intro

On low memory devices like the arduino and esp8266 you do not want strings to be stored in RAM. This occurs by default on these systems. Declare a string const char * xyz = "this is a string" and it will use up RAM.

The solution on these devices is to allow strings to be stored in read only memory, in Arduino this is the PROGMEM macro. Most of my experience is with the ESP8266 which is a 32bit micros controller. This device stores PROGMEM data in flash. The macro PROGMEM on ESP8266 is simply

#define PROGMEM   ICACHE_RODATA_ATTR
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
const char* ssid = "xxx";
const char* password = "xxx";
void setup() {
Serial.begin(1000000);
/* Base temaplte for ESP8266 */
/* PlatformIO modifications: please search for "*.pioenvs" */
/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
PHDRS
{
dport0_0_phdr PT_LOAD;
sudo: false
language: bash
os:
- linux
env:
global:
- BUILD_FOLDER=$TRAVIS_BUILD_DIR/build.tmp
- SKETCH_LOCATION="$TRAVIS_BUILD_DIR"
#- LIBRARIES_LOCATION="-l $HOME/Arduino/libraries"
- BOARD_TYPE="-b generic"
root@test:/opt/Espressif/crosstool-NG # ./bootstrap && ./configure --prefix=`pwd` && make && make install
Running autoconf...
Done. You may now run:
./configure
checking build system type... x86_64-unknown-freebsd9.2
checking host system type... x86_64-unknown-freebsd9.2
checking for a BSD-compatible install... /usr/bin/install -c
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
@sticilface
sticilface / espmanagertemplate.cpp
Created May 14, 2016 17:50
templated version of espmanager
#pragma once
#include <functional>
class AsyncWebServer;
class ESP8266WebServer;
using namespace std::placeholders;
template <class RESPONSE, class HTTP >
#pragma once
class handler
{
public:
virtual ~handler() {
Serial.println("[handler] Deconstructor Called");
}
private:
@sticilface
sticilface / ESP_asyncJSON.ino
Last active January 26, 2016 13:05
demonstrates crash with large JSONs
/*
*
* Demonstrates crash using chuncked print and large Json
* Requires
* https://github.com/me-no-dev/ESPAsyncWebServer
* https://github.com/me-no-dev/ESPAsyncTCP
* https://github.com/bblanchon/ArduinoJson
*
* use curl to make request...
* http://ip/json -> Will make request and send results async... causes crash. Works if lines are removed from json.. see addJson function
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <FS.h>
File configFile;
bool config_read() {
DynamicJsonBuffer jsonBuffer;
@sticilface
sticilface / SPIFFSfile length issue
Last active November 27, 2015 11:02
demonstrates the file length issue
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>
const char* ssid = "xxx";
const char* password = "xxx";