日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Arduino的崇高感和Lilytiny的優(yōu)美感

 新用戶5228KeDY 2021-10-10

Arduino的崇高感和Lilytiny的優(yōu)美感

Arduino的易用性讓我們設計物理實驗的想法成為現(xiàn)實,這說明以方便易用為目的的單片機產(chǎn)品發(fā)展方向是崇高的;而Arduino家庭多數(shù)使用的是Atmel芯片,基于ATtiny的微小型芯片除了Gemma,還有Lilytiny和LilyPad,從名字就能看出她們的優(yōu)美感,如果一定要有中文的名字,也許叫她們莉莉蒂妮和莉莉帕德的好。

不過,Arduino是開源的,因此這種開發(fā)板規(guī)格非常的混亂,不易使用。

第一亂,是這種開發(fā)板的名稱:有的稱為CJMCU Lilytiny,有的稱為MCU Lilytiny,甚至LilyUSB等,總之是CJMCU/MCU與Lilytiny/LilyUSB等組合出來的名稱,這會讓我們在中英文網(wǎng)站里尋找資料時,都很困難。

第二亂,是我們難于辨認在淘寶上的這種開發(fā)板是國內(nèi)自制的,還是原產(chǎn)的。當然從價格與包裝上往往能夠識別,原產(chǎn)的開發(fā)板包裝一般非常精致,而仿制的一般只用防靜電袋包裝且大約7元左右的價格。

這些都不是最重要的,重要的是我確實看不到這種開發(fā)板的DataSheets或者PCB圖,于是P0至P5這6個引腳一直沒弄明白到底有什么功能和區(qū)別。昨天搞明白了手里的Gemma,也燒錄了代碼——Gemma只有3只引腳可用,直徑28mm,而Lilytiny的直徑,則是25mm。做一些事情時,使用Lily的優(yōu)勢是顯然的。

Lilytiny與Gemma的燒錄有微微的不同。記錄如下。

為燒錄Lily的代碼,網(wǎng)上有一種Arduino IDE,是從很久以前的一種Arduino IDE改造的版本演化來的,一切使用都正常,只是IDE還是1.04的版本,同樣的也要安裝libusb-win32 devices這個驅動,否則Lilytiny也不能正常燒寫,因為顯然它也不需要Com號。Lilytiny燒寫和Gemma又有不同,必須在燒寫之前拔掉USB線,然后燒寫,IDE提示插入,這時要在60s內(nèi)插入才能正常燒寫。

為了測試Lilytiny的引腳,我們改造Blink:

void setup() {                
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  delay(50);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  delay(50);
}

找個LED分別插到P0至P5與GND,發(fā)現(xiàn):P0、P1、P2、P3、P4均可作為輸出,P5為復位RST。

給每個引腳寫PWM,只有P0、P1能正常實現(xiàn)。P0、P1為PWM引腳。

同時測試到,板載LED為P1引腳,與UNO的A13類似。

在琢磨Analog的讀和寫的時候,發(fā)現(xiàn)在http:///wiki/digispark/tutorials/basics有一些關于LilyTiny的介紹,復制粘貼,整理如下。

Differences (from the Arduino) and limitations

The Digispark is compatible with the Arduino IDE - that does not, however, mean it can do everything an Arduino can do. In order to achieve the low cost and small size of the Digispark some compromises had to be made.

Here is a list of some of the differences worth considering when designing or troubleshooting (pin differences are outlined in the sections below this list):

The Digispark is powered by an Atmel Attiny85 MCU - this has many differences from an Arduino's ATmega328 and some libraries may not work correctly on it.

The Digispark only has about 6 KB of flash memory for storing your code.

Pin 3 and Pin 4 (P3 and P4) are used for USB communication and programming, while you can use them in your circuit if you are not using USB communication, you may have to unplug your circuit during programming if the circuit would impede the pin states or dramatically affect the voltage levels on these pins.

Pin 3 (P3) has a 1.5 kΩ pull-up resistor attached to it which is required for when P3 and P4 are used for USB communication (including programming). Your design may need to take into account that you'd have to overpower this to pull this pin low.

The Digispark does not have a hardware serial port nor a hardware serial to USB converter. An example library (DigiUSB) is provided, as well as some example code and a serial monitor like program, but communication with the computer will not always be plug and play, especially when other libraries are involved. 這里P3、P4雖然可以用軟串口庫模擬,但是模擬之后,錯誤的時間比正常的時間多太多,大概是不能實用。

DigitalWrite:

void setup() {
    //All pins are capable of Digital output, though P5 is 3 V at HIGH instead of 5 V
//是3V而不是5V,因此可以直接不限流不分壓直接串LED
    pinMode(0, OUTPUT); //0 is P0, 1 is P1, 2 is P2, etc. - unlike the analog inputs, for digital outputs the pin number matches.
}

void loop() {
    digitalWrite(0,HIGH); //Turn the pin HIGH (5 V)
    delay(1000);
    digitalWrite(0,LOW); //Turn the pin LOW (GND)
    delay(1000);
}

Digital Read:

NOTE: The internal pull-up resistor (turned on by calling digitalWrite(0) after setting the pin to output, where 0 is the pin number) are much weaker (about 25 kohm) on an ATtiny than on an Arduino, so the onboard LED interferes with them. If you need them, you can use a different port. Change your circuit to not need the internal pull-up, or cut the LED trace. For Model A this would apply to P1 for Model B this would apply to P0.(Model Identification)

int sensorValue = 0;

void setup() {
    //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.
}

void loop() {
    sensorValue = digitalRead(1); //Returns HIGH or LOW (true or false / 1 or 0).
}

Analog Read:

int sensorValue = 0;

void setup() {
    //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.
}

void loop() {
    // 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: (AKA PWM)

void setup() {
    //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.
}

void loop() {
    analogWrite(0,255); //Turn the pin on full (100%)
    delay(1000);
    analogWrite(0,128); //Turn the pin on half (50%)
    delay(1000);
    analogWrite(0,0);   //Turn the pin off (0%)
    delay(1000);
}

    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多