Skip to content

Commit e9a8fcb

Browse files
authored
Merge pull request #531 from cod3doomy/dev
RAK4631 ESM Migration
2 parents 46d30f6 + 6b4592b commit e9a8fcb

File tree

6 files changed

+147
-519
lines changed

6 files changed

+147
-519
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

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

50+
#if ENV_INCLUDE_GPS && RAK_BOARD
51+
static uint32_t gpsResetPin = 0;
52+
static bool i2cGPSFlag = false;
53+
static bool serialGPSFlag = false;
54+
#define TELEM_RAK12500_ADDRESS 0x42 //RAK12500 Ublox GPS via i2c
55+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h>
56+
static SFE_UBLOX_GNSS ublox_GNSS;
57+
#endif
58+
5059
bool EnvironmentSensorManager::begin() {
5160
#if ENV_INCLUDE_GPS
61+
#if RAK_BOARD
62+
rakGPSInit(); //probe base board/sockets for GPS
63+
#else
5264
initBasicGPS();
5365
#endif
66+
#endif
5467

5568
#if ENV_INCLUDE_AHTX0
5669
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) {
@@ -296,8 +309,85 @@ void EnvironmentSensorManager::initBasicGPS() {
296309
gps_active = false; //Set GPS visibility off until setting is changed
297310
}
298311

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

310400
void EnvironmentSensorManager::stop_gps() {
311401
gps_active = false;
402+
#ifdef RAK_BOARD
403+
pinMode(gpsResetPin, OUTPUT);
404+
digitalWrite(gpsResetPin, LOW);
405+
return;
406+
#endif
312407
#ifdef PIN_GPS_EN
313408
pinMode(PIN_GPS_EN, OUTPUT);
314409
digitalWrite(PIN_GPS_EN, LOW);
@@ -324,11 +419,28 @@ void EnvironmentSensorManager::loop() {
324419
_location->loop();
325420

326421
if (millis() > next_gps_update) {
327-
if (gps_active && _location->isValid()) {
422+
if(gps_active){
423+
#ifndef RAK_BOARD
424+
if (_location->isValid()) {
425+
node_lat = ((double)_location->getLatitude())/1000000.;
426+
node_lon = ((double)_location->getLongitude())/1000000.;
427+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
428+
}
429+
#else
430+
if(i2cGPSFlag){
431+
node_lat = ((double)ublox_GNSS.getLatitude())/10000000.;
432+
node_lon = ((double)ublox_GNSS.getLongitude())/10000000.;
433+
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
434+
}
435+
else if (serialGPSFlag && _location->isValid()) {
328436
node_lat = ((double)_location->getLatitude())/1000000.;
329437
node_lon = ((double)_location->getLongitude())/1000000.;
330438
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
331439
}
440+
//else
441+
//MESH_DEBUG_PRINTLN("No valid GPS data");
442+
#endif
443+
}
332444
next_gps_update = millis() + 1000;
333445
}
334446
}

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: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,33 @@ board_check = true
66
build_flags = ${nrf52_base.build_flags}
77
-I variants/rak4631
88
-D RAK_4631
9+
-D RAK_BOARD
910
-D PIN_BOARD_SCL=14
1011
-D PIN_BOARD_SDA=13
12+
-D PIN_GPS_TX=16
13+
-D PIN_GPS_RX=15
14+
-D PIN_GPS_EN=-1
1115
-D PIN_OLED_RESET=-1
1216
-D RADIO_CLASS=CustomSX1262
1317
-D WRAPPER_CLASS=CustomSX1262Wrapper
1418
-D LORA_TX_POWER=22
1519
-D SX126X_CURRENT_LIMIT=140
1620
-D SX126X_RX_BOOSTED_GAIN=1
21+
-D ENV_INCLUDE_GPS=1
22+
-D ENV_INCLUDE_SHTC3=1
23+
-D ENV_INCLUDE_LPS22HB=1
24+
-D ENV_INCLUDE_INA219=1
1725
build_src_filter = ${nrf52_base.build_src_filter}
1826
+<../variants/rak4631>
27+
+<helpers/sensors>
1928
lib_deps =
2029
${nrf52_base.lib_deps}
2130
adafruit/Adafruit SSD1306 @ ^2.5.13
2231
stevemarple/MicroNMEA @ ^2.0.6
32+
adafruit/Adafruit SHTC3 Library@^1.0.1
33+
arduino-libraries/Arduino_LPS22HB@^1.0.2
34+
adafruit/Adafruit INA219@^1.2.3
35+
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.27
2336

2437
[env:RAK_4631_Repeater]
2538
extends = rak4631
@@ -37,30 +50,6 @@ build_src_filter = ${rak4631.build_src_filter}
3750
+<helpers/ui/SSD1306Display.cpp>
3851
+<../examples/simple_repeater>
3952

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-
6453
[env:RAK_4631_room_server]
6554
extends = rak4631
6655
build_flags =
@@ -117,33 +106,6 @@ lib_deps =
117106
${rak4631.lib_deps}
118107
densaugeo/base64 @ ~1.4.0
119108

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-
147109
[env:RAK_4631_terminal_chat]
148110
extends = rak4631
149111
build_flags =

0 commit comments

Comments
 (0)