佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 4699|回复: 29

最简单又最便宜的Arduino

[复制链接]
发表于 6-12-2012 07:00 PM | 显示全部楼层 |阅读模式
Arduino没有真正的中文名,直接翻译就很滑稽,可以是:
唉癫佬(毫无用处)
哦癫佬(平平無奇)
爱癫佬(功能可以)
啊癫佬(啊!伟大的癫佬,一级棒)

这里我们打造一个US3.00的Arduino,只是使用一个ATTiny85(ATTiny45,ATTiny44都可以),所以称它为Tiny Arduino。

Tiny Arduino只有八个接脚(Pin),Pin4为接地(Gnd),Pin8为5V(Vcc),Pin1为复位(Reset),Pin2和Pin3原本用来连接Crystal,为了要尽量用完全部IO,所以使用了内部振荡(RC Oscillator),因此Tiny Arduino共有五个IO。以下是Tiny Arduino的功能。
  • 五个IO,各个IO可以设成输入(Input)或者输出(Output)
  • 其中两个IO可以设成PWM
  • 其中三个IO可以设成Analog输入

如果功能不足够,可以通过I2C对外扩展


本帖最后由 西门庆33 于 6-12-2012 07:38 PM 编辑

评分

参与人数 1积分 +100 收起 理由
pic + 100 原创内容

查看全部评分

回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 6-12-2012 07:00 PM | 显示全部楼层
材料
  • 1 x 5V电源power supply
  • 1 x Breadboard (Project board)
  • 1 x ATTiny85 (这就是我们的Tiny Arduino)
  • 1 x Arduino duemilanove(用来上传Sketch至ATTiny85)
  • 1 x 10 uF 电容器capacitors(防止Arduino duemilanove自动复位)
  • 5 x 光二极管LED
  • 5 x 电阻器Resistors
  • 以及少许Wire

由于ATTiny85 本身没有串行(Serial)接口,所以我们必须借用外面的编译器来上载Sketch,这里我们使用Arduino duemilanove上载Sketch至ATTiny85。因此我们必须把Arduino duemilanove设成编译器(in-system programmer)简称为ISP。
  • 将Arduino duemilanove连接至电脑
  • 打开Arduino 软件,这里我使用arduino-0023
  • 按File>Examples>ArduinoISP
本帖最后由 西门庆33 于 6-12-2012 07:15 PM 编辑

评分

参与人数 1人气 +5 收起 理由
oribags + 5 精品文章

查看全部评分

回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:01 PM | 显示全部楼层
  • 按Tools>Board>Arduino Duemilanove or Nano w/ATmega328 或者Arduino UNO

  • 单击Upload icon开始上载Sketch至Arduino duemilanove
  • 现在你的Arduino duemilanove变成ISP编译器了
回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:02 PM | 显示全部楼层
你必须添加plugin支持ATtiny85:
  • 下载ATtiny85 Plugin
  • 找出Arduino sketchbook文件夹,按File>Peferences,我的sketchbook是在D:\My Documents\Arduino如图下
本帖最后由 西门庆33 于 6-12-2012 07:15 PM 编辑

回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:03 PM | 显示全部楼层
  • 如果sketchbook文件夹里没有Hardware文件夹,就自己创建一个。
  • 把已经下载的ATtiny85 Plugin解压到Hardware文件夹里。如图下

完成这步骤后,你会在Tools>Board看到ATtiny85 (w/Arduino as ISP)
本帖最后由 西门庆33 于 6-12-2012 07:46 PM 编辑

回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:03 PM | 显示全部楼层
连接Arduino duemilanove至ATTiny85,接法如图下:
回复

使用道具 举报

Follow Us
 楼主| 发表于 6-12-2012 07:04 PM | 显示全部楼层
这里设计一个跑马灯电路图,五粒LED顺序地跑。
回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:05 PM | 显示全部楼层
  • 按File>New
  • 复制以下跑马灯源码
  • 按Tools>Board>ATtiny85 (w/Arduino as ISP)

  • 单击Upload icon开始上载Sketch至ATtin85
完成上载后,你会看到以下两行错误,那是没问题的
avrdude: please define PPAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PPAGEL and BS2 signals in the configuration file for part ATtiny85 本帖最后由 西门庆33 于 9-12-2012 12:35 PM 编辑

回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 6-12-2012 07:06 PM | 显示全部楼层
跑马灯源码,只占用了8KByte Flash Memory中的804Byte

// The sketch demonstrate a 5 channel running light using ATTiny45/85 micro controller

#define CH1 0 // ATTiny45/85 PIN5
#define CH2 1 // ATTiny45/85 PIN6
#define CH3 2 // ATTiny45/85 PIN7
#define CH4 3 // ATTiny45/85 PIN2
#define CH5 4 // ATTiny45/85 PIN3

