Please post all error messages as <CODE/>
Often there is interesting stuff outside the edges of a screenshot.
In this case, the error is easy to reproduce
String s;
uint16_t i = 42;
s = i;
I don't have an R3, but on Uno and ESP32 for example, you can get away with this, assigning an integer to a String
, via automatic conversion. But not on R4, the combination of libraries and compiler switches suggests more than one potential route, and so the operation is "ambiguous"
FQBN: arduino:renesas_uno:unor4wifi
Using board 'unor4wifi' from platform in folder: $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0
Using core 'arduino' from platform in folder: $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino: In function 'void setup()':
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: ambiguous overload for 'operator=' (operand types are 'arduino::String' and 'uint16_t {aka short unsigned int}')
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:97:11: note: candidate: arduino::String& arduino::String::operator=(const arduino::String&) <near match>
String & operator = (const String &rhs);
^~~~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:97:11: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::String' is ambiguous
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:74:2: note: candidate: arduino::String::String(const arduino::__FlashStringHelper*) <near match>
String(const __FlashStringHelper *str);
^~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:74:2: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::__FlashStringHelper*' [-fpermissive]
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:70:2: note: candidate: arduino::String::String(const char*) <near match>
String(const char *cstr = "");
^~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:70:2: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:98:11: note: candidate: arduino::String& arduino::String::operator=(const char*) <near match>
String & operator = (const char *cstr);
^~~~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:98:11: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:99:11: note: candidate: arduino::String& arduino::String::operator=(const arduino::__FlashStringHelper*) <near match>
String & operator = (const __FlashStringHelper *str);
^~~~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:99:11: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::__FlashStringHelper*' [-fpermissive]
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:100:11: note: candidate: arduino::String& arduino::String::operator=(arduino::String&&) <near match>
String & operator = (String &&rval);
^~~~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:100:11: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: conversion from 'uint16_t {aka short unsigned int}' to 'arduino::String' is ambiguous
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:74:2: note: candidate: arduino::String::String(const arduino::__FlashStringHelper*) <near match>
String(const __FlashStringHelper *str);
^~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:74:2: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::__FlashStringHelper*' [-fpermissive]
s = i;
^
In file included from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/IPAddress.h:24:0,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/ArduinoAPI.h:30,
from $HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/Arduino.h:4,
from $HOME\Temp\arduino\sketches\CD95D4E408ABF4D9F618A5940DD416F8\sketch\sketch_sep26b.ino.cpp:1:
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:70:2: note: candidate: arduino::String::String(const char*) <near match>
String(const char *cstr = "");
^~~~~~
$HOME\Arduino15\packages\arduino\hardware\renesas_uno\1.2.0\cores\arduino/api/String.h:70:2: note: conversion of argument 1 would be ill-formed:
$HOME\Temp\.arduinoIDE-unsaved2024826-2796-wdwqbt.43k3\sketch_sep26b\sketch_sep26b.ino:4:7: error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]
s = i;
^
exit status 1
Compilation error: ambiguous overload for 'operator=' (operand types are 'arduino::String' and 'uint16_t {aka short unsigned int}')
That's a lot of detail. Remove all the file path/line/column stuff (mostly redundant in this case anyway)
In function 'void setup()':
error: ambiguous overload for 'operator=' (operand types are 'arduino::String' and 'uint16_t {aka short unsigned int}')
s = i;
^
'operator =
' is assignment of course: "can't assign one of these as one of those because there is more than way to do it." First way:
note: candidate: arduino::String& arduino::String::operator=(const arduino::String&) <near match>
String & operator = (const String &rhs);
^~~~~~~~
note: conversion of argument 1 would be ill-formed:
error: conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::String' is ambiguous
s = i;
^
rhs
means "right-hand side" of the equal sign. The most obvious thing to assign to a String
is another String
, but converting an int
to a String
is itself ambiguous!
note: candidate: arduino::String::String(const arduino::__FlashStringHelper*) <near match>
String(const __FlashStringHelper *str);
^~~~~~
note: conversion of argument 1 would be ill-formed:
error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::__FlashStringHelper*' [-fpermissive]
s = i;
^
Convert an integer to a pointer (to a __FlashStringHelper
) to load a String
? Only allowed with the -fpermissive
compiler switch. Actually just wrong in this case, so good thing it doesn't try.
note: candidate: arduino::String::String(const char*) <near match>
String(const char *cstr = "");
^~~~~~
note: conversion of argument 1 would be ill-formed:
error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]
s = i;
^
Another pointer, this time to a C-string, to convert to a String
? No, it's a number, not a pointer.
note: candidate: arduino::String& arduino::String::operator=(const char*) <near match>
String & operator = (const char *cstr);
^~~~~~~~
conversion of argument 1 would be ill-formed:
error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]
s = i;
^
Instead of assigning String
to String
, how about assigning a pointer to C-string? No, the same conversion as before, and not allowed.
note: candidate: arduino::String& arduino::String::operator=(const arduino::__FlashStringHelper*) <near match>
String & operator = (const __FlashStringHelper *str);
^~~~~~~~
note: conversion of argument 1 would be ill-formed:
error: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const arduino::__FlashStringHelper*' [-fpermissive]
s = i;
^
__FlashStringHelper
again? No.
note: candidate: arduino::String& arduino::String::operator=(arduino::String&&) <near match>
String & operator = (String &&rval);
^~~~~~~~
note: conversion of argument 1 would be ill-formed:
error: conversion from 'uint16_t {aka short unsigned int}' to 'arduino::String' is ambiguous
OK, how about an rvalue reference? Note that this is trying to convert "to 'arduino::String'
", while the first was "to 'const arduino::String'
" It considers again converting to the same two kinds of pointers, so: of course, no.
It appears that R4 is missing a valid conversion, not that there are too many working ones.
So how to work around this? You could make your variables the appropriate type, which would likely require other changes elsewhere. The simplest fix is to do an explicit conversion manually:
ano = String(now.year());
mes = String(now.month());
The corresponding constructor is explicit
explicit String(unsigned int, unsigned char base=10);
which is why the compiler couldn't just do it for you.