Skip to content

Commit 660ab06

Browse files
committed
RAK4631 ESM Migration
Changes to migrate sensor code to the ESM. Added a separate GPS init sequence for the RAK that scans I2C and Serial1 on the various sockets of the various base boards to find the RAK12500. (and soon the RAK12501) Removed the GPS specific envs from platformio.ini and enabled GPS for all envs. Verified working with RAK12500 on RAK19007 sockets A and D, as well as RAK19003.
1 parent 6a6221f commit 660ab06

File tree

6 files changed

+146
-520
lines changed

6 files changed

+146
-520
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,26 @@ static Adafruit_INA3221 INA3221;
4747
static Adafruit_INA219 INA219(TELEM_INA219_ADDRESS);
4848
#endif
4949

50+
#if ENV_INCLUDE_GPS & RAK_BOARD
51+
uint32_t gpsResetPin = 0;
52+
bool i2cGPSFlag = false;
53+
bool serialGPSFlag = false;
54+
//#define PIN_GPS_STANDBY_A 34 //GPS Reset/Standby pin (IO2 for socket A)
55+
//#define PIN_GPS_STANDBY_C 4 //GPS Reset/Standby pin (IO4 for socket C)
56+
//#define PIN_GPS_STANDBY_F 9 //GPS Reset/Standby pin (IO5 for socket F)
57+
#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c
58+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
59+
static SFE_UBLOX_GNSS ublox_GNSS;
60+
#endif
61+
5062
bool EnvironmentSensorManager::begin() {
5163
#if ENV_INCLUDE_GPS
64+
#if RAK_BOARD
65+
rakGPSInit(); //probe base board/sockets for GPS
66+
#else
5267
initBasicGPS();
5368
#endif
69+
#endif
5470

5571
#if ENV_INCLUDE_AHTX0
5672
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) {
@@ -296,8 +312,87 @@ void EnvironmentSensorManager::initBasicGPS() {
296312
gps_active = false; //Set GPS visibility off until setting is changed
297313
}
298314

315+
#ifdef RAK_BOARD
316+
void EnvironmentSensorManager::rakGPSInit(){
317+
318+
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
319+
320+
#ifdef GPS_BAUD_RATE
321+
Serial1.begin(GPS_BAUD_RATE);
322+
#else
323+
Serial1.begin(9600);
324+
#endif
325+
326+
delay(1000);
327+
328+
//search for the correct IO standby pin depending on socket used
329+
if(gpsIsAwake(WB_IO2)){
330+
// MESH_DEBUG_PRINTLN("RAK base board is RAK19007/10");
331+
// MESH_DEBUG_PRINTLN("GPS is installed on Socket A");
332+
}
333+
else if(gpsIsAwake(WB_IO4)){
334+
// MESH_DEBUG_PRINTLN("RAK base board is RAK19003/9");
335+
// MESH_DEBUG_PRINTLN("GPS is installed on Socket C");
336+
}
337+
else if(gpsIsAwake(WB_IO5)){
338+
// MESH_DEBUG_PRINTLN("RAK base board is RAK19001/11");
339+
// MESH_DEBUG_PRINTLN("GPS is installed on Socket F");
340+
}
341+
else{
342+
MESH_DEBUG_PRINTLN("No GPS found");
343+
gps_active = false;
344+
gps_detected = false;
345+
return;
346+
}
347+
348+
#ifndef FORCE_GPS_ALIVE // for use with repeaters, until GPS toggle is implimented
349+
//Now that GPS is found and set up, set to sleep for initial state
350+
stop_gps();
351+
#endif
352+
}
353+
354+
bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
355+
356+
//set initial waking state
357+
pinMode(ioPin,OUTPUT);
358+
digitalWrite(ioPin,LOW);
359+
delay(1000);
360+
digitalWrite(ioPin,HIGH);
361+
delay(1000);
362+
363+
//Try to init RAK12500 on I2C
364+
if (ublox_GNSS.begin(Wire) == true){
365+
MESH_DEBUG_PRINTLN("RAK12500 GPS init correctly with pin %i",ioPin);
366+
ublox_GNSS.setI2COutput(COM_TYPE_NMEA);
367+
ublox_GNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT);
368+
gpsResetPin = ioPin;
369+
i2cGPSFlag = true;
370+
gps_active = true;
371+
gps_detected = true;
372+
return true;
373+
}
374+
else if(Serial1){
375+
MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on");
376+
if(PIN_GPS_EN){
377+
gpsResetPin = PIN_GPS_EN;
378+
}
379+
serialGPSFlag = true;
380+
gps_active = true;
381+
gps_detected = true;
382+
return true;
383+
}
384+
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
385+
return false;
386+
}
387+
#endif
388+
299389
void EnvironmentSensorManager::start_gps() {
300390
gps_active = true;
391+
#ifdef RAK_BOARD
392+
pinMode(gpsResetPin, OUTPUT);
393+
digitalWrite(gpsResetPin, HIGH);
394+
return;
395+
#endif
301396
#ifdef PIN_GPS_EN
302397
pinMode(PIN_GPS_EN, OUTPUT);
303398
digitalWrite(PIN_GPS_EN, HIGH);
@@ -309,6 +404,11 @@ void EnvironmentSensorManager::start_gps() {
309404

310405
void EnvironmentSensorManager::stop_gps() {
311406
gps_active = false;
407+
#ifdef RAK_BOARD
408+
pinMode(gpsResetPin, OUTPUT);
409+
digitalWrite(gpsResetPin, LOW);
410+
return;
411+
#endif
312412
#ifdef PIN_GPS_EN
313413
pinMode(PIN_GPS_EN, OUTPUT);
314414
digitalWrite(PIN_GPS_EN, LOW);
@@ -324,11 +424,28 @@ void EnvironmentSensorManager::loop() {
324424
_location->loop();
325425

326426
if (millis() > next_gps_update) {
327-
if (gps_active && _location->isValid()) {
427+
if(gps_active){
428+
#ifndef RAK_BOARD
429+
if (_location->isValid()) {
430+
node_lat = ((double)_location->getLatitude())/1000000.;
431+
node_lon = ((double)_location->getLongitude())/1000000.;
432+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
433+
}
434+
#else
435+
if(i2cGPSFlag){
436+
node_lat = ((double)ublox_GNSS.getLatitude())/10000000.;
437+
node_lon = ((double)ublox_GNSS.getLongitude())/10000000.;
438+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
439+
}
440+
else if (serialGPSFlag && _location->isValid()) {
328441
node_lat = ((double)_location->getLatitude())/1000000.;
329442
node_lon = ((double)_location->getLongitude())/1000000.;
330443
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
331444
}
445+
//else
446+
//MESH_DEBUG_PRINTLN("No valid GPS data");
447+
#endif
448+
}
332449
next_gps_update = millis() + 1000;
333450
}
334451
}

src/helpers/sensors/EnvironmentSensorManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class EnvironmentSensorManager : public SensorManager {
2424
void start_gps();
2525
void stop_gps();
2626
void initBasicGPS();
27+
#ifdef RAK_BOARD
28+
void rakGPSInit();
29+
bool gpsIsAwake(uint8_t ioPin);
30+
#endif
2731
#endif
2832

2933

variants/rak4631/RAK4631Board.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
#define P_LORA_MOSI 44
1414
#define SX126X_POWER_EN 37
1515

16-
#define P_GPS_SDA 13 //GPS SDA pin (output option)
17-
#define P_GPS_SCL 14 //GPS SCL pin (output option)
18-
#define P_GPS_TX 16 //GPS TX pin
19-
#define P_GPS_RX 15 //GPS RX pin
20-
#define P_GPS_STANDBY_A 34 //GPS Reset/Standby pin (IO2 for socket A)
21-
#define P_GPS_STANDBY_C 4 //GPS Reset/Standby pin (IO4 for socket C)
22-
#define P_GPS_STANDBY_F 9 //GPS Reset/Standby pin (IO5 for socket F)
23-
#define P_GPS_1PPS 17 //GPS PPS pin
16+
//#define PIN_GPS_SDA 13 //GPS SDA pin (output option)
17+
//#define PIN_GPS_SCL 14 //GPS SCL pin (output option)
18+
//#define PIN_GPS_TX 16 //GPS TX pin
19+
//#define PIN_GPS_RX 15 //GPS RX pin
20+
#define PIN_GPS_1PPS 17 //GPS PPS pin
2421
#define GPS_BAUD_RATE 9600
2522
#define GPS_ADDRESS 0x42 //i2c address for GPS
2623

variants/rak4631/platformio.ini

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ board = wiscore_rak4631
55
board_check = true
66
build_flags = ${nrf52_base.build_flags}
77
-I variants/rak4631
8-
-D RAK_4631
8+
-D RAK_BOARD
99
-D PIN_BOARD_SCL=14
1010
-D PIN_BOARD_SDA=13
11+
-D PIN_GPS_TX=16
12+
-D PIN_GPS_RX=15
13+
-D PIN_GPS_EN=-1
1114
-D PIN_OLED_RESET=-1
1215
-D RADIO_CLASS=CustomSX1262
1316
-D WRAPPER_CLASS=CustomSX1262Wrapper
1417
-D LORA_TX_POWER=22
1518
-D SX126X_CURRENT_LIMIT=140
1619
-D SX126X_RX_BOOSTED_GAIN=1
20+
-D ENV_INCLUDE_GPS=1
1721
build_src_filter = ${nrf52_base.build_src_filter}
1822
+<../variants/rak4631>
23+
+<helpers/sensors>
1924
lib_deps =
2025
${nrf52_base.lib_deps}
2126
adafruit/Adafruit SSD1306 @ ^2.5.13
2227
stevemarple/MicroNMEA @ ^2.0.6
28+
sparkfun/SparkFun u-blox GNSS Arduino Library @ ^2.2.27
2329

2430
[env:RAK_4631_Repeater]
2531
extends = rak4631
@@ -37,30 +43,6 @@ build_src_filter = ${rak4631.build_src_filter}
3743
+<helpers/ui/SSD1306Display.cpp>
3844
+<../examples/simple_repeater>
3945

40-
[env:RAK_4631_GPS_Repeater]
41-
extends = rak4631
42-
build_flags =
43-
${rak4631.build_flags}
44-
-D DISPLAY_CLASS=SSD1306Display
45-
-D ADVERT_NAME='"RAK4631 GPS Repeater"'
46-
-D ADVERT_LAT=0.0
47-
-D ADVERT_LON=0.0
48-
-D ADMIN_PASSWORD='"password"'
49-
-D MAX_NEIGHBOURS=8
50-
-D FORCE_GPS_ALIVE=1
51-
-D ENV_INCLUDE_GPS=1
52-
-D ENV_INCLUDE_BME680=1
53-
; -D MESH_PACKET_LOGGING=1
54-
; -D MESH_DEBUG=1
55-
build_src_filter = ${rak4631.build_src_filter}
56-
+<helpers/ui/SSD1306Display.cpp>
57-
+<../examples/simple_repeater>
58-
lib_deps =
59-
${rak4631.lib_deps}
60-
sparkfun/SparkFun u-blox GNSS Arduino Library @ ^2.2.27
61-
https://github.com/boschsensortec/Bosch-BSEC2-Library
62-
https://github.com/boschsensortec/Bosch-BME68x-Library
63-
6446
[env:RAK_4631_room_server]
6547
extends = rak4631
6648
build_flags =
@@ -117,33 +99,6 @@ lib_deps =
11799
${rak4631.lib_deps}
118100
densaugeo/base64 @ ~1.4.0
119101

120-
[env:RAK_4631_GPS_companion_radio_ble]
121-
extends = rak4631
122-
build_flags =
123-
${rak4631.build_flags}
124-
-D PIN_USER_BTN=9
125-
-D PIN_USER_BTN_ANA=31
126-
-D DISPLAY_CLASS=SSD1306Display
127-
-D MAX_CONTACTS=100
128-
-D MAX_GROUP_CHANNELS=8
129-
-D BLE_PIN_CODE=123456
130-
-D BLE_DEBUG_LOGGING=1
131-
-D OFFLINE_QUEUE_SIZE=256
132-
-D ENV_INCLUDE_GPS=1
133-
-D ENV_INCLUDE_BME680=1
134-
; -D MESH_PACKET_LOGGING=1
135-
; -D MESH_DEBUG=1
136-
build_src_filter = ${rak4631.build_src_filter}
137-
+<helpers/ui/SSD1306Display.cpp>
138-
+<helpers/nrf52/SerialBLEInterface.cpp>
139-
+<../examples/companion_radio>
140-
lib_deps =
141-
${rak4631.lib_deps}
142-
sparkfun/SparkFun u-blox GNSS Arduino Library @ ^2.2.27
143-
https://github.com/boschsensortec/Bosch-BSEC2-Library
144-
https://github.com/boschsensortec/Bosch-BME68x-Library
145-
densaugeo/base64 @ ~1.4.0
146-
147102
[env:RAK_4631_terminal_chat]
148103
extends = rak4631
149104
build_flags =

0 commit comments

Comments
 (0)