Init fork from Stuart Robinson's repo
This commit is contained in:
@ -0,0 +1,72 @@
|
||||
// --------------------------------------
|
||||
// i2c_scanner
|
||||
// from: https://playground.arduino.cc/Main/I2cScanner/
|
||||
|
||||
// This sketch tests the standard 7-bit addresses
|
||||
// Devices with higher bit address might not be seen properly.
|
||||
|
||||
|
||||
#include <Wire.h>
|
||||
uint16_t counter;
|
||||
|
||||
#define SDA 21
|
||||
#define SCL 22
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(SDA, SCL); //format is Wire.begin(SDA,SCL);
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("I2C Scanner starting"));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t error, address;
|
||||
int16_t nDevices;
|
||||
|
||||
counter++;
|
||||
Serial.print(counter);
|
||||
Serial.println(F(" Scanning..."));
|
||||
|
||||
nDevices = 0;
|
||||
for (address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print(F("I2C device found at address 0x"));
|
||||
if (address < 16)
|
||||
Serial.print(F("0"));
|
||||
Serial.println(address, HEX);
|
||||
nDevices++;
|
||||
}
|
||||
else if (error == 4)
|
||||
{
|
||||
Serial.print(F("Unknown error at address 0x"));
|
||||
if (address < 16)
|
||||
Serial.print(F("0"));
|
||||
Serial.println(address, HEX);
|
||||
}
|
||||
}
|
||||
|
||||
if (nDevices == 0)
|
||||
{
|
||||
Serial.println(F("No I2C devices found"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println(F("Done"));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
||||
@ -0,0 +1,262 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 04/06/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - This test program has been written to check that a connected SD card adapter, Micro
|
||||
or standard, is functional.
|
||||
|
||||
When the program runs it will attempts to create a file that is next in sequence to Log0000.txt, thus
|
||||
if this is the first time the program has run on the SD card it will create file Log0001.txt. If the
|
||||
file Log0001.txt exists it will create Log0002.txt etc. This ensures that everytime the program starts
|
||||
it creates a new file for testing.
|
||||
|
||||
Next the program checks if the Logxxxx.txt file exists and if so attempts to delete it.
|
||||
|
||||
Then the program starts a loop. First the same file is again opened for append, it will be created if it
|
||||
does not exist and then the line '1 Hello World' is writtent to the file. The file is closed and the
|
||||
contents of the file are dumped to the serial monitor. The loop restarts, and this time the line
|
||||
'2 Hello World' is appended to the file.
|
||||
|
||||
As the program progresses the file will grow in size and after 4 iterrations of the open,write,close
|
||||
and dump loop the file dump on serial monitor will look like this
|
||||
|
||||
1 Hello World
|
||||
2 Hello World
|
||||
3 Hello World
|
||||
4 Hello World
|
||||
|
||||
This file dump will grow if you let the program run. If an error with the SD card is detected at any
|
||||
time the LED will rapid flash continuously and the message 'X Card failed, or not present' is printed
|
||||
to serial monitor. The number X will allow you to check the program listing for where the error occured.
|
||||
|
||||
1 Card failed = SD card did not initialise
|
||||
2 Card failed = Could nt setup logFile for new name
|
||||
3 Card failed = Could not open file for append
|
||||
4 Card failed = Failure to dump file to serial monitor
|
||||
|
||||
Note: At the time of writing, 04/06/20, the function that the dumpFile() routine uses to check if an SD
|
||||
card is still present, SD.exists(filename), does not work on the SD.h file included in the current Expressif
|
||||
core for Arduino. If the SD card is removed, the SD.exists(filename) function returns true so the following
|
||||
dump of the file locks up the ESP32.
|
||||
|
||||
Serial monitor baud rate is set at 9600
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
|
||||
//pin definitions. You also need to connect the card SCK to pin 18, MISO to pin 19 and MOSI to pin 23
|
||||
#define LED1 2 //pin number for LED
|
||||
#define SDCS 13 //pin number for device select on SD card module
|
||||
|
||||
File logFile;
|
||||
|
||||
char filename[] = "/LOG0000.TXT"; //filename used as base for creating logfile, 0000 replaced with numbers
|
||||
|
||||
uint16_t linecount;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("Initializing SD card");
|
||||
|
||||
if (!SD.begin(SDCS))
|
||||
{
|
||||
cardFail(1);
|
||||
}
|
||||
|
||||
Serial.println("Card initialized");
|
||||
|
||||
logFile = SD.open("/");
|
||||
Serial.println("Card directory");
|
||||
Serial.println();
|
||||
printDirectory(logFile, 0);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
if (!setupSDLOG(filename)) //setup logfile name for writing
|
||||
{
|
||||
cardFail(2);
|
||||
}
|
||||
|
||||
Serial.print(F("logFile name is "));
|
||||
Serial.println(filename);
|
||||
|
||||
if (SD.exists(filename))
|
||||
{
|
||||
Serial.print(filename);
|
||||
Serial.println(" exists - delete");
|
||||
SD.remove(filename);
|
||||
}
|
||||
|
||||
if (!SD.exists(filename))
|
||||
{
|
||||
Serial.print(filename);
|
||||
Serial.println(" does not exist");
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
logFile = SD.open(filename, FILE_APPEND);
|
||||
|
||||
if (!logFile)
|
||||
{
|
||||
cardFail(3);
|
||||
}
|
||||
|
||||
linecount++;
|
||||
logFile.print(linecount);
|
||||
logFile.println(" Hello World");
|
||||
logFile.close();
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Dump file ");
|
||||
Serial.println(filename);
|
||||
Serial.println();
|
||||
|
||||
digitalWrite(LED1, HIGH);
|
||||
|
||||
if (dumpFile(filename))
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println("Finished File Dump");
|
||||
}
|
||||
else
|
||||
{
|
||||
cardFail(4);
|
||||
}
|
||||
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printDirectory(File dir, int numTabs)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
||||
File entry = dir.openNextFile();
|
||||
if (! entry)
|
||||
{
|
||||
//no more files
|
||||
break;
|
||||
}
|
||||
for (uint8_t i = 0; i < numTabs; i++) {
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.print(entry.name());
|
||||
if (entry.isDirectory())
|
||||
{
|
||||
Serial.println("/");
|
||||
printDirectory(entry, numTabs + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
//files have sizes, directories do not
|
||||
Serial.print("\t\t");
|
||||
Serial.println(entry.size(), DEC);
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool dumpFile(char *buf)
|
||||
{
|
||||
//Note, this function will return true if the SD card is remove. See note at program start.
|
||||
if (SD.exists(buf))
|
||||
{
|
||||
Serial.print(buf);
|
||||
Serial.println(" found");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(filename);
|
||||
Serial.println(" not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
logFile = SD.open(buf);
|
||||
|
||||
if (logFile) //if the file is available, read from it
|
||||
{
|
||||
while (logFile.available())
|
||||
{
|
||||
Serial.write(logFile.read());
|
||||
}
|
||||
logFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t setupSDLOG(char *buf)
|
||||
{
|
||||
//creats a new filename
|
||||
|
||||
uint16_t index;
|
||||
|
||||
for (index = 1; index <= 9999; index++) {
|
||||
buf[4] = index / 1000 + '0';
|
||||
buf[5] = ((index % 1000) / 100) + '0';
|
||||
buf[6] = ((index % 100) / 10) + '0';
|
||||
buf[7] = index % 10 + '0' ;
|
||||
if (! SD.exists(filename)) {
|
||||
// only open a new file if it doesn't exist
|
||||
logFile = SD.open(buf, FILE_WRITE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!logFile)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return index; //return number of logfile created
|
||||
}
|
||||
|
||||
|
||||
void cardFail(uint8_t num)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
Serial.print(num); //so we can tell where card failed
|
||||
Serial.println(" Card failed, or not present");
|
||||
led_Flash(100, 25);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
led_Flash(4, 125);
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("43_SD_Card_Test_ESP32 Starting"));
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - This test program has been written to check that a connected SD card adapter, Micro
|
||||
or standard, is funtional with the FS functions. To use the program first copy the file (in this programs
|
||||
directory) called testfile.txt to the root directory of the SD card.
|
||||
|
||||
When the program runs it will attempt to open 'testfile.txt' and spool the contents to the Arduino IDE
|
||||
serial monitor. The testfile is part of the source code for the Apollo 11 Lunar Lander navigation and
|
||||
guidance computer. There are LED flashes at power up or reset, then at start of every loop of the test.
|
||||
The LED is on whilst the testfile is being read. If the LED flashes very rapidly then there is a problem
|
||||
accessing the SD card.
|
||||
|
||||
The program also has the option of using a logic pin to control the power to the lora and SD card
|
||||
devices, which can save power in sleep mode. If the hardware is fitted to your board these devices are
|
||||
powered on by setting the VCCPOWER pin low. If your board does not have this feature set VCCPOWER to -1.
|
||||
|
||||
Serial monitor baud rate is set at 9600
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
#include "SPI.h"
|
||||
|
||||
|
||||
#define SWITCH1 0 //pin number to attach switch
|
||||
#define LED1 2 //pin number for LED
|
||||
#define SDCS 13 //ESP32 pin number for device select on SD card module
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(F("LED Flash"));
|
||||
Serial.println();
|
||||
led_Flash(2, 50);
|
||||
readFile(SD, "/testfile.txt");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void readFile(fs::FS &fs, const char * path) {
|
||||
Serial.printf("Reading file: %s\n", path);
|
||||
|
||||
File file = fs.open(path);
|
||||
if (!file) {
|
||||
Serial.println();
|
||||
Serial.println("Failed to open file for reading");
|
||||
Serial.println();
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Read from file: ");
|
||||
digitalWrite(LED1, HIGH);
|
||||
while (file.available()) {
|
||||
Serial.write(file.read());
|
||||
}
|
||||
file.close();
|
||||
digitalWrite(LED1, LOW);
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
led_Flash(4, 125);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println(F("44_SD_Card_Test_With_FS_ESP32 Starting"));
|
||||
Serial.print("Initializing SD card...");
|
||||
|
||||
if (!SD.begin(SDCS)) {
|
||||
Serial.println("Card failed, or not present.");
|
||||
led_Flash(100, 25);
|
||||
return; //loop if no card found
|
||||
}
|
||||
|
||||
Serial.println("Card initialized.");
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,104 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - This test program has been written to check that hardware for reading the battery
|
||||
voltage has been assembled correctly such that it is funtional. The value defined as 'ADMultiplier'
|
||||
in settings.h is used to adjust the value read from the 91K\11K resistor divider and convert into mV.
|
||||
|
||||
There is also an option of using a logic pin to turn the resistor divider used to read battery voltage
|
||||
on and off. This reduces current used in sleep mode. To use the feature set the define for pin BATVREADON
|
||||
in 'Settings.h' to the pin used. If not using the feature set the pin number to -1.
|
||||
|
||||
Serial monitor baud rate is set at 9600
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
#define ADMultiplier 10.872 //adjustment to convert AD value read into mV of battery voltage
|
||||
#define BATVREADON 25 //used to turn on the resistor divider to measure voltage //this pin turns on the MOSFET that switches in the resistor divider
|
||||
#define LED1 2 //pin for PCB LED
|
||||
#define SupplyAD 36 //Resitor divider for battery connected here
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(F("LED Flash"));
|
||||
led_Flash(4, 125);
|
||||
printSupplyVoltage();
|
||||
Serial.println();
|
||||
delay(1500);
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(uint16_t flashes, uint16_t delaymS)
|
||||
{
|
||||
uint16_t index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printSupplyVoltage()
|
||||
{
|
||||
//get and display supply volts on terminal or monitor
|
||||
Serial.print(F("Supply Volts "));
|
||||
Serial.print(readSupplyVoltage());
|
||||
Serial.println(F("mV"));
|
||||
}
|
||||
|
||||
|
||||
uint16_t readSupplyVoltage()
|
||||
{
|
||||
//ESP32 uses the 3.3V VCC as reference
|
||||
|
||||
uint16_t temp;
|
||||
uint16_t volts = 0;
|
||||
byte index;
|
||||
|
||||
if (BATVREADON >= 0)
|
||||
{
|
||||
digitalWrite(BATVREADON, HIGH); //turn on MOSFET connecting resitor divider in circuit
|
||||
}
|
||||
|
||||
temp = analogRead(SupplyAD);
|
||||
|
||||
for (index = 0; index <= 4; index++) //sample AD 5 times
|
||||
{
|
||||
temp = analogRead(SupplyAD);
|
||||
volts = volts + temp;
|
||||
}
|
||||
volts = ((volts / 5) * ADMultiplier);
|
||||
|
||||
if (BATVREADON >= 0)
|
||||
{
|
||||
digitalWrite(BATVREADON, LOW); //turn off MOSFET connecting resitor divider in circuit
|
||||
}
|
||||
|
||||
return volts;
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //setup Serial console ouput
|
||||
Serial.println("45_Battery_Voltage_Read_Test_ESP32 Starting");
|
||||
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
|
||||
if (BATVREADON >= 0)
|
||||
{
|
||||
pinMode(BATVREADON, OUTPUT); //controls MOSFET connecting resitor divider in circuit
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 20/02/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - The program flashes a LED connected to the pin defined by LED1, and puts the ESP32
|
||||
to deep_sleep for a period determined by the TIME_TO_SLEEP variable (in seconds).
|
||||
|
||||
The program also has the option of using a logic pin to control the power to the lora and SD card
|
||||
devices, which can save power in sleep mode. If the hardware is fitted to your board these devices are
|
||||
powered on by setting the VCCPOWER pin low. If your board does not have this feature set VCCPOWER to -1.
|
||||
|
||||
Current in deep_sleep for a bare bones ESP32 with regulator and no other devices was 27uA.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define LED1 2 //pin number for LED
|
||||
#define VCCPOWER 14 //pin may control power to external devices, -1 if not used
|
||||
|
||||
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
|
||||
#define TIME_TO_SLEEP 15 //Time ESP32 will go to sleep (in seconds)
|
||||
|
||||
RTC_DATA_ATTR int32_t bootCount = 0;
|
||||
RTC_DATA_ATTR uint32_t sleepcount = 0;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(F("Bootcount "));
|
||||
Serial.println(bootCount);
|
||||
Serial.print(F("Sleepcount "));
|
||||
Serial.println(sleepcount);
|
||||
Serial.println(F("LED Flash"));
|
||||
led_Flash(4, 125);
|
||||
Serial.println(F("LED On"));
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(2500);
|
||||
Serial.println(F("LED Off"));
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||
Serial.println(F("Start Sleep"));
|
||||
Serial.flush();
|
||||
sleepcount++;
|
||||
esp_deep_sleep_start();
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("Awake !"));
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
//flash LED to show tracker is alive
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //setup Serial console ouput
|
||||
Serial.println(F("47_DeepSleep_Timed_Wakeup_ESP32 - Starting"));
|
||||
|
||||
if (bootCount == 0) //Run this only the first time
|
||||
{
|
||||
bootCount = bootCount + 1;
|
||||
}
|
||||
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
|
||||
if (VCCPOWER >= 0)
|
||||
{
|
||||
pinMode(VCCPOWER, OUTPUT);
|
||||
digitalWrite(VCCPOWER, HIGH); //VCCOUT off
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 03/02/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
/*
|
||||
|
||||
****************************************************************************************************************
|
||||
Program operation - The program flashes a LED connected to the pin defined by LED1, and puts the ESP32 to
|
||||
light_sleep for a period determined by TIME_TO_SLEEP (in seconds).
|
||||
|
||||
The program also has the option of using a logic pin to control the power to the lora.SD card and DS18B20
|
||||
devices, which can save power in sleep mode. If the hardware is fitted to your board these devices are
|
||||
powered on by setting the VCCPOWER pin low. If your board does not have this feature set VCCPOWER to -1.
|
||||
|
||||
Current in light_sleep mode was 1500uA
|
||||
****************************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#define VCCPOWER 14 //when low supplies VCC power to external devices. Set to -1 if not used
|
||||
#define LED1 2 //On board LED, high for on
|
||||
|
||||
|
||||
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
|
||||
#define TIME_TO_SLEEP 15 //Time ESP32 will go to sleep (in seconds)
|
||||
|
||||
RTC_DATA_ATTR int16_t bootCount = 0;
|
||||
RTC_DATA_ATTR uint16_t sleepcount = 0;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(F("Bootcount "));
|
||||
Serial.println(bootCount);
|
||||
Serial.print(F("Sleepcount "));
|
||||
Serial.println(sleepcount);
|
||||
Serial.println(F("LED Flash"));
|
||||
led_Flash(4, 125);
|
||||
Serial.println(F("LED On"));
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(2500);
|
||||
Serial.println(F("LED Off"));
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||
Serial.println(F("Start Sleep"));
|
||||
Serial.flush();
|
||||
sleepcount++;
|
||||
esp_light_sleep_start();
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("Awake !"));
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
//flash LED to show tracker is alive
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //setup Serial console ouput
|
||||
Serial.println(F("50_LightSleep_Timed_Wakeup_ESP32 - Starting"));
|
||||
|
||||
if (bootCount == 0) //Run this only the first time
|
||||
{
|
||||
bootCount = bootCount + 1;
|
||||
}
|
||||
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
|
||||
if (VCCPOWER >= 0)
|
||||
{
|
||||
pinMode(VCCPOWER, OUTPUT); //For controlling power to external devices
|
||||
digitalWrite(VCCPOWER, HIGH); //VCCOUT off, lora device and SD card off
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 20/02/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - The program flashes a LED connected to the pin defined by LED1, and puts the ESP32
|
||||
to deep_sleep. Pressing BOOT switch should wake up the ESP32 from sleep.
|
||||
|
||||
Only the specific RTC IO pins can be used as a source for external wakeup.
|
||||
These are pins: 0,2,4,12-15,25-27,32-39.
|
||||
|
||||
Current in deep_sleep for a bare bones ESP32 with regulator and no other devices was 27uA.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define LED1 2 //pin number for LED
|
||||
#define SWITCH1 0 //pin number wakeup switch
|
||||
|
||||
|
||||
RTC_DATA_ATTR int16_t bootCount = 0;
|
||||
RTC_DATA_ATTR uint16_t sleepcount = 0;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(F("Bootcount "));
|
||||
Serial.println(bootCount);
|
||||
Serial.print(F("Sleepcount "));
|
||||
Serial.println(sleepcount);
|
||||
Serial.println(F("LED Flash"));
|
||||
led_Flash(4, 125);
|
||||
Serial.println(F("LED On"));
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(2500);
|
||||
Serial.println(F("LED Off"));
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
//esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, 0); //wakeup on pin GPIO0 going low
|
||||
|
||||
Serial.println(F("Start Sleep"));
|
||||
Serial.flush();
|
||||
sleepcount++;
|
||||
esp_deep_sleep_start();
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("Awake ?")); //should not really see this, deep sleep wakeup causes reset ....
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
//flash LED to show tracker is alive
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //setup Serial console ouput
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("51_DeepSleep_Timed_Wakeup_ESP32 - Starting"));
|
||||
|
||||
if (bootCount == 0) //Run this only the first time
|
||||
{
|
||||
bootCount = bootCount + 1;
|
||||
}
|
||||
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
pinMode(SWITCH1, INPUT_PULLUP); //for wakeup switch
|
||||
|
||||
}
|
||||
@ -0,0 +1,131 @@
|
||||
/*******************************************************************************************************
|
||||
lora Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - When the ESP32 turns on the WiFi function, there is a short high current pulse that
|
||||
can cause the ESP32 brownout detect to operate.
|
||||
|
||||
This test program at startup flashes an LED, leaves it on and then starts the WiFi. If the Wifi initiates
|
||||
a brownout, you will see the LED flash again. The LED stays on when scanning, the program reports the
|
||||
networks found to the serial console and displays them on an attached SSD1306 OLED.
|
||||
|
||||
Thus if you see the LED continually doing short bursts of flashing the turn on\off the WiFi is causing
|
||||
the ESP32 to reset. There will also be a message on the serial monitor that the brownout detector operated.
|
||||
|
||||
Serial monitor baud rate is set at 9600
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include "WiFi.h"
|
||||
#define LED1 2 //Arduino pin number for LED, when high LED should be on.
|
||||
|
||||
#include <U8x8lib.h> //get library here > https://github.com/olikraus/u8g2
|
||||
//U8X8_SSD1306_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE); //use this line for standard 0.96" SSD1306
|
||||
U8X8_SH1106_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE); //use this line for 1.3" OLED often sold as 1.3" SSD1306
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Set WiFi to Station mode"); //Set WiFi to station mode
|
||||
Serial.flush();
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Setup done");
|
||||
Serial.flush();
|
||||
|
||||
digitalWrite(LED1, HIGH);
|
||||
Serial.println("WiFi scan start");
|
||||
Serial.flush();
|
||||
int n = WiFi.scanNetworks(); //WiFi.scanNetworks will return the number of networks found
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(500);
|
||||
disp.clear();
|
||||
disp.setCursor(0, 0);
|
||||
|
||||
if (n == 0) {
|
||||
Serial.println("No WiFi");
|
||||
disp.println("No WiFi");
|
||||
} else {
|
||||
Serial.print(n);
|
||||
disp.print(n);
|
||||
Serial.println(" WiFi found");
|
||||
disp.println(" WiFi found");
|
||||
led_Flash(n, 500);
|
||||
|
||||
if (n > 16) //only want to display first 16 networks
|
||||
{
|
||||
n = 16;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
//Print SSID and RSSI for each network found
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(WiFi.SSID(i));
|
||||
|
||||
if (i > 7)
|
||||
{ disp.clearLine(i - 8);
|
||||
disp.setCursor(0, i - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
disp.clearLine(i);
|
||||
disp.setCursor(0, i);
|
||||
}
|
||||
|
||||
disp.print(WiFi.SSID(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||
if (i == 7) //check if 8 lines have already been sent to display
|
||||
{
|
||||
delay(2000); //leave last 8 on display for a while
|
||||
disp.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
disp.println();
|
||||
|
||||
|
||||
// Wait a bit before scanning again
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
//flash LED
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
led_Flash(5, 50);
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(1000);
|
||||
Serial.begin(9600);
|
||||
|
||||
disp.begin();
|
||||
disp.setFont(u8x8_font_chroma48medium8_r);
|
||||
disp.clear();
|
||||
disp.setCursor(0, 0);
|
||||
disp.print(F("Scanner Ready"));
|
||||
}
|
||||
Reference in New Issue
Block a user