Skip to content

Commit e37fc67

Browse files
authored
Support for PCA9685 as RGB/RGBW/W dimmer (#421)
1 parent 751b0b5 commit e37fc67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+814
-80
lines changed

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,25 @@ jobs:
454454
- sed -r -i 's/\/\/(SensorPH .+)/\1/' $SKETCH
455455
- sed -r -i 's/\/\/(#include <sensors\/SensorPH.h>)/\1/' $SKETCH
456456
- eval $OTA_CONFIGURATION
457+
- eval $COMPILE
458+
- name: "SensorPca9685W"
459+
script:
460+
- arduino --install-library "Adafruit PWM Servo Driver Library"
461+
- sed -r -i 's/\/\/(SensorPca9685W .+)/\1/' $SKETCH
462+
- sed -r -i 's/\/\/(#include <sensors\/SensorPca9685W.h>)/\1/' $SKETCH
463+
- eval $OTA_CONFIGURATION
464+
- eval $COMPILE
465+
- name: "SensorPca9685Rgb"
466+
script:
467+
- arduino --install-library "Adafruit PWM Servo Driver Library"
468+
- sed -r -i 's/\/\/(SensorPca9685Rgb .+)/\1/' $SKETCH
469+
- sed -r -i 's/\/\/(#include <sensors\/SensorPca9685Rgb.h>)/\1/' $SKETCH
470+
- eval $OTA_CONFIGURATION
471+
- eval $COMPILE
472+
- name: "SensorPca9685Rgbw"
473+
script:
474+
- arduino --install-library "Adafruit PWM Servo Driver Library"
475+
- sed -r -i 's/\/\/(SensorPca9685Rgbw .+)/\1/' $SKETCH
476+
- sed -r -i 's/\/\/(#include <sensors\/SensorPca9685Rgbw.h>)/\1/' $SKETCH
477+
- eval $OTA_CONFIGURATION
457478
- eval $COMPILE

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ SensorNeopixel | 1 | Control a Neopixel LED
144144
SensorSDS011 | 2 | SDS011 air quality sensor, return concentrations of 2.5 and 10 micrometer particles. | https://github.com/ricki-z/SDS011
145145
SensorFPM10A | 1 | FPM10A fingerprint sensor | https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library
146146
SensorPH | 1 | PH ( SKU SEN161 ) sensor, measure the analog value from the amplifier module | -
147+
SensorPca9685W | 1 | Generic dimmer sensor (S_DIMMER) used to drive a single channel pwm output of PCA9685 | https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
148+
SensorPca9685Rgb | 1 | Generic RGB-dimmer sensor (S_RGB_LIGHT) used to drive RGB resp. 3-channel pwm output of PCA9685 | https://github.com/adafruit/Adafruit-PWM-Servo- Driver-Library
149+
SensorPca9685Rgbw | 1 | Generic RGBW-dimmer sensor (S_RGBW_LIGHT) used to drive RGBW resp. 4-channel pwm output of PCA9685| https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
147150

148151
Those sensors requiring a pin to operate would take it as an argument in the constructor.
149152
NodeManager automatically creates all the child_ids, assigning an incremental counter. If you need to set your own child_id, pass it as the last argument to the constructor
@@ -268,7 +271,7 @@ You can interact with each class provided by NodeManager through a set of API fu
268271
void registerTimer(Timer* timer);
269272
#endif
270273
// return the next-available child id
271-
uint8_t getAvailableChildId(uint8_t child_id = 255);
274+
uint8_t getAvailableChildId(uint8_t child_id = 0);
272275
// list containing all the registered sensors
273276
List<Sensor*> sensors;
274277
// return the Child object of the given child_id
@@ -882,6 +885,60 @@ Each sensor class may expose additional methods.
882885
void setPH4Voltage(float value);
883886
~~~
884887
888+
* SensorPca9685W
889+
~~~c
890+
// [101] set the effect to use for a smooth transition, can be one of SensorDimmer::EASE_LINEAR (0), SensorDimmer::EASE_INSINE (1), SensorDimmer::EASE_OUTSINE (2), SensorDimmer::EASE_INOUTSINE (3) (default: EASE_LINEAR)
891+
void setEasing(int value);
892+
// [102] the duration of entire the transition in seconds (default: 1)
893+
void setDuration(int value);
894+
// [103] the duration of a single step of the transition in milliseconds (default: 100)
895+
void setStepDuration(int value);
896+
//get instance of PCA9685-board
897+
Adafruit_PWMServoDriver* getPWMServoDriver();
898+
//set instance of PCA9685-board, if using more than one pca9685-dimmer sensor on the same pca9685-board
899+
void setPWMServoDriver(Adafruit_PWMServoDriver* servoDriver);
900+
//set the RGB (red/green/blue) value as hex-string (e.g. 000000...black/off, ff0000...red, 00ff00...green, 0000ff...blue, ffa500...orange, ffffff...white)
901+
void setRgbVal(String hexstring);
902+
//get the current RGB (red/green/blue) value as hex-string
903+
String getRgbVal();
904+
~~~
905+
906+
* SensorPca9685Rgb
907+
~~~c
908+
// [101] set the effect to use for a smooth transition, can be one of SensorDimmer::EASE_LINEAR (0), SensorDimmer::EASE_INSINE (1), SensorDimmer::EASE_OUTSINE (2), SensorDimmer::EASE_INOUTSINE (3) (default: EASE_LINEAR)
909+
void setEasing(int value);
910+
// [102] the duration of entire the transition in seconds (default: 1)
911+
void setDuration(int value);
912+
// [103] the duration of a single step of the transition in milliseconds (default: 100)
913+
void setStepDuration(int value);
914+
//get instance of PCA9685-board
915+
Adafruit_PWMServoDriver* getPWMServoDriver();
916+
//set instance of PCA9685-board, if using more than one pca9685-dimmer sensor on the same pca9685-board
917+
void setPWMServoDriver(Adafruit_PWMServoDriver* servoDriver);
918+
//set the RGB (red/green/blue) value as hex-string (e.g. 000000...black/off, ff0000...red, 00ff00...green, 0000ff...blue, ffa500...orange, ffffff...white)
919+
void setRgbVal(String hexstring);
920+
//get the current RGB (red/green/blue) value as hex-string
921+
String getRgbVal();
922+
~~~
923+
924+
* SensorPca9685Rgbw
925+
~~~c
926+
// [101] set the effect to use for a smooth transition, can be one of SensorDimmer::EASE_LINEAR (0), SensorDimmer::EASE_INSINE (1), SensorDimmer::EASE_OUTSINE (2), SensorDimmer::EASE_INOUTSINE (3) (default: EASE_LINEAR)
927+
void setEasing(int value);
928+
// [102] the duration of entire the transition in seconds (default: 1)
929+
void setDuration(int value);
930+
// [103] the duration of a single step of the transition in milliseconds (default: 100)
931+
void setStepDuration(int value);
932+
//get instance of PCA9685-board
933+
Adafruit_PWMServoDriver* getPWMServoDriver();
934+
//set instance of PCA9685-board, if using more than one pca9685-dimmer sensor on the same pca9685-board
935+
void setPWMServoDriver(Adafruit_PWMServoDriver* servoDriver);
936+
//set the RGBW (red/green/blue/white) value as hex-string (see RGB-examples from PCA9685RGB and add "00".."ff" for the white-channel)
937+
void setRgbwVal(String hexstring);
938+
//get the current RGBW (red/green/blue/white) value as hex-string
939+
String getRgbwVal();
940+
~~~
941+
885942
### OTA Configuration
886943

887944
When `NODEMANAGER_OTA_CONFIGURATION` is set to ON the API presented above can be also called remotely through `SensorConfiguration`, which is automatically added to NodeManager. SensorConfiguration exposes by default child id 200 that can be used to interact with the service by sending `V_CUSTOM` type of messages and commands within the payload. For each `REQ` message, the node will respond with a `SET` message if successful.

examples/Template/Template.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ NodeManager. Just uncomment the settings you need and the sensors you want to ad
346346
//#include <sensors/SensorPH.h>
347347
//SensorPH ph(A0);
348348

349+
//#include <sensors/SensorPca9685W.h>
350+
//SensorPca9685W pca9685W;
351+
352+
//#include <sensors/SensorPca9685Rgb.h>
353+
//SensorPca9685Rgb pca9685Rgb;
354+
355+
//#include <sensors/SensorPca9685Rgbw.h>
356+
//SensorPca9685Rgbw pca9685Rgbw;
357+
349358
/***********************************
350359
* Main Sketch
351360
*/

keywords.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,8 @@ SensorThermistor KEYWORD1
210210
SensorTSL2561 KEYWORD1
211211
SensorTTP KEYWORD1
212212
SensorVL53L0X KEYWORD1
213-
SensorWaterMeter KEYWORD1
213+
SensorWaterMeter KEYWORD1
214+
SensorPH KEYWORD1
215+
SensorPca9685Rgb KEYWORD1
216+
SensorPca9685Rgbw KEYWORD1
217+
SensorPca9685W KEYWORD1

nodemanager/Node.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,14 @@ void NodeManager::loop() {
461461

462462
// return the next available child_id
463463
uint8_t NodeManager::getAvailableChildId(uint8_t child_id) {
464-
// Childs 0 and 255 not allowed
465-
if ( (child_id != 0) && (child_id != 255) ) return child_id;
464+
if (child_id != 0) {
465+
// requested a specific child_id, check if it is available
466+
Child* child = getChild(child_id);
467+
if (child == nullptr) return child_id;
468+
}
469+
// automatic child_id assignment or child already in use
466470
for (int i = 1; i < 255; i++) {
471+
// look for the first available child_id
467472
Child* child = getChild(i);
468473
if (child == nullptr) return i;
469474
}

nodemanager/Node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class NodeManager {
7474
// register a timer
7575
void registerTimer(Timer* timer);
7676
// return the next-available child id
77-
uint8_t getAvailableChildId(uint8_t child_id = 255);
77+
uint8_t getAvailableChildId(uint8_t child_id = 0);
7878
// list containing all the registered sensors
7979
List<Sensor*> sensors;
8080
// return the Child object of the given child_id

sensors/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Display: public Sensor {
2828
const char* _caption = "";
2929

3030
public:
31-
Display(uint8_t child_id = 255): Sensor(-1) {
31+
Display(uint8_t child_id = 0): Sensor(-1) {
3232
_name = "";
3333
// We don't need any sensors, but we need a child, otherwise the loop will never be executed
3434
children.allocateBlocks(1);

sensors/DisplayHD44780.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DisplayHD44780: public Display {
3434
uint8_t _i2caddress = 0x38;
3535
int _column = 0;
3636
public:
37-
DisplayHD44780(uint8_t child_id = 255): Display(child_id) {
37+
DisplayHD44780(uint8_t child_id = 0): Display(child_id) {
3838
_name = "HD44780";
3939
children.get()->setDescription(_name);
4040
};

sensors/DisplaySSD1306.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DisplaySSD1306: public Display {
3939
uint8_t _contrast = -1;
4040

4141
public:
42-
DisplaySSD1306(uint8_t child_id = 255): Display(child_id) {
42+
DisplaySSD1306(uint8_t child_id = 0): Display(child_id) {
4343
_name = "SSD1306";
4444
children.get()->setDescription(_name);
4545
};

sensors/SensorAM2320.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class SensorAM2320: public Sensor {
3131
AM2320* _th;
3232

3333
public:
34-
SensorAM2320(uint8_t child_id = 255): Sensor(-1) {
34+
SensorAM2320(uint8_t child_id = 0): Sensor(-1) {
3535
_name = "AM2320";
3636
children.allocateBlocks(2);
3737
new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id),S_TEMP,V_TEMP,_name);
38-
new Child(this,FLOAT,nodeManager.getAvailableChildId(child_id+1),S_HUM,V_HUM,_name);
38+
new Child(this,FLOAT,child_id > 0 ? nodeManager.getAvailableChildId(child_id+1) : nodeManager.getAvailableChildId(child_id),S_HUM,V_HUM,_name);
3939
};
4040

4141
// define what to do during setup

0 commit comments

Comments
 (0)