Has something changed in IDE?????? Ax / Dx for Pins

Hello

I used the IDE 3 years ago now I want to do something new, downloaded the latest IDe and did like before but get Errors compiling....

I really don't understand why because it was working before.....

For example:

'void setup()':
MySketch:7:18: error: 'D3' was not declared in this scope

#define PowerLED D3

Or:

MySketch:23:33: warning: integer overflow in expression [-Woverflow]

unsigned long MessTimer = (1000 * 60 * 10); // Mess Abstand (10 Min)

I'm pretty sure this is not a problem of my programming.

I don't get any of these errors if I insert the mentioned lines into a sketch. I'm using IDE 1.8.9, board is set to UNO. What did you use?

Some boards define Dn names for digital pins. Most do not.

Grab your calculator. 1000 * 60 * 10 is what? Is that a valid value for an int? It does NOT matter that you want the result stored in an unsigned long. Because all the values are ints, integer registers are used.

Make one of the values an unsigned long (1000UL), and the computation will be done using long registers, and no overflow will occur.

I'm using 1.8.9 as well

I just noticed in my old sketch I did not use Dx for pins but the pin number lets say 13 instead.

Can't you use Dx in defines maybe? But the precompiler should exchange it before the compiler works on it or not?

Very confusing....

PaulS:
Some boards define Dn names for digital pins. Most do not.

Grab your calculator. 1000 * 60 * 10 is what? Is that a valid value for an int? It does NOT matter that you want the result stored in an unsigned long. Because all the values are ints, integer registers are used.

Make one of the values an unsigned long (1000UL), and the computation will be done using long registers, and no overflow will occur.

  1. Why is this a problem of the board? It is something the compiler translates rigth?

  2. I used the "unsigned long" and it works with my old sketch if I compile it in this IDE but not the new one I am writing now.

So 1000UL works for this problem but....

  1. Why doesn't it gibe an error with my old script having exactly the same
  2. define is not working wit Dx for me, maybe he only gives an error if you try to use it lateron?
    like:
    pinMode(PowerLED, OUTPUT);

Any ideas?

  1. Why is this a problem of the board? It is something the compiler translates rigth?

The preprocessor substitutes the value (D3) wherever the name (PowerLED) appears. If you have a statement like:

  digitalWrite(PowerLED, HIGH);

the compiler will see

  digitalWrite(D3, HIGH);

There may, or may not, depending on the board you have selected, a #define statement that assigns a numeric value to D3. For the UNO, there is not. So, for the UNO, the compiler says that D3 is an undefined name.

Re: 2, it didnt work before either; I think before they may have suppressed that warning in the past, but I can assure you the value stored to MessTimer was not what you intended.

It's a warning, not an error - it compiles, but doesnt fo what you expect. Warnings dont prevent it from compiling, errors do.

ok thanks so I found a bug in my earlier code.

But now I tried "const int PowerLED = D3;" and get:

MySketch: 'D3' was not declared in this scope

const int PowerLED = D3;

So does it mean I cannot use Dx on the uno if I understand you correctly? I'm pretty sure it did work earlier...

I thought the Uno had Dn defines, but I don't see them in the variant pins_arduino.h at least in the current version of the official arduino core, so it makes sense that they don't work.

I have never made use of them, so I couldn't say if they ever worked - I always just use the pin numbers.

Thanks but for my understanding the Dx and Ax were so you can easyly translate this to every board pinout....

For example I design on an Uno but want that later on an Pro mini.

They will probably be the same nut there are other configurations...

Gorkde:
Thanks but for my understanding the Dx and Ax were so you can easyly translate this to every board pinout....

For example I design on an Uno but want that later on an Pro mini.

They will probably be the same nut there are other configurations...

All the Dn defines, where present, are just defined to the number after the D - so it's no different to use the number than the Dn defines.

The An defines work as you say

The pin numbering on all the '328p-based boards is identical (in fact, they all use the same variant definition!)

