first commit
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 26/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 tests the deep sleep mode and wakeup with a switch of an Atmel 328P or
|
||||
1284P processor. The program starts, flashes the LED and then puts the processor into permanent sleep.
|
||||
It can be woken up with a switch press. Used as a base test routine for checking the sleep current of
|
||||
a board.
|
||||
|
||||
Tested on a 'bare bones' ATmega328P board, the current in sleep mode was 1.7uA with a 3.3V MCP1700
|
||||
regulator being used.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define Program_Version "V1.0"
|
||||
|
||||
#include <avr/sleep.h>
|
||||
|
||||
#define LED1 8 //on board LED, high for on
|
||||
#define SWITCH1 2 //switch used to wake processor up, switch pin connected to
|
||||
//ground to activate. Define as -1 if switch not used.
|
||||
|
||||
uint32_t sleeps;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(2000);
|
||||
sleeps++;
|
||||
Serial.print(sleeps);
|
||||
Serial.println(F(" Sleeping zzzzz...."));
|
||||
Serial.println();
|
||||
Serial.flush(); //make sure serial out buffer is empty
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(SWITCH1), wakeUp, FALLING); //This is a hardware interrupt
|
||||
|
||||
sleep_permanent(); //goto sleep till woken up by switch press
|
||||
|
||||
detachInterrupt(digitalPinToInterrupt(SWITCH1));
|
||||
|
||||
Serial.println(F("Awake !"));
|
||||
digitalWrite(LED1, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void sleep_permanent()
|
||||
{
|
||||
ADCSRA = 0; //disable ADC
|
||||
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
|
||||
noInterrupts (); //timed sequence follows
|
||||
sleep_enable();
|
||||
|
||||
//turn off brown-out enable in software
|
||||
MCUCR = bit (BODS) | bit (BODSE); //turn on brown-out enable select
|
||||
MCUCR = bit (BODS); //this must be done within 4 clock cycles of above
|
||||
interrupts (); //guarantees next instruction executed
|
||||
|
||||
sleep_cpu (); //sleep within 3 clock cycles of above
|
||||
|
||||
/* wake up here */
|
||||
|
||||
sleep_disable();
|
||||
}
|
||||
|
||||
|
||||
void wakeUp()
|
||||
{
|
||||
//handler for the interrupt
|
||||
}
|
||||
|
||||
|
||||
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(SWITCH1, INPUT_PULLUP); //setup switch pin, ground to activate
|
||||
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
|
||||
led_Flash(2, 125); //two quick LED flashes to indicate program start
|
||||
|
||||
pinMode(SWITCH1, INPUT_PULLUP); //setup switch pin, connect to ground to activate
|
||||
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
Serial.print(__TIME__);
|
||||
Serial.print(F(" "));
|
||||
Serial.println(__DATE__);
|
||||
Serial.println(F(Program_Version));
|
||||
Serial.println();
|
||||
|
||||
Serial.println(F("12_ATmel_Sleep_with_Switch_Wakeup Starting"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 24/12/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 program to test a GPS. It reads characters from the GPS using
|
||||
software serial and sends them (echoes) to the IDE serial monitor. If your ever having problems with
|
||||
a GPS (or just think you are) use this program first.
|
||||
|
||||
If you get no data displayed on the serial monitor, the most likely cause is that you have the receive
|
||||
data pin into the Arduino (RX) pin connected incorrectly.
|
||||
|
||||
GPS baud rate set at 9600 baud, Serial monitor set at 115200 baud. If the data displayed on the serial
|
||||
terminal appears to be random text with odd symbols its very likely you have the GPS serial baud rate
|
||||
set incorrectly for the GPS.
|
||||
|
||||
Note that not all pins on all Arduinos will work with software serial, see here;
|
||||
|
||||
https://www.arduino.cc/en/Reference/softwareSerial
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
#define RXpin A3 //this is the pin that the Arduino will use to receive data from the GPS
|
||||
#define TXpin A2 //this is the pin that the Arduino can use to send data (commands) to the GPS - not used
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPS(RXpin, TXpin);
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (GPS.available())
|
||||
{
|
||||
Serial.write(GPS.read());
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
GPS.begin(9600);
|
||||
Serial.begin(115200);
|
||||
Serial.println("GPS_Echo Starting");
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 14/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 is a simple program to test a GPS. It reads characters from the GPS using
|
||||
a hardware serial port, set to Serial1 as default, and then sends them (echoes) to the Arduino IDE
|
||||
serial monitor. If your ever having problems with a GPS (or just think you are) use this program first.
|
||||
|
||||
If you get no data displayed on the serial monitor, the most likely cause is that you have the receive
|
||||
data pin into the Arduino (RX) pin connected incorrectly.
|
||||
|
||||
At program start you should see '26A_GPS_Echo_Hardware_Serial Starting' in the serial monitor, if you
|
||||
dont the serial monitor baud rate is probably incorrectly set. If you then see data displayed on the
|
||||
serial terminal which appears to be random text with odd symbols its very likely you have the GPS
|
||||
serial baud rate set incorrectly.
|
||||
|
||||
Change 'Serial1' in the program to match the hardware serial port you are using, for an Arduino Mega
|
||||
this would normally be Serial1, Serila2 or Serial3.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (Serial3.available())
|
||||
{
|
||||
Serial.write(Serial3.read());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial3.begin(9600);
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println("26B_GPS_Echo_Hardware_Serial Starting");
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 14/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 is a simple program to test a UBLOX GPS. It reads characters from the GPS using
|
||||
the I2C interface and sends them (echoes) to the IDE serial monitor. If your ever having problems with a
|
||||
GPS (or just think you are) use this program first.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
const uint16_t GPSI2CAddress = 0x42;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t GPSByte;
|
||||
|
||||
do
|
||||
{
|
||||
Wire.requestFrom(GPSI2CAddress, 1);
|
||||
GPSByte = Wire.read();
|
||||
|
||||
if (GPSByte != 0xFF)
|
||||
{
|
||||
Serial.write(GPSByte);
|
||||
}
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin();
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println("26C_GPS_Echo_UBLOXI2C Starting");
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 14/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 is a simple program to test a GPS. It reads characters from the GPS using
|
||||
software serial and sends them (echoes) to the IDE serial monitor. If your ever having problems with
|
||||
a GPS (or just think you are) use this program first.
|
||||
|
||||
If you get no data displayed on the serial monitor, the most likely cause is that you have the receive
|
||||
data pin into the Arduino (RX) pin connected incorrectly.
|
||||
|
||||
If the data displayed on the serial terminal appears to be random text with odd symbols its very
|
||||
likely you have the GPS serial baud rate set incorrectly.
|
||||
|
||||
Note that not all pins on all Arduinos will work with software serial, see here;
|
||||
|
||||
https://www.arduino.cc/en/Reference/softwareSerial
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define RXpin A3 //this is the pin that the Arduino will use to receive data from the GPS
|
||||
#define TXpin A2 //this is the pin that the Arduino can use to send data (commands) to the GPS - not used
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial GPS(RXpin, TXpin);
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (GPS.available())
|
||||
{
|
||||
Serial.write(GPS.read());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
GPS.begin(9600);
|
||||
Serial.begin(115200);
|
||||
Serial.println("26_GPS_Echo Starting");
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 24/12/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 program is a portable GPS checker. It reads the GPS for 5 seconds and copies
|
||||
the characters from the GPS to the serial monitor, this is an example printout from a working GPS that
|
||||
has just been powered on;
|
||||
|
||||
28_GPS_Checker Starting
|
||||
Wait GPS Fix 5 seconds
|
||||
Timeout - No GPS Fix 5s
|
||||
Wait GPS Fix 5 seconds
|
||||
$PGACK,103*40
|
||||
$PGACK,105*46
|
||||
$PMTK011,MTKGPS*08
|
||||
$PMTK010,001*2E
|
||||
$PMTK010,00æ*2D
|
||||
$GPGGA,235942.800,,,,,0,0,,,M,,M,,*4B
|
||||
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
|
||||
$GPRMC,235942.800,V,,,,,0.00,0.00,050180,,,N*42
|
||||
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
|
||||
$GPGSV,1,1,03,30,,,43,07,,,43,05,,,38*70
|
||||
|
||||
Timeout - No GPS Fix 5s
|
||||
Wait GPS Fix 5 seconds
|
||||
|
||||
That printout is from a Meadiatek GPS, the Ublox ones are similar. The data from the GPS is also fed into
|
||||
the TinyGPS++ library and if there is no fix a message is printed on the serial monitor.
|
||||
|
||||
When the program detects that the GPS has a fix, it prints the Latitude, Longitude, Altitude, Number
|
||||
of satellites in use, the HDOP value, time and date to the serial monitor.
|
||||
|
||||
The program has the option of using a pin to control the power to the GPS, if the GPS module being used
|
||||
has this feature. To use the option change the define; '#define GPSPOWER -1' from -1 to the pin number
|
||||
being used. Also set the GPSONSTATE and GPSOFFSTATE to the appropriate logic levels.
|
||||
|
||||
There is a set of GPS co-ordinates defined, TestLatitude and TestLongitude, when the GPS has its location
|
||||
fix the distance and direction to the Test location is calculated and shown on the serial monitor.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define Program_Version "V1.2"
|
||||
#define authorname "Stuart Robinson"
|
||||
|
||||
#include <TinyGPS++.h> //get library here > http://arduiniana.org/libraries/tinygpsplus/
|
||||
TinyGPSPlus gps; //create the TinyGPS++ object
|
||||
|
||||
#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
|
||||
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS
|
||||
#define LED1 8 //pin number for LED, turns on when printing Fix data
|
||||
|
||||
#define GPSPOWER -1 //Pin that controls power to GPS, set to -1 if not used
|
||||
#define GPSONSTATE HIGH //logic level to turn GPS on via pin GPSPOWER
|
||||
#define GPSOFFSTATE LOW //logic level to turn GPS off via pin GPSPOWER
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPSserial(RXpin, TXpin);
|
||||
|
||||
|
||||
float GPSLat; //Latitude from GPS
|
||||
float GPSLon; //Longitude from GPS
|
||||
float GPSAlt; //Altitude from GPS
|
||||
uint8_t GPSSats; //number of GPS satellites in use
|
||||
uint32_t GPSHdop; //HDOP from GPS
|
||||
uint8_t hours, mins, secs, day, month;
|
||||
uint16_t year;
|
||||
uint32_t startGetFixmS;
|
||||
uint32_t endFixmS;
|
||||
|
||||
//GPS co-ordinates to use for the test location transmission
|
||||
const float TestLatitude = 51.48230; //Cardiff castle keep, used for location testing purposes
|
||||
const float TestLongitude = -3.18136;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (gpsWaitFix(5))
|
||||
{
|
||||
digitalWrite(LED1, HIGH); //LED on to indicate fix
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Fix time "));
|
||||
Serial.print(endFixmS - startGetFixmS);
|
||||
Serial.println(F("mS"));
|
||||
|
||||
GPSLat = gps.location.lat();
|
||||
GPSLon = gps.location.lng();
|
||||
GPSAlt = gps.altitude.meters();
|
||||
GPSSats = gps.satellites.value();
|
||||
GPSHdop = gps.hdop.value();
|
||||
|
||||
hours = gps.time.hour();
|
||||
mins = gps.time.minute();
|
||||
secs = gps.time.second();
|
||||
day = gps.date.day();
|
||||
month = gps.date.month();
|
||||
year = gps.date.year();
|
||||
|
||||
printGPSfix();
|
||||
startGetFixmS = millis(); //have a fix, next thing that happens is checking for a fix, so restart timer
|
||||
digitalWrite(LED1, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Timeout - No GPS Fix "));
|
||||
Serial.print( (millis() - startGetFixmS) / 1000 );
|
||||
Serial.println(F("s"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool gpsWaitFix(uint16_t waitSecs)
|
||||
{
|
||||
//waits a specified number of seconds for a fix, returns true for updated fix
|
||||
|
||||
uint32_t startmS, waitmS;
|
||||
uint8_t GPSchar;
|
||||
|
||||
Serial.print(F("Wait GPS Fix "));
|
||||
Serial.print(waitSecs);
|
||||
Serial.println(F(" seconds"));
|
||||
|
||||
waitmS = waitSecs * 1000; //convert seconds wait into mS
|
||||
|
||||
startmS = millis();
|
||||
|
||||
while ( (uint32_t) (millis() - startmS) < waitmS) //allows for millis() overflow
|
||||
{
|
||||
if (GPSserial.available() > 0)
|
||||
{
|
||||
GPSchar = GPSserial.read();
|
||||
gps.encode(GPSchar);
|
||||
Serial.write(GPSchar);
|
||||
}
|
||||
|
||||
if (gps.location.isUpdated() && gps.altitude.isUpdated() && gps.date.isUpdated())
|
||||
{
|
||||
endFixmS = millis(); //record the time when we got a GPS fix
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void printGPSfix()
|
||||
{
|
||||
float tempfloat;
|
||||
uint32_t distance;
|
||||
uint16_t direction;
|
||||
|
||||
Serial.print(F("New GPS Fix "));
|
||||
|
||||
tempfloat = ( (float) GPSHdop / 100);
|
||||
|
||||
Serial.print(F("Lat,"));
|
||||
Serial.print(GPSLat, 6);
|
||||
Serial.print(F(",Lon,"));
|
||||
Serial.print(GPSLon, 6);
|
||||
Serial.print(F(",Alt,"));
|
||||
Serial.print(GPSAlt, 1);
|
||||
Serial.print(F("m,Sats,"));
|
||||
Serial.print(GPSSats);
|
||||
Serial.print(F(",HDOP,"));
|
||||
Serial.print(tempfloat, 2);
|
||||
Serial.print(F(",Time,"));
|
||||
|
||||
if (hours < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(hours);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (mins < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(mins);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (secs < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(secs);
|
||||
Serial.print(F(",Date,"));
|
||||
|
||||
Serial.print(day);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(month);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(year);
|
||||
|
||||
distance = gps.distanceBetween(GPSLat, GPSLon, TestLatitude, TestLongitude);
|
||||
direction = gps.courseTo(GPSLat, GPSLon, TestLatitude, TestLongitude);
|
||||
|
||||
Serial.println();
|
||||
Serial.print(F("Distance to Test Location ("));
|
||||
Serial.print(TestLatitude, 6);
|
||||
Serial.print((","));
|
||||
Serial.print(TestLongitude, 6);
|
||||
Serial.print((") "));
|
||||
Serial.print(distance);
|
||||
Serial.print(("m"));
|
||||
Serial.println();
|
||||
Serial.print(F("Direction to Test Location ("));
|
||||
Serial.print(TestLatitude, 6);
|
||||
Serial.print((","));
|
||||
Serial.print(TestLongitude, 6);
|
||||
Serial.print((") "));
|
||||
Serial.print(direction);
|
||||
Serial.print(("d"));
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void GPSON()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSONSTATE); //power up GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPSOFF()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSOFFSTATE); //power off GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
|
||||
if (GPSPOWER >= 0)
|
||||
{
|
||||
pinMode(GPSPOWER, OUTPUT);
|
||||
GPSON();
|
||||
}
|
||||
|
||||
GPSserial.begin(9600);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(F(__TIME__));
|
||||
Serial.print(F(" "));
|
||||
Serial.println(F(__DATE__));
|
||||
Serial.println(F(Program_Version));
|
||||
Serial.println();
|
||||
|
||||
Serial.println(F("28_GPS_Checker Starting"));
|
||||
Serial.println();
|
||||
|
||||
startGetFixmS = millis();
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 29/12/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 program is a portable GPS checker with display option. It uses an SSD1306 or
|
||||
SH1106 128x64 I2C OLED display. The program reads the GPS for 5 seconds checking for a fix and copies
|
||||
the characters from the GPS to the serial monitor so you can see if the GPS is working. This is an example
|
||||
printout from a working GPS with the program having been just been powered on;
|
||||
|
||||
29_GPS_Checker_Display Starting
|
||||
|
||||
Wait GPS Fix 5 seconds
|
||||
$GPGGA,235945.020,,,,,0,0,,,M,,M,,*46
|
||||
$GPGLL,,,,,235945.020,V,N*74
|
||||
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
|
||||
$GPGSV,1,1,01,11,,,33*78
|
||||
$GPRMC,235945.020,V,,,,,0.00,0.00,050180,,,N*4F
|
||||
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
|
||||
$GPGGA,235946.020,,,,,0,0,,,M,,M,,*45
|
||||
$GPGLL,,,,,235946.020,V,N*77
|
||||
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
|
||||
$GPGSV,1,1,02,22,,,36,11,,,33*7E
|
||||
$GPRMC,235946.020,V,,,,,0.00,0.00,050180,,,N*4C
|
||||
|
||||
Timeout - No GPS Fix 5s
|
||||
Wait GPS Fix 5 seconds
|
||||
|
||||
That printout is from a Meadiatek GPS, the Ublox ones are similar. The data from the GPS is also fed into
|
||||
the TinyGPS++ library and if there is no fix a message is printed on the serial monitor.
|
||||
|
||||
When the program detects that the GPS has a fix, it prints the Latitude, Longitude, Altitude, Speed, Number
|
||||
of satellites in use, the HDOP value, time and date to the serial monitor. If the I2C OLED display is
|
||||
attached that is updated as well. Display is assumed to be on I2C address 0x3C.
|
||||
|
||||
The program has the option of using a pin to control the power to the GPS, if the GPS module being used
|
||||
has this feature. To use the option change the define; '#define GPSPOWER -1' from -1 to the pin number
|
||||
being used. Also set the GPSONSTATE and GPSOFFSTATE to the appropriate logic levels.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
Changes:
|
||||
290920 - Add speed to serial monitor output and display
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define Program_Version "V1.2"
|
||||
#define authorname "Stuart Robinson"
|
||||
|
||||
#include <TinyGPS++.h> //get library here > http://arduiniana.org/libraries/tinygpsplus/
|
||||
TinyGPSPlus gps; //create the TinyGPS++ object
|
||||
|
||||
#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
|
||||
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS
|
||||
|
||||
#define GPSPOWER -1 //Pin that controls power to GPS, set to -1 if not used
|
||||
#define GPSONSTATE HIGH //logic level to turn GPS on via pin GPSPOWER
|
||||
#define GPSOFFSTATE LOW //logic level to turn GPS off via pin GPSPOWER
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPSserial(RXpin, TXpin);
|
||||
|
||||
|
||||
#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 used by U8X8 Library
|
||||
|
||||
|
||||
float GPSLat; //Latitude from GPS
|
||||
float GPSLon; //Longitude from GPS
|
||||
float GPSAlt; //Altitude from GPS
|
||||
uint8_t GPSSats; //number of GPS satellites in use
|
||||
uint32_t GPSHdop; //HDOP from GPS
|
||||
float GPSSpeed; //Speed of GPS, mph
|
||||
|
||||
uint8_t hours, mins, secs, day, month;
|
||||
uint16_t year;
|
||||
uint32_t startGetFixmS;
|
||||
uint32_t endFixmS;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (gpsWaitFix(5))
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Fix time "));
|
||||
Serial.print(endFixmS - startGetFixmS);
|
||||
Serial.println(F("mS"));
|
||||
|
||||
GPSLat = gps.location.lat();
|
||||
GPSLon = gps.location.lng();
|
||||
GPSAlt = gps.altitude.meters();
|
||||
GPSSats = gps.satellites.value();
|
||||
GPSHdop = gps.hdop.value();
|
||||
GPSSpeed = gps.speed.mph();
|
||||
|
||||
hours = gps.time.hour();
|
||||
mins = gps.time.minute();
|
||||
secs = gps.time.second();
|
||||
day = gps.date.day();
|
||||
month = gps.date.month();
|
||||
year = gps.date.year();
|
||||
|
||||
printGPSfix(); //print GPS data to serial monitor
|
||||
displayscreen1(); //print GPS data on display
|
||||
startGetFixmS = millis(); //have a fix, next thing that happens is checking for a fix, so restart timer
|
||||
}
|
||||
else
|
||||
{
|
||||
disp.clearLine(0);
|
||||
disp.setCursor(0, 0);
|
||||
disp.print(F("No GPS Fix "));
|
||||
disp.print( (millis() - startGetFixmS) / 1000 );
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Timeout - No GPS Fix "));
|
||||
Serial.print( (millis() - startGetFixmS) / 1000 );
|
||||
Serial.println(F("s"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool gpsWaitFix(uint16_t waitSecs)
|
||||
{
|
||||
//waits a specified number of seconds for a fix, returns true for updated fix
|
||||
|
||||
uint32_t startmS, waitmS;
|
||||
uint8_t GPSchar;
|
||||
|
||||
Serial.print(F("Wait GPS Fix "));
|
||||
Serial.print(waitSecs);
|
||||
Serial.println(F(" seconds"));
|
||||
//Serial.print(F("Current millis() "));
|
||||
//Serial.println(millis());
|
||||
|
||||
waitmS = waitSecs * 1000; //convert seconds wait into mS
|
||||
|
||||
startmS = millis();
|
||||
|
||||
while ( (uint32_t) (millis() - startmS) < waitmS) //allows for millis() overflow
|
||||
{
|
||||
if (GPSserial.available() > 0)
|
||||
{
|
||||
GPSchar = GPSserial.read();
|
||||
gps.encode(GPSchar);
|
||||
Serial.write(GPSchar);
|
||||
}
|
||||
|
||||
if (gps.location.isUpdated() && gps.altitude.isUpdated() && gps.date.isUpdated())
|
||||
{
|
||||
endFixmS = millis(); //record the time when we got a GPS fix
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void printGPSfix()
|
||||
{
|
||||
float tempfloat;
|
||||
|
||||
Serial.print(F("New GPS Fix "));
|
||||
|
||||
tempfloat = ( (float) GPSHdop / 100);
|
||||
|
||||
Serial.print(F("Latitude,"));
|
||||
Serial.print(GPSLat, 6);
|
||||
Serial.print(F(",Longitude,"));
|
||||
Serial.print(GPSLon, 6);
|
||||
Serial.print(F(",Altitude,"));
|
||||
Serial.print(GPSAlt, 1);
|
||||
Serial.print(F("m,Speed,"));
|
||||
Serial.print(GPSSpeed, 1);
|
||||
Serial.print(F("mph,Sats,"));
|
||||
Serial.print(GPSSats);
|
||||
Serial.print(F(",HDOP,"));
|
||||
Serial.print(tempfloat, 2);
|
||||
Serial.print(F(",Time,"));
|
||||
|
||||
if (hours < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(hours);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (mins < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(mins);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (secs < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(secs);
|
||||
Serial.print(F(",Date,"));
|
||||
|
||||
Serial.print(day);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(month);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(year);
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void displayscreen1()
|
||||
{
|
||||
//show GPS data on display
|
||||
float tempfloat;
|
||||
tempfloat = ( (float) GPSHdop / 100);
|
||||
|
||||
disp.clearLine(0);
|
||||
disp.setCursor(0, 0);
|
||||
disp.print(GPSLat, 6);
|
||||
disp.clearLine(1);
|
||||
disp.setCursor(0, 1);
|
||||
disp.print(GPSLon, 6);
|
||||
disp.clearLine(2);
|
||||
disp.setCursor(0, 2);
|
||||
disp.print(GPSAlt,0);
|
||||
disp.print(F("m"));
|
||||
disp.clearLine(3);
|
||||
disp.setCursor(0, 3);
|
||||
disp.print(GPSSpeed,0);
|
||||
disp.print(F("mph"));
|
||||
disp.clearLine(4);
|
||||
disp.setCursor(0, 4);
|
||||
disp.print(F("Sats "));
|
||||
disp.print(GPSSats);
|
||||
disp.clearLine(5);
|
||||
disp.setCursor(0, 5);
|
||||
disp.print(F("HDOP "));
|
||||
disp.print(tempfloat);
|
||||
disp.clearLine(6);
|
||||
disp.setCursor(0, 6);
|
||||
|
||||
if (hours < 10)
|
||||
{
|
||||
disp.print(F("0"));
|
||||
}
|
||||
|
||||
disp.print(hours);
|
||||
disp.print(F(":"));
|
||||
|
||||
if (mins < 10)
|
||||
{
|
||||
disp.print(F("0"));
|
||||
}
|
||||
|
||||
disp.print(mins);
|
||||
disp.print(F(":"));
|
||||
|
||||
if (secs < 10)
|
||||
{
|
||||
disp.print(F("0"));
|
||||
}
|
||||
|
||||
disp.print(secs);
|
||||
disp.print(F(" "));
|
||||
|
||||
disp.clearLine(7);
|
||||
disp.setCursor(0, 7);
|
||||
|
||||
disp.print(day);
|
||||
disp.print(F("/"));
|
||||
disp.print(month);
|
||||
disp.print(F("/"));
|
||||
disp.print(year);
|
||||
}
|
||||
|
||||
|
||||
void GPSON()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSONSTATE); //power up GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPSOFF()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSOFFSTATE); //power off GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
if (GPSPOWER >= 0)
|
||||
{
|
||||
pinMode(GPSPOWER, OUTPUT);
|
||||
GPSON();
|
||||
}
|
||||
|
||||
GPSserial.begin(9600);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(F(__TIME__));
|
||||
Serial.print(F(" "));
|
||||
Serial.println(F(__DATE__));
|
||||
Serial.println(F(Program_Version));
|
||||
Serial.println();
|
||||
|
||||
disp.begin();
|
||||
disp.setFont(DEFAULTFONT);
|
||||
disp.clear();
|
||||
disp.setCursor(0, 0);
|
||||
disp.print(F("Display Ready"));
|
||||
|
||||
Serial.println(F("29_GPS_Checker_With_Display Starting"));
|
||||
Serial.println();
|
||||
|
||||
startGetFixmS = millis();
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*******************************************************************************************************
|
||||
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 running on
|
||||
a 3.3V 8Mhz bare bones ATmega328P. The program prints a short message on each line, pauses, clears the
|
||||
screen, turns off the screem, puts the processor to sleep and starts again. Sleep current with display
|
||||
off is circa 8uA.
|
||||
|
||||
OLED address defaults to 0x3C.
|
||||
|
||||
Screen write on 8Mhz Atmel 196mS.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
uint16_t writecount;
|
||||
uint32_t startwritemS, endwritemS, timemS;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
writecount++;
|
||||
Serial.print(writecount);
|
||||
Serial.print(F(" Writing to display"));
|
||||
|
||||
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"));
|
||||
Serial.flush(); //pending serial output affects sleep mode
|
||||
disp.setPowerSave(1); //power save display, turns off, sleep current circa 8uA
|
||||
sleep1seconds(2); //sleep in units of 1 second
|
||||
disp.setPowerSave(0); //display back to normal
|
||||
}
|
||||
|
||||
|
||||
void sleep1seconds(uint32_t sleeps)
|
||||
{
|
||||
uint32_t index;
|
||||
|
||||
for (index = 1; index <= sleeps; index++)
|
||||
{
|
||||
ADCSRA = 0; //disable ADC
|
||||
MCUSR = 0; //clear various "reset" flags
|
||||
WDTCSR = bit (WDCE) | bit (WDE); //allow changes, disable reset
|
||||
WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1); //set interrupt mode and an interval, set WDIE, and 1 seconds sleep
|
||||
wdt_reset(); //pat the dog
|
||||
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
|
||||
noInterrupts (); //timed sequence follows
|
||||
sleep_enable();
|
||||
MCUCR = bit (BODS) | bit (BODSE); //turn off brown-out enable in software
|
||||
MCUCR = bit (BODS);
|
||||
interrupts (); //guarantees next instruction executed
|
||||
|
||||
sleep_cpu ();
|
||||
//awake here
|
||||
sleep_disable(); //cancel sleep as a precaution
|
||||
}
|
||||
}
|
||||
|
||||
ISR (WDT_vect)
|
||||
{
|
||||
//watchdog interrupt
|
||||
wdt_disable(); // disable watchdog
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("31_SSD1306_SH1106_OLED_Checker starting"));
|
||||
disp.begin();
|
||||
disp.setFont(DEFAULTFONT);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 05/04/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 program is GPS Time checker. It reads the GPS NMEA output and displays the time
|
||||
on the Arduino IDE serial monitor. If you have the serial monitor output on screen as the same time as
|
||||
observing a web site displaying the current time you can check how close your GPS is reporting to real time.
|
||||
|
||||
At power up a GPS will not normally display the time accurate to the exact second until it receives the
|
||||
navigation message that is the updated value of current leaps seconds which is sent out every 12.5 minutes.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#define Program_Version "V1.0"
|
||||
#define authorname "Stuart Robinson"
|
||||
|
||||
#include <TinyGPS++.h> //get library here > http://arduiniana.org/libraries/tinygpsplus/
|
||||
TinyGPSPlus gps; //create the TinyGPS++ object
|
||||
|
||||
#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
|
||||
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS
|
||||
|
||||
#define GPSPOWER -1 //Pin that controls power to GPS, set to -1 if not used
|
||||
#define GPSONSTATE HIGH //logic level to turn GPS on via pin GPSPOWER
|
||||
#define GPSOFFSTATE LOW //logic level to turn GPS off via pin GPSPOWER
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPSserial(RXpin, TXpin);
|
||||
|
||||
uint8_t hours, mins, secs;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (gpsWaitFix(5))
|
||||
{
|
||||
hours = gps.time.hour();
|
||||
mins = gps.time.minute();
|
||||
secs = gps.time.second();
|
||||
|
||||
printGPSfix();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("Timeout - No GPS Fix "));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool gpsWaitFix(uint16_t waitSecs)
|
||||
{
|
||||
//waits a specified number of seconds for a fix, returns true for updated fix
|
||||
|
||||
uint32_t endwaitmS;
|
||||
uint8_t GPSchar;
|
||||
|
||||
endwaitmS = millis() + (waitSecs * 1000);
|
||||
|
||||
while (millis() < endwaitmS)
|
||||
{
|
||||
if (GPSserial.available() > 0)
|
||||
{
|
||||
GPSchar = GPSserial.read();
|
||||
gps.encode(GPSchar);
|
||||
//Serial.write(GPSchar);
|
||||
}
|
||||
|
||||
if (gps.location.isUpdated() && gps.time.isUpdated())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void printGPSfix()
|
||||
{
|
||||
Serial.print(F("Time,"));
|
||||
|
||||
if (hours < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(hours);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (mins < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(mins);
|
||||
Serial.print(F(":"));
|
||||
|
||||
if (secs < 10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
|
||||
Serial.print(secs);
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void GPSON()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSONSTATE); //power up GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPSOFF()
|
||||
{
|
||||
if (GPSPOWER)
|
||||
{
|
||||
digitalWrite(GPSPOWER, GPSOFFSTATE); //power off GPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
if (GPSPOWER >= 0)
|
||||
{
|
||||
pinMode(GPSPOWER, OUTPUT);
|
||||
GPSON();
|
||||
}
|
||||
|
||||
GPSserial.begin(9600);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.print(F(__TIME__));
|
||||
Serial.print(F(" "));
|
||||
Serial.println(F(__DATE__));
|
||||
Serial.println(F(Program_Version));
|
||||
Serial.println();
|
||||
|
||||
Serial.println(F("32_GPS_Checker_Time Starting"));
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 03/09/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 program tests the sleep mode of an Atmel ATMega328P processor.
|
||||
|
||||
At power up the flashes an LED 4 times, then turns on the LED for 5 seconds. Then the processor is put
|
||||
to sleep for 16 seconds. On wakeup the LED flashes twice, then is on for 2 seconds and the board goes to
|
||||
sleep again. And the sequence repeats.
|
||||
|
||||
Sleep current for a 'bare bones' ATmega328 with a MCP1700 regulator @ 3.3V and using an external event
|
||||
such as a switch to wakeup from sleep should be around 2uA. Using the watchdog timer to wakeup raises
|
||||
the deep sleep current to circa 6.2uA.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
//basic code from here - https://www.gammon.com.au/forum/?id=11497
|
||||
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
|
||||
#define LED1 8
|
||||
|
||||
|
||||
void loop ()
|
||||
{
|
||||
Serial.println("LED Off");
|
||||
digitalWrite(LED1, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
Serial.println(F("Now Sleeping... "));
|
||||
Serial.flush();
|
||||
|
||||
sleep8seconds(2); //sleep for about 16 seconds
|
||||
|
||||
Serial.println("Awake ");
|
||||
led_Flash(2, 125);
|
||||
Serial.println("LED On ");
|
||||
digitalWrite(LED1, HIGH);
|
||||
digitalWrite(13, HIGH);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
void sleep8seconds(uint32_t sleeps)
|
||||
{
|
||||
uint32_t index;
|
||||
|
||||
for (index = 1; index <= sleeps; index++)
|
||||
{
|
||||
ADCSRA = 0; //disable ADC
|
||||
MCUSR = 0; //clear various "reset" flags
|
||||
WDTCSR = bit (WDCE) | bit (WDE); //allow changes, disable reset
|
||||
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); //set interrupt mode and an interval, set WDIE, and 8 seconds delay
|
||||
wdt_reset(); //pat the dog
|
||||
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
|
||||
noInterrupts (); //timed sequence follows
|
||||
sleep_enable();
|
||||
MCUCR = bit (BODS) | bit (BODSE); //turn off brown-out enable in software
|
||||
MCUCR = bit (BODS);
|
||||
interrupts (); //guarantees next instruction executed
|
||||
|
||||
sleep_cpu ();
|
||||
//awake here
|
||||
sleep_disable(); //cancel sleep as a precaution
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(uint16_t flashes, uint16_t delaymS)
|
||||
{
|
||||
uint16_t index;
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
digitalWrite(13, HIGH);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, LOW);
|
||||
digitalWrite(13, LOW);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup ()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
pinMode(13, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
led_Flash(4, 125);
|
||||
Serial.println("LED On ");
|
||||
digitalWrite(LED1, HIGH);
|
||||
digitalWrite(13, HIGH);
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
ISR (WDT_vect)
|
||||
{
|
||||
//watchdog interrupt
|
||||
wdt_disable(); // disable watchdog
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 30/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 sweeps two servos from one end of their travel to the other. Useful to
|
||||
check servos are connected correctly and working.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
#define pinservoX1 2 //pin for controlling servo X 1
|
||||
#define pinservoY1 4 //pin for controlling servo Y 1
|
||||
|
||||
|
||||
#define LED1 8
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
Servo ServoX1; //create the servo object
|
||||
Servo ServoY1; //create the servo object
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint16_t index;
|
||||
|
||||
for (index = 900; index <= 2100; index++)
|
||||
{
|
||||
//Serial.print(F("Microseconds1 "));
|
||||
//Serial.println(index);
|
||||
ServoX1.writeMicroseconds(index);
|
||||
ServoY1.writeMicroseconds(index);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
|
||||
for (index = 2100; index >= 900; index--)
|
||||
{
|
||||
//Serial.print(F("Microseconds1 "));
|
||||
//Serial.println(index);
|
||||
ServoX1.writeMicroseconds(index);
|
||||
ServoY1.writeMicroseconds(index);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
led_Flash(2, 125);
|
||||
|
||||
|
||||
Serial.begin(9600);
|
||||
ServoX1.attach(pinservoX1); //using pin servoX for servo object
|
||||
ServoY1.attach(pinservoY1); //using pin servoX for servo object
|
||||
|
||||
Serial.println(F("Servo sweep test starting"));
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
/*******************************************************************************************************
|
||||
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
|
||||
|
||||
Serial monitor baud rate is set at 9600
|
||||
*******************************************************************************************************/
|
||||
#define Program_Version "V1.1"
|
||||
|
||||
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
#define LED1 8 //pin number for LED
|
||||
#define SDCS 4 //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_WRITE);
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*******************************************************************************************************
|
||||
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
|
||||
*******************************************************************************************************/
|
||||
/*
|
||||
******************************************************************************************************
|
||||
Program operation -
|
||||
|
||||
******************************************************************************************************
|
||||
*/
|
||||
|
||||
#define ADMultiplier 6.36 //adjustment to convert AD value read into mV of battery voltage
|
||||
#define BATVREADON 8 //used to turn on the resistor divider to measure voltage, //this pin turns on the MOSFET that switches in the resistor divider
|
||||
#define LED1 8 //pin for PCB LED
|
||||
#define SupplyAD A0 //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()
|
||||
{
|
||||
//relies on internal reference and 91K & 11K resistor divider
|
||||
//returns supply in mV @ 10mV per AD bit read
|
||||
uint16_t temp;
|
||||
uint16_t volts = 0;
|
||||
byte index;
|
||||
|
||||
if (BATVREADON >= 0)
|
||||
{
|
||||
digitalWrite(BATVREADON, HIGH); //turn MOSFET connection resitor divider in circuit
|
||||
}
|
||||
|
||||
analogReference(INTERNAL);
|
||||
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 MOSFET connection 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 Starting");
|
||||
|
||||
pinMode(LED1, OUTPUT); //for PCB LED
|
||||
|
||||
if (BATVREADON >= 0)
|
||||
{
|
||||
pinMode (BATVREADON, OUTPUT); //for turning on resistor divider
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 02/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 - This program tests that an MB85RC16PNF or FM24CL64 FRAM is working and retaining
|
||||
memory contents when power is removed. FRAMs are non-voltatile memory devices with a typical write
|
||||
endurance of from 10,000,000,000 (MB85RC16PNF) to 100,000,000,000,000 (FM24CL64B) write cycles.
|
||||
|
||||
When the program starts the serial monitor will first display the results of an I2C Device scan which
|
||||
should list 8 devices found from 0x50 to 0x57 for a MB85RC16PNF and 0x50 for a FM24CL64 with the default
|
||||
pin connections. The MB85RC16PNF has eight 256 byte pages, FM24CL64 is one page of 8kbytes. The program
|
||||
then will print the contents of the memory. Next all the variable types will be written to successive
|
||||
addresses will print the area of memory, then read back each variable from memory.
|
||||
|
||||
To check if the FRAM is reating memory you could make some changes to the variables written, run the
|
||||
program and then power off. On restart the changed variables should be displayed.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
#define Program_Version "V1.0"
|
||||
|
||||
|
||||
//#include <FRAM_FM24CL64.h> //SX12xx library file for FM24CL64 FRAM, 64kbit, 8kbyte, , I2C addresse 0x50
|
||||
#include <FRAM_MB85RC16PNF.h> //SX12xx library file for MB85RC16PNF FRAM, 16kbit, 2kbyte, I2C addresses 0x50 to 0x57
|
||||
|
||||
#include <Wire.h>
|
||||
#include "I2C_Scanner.h"
|
||||
|
||||
#define Serial_Monitor_Baud 9600 //this is baud rate used for the Arduino IDE Serial Monitor
|
||||
|
||||
int16_t Memory_Address = 0x50; //default I2C address of MB85RC16PNF and FM24CL64 FRAM
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(F("Printing memory"));
|
||||
Serial.flush();
|
||||
printMemory(0, 31);
|
||||
Serial.println();
|
||||
Serial.flush();
|
||||
|
||||
while (true)
|
||||
{
|
||||
Serial.println();
|
||||
writeMemory();
|
||||
Serial.println();
|
||||
readMemory();
|
||||
Serial.println();
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeMemory()
|
||||
{
|
||||
Serial.println(F("Writing variables"));
|
||||
Serial.flush();
|
||||
Serial.println(F("Write char A"));
|
||||
writeMemoryChar(0, 'A');
|
||||
|
||||
Serial.println(F("Write int8_t 0x55"));
|
||||
writeMemoryInt8(1, 0x55);
|
||||
|
||||
Serial.println(F("Write uint8_t 0xAA"));
|
||||
writeMemoryUint8(2, 0xAA);
|
||||
|
||||
Serial.println(F("Write int16_t 0xFEDC"));
|
||||
writeMemoryInt16(3, 0xFEDC);
|
||||
|
||||
Serial.println(F("Write uint16_t 0x1234"));
|
||||
writeMemoryUint16(5, 0x1234);
|
||||
|
||||
Serial.println(F("Write int32_t 0xFEDCBA98"));
|
||||
writeMemoryInt32(7, 0xFEDCBA98);
|
||||
|
||||
Serial.println(F("Write uint32_t 0x12345678"));
|
||||
writeMemoryUint32(11, 0x12345678);
|
||||
|
||||
Serial.println(F("Write float 0.12345678"));
|
||||
writeMemoryFloat(15, 0.12345678);
|
||||
}
|
||||
|
||||
|
||||
void readMemory()
|
||||
{
|
||||
char var1;
|
||||
int8_t var2;
|
||||
uint8_t var3;
|
||||
int16_t var4;
|
||||
uint16_t var5;
|
||||
int32_t var6;
|
||||
uint32_t var7;
|
||||
float var8;
|
||||
char buf[9];
|
||||
|
||||
Serial.println(F("Reading variables"));
|
||||
Serial.flush();
|
||||
var1 = readMemoryChar(0);
|
||||
Serial.print(F("Read char "));
|
||||
Serial.write(var1);
|
||||
Serial.println();
|
||||
|
||||
var2 = readMemoryInt8(1);
|
||||
Serial.print(F("Read int8_t 0x"));
|
||||
Serial.println(var2,HEX);
|
||||
|
||||
var3 = readMemoryUint8(2);
|
||||
Serial.print(F("Read uint8_t 0x"));
|
||||
Serial.println(var3,HEX);
|
||||
|
||||
var4 = readMemoryInt16(3);
|
||||
Serial.print(F("Read int16_t 0x"));
|
||||
sprintf(buf, "%04X", var4);
|
||||
Serial.println(buf);
|
||||
|
||||
var5 = readMemoryUint16(5);
|
||||
Serial.print(F("Read uint16_t 0x"));
|
||||
Serial.println(var5,HEX);
|
||||
|
||||
var6 = readMemoryInt32(7);
|
||||
Serial.print(F("Read int32_t 0x"));
|
||||
Serial.println(var6,HEX);
|
||||
|
||||
var7 = readMemoryUint32(11);
|
||||
Serial.print(F("Read uint32_t 0x"));
|
||||
Serial.println(var7,HEX);
|
||||
|
||||
var8 = readMemoryFloat(15);
|
||||
Serial.print(F("Read float "));
|
||||
Serial.println(var8, 7);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
Serial.print(F(__TIME__));
|
||||
Serial.print(F(" "));
|
||||
Serial.println(F(__DATE__));
|
||||
Serial.println(F(Program_Version));
|
||||
Serial.println();
|
||||
|
||||
setup_I2CScan();
|
||||
run_I2CScan();
|
||||
|
||||
memoryStart(Memory_Address); //optional command to start memory with I2C address, if required
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// --------------------------------------
|
||||
// i2c_scanner
|
||||
//
|
||||
// Version 1
|
||||
// This program (or code that looks like it)
|
||||
// can be found in many places.
|
||||
// For example on the Arduino.cc forum.
|
||||
// The original author is not know.
|
||||
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||
// Version 3, Feb 26 2013
|
||||
// V3 by louarnold
|
||||
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||
// by Arduino.cc user Krodal.
|
||||
// Changes by louarnold removed.
|
||||
// Scanning addresses changed from 0...127 to 1...119,
|
||||
// according to the i2c scanner by Nick Gammon
|
||||
// http://www.gammon.com.au/forum/?id=10896
|
||||
// Version 5, March 28, 2013
|
||||
// As version 4, but address scans now to 127.
|
||||
// A sensor seems to use address 120.
|
||||
// Version 6, November 27, 2015.
|
||||
// Added waiting for the Leonardo serial communication.
|
||||
//
|
||||
//
|
||||
// This sketch tests the standard 7-bit addresses
|
||||
// Devices with higher bit address might not be seen properly.
|
||||
//
|
||||
|
||||
|
||||
//#include <Wire.h>
|
||||
|
||||
|
||||
void setup_I2CScan()
|
||||
{
|
||||
Wire.begin();
|
||||
|
||||
//Serial.begin(9600);
|
||||
Serial.println("I2C Scanner");
|
||||
}
|
||||
|
||||
|
||||
void run_I2CScan()
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning for I2C Devices...");
|
||||
|
||||
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("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found");
|
||||
else
|
||||
Serial.println("done");
|
||||
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*******************************************************************************************************
|
||||
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 - The program reads a single DS18B20 temperature sensor and prints the result to the
|
||||
serial monitor.
|
||||
|
||||
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 then these devices are
|
||||
assumed to be 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 programversion "V1.0"
|
||||
|
||||
#define ONE_WIRE_BUS 4 //pin the DS18B20 is connected to
|
||||
#define LED1 8 //LED, on when reading temperature
|
||||
|
||||
|
||||
#include <OneWire.h> //get library here > https://github.com/PaulStoffregen/OneWire
|
||||
OneWire oneWire(ONE_WIRE_BUS); //create instance of OneWire library
|
||||
|
||||
#include <DallasTemperature.h> //get library here > https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||
DallasTemperature sensor(&oneWire); //create instance of dallas library
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
float DS18B20temperature;
|
||||
|
||||
digitalWrite(LED1, HIGH);
|
||||
sensor.requestTemperatures();
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
DS18B20temperature = sensor.getTempCByIndex(0);
|
||||
Serial.print(F("DS18B20 Temperature "));
|
||||
Serial.print(DS18B20temperature, 2);
|
||||
Serial.println(F("c"));
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void led_Flash(unsigned int flashes, unsigned int delaymS)
|
||||
{
|
||||
unsigned int index;
|
||||
|
||||
for (index = 1; index <= flashes; index++)
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
delay(delaymS);
|
||||
digitalWrite(LED1, HIGH);
|
||||
delay(delaymS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
Serial.print(__TIME__);
|
||||
Serial.print(F(" "));
|
||||
Serial.println(__DATE__);
|
||||
Serial.println(F(programversion));
|
||||
Serial.println();
|
||||
Serial.println("48_DS18B20_Test Starting");
|
||||
|
||||
pinMode(LED1, OUTPUT);
|
||||
|
||||
led_Flash(4, 125); //one second of flashes
|
||||
|
||||
sensor.begin();
|
||||
sensor.requestTemperatures(); //do a null temperature read
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 05/12/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 program is stand alone, it is not necessary to install a NRF2401 library to
|
||||
check the NRF2401 can be written to and read from over the SPI bus.
|
||||
|
||||
The contents of the NRF2401 registers from 0x00 to 0x1F are read and printed to the serial monitor.
|
||||
If the connections are OK then the printout should look like this;
|
||||
|
||||
57_NRF24L01_Is_It_There ?
|
||||
|
||||
Print registers 0x00 to 0x1F
|
||||
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
0x00 00 3F 02 03 5F 4C 27 42 00 00 E7 52 C3 C4 C5 C6
|
||||
0x10 E7 00 20 00 00 00 00 12 00 00 FF FF FF FF FF FF
|
||||
|
||||
Note that this is just a 'is it there type check' the CE pin is not used or needed for this simple check.
|
||||
If the device is faulty, not present or wired incorrectly the register contents will likely be all 00s or
|
||||
FFs. The program makes no attempt to turn on the RF transmitter or receiver.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
#define CSN_PIN 10
|
||||
|
||||
#define NUM_REGISTERS 26
|
||||
#define CMD_R_REGISTER 0x00
|
||||
#define CMD_W_REGISTER 0x20
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(F("Print registers 0x00 to 0x1F"));
|
||||
printRegisters(0, 0x1F);
|
||||
Serial.println();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void printRegisters(uint16_t Start, uint16_t End)
|
||||
{
|
||||
uint16_t Loopv1, Loopv2, RegData;
|
||||
|
||||
Serial.print(F("Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F"));
|
||||
Serial.println();
|
||||
|
||||
for (Loopv1 = Start; Loopv1 <= End;) //32 lines
|
||||
{
|
||||
Serial.print(F("0x"));
|
||||
if (Loopv1 < 0x10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
Serial.print((Loopv1), HEX); //print the register number
|
||||
Serial.print(F(" "));
|
||||
for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
|
||||
{
|
||||
RegData = readRegister(Loopv1);
|
||||
if (RegData < 0x10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
Serial.print(RegData, HEX); //print the register number
|
||||
Serial.print(F(" "));
|
||||
Loopv1++;
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t readRegister(uint8_t reg)
|
||||
{
|
||||
uint8_t result = 0xFF;
|
||||
|
||||
if (reg < NUM_REGISTERS) {
|
||||
digitalWrite(CSN_PIN, LOW);
|
||||
SPI.transfer(CMD_R_REGISTER | reg);
|
||||
result = SPI.transfer(0xff);
|
||||
digitalWrite(CSN_PIN, HIGH);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
pinMode(CSN_PIN, OUTPUT);
|
||||
Serial.println();
|
||||
Serial.println(F("57_NRF24L01_Is_It_There ?"));
|
||||
Serial.println();
|
||||
SPI.begin();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 06/04/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 program to test a Serial Bluetooth device is working. The program
|
||||
uses software serial to send a Hello World message to a serial port. If the Bluetooth device is paired
|
||||
with an Android device you should see Hello World in an Andriod Bluetooth terminal application.
|
||||
|
||||
Bluetooth baud rate is set at 9600, an HC-06 Bluetooth device is assumed.
|
||||
Note that not all pins on all Arduinos will work with software serial, see here;
|
||||
|
||||
https://www.arduino.cc/en/Reference/softwareSerial
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
#define BlueToothBAUD 9600 //this is the serial baud rate that will be used for the Bluetooth, a common default
|
||||
#define MONITORBAUD 9600 //this is the serial baud rate that will be used for the serial monitor
|
||||
|
||||
#define RXpin A3 //this is the pin that the Arduino will use to receive data from the Bluetooth
|
||||
#define TXpin A2 //this is the pin that the Arduino can use to send data (commands) to the Bluetooth
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial BlueTooth(RXpin, TXpin);
|
||||
|
||||
uint32_t counter;
|
||||
|
||||
void loop()
|
||||
{
|
||||
BlueTooth.print(counter++);
|
||||
BlueTooth.println(F(" Hello World"));
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
BlueTooth.begin(BlueToothBAUD);
|
||||
Serial.begin(MONITORBAUD);
|
||||
Serial.println("61_Bluetooth_Test Starting");
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 08/09/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 program sends a command to a Quectel GPS to return its firmware revision.
|
||||
The output from the GPS is copied to the Serial Monitor.
|
||||
|
||||
If you get no data displayed on the serial monitor, the most likely cause is that you have the receive
|
||||
data pin into the Arduino (RX) pin connected incorrectly.
|
||||
|
||||
If the data displayed on the serial terminal appears to be random text with odd symbols its very
|
||||
likely you have the GPS serial baud rate set incorrectly.
|
||||
|
||||
Note that not all pins on all Arduinos will work with software serial, see here;
|
||||
|
||||
https://www.arduino.cc/en/Reference/softwareSerial
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
#define GPSBAUD 9600 //this is the serial baud rate that will be used for the GPS, a common default
|
||||
#define MONITORBAUD 115200 //this is the serial baud rate that will be used for the serial monitor
|
||||
|
||||
#define RXpin A3 //this is the pin that the Arduino will use to receive data from the GPS
|
||||
#define TXpin A2 //this is the pin that the Arduino can use to send data (commands) to the GPS - not used
|
||||
#define GPSPOWER 4 //When high this pin turns GPS on
|
||||
#define LED1 8 //when high this pin turns LED on
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial GPS(RXpin, TXpin);
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (GPS.available())
|
||||
{
|
||||
Serial.write(GPS.read());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(GPSPOWER, OUTPUT);
|
||||
digitalWrite(GPSPOWER, HIGH);
|
||||
|
||||
pinMode(LED1, OUTPUT);
|
||||
digitalWrite(LED1, HIGH);
|
||||
|
||||
GPS.begin(GPSBAUD);
|
||||
Serial.begin(MONITORBAUD);
|
||||
Serial.println("63_QuectelGPS_Firmware_Checker");
|
||||
delay(2000);
|
||||
GPS.println("$PMTK605*31");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 12/10/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 program uses a GPS to indicate speed, should work with most GPSs. Speed update
|
||||
rate approx once per second. GPS characters are output to serial monitor when checking for update from
|
||||
GPS. Prints speed in large text on an SSD1306 or SH1106 OLED.
|
||||
|
||||
Display and serial monitor updatesto speed only occur when the a new update has been decoded from the
|
||||
GPS.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <TinyGPS++.h> //get library here > http://arduiniana.org/libraries/tinygpsplus/
|
||||
TinyGPSPlus gps; //create the TinyGPS++ object
|
||||
|
||||
#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
|
||||
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPSserial(RXpin, TXpin);
|
||||
|
||||
#include <U8g2lib.h> //get library here > https://github.com/olikraus/u8g2
|
||||
#include <Wire.h>
|
||||
|
||||
U8G2_SSD1306_128X64_NONAME_1_HW_I2C disp(U8G2_R0, U8X8_PIN_NONE); //use this line for 0.96" SSD1306 OLED
|
||||
//U8G2_SH1106_128X64_NONAME_1_HW_I2C disp(U8G2_R0, U8X8_PIN_NONE); //use this line for 1.3" SH1106 OLED
|
||||
|
||||
float GPSSpeed; //Speed of GPS, mph
|
||||
|
||||
uint32_t startGetFixmS;
|
||||
uint32_t endFixmS;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (gpsWaitFix(3))
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Fix time "));
|
||||
Serial.print(endFixmS - startGetFixmS);
|
||||
Serial.println(F("mS"));
|
||||
|
||||
GPSSpeed = gps.speed.mph();
|
||||
|
||||
Serial.print(F("Speed,"));
|
||||
Serial.print(GPSSpeed, 1);
|
||||
Serial.println();
|
||||
|
||||
displayscreen1(); //print GPS data on display
|
||||
startGetFixmS = millis(); //have a fix, next thing that happens is checking for a fix, so restart timer
|
||||
}
|
||||
else
|
||||
{
|
||||
displayscreen2();
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Timeout - No GPS Fix "));
|
||||
Serial.print( (millis() - startGetFixmS) / 1000 );
|
||||
Serial.println(F("s"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool gpsWaitFix(uint16_t waitSecs)
|
||||
{
|
||||
//waits a specified number of seconds for a fix, returns true for good fix
|
||||
|
||||
uint32_t startmS, waitmS;
|
||||
uint8_t GPSchar;
|
||||
|
||||
Serial.print(F("Wait GPS Fix "));
|
||||
Serial.print(waitSecs);
|
||||
Serial.println(F(" seconds"));
|
||||
|
||||
waitmS = waitSecs * 1000; //convert seconds wait into mS
|
||||
startmS = millis();
|
||||
|
||||
while ((uint32_t) (millis() - startmS) < waitmS)
|
||||
{
|
||||
if (GPSserial.available() > 0)
|
||||
{
|
||||
GPSchar = GPSserial.read();
|
||||
gps.encode(GPSchar);
|
||||
Serial.write(GPSchar);
|
||||
}
|
||||
|
||||
if (gps.location.isUpdated() && gps.altitude.isUpdated() && gps.speed.isUpdated())
|
||||
{
|
||||
endFixmS = millis(); //record the time when we got a new GPS update
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void displayscreen1()
|
||||
{
|
||||
disp.setFont(u8g2_font_logisoso62_tn);
|
||||
disp.firstPage();
|
||||
do {
|
||||
disp.setCursor(0, 63);
|
||||
disp.print(GPSSpeed, 0);
|
||||
} while ( disp.nextPage() );
|
||||
}
|
||||
|
||||
|
||||
void displayscreen2()
|
||||
{
|
||||
disp.setFont(u8g2_font_lubB14_tr);
|
||||
disp.firstPage();
|
||||
do {
|
||||
disp.setCursor(35, 15);
|
||||
disp.print(F("Speedo"));
|
||||
disp.setCursor(15, 45);
|
||||
disp.print(F("No GPS fix"));
|
||||
} while ( disp.nextPage() );
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Serial.begin(115200);
|
||||
GPSserial.begin(9600);
|
||||
|
||||
disp.begin();
|
||||
disp.clear();
|
||||
displayscreen2();
|
||||
disp.print(F("Display Ready"));
|
||||
|
||||
Serial.println(F("72A_GPS_Speedo_With_Display Starting"));
|
||||
Serial.println();
|
||||
|
||||
startGetFixmS = millis();
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 30/12/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 program uses a GPS to indicate speed, should work with most GPSs. Speed update
|
||||
rate approx onece per second. GPS characters are output to serial monitor when checking for update from
|
||||
GPS.
|
||||
|
||||
Serial monitor baud rate is set at 115200.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <TinyGPS++.h> //get library here > http://arduiniana.org/libraries/tinygpsplus/
|
||||
TinyGPSPlus gps; //create the TinyGPS++ object
|
||||
|
||||
#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
|
||||
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial GPSserial(RXpin, TXpin);
|
||||
|
||||
float GPSSpeed; //Speed of GPS, mph
|
||||
|
||||
uint32_t startGetFixmS;
|
||||
uint32_t endFixmS;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (gpsWaitFix(5))
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Fix time "));
|
||||
Serial.print(endFixmS - startGetFixmS);
|
||||
Serial.println(F("mS"));
|
||||
|
||||
GPSSpeed = gps.speed.mph();
|
||||
|
||||
Serial.print(F("Speed,"));
|
||||
Serial.print(GPSSpeed, 1);
|
||||
Serial.println();
|
||||
|
||||
startGetFixmS = millis(); //have a fix, next thing that happens is checking for a fix, so restart timer
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.print(F("Timeout - No GPS Fix "));
|
||||
Serial.print( (millis() - startGetFixmS) / 1000 );
|
||||
Serial.println(F("s"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool gpsWaitFix(uint16_t waitSecs)
|
||||
{
|
||||
//waits a specified number of seconds for a fix, returns true for good fix
|
||||
|
||||
uint32_t startmS, waitmS;
|
||||
uint8_t GPSchar;
|
||||
|
||||
Serial.print(F("Wait GPS Fix "));
|
||||
Serial.print(waitSecs);
|
||||
Serial.println(F(" seconds"));
|
||||
|
||||
waitmS = waitSecs * 1000; //convert seconds wait into mS
|
||||
startmS = millis();
|
||||
|
||||
while ((uint32_t) (millis() - startmS) < waitmS)
|
||||
{
|
||||
if (GPSserial.available() > 0)
|
||||
{
|
||||
GPSchar = GPSserial.read();
|
||||
gps.encode(GPSchar);
|
||||
Serial.write(GPSchar);
|
||||
}
|
||||
|
||||
if (gps.location.isUpdated() && gps.altitude.isUpdated() && gps.speed.isUpdated())
|
||||
{
|
||||
endFixmS = millis(); //record the time when we got a new GPS update
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Serial.begin(115200);
|
||||
GPSserial.begin(9600);
|
||||
|
||||
Serial.println(F("72_GPS_Speedo Starting"));
|
||||
Serial.println();
|
||||
|
||||
startGetFixmS = millis();
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 30/09/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 program is a simple test program for the LIL9341 TFT display that comes in a
|
||||
range of sizes. The program prints a short message on each line, pauses, clears the screen, and starts
|
||||
again. Program uses Adafruit ILI9341 library.
|
||||
|
||||
Screen write time on Arduino DUE 332mS, screen clear 268mS
|
||||
Screen write time on Teensy 4.1 207mS, screen clear 180mS
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include "SPI.h"
|
||||
#include "Adafruit_GFX.h" //get library here > https://github.com/adafruit/Adafruit-GFX-Library
|
||||
#include "Adafruit_ILI9341.h" //get library here > https://github.com/adafruit/Adafruit_ILI9341
|
||||
|
||||
int8_t DISPCS = 10;
|
||||
int8_t DISPDC = 8;
|
||||
|
||||
//int8_t DISPCS = 43; //for DUE shield
|
||||
//int8_t DISPDC = 45; //for DUE shield
|
||||
|
||||
Adafruit_ILI9341 disp = Adafruit_ILI9341(DISPCS, DISPDC);
|
||||
|
||||
#define textscale 2 //default text scale
|
||||
|
||||
uint16_t writecount;
|
||||
uint32_t startmS, endmS, timemS;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
setCursor(0, 0);
|
||||
disp.setTextColor(ILI9341_WHITE);
|
||||
disp.setTextSize(textscale);
|
||||
|
||||
writecount++;
|
||||
Serial.print(writecount);
|
||||
Serial.print(F(" Writing to display"));
|
||||
|
||||
startmS = millis();
|
||||
disp.fillScreen(ILI9341_BLACK); //clear screen
|
||||
screen1();
|
||||
endmS = millis();
|
||||
timemS = endmS - startmS;
|
||||
setCursor(8, 4);
|
||||
disp.print(timemS);
|
||||
disp.print(F("mS"));
|
||||
|
||||
Serial.print(F(" - done "));
|
||||
Serial.print(timemS);
|
||||
Serial.println(F("mS"));
|
||||
|
||||
delay(2000);
|
||||
|
||||
startmS = millis();
|
||||
disp.fillScreen(ILI9341_BLACK); //clear screen
|
||||
endmS = millis();
|
||||
timemS = endmS - startmS;
|
||||
setCursor(0, 0);
|
||||
disp.print(F("Screen clear "));
|
||||
disp.print(timemS);
|
||||
disp.print(F("mS"));
|
||||
|
||||
delay(2000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void setCursor(uint8_t lcol, uint8_t lrow)
|
||||
{
|
||||
disp.setCursor((lcol * 6 * textscale), (lrow * 10 * textscale));
|
||||
}
|
||||
|
||||
|
||||
void screen1()
|
||||
{
|
||||
setCursor(0, 0);
|
||||
disp.print(F("ILI9341_Checker"));
|
||||
|
||||
setCursor(0, 1);
|
||||
disp.print(F("Line 1"));
|
||||
|
||||
setCursor(0, 2);
|
||||
disp.print(F("Line 2"));
|
||||
|
||||
setCursor(0, 3);
|
||||
disp.print(F("Line 3"));
|
||||
|
||||
setCursor(0, 4);
|
||||
disp.print(F("Line 4"));
|
||||
|
||||
setCursor(0, 5);
|
||||
disp.print(F("Line 5"));
|
||||
|
||||
setCursor(0, 6);
|
||||
disp.print(F("Line 6"));
|
||||
|
||||
setCursor(0, 7);
|
||||
disp.print(F("Line 7"));
|
||||
|
||||
setCursor(0, 8);
|
||||
disp.print(F("Line 8"));
|
||||
|
||||
setCursor(0, 9);
|
||||
disp.print(F("Line 9"));
|
||||
|
||||
setCursor(0, 10);
|
||||
disp.print(F("Line 10"));
|
||||
|
||||
setCursor(0, 11);
|
||||
disp.print(F("01234567890123456789012")); //display is 12 lines x 23 charaters
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("77_ILI9341_Display_Checker starting"));
|
||||
SPI.begin();
|
||||
disp.begin();
|
||||
//disp.setFont(Arial_16);
|
||||
disp.fillScreen(ILI9341_BLACK);
|
||||
disp.setTextColor(ILI9341_WHITE);
|
||||
disp.setRotation(1);
|
||||
disp.setTextSize(textscale);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 14/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 is a simple terminal to allow you to use a Serial terminal program, such as Teraterm
|
||||
or CoolTerm to talk to a serial device such as a Bluetooth module connected to your Arduino.
|
||||
|
||||
Note that not all pins on all Arduinos will work with software serial, see here;
|
||||
|
||||
https://www.arduino.cc/en/Reference/softwareSerial
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
#define DEVICEBAUD 9600 //serial baud rate that will be used for the device conncted to your Arduino
|
||||
#define MONITORBAUD 9600 //serial baud rate that will be used for the serial monitor
|
||||
|
||||
#define RXpin A3 //this is the pin that the Arduino will use to receive data from the serial device
|
||||
#define TXpin A2 //this is the pin that the Arduino can use to send data (commands) to the serial device
|
||||
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
SoftwareSerial device(RXpin, TXpin);
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (device.available())
|
||||
{
|
||||
Serial.write(device.read());
|
||||
}
|
||||
|
||||
while (Serial.available())
|
||||
{
|
||||
device.write(Serial.read());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
device.begin(DEVICEBAUD);
|
||||
Serial.begin(MONITORBAUD);
|
||||
Serial.println("79_Serial_Terminal Starting");
|
||||
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*******************************************************************************************************
|
||||
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 - This is a simple test for a Bosch BME280 sensor. Readings are sent to the serial
|
||||
monitor. The Seeed library assumes the BME280 is at address 0x76. It can be changed to 0x77 by an edit
|
||||
in the Seeed_BME280.h librsry file.
|
||||
|
||||
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_REGISTER_CONTROL 0xF4 //BME280 register number for power control
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#define LED1 8 //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(500);
|
||||
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 starting"));
|
||||
|
||||
bme280.init();
|
||||
Serial.println(F("Initialised BME280"));
|
||||
Serial.println();
|
||||
|
||||
readSensors(); //do an initial sensor read
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//see the video here > https://www.youtube.com/watch?v=eeDC1m7ANJI&t=100s
|
||||
//code here > https://gist.github.com/speters/f889faec42b510052a6ab4be437d38ca
|
||||
|
||||
//Purpose is to simply run a memory check on ATMEGA238P to test for counterfeit parts
|
||||
|
||||
#include <avr/boot.h>
|
||||
#define SIGRD 5
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("");
|
||||
Serial.println("boot sig dump");
|
||||
int newLineIndex = 0;
|
||||
for (uint8_t i = 0; i <= 0x1F; i += 1) {
|
||||
Serial.print(boot_signature_byte_get(i), HEX);
|
||||
Serial.print("\t");
|
||||
newLineIndex++;
|
||||
if (newLineIndex == 8) {
|
||||
Serial.println("");
|
||||
newLineIndex = 0;
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// ArduinoUniqueID.ino
|
||||
//
|
||||
// Example shows the UniqueID on the Serial Monitor.
|
||||
//
|
||||
|
||||
#include <ArduinoUniqueID.h> //get library here > https://github.com/ricaun/ArduinoUniqueID
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
UniqueIDdump(Serial);
|
||||
Serial.print("UniqueID: ");
|
||||
for (size_t i = 0; i < UniqueIDsize; i++)
|
||||
{
|
||||
if (UniqueID[i] < 0x10)
|
||||
Serial.print("0");
|
||||
Serial.print(UniqueID[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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, 3);
|
||||
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_OLED_Checker starting"));
|
||||
disp.begin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user