Skip to content

Commit d4c4c34

Browse files
kainhoferuser2684
authored andcommitted
Improve support for NRF5 boards (#431)
1 parent ccddc1d commit d4c4c34

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

nodemanager/Constants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Chip type
8989
#if defined(ESP32) || defined(MY_GATEWAY_ESP32)
9090
#define CHIP_ESP32
9191
#endif
92-
#if defined (MYBOARDNRF5)
92+
#if defined (MYBOARDNRF5) || defined(NRF51) || defined(NRF52)
9393
#define CHIP_NRF5
9494
#endif
9595
#if !defined(CHIP_ESP8266) && !defined(CHIP_ESP32) && !defined(CHIP_STM32) && !defined(CHIP_NRF5)
@@ -187,4 +187,4 @@ Default configuration settings
187187
#define debug_verbose(x,...)
188188
#endif
189189

190-
#endif
190+
#endif

sensors/DisplaySSD1306.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@
2424
*/
2525

2626
#include <SSD1306Ascii.h>
27-
#include <SSD1306AsciiAvrI2c.h>
27+
#ifdef CHIP_AVR
28+
#include <SSD1306AsciiAvrI2c.h>
29+
#else
30+
#include <SSD1306AsciiWire.h>
31+
#endif
2832

2933
#include "Display.h"
3034

3135
class DisplaySSD1306: public Display {
3236
protected:
37+
#ifdef CHIP_AVR
3338
SSD1306AsciiAvrI2c* _oled;
39+
#else
40+
SSD1306AsciiWire* _oled;
41+
#endif
3442
const DevType* _dev = &Adafruit128x64;
3543
uint8_t _i2caddress = 0x3c;
3644
int _fontsize = 1;
@@ -125,7 +133,11 @@ class DisplaySSD1306: public Display {
125133

126134
// define what to do during setup
127135
void onSetup() {
136+
#ifdef CHIP_AVR
128137
_oled = new SSD1306AsciiAvrI2c();
138+
#else
139+
_oled = new SSD1306AsciiWire();
140+
#endif
129141
_oled->begin(_dev, _i2caddress);
130142
_oled->setFont(_font);
131143
if (_contrast > -1) _oled->setContrast(_contrast);
@@ -146,4 +158,4 @@ class DisplaySSD1306: public Display {
146158
};
147159
#endif
148160
};
149-
#endif
161+
#endif

sensors/SensorConfiguration.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SensorConfiguration_h
2020
#define SensorConfiguration_h
2121

22+
#if NODEMANAGER_OTA_CONFIGURATION == ON
2223
/*
2324
SensorConfiguration: allow remote configuration of the board and any configured sensor
2425
*/
@@ -126,4 +127,9 @@ class SensorConfiguration: public Sensor {
126127
nodeManager.sendMessage(children.get(1)->getChildId(),V_CUSTOM,function);
127128
};
128129
};
129-
#endif
130+
131+
#else
132+
#warning "SensorConfiguration.h included, but NODEMANAGER_OTA_CONFIGURATION configured to off..."
133+
#endif
134+
135+
#endif

sensors/SensorVL53L0X.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ class SensorVL53L0X: public Sensor {
4040
// define what to do during setup
4141
void onSetup() {
4242
if (_pin > 0) {
43-
pinMode(_pin, OUTPUT); // Put sensor in deep sleep until the loop
43+
#ifdef CHIP_NRF5
44+
// The NRF5 chip has hwPinMode S0D1, i.e. standard LOW, but disconnected
45+
// HIGH, which is exactly what we need for the power pin of the VL53L0X
46+
// (the sensort board has a pull-up, so disconnected means sensor's
47+
// VCC, not the arduino/NRF5's potentially higher VCC!)
48+
hwPinMode(_pin, OUTPUT_S0D1);
49+
#else
50+
pinMode(_pin, OUTPUT);
51+
#endif
52+
// Put sensor in deep sleep until the loop
4453
digitalWrite(_pin, LOW);
4554
}
4655
_lox = new VL53L0X();
@@ -59,12 +68,20 @@ class SensorVL53L0X: public Sensor {
5968
int _getDistance() {
6069
int distance = -1;
6170
if (_lox) {
62-
// The XSHUT pin puts the sensor into deep sleep when pulled to LOW;
63-
// To wake up, do NOT write HIGH (=3.3V or 5V) to the pin, as the sensor
64-
// uses only 2.8V and is not 5V-tolerant. Instead, set the pin to INPUT.
6571
if (_pin >= 0) {
72+
#ifdef CHIP_NRF5
73+
// The nrf5 chips have disconnected high, so the pullup will
74+
// cause the XSHUT pin to go to the sensor's VCC, which will
75+
// not fry the chip. The arduino/nrf5's VCC (3.3V or 5V) is
76+
// too high for the sensor's 2.8V VCC...
77+
digitalWrite(_pin, HIGH);
78+
#else
79+
// The XSHUT pin puts the sensor into deep sleep when pulled to LOW;
80+
// To wake up, do NOT write HIGH (=3.3V or 5V) to the pin, as the sensor
81+
// uses only 2.8V and is not 5V-tolerant. Instead, set the pin to INPUT.
6682
pinMode(_pin, INPUT);
67-
sleep(5); // Transition from HW standby to SW standby might take up to 1.5 ms => use 5ms to be on the safe side
83+
#endif
84+
sleep(3); // Transition from HW standby to SW standby might take up to 1.5 ms => use 3ms to be on the safe side
6885
}
6986
_lox->init();
7087
_lox->setTimeout(500);
@@ -73,12 +90,11 @@ class SensorVL53L0X: public Sensor {
7390
digitalWrite(_pin, LOW);
7491
pinMode(_pin, OUTPUT);
7592
}
76-
}
77-
// if (measure.RangeStatus == 0) { // only 0 data
78-
if (_lox->timeoutOccurred()) {
79-
distance = -1;
93+
if (_lox->timeoutOccurred()) {
94+
distance = -1;
95+
}
8096
}
8197
return distance;
8298
};
8399
};
84-
#endif
100+
#endif

0 commit comments

Comments
 (0)