Skip to main content
added info
Source Link

Okay guys, finally found the solution for my problem:

At first I thought the capacitor C1 which is connected between RST and GND, was the problem, so I removed it. But this did not fix the problem.

It was indeed a software problem. I programmed the Mega328P using the Arduino IDE and MiniCore.

It seems like for some reason, the standard Arduino commands "pinMode()", or "digitalWrite()" etc. don't work.

But when I'm using the port register commands with DDRx and PORTx, everything works.

So instead of writing

pinMode(PB2, OUTPUT);
digitalWrite(PB2, HIGH);
delay(1000);
digitalWrite(PB2, LOW);
delay(1000);

I wrote

DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
delay(1000);
PORTB &= ~(1<<PB2);
delay(1000);

and that solved my problem.

Why didn't I think of that earlier?

Edit: what also works, is instead of

digitalWrite(PB2, HIGH);

writing

digitalWrite(PIN_PB2, HIGH);

Okay guys, finally found the solution for my problem:

At first I thought the capacitor C1 which is connected between RST and GND, was the problem, so I removed it. But this did not fix the problem.

It was indeed a software problem. I programmed the Mega328P using the Arduino IDE and MiniCore.

It seems like for some reason, the standard Arduino commands "pinMode()", or "digitalWrite()" etc. don't work.

But when I'm using the port register commands with DDRx and PORTx, everything works.

So instead of writing

pinMode(PB2, OUTPUT);
digitalWrite(PB2, HIGH);
delay(1000);
digitalWrite(PB2, LOW);
delay(1000);

I wrote

DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
delay(1000);
PORTB &= ~(1<<PB2);
delay(1000);

and that solved my problem.

Why didn't I think of that earlier?

Okay guys, finally found the solution for my problem:

At first I thought the capacitor C1 which is connected between RST and GND, was the problem, so I removed it. But this did not fix the problem.

It was indeed a software problem. I programmed the Mega328P using the Arduino IDE and MiniCore.

It seems like for some reason, the standard Arduino commands "pinMode()", or "digitalWrite()" etc. don't work.

But when I'm using the port register commands with DDRx and PORTx, everything works.

So instead of writing

pinMode(PB2, OUTPUT);
digitalWrite(PB2, HIGH);
delay(1000);
digitalWrite(PB2, LOW);
delay(1000);

I wrote

DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
delay(1000);
PORTB &= ~(1<<PB2);
delay(1000);

and that solved my problem.

Why didn't I think of that earlier?

Edit: what also works, is instead of

digitalWrite(PB2, HIGH);

writing

digitalWrite(PIN_PB2, HIGH);
Source Link

Okay guys, finally found the solution for my problem:

At first I thought the capacitor C1 which is connected between RST and GND, was the problem, so I removed it. But this did not fix the problem.

It was indeed a software problem. I programmed the Mega328P using the Arduino IDE and MiniCore.

It seems like for some reason, the standard Arduino commands "pinMode()", or "digitalWrite()" etc. don't work.

But when I'm using the port register commands with DDRx and PORTx, everything works.

So instead of writing

pinMode(PB2, OUTPUT);
digitalWrite(PB2, HIGH);
delay(1000);
digitalWrite(PB2, LOW);
delay(1000);

I wrote

DDRB |= (1<<PB2);
PORTB |= (1<<PB2);
delay(1000);
PORTB &= ~(1<<PB2);
delay(1000);

and that solved my problem.

Why didn't I think of that earlier?