Created
May 4, 2018 12:48
-
-
Save CelliesProjects/de29de6d9135b3449f5b56336f74d5e2 to your computer and use it in GitHub Desktop.
A poc of the ledc pwm flicker caused by accessing the SD card.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* UPLOAD curl -F data=@'filename' IPADDRESS/upload | |
* UPLOAD: curl -F data=@'/home/cellie/Moon.zip' 192.168.0.194/upload | |
*/ | |
#include <SPI.h> /* should be installed together with ESP32 Arduino install */ | |
#include <FS.h> /* should be installed together with ESP32 Arduino install */ | |
#include <SD.h> /* should be installed together with ESP32 Arduino install */ | |
#include <SPIFFS.h> | |
#include <AsyncTCP.h> /* https://github.com/me-no-dev/ESPAsyncTCP */ | |
#include <ESPAsyncWebServer.h> /* https://github.com/me-no-dev/ESPAsyncWebServer */ | |
/************************************************************************** | |
SPI pin definitions | |
**************************************************************************/ | |
#define SPI_TFT_DC_PIN 27 /* Goes to TFT DC */ | |
#define SPI_SCK_PIN 25 /* Goes to TFT SCK/CLK */ | |
#define SPI_MOSI_PIN 32 /* Goes to TFT MOSI */ | |
#define SPI_TFT_RST_PIN 12 /* Goes to TFT RESET */ | |
#define SPI_TFT_CS_PIN 4 /* Goes to TFT CS */ | |
#define SPI_SD_CS_PIN 0 /* Goes to SD CS */ | |
#define SPI_MISO_PIN 39 /* Goes to TFT MISO */ | |
#define TOUCH_CS_PIN 33 /* Goes to TFT T_CS */ | |
#define TOUCH_IRQ_PIN 35 /* Goes to TFT T_IRQ */ | |
/* 3.3v Goes to TFT Vcc */ | |
/* Gnd Goes to TFT Gnd */ | |
/************************************************************************** | |
TFT display backlight control | |
**************************************************************************/ | |
#define TFT_BACKLIGHT_PIN 2 | |
const char* textHtmlHeader = "text/html"; | |
AsyncWebServer server(80); | |
int channel = 0; | |
int freq = 1300; | |
int numberOfBits = 16; | |
void setup() { | |
WiFi.begin(); | |
while( !WiFi.isConnected() ) | |
{ | |
delay(100); | |
} | |
ESP_LOGI( TAG, "WiFi connected to: %s %s", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str() ); | |
ledcAttachPin( TFT_BACKLIGHT_PIN, channel ); | |
ledcSetup( channel, freq, numberOfBits ); | |
SPI.begin( SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN ); | |
if (!SD.begin( SPI_SD_CS_PIN )) | |
{ | |
ESP_LOGE( TAG, "SD Card Mount Failed" ); | |
} | |
server.on( "/", HTTP_GET, [] ( AsyncWebServerRequest * request ) | |
{ | |
request->send( 200, textHtmlHeader, "Use curl -F data=@'filename' IPADDRESS/upload to upload" ); | |
}); | |
server.serveStatic( "/", SD, "/" ); | |
server.onNotFound( []( AsyncWebServerRequest * request ) | |
{ | |
ESP_LOGI( TAG, "NOT FOUND: http://%s%s\n", request->host().c_str(), request->url().c_str()); | |
request->send( 404 ); | |
}); | |
server.on( "/upload", HTTP_POST, []( AsyncWebServerRequest * request ) | |
{ | |
return request->send(200); | |
}, | |
[]( AsyncWebServerRequest * request, String filename, size_t index, uint8_t *data, size_t len, bool final ) | |
{ | |
static time_t startTimer; | |
if ( !index ) | |
{ | |
startTimer = millis(); | |
if ( !filename.startsWith( "/" ) ) | |
{ | |
filename = "/" + filename; | |
} | |
ESP_LOGI( TAG, "Starting upload. filename = %s\n", filename.c_str() ); | |
SD.remove( filename ); | |
request->_tempFile = SD.open( filename, "w" ); | |
} | |
if ( request->_tempFile && len ) | |
{ | |
request->_tempFile.write( data, len ); | |
} | |
if ( final ) | |
{ | |
if ( request->_tempFile ) | |
{ | |
request->_tempFile.close(); | |
} | |
ESP_LOGI( TAG, "Upload %iBytes in %.2fs which is %.2ikB/s.\n", index, ( millis() - startTimer ) / 1000.0, index / ( millis() - startTimer ) ); | |
} | |
}); | |
server.begin(); | |
ESP_LOGI( TAG, "HTTP server started." ); | |
} | |
int currentDuty = 0; | |
void loop() { | |
ledcWrite( channel, currentDuty ); | |
currentDuty++; | |
if ( currentDuty > ( 0x00000001 << numberOfBits ) - 1 ) | |
{ | |
currentDuty = 0; | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment