diff --git a/libraries/PCF8591/.arduino-ci.yml b/libraries/PCF8591/.arduino-ci.yml index ff5659b9..e7cb4633 100644 --- a/libraries/PCF8591/.arduino-ci.yml +++ b/libraries/PCF8591/.arduino-ci.yml @@ -2,6 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 \ No newline at end of file diff --git a/libraries/PCF8591/.github/workflows/arduino_test_runner.yml b/libraries/PCF8591/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/PCF8591/.github/workflows/arduino_test_runner.yml +++ b/libraries/PCF8591/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/PCF8591/LICENSE b/libraries/PCF8591/LICENSE index 8eba944a..c3d6b3da 100644 --- a/libraries/PCF8591/LICENSE +++ b/libraries/PCF8591/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2021 Rob Tillaart +Copyright (c) 2020-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/PCF8591/PCF8591.cpp b/libraries/PCF8591/PCF8591.cpp index c162633c..44d41c3f 100644 --- a/libraries/PCF8591/PCF8591.cpp +++ b/libraries/PCF8591/PCF8591.cpp @@ -2,15 +2,16 @@ // FILE: PCF8591.cpp // AUTHOR: Rob Tillaart // DATE: 2020-03-12 -// VERSION: 0.1.1 +// VERSION: 0.1.2 // PURPOSE: I2C PCF8591 library for Arduino // URL: https://github.com/RobTillaart/PCF8591 // // HISTORY: // 0.0.1 2020-03-12 initial version // 0.0.2 2020-07-22 testing, refactor, documentation and examples -// 0.1.0 2021-01-04 arduino-CI +// 0.1.0 2021-01-04 Arduino-CI // 0.1.1 2021-01-14 added WireN + improve error handling. +// 0.1.2 2021-12-23 update library.json, readme, license, minor edits #include "PCF8591.h" @@ -178,5 +179,5 @@ int PCF8591::lastError() } - // -- END OF FILE -- + diff --git a/libraries/PCF8591/PCF8591.h b/libraries/PCF8591/PCF8591.h index 1bab5347..d174571a 100644 --- a/libraries/PCF8591/PCF8591.h +++ b/libraries/PCF8591/PCF8591.h @@ -3,7 +3,7 @@ // FILE: PCF8591.h // AUTHOR: Rob Tillaart // DATE: 2020-03-12 -// VERSION: 0.1.1 +// VERSION: 0.1.2 // PURPOSE: I2C PCF8591 library for Arduino // URL: https://github.com/RobTillaart/PCF8591 // @@ -16,19 +16,20 @@ #include "Wire.h" -#define PCF8591_LIB_VERSION (F("0.1.1")) +#define PCF8591_LIB_VERSION (F("0.1.2")) -#define PCF8591_OK 0x00 -#define PCF8591_PIN_ERROR 0x81 -#define PCF8591_I2C_ERROR 0x82 -#define PCF8591_MODE_ERROR 0x83 -#define PCF8591_CHANNEL_ERROR 0x84 -#define PCF8591_ADDRESS_ERROR 0x85 +#define PCF8591_OK 0x00 +#define PCF8591_PIN_ERROR 0x81 +#define PCF8591_I2C_ERROR 0x82 +#define PCF8591_MODE_ERROR 0x83 +#define PCF8591_CHANNEL_ERROR 0x84 +#define PCF8591_ADDRESS_ERROR 0x85 // INTERNAL USE ONLY -#define PCF8591_DAC_FLAG 0x40 -#define PCF8591_INCR_FLAG 0x04 +#define PCF8591_DAC_FLAG 0x40 +#define PCF8591_INCR_FLAG 0x04 + class PCF8591 { @@ -36,9 +37,9 @@ public: explicit PCF8591(const uint8_t address = 0x48, TwoWire *wire = &Wire); #if defined (ESP8266) || defined(ESP32) - bool begin(uint8_t sda, uint8_t scl, uint8_t val = 0); + bool begin(uint8_t sda, uint8_t scl, uint8_t value = 0); #endif - bool begin(uint8_t val = 0); + bool begin(uint8_t value = 0); bool isConnected(); @@ -62,14 +63,17 @@ public: int lastError(); + private: uint8_t _address; uint8_t _control; uint8_t _dac; uint8_t _adc[4]; int _error; - + TwoWire* _wire; }; -// END OF FILE + +// -- END OF FILE -- + diff --git a/libraries/PCF8591/README.md b/libraries/PCF8591/README.md index 532ce45c..18a8813d 100644 --- a/libraries/PCF8591/README.md +++ b/libraries/PCF8591/README.md @@ -1,22 +1,24 @@ [![Arduino CI](https://github.com/RobTillaart/PCF8591/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/PCF8591/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PCF8591/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/PCF8591/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PCF8591/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PCF8591/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/PCF8591.svg?maxAge=3600)](https://github.com/RobTillaart/PCF8591/releases) # PCF8591 -Arduino Library for PCF8591 I2C 4 channel 8 bit ADC + 1 channel 8 bit DAC +Arduino Library for PCF8591 I2C 4 channel 8 bit ADC + 1 channel 8 bit DAC. ## Description -**warning** during tests I could overclock the chip at 650 kHz but it is only specified +**warning** during tests I could overclock the chip up to 650 KHz but it is only specified to run at 100 kHz. After getting pretty hot it broke down. So overclocking is fun but not recommended. PCF8591 has one 8 bit ADC on board for 4 channels. The ADC is 8 bit and quite fast. -At 100 kHz one gets \> 2000 reads per second for **analogRead()** and +At 100 KHz one gets \> 2000 reads per second for **analogRead()** and \> 2000 writes per second for **analogWrite()**. Note that most time is probably spend on I2C communication. @@ -32,52 +34,61 @@ First tests shows it is 2.6 x faster than 4 individual reads. ### Generic -- **PCF8591(const uint8_t address, TwoWire \*wire = &Wire)** constructor with I2C address, default is 0x48, optional set the WireN I2C bus. -- **begin(uint8_t sda, uint8_t scl, uint8_t val = 0)** set wire pins for ESP series. +- **PCF8591(const uint8_t address, TwoWire \*wire = &Wire)** constructor with I2C address, +default is 0x48, optional set the WireN I2C bus. +- **bool begin(uint8_t sda, uint8_t scl, uint8_t value = 0)** set wire pins for ESP series. Also set initial value for the DAC. Returns **true** if successful. -- **begin(uint8_t val = 0)** Set initial value for the DAC. Returns **true** if successful. -- **isConnected()** test to see if chip can be reached. +- **bool begin(uint8_t value = 0)** Set initial value for the DAC. Returns **true** if successful. +- **bool isConnected()** test to see if chip can be reached. ### ADC part The PCF8591 has four 8 bit ADC channels. Values = 0..255 -- **enableINCR()** used in analogRead4(); Could become private in the future. -- **disableINCR()** idem. -- **isINCREnabled()** idem. -- **analogRead(uint8_t channel, uint8_t mode = 0)** read one of the 4 analog ports. +- **void enableINCR()** used in analogRead4(); Could become private in the future. +- **void disableINCR()** idem. +- **bool isINCREnabled()** idem. +- **uint8_t analogRead(uint8_t channel, uint8_t mode = 0)** read one of the 4 analogue ports. Default mode is single ports. For comparator modes test datasheet. -- **analogRead4()** read all 4 channels in one call. +- **uint8_t analogRead4()** read all 4 channels in one call. Uses **enableINCR()** to do that efficiently. -It is about 2.6 x faster than 4 individual **analogRead()**, although the latter +It is about 2.6 x faster than 4 individual **analogRead()**, although the latter allows for optimized timing per channel. Only 4x single ports mode supported for now, comparator modi needs investigation. -- **lastRead(uint8_t channel)** get last read value from cache. +- **uint8_t lastRead(uint8_t channel)** get last read value from cache. This cache is filled both by **analogRead()** and **analogRead4()**. See example sketch. ### DAC part -The PCF8591 has one 8 bit DAC. Value 0..255 +The PCF8591 has one 8 bit DAC. output value 0..255 == 0..Vref Volts (datasheet) -- **enableDAC()** switch on the analog output -- **disableDAC()** switch off the analog output (high impedance) Sort of energy saving mode. -- **isDACEnabled()** check the modus operandi. -- **analogWrite(uint8_t value = 0)** writes a value 0..255 to the DAC. Check datasheet for voltage. -- **lastWrite()** get last written value from cache. -- **lastError()** always check this value after a read / write to see if it was OK (== 0). -After the read the error value is reset to OK - - -## Future - -- Improve comparator modi support, how to do that? -dedicated functions? return type int8_t? -- **analogRead4()** needs investigation for the other modi. Does it work? -Is it user understandable? +- **void enableDAC()** switch on the analogue output. +- **void disableDAC()** switch off the analogue output (high impedance) Sort of energy saving mode. +- **bool isDACEnabled()** check the modus operandi. +- **bool analogWrite(uint8_t value = 0)** writes a value 0..255 to the DAC. Check datasheet for voltage. +- **uint8_t lastWrite()** get last written value from cache. +- **int lastError()** always check this value after a read / write to see if it was OK (== 0). +After the read the error value is reset to OK. ## Operations See examples. + + +## Future + +- add / improve comparator modi support, datasheet (par.8.2 figure 4) + - int16_t readComparator10() + - int16_t readComparator30() - return type correct? + - int16_t readComparator31() + - int16_t readComparator32() + - set modi and read. +- **analogRead4()** needs investigation for the other modi. + - Does it work? + - Is it user understandable? + - good example... +- ... + diff --git a/libraries/PCF8591/examples/PCF8591_demo/PCF8591_demo.ino b/libraries/PCF8591/examples/PCF8591_demo/PCF8591_demo.ino index 8f8d74e6..3cdd6cba 100644 --- a/libraries/PCF8591/examples/PCF8591_demo/PCF8591_demo.ino +++ b/libraries/PCF8591/examples/PCF8591_demo/PCF8591_demo.ino @@ -1,15 +1,16 @@ // // FILE: PCF8591_demo.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-07-22 // URL: https://github.com/RobTillaart/PCF8591 + #include "PCF8591.h" PCF8591 dev(0x48); + void setup() { Serial.begin(115200); @@ -24,6 +25,7 @@ void setup() dev.begin(); } + void loop() { test_DAC(); @@ -57,6 +59,7 @@ void test_DAC() Serial.println(); } + void test_ADC_mode(uint8_t mode) { uint8_t channels[] = {4, 3, 3, 2 }; // channels per mode @@ -75,4 +78,6 @@ void test_ADC_mode(uint8_t mode) Serial.println(); } + // -- END OF FILE -- + diff --git a/libraries/PCF8591/examples/PCF8591_incremental_read/PCF8591_incremental_read.ino b/libraries/PCF8591/examples/PCF8591_incremental_read/PCF8591_incremental_read.ino index d6df49b6..3f8a2acb 100644 --- a/libraries/PCF8591/examples/PCF8591_incremental_read/PCF8591_incremental_read.ino +++ b/libraries/PCF8591/examples/PCF8591_incremental_read/PCF8591_incremental_read.ino @@ -1,17 +1,18 @@ // // FILE: PCF8591_incremental_read.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-07-22 // URL: https://github.com/RobTillaart/PCF8591 + #include "PCF8591.h" PCF8591 dev(0x48); uint32_t start, stop, dura1, dura2; + void setup() { Serial.begin(115200); @@ -76,8 +77,11 @@ void setup() Serial.println("\nDone...\n"); } + void loop() { } + // -- END OF FILE -- + diff --git a/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino b/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino index c54e63fe..9e01c728 100644 --- a/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino +++ b/libraries/PCF8591/examples/PCF8591_performance/PCF8591_performance.ino @@ -1,20 +1,22 @@ // // FILE: PCF8591_demo.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 // PURPOSE: demo // DATE: 2020-07-22 // URL: https://github.com/RobTillaart/PCF8591 - +// // NOTE: output is written in markdown format of a table +// (so oeasy to include in the readme.md ;) // can be changed to tab based or comma based output + #include "PCF8591.h" PCF8591 dev(0x48); uint32_t start, stop; + void setup() { Serial.begin(115200); @@ -39,10 +41,12 @@ void setup() test2(); } + void loop() { } + ///////////////////////////////////////////////////////////////////////// void test1() @@ -64,6 +68,7 @@ void test1() Serial.println(); } + void test2() { Serial.println(F("| - Wire clock KHz - | - analogWrite() OK% - | - analogRead() OK% - |")); @@ -83,6 +88,7 @@ void test2() Serial.println(); } + void test_DAC() { dev.enableDAC(); @@ -98,6 +104,7 @@ void test_DAC() Serial.print((stop - start) * 0.001); } + void test_ADC() { volatile uint8_t x = 0; @@ -111,6 +118,7 @@ void test_ADC() Serial.print((stop - start) * 0.001); } + void test_DAC_error() { float perc = 0; @@ -126,6 +134,7 @@ void test_DAC_error() Serial.print(perc); } + void test_ADC_error() { float perc = 0; @@ -139,4 +148,6 @@ void test_ADC_error() Serial.print(perc); } + // -- END OF FILE -- + diff --git a/libraries/PCF8591/keywords.txt b/libraries/PCF8591/keywords.txt index 2b13b3c3..77223562 100644 --- a/libraries/PCF8591/keywords.txt +++ b/libraries/PCF8591/keywords.txt @@ -1,6 +1,6 @@ -# Syntax Coloring Map For PCF8591 +# Syntax Colouring Map For PCF8591 -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) PCF8591 KEYWORD1 # Methods and Functions (KEYWORD2) diff --git a/libraries/PCF8591/library.json b/libraries/PCF8591/library.json index a1ec4fe5..e428c580 100644 --- a/libraries/PCF8591/library.json +++ b/libraries/PCF8591/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/PCF8591.git" }, - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "PCF8591.h" } diff --git a/libraries/PCF8591/library.properties b/libraries/PCF8591/library.properties index f49b4e02..00ca39bd 100644 --- a/libraries/PCF8591/library.properties +++ b/libraries/PCF8591/library.properties @@ -1,5 +1,5 @@ name=PCF8591 -version=0.1.1 +version=0.1.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=PCF8591 library for Arduino. Supports multiple I2C WireN bus. diff --git a/libraries/PCF8591/test/unit_test_001.cpp b/libraries/PCF8591/test/unit_test_001.cpp index e4a1f055..6a046671 100644 --- a/libraries/PCF8591/test/unit_test_001.cpp +++ b/libraries/PCF8591/test/unit_test_001.cpp @@ -39,17 +39,32 @@ unittest_setup() { + fprintf(stderr, "PCF8591_LIB_VERSION: %s\n", (char *) PCF8591_LIB_VERSION); } + unittest_teardown() { } +unittest(test_constants) +{ + assertEqual(PCF8591_OK , 0x00); + assertEqual(PCF8591_PIN_ERROR , 0x81); + assertEqual(PCF8591_I2C_ERROR , 0x82); + assertEqual(PCF8591_MODE_ERROR , 0x83); + assertEqual(PCF8591_CHANNEL_ERROR, 0x84); + assertEqual(PCF8591_ADDRESS_ERROR, 0x85); + + fprintf(stderr, "increment flags\n"); + assertEqual(PCF8591_DAC_FLAG , 0x40); + assertEqual(PCF8591_INCR_FLAG , 0x04); +} + + unittest(test_constructor) { - fprintf(stderr, "VERSION: %s\n", PCF8591_LIB_VERSION); - PCF8591 dev(0x48); assertTrue(dev.begin());