Warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second

i got this error message, but i already tried many ways with this code

void RawData_BH1750(int ADDRESS){
Wire.beginTransmission(ADDRESS);
Wire.requestFrom(ADDRESS,2,true); // request a total of 2 registers
RawData = Wire.read() << 8 | Wire.read(); // Read Raw Data of BH1750
Wire.endTransmission(true);
}

warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
92 | Wire.requestFrom(ADDRESS,2,true); // request a total of 2 registers

note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
74 | uint8_t requestFrom(int, int, int);

note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)'
68 | size_t requestFrom(uint8_t address, size_t size, bool sendStop);

Post you full sketch. Just in case, use code tags ( the <CODE> button above the composer window).

#include <RBDdimmer.h>
#include <Stdio.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "CTBot.h"
#include "ESP8266WiFi.h"
CTBot myBot;


const int relay = 4; 
const int outputPin = 5;
const int zerocross = 7;
#define DELAY 1000
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET 13
#define LED_PIN 14
Adafruit_SSD1306 display(OLED_RESET);



String data;
char c;

#define BH1750_POWER_DOWN 0x00  // No active state
#define BH1750_POWER_ON 0x01  // Waiting for measurement command
#define BH1750_RESET 0x07  

#define CONTINUOUS_HIGH_RES_MODE 0x10  // Measurement at 1 lux resolution. Measurement time is approx 120ms
#define CONTINUOUS_HIGH_RES_MODE_2 0x11  // Measurement at 0.5 lux resolution. Measurement time is approx 120ms
#define CONTINUOUS_LOW_RES_MODE 0x13  // Measurement at 4 lux resolution. Measurement time is approx 16ms
#define ONE_TIME_HIGH_RES_MODE 0x20  // Measurement at 1 lux resolution. Measurement time is approx 120ms
#define ONE_TIME_HIGH_RES_MODE_2 0x21  // Measurement at 0.5 lux resolution. Measurement time is approx 120ms
#define ONE_TIME_LOW_RES_MODE 0x23  // Measurement at 4 lux resolution. Measurement time is approx 16ms

#define BH1750_1_ADDRESS 0x23  // Sensor 1 connected to GND
#define BH1750_2_ADDRESS 0x5C  // Sensor 2 connected to VCC

int outVal = 0;
dimmerLamp dimmer(outputPin,zerocross);

int16_t s_en = 0;
int16_t s0 = 1;
int16_t s1 = 2;
int16_t s2 = 3;

int16_t RawData;
int16_t SensorValue[4];

void setup() {
  Wire.begin();
  dimmer.begin(NORMAL_MODE, ON);
  Serial.begin(115200); // Baud Rate
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(1);
  display.clearDisplay();
	Serial.println("Starting TelegramBot...");
	myBot.wifiConnect(ssid, pass);
	myBot.setTelegramToken(token);

	if (myBot.testConnection())
		Serial.println("\ntestConnection OK");
	else
		Serial.println("\ntestConnection NOK");


  pinMode(s_en, OUTPUT);
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);

  digitalWrite(s_en, HIGH);
  digitalWrite(s0, HIGH);
  digitalWrite(s1, HIGH);
  digitalWrite(s2, HIGH);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
}
void init_BH1750(int ADDRESS, int MODE){
  //BH1750 Initializing & Reset
  Wire.beginTransmission(ADDRESS);
  Wire.write(MODE);  // PWR_MGMT_1 register
  Wire.endTransmission(true);
}
void RawData_BH1750(int ADDRESS){
  Wire.beginTransmission(ADDRESS);
  Wire.requestFrom(ADDRESS,2,true);  // request a total of 2 registers
  RawData = Wire.read() << 8 | Wire.read();  // Read Raw Data of BH1750
  Wire.endTransmission(true);
}

