Wire library read/write problem... wont compile... [solved]

Dear Forum,

I tried to search for a similar problem on the forum but couldn’t find anything.
I’m trying to use the Wire library to read and write P8574AP port expanders.
In separate programs reading and writing works, but when I put them together, the compiler makes a strange error:
/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:53: note: candidate 1: uint8_t TwoWire::requestFrom(int, int)
/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:52: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)

I’m afraid my programming skills are just one month old, so I’m stuck…

Do I have to change the library?

Thanks for any hints…

here’s my code (some stuff is in german, sorry not very tidy…)

/* 
*Analog Pin 4 -- PCF8574A Pin 15 SDA
*Analog Pin 5 -- PCF8574 Pin 14 SCL
*/

#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 7, 9, 10, 11, 12);

// Adressen setzen:

byte expanderVOL = 0x76 >>1;  // Adresse für P8574 ist 0111 -A2 -A1 -A0 letztes Bit ist R/W und wird nicht benötigt
byte expanderOUT = 0x74 >>1;
byte expanderINS = 0x72 >>1;
byte expanderLED = 0x70 >>1;
byte expanderbuttonL = 0x7E >>1;
byte expanderButtonR = 0x7C >>1;
byte i=0;



// Taster lesen

byte buttonV;
byte whichButton = buttonV>>0&1;
byte inputs = 1;
byte outputs = 1;
boolean dim = false;  // nur zum Test

// für Encoder und Volume:

#define DEFAULTATTNU 10 // Referenzlevel
#define MAXATTNU 30     // -30dB
#define MINATTNU 0     //  0 dB
#define DIMVOL 10     //      
#define INTERVAL_SWITCHBOUNCE 200  // Time in milliseconds to debounce switch
#define VOL 0
                           
#define ENC_A 14
#define ENC_B 15
#define ENC_PORT PINC

byte regVal; 
byte currAttnu=DEFAULTATTNU; // Variable to hold the current attenuation value
byte vol= 255-currAttnu;

//LCD schreiben

 void printVol(byte regVal)
{
  lcd.setCursor(11,1);
    
  if (regVal<10) // transition between two digit and one digit display
  {
    lcd.print("0");  // Add a leading zero
    lcd.print(regVal, DEC);
  }
  else
  {
    lcd.print(regVal, DEC);
  }
  if (regVal > 0)
  {
    lcd.setCursor(10,1);
    lcd.print("-");  // Minuszeichen
  }
else {
   lcd.setCursor(10,1);
    lcd.print(" ");  // Minuszeichen
 }
 if(regVal>MAXATTNU){
   lcd.setCursor(11,1);
    lcd.print("--");  // Mute
 }
}

/*void test(int aktion){
   lcd.setCursor(3,0);
    lcd.print(aktion);
}
*/


// Write SAA1064


byte ctl = B01110111; // X, C6(+12mA) C5(+6mA) C4(+3mA) C3 C2 C1 C0
byte leftButtons = 0;
byte rightButtons = 0;
byte xbuttons = 0;
byte ybuttons = 0;



void setup() {
  
  Wire.begin();
  
  //Serial.begin (9600);
 // Serial.println("Start");
 
 // P8574A auf Input schalten  

Wire.beginTransmission(expanderButtonR);
Wire.send(255);
Wire.endTransmission();  
delay(50);
  
    // LCD definieren
  lcd.begin(16, 2);
  
  /* A0 und A1 als Encoder Inputs definieren */
  pinMode(ENC_A, INPUT);
  digitalWrite(ENC_A, HIGH);
  pinMode(ENC_B, INPUT);
  digitalWrite(ENC_B, HIGH);
  
  
  // LCD initialisieren
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Mein Abhörcontroller");
  lcd.setCursor(0,1);
  lcd.print("----V.0.0.4------");

  delay(1000);
  lcd.clear();
  delay(500);
    lcd.setCursor(9,0);
    lcd.print("|");
     lcd.setCursor(9,1);
    lcd.print("|");
    lcd.setCursor(12,0);
    lcd.print("vol");
    lcd.setCursor(14,1);
    lcd.print("dB");
    lcd.setCursor(0,0);
    lcd.print("In:");
    lcd.setCursor(0,1);
    lcd.print("Out:");
    lcd.setCursor(11,1);
    lcd.print(DEFAULTATTNU);
     lcd.setCursor(10,1);
    lcd.print("-");
    
  
   // Test Sequenz für LEDs
 
 for(leftButtons=1;leftButtons<128;leftButtons=leftButtons*2){
  writeLEDs(0x00,ctl,leftButtons, rightButtons, xbuttons, ybuttons);
  delay(50);}
  for(rightButtons=1;rightButtons<128;rightButtons=rightButtons*2){
  writeLEDs(0x00,B00111111,leftButtons, rightButtons, xbuttons, ybuttons);
  delay(50);}
  clear_display(); 
  delay(100);
  writeLEDs(0x00,B00111111,leftButtons, rightButtons, xbuttons, ybuttons);
  delay(500);
  clear_display();
  
  // Volume Test
  
/*setVolume(B11111111);
for (int x=255;x>=240;x--){
 // x=x;
  setVolume(x);
  delay(200);
}
*/ 
  // INPUT und Output Default auf 1
  
  expanderWrite(B11111110);
  
  // Set Volume
  
  setVolume(DEFAULTATTNU);
}  
  



  
  

  


