M♪o 之學習筆記本《子》開關

派生碼訊

子 鼠

蕩蕩天門萬古開,
幾人歸去幾人來。
山河雖好非完璧,
不信黃金是禍胎。

子鼠︰ 兩態系統是數位設計之本。數學完整的編碼體系布林代數為集其大成者也。

雖然已經說明編輯體例,不略說說改寫規則,恐怕失真。這 M♪o 她學習的孜孜不倦,閱讀之熱情不息,讓作者苦惱。由於我們與她們之間的『社會』不同與『科技』有異,所以有時不得不以『人類』之角度來引用『術語』和『名物』,萬一有所『誤解』,絕非 M♪o 之『過』,實是改寫者之『錯讀』所造成的,特此聲明。舉例而言 ,『踏天之紀』改為『伏羲之時』等等,若加上『註釋』未免閱讀不易,又恐讓作者自曝其短,所以不出『校記』,希望讀者知之。再者該筆記篇幅巨大,因此只擇部分『譯改』,萬一有前後不搭,尚祈見諒。

 

派︰伏羲之時,已知太極陰陽,然而太極之非陰非陽與或陰或陽之陰陽不測的古意雖喪,大道源流依據不失。現今正負之理,始於『卡文迪什』親身體驗 ☿☹︰

鐵線』的電傳導性要比『蒸餾水』好上四億倍,『海水』又比『雨水』好一百倍,然而『飽和』的『海鹽溶液』要比『雨水』更好了七百二十倍……

;其後『歐姆』歸結為『因勢 VIR』 ☿☺︰

V = I \times R

。之後又有了『焦耳』的『熱功當量』︰

他將一段導線浸入定量的水中,然後量測上升的溫度,在實驗過各種材質的導體、多種電流大小與不同時間長短後發現

Q = I^2 \cdot R \cdot t

,此處 Q 是熱量【焦耳】、 I 是電流量【安培】、 R 是電阻值【歐姆】、 t 時間【秒】。

故說『熱焦』 ☿☺ 電路者常是瞬間『勢利』 V \times I 過大太久所致。

※註︰  ☿☹ 以及 ☿☺ 是 M♪o 筆記裡的特有符號,雖說推想是表達 M♪o 的『心情』,就其使用脈落而言,彷彿更像是種『聯想法』。

 

生 ︰『針太極』  ☿☺ Pin 出入者之電路特性︰

raspberry-pi-circuit-gpio-input-pins

 

☆ 編者言說明

因選擇了『樹莓派』作為『實習』的計算機主體,故 M♪o 筆記裡的一切有關資料『改編』以『樹莓派』基金會官方的『說明』為主,不足時,補以其它來源。比方說,此『輸出入』『針』腳, M♪o 記之以『太極』者,蓋因為既可用作『輸出』,又可用於『輸入』。而且當作『輸入』時,若是不設定『 Pull-up 』或『 Pull-down 』,如《 An introduction to GPIO and physical computing on the Raspberry Pi 》所講︰

Input

GPIO outputs are easy; they are on or off, HIGH or LOW, 3v3 or 0v. Inputs are a bit trickier because of the way that digital devices work. Although it might seem reasonable just to connect a button across an input pin and a ground pin, the Pi can get confused as to whether the button is on or off. It might work properly, it might not. It’s a bit like floating about in deep space; without a reference it would be hard to tell if you were going up or down, or even what up or down meant!

This is why you will see phrases like “pull up” and “pull down” in Raspberry Pi GPIO tutorials. It’s a way of giving the input pin a reference so it knows for certain when an input is received.

If you’d like to have a go at using the GPIO as an input then have a look at our screaming jelly baby and quick reaction game tutorials for Python, or a reaction game for Scratch.

,果有類似 M♪o 所用之『物』的特性。雖想自然之理是一脈相通,有時確有偏勝之處,特以『☆ 編者言說明』符號表明此係編者之言,對錯真假與 M♪o 無涉。

