Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xreef/pcf8591_library
Library to use pcf8591 i2c analog IC with Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read analog value and write analog value with only 2 wire.
https://github.com/xreef/pcf8591_library
analog arduino arduino-library esp-01 esp32 esp8266 expander i2c library pcf8591 raspberry-pi read rp2040 stm32 write
Last synced: about 7 hours ago
JSON representation
Library to use pcf8591 i2c analog IC with Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read analog value and write analog value with only 2 wire.
- Host: GitHub
- URL: https://github.com/xreef/pcf8591_library
- Owner: xreef
- License: mit
- Created: 2017-11-09T17:34:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T17:32:20.000Z (9 months ago)
- Last Synced: 2024-05-21T12:05:24.500Z (6 months ago)
- Topics: analog, arduino, arduino-library, esp-01, esp32, esp8266, expander, i2c, library, pcf8591, raspberry-pi, read, rp2040, stm32, write
- Language: C++
- Homepage:
- Size: 6.8 MB
- Stars: 27
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
#You can find updated version of documentation on my site [PCF8591](https://www.mischianti.org/2019/01/03/pcf8591-i2c-analog-i-o-expander/)
Library to use i2c analog IC with arduino and esp8266. Can read analog value and write analog value with only 2 wire (perfect for ESP-01).
- 01/02/2024: v1.1.2 Add the possibility to insert address at begin() function
- 10/07/2023: v1.1.1 Add support for Arduino UNO R4
- 16/02/2023: v1.1.0
- Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards
- Add support for custom SERCOM interface of Arduino SAMD devices. Force SDA SCL to use GPIO numeration for STM32 bug (https://www.mischianti.org/forums/topic/compatible-with-stm32duino/).
- Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/).
- Fix the SDA SCL type #58 and add basic support for SAMD device.
- 06/04/2022: v1.0.2 Fix package sizeTutorial:
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8591. Check that the PCF8591 folder contains `PCF8591\\.cpp` and `PCF8591.h`. Place the DHT library folder your `/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
# Reef complete PCF8591 Analog input and analog output to digital converter with i2c bus.
I try to simplify the use of this IC, with a minimal set of operation.Constructor:
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
```cpp
PCF8591(uint8_t address);
```
for esp8266 if you want specify SDA e SCL pin use this:```cpp
PCF8591(uint8_t address, uint8_t sda, uint8_t scl);
```then IC as you can see in the image have 4 analog input and 1 analog output:
![PCF8591 schema](https://github.com/xreef/PCF8591_library/blob/master/resources/PCF8591-Pin-Outs.png)
So to read all analog input in one trasmission you can do (the value is from 0 to 255):
```cpp
PCF8591::AnalogInput ai = pcf8591.analogReadAll();
Serial.print(ai.ain0);
Serial.print(" - ");
Serial.print(ai.ain1);
Serial.print(" - ");
Serial.print(ai.ain2);
Serial.print(" - ");
Serial.println(ai.ain3);
```if you want read a single analog input or channel:
```cpp
int ana = pcf8591.analogRead(AIN0); // read analog 0
```This IC have multiple type of read and you can use Analog input or analog channel (when you use single read analog input and channel are the same:
![Channel selection](https://github.com/xreef/PCF8591_library/blob/master/resources/channel_selection.PNG)
For example to read the value of channel 0 in Two differential input you must do:
```cpp
int ana = pcf8591.analogRead(CHANNEL0, TWO_DIFFERENTIAL_INPUT); // read analog 0
```If you want write an analog value you must do (the value is from 0 to 255):
```cpp
pcf8591.analogWrite(128);
```Additional feature is to read a write voltage:
For the calculation of voltage you must pass some parameter:
- microcontrollerReferenceVoltage: get voltage from microcontroller voltage (only AVR no esp8266 for esp 3.3v fixed)
- referenceVoltage: if microcontrollerReferenceVoltage false take this value
The command are:
```cpp
void voltageWrite(float value, bool microcontrollerReferenceVoltage = true, float referenceVoltage = 5.0);
float voltageRead(uint8_t analogPin, bool microcontrollerReferenceVoltage = true, float referenceVoltage = 5.0);
```An examples is:
```cpp
pcf8591.voltageWrite(2.7); // 2.7Volts output
delay(3000);float ana0V = pcf8591.voltageRead(AIN0); // Read voltage from analog 0
Serial.println(ana0V);
```For the examples I use this wire schema on breadboard:
![Breadboard](https://github.com/xreef/PCF8591_library/blob/master/resources/simpleschema_bb.png)