The only place I've seen Dn pin notation used is on certain ESP8266 boards like the WeMos D1 Mini. These names are used to match the pin labels on the silkscreen of the ESP8266 board. The ESP8266 core uses regular pin number to refer to the ESP8266's GPIO pin numbers but some board manufacturers to remap the pin numbers either so that they would match more closely to the Uno pinout as in the case of the WeMos D1 R2, or just so the pin numbers would be consecutive on the board rather than random as in the case of the WeMos D1 Mini. The GPIO pin numbers do not match the Dn pin names:

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t RX   = 3;
static const uint8_t TX   = 1;

My suspicion is that before when you were able to use D3 in your code you were using an ESP8266 board but now you're trying to compile it for the Uno, which does not have Dn pin names defined.

DrAzzy:
All the Dn defines, where present, are just defined to the number after the D - so it's no different to use the number than the Dn defines.

The An defines work as you say

The pin numbering on all the '328p-based boards is identical (in fact, they all use the same variant definition!)

What core? Can you give me link?
From what I've seen over the years, the arduino.cc supplied board cores that come with the IDE like the AVR core, have never defined Dn pin symbols.

While some cores have them like the esp8266, but on the boards withing the cores that have them, things it can get confusing for some people as Dn is not the same pin as n.
i.e. using D3 is not guaranteed be the same as using 3.

--- bill

No idea where I saw it, as it was some time ago and I didn't give it much thought. I swear I've seen a list of defines of digital pins Dn where each one was just defined as the number. But maybe I am conflating things I've seen.

Regardless, using the pin numbers, rather than Dn will cause no issues for the OP, and as we all agree, the current arduino cores do not have Dn defines.

It seems I found the problem....

I tried to use Pin numbers instead A0 or D0.... This compiled but did get me the wrong output....

Then I realized:
Digital Pins are no longer labled as D5 but 5 instead while analog Pins are labled A0-A5....
This is pretty riddiculus in my opinion!

This is not easier but way more confusing for beginners as well as people used to the old labeling!

Eiter they should use Pin numbers or Ax and Dx

Gorkde:
It seems I found the problem....

I tried to use Pin numbers instead A0 or D0.... This compiled but did get me the wrong output....

Then I realized:
Digital Pins are no longer labled as D5 but 5 instead while analog Pins are labled A0-A5....
This is pretty riddiculus in my opinion!

This is not easier but way more confusing for beginners as well as people used to the old labeling!

If you are using naked pin numbers and not addressing the proper pin, then either you have selected the incorrect board type or are using a wemos board.

While some 3rd party core board variants support using Dn symbols for digital pins
I've not seen Dn symbols in the arduino.cc supplied AVR cores and board types of an any version of the IDE going back to before 1.0 and up to the present.

Naked number constants has always worked for both arduino digital pins and arduino analog pins.
The An symbols were created in IDE version 1.0 when the concept of board variants was also invented/added.
However as far as I've seen, Dn symbols were never added to the arduino.cc supplied cores board variants.
And even though the An symbols were added, naked constants still worked. i.e. 0 is the same A0 for analog operations.

I'll agree that there can be confusion for the esp8266 Wemos boards (which are only a subset of the boards in the esp8266 core).
On those particular boards, you must use Dn to control the associated pin.
This was a trade off between UNO compatibility and performance. It was carried over into the Wemos mini devices.

On all other boards you simply use the naked number constant.
There may be some 3rd party cored variant files that do define Dn symbols but I have not see that the official Arduino cores ever created these.

Can you provide a specific version of the IDE, core and board type that you were using that supported Dn but now doesn't?

Perhaps you are thinking of the Dn symbols with some other notations you may have seen like
PIN_{port}{bit} that is in some 3rd party AVR cores and board types.

This creates defines like PIN_D0, PIN_D1, PIN_B2 etc... but the Dn symbols are not for digital pin 0 and digital pin 1 but rather AVR port D bit 0 and AVR port D bit 1 etc....

More recent arduino.cc core and board variant files now contain PIN_An symbols for the analog pins.
IMO, this was not a good thing to add as the An symbols already existed and the PIN_An symbols collide with 3rd party AVR and board types that were already using PIN_{port]{bit} notation. i.e. PIN_A0 on the third party core was AVR port A bit 0 but on the now on the newer IDEs and arduino.cc AVR core, PIN_A0 means the same as A0 which is the same analog pin 0.

--- bill