0.3.2 PCA9635

This commit is contained in:
rob tillaart 2021-12-23 10:41:42 +01:00
parent c6321536a7
commit 514d1036ef
12 changed files with 136 additions and 69 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
platforms: platforms:
- uno - uno
- leonardo # - due
- due # - zero
- zero # - leonardo
- m4
- esp32
# - esp8266
# - mega2560

View File

@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
arduino_ci: runTest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Arduino-CI/action@master - uses: ruby/setup-ruby@v1
# Arduino-CI/action@v0.1.1 with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2016-2021 Rob Tillaart Copyright (c) 2016-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -2,15 +2,17 @@
// FILE: PCA9635.cpp // FILE: PCA9635.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 23-apr-2016 // DATE: 23-apr-2016
// VERSION: 0.3.1 // VERSION: 0.3.2
// PURPOSE: Arduino library for PCA9635 I2C LED driver // PURPOSE: Arduino library for PCA9635 I2C LED driver
// URL: https://github.com/RobTillaart/PCA9635 // URL: https://github.com/RobTillaart/PCA9635
// //
// HISTORY: // HISTORY:
// 0.3.2 2021-12-23 update library.json, readme, license, minor edits
// 0.3.1 2021-04-25 fix writeN by aspyra // 0.3.1 2021-04-25 fix writeN by aspyra
// 0.3.0 2021-01-18 support Wire1..WireN // 0.3.0 2021-01-18 support Wire1..WireN
//
// 0.2.2 2021-01-13 refactor + fix register index error. // 0.2.2 2021-01-13 refactor + fix register index error.
// 0.2.1 2021-01-05 arduino-CI + unit test // 0.2.1 2021-01-05 Arduino-CI + unit test
// 0.2.0 2020-05-26 major refactor; ESP32 support // 0.2.0 2020-05-26 major refactor; ESP32 support
// 0.1.2 2020-05-07 fix for PCA9635_MODE1 // 0.1.2 2020-05-07 fix for PCA9635_MODE1
// 0.1.1 2016-04-24 set autoincr in constructor // 0.1.1 2016-04-24 set autoincr in constructor
@ -222,4 +224,6 @@ uint8_t PCA9635::readReg(uint8_t reg)
return _data; return _data;
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -3,17 +3,16 @@
// FILE: PCA9635.H // FILE: PCA9635.H
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 23-apr-2016 // DATE: 23-apr-2016
// VERSION: 0.3.1 // VERSION: 0.3.2
// PURPOSE: Arduino library for PCA9635 I2C LED driver // PURPOSE: Arduino library for PCA9635 I2C LED driver
// URL: https://github.com/RobTillaart/PCA9635 // URL: https://github.com/RobTillaart/PCA9635
//
#include "Arduino.h" #include "Arduino.h"
#include "Wire.h" #include "Wire.h"
#define PCA9635_LIB_VERSION (F("0.3.1")) #define PCA9635_LIB_VERSION (F("0.3.2"))
#define PCA9635_MODE1 0x00 #define PCA9635_MODE1 0x00
#define PCA9635_MODE2 0x01 #define PCA9635_MODE2 0x01

View File

