Okay, I did some troubleshooting and didn’t found the solution yet, but:
- I can confirm the Vext pin is LOW all the time when on battery
- The UART_RX2 pin of the board is HIGH when running on battery
Basically after I plug in the usb cable I become the valid output…
Here is my code:
#include "LoRaWan_APP.h"
#include "Arduino.h"
#include <TinyGPS++.h>
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
#define RF_FREQUENCY 868E6 // Hz
#define TX_OUTPUT_POWER 20 // dBm
#define LORA_BANDWIDTH 1 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 11 // [SF7..SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 50 // Define the payload size here
char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
int counter = 0;
static RadioEvents_t RadioEvents;
int16_t rssi, rxSize;
void DoubleToString( char *str, double double_num, unsigned int len);
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Serial1.available())
gps.encode(Serial1.read());
} while (millis() - start < ms);
}
void setup() {
boardInitMcu();
pinMode(Vext, OUTPUT);
// pinMode(UART_TX2, OUTPUT);
// pinMode(UART_RX2, OUTPUT);
digitalWrite(Vext, LOW);
// pinMode(UART_RX,OUTPUT);
// digitalWrite(UART_RX,1);
// digitalWrite(UART_TX2, LOW);
// digitalWrite(UART_RX2, LOW);
delay(500);
Serial.begin(115200);
Serial1.begin(GPSBaud);
rssi = 0;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
}
void loop()
{
sendShortMsg();
Serial.println(digitalRead(UART_RX2));
delay(1000);
while (Serial1.available() > 0) {
if (gps.encode(Serial1.read())) {
sendMsg();
return;
}
}
}
void sendMsg() {
if (gps.location.isValid()) {
sprintf(txpacket, "");
Serial.println("\r\nsending packet");
sprintf(txpacket, "lat: %d.%d lng: %d.%d", (int)gps.location.lat(), abs(fracPart(gps.location.lat(), 6)), (int)gps.location.lng(), abs(fracPart(gps.location.lng(), 5)));
//sprintf(txpacket,"lng: %d.%d",(int)gps.location.lng(),abs(fracPart(gps.location.lng(),6)));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out
}
}
void sendShortMsg() {
sprintf(txpacket, "");
Serial.println("\r\nsending day: "+ String(gps.date.day()) + " year " + String(gps.date.year()));
sprintf(txpacket, "ssa: %d/%d/%d/%d/%d", digitalRead(Vext),gps.date.day(), gps.date.month(), gps.date.year(), digitalRead(UART_RX2));
//sprintf(txpacket,"lng: %d.%d",(int)gps.location.lng(),abs(fracPart(gps.location.lng(),6)));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out
}
/**
@brief Double To String
@param str: Array or pointer for storing strings
@param double_num: Number to be converted
@param len: Fractional length to keep
@retval None
*/
void DoubleToString( char *str, double double_num, unsigned int len) {
double fractpart, intpart;
fractpart = modf(double_num, &intpart);
fractpart = fractpart * (pow(10, len));
sprintf(str + strlen(str), "%d", (int)(intpart)); //Integer part
sprintf(str + strlen(str), ".%d", (int)(fractpart)); //Decimal part
}
int fracPart(double val, int n)
{
return (int)((val - (int)(val)) * pow(10, n));
}
Would very much appriciate any help on this one! (Reading GPS value on battery)
Cheers, bockwurstpaule