Attiny85 and tone not working

Hello everyone,

I’m having a problem with the Attiny default core,

Trying to use the tone with the default platformio does not work, but using arduino IDE and SpenceKonde core with the same code does work, is there a work around?

Can you show what exact code / setup you’re running, and what the behaviour / output wave forms are with Arduino IDE vs PlatformIO? What development board are you using (Digispark USB?)

I’m using a simple attiny85 chip and a USBtinyISP, The code is uploading fine, I can add blinking lights on the middle of my code and i can see it blinking.

Simplified the code a bit for testing:

#include <Arduino.h>

#define BUZZER_PIN 4
#define LED_PIN 1

#define BUZZER_ALARM_FREQUENCY 600

void setup()
{
    pinMode(LED_PIN, OUTPUT);
    pinMode(BUZZER_PIN, OUTPUT);
}

void loop()
{
    tone(BUZZER_PIN, BUZZER_ALARM_FREQUENCY);
    digitalWrite(LED_PIN, HIGH);  
    delay(500);
    noTone(BUZZER_PIN);
    digitalWrite(LED_PIN, LOW);
    delay(500);
}

Buzzer works on arduino but not on platformio (on vscode), to test my theory out, I replaced the cores/tiny definition from platformio with the SpenceKonde (i did a diff, some files are different, but strangely not the tone.cpp), created a new variant called attiny85x

{
  "build": {
    "core": "tiny",
    "extra_flags": "-DARDUINO_ARCH_AVR -DARDUINO_AVR_ATTINY85",
    "f_cpu": "8000000L",
    "mcu": "attiny85",
    "variant": "tinyX5"
  },

Now, if I change my board file from board=attiny85 to attiny85x, the tone function does work under platformIO. So it is definitely something with the core shipped with Atmel AVR platform.

Looking on my oscilloscope, there is no output wave coming from the pin when using plaftormio and the default core, and the output looks fine with the new core or arduino IDE.

How did you install ATTiny support in the Arduino IDE? Does it use the same ATTinyCore?

So this could well be due to an outdated core. There seems to be a month-old pull request regarding upgrading to a newer version of the ATTinyCore. @ivankravets was this noticed?

Yes, it does use the SpenceKonde core, I installed following the documentation on github.

Looking the pull request it does seem similar from the diff that I was looking comparing the core on platformIO and the Github, I can double check if you want, Just need to uninstall the avr core and compare it once again…

Done!

Please re-test with the latest upstream version Atmel AVR — PlatformIO latest documentation

Do I need to uninstall avr on platformio to remove the files that I manually changed to test it out? or it will override everything by default?

PlatformIO should do all work automatically. It will download new version of Arduino framework.