switch to esp32
This commit is contained in:
parent
a7e2023470
commit
5be0ac009b
|
@ -8,6 +8,25 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32]
|
||||
platform = platformio/espressif32@^6.7
|
||||
board = esp32-s3-devkitm-1
|
||||
;Devboard is ESP32-S3-DevKitC-1 (N16R8). board=esp32-s3-devkitm-1 works fine
|
||||
framework = arduino
|
||||
|
||||
|
||||
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel@^1.12.3
|
||||
|
||||
|
||||
build_flags =
|
||||
-D PIXELPIN=4
|
||||
-D NUMPIXELS=600
|
||||
|
||||
[env:d1_mini]
|
||||
platform = espressif8266
|
||||
board = d1_mini
|
||||
|
@ -16,6 +35,10 @@ framework = arduino
|
|||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
|
||||
build_flags =
|
||||
-D PIXELPIN=D4
|
||||
-D PIN_LDR=A0
|
||||
-D NUMPIXELS=600
|
||||
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel @ ^1.7.0
|
||||
|
@ -37,3 +60,6 @@ lib_deps =
|
|||
|
||||
upload_flags =
|
||||
--auth=ROLLERCOASTER
|
||||
-D PIXELPIN=D4
|
||||
-D PIN_LDR=A0
|
||||
-D NUMPIXELS=600
|
||||
|
|
92
src/main.cpp
92
src/main.cpp
|
@ -1,7 +1,5 @@
|
|||
//flash as Wemos D1 R2 & mini
|
||||
|
||||
#include <Arduino.h>
|
||||
//#include "simpleota.h"
|
||||
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifdef __AVR__
|
||||
|
@ -34,12 +32,15 @@ uint32_t Wheel(byte WheelPos);
|
|||
void loadHeightmapRaw();
|
||||
void saveHeightmapRaw();
|
||||
|
||||
#define PIN_LDR A0 //comment if not used
|
||||
|
||||
#define PIN D4
|
||||
#define NUMPIXELS 600
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
#ifdef PIN_NEOPIXEL
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
Adafruit_NeoPixel statuspixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||
#endif
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
long lastPixelUpdate=0;
|
||||
#define PIXELUPDATETIME 20
|
||||
|
@ -112,6 +113,34 @@ void setup() {
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(NEOPIXEL_POWER)
|
||||
// If this board has a power control pin, we must set it to output and high
|
||||
// in order to enable the NeoPixels. We put this in an #if defined so it can
|
||||
// be reused for other boards without compilation errors
|
||||
pinMode(NEOPIXEL_POWER, OUTPUT);
|
||||
digitalWrite(NEOPIXEL_POWER, HIGH);
|
||||
#endif
|
||||
#ifdef PIN_NEOPIXEL
|
||||
statuspixel.begin();
|
||||
statuspixel.setBrightness(100); // not so bright
|
||||
statuspixel.clear();
|
||||
|
||||
//Flash colors for debug
|
||||
statuspixel.setPixelColor(0, statuspixel.Color(255, 0,0));
|
||||
statuspixel.show();
|
||||
delay(250);
|
||||
statuspixel.setPixelColor(0, statuspixel.Color(0, 255,0));
|
||||
statuspixel.show();
|
||||
delay(250);
|
||||
statuspixel.setPixelColor(0, statuspixel.Color(0, 0,255));
|
||||
statuspixel.show();
|
||||
delay(250);
|
||||
statuspixel.clear();
|
||||
statuspixel.show();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
EEPROM.begin(4096); //set eeprom size, between 4 and 4096 bytes.
|
||||
|
||||
|
||||
|
@ -121,15 +150,6 @@ void setup() {
|
|||
strip.show(); // Initialize all pixels to 'off'
|
||||
|
||||
|
||||
/*checkOTA();
|
||||
|
||||
if(initOTA()) { //initialize ota if ota enabled
|
||||
Serial.println("OTA Initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
//server.begin();
|
||||
*/
|
||||
|
||||
Serial.println("Started");
|
||||
|
||||
|
@ -327,47 +347,7 @@ void spawnWagon(float pos, float wagonlength,float startvel, float startacc, flo
|
|||
|
||||
void loop() {
|
||||
|
||||
//ota deactivated because of problems with exceptions/reboots. also maybe problems with eeprom and ota.
|
||||
/*
|
||||
if (loopOTA()) {
|
||||
#ifndef OTA_CONTINUOUS
|
||||
return; //just wait for ota
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if (state_server==0)
|
||||
{
|
||||
client = server.available();
|
||||
|
||||
if (client) {
|
||||
if(client.connected())
|
||||
{
|
||||
Serial.println("Client Connected");
|
||||
state_server=1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (state_server==1) {
|
||||
if(client.connected()){
|
||||
while(client.available()>0){
|
||||
// read data from the connected client
|
||||
Serial.write(client.read());
|
||||
}
|
||||
//Send Data to connected client
|
||||
while(Serial.available()>0)
|
||||
{
|
||||
client.write(Serial.read());
|
||||
}
|
||||
}else{
|
||||
client.stop();
|
||||
Serial.println("Client disconnected");
|
||||
state_server=0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
loopmillis=millis();
|
||||
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
#include "simpleota.h"
|
||||
|
||||
|
||||
uint16_t otaWaitCounter;
|
||||
|
||||
|
||||
OTA_MODE otaMode;
|
||||
|
||||
void checkOTA() {
|
||||
otaMode = SEARCHING;
|
||||
Serial.println("looking for OTA WiFi...");
|
||||
|
||||
// WARNING: to allow ESP-NOW work, this WiFi must be on Channel 1
|
||||
if (OTA_WIFI_PASSWORD!="") {
|
||||
WiFi.begin(OTA_WIFI_SSID, OTA_WIFI_PASSWORD); //wifi with password
|
||||
}else{
|
||||
WiFi.begin(OTA_WIFI_SSID); //open wifi
|
||||
}
|
||||
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("no OTA WiFi found, proceed normal boot");
|
||||
otaMode = NONE;
|
||||
WiFi.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
otaMode = WAITING;
|
||||
}
|
||||
|
||||
|
||||
bool initOTA() {
|
||||
if (otaMode == WAITING) {
|
||||
Serial.println("connected to OTA WiFi. Waiting for firmware...");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
ArduinoOTA.setPassword((const char *)OTA_PASSWORD);
|
||||
|
||||
ArduinoOTA.onStart([]() {
|
||||
otaMode = UPDATING;
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
|
||||
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
Serial.println("Start updating " + type);
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
Serial.println("\nEnd");
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
int prog = (progress / (total / 100));
|
||||
Serial.printf("Progress: %u%%\r", prog);
|
||||
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
return 1; //ota ok
|
||||
}else{
|
||||
return 0; //not using ota
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool loopOTA() {
|
||||
if (otaMode != NONE) {
|
||||
ArduinoOTA.handle();
|
||||
|
||||
|
||||
if(otaMode == WAITING) {
|
||||
static long mil = millis();
|
||||
static boolean huehott = false;
|
||||
|
||||
|
||||
if(millis() - mil > 100) {
|
||||
huehott = !huehott;
|
||||
mil = millis();
|
||||
|
||||
otaWaitCounter++;
|
||||
if(otaWaitCounter >= OTA_WAIT_TIMEOUT) {
|
||||
Serial.println("OTA wait timeout, proceeding normal boot");
|
||||
otaMode = NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef simpleota_h
|
||||
#define simpleota_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
|
||||
#define OTA_WIFI_SSID ""
|
||||
#define OTA_WIFI_PASSWORD ""
|
||||
#define OTA_WAIT_TIMEOUT 50 // in 0.1s increments -> 10s
|
||||
#define OTA_PASSWORD "ROLLERCOASTER" //password needed for ota flashing
|
||||
|
||||
//#define OTA_CONTINUOUS
|
||||
|
||||
|
||||
void checkOTA();
|
||||
bool initOTA();
|
||||
bool loopOTA();
|
||||
|
||||
enum OTA_MODE {
|
||||
NONE,
|
||||
SEARCHING,
|
||||
WAITING,
|
||||
UPDATING
|
||||
};
|
||||
|
||||
extern OTA_MODE otaMode;
|
||||
|
||||
extern uint16_t otaWaitCounter;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue