arduino 的學習之路..( Part. 1~11 )
本帖最後由 tommylin 於 2012-9-10 14:57 編輯arduino Mini + USB Mini
LCD 2x16
光敏電阻
尚未遮蔽 光敏電阻 的數值顯示在 LCD
遮蔽 光敏電阻的時候, LCD 數據降低.
cp8Kv7xxNMY 好一段時間沒玩Arduino了,看了影片,我也想翻出來重新玩了
另外youtube的影片只需要在編輯畫麵點插入youtube影片,然後帶入youtube連結中【v=】後面的參數就可以了,先幫您修正。 先針對 Part. 1 做一些完整的補充..
~~ 安裝教學 Step By Step ~~
1. 先安裝電腦 Driver:
Download USBtoTTL Driver "CDM20600.exe",
下載連結 http://www.ftdichip.com/Drivers/VCP.htm
2. 將USB線插入電腦:
這時候打開工作管理員,
確認 COM PORT 的使用和驅動無誤( 使用的 PORT依情況會不同 ),
3. 執行 Arduino 0018:
設定 Tools->Board ( Arduino Mini )
設定 Tools->Serial Port ( COM 3)
4. 光感測器接線:
黑 - GND
紅 - 5V
白 - 信號 ( 接到 Arduino 的 digital pin 0 )
5. Parallax LCD接線:
GND
5V
RX(接到 Arduino 的 TX)
~~ 使用材料 ~~
1. Arduino Mini.
2. USBtoTTL Board.
3. USB Cable.
4. 光感測器
5. LED
6. 麵包板.
7. Parallax LCD
// 程式碼 //
int ledPin = 13; // LED connected to digital pin 13
int PhotoSPin = 0; // Photosensitive connected to digital pin 0
int Analog_val =0; // Photosensitive Val
void setup()
{
Serial.begin ( 9600 );
pinMode(ledPin, OUTPUT); // LED
pinMode(PhotoSPin, INPUT); // Photosensitive
}
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(Analog_val); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(Analog_val); // wait for a second
Analog_val = analogRead(PhotoSPin); //讀取 光敏電阻 的數值
clearLCD (); // 清除 LCD 畫面
//===== 輸出數值到 LCD =====
Serial.print ( "Val= ");
Serial.print ( Analog_val, DEC );
Serial.print ( "\n");
}
// ===== clear the LCD =====
void clearLCD()
{
Serial.print(12, BYTE);
}
arduino Mini 的學習之路..( Part -2 )
本帖最後由 tommylin 於 2010-2-18 20:10 編輯看了網頁上的一些前輩教學,( http://accrochages.drone.ws/en/node/90 )
接續我的 Arduino Part -1 程式 ,
加入應用 Processing 實現了圖形化的數據顯示,
和學習 Serial Port 如何和 PC <-> Arduino 通訊,
一方面也學習使用 Java 底層的應用工具程式 Arduino / Processing
相關網站 www.Arduino.cc / www.processing.org
因為開始複雜化了.. 2 x 16 LCD 不敷使用了.
上面的曲線就是光敏電阻傳回來的數值.
實驗使用環境:
SONY CPU i5 (2.13GHz),RAM 3GB,
Windows 7 (64Bit)
Arduino 0018
Processing 1.0.9
接下來 Project 越來越精彩了... 敬請期待~
http://1.bp.blogspot.com/_8wGLCYoZMqQ/S3rZxlbOUuI/AAAAAAAAABA/Pu6Uzee8QzM/s320/oscilloscope.png
http://tommylin99.blogspot.com ) 本帖最後由 tommylin 於 2010-2-18 20:08 編輯
課目: 伺服馬達的控制( PWM )
http://1.bp.blogspot.com/_8wGLCYoZMqQ/S3tBvOx_DEI/AAAAAAAAABQ/zuUTmvx-8AM/s320/Hitec+HSR-8498HB+Servo+Pin.png
我這個實驗使用的是 Hitec HSR-8498HB 伺服馬達.
目前使用驅動模式選擇第一種已經成功.
這個馬達總共有3種模式,
1. Standard Pulse Mode (Pulse width 550 to 2450 Microseconds)
角度計算式 Servo Angle (degrees) = (Pulse Width (‧S) – 1500) / 10
2. Extended Pulse Mode. (Pulse width 50 to 200 Microseconds) (未完成)
3. Serial Mode. (Pulse width 416 Microseconds) (未完成)
範例程式:
#include
Servo myservo; // create servo object to control a servo
void setup()
{
myservo.attach(9); //連接 Servo 信號到 Digital Pin 9
myservo.writeMicroseconds( 1024 ); //Pulse width 550 to 2450 Microseconds = Standard Pulse Mode
}
void loop()
{} 呵呵
這是很好的教學哩, 繼續加油喔
不過為何你的arduino推的動馬達呢?
還是這顆馬達的電流需求不高!?
arduino mini 很迷你, 一組又便宜 ($450)
初學者玩這個就對了 本帖最後由 tommylin 於 2010-2-17 13:55 編輯
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/G94anJ9bXlo&hl=zh_TW&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/G94anJ9bXlo&hl=zh_TW&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
成功設定 Servo 轉動角度,
讀取 servo 角度數值.
範例程式:
#include <Servo.h>
Servo myservo;// create servo object to control a servo
void setup()
{
Serial.begin( 19200 );
myservo.attach(9);//連接 Servo 信號到 Digital Pin 9
}
int angleVal=550;
void loop()
{
myservo.writeMicroseconds( angleVal ); //Pulse width 550 to 2450 Microseconds = Standard Pulse Mode
if ( angleVal + 100 <= 2450 )
{
angleVal += 100;
delay ( 1000 );
}
else angleVal = 550;
delay ( 300 );
int readdata=0;
readdata = myservo.read ();
Serial.println ( readdata );
} 呵呵
這是很好的教學哩, 繼續加油喔
不過為何你的arduino推的動馬達呢?
還是這顆馬達的電流需求不高!?
...
mzw2008 發表於 2010-2-17 12:21 http://www.robofun.net/forum/images/common/back.gif
Hi 鯨魚大大..
我直接用 Arduino 的 5V 接出來,
電表量馬達電壓大約 4.8 左右,
不知道電流多少 XD
只有接一顆應該OK吧~ 本帖最後由 tommylin 於 2010-2-17 15:01 編輯
更正~~~
剛剛確認下列的代碼是無效的... XD
myservo.read ();
等我研究清楚再來報告... Sorry ..
如果有哪位大大知道怎麼讀取 servo 數值的話,
請不吝賜教..謝謝嚕~ 本帖最後由 mzw2008 於 2010-2-17 16:48 編輯
為何現在不能上傳圖片啊..
誰教我一下咧?
總之這顆要讀取資料得要...
A. 送出一個50us的high訊號
B. 送2~20us的low
C. SERVO會進入"暫停" low 狀態, 約125us
D. SERVO 會"傳回"一個high的訊號, 持續時間550~2450 (就是SERVO目前位置)
E. SERVO 回復LOW 250 us
F . 恢復原狀, SERVO又可繼續受到控制
因為這種讀取方式, 使得讀取位置的時候, SERVO會暫時停頓
SERVO的扭力和速度都會"暫時"減少, 所以不能用的太頻繁 這樣說好了, 他的原廠文件提到, 這東西要能精準控制
好像是使用Serial Mode會比較好, 能使用的指令會比較詳細和多功能 感謝鯨魚大大的解說..
和 Datasheet 上面說的..
我有看沒有懂 = =
我目前功力不夠.. 所以先跳過了..
先進行下一個課目練習嚕~ 本帖最後由 tommylin 於 2010-3-10 16:29 編輯
網站好像不提供圖片上傳了..
先把圖上傳到別的網站..然後做連結... 測試一下...
http://1.bp.blogspot.com/_8wGLCYoZMqQ/S4vwQ3PQf2I/AAAAAAAAALo/ve55NqOmzSU/s320/DSC03093.JPG 原來如此...
不過這張照片不妥吧
等一下被愛護動物人士告虐待動物喔 換了一張... 這張的背肌... 漂亮吧~ 本帖最後由 tommylin 於 2010-7-11 11:36 編輯
Part 4
控制 servo 轉動的速度,
而且要轉動的 Smooth
影片如下:
rGG4y5_GM9A
原始碼如下:
#include <Servo.h>
Servo myservo;// create servo object to control a servo
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
int pulse =2450;
int dir=1;
int offset=1;
void loop()
{
myservo.writeMicroseconds( pulse );
if ( pulse + offset >= 2450 ) dir = -1;
else if ( pulse - offset <= 600 ) dir = 1;
pulse += ( offset * dir);
Serial.println ( pulse, DEC );
} 本帖最後由 tommylin 於 2010-7-11 15:46 編輯
換轉動上臂的 servo , 最慢速..9wN21YOj3AM 本帖最後由 tommylin 於 2010-7-11 16:23 編輯
換轉動上臂的 servo , 中速..
no3vtc-3zD8 本帖最後由 tommylin 於 2010-8-27 11:48 編輯
arduino Mini 的學習之路..( Part -5 )
曠課了好久 @@ 把買了幾個月的零件翻出來試試,
課目: RGB Led 的控制.
電路圖:
http://2.bp.blogspot.com/_8wGLCYoZMqQ/TGzdb1S4RuI/AAAAAAAAANA/Vy3y8PQwZgs/s1600/RGB+LED+circuit.bmp
這個實作..關鍵在電路板上印 "-" 的地方要接 DC + .. 不要問我為什麼(我也不知道)
程式中, pin 的 Value 255 是關閉 LED, 明暗的數值是 0~254 (靠 Gooooogle 老師教的 )
影片:
evcyGZuxiNk
原始程式碼:
int R_ledPin = 9;
int G_ledPin = 10;
int B_ledPin = 11;
int ledPin = 13;
// val 255 = off
int R_val=254;
int G_val=254;
int B_val=254;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode( R_ledPin, OUTPUT);
pinMode( G_ledPin, OUTPUT);
pinMode( B_ledPin, OUTPUT);
Serial.begin ( 9600 );
analogWrite ( R_ledPin, R_val );
analogWrite ( G_ledPin, G_val );
analogWrite ( B_ledPin, B_val );
delay ( 1000 );
}
int dir=0;
int color = 0;
int offset = 5;
void loop()
{
digitalWrite(ledPin, HIGH);
switch ( color )
{
case 0: analogWrite ( R_ledPin, R_val ); break;
case 1: analogWrite ( G_ledPin, R_val ); break;
case 2: analogWrite ( B_ledPin, R_val ); break;
}
if ( dir == 0 )
{
if ( R_val - offset > 0 )
{
R_val -= offset;
}
else
{
R_val = 0;
dir = 1;
}
}
if ( dir == 1 )
{
if ( R_val + offset < 255 )
{
R_val += offset;
}
else
{
R_val = 254;
dir = 0;
if ( color + 1 < 3 ) color ++;
else color = 0;
}
}
clearLCD (); // 清除 LCD 畫面
// 輸出數值到 LCD
Serial.print ( "R= ");
Serial.print ( R_val, DEC );
Serial.print ( "\n");
}
// ===== clear the LCD =====
void clearLCD()
{
Serial.print(12, BYTE);
} Part 6:
這個版好冷@@ 我來貼一些...
最近連續做了2個和馬達有關的練習..
提供各位參考嚕..
Stepper motor 步進馬達的控制:
步進馬達的控制:
把老舊的 彩色印表機拆了,
發現裡面有一顆步進馬達,
使用 Arduino 接上馬達的4條線,
我使用了 pin 9~12,
輕易控制馬達前進後退和速度..
http://4.bp.blogspot.com/-5cdwjBbpRms/TWE84ER0B4I/AAAAAAAAAOI/85M9HdBS9iY/s1600/DSC04994.JPG
Code:
#include
const int stepsPerRevolution = 100;
Stepper myStepper(stepsPerRevolution, 9,10,11,12);
void setup() {
myStepper.setSpeed(100);
Serial.begin(9600);
}
void loop() {
Serial.println("clockwise");
myStepper.step(stepsPerRevolution * 10);
delay(500);
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution * 10 );
delay(500);
}
影片:
F9liKrB990I