“SKU:RB-02S043 光電測(cè)速碼盤(pán)套件”的版本間的差異
來(lái)自ALSROBOT WiKi
(→?使用方法) |
(→?產(chǎn)品相關(guān)推薦) |
||
第118行: | 第118行: | ||
通過(guò)串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速 | 通過(guò)串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速 | ||
? | == | + | ==資料下載== |
[[文件:erweima.png|230px|無(wú)框|右]] | [[文件:erweima.png|230px|無(wú)框|右]] | ||
? | + | * 產(chǎn)品資料 | |
? | + | 下載鏈接:https://pan.baidu.com/s/1XWomNov02Z87UlrCiaTHRg | |
? | + | 提取碼:6mpi <br/> | |
? | + | * 產(chǎn)品購(gòu)買鏈接:http://lifestyle201.com/goods-185.html | |
? | + | ||
? | + | ||
? | + | ||
? | + |
2018年9月29日 (六) 14:21的版本
目錄 |
產(chǎn)品概述
Arduino 光電碼盤(pán)是哈爾濱奧松機(jī)器人科技有限公司2012年最新推出的光電測(cè)試傳感器,該產(chǎn)品是一款短響應(yīng)速度、開(kāi)關(guān)量輸出的測(cè)速模組,配合白色碼盤(pán)可以測(cè)量電機(jī)轉(zhuǎn)速,該款測(cè)試碼盤(pán)可以直接固定到雙輸出軸直流減速電機(jī)上方便安裝,簡(jiǎn)單易用。
規(guī)格參數(shù)
- 工作電壓:5v DC
- 工作電流:小于 20mA
- 工作溫度:10℃ - 30℃
- 與傳感器擴(kuò)展板I/O兼容
- 傳感器類型:模擬輸出
- 平面尺寸:15×35×16mm
- 重量大?。?4g
接口定義
- S:信號(hào)控制端(Signal)
- +:電源(VCC)
- -:地(GND)
使用方法
接線方法1
將光電測(cè)速碼盤(pán)的 S 端口接到控制器的數(shù)字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。
例子程序1
#include "MsTimer2.h" #define ENCODER_READ 5 unsigned int encoderPos,a; void setup() { Serial.begin(9600); MsTimer2::set(1000, flash); // 500ms period MsTimer2::start(); counterStart(); } void loop() { } void counterStart() { TCCR1A=0; TCCR1B=0; TCNT1=0; TCCR1B = TCCR1B | 7; } unsigned int getCount() { unsigned int count; count = TCNT1; TCNT1=0; TCCR1B = TCCR1B & ~7; TCCR1B = TCCR1B | 7; return count; } void flash() { encoderPos = getCount(); a=encoderPos*6; Serial.print("rotate speed = "); Serial.print(a); Serial.println(" RPM"); }
程序效果1
在串口打印出"rotate speed ="及 "RPM"相關(guān)數(shù)據(jù)
接線方法2
將光電測(cè)速碼盤(pán)1的 S 端口接到控制器的數(shù)字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND
將光電測(cè)速碼盤(pán)2的 S 端口接到控制器的數(shù)字 I/O 口 3,+ 和-分別接到電源的 +5V 和 GND
例子程序2
#include "TimerOne.h" const byte MOTOR1 = 2; // Motor 1 使用外部中斷 0 const byte MOTOR2 = 3; // Motor 2 使用外部中斷 1 unsigned int counter1 = 0; unsigned int counter2 = 0; float diskslots = 10; //碼盤(pán)數(shù) void ISR_count1() { counter1++; //Motor1 } void ISR_count2() { counter2++; //Motor 2 } // TimerOne 中斷 void ISR_timerone() { Timer1.detachInterrupt(); // Stop the timer Serial.print("Motor Speed 1: "); float rotation1 = (counter1 / diskslots) * 60.00; // Motor 1 Serial.print(rotation1); Serial.print(" RPM "); counter1 = 0; Serial.print("Motor Speed 2: "); float rotation2 = (counter2 / diskslots) * 60.00; // Motor 2 Serial.print(rotation2); Serial.println(" RPM"); counter2 = 0; Timer1.attachInterrupt( ISR_timerone ); } void setup() { Serial.begin(9600); Timer1.initialize(1000000); // 設(shè)定時(shí)間為 1s attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING); // 當(dāng)檢測(cè)到上升沿時(shí),計(jì)數(shù) attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING); Timer1.attachInterrupt( ISR_timerone ); // 開(kāi)啟Timer中斷 } void loop() { }
程序效果2
通過(guò)串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速
資料下載
- 產(chǎn)品資料
下載鏈接:https://pan.baidu.com/s/1XWomNov02Z87UlrCiaTHRg
提取碼:6mpi
- 產(chǎn)品購(gòu)買鏈接:http://lifestyle201.com/goods-185.html