△ 電工之行, 安 安特第一。【※ Tux 語言,專有詞法,請參考 Tux@rpi ︰《踏天之梯》,未免於失實失義,用古今字轉譯,存其會意。此處『安特』意指︰安全性重要的不得了!!】

△ 電路之設,在『內』『外』之『阻導』之配,《 圖 》圖曰︰

EGHS-PullUpDownSwitchProtected

,須細究其理。

☆ 編者言說明

由於不知那《圖》是何書?也許是 TUX 的教科書吧!還好 M♪o 她喜歡自己手繪,編者方得『按圖索驥』,求可匹配的『電路圖』,此後文章,凡用《 圖 》符示者,皆同此意。這裡的這張圖,出自《 Physical computing with Raspberry Pi 》︰

BACKGROUND:

Circuit with current-limiting resistors in place. Diagram from eLinux.

When a GPIO pin is set as an input it is “floating” and has no defined voltage level. For us to be able to reliably detect whether the input is high or low we need to tie it so that it is always connected and either reads high or low.

To tie the pin we connect either a Pull Up or Pull Down resistor. A Pull down resistor connects the pin to ground through a large resistor, this means that when the switch is open there is a path to ground and so it will read low. When the switch is pressed (with the other side connected to 3.3V) there is a lower resistance path to high and so the pin will read high. The large (10kΩ) resistor ensures that only a little current is drawn when the switch is pressed.

Setting up a circuit like this means that we will be able to take reliable readings from a switch, however we could still damage the pins if they are accidentally set to an output. If we drive it low the output is connected directly to ground. Pushing the button will then create a short circuit between 3.3V and ground! To make this safer we put in a current limiting resistor (1kΩ will do) to make sure the Pi can handle the current drawn.

,因為意義相通而選擇。

 

碼 ︰無 習 。【※蓋指沒有習作】

行 ︰……

☆ 編者言說明

此處『…』者並非『留白』不譯,因為那是 M♪o 自己的先行練習,轉譯需要一個『軟體環境』,於此假設我們主要使用︰

‧ Python3

‧ python-rpi.gpio

‧ wiringPi

‧ ……

在此選擇 Python3 的原因,是因為如

W!o 的派生‧十日談之《六》 一文上所講︰

然而從 Python 3.0 開始,『派生』已經支持『萬國碼』 Unicode 的『標識符』,這意味著︰

# 可以使用中文『標識符』
>>> 甲=7
>>> 乙=甲*甲-3*甲+2
>>> 甲;乙
7
30
>>>

。這使得翻譯『軟體習作』更貼近 M♪o 的精神。同時假設讀者使用的是已經中文化了的官方版 Raspbian 發行版。

如是那段文字,可以轉譯成︰安裝設定軟體『習作環境』。

# 更新至最新版
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

# 安裝 Python 開發環境與套件工具
sudo apt-get install python2.7-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo apt-get install python3-pip

# 應該已是預設安裝
sudo apt-get install git-core
sudo apt-get install python-rpi.gpio

# 安裝 wiringPi
git clone git://git.drogon.net/wiringPi
cd wiringPi/
./build

# 安裝 wiringPi Python 套件
sudo pip install wiringpi2
sudo pip-3.2 install wiringpi2
#

過去作者曾經寫過相關若干套《系列文章》,讀者也可瀏覽,選讀有興趣的部分,此處僅列出每套的首篇,以利檢索︰

Physical computing ︰《一》引言

春雷早發︰樹莓派 2 Model B ︰早鳥篇

大樹底下好乘涼 ︰ 《開場白》

‧  W!o 的派生‧十日談之《一》

《派生》 Python 作坊【甲】尋本溯源

 

訊 ︰需要自修『電路學』知識,才能充分理解『電路工作』原理。 ☿☹☺ 千里之行,始於足下。