long interval = 1000; // set the LED blink speed (1000ms= one second)

void setup()
{
pinMode(CH1, OUTPUT); // set CH1 as output
pinMode(CH2, OUTPUT); // set CH2 as output
pinMode(CH3, OUTPUT); // set CH3 as output
pinMode(CH4, OUTPUT); // set CH4 as output
pinMode(CH5, OUTPUT); // set CH5 as output
}

void loop() {
digitalWrite(CH1, HIGH); // set the LED on
delay(interval); // wait for a second
digitalWrite(CH1, LOW); // set

digitalWrite(CH2, HIGH); // set the LED on
delay(interval); // wait for a second
digitalWrite(CH2, LOW); // set the LED off

digitalWrite(CH3, HIGH); // set the LED on
delay(interval); // wait for a second
digitalWrite(CH3, LOW); // set the LED off

digitalWrite(CH4, HIGH); // set the LED on
delay(interval); // wait for a second
digitalWrite(CH4, LOW); // set the LED off

digitalWrite(CH5, HIGH); // set the LED on
delay(interval); // wait for a second
digitalWrite(CH5, LOW); // set the LED off
}
回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:06 PM | 显示全部楼层
比较复杂的Sketch,占用了8KByte Flash Memory中的1508Byte

#define MAX_CHANNEL 5
#define CH1 0 // ATTiny45/85 PIN5
#define CH2 1 // ATTiny45/85 PIN6
#define CH3 2 // ATTiny45/85 PIN7
#define CH4 3 // ATTiny45/85 PIN2
#define CH5 4 // ATTiny45/85 PIN3

int Channel[MAX_CHANNEL] = {CH1, CH2, CH3, CH4, CH5};

long interval = 500; //speed = 0.5 second

void setup() {
//Serial.begin(9600);
for (byte i=0; i<MAX_CHANNEL; i++) {
pinMode(Channel, OUTPUT); // declare all channel as output
}

allChannelOn(); //turn on all LED for one second during startup
delay(1000);
}

void loop()
{
runDown();
runKnightRider();
for (byte i=0; i<10; i++) { // loop 10 times for random LED
runRandom();
}
}

///////////////////////// turn on all LED
void allChannelOn(void) {
for (byte i=0; i<MAX_CHANNEL; i++) {
digitalWrite(Channel, HIGH);
}
}

///////////////////////// turn off all LED
void allChannelOff(void) {
for (byte i=0; i<MAX_CHANNEL; i++) {
digitalWrite(Channel, LOW);
}
}

///////////////////////// run LED in sequence
void runDown(void) {
for (byte i=0; i<MAX_CHANNEL; i++) {
allChannelOff();
digitalWrite(Channel, HIGH);
delay(interval);
}
}

///////////////////////// Knight Rider
void runKnightRider (void) {
allChannelOff();
for (byte i=0; i<MAX_CHANNEL; i++) {
digitalWrite(Channel, HIGH);
delay(interval);
}
for (byte i=0; i<MAX_CHANNEL; i++) {
digitalWrite(Channel, LOW);
delay(interval);
}
}

///////////////////////// run LED randomly
void runRandom(void) {
int allChannelState, previousState, state;
allChannelState= 0;

for (byte i=0; i<MAX_CHANNEL; i++) {
state= random(2);
allChannelState= allChannelState + state;
digitalWrite(Channel, state);
}

if (allChannelState==0) { //if all LED turned off
// reserved
} else {
delay(interval);
}
}
本帖最后由 西门庆33 于 6-12-2012 07:30 PM 编辑

回复

使用道具 举报

 楼主| 发表于 6-12-2012 07:07 PM | 显示全部楼层
Arduino Tiny支持以下指令
pinMode()
digitalWrite()
digitalRead()
analogRead()
analogWrite()
shiftOut()
pulseIn()
millis()
micros()
delay()
delayMicroseconds()
SoftwareSerial (Arduino 1.0才支持)

这是我的真实例子,左边是ATtiny85,右边是ATMega328形成Arduino ISP。上载完Sketch后,可以把ATMega328和USB至Serial转换器移掉。
原来我的Arduino Duemilanove也是这么简单


最后谢谢High-Low Tech 本帖最后由 西门庆33 于 6-12-2012 07:35 PM 编辑

回复

使用道具 举报

发表于 6-12-2012 10:19 PM | 显示全部楼层
好像很复杂,以我这新手来讲

1 x ATTiny85 (这就是我们的Tiny Arduino)
1 x Arduino duemilanove(用来上传Sketch至ATTiny85)

这两个要哪里买? 还是自己装
回复

使用道具 举报

 楼主| 发表于 6-12-2012 10:49 PM | 显示全部楼层
nok7610 发表于 6-12-2012 10:19 PM
好像很复杂,以我这新手来讲

