以下英文部分引自原網址:

https://www.arduino.cc/en/Tutorial/DigitalPins

Tutorial裡,foundation裡的 Microcontrollers 部分,4個項目的第一個部份

這篇是邊翻譯邊作為讀書筆記用的,沒有翻得很精準(word by word),大致意思對而已,僅供參考。

==================

在此先列出一些單字的翻譯

以下翻譯,同樣單字可能採用不同翻譯,但其實都是指同一件事(不負責任翻譯)

configued  被配置;被設定

pull-up resistor  提升電阻、上拉電阻

pin  接腳、腳位

 

=================

 

 

Digital Pins   數位接腳

 

  The pins on the Arduino can be configured as either inputs or outputs. This document explains the functioning of the pins in those modes.

While the title of this document refers to digital pins, it is important to note that vast majority of Arduino (Atmega) analog pins, may be configured, and used, in exactly the same manner as digital pins.

 

  Arduino上的pin腳可被配置成輸入或輸出。本文件解釋那些模式下的運作(funcitoning)。

  雖然此文件的標題指的是數位接腳,但很重要且需要注意的:Arduino上的絕大多數的類比接腳,都可以完全如同數位接腳的方式---被配置、使用。

 

 

Properties of Pins Configured as INPUT    設定成輸入時,接腳的特性

 

  Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode() when you're using them as inputs. Pins configured this way are said to be in a high-impedance state. Input pins make extremely small demands on the circuit that they are sampling, equivalent to a series resistor of 100 megohm in front of the pin. This means that it takes very little current to move the input pin from one state to another, and can make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a photodiode, or reading an analog sensor with a scheme such as RCTime.

 

  Arduino (Atmega)的接腳,預設即是輸入(inputs),所以當你要把接腳作為輸入使用時,並不需要用pinMode() 明確宣告成輸入(inputs)。

  這樣配置的接腳被稱為處於高阻抗態(high-impedance state)。當取樣(sampling)時,輸入接腳對電路只有極低的需求,等同於在接腳前串聯一個100M歐姆的電阻一樣。

  這意味著,輸入接腳從一個狀態到另一個狀態,只需要耗費非常小的電流,對實現下列功能來說都是很有用處的:電容按壓感測器(capacitative touch sensor)讀取LED(作為光電感測器),或是scheme讀取類比感測器,例如RCTime。(這部分不確定翻的對不對,因為scheme有蠻多種意思的,但這裡僅是敘述用途,不太重要,不太care可跳過)

 

 

  This also means however, that pins configured as pinMode(pin, INPUT) with nothing connected to them, or with wires connected to them that are not connected to other circuits, will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.

 

  然而,這也意味著,在沒有接上任何東西的情況下,或是只有接上線,但是線沒有接上任何其他電路時,配置為pinMode(pin, INPUT)的接腳,會隨機改變接腳狀態(pin state),從環境中拾取電子雜訊,或從附近的接腳電容性耦合狀態。

 

 

Pullup Resistors with pins configured as INPUT   接腳設定為INPUT時的上拉電阻

 

  Often it is useful to steer an input pin to a known state if no input is present. This can be done by adding a pullup resistor (to +5V), or a pulldown resistor (resistor to ground) on the input. A 10K resistor is a good value for a pullup or pulldown resistor.

 

  通常,如果沒有輸入,把輸入腳位導向一個已知的狀態(known state),會是蠻有用的技巧。這可藉由增加一個上拉電阻(到+5V),或是一個下拉電阻(接到地)到接腳上來完成。

  對於上拉或下拉電阻,10K 歐姆是一個不錯的值。

 

 

