Skip to content

Commit 82c0c5b

Browse files
committed
Fix BT RX of NTRIP data
The trick was setting the BT timeout to 1ms.
1 parent 01b316e commit 82c0c5b

File tree

6 files changed

+165
-15
lines changed

6 files changed

+165
-15
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
September 1st, 2020
3+
SparkFun Electronics
4+
Nathan Seidle
5+
6+
*/
7+
8+
#include <Wire.h> //Needed for I2C to GPS
9+
10+
11+
// setting PWM properties
12+
const int freq = 5000;
13+
const int ledRedChannel = 0;
14+
const int ledGreenChannel = 1;
15+
const int resolution = 8;
16+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
17+
18+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
19+
//Setup hardware serial and BT buffers
20+
#include "BluetoothSerial.h"
21+
BluetoothSerial SerialBT;
22+
23+
HardwareSerial GPS(2);
24+
#define RXD2 16
25+
#define TXD2 17
26+
27+
#define SERIAL_SIZE_RX 1024 * 16 //Using a large buffer. This might be much bigger than needed but the ESP32 has enough RAM
28+
uint8_t rBuffer[SERIAL_SIZE_RX]; //Buffer for reading F9P
29+
uint8_t wBuffer[SERIAL_SIZE_RX]; //Buffer for writing to F9P
30+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
31+
32+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
33+
//Hardware connections v11
34+
const int positionAccuracyLED_1cm = 2;
35+
const int baseStatusLED = 4;
36+
const int baseSwitch = 5;
37+
const int bluetoothStatusLED = 12;
38+
const int positionAccuracyLED_100cm = 13;
39+
const int positionAccuracyLED_10cm = 15;
40+
const int sd_cs = 25;
41+
const int zed_tx_ready = 26;
42+
const int zed_reset = 27;
43+
const int batteryLevelLED_Red = 32;
44+
const int batteryLevelLED_Green = 33;
45+
const int batteryLevel_alert = 36;
46+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
47+
48+
void setup()
49+
{
50+
Serial.begin(115200); //UART0 for programming and debugging
51+
Serial.setRxBufferSize(SERIAL_SIZE_RX);
52+
Serial.setTimeout(1);
53+
54+
GPS.begin(115200); //UART2 on pins 16/17 for SPP. The ZED-F9P will be configured to output NMEA over its UART1 at 115200bps.
55+
GPS.setRxBufferSize(SERIAL_SIZE_RX);
56+
GPS.setTimeout(1);
57+
58+
Wire.begin();
59+
60+
Serial.println("SparkFun RTK Surveyor v1.0");
61+
62+
pinMode(positionAccuracyLED_1cm, OUTPUT);
63+
pinMode(positionAccuracyLED_10cm, OUTPUT);
64+
pinMode(positionAccuracyLED_100cm, OUTPUT);
65+
pinMode(baseStatusLED, OUTPUT);
66+
pinMode(bluetoothStatusLED, OUTPUT);
67+
pinMode(baseSwitch, INPUT_PULLUP); //HIGH = rover, LOW = base
68+
69+
digitalWrite(positionAccuracyLED_1cm, LOW);
70+
digitalWrite(positionAccuracyLED_10cm, LOW);
71+
digitalWrite(positionAccuracyLED_100cm, LOW);
72+
digitalWrite(baseStatusLED, LOW);
73+
digitalWrite(bluetoothStatusLED, LOW);
74+
75+
//SerialBT.register_callback(btCallback);
76+
if (startBluetooth() == false)
77+
{
78+
Serial.println("An error occurred initializing Bluetooth");
79+
digitalWrite(bluetoothStatusLED, LOW);
80+
}
81+
else
82+
{
83+
digitalWrite(bluetoothStatusLED, HIGH);
84+
}
85+
86+
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
87+
}
88+
89+
void loop()
90+
{
91+
92+
delay(10); //Required if no other I2C or functions are called
93+
94+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED
2+
//Task for writing to the GNSS receiver
3+
void F9PSerialWriteTask(void *e)
4+
{
5+
while (true)
6+
{
7+
if (SerialBT.available())
8+
{
9+
while (SerialBT.available())
10+
{
11+
auto s = SerialBT.readBytes(wBuffer, SERIAL_SIZE_RX);
12+
GPS.write(wBuffer, s);
13+
}
14+
}
15+
16+
taskYIELD();
17+
}
18+
}
19+
20+
//Tack device's MAC address to end of friendly broadcast name
21+
//This allows multiple units to be on at same time
22+
bool startBluetooth()
23+
{
24+
uint8_t mac[6];
25+
esp_read_mac(mac, ESP_MAC_WIFI_STA);
26+
mac[5] += 2; //Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
27+
28+
char deviceName[20];
29+
if (digitalRead(baseSwitch) == HIGH)
30+
{
31+
//Rover mode
32+
sprintf(deviceName, "Surveyor Rover-%02X%02X", mac[4], mac[5]);
33+
}
34+
else
35+
{
36+
//Base mode
37+
sprintf(deviceName, "Surveyor Base-%02X%02X", mac[4], mac[5]);
38+
}
39+
40+
if (SerialBT.begin(deviceName) == false)
41+
return (false);
42+
Serial.print("Bluetooth broadcasting as: ");
43+
Serial.println(deviceName);
44+
45+
//Start the tasks.
46+
//Can also use xTaskCreatePinnedToCore to pin a task to one of the two cores
47+
//on the ESP32
48+
//xTaskCreate(F9PSerialReadTask, "F9Read", 10000, NULL, 0, NULL);
49+
xTaskCreate(F9PSerialWriteTask, "F9Write", 10000, NULL, 0, NULL);
50+
51+
SerialBT.setTimeout(1);
52+
53+
return (true);
54+
}

Firmware/RTK_Enclosed/RTK_Enclosed.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,6 @@ void loop()
321321
}
322322