int readMux(int channel){
  int controlPin[] = {s0, s1, s2}; 
  int muxChannel[8][3] = { 
    {0,0,0}, //channel 0 
    {1,0,0}, //channel 1 
    {0,1,0}, //channel 2 
    {1,1,0}, //channel 3 
    {0,0,1}, //channel 4 
    {1,0,1}, //channel 5 
    {0,1,1}, //channel 6 
    {1,1,1}, //channel 7  //loop through the 3 Signals 
  };
  for(int i = 0; i < 3; i++){ // Connecting MUX Channel
    digitalWrite(controlPin[i], muxChannel[channel][i]); 
  }  
return;
}

void loop() {
  	TBMessage msg;

	if (myBot.getNewMessage(msg)) {

		if (msg.text.equalsIgnoreCase("RELAY ON")) {              
			myBot.sendMessage(msg.sender.id, "RELAY is now ON");  //kirim pesan ke bot telegram
		  Serial.print("RELAY ON");
		}
		else if (msg.text.equalsIgnoreCase("RELAY OFF")) {        
			myBot.sendMessage(msg.sender.id, "RELAY is now OFF"); 
		  Serial.print("RELAY OFF");        
		}
    delay(500);
	} 
	
  digitalWrite(s_en, LOW); // Enabling the Enable Switch

  for(int i = 0; i < 4; i++){ 
   readMux(i);

    init_BH1750(BH1750_1_ADDRESS, CONTINUOUS_HIGH_RES_MODE);
    delay(120);
    RawData_BH1750(BH1750_1_ADDRESS);
    SensorValue[i] = RawData / 1.2;  
    delay(20);
   }
  

   Serial.print("Sensor_1 = "); Serial.print(SensorValue[0]);
   Serial.print(" | Sensor_2 = "); Serial.print(SensorValue[1]);
   Serial.print(" | Sensor_3 = "); Serial.print(SensorValue[2]);
   Serial.print(" | Sensor_4 = "); Serial.println(SensorValue[3]);

   int x= SensorValue[0] + SensorValue[1] + SensorValue[2] + SensorValue[3];
   int y= 4;
   int z= x / y;

   Serial.print("Lux = ");Serial.println(z);
  
   if (z =500){
    outVal =0;
    }
    else {
     if (z<500)
       while (z<500){
        outVal -=1;
        delay(DELAY);
      }
    }
   if (z >500)
    while (z>500){
     outVal += 1;
     delay(DELAY);
    }
    
   dimmer.setPower(outVal);
   Serial.print("Dimmer = "); Serial.println(outVal);
   delay(DELAY);
}

i'm sorry, this the full sketch

Try this:

Basically requestFrom() has two possible signatures (type of arguments)

requestFrom(int, int, int);
and
requestFrom(uint8_t, size_t, bool)

From your code the compiler cannot decide which one to use - that’s often the consequence of using a mix of #defined parameters or integral values as they become int. Using strongly typed variables helps the compiler make decisions.

With your code
Wire.requestFrom(ADDRESS,2,true);
You pass a signature of int,int,bool so the compiler can’t decide which one you want to use.

As true is always a bool type (but can be implicitly cast to int) Your function
void RawData_BH1750(int ADDRESS){
could make ADDRESS a uint8_t instead of int. That would clarify the first param. The last is true so a bool by definition and so you just need to force 2 to be seen as a size_t type and not an int. You likely succeed with this if you write instead 2ul to say it’s 2 as an unsigned long or as @b707 proposed cast the value directly to that type.

So basically I would say try

void RawData_BH1750(uint8_t ADDRESS){
  Wire.beginTransmission(ADDRESS);
  Wire.requestFrom(ADDRESS, 2ul, true); // request a total of 2 registers
  …

Alternatively if you keep things as they are since ADDRESS and 2 are already int use 1 instead of true for the last parameter et you’ll have 3 int and so it will be clear to the compiler which version to choose. Of course the latter is less readable so I would go for the former.

thanks its work, :slight_smile: but, appears this note note: declared here
26 | void ICACHE_RAM_ATTR onTimerISR();
| ^~~~~~~~~~
what is it ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.