Arduino as ISP upload to Attiny167

My program works using the Arduino IDE and using the Arduino as ISP (AttinyCore). On Platformio it seem program okay and I get no errors but the chip doesn’t seem to program. This is my first time using Platformio so any help would be greatly appreciated.

Bryan

platformio.ini:

[env:attiny167]
platform = atmelavr
board = attiny167
board_build.mcu = attiny167
; change MCU frequency
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = stk500v1
; each flag in a new line
upload_flags =
    -P$UPLOAD_PORT
    -b$UPLOAD_SPEED
  
; edit these lines
upload_port = COM9
upload_speed = 19200

Terminal Output

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny167.html
PLATFORM: Atmel AVR 2.0.0 > Generic ATtiny167 
HARDWARE: ATTINY167 8MHz, 512B RAM, 16KB Flash
PACKAGES:
 - framework-arduino-avr-attiny 1.3.2
 - tool-avrdude 1.60300.190424 (6.3.0)
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
Converting RFOG_FIRMWARE_REV_6_.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\attiny167\src\RFOG_FIRMWARE_REV_6_.ino.cpp.o
Linking .pio\build\attiny167\firmware.elf
Checking size .pio\build\attiny167\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.3% (used 58 bytes from 512 bytes)
Flash: [====      ]  35.6% (used 5836 bytes from 16384 bytes)
Configuring upload protocol...
AVAILABLE: stk500v1
CURRENT: upload_protocol = stk500v1
Programming .pio\build\attiny167\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9487 (probably t167)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file ".pio\build\attiny167\firmware.hex"
avrdude: writing flash (5836 bytes):

Writing | ################################################## | 100% 6.41s

avrdude: 5836 bytes of flash written
avrdude: verifying flash memory against .pio\build\attiny167\firmware.hex:
avrdude: load data flash data from input file .pio\build\attiny167\firmware.hex:
avrdude: input file .pio\build\attiny167\firmware.hex contains 5836 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.58s

avrdude: verifying ...
avrdude: 5836 bytes of flash verified

avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)

avrdude done.  Thank you.

The program was verified by avrdude to have been written correctly. Are you sure you don’t have a case of “PIO compiled firmware doesn’t work the same as Arduino IDE compiled one”? Have you tried minimal examples like flashing an LED with PIO so that you know your general setup works? Differences in Arduino IDE core (or core version) might explain the not-working later on.

1 Like

Thank you,

I will give that a try and report back.

Same result with the blink program.

With the same platformio.ini? What code are you running? How did you wire up the ATTiny167? What settings have you chosen in the Arduino IDE which work?

I copied over my platformio.ini from the other project.

Platformio.ini:

[env:attiny167]
platform = atmelavr
board = attiny167
board_build.mcu = attiny167
; change MCU frequency
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = stk500v1
; each flag in a new line
upload_flags =
    -P$UPLOAD_PORT
    -b$UPLOAD_SPEED
     
; edit these lines
upload_port = COM9
upload_speed = 19200

I’m using physical pin 18, Arduino 10 for the LED.

Blinky code:

#include <Arduino.h>

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

// the loop function runs over and over again forever
void loop() {
  digitalWrite(10, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(10, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

In order to get the Attiny167 work with the Arduino I followed this video on Youtube.

Since it looks like you’re on Windows, can you check the %userprofile%\.platformio\packages\framework-arduinoavr\cores\tiny folder and see if the files there are dated December 2018. I suspect the Tiny core is a very old one… perhaps there’s an issue there?

With the new folder structure this is now under C:\Users\<user>\.platformio\packages\framework-arduino-avr-attiny\cores\tiny though. There’s also a tiny-modern core. But the JSON board file is configured to use the tiny core with the variant tinyX7.

… for that framework there’s also a tinyX7_New variant. I’ll check the pinouts.

Hm… now I’ll have to force the new core to download… as my folders from September 2019 and says it’s up to date. but platformio should have v1.3.2 of attinycore… so not an ancient version :wink:

According to the pin map of C:\Users\<user>\.platformio\packages\framework-arduino-avr-attiny\variants\tinyX7 you have

// On the Arduino board, digital pins are also used
// for the analog output (software PWM).  Analog input
// pins are a separate set.

// ATMEL ATTINY167
//
//                   +-\/-+
// RX   (D  0) PA0  1|    |20  PB0 (D  4)
// TX   (D  1) PA1  2|    |19  PB1 (D  5)
//     *(D 12) PA2  3|    |18  PB2 (D  6)
//      (D  3) PA3  4|    |17  PB3 (D  7)*
//            AVCC  5|    |16  GND
//            AGND  6|    |15  VCC
// INT1 (D 11) PA4  7|    |14  PB4 (D  8)
//      (D 13) PA5  8|    |13  PB5 (D  9)
//      (D 10) PA6  9|    |12  PB6 (D  2)* INT0
//      (D 14) PA7 10|    |11  PB7 (D 15)
//                   +----+
//
// * indicates PWM pin.

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] =
{
  NOT_A_PORT,
  (uint16_t)&DDRA,
  (uint16_t)&DDRB,
};

const uint16_t PROGMEM port_to_output_PGM[] =
{
  NOT_A_PORT,
  (uint16_t)&PORTA,
  (uint16_t)&PORTB,
};

const uint16_t PROGMEM port_to_input_PGM[] =
{
  NOT_A_PORT,
  (uint16_t)&PINA,
  (uint16_t)&PINB,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
  PA, /* 0 */
  PA,
  PB, /* 2 */
  PA, /* 3 */
  PB, /* 4 */
  PB,
  PB,
  PB,
  PB,
  PB,
  PA, /* 10 */
  PA,
  PA,
  PA,
  PA,
  PB, /* 15 */
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
  _BV(0), /* 0 */
  _BV(1),
  _BV(6), /* 2 */
  _BV(3), /* 3 */
  _BV(0), /* 4 */
  _BV(1),
  _BV(2),
  _BV(3),
  _BV(4),
  _BV(5),
  _BV(6), /* 10 */
  _BV(4),
  _BV(2),
  _BV(5),
  _BV(7),
  _BV(7), /* 15 */
};

so for Digital pin 10 can you try PA6 (pin 9)? Does the LED blink there?

Nice catch… that’s what I was afraid of when I saw the date of the files initally as Dr Azzy mentioned there was an older, “different and more awkward pinout”… which looks to be that. So assuming that is the OPs issue, adding board_build.variant=tinyX7_New in the platformio.ini to use the core default variant should fix it?

Thank you for that, works great now.

Bryan

2 Likes

Thanks for that Bryan… I’ve done a PR to get the 87 & 167 board definitions updated to use the tinyX7_New variant as the default since this is the expected variant per the ATTinyCore documentation, so assuming that is adopted this won’t be an issue in the future. :slight_smile:

2 Likes