Skip to main content

How to Program an ATtiny85 with an Arduino Uno

What is aan DFPlayer?ATtiny85?

The DFPlayer Mini MP3 Player For ArduinoATtiny85 is a small8-bit AVR microcontroller based on AVR enhanced RISC architecture. It has an 8-pin interface (PDIP) and lowcomes price MP3 module with an simplified output directly toin the speaker.category Theof modulelow-power canmicrocontrollers. beThis usedmicrocontroller asis a stand alone module with attached battery, speakerdesigned and pushmanufactured buttonsby or used in combination with an Arduino UNO or any other with RX/TX capabilities.Microchip. Know More

dfplayer.jpgattiny85.jpeg

Set the Arduino Uno Into ISP Mode

So that the Arduino can act as a device to upload code to ATtiny85. File - Examples - Arduino ISP - ArduinoISP

Add this line #define USE_OLD_STYLE_WIRING to the code before setup()

UPLOAD!

Wiring

Wiring up the sensor is quite complex, theThe pins are not labelled so you will have to refer to the pinout. dfplayerpinout.pngattiny85_pinout.jpeg Arduino --> ATtiny85

DFplayer Mini Wiring
  1. VCC to 5V --> Vcc (Power)
  2. RX to D2 via 1K resistor
  3. TX to D3
  4. SPK_1 to Speaker(+) red wire 8)
  5. GND to--> GND (Ground)4)
  6. SPK_2Pin to13 Speaker(-)-> blackPin wire2 (7)
  7. Pin 12 --> Pin 1 (6)
  8. Pin 11 --> Pin 0 (5)
  9. Pin 10 --> Reset (1)
potentiometer Wiring
  1. right pin to 5V (Power)
  2. middle pin to A0 (Signal)
  3. left pin to GND (Ground) dfplayermini_bb.png

File handling

The order you copy the mp3 into micro SD card will affect the order mp3 played , which means play(1) function will play the first mp3 copied into micro SD card.

MACOnly User Attention!
 Ifwhen you are usinguploading Mac OS Xcode to copyATtiny85
thePut mp3,a the10uF filecapacitor systembetween willGND automaticallyand addRESET hiddenon filesArduino like: "._0001.mp3" for index, which this module will handle as valid mp3 files.

Adding Attiny85 to Boards Manager

ItWe ishave reallyto annoying.make SoATtiny youcompatible with Arduino IDE first, so that we can changechoose YourSDCardNameATting85 infrom Tools -> Board Go to Arduino Preference

Copy the below commandcode and then runpaste it ininto terminalAdditional toBoards eliminateManager thoseURLs, files.

if

dot_cleanyou /Volumes/<YourSDCardName>

Library

DFRobotDFPlayerMini library will be used for this module. Wealready have a tutorialboard onmanager URL just add a comma before pasting. Click OK and restart Arduino IDE.

https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

howAdditional Boards Manager URLs.png

Go to installTools a- libraryBoard - Boards Manager, search for ATtiny, then install! attinyBoard.png here.

Get Started

InBefore thisuploading example,the code, we arehave usingto change some settings.

  1. Tools -> Board scroll to the potentiometerbottom controlselect twoATtiny25/45/85
  2. audios.
  3. Tools It-> willProcessor--> play8 theMHz first(internal)
  4. audio
  5. Tools-->Programmer-->Arduino whenas theISP
  6. potentiometer
  7. Check turnsthat toall rightwiring, capacitor, and playboard theselections secondare whencorrect.

toolsSetting.png

Open up a basic code and upload as usual! If it turnsdoesn't towork, left.

try
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

const int pot = A0;
int potValue = 0;

// Create the Player object
DFRobotDFPlayerMini player;

void setup() {

  pinMode(pot, INPUT);

  // Init USB serial port for debugging
  Serial.begin(9600);
  // Init serial port for DFPlayer Mini
  softwareSerial.begin(9600);

  // Start communication with DFPlayer Mini
  if (player.begin(softwareSerial)) {
    Serial.println("OK");

    // Set volume to maximum (0 to 30).
    player.volume(30);
  } else {
    Serial.println("Connecting to DFPlayer Mini failed!");
  }      
}

void loop() {

	potValue = analogRead(pot);

	if(potValue > 500 ){ 

	 static unsigned long timer = millis();
 	 if (millis()Tools - timerBurn >Bootloader

2000) { //2000 is the duration of the audio(1) timer = millis(); //(2) is the 2rd file in the sd card, the order = the order you copied the file to it player.play(2); } }else { static unsigned long timer = millis(); if (millis() - timer > 3000) { //3000 is the duration of the audio(2) timer = millis(); player.play(1); } } }