323323
updateBattLEDs();
324+
delay(10); //Required if no other I2C or functions are called
324325

325326
}

Firmware/RTK_Enclosed/System.ino

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
uint8_t settingPayload[MAX_PAYLOAD_SIZE]; //This array holds the payload data bytes. Global so that we can use between config functions.
33

4-
//If the phone has any new data (NTRIP RTCM, etc), pass it out over Bluetooth
4+
//If the phone has any new data (NTRIP RTCM, etc), read it in over Bluetooth and pass along to ZED
55
//Task for writing to the GNSS receiver
66
void F9PSerialWriteTask(void *e)
77
{
@@ -14,10 +14,15 @@ void F9PSerialWriteTask(void *e)
1414
auto s = Serial.readBytes(wBuffer, SERIAL_SIZE_RX);
1515
GPS.write(wBuffer, s);
1616
}
17-
else if (SerialBT.connected() && SerialBT.available())
17+
// else if (SerialBT.connected() && SerialBT.available())
18+
19+
if (SerialBT.available())
1820
{
19-
auto s = SerialBT.readBytes(wBuffer, SERIAL_SIZE_RX);
20-
GPS.write(wBuffer, s);
21+
while (SerialBT.available())
22+
{
23+
auto s = SerialBT.readBytes(wBuffer, SERIAL_SIZE_RX);
24+
GPS.write(wBuffer, s);
25+
}
2126
}
2227

2328
taskYIELD();
@@ -115,17 +120,9 @@ bool configureUbloxModule()
115120

116121
//When receiving 15+ satellite information, the GxGSV sentences can be a large amount of data
117122
//If the update rate is >1Hz then this data can overcome the BT capabilities causing timeouts and lag
118-
if (gnssUpdateRate == 1)
119-
{
120-
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != 1)
121-
response &= myGPS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
122-
}
123-
else
124-
{
125-
//Turn off satellite sentences
126-
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != 0)
127-
response &= myGPS.disableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1);
128-
}
123+
//So we set the GSV sentence to 1Hz regardless of update rate
124+
if (getNMEASettings(UBX_NMEA_GSV, COM_PORT_UART1) != gnssUpdateRate)
125+
response &= myGPS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_UART1, gnssUpdateRate);
129126

130127
if (getNMEASettings(UBX_NMEA_RMC, COM_PORT_UART1) != 1)
131128
response &= myGPS.enableNMEAMessage(UBX_NMEA_RMC, COM_PORT_UART1);
@@ -378,6 +375,8 @@ bool startBluetooth()
378375
xTaskCreate(F9PSerialReadTask, "F9Read", 10000, NULL, 0, NULL);
379376
xTaskCreate(F9PSerialWriteTask, "F9Write", 10000, NULL, 0, NULL);
380377

378+
SerialBT.setTimeout(1);
379+
381380
return (true);
382381
}
383382

0 commit comments

Comments
 (0)