'DDRD' was not declared in this scope

Hey guys, I am using Arduino IDE 1.8.16 with no external libraries nor did I put in any extra libraries yet my simple code gave me an error.

Code:
void setup() {
// put your setup code here, to run once:
DDRD = 0x40;
}

void loop() {
// put your main code here, to run repeatedly:
PORTD = 0x40;
delay(1000);
PORTD = 0x00;
delay(1000);
}

The error message :
Arduino: 1.8.16 (Windows 10), Board: "NodeMCU-32S, 80MHz, 921600"

C:\Users\lynn\OneDrive\Documents\Arduino\sketch_oct30a\sketch_oct30a.ino: In function 'void setup()':

sketch_oct30a:3:1: error: 'DDRD' was not declared in this scope

DDRD = 0x40;

^~~~

C:\Users\lynn\OneDrive\Documents\Arduino\sketch_oct30a\sketch_oct30a.ino:3:1: note: suggested alternative: 'DDR'

DDRD = 0x40;

^~~~

DDR

C:\Users\lynn\OneDrive\Documents\Arduino\sketch_oct30a\sketch_oct30a.ino: In function 'void loop()':

sketch_oct30a:8:1: error: 'PORTD' was not declared in this scope

PORTD = 0x40;

^~~~~

C:\Users\lynn\OneDrive\Documents\Arduino\sketch_oct30a\sketch_oct30a.ino:8:1: note: suggested alternative: 'PRID'

PORTD = 0x40;

^~~~~

PRID

exit status 1

'DDRD' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any ideas on how to fix this?

You did not say what data type DDRD is.
Paul

Which Arduino do you have? There may be no port D.

Edit: NodeMCU is not an Arduino, so Arduino direct port access macros cannot be used.

Hi, I am trying to do port manipulation and it does not seem like I need to give DDRD a data type. I could be wrong

You are attempting to use low level access to registers appropriate for the AVR architecture (Arduino Uno etc.) . The ESP32/ 8266 is completely different.

Hi, I am currently using ATmega328P built into an Arduino UNO

Hi, sorry I still new to this Adruino Coding stuff. How do I change the settings to make it work for an ATmega328P on an Arduino UNO board?

In the IDE:

YOOOOO. THIS WAS IT!!! OMG!!! THANK YOU THANK YOU THANK YOU!!!!! My grades were on the line. You have no idea how much of a life saver you are <3. Thank you so much :DDDDDDD

1 Like