void loop() {

//Displaybeleuchtung an:

  writeLEDs(0x00,ctl,leftButtons, rightButtons, 1, ybuttons);
  
// Tasten lesen:

 buttonScan();
/* 
 buttonScanR();  Später testen
 
if(((buttonV>>0)&1)==0){inputs=8;}

if(((buttonV>>1)&1)==0){inputs=2;}
else{
 outputs=0; 
}

leftButtons = inputs|outputs<<2;

  


writeLEDs(0x00,ctl,leftButtons, 1, 1, 1); 
  
*/  
  
  
// Encoder 

   static uint8_t counter = 0;      //this variable will be changed by encoder input
 int8_t tmpdata;
 /**/
  tmpdata = read_encoder();
  if( tmpdata ) {
    if (tmpdata < 0)  // CCW
      {
        if (currAttnu<MAXATTNU)      // Check if not already at maximum attenuation (minimum Volume)
        {
          currAttnu+=1;              // Increase 1 dB attenuation (decrease volume 1 db)
          setVolume(currAttnu); // Write value into registers
          printVol(currAttnu);     // Divide by 2 to print in whole dBs
        }
      }
      else                           // If not CCW, then it is CW
      {
        if (currAttnu>MINATTNU)      // Check if not already at minimum attenuation (max volume)
        {
          currAttnu-=1;              // Decrease attenuation 1 dB (increase volume 1 db)

          setVolume(currAttnu); // Write value into registers
          printVol(currAttnu);     // Divide by 2 to print in whole dBs
        }
      }
    //Serial.print("Counter value: ");
   // Serial.println(counter, DEC);
   // counter += tmpdata;
    //printVol(counter);
   // test (tmpdata);
    //    lcd.print("Counter value: ");
   //       lcd.print(counter, DEC);
  }
  
  // Encoder end
  




  
//  Display Test
  
/*  clear_display(); 
  delay(50);
  writeLEDs(0x00,B00111111,leftButtons, rightButtons, xbuttons, ybuttons);
  delay(2000);
  clear_display();
  */
}

// END OF LOOP !!!!!



void buttonScan(){
Wire.requestFrom(expanderButtonR,1);
if (Wire.available())
buttonV = Wire.receive();
}



/* Später testen
void buttonRScan(){
Wire.requestFrom(expanderButtonR,1);
if (Wire.available())
buttonV = Wire.receive();
}
*/

void expanderWrite(byte _data) {
  Wire.endTransmission();
  Wire.beginTransmission(expanderOUT);
  Wire.send(_data);
  Wire.endTransmission();
  Wire.beginTransmission(expanderINS);
  Wire.send(_data);
  Wire.endTransmission();
  

}

void setVolume(byte regVal)
{
  byte _data=(regVal/2|B11110000);
  Wire.beginTransmission(expanderVOL); //Adresse von der vol-Karte
  Wire.send(_data); // Writing the volume value into the register
  Wire.endTransmission();
}
  
  


void writeLEDs(byte instruction,byte ctl,byte data1,byte data2, byte data3, byte data4)
{
  Wire.beginTransmission(expanderLED); // transmit to device 
  Wire.send(instruction);
  Wire.send(ctl);
  Wire.send(data1);
  Wire.send(data2);
   Wire.send(data3);
    Wire.send(data4);
  Wire.endTransmission();     // stop transmitting
}

void clear_display()
{
  Wire.beginTransmission(expanderLED); // transmit to device 1
  Wire.send(0x00);            // sends instruction byte  
  Wire.send(0x00);             // sends controldata value byte 
  Wire.send(0x00);
  Wire.send(0x00);
  Wire.send(0x00);
  Wire.send(0x00);
  Wire.endTransmission();     // stop transmitting
  delay(50);
}
/*
  byte expanderRead() {
  byte _data;
  Wire.requestFrom(expander, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}
*/

int8_t read_encoder()
{
  int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  static uint8_t old_AB = 0;
  /**/
  old_AB <<= 2;                   //remember previous state
  old_AB |= ( ENC_PORT & 0x03 );  //add current state
  return ( enc_states[( old_AB & 0x0f )]);
}

The compiler tells you which line it is having problems with:

Wire.requestFrom(expanderButtonR,1);

It is telling you what the problem is:

sketch_feb17a.cpp: In function 'void buttonScan()': sketch_feb17a:274: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: C:\Users\pjs9486\Documents\arduino-0022\libraries\Wire/Wire.h:53: note: candidate 1: uint8_t TwoWire::requestFrom(int, int) C:\Users\pjs9486\Documents\arduino-0022\libraries\Wire/Wire.h:52: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)

There are 2 versions of the requestFrom function. One version takes two int arguments, and one version takes two byte arguments.

You are supplying a byte and an int. It is telling you that each argument would be a better match for a different version of the function.

Change your call to use a variable for the 2nd argument:

byte cnt = 1;
Wire.requestFrom(expanderButtonR, cnt);

Wow, that was a quick fix...

thank you! now it's working... and I'm understanding a little bit more what I'm actually telling the compiler... and what he is telling me...