Properties of Pins Configured as INPUT_PULLUP   配置為INPUT_PULLUP的接腳之特性

 

  There are 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed by setting the pinMode() as INPUT_PULLUP. This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on.

 

  Atmega晶片上內建有20k歐姆的上拉電阻,可以軟體來存取控制。藉由將pinMode()設定為INPUT_PULLUP,內建電阻可以被控制。

  這有效地反向(invert)了輸入模式,HIGH表示感應器是關閉的(off),LOW表示感應器是開啟的(on)。

 

 

  The value of this pullup depends on the microcontroller used. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board.

 

  上拉電阻的值依使用的微控器而定。在大部分的AVR板(AVR-based boards)中,上拉電阻的值是保證介於20k~50k歐姆。在Arduino Due中,上拉電阻的值是介於50k~150k歐姆。

  要知道實際的值的話,請參閱你的板子上的微控器的datasheet。

 

 

  When connecting a sensor to a pin configured with INPUT_PULLUP, the other end should be connected to ground. In the case of a simple switch, this causes the pin to read HIGH when the switch is open, and LOW when the switch is pressed.

 

  當把一個感測器接上一配置為 INPUT_PULLUP的腳位時,感測器的另一端應該接到地(ground)。

  以簡易的開關的情況來說,當開關是開路時(open),這使得接腳讀到HIGH(1),而當開關被壓下時,接腳讀到LOW(0)。

 

 

  The pullup resistors provide enough current to dimly (昏暗地、微微地)light an LED connected to a pin that has been configured as an input. If LEDs in a project seem to be working, but very dimly, this is likely what is going on.

 

  上拉電阻提供了足夠的電流,以微微地點亮連接到配置為輸入的接腳上的LED。如果在一個專案中,LED似乎有在工作,但僅僅是微微的發光,這就很有可能是原因。

  (編按:就是說明明是把腳位設定成輸入,不是輸出,但LED還是會亮,那就是因為啟用了PULLUP電阻的關係。)

 

 

  The pullup resistors are controlled by the same registers (internal chip memory locations) that control whether a pin is HIGH or LOW. Consequently, a pin that is configured to have pullup resistors turned on when the pin is an INPUT, will have the pin configured as HIGH if the pin is then switched to an OUTPUT with pinMode(). This works in the other direction as well, and an output pin that is left in a HIGH state will have the pullup resistors set if switched to an input with pinMode().

 

  上拉電阻是由---控制接腳是HIGH或是LOW的暫存器(內部晶片記憶體位置)---同樣的暫存器所控制。

  因此,當一接腳是個輸入(INPUT)時,上拉電阻設定為開啟,如果該接腳接著被用 pinMode()設定為輸出。

(OUTPUT),會有設定為HIGH的接腳(即輸入時,上拉電阻ENABLE(1),改成輸出時,會直接變成輸出HIGH(1))

  換個方向說也是一樣的,如果一處於高態(HIGH state)的輸出接腳,被用pinMode()切換成輸入,接腳的上拉點組會是開啟的(ENABLE)。

 

 

  Prior to Arduino 1.0.1, it was possible to configure the internal pull-ups in the following manner:

  在Arduino 1.0.1以前,配置內部上拉電阻可能是用下列的方式:

 

pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors

 

  NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V instead of the expected 5V because the onboard LED and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 13 as a digital input, set its pinMode() to INPUT and use an external pull down resistor.

 

  注意:作為數位輸入,相較於其他數位接腳,數位接腳13會比較難使用,因為在大部分的板子上,它有焊了一個LED以及電阻,接在上面。

  如果你開啟了內部的20k上拉電阻,電壓會在1.7V左右浮盪,而不是預期的5V,因為板子上的LED以及串聯電阻把電壓位準拉低了,意即:回傳永遠都是LOW。

  如果你必須使用腳位13來當數位輸入,設定 它的pinMode() 為INPUT,並使用外部下拉電阻(external pull down resistor)。

 

 

Properties of Pins Configured as OUTPUT   設定為OUTPUT的腳位之特性

 

  Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial (大量的、相當程度的)amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This is enough current to brightly light up an LED (don't forget the series resistor), or run many sensors, for example, but not enough current to run most relays, solenoids, or motors.

 

  以 pinMode()設定為OUTPUT的腳位,被稱為處於低阻態( low-impedance state)。這意味著他們能提供大量的電流給其他電路。

  Atmega的腳位能推出(source)(提供正電流)或汲取(sink)(提供負電流)高達40mA的電流,給其他的裝置/電路。

  對點亮LED燈(別忘了串接限流電阻),或是運作很多顆感應器來說,電流量應該是足夠了。(但是仍不足以推動繼電器、螺線圈、電動機)

 

 

  Short circuits on Arduino pins, or attempting to run high current devices from them, can damage or destroy the output transistors in the pin, or damage the entire Atmega chip. Often this will result in a "dead" pin in the microcontroller but the remaining chip will still function adequately. For this reason it is a good idea to connect OUTPUT pins to other devices with 470Ω or 1k resistors, unless maximum current draw from the pins is required for a particular application.

 

  Arduino上的腳位的短路,或是試圖在腳位上運作高電流,皆會損燒或毀壞接腳內的輸出電晶體,或損壞整個Atmega晶片。

  通常,這會導致微控器有個「死掉的」接腳,但是晶片其餘的部分仍然正常的工作。

  基於這個原因,在接到其他裝置的OUTPUT腳位上,接上470歐姆或1k歐姆的電阻,會是一個不錯的想法。

  (除非基於特定應用,需要從接腳上汲取最大電流)

 

 

 

arrow
arrow

    迷途工程師 發表在 痞客邦 留言(0) 人氣()