@ -1,84 +1,100 @@
[![Arduino CI](https://github.com/RobTillaart/PCA9635/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino CI](https://github.com/RobTillaart/PCA9635/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/PCA9635/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PCA9635/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/PCA9635/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PCA9635/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCA9635/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCA9635/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PCA9635.svg?maxAge=3600)](https://github.com/RobTillaart/PCA9635/releases) [![GitHub release](https://img.shields.io/github/release/RobTillaart/PCA9635.svg?maxAge=3600)](https://github.com/RobTillaart/PCA9635/releases)
# PCA9635 # PCA9635
Arduino library for PCA9635 I2C 8 bit PWM LED driver Arduino library for PCA9635 I2C 8 bit PWM LED driver.
# Description ## Description
This library is to control the I2C PCA9635 PWM extender. This library is to control the I2C PCA9635 PWM extender.
The 16 channels are independently configurable is steps of 1/256. The 16 channels are independently configurable is steps of 1/256.
this allows for better than 1% finetuning of the duty-cycle this allows for better than 1% fine tuning of the duty-cycle
of the PWM signal. of the PWM signal.
## Interface ## Interface
### Constructor ### Constructor
- **PCA9635(deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address, and optional the Wire interface as parameter. - **PCA9635(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address,
- **begin()** initializes the library after startup. Mandatory. and optional the Wire interface as parameter.
- **begin(sda, scl)** idem, ESP32 ESP8266 only. Library does not support - **bool begin()** initializes the library after startup. Mandatory.
- **bool begin(uint8_t sda, uint8_t scl)** idem, ESP32 ESP8266 only. Library does not support
multiple Wire instances (yet). multiple Wire instances (yet).
- **reset()** resets the library to start up conditions. - **void reset()** resets the library to start up conditions.
- **isConnected()** checks if address is available on I2C bus. - **bool isConnected()** checks if address is available on I2C bus.
### LedDriverMode ### LedDriverMode
- **setLedDriverMode(channel, mode)** mode is 0..3 See datasheet for full details. - **uint8_t setLedDriverMode(uint8_t channel, uint8_t mode)** mode is 0..3 See datasheet for full details.
- **getLedDriverMode(channel)** returns the current mode of the channel. - **uint8_t getLedDriverMode(uint8_t channel)** returns the current mode of the channel.
| LED mode | Value | Description | | LED mode | Value | Description |
|:----|:----:|:----| |:-------------------|:-----:|:------------|
| PCA9635_LEDOFF | 0x00 | led is 100% off, default @startup | PCA9635_LEDOFF | 0x00 | led is 100% off, default @startup
| PCA9635_LEDON | 0x01 | led is 100% on. | PCA9635_LEDON | 0x01 | led is 100% on.
| PCA9635_LEDPWM | 0x02 | set LED in PWM mode, 0..255 | PCA9635_LEDPWM | 0x02 | set LED in PWM mode, 0..255
| PCA9635_LEDGRPPWM | 0x03 | add LED to the GRPPWM* | PCA9635_LEDGRPPWM | 0x03 | add LED to the GRPPWM*
\* all leds in the group GRPPWM can be set to the same PWM value in one set. \* all LEDs in the group GRPPWM can be set to the same PWM value in one set.
This is ideal to trigger e.g. multiple LEDS (servo's) at same time. This is ideal to trigger e.g. multiple LEDs (servo's) at same time.
### Read and write ### Read and write
- **write1(channel, value)** writes a single 8 bit PWM value. - **uint8_t write1(uint8_t channel, uint8_t value)** writes a single 8 bit PWM value.
- **write3(channel, R, G, B)** writes three consecutive PWM registers. - **uint8_t write3(uint8_t channel, uint8_t R, uint8_t G, uint8_t B)** writes three consecutive PWM registers.
- **writeN(channel, array, count)** write count consecutive PWM registers. typical use is to write R, G, B values for a full colour LED.
- **uint8_t writeN(uint8_t channel, uint8_t \* array, uint8_t count)** write count consecutive PWM registers.
May return **PCA9635_ERR_WRITE** if array has too many elements May return **PCA9635_ERR_WRITE** if array has too many elements
(including channel as offset) (including channel as offset).
- **writeMode(reg, mode)** configuration of one of the two configuration registers. - **uint8_t writeMode(uint8_t reg, uint8_t value)** configuration of one of the two configuration registers.
check datasheet for details. check datasheet for details.
- **readMode(reg)** reads back the configured mode, useful to add or remove a - **uint8_t readMode(uint8_t reg)** reads back the configured mode,
single flag (bit masking) useful to add or remove a single flag (bit masking).
### Group PWM and frequency ### Group PWM and frequency
- **setGroupPWM(uint8_t value)** sets all channels that are part of the PWM group to value. - **void setGroupPWM(uint8_t value)** sets all channels that are part of the PWM group to value.
- **getGroupPWM()** get the current PWM setting of the group. - **uint8_t getGroupPWM()** get the current PWM setting of the group.
- **setGroupFREQ(value)** see datasheet for details. - **void setGroupFREQ(value)** see datasheet for details.
- **getGroupFREQ()** returns the freq of the PWM group. - **uint8_t getGroupFREQ()** returns the freq of the PWM group.
### Misc
- **lastError()** returns **PCA9635_OK** if all is OK, and other error codes otherwise.
| Error code | Value | Description |
|:----|:----:|:----|
| PCA9635_OK | 0x00 | Everything went well
| PCA9635_ERROR | 0xFF | Generic error
| PCA9635_ERR_WRITE | 0xFE | Tries to write more elements than PWM channels
| PCA9635_ERR_CHAN | 0xFD | Channel out of range
| PCA9635_ERR_MODE | 0xFC | Invalid mode
| PCA9635_ERR_REG | 0xFB | Invalid register
| PCA9635_ERR_I2C | 0xFA | PCA9635 I2C communication error
# Operation ### Miscellaneous
- **int lastError()** returns **PCA9635_OK** if all is OK, and other error codes otherwise.
| Error code | Value | Description |
|:------------------|:-----:|:------------|
| PCA9635_OK | 0x00 | Everything went well
| PCA9635_ERROR | 0xFF | Generic error
| PCA9635_ERR_WRITE | 0xFE | Tries to write more elements than PWM channels
| PCA9635_ERR_CHAN | 0xFD | Channel out of range
| PCA9635_ERR_MODE | 0xFC | Invalid mode
| PCA9635_ERR_REG | 0xFB | Invalid register
| PCA9635_ERR_I2C | 0xFA | PCA9635 I2C communication error
## Operation
See examples See examples
## Future
- improve documentation
- unit tests
- add examples

View File

@ -2,15 +2,15 @@
// FILE: PCA9635_test01.ino // FILE: PCA9635_test01.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 23-APR-2016 // DATE: 23-APR-2016
// VERSION: 0.2.0
// PUPROSE: test PCA9635 library // PUPROSE: test PCA9635 library
//
#include "PCA9635.h" #include "PCA9635.h"
#include <Wire.h> #include <Wire.h>
PCA9635 ledArray(0x20); PCA9635 ledArray(0x20);
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -34,6 +34,7 @@ void setup()
Serial.println("done..."); Serial.println("done...");
} }
void testSetLedDriverModeLEDON() void testSetLedDriverModeLEDON()
{ {
Serial.print(millis()); Serial.print(millis());
@ -52,6 +53,7 @@ void testSetLedDriverModeLEDON()
} }
} }
void testPWMMode() void testPWMMode()
{ {
Serial.print(millis()); Serial.print(millis());
@ -72,6 +74,7 @@ void testPWMMode()
} }
} }
void testWrite1() void testWrite1()
{ {
Serial.print(millis()); Serial.print(millis());
@ -97,6 +100,7 @@ void testWrite1()
} }
} }
void testWrite3() void testWrite3()
{ {
Serial.print(millis()); Serial.print(millis());
@ -111,6 +115,7 @@ void testWrite3()
} }
} }
void testWriteN() void testWriteN()
{ {
Serial.print(millis()); Serial.print(millis());
@ -120,6 +125,7 @@ void testWriteN()
ledArray.writeN(0, arr, 16); ledArray.writeN(0, arr, 16);
} }
void testSetGroupPWM_FREQ() void testSetGroupPWM_FREQ()
{ {
Serial.print(millis()); Serial.print(millis());
@ -166,6 +172,7 @@ void testSetGroupPWM_FREQ()
} }
} }
void testSetAndReadMode() void testSetAndReadMode()
{ {
Serial.print(millis()); Serial.print(millis());
@ -185,6 +192,7 @@ void testSetAndReadMode()
Serial.println(regval); Serial.println(regval);
} }
void testSetLedDriverModeLEDOFF() void testSetLedDriverModeLEDOFF()
{ {
Serial.print(millis()); Serial.print(millis());
@ -203,9 +211,11 @@ void testSetLedDriverModeLEDOFF()
} }
} }
void loop() void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,9 +2,7 @@
// FILE: PCA9635_test_multiple.ino // FILE: PCA9635_test_multiple.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// DATE: 2018-02-18 // DATE: 2018-02-18
// VERSION: 0.2.1
// PUPROSE: test PCA9635 library // PUPROSE: test PCA9635 library
//
#include "PCA9635.h" #include "PCA9635.h"
@ -14,6 +12,7 @@
PCA9635 ledArray(0x20); PCA9635 ledArray(0x20);
PCA9635 ledArray2(0x21); PCA9635 ledArray2(0x21);
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -50,9 +49,11 @@ void setup()
Serial.println("done..."); Serial.println("done...");
} }
void loop() void loop()
{ {
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,13 +1,14 @@
# Syntax Coloring Map for PCA9635 # Syntax Colouring Map for PCA9635
# Datatypes (KEYWORD1) # Data types (KEYWORD1)
PCA9635 KEYWORD1 PCA9635 KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
begin KEYWORD2 begin KEYWORD2
reset KEYWORD2 reset KEYWORD2
isConnected KEYWORD2 isConnected KEYWORD2
setLedDriverMode KEYWORD2 setLedDriverMode KEYWORD2
getLedDriverMode KEYWORD2 getLedDriverMode KEYWORD2

View File

@ -15,8 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/PCA9635.git" "url": "https://github.com/RobTillaart/PCA9635.git"
}, },
"version":"0.3.1", "version": "0.3.2",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*",
"headers": "PCA9635.h"
} }

