再谈使用Arduino UNO对ATtiny85进行编程

Atmel(已被Microchip Technology收购)的ATtiny85芯片可以作为Arduino来使用,可以满足一些要求体积小且只需要少量PWM引脚的场景下使用。要了解更多ATtiny85的特性,请查看Microchip网站上的 ATtiny85数据表。前期的文章中也对ATtiny85的编程做过介绍,比如:

使用Arduino Uno对ATtiny85编程

用ATTINY45制作SD卡音乐播放器

ATtiny85芯片如何变成Arduino呢?ATtiny85只是一个单片机芯片,使用它之前,我们需要一个ISP来编程。本文的重点就是编写一个Arduino Uno的程序,使它作为ISP对ATtiny85进行编程。并使ATtiny85能够像普通Arduino一样使用。

Arduino UNO作为ISP

要为ATtiny85编程,首先需要将Arduino UNO设置为ISP模式。这是为了确保启动代码上传时,Arduino IDE在能在ISP模式下检测到Arduino UNO。

首先将Arduino UNO通过USB接口连接到PC端,接着启动Arduino IDE软件,然后打开“ArduinoISP”示例文件,选择“文件 > 示例 > ArduinoISP ”。

Arduino ISP example

 

Arduino ISP upload

连接ATtiny85和Arduino UNO

要对ATtiny85进行编程,我们通过面包板将其连接到Arduino UNO,如下图所示。

Attiny85连接Arduino uno的电路连接图

引脚对应关系如下:

5V – Vcc
Gnd – Gnd
Pin 13 – Pin 2
Pin 12 – Pin 1
Pin 11 – Pin 0
Pin 10 – Reset

添加核心文件

默认情况下,Arduino IDE是不支持ATtiny85的。因此,我们还需要将其核心文件添加到Arduino IDE中。在Arduino IDE中选择“文件 > 首选项”,

Arduino IDE Preferences

在“附加开发板管理网址”中,添加下面的GitHub代码,添加地址“https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json”。

Arduino IDE Add-on Manager URL

验证地址是否有效,可直接复制后在浏览器中打开,显示json代码如下:

{
  "packages": [
    {
      "name": "attiny",
      "maintainer": "David A. Mellis",
      "websiteURL": "https://github.com/damellis/attiny",
      "email": "",
      "help": {
        "online": ""
      },
      "platforms": [
        {
          "name": "attiny",
          "architecture": "avr",
          "version": "1.0.0",
          "category": "attiny",
          "help": {
            "online": ""
          },
          "url": "https://github.com/damellis/attiny/archive/702aa287455f7e052cf94fd4949398fec0ef21b8.zip",
          "archiveFileName": "702aa287455f7e052cf94fd4949398fec0ef21b8.zip",
          "checksum": "SHA-256:bfffa4a700e42ae993895f5eea22bc369ba5ac3ea36eca18ac5f72a05bb60ab5",
          "size": "5005",
          "boards": [
            {"name": "ATtiny45"},
            {"name": "ATtiny85"},
            {"name": "ATtiny44"},
            {"name": "ATtiny84"}
          ],
          "toolsDependencies": [
            {
              "packager": "arduino",
              "name": "avr-gcc",
              "version": "4.8.1-arduino5"
            },
            {
              "packager": "arduino",
              "name": "avrdude",
              "version": "6.0.1-arduino5"
            }
          ]
        },
        {
          "name": "attiny",
          "architecture": "avr",
          "version": "1.0.1",
          "category": "attiny",
          "help": {
            "online": ""
          },
          "url": "https://github.com/damellis/attiny/archive/76ca88ce3c195fcba8e8a645084e352965dc80e0.zip",
          "archiveFileName": "76ca88ce3c195fcba8e8a645084e352965dc80e0.zip",
          "checksum": "SHA-256:49a4dfc3796caf2533050b0b962ae0affb2471b8ded1283936d7b712cc1fdff1",
          "size": "5719",
          "boards": [
            {"name": "ATtiny45"},
            {"name": "ATtiny85"},
            {"name": "ATtiny44"},
            {"name": "ATtiny84"}
          ],
          "toolsDependencies": [
            {
              "packager": "arduino",
              "name": "avr-gcc",
              "version": "4.8.1-arduino5"
            },
            {
              "packager": "arduino",
              "name": "avrdude",
              "version": "6.0.1-arduino5"
            }
          ]
        },
        {
          "name": "attiny",
          "architecture": "avr",
          "version": "1.0.2",
          "category": "attiny",
          "help": {
            "online": ""
          },
          "url": "https://github.com/damellis/attiny/archive/6bba7d452af59d5190025bc870ec9e53d170e4d9.zip",
          "archiveFileName": "6bba7d452af59d5190025bc870ec9e53d170e4d9.zip",
          "checksum": "SHA-256:1654a8968fea7d599255bd18430786f9c84340606e7a678b9cf9a3cd49d94ad7",
          "size": "5913",
          "boards": [
            {"name": "ATtiny25"},
            {"name": "ATtiny45"},
            {"name": "ATtiny85"},
            {"name": "ATtiny24"},
            {"name": "ATtiny44"},
            {"name": "ATtiny84"}
          ]
        }
      ],
      "tools": []
    }
  ]
}

如果以前添加过这个地址,也可以直接选择即可。

Arduino IDE Add-on Manager URL

后续Arduino IDE 的设置与 使用Arduino Uno对ATtiny85编程文章中设置一致,安装开发板支持包即可。这样我们就拥有了一款小体积的Arduino了。

 

 

 

标签: