Attiny24 (Attiny2313) pinmapping false? Blink ist not working!

Hello,
I tested the Arduino Blink example with the Attiny 13, -2313 and -24 controllersfrom Atmel. It only worked with the Attiny 13. The assigned port did not flash on the other two controllers!
The following warning message was issued on the Attiny 2313 and 24 controllers during compilation:

C:\users\xxx.platformio\packages\framework-arduino-avr-attiny\variants\
tinyX4/pins_arduino.h:156:2: warning: #warning “This is the
COUNTERCLOCKWISE pin mapping - make sure you’re using the pinout diagram
with the pins in counter clockwise order” [-Wcpp]
#warning “This is the COUNTERCLOCKWISE pin mapping - make sure you’re
using the pinout diagram with the pins in counter clockwise order”

How do I use the clockwise order?

Program code:

#include <Arduino.h>

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(PA0, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(PA0, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(PA0, LOW);
  // wait for a second
  delay(1000);
}

Platformio.ini:

[env:attiny24]
platform = atmelavr
board = attiny24
framework = arduino
; change MCU frequency
;board_build.f_cpu = 1000000L

upload_protocol = custom
upload_port = COM5
upload_speed = 19200
upload_flags =
    -C
    ; use "tool-avrdude-megaavr" for the atmelmegaavr platform
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -c
    avrispv2
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

Best regards

This board setting contains the build info

so it’s using the ATTinyCore in the variant tinyX4. The used framework core version in

The available variants are per this.

As you can see, there’s tinyX4 and tinyX4_reverse as possible variants. But, both will throw a “warning” reminding you which pin mapping is used

So it doesn’t really make a lot of difference if you use the right macros / variables to refer to your pins.

In your code you write

i.e. PA0 everywhere to refer to the pin. This is wrong. PA0 is a definition inside the IO header file of Atmel, but the Arduino core uses a pin mapping number (“digital pin X”) that you must use.

The mapping is shown as in the comments and above – a pinMode(0) would refer to digital pin 0 aka PB0 in the tinyX4 variant (and PA0 in the reversed varaiant).

There exist convenience macros

Which are always correct no matter which variant you use (reversed or non-reversed).

So you must just use these. Rewrite your code as

#include <Arduino.h>

void setup()
{
// initialize LED digital pin as an output.
pinMode(PIN_A0, OUTPUT);
}

void loop()
{
// turn the LED on (HIGH is the voltage level)
digitalWrite(PIN_A0, HIGH);
// wait for a second
delay(1000);
// turn the LED off by making the voltage LOW
digitalWrite(PIN_A0, LOW);
// wait for a second
delay(1000);
}

and the LED shoul blink.

Now regarding the

You can change the variant per

board_build.variant = tinyX4_reverse

in the platformio.ini to use the reverse order.

The correctness of the blink sketch is unaffected when using the PIN_A0 macro, as previously said, so if you’re using these macros to refer to your pins, there’s no nee to use the reversed pin mapping.

Also, the author of the Arduino core provides a handy pinout reference sheet at ATTinyCore/ATtiny_x4.md at 1.3.2 · SpenceKonde/ATTinyCore · GitHub.

Hello maxgerhardt,

thank you very much for your detailed answer!
With the right pin number it works fine.

Now I understand the backround a litte better :wink:

Best regards RM