View File

@ -1,5 +1,5 @@
name=PCA9635 name=PCA9635
version=0.3.1 version=0.3.2
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCA9635 I2C LED driver sentence=Arduino library for PCA9635 I2C LED driver

View File

@ -37,13 +37,40 @@
unittest_setup() unittest_setup()
{ {
fprintf(stderr, "PCA9635_LIB_VERSION: %s\n", (char *) PCA9635_LIB_VERSION);
} }
unittest_teardown() unittest_teardown()
{ {
} }
unittest(test_constants)
{
assertEqual(PCA9635_MODE1 , 0x00);
assertEqual(PCA9635_MODE2 , 0x01);
assertEqual(PCA9635_GRPPWM , 0x12);
assertEqual(PCA9635_GRPFREQ , 0x13);
assertEqual(PCA9635_LEDOUT_BASE, 0x14);
assertEqual(PCA9635_LEDOFF , 0x00);
assertEqual(PCA9635_LEDON , 0x01);
assertEqual(PCA9635_LEDPWM , 0x02);
assertEqual(PCA9635_LEDGRPPWM , 0x03);
fprintf(stderr, "\nerrorcodes");
assertEqual(PCA9635_OK , 0x00);
assertEqual(PCA9635_ERROR , 0xFF);
assertEqual(PCA9635_ERR_WRITE , 0xFE);
assertEqual(PCA9635_ERR_CHAN , 0xFD);
assertEqual(PCA9635_ERR_MODE , 0xFC);
assertEqual(PCA9635_ERR_REG , 0xFB);
assertEqual(PCA9635_ERR_I2C , 0xFA);
}
unittest(test_constructor) unittest(test_constructor)
{ {
fprintf(stderr, "VERSION: %s\n", PCA9635_LIB_VERSION); fprintf(stderr, "VERSION: %s\n", PCA9635_LIB_VERSION);