first commit

This commit is contained in:
2021-05-11 20:43:42 +03:00
commit 9f3ffaba30
381 changed files with 69596 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
// --------------------------------------
// 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;
void setup()
{
Wire.begin();
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
}

View File

@@ -0,0 +1,86 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 20/12/19
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 program is a simple test program for the SSD1306 and SH1106 OLEDs. The program
prints a short message on each line, pauses, clears the screen, and starts again.
OLED address is defined as 0x3C.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#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
#define DEFAULTFONT u8x8_font_chroma48medium8_r //font for U8X8 Library
#define OLED_Address 0x3C
uint16_t writecount;
uint32_t startwritemS, endwritemS, timemS;
void loop()
{
writecount++;
Serial.print(writecount);
Serial.print(F(" Writing to display"));
disp.setI2CAddress(OLED_Address<<1); //I2C address multiplied by 2, the lowest bit must be zero
disp.setFont(DEFAULTFONT);
startwritemS = millis();
disp.clear();
screen1();
endwritemS = millis();
timemS = endwritemS - startwritemS;
disp.setCursor(8, 4);
disp.print(timemS);
disp.print(F("mS"));
Serial.print(F(" - done"));
Serial.print(timemS);
Serial.println(F("mS"));
delay(2000);
Serial.println(F("PowerSave display"));
disp.setPowerSave(1); //power save display, turns off
delay(2000);
disp.setPowerSave(0); //display back to normal
}
void screen1()
{
disp.setCursor(0, 0);
disp.print(F("Hello World !"));
disp.setCursor(0, 1);
disp.print(F("Line 1"));
disp.setCursor(0, 2);
disp.print(F("Line 2"));
disp.setCursor(0, 3);
disp.print(F("Line 3"));
disp.setCursor(0, 4);
disp.print(F("Line 4"));
disp.setCursor(0, 5);
disp.print(F("Line 5"));
disp.setCursor(0, 6);
disp.print(F("Line 6"));
disp.setCursor(0, 7);
disp.print(F("0123456789012345")); //display is 8 lines x 16 charaters when using the
//u8x8_font_chroma48medium8_r font
}
void setup()
{
Serial.begin(9600);
Serial.println(F("31_SSD1306_SH1106_OLED_Checker_ESP32 starting"));
disp.begin();
}

View File

@@ -0,0 +1,272 @@
/*******************************************************************************************************
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
*******************************************************************************************************/
#define Program_Version "V1.1"
#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();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("43_SD_Card_Test Starting"));
}

View File

@@ -0,0 +1,110 @@
/*******************************************************************************************************
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
*******************************************************************************************************/
#define Program_Version "V1.0"
#include "ESP32_LoRa_Micro_Node.h"
#include "FS.h"
#include "SD.h"
#include "SPI.h"
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);
if (VCCPOWER >= 0)
{
pinMode(VCCPOWER, OUTPUT); //For controlling power to external devices
digitalWrite(VCCPOWER, LOW); //VCCOUT on. lora device on
}
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
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.");
}

View File

