xreef/PCF8591_library

Multiple PCF8591 issue

Headburn911 opened this issue · 3 comments

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

Greetings,

Rick

xreef commented

Hi Rick,
post your code.
Bye Renzo

Hi reef,
I'm using one of the example codes.
I can't figure out how to add en use a second PCF8591.
so to define it and how to name it with the address.

greetings Rick

`#include "Arduino.h"
#include "PCF8591.h"
#define PCF8591_I2C_ADDRESS 0x48

PCF8591 pcf8591(PCF8591_I2C_ADDRESS);

void setup()
{
  Serial.begin(115200);
  pcf8591.begin();
}

void loop()
{
  int ana = pcf8591.analogRead(AIN0);
  Serial.print("AIN0 --> ");
  Serial.println(ana);

  ana = pcf8591.analogRead(AIN1);
  Serial.print("AIN1 --> ");
  Serial.println(ana);

  ana = pcf8591.analogRead(AIN2);
  Serial.print("AIN2 --> ");
  Serial.println(ana);

  ana = pcf8591.analogRead(AIN3);
  Serial.print("AIN3 --> ");
  Serial.println(ana);
  delay(3000);
}`
xreef commented

Hi,
you must declare new pcf like so

PCF8591 pcf8591_2(PCF8591_2_I2C_ADDRESS)

Bye Renzo