I am working with Rpi Pico using arduino IDE:
I am facing issues with different uarts of pico ( UART 1 & UART 0) not working simultaneously in the integrated code of whole system.
Basically I have used a GPS module at another UART and radio module at different UART. I tried using separately GPS and it worked, but with integrated code both uarts ( UART 1 & UART 0) not working simultaneously. I also tried different ways for debugging like checking GPIO pins of UART with actual physical pins on the Rpi Pico. I have indicated the block which has problem using this comment : /This UART block -->/
My reference of Rpi Pico UARTs : Rpi Pico UARTs
The code:
// MAIN BALLOON TESTING CODE - By Vivek Samani
// Send b or B to trigger the burn wire from GS
// Serial transmit string format: Read_Count, gps_Altd, Lat, Lng, Sats, Hf, T, Po
/* ************ PROJECT DESCRIPTION ************
HOT AIR BALLOON - MODEL SATELLITE DROP TEST
Hardware description:
MCU : Rpi Pico
Burn wire triggering: MOSFET Module
LOCATION: L89 GPS module
Temp / Absolute Altitude / Pressure: BMP 280
For Burnner valve control: Servo SG90
Radio Module: LORA EBYTE E22 400T30D
GS : Ground station occupied with LORA With (viaz TTL to USB) laptop and monitoring data on CUTECOM Software)
*/
// Including necessary libraries
#include <Wire.h>
#include <Servo.h>
#include <TinyGPS++.h>
#include <Adafruit_BMP280.h>
#include <SimpleKalmanFilter.h>
// LORA Rx & Tx pins declaration
#define LORA_Tx 16
#define LORA_Rx 17
// GPS @ Rx & Tx pins declaration
#define Tx_UART1 8
#define Rx_UART1 9
#define burn_pin 15
// Servo pin
#define svr_pin 22
bool newData;
float incoming_serial_pressure, Po, Pf;
SimpleKalmanFilter pressureKalmanFilter(1, 1, 1);
// Instance and object declaration6h
Servo svr;
TinyGPSPlus gps;
Adafruit_BMP280 bmp;
// Serial output refresh time
unsigned long refresh_time;
const long SERIAL_REFRESH_TIME = 100;
volatile float gps_Altd, Lat, Long, Hf, T, P, H;
volatile signed int Sats, svr_pos = 0, Read_Count = 1;
void setup() {
// GPS Baud Rates and UART declaration
Serial2.setTX(Tx_UART1);
Serial2.setRX(Rx_UART1);
Serial2.begin(9600);
// LORA Baud Rates and UART declaration
Serial1.setTX(LORA_Tx);
Serial1.setRX(LORA_Rx);
Serial1.begin(9600);
// Serial monitor baud rate
Serial.begin(9600);
// Attach & Set servo to initial position
svr.attach(svr_pin);
svr.write(svr_pos);
// Check the status of sensor
unsigned status;
status = bmp.begin(0x76);
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
}
// Defining sampling rates for BMP280
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_1); /* Standby time. */
// Set reference pressure
for (int i = 0; i < 10; i++) {
incoming_serial_pressure += bmp.readPressure();
// wait for next reading
delay(200);
}
// Reference pressure
Po = incoming_serial_pressure / 10;
P = Po;
}
void loop() {
// send to Serial output every 100ms
if (millis() > refresh_time) {
/* Activate burn wire or Rotate servo as per command */
/*This UART block -->*/ if (Serial1.available() > 0) {
char receivedChar = Serial1.read();
if (receivedChar == 'B' || receivedChar == 'b') {
BurnWire();
}
svr_pos = Serial1.read();
if (svr_pos >= 0 || svr_pos <= 180) {
svr.write(svr_pos);
}
}
// Collect data from L89 GPS Module
/*This UART block -->*/
if (Serial2.available() > 0) {
if (gps.encode(Serial2.read())) {
Serial.print("# READING NO:- ");
Serial.println(Read_Count);
Serial.print("SATS :- ");
Serial.println(gps.satellites.value());
Serial.print("LAT :- ");
Serial.println(gps.location.lat(), 7);
Serial.print("LONG :- ");
Serial.println(gps.location.lng(), 7);
Serial.print("ALT :- ");
Serial.println(gps.altitude.meters());
Read_Count++;
}
}
// filtered_pressure_value
Pf = pressureKalmanFilter.updateEstimate(bmp.readPressure());
// measured altitude
H = bmp.readAltitude(Po * 0.01);
// measured temprature
T = bmp.readTemperature();
// filtered altitude
Hf = 44330 * (1 - pow((Pf / Po), (0.1903)));
// Read_Count, gps_Altd, Lat, Lng, Sats, Hf, T, Po
String csvData = String(Read_Count) + "," + String(gps_Altd) + "," + String(Lat) + "," + String(Long) + "," + String(Sats) + "," + String(Hf) + "," + String(T) + "," + String(Po);
Serial1.println(csvData);
Serial.println(csvData);
Read_Count += 1;
refresh_time = millis() + SERIAL_REFRESH_TIME;
}
}
void BurnWire() {
static bool executed = false;
if (!executed) {
Serial.println(" BURN WIRE TRIGGERED SUCCESSFULLY !! ");
digitalWrite(burn_pin, HIGH);
delay(1000);
digitalWrite(burn_pin, LOW);
}
executed = true;
}