1 x ATTiny85 (这就是我们的Tiny Arduino)

最复杂处应该是如何program sketch至ATtiny85。如果你已经有了别的programmer(比如AVRISP mkII),只要把Compiled Hex文件烧录去Tiny85就行了,这样就不需要使用Arduino duemilanove。

ATtin85可以去http://my.element14.com/
http://my.element14.com/atmel/at ... -ram-spi/dp/1455162

Arduino duemilanove可以去http://myduino.com
http://www.myduino.com/index.php ... th=37&product_id=51

本帖最后由 西门庆33 于 6-12-2012 10:54 PM 编辑

回复

使用道具 举报

 楼主| 发表于 6-12-2012 11:03 PM | 显示全部楼层
Tiny Arduino只有两个Hareware PWM,如果想要更多PWM,怎么办?可使用Software PWM。
这是网上搜到的一个Sketch,五粒LED慢慢亮着,然后慢慢暗下来,顺序一粒一粒跑。

// code for ATtiny
// fades LEDs on all five pins on and off using software PWM
#define fadeSpeed 5

void setup(){
  for(int pin=0;pin<5;pin++) pinMode(pin, OUTPUT);
}

void loop(){
  for(int pin=0;pin<5;pin++) {
    for(int fade=1;fade<254;fade++) { //fade on
      softPWM(pin, fade, fadeSpeed);
    }
    for(int fade=254;fade>1;fade--) { //fade off
      softPWM(pin, fade, fadeSpeed);
    }
  }
}

void softPWM(int pin, int freq, int sp) { // software PWM function that fakes analog output
  digitalWrite(pin,HIGH); //on
  delayMicroseconds(sp*freq);
  digitalWrite(pin,LOW); //off
  delayMicroseconds(sp*(255-freq));
} 本帖最后由 西门庆33 于 6-12-2012 11:05 PM 编辑

回复

使用道具 举报

发表于 7-12-2012 09:20 PM | 显示全部楼层
西门庆33 发表于 6-12-2012 11:03 PM
Tiny Arduino只有两个Hareware PWM,如果想要更多PWM,怎么办?可使用Software PWM。
这是网上搜到的一个S ...

谢谢分享, 网友受益良多。
回复

使用道具 举报

 楼主| 发表于 9-12-2012 01:01 PM | 显示全部楼层
西门庆33 发表于 6-12-2012 11:03 PM
Tiny Arduino只有两个Hareware PWM,如果想要更多PWM,怎么办?可使用Software PWM。
这是网上搜到的一个S ...

按照14樓的Sketch,我在网站找到时,#define fadeSpeed 原本是20,我特意换成5。如果使用原本的20将会出现闪烁。后来发现是内部的时钟(Internal Clock)出现问题。其实我一直用着1Mhz。

原本是8Mhz,为什么只是1Mhz?
这是因为新的ATTiny85 Fuse bit选择了Div8,意思是8Mhz除8=1Mhz。如果你有AVRISP mkII,在Fuse bit里不选择Div8就行了。这里有另一个方法,用回同一样的Arduino ISP和连接图。但是Arduino软件是使用V1.02版本.

去这里下载ATtiny: https://github.com/damellis/attiny/archive/master.zip
用回4樓5樓的方法把以上下载了的文件解压去Hardware文件夹(去掉attiny-master文件夹),如果图下:
Arduino ATtiny.jpg


回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 9-12-2012 01:02 PM | 显示全部楼层
完全此步骤后,你会在Tools>Board>看到以下画面
Arduono ATtiny Enviroment.jpg
回复

使用道具 举报

 楼主| 发表于 9-12-2012 01:04 PM | 显示全部楼层
把1Mhz变成8Mhz
Arduono ATtiny Enviroment 8Mhz.jpg 本帖最后由 西门庆33 于 9-12-2012 01:47 PM 编辑

回复

使用道具 举报

 楼主| 发表于 9-12-2012 01:05 PM | 显示全部楼层
选择Tools>Pgogrammer>Arduino as ISP如图下:
Arduino as ISP.jpg
回复

使用道具 举报

 楼主| 发表于 9-12-2012 01:07 PM | 显示全部楼层
  • 选择Tools>Burn Bootloader开始写入ATtiny85
  • 完成Burn Bootloader后(其实Tiny Arduino是没有Bootloader的),你会看到以下错误,这是没问题的,它已经把Fuse bit写入ATtiny85。
avrdude: please define PPAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PPAGEL and BS2 signals in the configuration file for part ATtiny85

完成到这里,ATtiny85已经是8MHz了,但是原本里面的program(Sketch)也不运行了,所以你必须重新把Sketch上载至Tiny Arduino。 本帖最后由 西门庆33 于 9-12-2012 04:50 PM 编辑

Burn Bootloader failder.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-4-2024 04:15 PM , Processed in 0.079704 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表