Git Product home page Git Product logo

pcf8591_library's Introduction

Support forum pcf8591 English
Forum supporto pcf8591 italiano

You can find updated version of documentation on my site​ PCF8591

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

Tutorial:

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 <arduinosketchfolder>/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)

	PCF8591(uint8_t address);

for esp8266 if you want specify SDA e SCL pin use this:

	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

So to read all analog input in one trasmission you can do (the value is from 0 to 255):

	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:

	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

For example to read the value of channel 0 in Two differential input you must do:

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

	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:

	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:

	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

pcf8591_library's People

Contributors

mwreef avatar per1234 avatar xreef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pcf8591_library's Issues

PCF8591 + PCF8574 = error: '...' does not name a type

Hi, thank you for the great work with this library!
Unfortunately I have troubles getting this library and one of your other library (for PCF8574) to work together properly.
If I include both libraries, only the first one goes pass the compiler, but for the other compiler shows error.
#include "Arduino.h"
#include "PCF8574.h"
#include "PCF8591.h"
PCF8574 pcf8574(0x21, SDA_PIN, SCL_PIN);
PCF8591 pcf8591(0x48, SDA_PIN, SCL_PIN);

One or the other causes error (I am using Atom+PlatformIO)
If first include is PCF8591, then the error will be:
error: 'PCF8574' does not name a type

and if I change the order of includes (first include is PCF8574), then the error is inverted:
error: 'PCF8591' does not name a type

Do you know what may cause this problem?

Multiple PCF8591 issue

My code doesn't reconise a 2nd pcf8591.
What is the proper way to declare a 2nd module in de code?

Greetings,

Rick

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.