#include <Arduino.h>
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
bool Initialise();
SFE_UBLOX_GNSS _gnss;
void setup()
{
Wire.begin();
vTaskDelay(10);
while(!_gnss.begin())
{
digitalToggle(LED_BLUE);
digitalToggle(LED_GREEN);
vTaskDelay(1000);
}
}
void loop() {
}
This to me, is even more simple than the example you pointed to, and this works āsometimesā and doesnāt work other times ā¦ what baffles me the most is that BOTH of the boards I am working with were working perfectly fine on Saturday, and then yesterday when I got back to them (because it was a bank holiday here on Monday), they just stopped working.
BatteryWatchdog_t BatteryWatchdog;
FlashChoreographer_t* startup_light;
TickType_t _lastRun;
void setup()
{
time_t timeout = millis();
Serial.begin(115200);
startup_light = new FlashChoreographer_t();
startup_light->CreateTask(FAIL_LED);
while (!Serial && ((millis() - timeout) < 5000))
{
startup_light->Flash(1);
vTaskDelay(250);
}
lora_rak4630_init();
Wire.begin();
while(!gpsUnit.Initialize())
{
#ifdef CONNECTED_FOR_DEBUG
Serial.println(F("u-blox GNSS not detected at default I2C address."));
#endif // CONNECTED_FOR_DEBUG
digitalToggle(SUCCESS_LED);
digitalToggle(FAIL_LED);
vTaskDelay(500);
}
digitalWrite(SUCCESS_LED, LOW);
digitalWrite(FAIL_LED, LOW);
BatteryWatchdog.CreateTask();
gpsTaskMaster.Initialize(BatteryWatchdog.GetMailBox());
RadioTransmitter.Initialize(SUCCESS_LED, FAIL_LED);
gpsTaskMaster.CreateTrackerTask(&gpsUnit);
gpsTaskMaster.CreateReporterTask(&RadioTransmitter);
}
void loop() { vTaskDelay(pdMS_TO_TICKS(50)); }
BatteryWatchdog_t
is a task whose responsibility is to check the battery voltage and then overwite the message in a Mailbox (queue with only one entry which is never removed, but is overwitten with new values as they change). gpsTaskMaster
is a class which wraps two OS Task
instances, one task (TrackerTask
) is responsible for collecting data from the GPS module and placing that data onto a queue, which the other (ReporterTask
) removes, formats and passes over to the RadioTransmitter
This is the code which was working as expected when I finished up on Saturday. Yesterday morning we had a brief discussion here and decided that we would now like to make sure that the program does not attempt to start up the radio or the GPS module if the battery charge is below a specified level. The following is the change I made to achieve that.
- I added
#include "BatteryReader.h"
in main.cpp
- Immediately prior to the call to
lora_rak4630_init();
in the setup
function shown above I added if(BatteryReader_t::ReadVoltage() <= LOWEST_ALLOWED_BATTERY_VOLTAGE) { return; }
which would stop all board initialisation -this would leave the board powered on, but with a program with would simply run the loop
function, so that we can charge the battery without it being dsicharged further.
This is the BatteryReader.h file (just for clarification of what it is doing)
typedef class ClsBatteryReader
{
private:
static const uint32_t vbat_pin = PIN_VBAT;
public:
static float ReadVoltage(void)
{
float raw;
raw = analogRead(vbat_pin); // Get the raw 12-bit, 0..3000mV ADC value
return raw * REAL_VBAT_MV_PER_LSB;
}
} BatteryReader_t;
When I uploaded that change to the board (which was connected via USB) I noticed that the board was not transmitting any data (we flash the onboard blue LED when a transmission is completed and it was not flashing). I opened comms on the connected port and there was no information coming through, which then led me to believe that the BatteryReader
test had failed and we were now in the empty loop()
.
So I made a further change:
void loop()
{
Serial.printf("Voltage : %04.f", BatteryReader_t::ReadVoltage());
vTaskDelay(pdMS_TO_TICKS(500));
}
Then, when I ran the program and opened up the COM port, I viewed readings like the following
Voltage : 0809
Voltage : 0854
Voltage : 0906
Voltage : 0862
So it was only registering as 0.8V. Something which I found to be incredibly odd, since the board was currently being powered by the connected USB.
I then swapped the USB cable out thinking that maybe there was a fault on that, but no, I got hte same readings. I had decided that there must be something wrong with the code and that I must have introduced some other change that had resulted in these strange readings, so I reverted all of my changes, uploaded the program to the board and that is when the GPS unit started failing consistently in an inconsistent manner (if that makes sense)