Arduino ATTiny85開發(fā)環(huán)境搭建及使用
ATTiny85開發(fā)板有以下兩種:
第一種:可直接插入U(xiǎn)SB口:
第二種:需要通過USB線來連接電腦:
ATTiny85芯片介紹
Arduino IDE下載及安裝
在Arduino官網(wǎng)Software | Arduino下載最新版Arduino IDE并安裝。
或使用安裝版Arduino IDE。添加ATTiny85開發(fā)板庫
在線安裝:
Arduino IDE下文件-首選項(xiàng)-附加開發(fā)板管理器網(wǎng)址,添加
http:///package_digistump_index.json
Arduino IDE下工具-開發(fā)板-開發(fā)板管理器,搜索找到Digistump AVR Boards項(xiàng)安裝。
上面的方法可能會(huì)存在json無法解析的問題
如果無法安裝請(qǐng)使用下面的離線安裝方式。
離線安裝:
將“DigistumpArduino-master.zip”解壓到Arduino IDE安裝目錄下的hardware文件夾下:
打開DigistumpArduino-master-tools文件夾,解壓“micronucleus-2.0a4-win.zip”到當(dāng)前目錄
打開Arduino IDE 工具-開發(fā)板如下圖所示,發(fā)現(xiàn)新增加的“Digistump AVR Boards”即可。
Arduino ATTiny85驅(qū)動(dòng)安裝
PC首次連接Arduino ATTiny85需安裝USB驅(qū)動(dòng),注意如果你的電腦是第一次連接ATTiny85開發(fā)板則會(huì)聽到USB設(shè)備連接的提示音,不過過了大概5秒左右就斷開連接了,這是因?yàn)闊o法識(shí)別USB驅(qū)動(dòng)造成的。如果不是第一次連接則可能再次插入ATTiny85時(shí)計(jì)算機(jī)就沒有反應(yīng)了。
在以下網(wǎng)址下載:
https://github.com/digistump/DigistumpArduino/releases/download/1.6.7/Digistump.Drivers.zip
驅(qū)動(dòng)正確安裝后在設(shè)備管理器中顯示如下:
程序編譯及下載
ATTiny85開發(fā)板選擇“Digispark(Default – 16.5mhz)”
Arduino IDE 文件-示例下的例程是針對(duì)Digistump開發(fā)板的
打開示例程序Start.ino,工具-開發(fā)板 選擇Digispark(Default – 16.5mhz)
選擇 項(xiàng)目-上傳,注意此時(shí)不要連接ATTiny85開發(fā)板,出現(xiàn)下圖所示的提示后再連接開發(fā)板
燒錄成功的提示如下:
ATTiny85 Pinout
DigitalWrite:
//All pins are capable of Digital output, though P5 is 3 V at HIGH instead of 5 V pinMode(0, OUTPUT); //0 is P0, 1 is P1, 2 is P2, etc. - unlike the analog inputs, for digital outputs the pin number matches. digitalWrite(0,HIGH); //Turn the pin HIGH (5 V) digitalWrite(0,LOW); //Turn the pin LOW (GND)
Digital Read:
注:ATtiny上的內(nèi)部上拉電阻(在將管腳設(shè)置為輸出后通過調(diào)用digitalWrite(0)打開,其中0是管腳編號(hào))比Arduino上的要弱得多(約25千歐),因此板載LED會(huì)干擾它們。如果需要,可以使用其他端口。將電路更改為不需要內(nèi)部上拉,大家可以加入遠(yuǎn)望創(chuàng)客學(xué)堂QQ群, 一起學(xué)習(xí)新知識(shí)。刪除& —等特殊字符18&751-82&17?;蚯袛郘ED軌跡。對(duì)于型號(hào)A,這將適用于型號(hào)B的P1,這將應(yīng)用于P0。(型號(hào)標(biāo)識(shí))
//All pins are capable of digital input. pinMode(0, INPUT); //0 is P0, 1 is P1, 2 is P2, etc. - unlike the analog inputs, for digital inputs the pin number matches. sensorValue = digitalRead(1); //Returns HIGH or LOW (true or false / 1 or 0).
Analog Read:
//You need not set pin mode for analogRead - though if you have set the pin to //output and later want to read from it then you need to set pinMode(0,INPUT); //where 0 is the physical pin number not the analog input number. //See below for the proper pinMode statement to go with each analog read. // The analog pins are referenced by their analog port number, not their pin //number and are as follows: sensorValue = analogRead(1); //Read P2 //To set to input: pinMode(2, INPUT); //THIS IS P2, P2 is analog input 1, so when you are using analog read, you refer to it as 1. //sensorValue = analogRead(2); //Read P4 //To set to input: pinMode(4, INPUT); //THIS IS P4, P4 is analog input 2, so when you are using analog read, you refer to it as 2. //sensorValue = analogRead(3); //Read P3 //To set to input: pinMode(3, INPUT); //THIS IS P3, P3 is analog input 3, so when you are using analog read, you refer to it as 3. //sensorValue = analogRead(0); //Read P5 //To set to input: pinMode(5, INPUT); //THIS IS P5, P5 is analog input 0, so when you are using analog read, you refer to it as 0.
Analog Write:
//P0, P1, and P4 are capable of hardware PWM (analogWrite). pinMode(0, OUTPUT); //0 is P0, 1 is P1, 4 is P4 - unlike the analog inputs, //for analog (PWM) outputs the pin number matches the port number. analogWrite(0,255); //Turn the pin on full (100%) analogWrite(0,128); //Turn the pin on half (50%) analogWrite(0,0); //Turn the pin off (0%)
如果需要實(shí)現(xiàn)USB HID并且對(duì)管腳要求不多的場(chǎng)合可以考慮使用這個(gè)板子。
|