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
@sticilface
sticilface / spram_allocator.h
Created March 21, 2019 16:28
custom PSRAM STL allocator
template <typename T>
class spram_allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
@sticilface
sticilface / modbus_MAX31865.ino
Last active July 19, 2019 09:01
Basic UNO sketch reading MAX31865 v2
//-----------------------------------------------------------------------------
// Copyright 2018 Thiago Alves
// This file is part of the OpenPLC Software Stack.
//
// OpenPLC is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenPLC is distributed in the hope that it will be useful,
@sticilface
sticilface / surrogate.ino
Created July 29, 2018 17:18
Working surrogate
/* This sketch lets a RemoteWorker device connected through Ethernet TCP act
as if it is present on the SoftwareBitBang bus connected to this Surrogate
device.
The RemoteWorker sketch can the run on a device not capable of SWBB but
with Ethernet support, like a PC or a Raspberry PI.
Surrogate and RemoteWorker examples contributed by Fred Larsen. */
#define PJON_PACKET_MAX_LENGTH 50
#define SERIAL_METHOD ThroughAsyncSerial // ThroughSerial or ThroughAsyncSerial
#define ROUTER_TYPE 2 // 1 = PJONVirtualBusRouter, 2 = segmented switch...
#define PJON_MAX_PACKETS 3
#define BUS_ID 253
#define PJON_BUS_PIN 2
#define PJON_INCLUDE_SWBB
#define PJON_INCLUDE_ANY
#define PJON_INCLUDE_TAS
#define USE_SERIAL
//#define USE_ACK
#define SERIAL_METHOD ThroughAsyncSerial // ThroughSerial or ThroughAsyncSerial
#define SERIAL_SPEED 115200
#define SWBB_PIN 2 // use 2 for arduino, 5 for ESP8266
#if defined (USE_SERIAL) && defined (ESP32)
#define SERIAL_PORT Serial2
@sticilface
sticilface / trans.ino
Last active July 29, 2018 17:13
Transmitter_speed_sketch
//#define USE_SERIAL
//#define USE_ACK
#define SERIAL_METHOD ThroughAsyncSerial // ThroughSerial or ThroughAsyncSerial
#define SERIAL_SPEED 115200
#define SWBB_PIN 2 // use 2 for arduino, 5 for ESP8266
#if defined (USE_SERIAL) && defined (ESP32)
#define SERIAL_PORT Serial2
#elif defined (USE_SERIAL)
#define SERIAL_METHOD ThroughSerial // ThroughSerial or ThroughAsyncSerial
#define PJON_MAX_PACKETS 3
#define PJON_BUS_PIN 2
#define PJON_INCLUDE_SWBB
#define PJON_INCLUDE_ANY
#define PJON_INCLUDE_TAS
#define PJON_INCLUDE_TS
@sticilface
sticilface / speedtests.md
Last active July 28, 2018 20:31
speed tests results PJON Serial

Speed Tests

ThroughSerial

Leonado to Leonado (115200 baud)

1 second communication speed test:
Packet Overhead: 10B - Total: 190B
Bandwidth: 570.00B/s

@sticilface
sticilface / servestaticrootfix.ino
Created November 26, 2015 18:03
Example sketch serving a static directory where / does not find /index.htm
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <FS.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>
const char* ssid = "xxx";
const char* password = "xxx";