控制器

如何将ATtiny45/85作为Arduino使用

字号+ 作者:duino123.com 来源:未知 2016-05-18 16:26 我要评论( )

由于ATtiny微小的体积和更低的成本,在控制比较简单的场合或者空间局限的情况下使用非常方便,本文将教你如何使用ATtiny45和ATtiny85微控制器作为Arduino。

PLCLIVE.COM注:

如何将ATtiny45/85作为Arduino使用

由于ATtiny微小的体积和更低的成本,在控制比较简单的场合或者空间局限的情况下使用非常方便,本文将教你如何使用ATtiny45和ATtiny85微控制器作为Arduino。

Did you know you can use an Atmel ATtiny45 or ATtiny85 microcontroller with Arduino software? Well you do now. The team at the High-Low Tech Group at MIT have published the information and examples on how to do this, and it looked like fun – so the purpose of this article is to document my experience with the ATtiny and Arduino and share the instructions with you in my own words. All credit goes to the interesting people at theMIT HLT Group for their article and of course to Alessandro Saporetti for his work on making all this possible.

简介:

请各位先不要激动,使用之前请先了解ATtiny的如下局限性:

局限1 – ATtiny之所以叫“tiny”是有原因的:

左侧芯片即ATtiny,是不是很可爱

可见,我们可用的IO管脚很少,请看ATtiny的管脚布置:

所以我们只有3个模拟量输入 (管脚7,3,2) 和两个数字量输出兼容PWM (管脚5,6)。管脚4为GND,管脚8为5V.

局限2 – memory. The ATtiny45 has 4096 bytes of flash memory available, the -85 has 8192. So you may not be controlling your home-built R2D2 with it.

局限3 – available Arduino functions. As stated by the HLT article, the following commands are supported:

Other functions may work or become available over time.

局限4 – You need Arduino IDE v1.0.1 or higher, except for v1.0.2. So v1.0.3 and higher is fine.

在项目中规划ATtiny的时候一定要谨记以上局限性。

下面开始:

You can use an existing Arduino-compatible board as a programmer with some external wiring. Before wiring it all up – plug in your Arduino board, load the IDE and upload the ArduinoISP sketch which is in the File>Examples menu. Whenever you want to upload a sketch to your ATtiny, you need to upload the ArduinoISP sketch to your Arduino first. Consider this sketch the “bridge” between the IDE and the ATtiny.

电路图:

schematicuno

Depending on the Arduino board you’re using, you may or may not need the 10uF capacitor between Arduino RST and GND. Follow the schematic above each time you want to program the ATtiny.

软件:

From a software perspective, to use the ATtinys you need to add some files to your Arduino IDE. First,download this zip file. Then extract the”attiny” folder and copy it to the “hardware” folder which sits under your main Arduino IDE folder, for example:

hardwarelocationfolder

 Now restart the Arduino IDE. As you’re using the Arduino as a programmer, you need select “Arduino as ISP” – which is found in the Tools>Programmer menu. Next – select the board type using theTools>Board  menu. Select the appropriate ATtiny that you’re using – with the 1 MHz internal clock option. Now you can enter and upload your ATtiny sketch. When uploading sketches you may see error messages as shown below:

errors

如果出现以上信息,无须担心,属于正常情况。

为ATtinys创建Arduino程序:

When creating your sketches, note that the pin number allocations are different for ATtinys in the IDE. Note the following pin number allocations:

  • digital pin zero is physical pin five (also PWM)
  • digital pin one is physical pin six (also PWM)
  • analogue input two is physical pin seven
  • analogue input three is physical pin two
  • analogue input four is physical pin three

For a quick demonstration, load the Blink example sketch – File>Examples>1. Basics>Blink. Change the pin number for the digital output from 13 to 0. For example:
 

void setup()
{
pinMode(0, OUTPUT);
}
void loop() {
digitalWrite(0, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(0, LOW); // set the LED off
delay(1000); // wait for a second
}

Upload the sketch using the methods described earlier. If you’re using programmer method one, your matching circuit is:

blinksch

If you’re using programmer method two, this will blink the on-board LED.

示例:

We test the digital outputs with digital and PWM outputs using two LEDs instead of one:

finalexampleschematic1

程序如下:
 

void setup()
{
   pinMode(0, OUTPUT);
   pinMode(1, OUTPUT);
}
void loop()
{
   for (int a=0; a<6; a++)
   {
     digitalWrite(0, HIGH); // set the LED on
     digitalWrite(1, LOW); // set the LED off
     delay(1000); // wait for a second
     digitalWrite(0, LOW); // set the LED off
     digitalWrite(1, HIGH); // set the LED on
     delay(1000); // wait for a second
   }
for (int z=0; z<3; z++)
{
   for (int a=0; a<256; a++)
   {
     analogWrite(0, a);
     analogWrite(1, a);
     delay(1);
   }
   for (int a=255; a>=0; --a)
   {
     analogWrite(0, a);
     analogWrite(1, a);
     delay(1);
   }
}
}

如需更详细资料,如有好资源分享,请加入QQ交流群:214461008

欢迎阅读,欢迎转载,不用注明出处!本站只提供入门和进阶资料,做您学习的小伙伴!

老司机也欢迎光临指导!有好内容请加群:214461008 不要看声明了,看内容吧!

相关文章
  • [2016.05.24] 如何利用Arduino UNO烧录ATmega328P PU的bootloade

    [2016.05.24] 如何利用Arduino UNO烧录ATmega328P PU的bootloade

    2016-05-24 09:30

  • 如何选择你的第一块Arduino?

    如何选择你的第一块Arduino?

    2016-04-23 23:32

网友点评
Arduino