“SKU:RB-02S043 光電測速碼盤套件”的版本間的差異
來自ALSROBOT WiKi
(以“右 ==產品概述== Arduino 光電碼盤是哈爾濱奧松機器人科技有限公司2012年最新推出的光電測試傳感...”為內容創(chuàng)建頁面) |
(→?資料下載) |
||
(未顯示1個用戶的3個中間版本) | |||
第15行: | 第15行: | ||
* -:地(GND) | * -:地(GND) | ||
==使用方法== | ==使用方法== | ||
? | === | + | ===example1_Arduino=== |
+ | * 硬件連接 | ||
將光電測速碼盤的 S 端口接到控制器的數字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。 | 將光電測速碼盤的 S 端口接到控制器的數字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。 | ||
? | + | ||
+ | * 示例程序 | ||
<pre style='color:blue'> | <pre style='color:blue'> | ||
#include "MsTimer2.h" | #include "MsTimer2.h" | ||
第56行: | 第58行: | ||
Serial.println(" RPM"); | Serial.println(" RPM"); | ||
}</pre> | }</pre> | ||
? | + | * 程序效果 | |
在串口打印出"rotate speed ="及 "RPM"相關數據 | 在串口打印出"rotate speed ="及 "RPM"相關數據 | ||
? | == | + | |
+ | ===example2_Arduino=== | ||
+ | * 硬件連接 | ||
+ | 將光電測速碼盤1的 S 端口接到控制器的數字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND<br/> | ||
+ | 將光電測速碼盤2的 S 端口接到控制器的數字 I/O 口 3,+ 和-分別接到電源的 +5V 和 GND<br/> | ||
+ | |||
+ | * 示例程序 | ||
+ | <pre style='color:blue'>#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; //碼盤數 | ||
+ | |||
+ | 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); // 設定時間為 1s | ||
+ | attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING); // 當檢測到上升沿時,計數 | ||
+ | attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING); | ||
+ | Timer1.attachInterrupt( ISR_timerone ); // 開啟Timer中斷 | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | |||
+ | }</pre> | ||
+ | |||
+ | * 程序效果 | ||
+ | 通過串口打印出兩個電機的轉速 | ||
+ | |||
+ | ==資料下載== | ||
[[文件:erweima.png|230px|無框|右]] | [[文件:erweima.png|230px|無框|右]] | ||
? | + | * 產品資料 | |
? | + | 下載鏈接:https://pan.baidu.com/s/1BBy385RbyeitgAo0U6DXxA | |
? | + | 提取碼:ym1r | |
? | + | * 產品購買鏈接:http://gharee.com/goods-185.html | |
? | + | ||
? | + | ||
? | + | ||
? | + |
2021年12月10日 (五) 09:37的最后版本
目錄 |
產品概述
Arduino 光電碼盤是哈爾濱奧松機器人科技有限公司2012年最新推出的光電測試傳感器,該產品是一款短響應速度、開關量輸出的測速模組,配合白色碼盤可以測量電機轉速,該款測試碼盤可以直接固定到雙輸出軸直流減速電機上方便安裝,簡單易用。
規(guī)格參數
- 工作電壓:5v DC
- 工作電流:小于 20mA
- 工作溫度:10℃ - 30℃
- 與傳感器擴展板I/O兼容
- 傳感器類型:模擬輸出
- 平面尺寸:15×35×16mm
- 重量大小:24g
接口定義
- S:信號控制端(Signal)
- +:電源(VCC)
- -:地(GND)
使用方法
example1_Arduino
- 硬件連接
將光電測速碼盤的 S 端口接到控制器的數字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。
- 示例程序
#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"); }
- 程序效果
在串口打印出"rotate speed ="及 "RPM"相關數據
example2_Arduino
- 硬件連接
將光電測速碼盤1的 S 端口接到控制器的數字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND
將光電測速碼盤2的 S 端口接到控制器的數字 I/O 口 3,+ 和-分別接到電源的 +5V 和 GND
- 示例程序
#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; //碼盤數 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); // 設定時間為 1s attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING); // 當檢測到上升沿時,計數 attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING); Timer1.attachInterrupt( ISR_timerone ); // 開啟Timer中斷 } void loop() { }
- 程序效果
通過串口打印出兩個電機的轉速
資料下載
- 產品資料
下載鏈接:https://pan.baidu.com/s/1BBy385RbyeitgAo0U6DXxA 提取碼:ym1r