Out of ideas here, i try using PB0-3 as sinks for a LED matrix and the pins just won't sink.

My test code:

void setup() {
  //bitClear(SPCR, 6);
  pinMode(PD5, OUTPUT);

  pinMode(PB0, OUTPUT);
  pinMode(PB1, OUTPUT);
  pinMode(PB2, OUTPUT);
  pinMode(PB3, OUTPUT);

  digitalWrite(PB0, LOW);
  digitalWrite(PB1, LOW);
  digitalWrite(PB2, LOW);
  digitalWrite(PB3, LOW);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PD5, HIGH);
  digitalWrite(PD5, LOW); 

(Using bog standard Blink as a starting point for tests)

My controller is an ATMega328P programmed using USBaspLoader on my own PCB.

If i connect the physical pin that should be sinking with a piece of wire to ground the LED starts blinking, so the "sending" part seems to work but the "receiving" part doesn't. As you can see i tried manually disabling the SPI port, no luck either. I tried different controllers, among them a good old ATMega8-16, nothing seems to work. I even breadboarded a test circuit but no luck, PortB wont sink.

  • Why are you using the likes of PB3 with digitalWrite() etc?
    – Majenko
    Mar 27, 2020 at 18:47

1 Answer 1


PB3 etc don't refer to Arduino pins. Instead they refer to the bits in the internal registers.

To use digitalWrite() etc you must use Arduino pins not internal register bit numbers.

The pin to port/bit mapping is defined by what board you have selected, and if you want to look it up you should examine the pins_arduino.h file for your selected board.

  • Thanks, i thought, because the compiler wasn't complaining, that they where defined as such. Is there some way to look at the intermediate code? Mar 28, 2020 at 9:49
  • You mean the assembly code? You can disassemble the elf file with avr-objdump -S I guess, but that's probably not of any help to you. In general PBx is defined as x (PB3 is defined as 3) and is intended to be used as PORTB |= (1 << PB3).
    – Majenko
    Mar 28, 2020 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.