I am fairly new to the using Freertos and rtos in general and would like to build an application that;
- Creates two global variables name longitude and latitude
- Blinks two LEDs alternately at a rate of 1 seconds each.
- Receive GPS location data (longitude and latitude) and store them in the global variables. This will run at a rate of 10seconds
- To check if longtitude and latitude values have been updated and display their new value in the serial monitor.
2,3,4 and written as separate tasks. I have also attached my code.
#include <Arduino_FreeRTOS.h>
#include <TinyGPS++.h>
#define led1 4
#define led2 6
double longitude;
double latitude;
TinyGPSPlus gps;
void GetGPS(void *pvParameters);
void BlinkLed1(void *pvParameters);
void BlinkLed2(void *pvParameters);
void PrintGPS(void *pvParameters);
//void SendData(void *pvParameters);
//void GetWeights(void *pvParameters);
void setup() {
Serial.begin(115200); // For serial monitor
Serial1.begin(115200); // For GPS connections
Serial1.println("AT+GPS=1"); // atmega32u4[TX] -> A9G[RX]
xTaskCreate(GetGPS,"gps",128,NULL,3,NULL);
xTaskCreate(BlinkLed1,"led 1",128,NULL,1,NULL);
xTaskCreate(BlinkLed2,"led 2",128,NULL,1,NULL);
xTaskCreate(PrintGPS,"print locations",128,NULL,2,NULL);
vTaskStartScheduler();
}
void loop() {
//pass
}
void BlinkLed1(void *pvParameters){
pinMode(led1,OUTPUT);
while (1) {
digitalWrite(led1,HIGH);
vTaskDelay(1000/portTICK_PERIOD_MS);
digitalWrite(led1,LOW);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
void BlinkLed2(void *pvParameters){
pinMode(led2,OUTPUT);
while (1) {
digitalWrite(led2,LOW);
vTaskDelay(1000/portTICK_PERIOD_MS);
digitalWrite(led2,HIGH);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
void GetGPS(void *pvparameters) {
Serial1.println("AT+GPSRD=10");
while (1) {
if (Serial1.available() > 0)
if (gps.encode(Serial1.read())) {
longitude = gps.location.lng();
latitude = gps.location.lat();
}
vTaskDelay(10000/portTICK_PERIOD_MS);
}
}
void PrintGPS(void *pvParameters){
while (1) {
// Check if there is any data in the variables
if (longitude != 0.0 && latitude != 0.0) {
// Display the data on the serial monitor
Serial.print("Longitude: ");
Serial.println(longitude);
Serial.print("Latitude: ");
Serial.println(latitude);
// Reset the variables
longitude = 0.0;
latitude = 0.0;
}
// Wait for 1 second before checking again
vTaskDelay(10000 / portTICK_PERIOD_MS);
}
}
The LEDs bit work however there is nothing displayed in the serial monitor to indicate if I am a getting anything from the GPS module. However the same code for getting the GPS readings work when running bare-metal. Could someone guide me to the right resources on how to get it done well. Thanks in advance