Skip to content

Commit

Permalink
update library.json, readme, license, minor edits (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Dec 23, 2021
1 parent f3b80cb commit 5512fa7
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions PCF8591.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -178,5 +179,5 @@ int PCF8591::lastError()
}



// -- END OF FILE --

32 changes: 18 additions & 14 deletions PCF8591.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -16,29 +16,30 @@
#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
{
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();

Expand All @@ -62,14 +63,17 @@ class PCF8591

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 --

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

# 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.

Expand All @@ -36,9 +36,9 @@ First tests shows it is 2.6 x faster than 4 individual reads.

- **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 val = 0)** set wire pins for ESP series.
- **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.
- **bool begin(uint8_t val = 0)** Set initial value for the DAC. Returns **true** if successful.
- **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.


Expand Down Expand Up @@ -89,5 +89,6 @@ See examples.
- **analogRead4()** needs investigation for the other modi.
- Does it work?
- Is it user understandable?
- good example...
- ...

2 changes: 1 addition & 1 deletion examples/PCF8591_demo/PCF8591_demo.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//
// FILE: PCF8591_demo.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-07-22
// URL: https://github.com/RobTillaart/PCF8591
Expand Down Expand Up @@ -81,3 +80,4 @@ void test_ADC_mode(uint8_t mode)


// -- END OF FILE --

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//
// FILE: PCF8591_incremental_read.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-07-22
// URL: https://github.com/RobTillaart/PCF8591
Expand Down Expand Up @@ -85,3 +84,4 @@ void loop()


// -- END OF FILE --

5 changes: 3 additions & 2 deletions examples/PCF8591_performance/PCF8591_performance.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// 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


Expand Down Expand Up @@ -150,3 +150,4 @@ void test_ADC_error()


// -- END OF FILE --

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCF8591.git"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PCF8591
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=PCF8591 library for Arduino. Supports multiple I2C WireN bus.
Expand Down
19 changes: 17 additions & 2 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,32 @@

unittest_setup()
{
fprintf(stderr, "PCF8591_LIB_VERSION: %s\n", (char *) PCF8591_LIB_VERSION);
}


unittest_teardown()
{
}


unittest(test_constructor)
unittest(test_constants)
{
fprintf(stderr, "VERSION: %s\n", PCF8591_LIB_VERSION);
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)
{
PCF8591 dev(0x48);
assertTrue(dev.begin());

Expand Down

0 comments on commit 5512fa7

Please sign in to comment.