@@ -0,0 +1,21 @@
/*******************************************************************************************************
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.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of the Tracker boards, the ESP32_Micro_Node, be sure to change
//them to match your own setup. You will also need to connect up the pins for the SPI bus, which on the
//ESP32_Micro_Node are SCK on pin 13, MISO on pin 19 and MOSI on pin 23. Some pins such as DIO1, DIO2 and
//BUZZER may not be in used by this sketch so they do not need to be connected and should be set to -1.
#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
#define VCCPOWER 14 //pin controls power to external devices, such as the SD card

View File

@@ -0,0 +1,111 @@
/*******************************************************************************************************
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();
Serial.println(__FILE__);
Serial.print(F("Compiled "));
Serial.print(__TIME__);
Serial.print(F(" "));
Serial.println(__DATE__);
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
}
}

View File

@@ -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
}
}

View File

@@ -0,0 +1,92 @@
/*******************************************************************************************************
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
}
}

View File

@@ -0,0 +1,87 @@
/*******************************************************************************************************
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
}

View File

@@ -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"));
}

View File

@@ -0,0 +1,35 @@
/*******************************************************************************************************
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.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of the Tracker boards, the ESP32_Micro_Node, be sure to change
//them to match your own setup. You will also need to connect up the pins for the SPI bus, which on the
//ESP32_Micro_Node are SCK on pin 18, MISO on pin 19 and MOSI on pin 23. Some pins such as DIO1, DIO2 and
//BUZZER may not be in used by this sketch so they do not need to be connected and should be set to -1.
#define SWITCH1 0 //pin number for switch, the boot switch also
#define LED1 2 //pin number for LED
#define NSS 5 //pin number where the NSS line for the LoRa device is connected
#define SDCS 13 //ESP32 pin number for device select on SD card module
#define VCCPOWER 14 //pin controls power to external devices
#define DIO2 15 //pin number for DIO2 pin on LoRa device
#define TonePin 15 //pin number for LoRa radio tone generation, connects to LoRa device pin DIO2
#define GPSTX 16 //pin number for TX output from Arduino - RX into GPS
#define GPSRX 17 //pin number for RX input into Arduino - TX from GPS
#define BATREAD 25 //pin that switches on supply measure resistor devider
#define GPSPOWER 26 //pin controls power to external devices
#define NRESET 27 //pin where LoRa device reset line is connected
#define ONEWIREBUS 33 //pin for one wire bus devices
#define DIO1 34 //pin connected to DIO1 on LoRa device
#define DIO0 35 //pin number for DIO0 pin on LoRa device
#define SupplyAD 36 //pin for reading supply voltage
#define ADMultiplier 10 //multiplier for supply volts calculation, default

View File

@@ -0,0 +1,125 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 27/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 is a simple test for a Bosch BME280 sensor. Readings are sent to the serial
monitor.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <Seeed_BME280.h> //get library here; https://github.com/Seeed-Studio/Grove_BME280
BME280 bme280; //create an instance of the BME280 senosor
#define BME280_ADDRESS 0x76 //I2C bus address of BME280
#define BME280_REGISTER_CONTROL 0xF4 //BME280 register number for power control
#include <Wire.h>
#define LED1 2 //on board LED, high for on
float temperature; //the BME280 temperature value
float pressure; //the BME280 pressure value
uint16_t humidity; //the BME280 humididty value
void loop()
{
Serial.print(F("Reading > "));
readSensors(); //read the sensor values
printSensorValues(); //print the sensor values
Serial.println();
sleepBME280();
delay(5000);
normalBME280(); //BME280 sensor to normal mode
}
void readSensors()
{
//read the sensor values into the global variables
temperature = bme280.getTemperature();
pressure = bme280.getPressure();
humidity = bme280.getHumidity();
}
void printSensorValues()
{
Serial.print(F("Temperature,"));
Serial.print(temperature, 1);
Serial.print(F("c,Pressure,"));
Serial.print(pressure, 0);
Serial.print(F("Pa,Humidity,"));
Serial.print(humidity);
Serial.print(F("%"));
Serial.print(F(" "));
Serial.flush();
}
void sleepBME280()
{
//write this register value to BME280 to put it to sleep
writeBME280reg(BME280_REGISTER_CONTROL, B01111100);
}
void normalBME280()
{
//write this register value to BME280 to put it to read mode
writeBME280reg(BME280_REGISTER_CONTROL, B01111111);
}
void writeBME280reg(uint8_t reg, uint8_t regvalue)
{
//write a register value to the BME280
Wire.beginTransmission((uint8_t) BME280_ADDRESS);
Wire.write((uint8_t)reg);
Wire.write((uint8_t)regvalue);
Wire.endTransmission();
}
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 setup()
{
pinMode(LED1, OUTPUT); //for PCB LED
led_Flash(2, 125);
Serial.begin(9600);
Serial.println();
Serial.println(F("81_BME280_Test_ESP32 starting"));
bme280.init(); //intialise BME280 library
Wire.begin(); //default for ESP32 is SDA on 21, SCL on 22
//alternative pins for I2C, ESP32 allows re-direction of I2C, format is Wire.begin(SDA,SCL);
//The SeedBME280 library does do a Wire.begin(); so this will overide it
Wire.begin(16,17);
Serial.println(F("Initialised BME280"));
Serial.println();
readSensors(); //do an initial sensor read
}