Overview
Specifications
-
Reduction gear ratio: 39.6
-
Rated voltage: 7.4 V
-
No-load current: 240 mA
-
Load current: ≤ 750 mA
-
No-load speed: 350 ± 5% (RPM)
-
Original speed: 14,000 ± 5% (RPM)
-
Start torque: 5 kg·cm
-
Rated torque: 800 g·cm
-
Length of the output shaft: 9 mm
-
Power: 3.7 W
-
Encoder rotation angle: 360°
Programming Guide
Block | Features |
Select a port Set the power to -100–100 |
|
Select a port Set the speed (the maximum speed depends on the motor model) |
|
Select a port Set the rotation angle (a natural number) Set the speed (the maximum speed depends on the motor model) |
|
Obtain the speed of the motor | |
Obtain the angle of the motor from the origin |
Block | Features |
Select a slot Set the power to -255–255 |
|
Select a slot Set the speed (the maximum speed depends on the motor model) |
|
Select a slot Set the rotation angle (a natural number) Set the speed (the maximum speed depends on the motor model) |
|
Obtain the speed of the motor | |
Obtain the position or degree of the motor from the origin |
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <MeMegaPiPro.h>
double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
MeEncoderOnBoard Encoder_1(SLOT1);
MeEncoderOnBoard Encoder_2(SLOT2);
void isr_process_encoder1(void)
{
if(digitalRead(Encoder_1.getPortB()) == 0){
Encoder_1.pulsePosMinus();
}else{
Encoder_1.pulsePosPlus();
}
}
void isr_process_encoder2(void)
{
if(digitalRead(Encoder_2.getPortB()) == 0){
Encoder_2.pulsePosMinus();
}else{
Encoder_2.pulsePosPlus();
}
}
void setup(){
TCCR1A = _BV(WGM10);//PIN12
TCCR1B = _BV(CS11) | _BV(CS10) | _BV(WGM12);
TCCR2A = _BV(WGM21) | _BV(WGM20);//PIN8
TCCR2B = _BV(CS22);
attachInterrupt(Encoder_1.getIntNum(), isr_process_encoder1, RISING);
attachInterrupt(Encoder_2.getIntNum(), isr_process_encoder2, RISING);
}
void loop(){
Encoder_1.setTarPWM(100);
Encoder_2.setTarPWM(100);
delay(1);
Encoder_1.setTarPWM(0);
Encoder_2.setTarPWM(0);
delay(1);
loop();
}
-
Install MegaPi Pro on Raspberry Pi, and connect the photoelectric encoder motor 180 RPM to the DC/encoder driver.
-
Install the latest Makeblock library for Raspberry Pi, do a “pip3 install makeblock” in the command line, and then do an “upgrade” in the command line.
-
Create a Python file suffixed with .py.
-
Write a program in the Python file.
-
Run the Python file, for example, “python123.py”.
Function | Feature |
EncoderMotor(port) | Set a port to connect the DC/encoder motor. port: MegaPiPro.PORT1~MegaPiPro.PORT4 |
run(speed) | Rotate at the specified speed. speed: rotation speed range: -180–180 |
move_to(position,speed,callback) | Rotate to the specified position at the specified speed. position: target position speed: rotation speed (range: -180–180) callback: callback is triggered when the target position is reached |
set_home() | Set the current position as the origin. |
from time import sleep
from makeblock import MegaPiPro
board = MegaPiPro.create()
encoder = board.EncoderMotor(MegaPiPro.PORT1)
while True:
encoder.run(50)
sleep(2)
encoder.run(0)
sleep(1)
encoder.run(-50)
sleep(2)
encoder.run(0)
sleep(1)
10 lines (9 sloc) 274 Bytes
RawBlameHistory
from time import sleep
from makeblock import MegaPiPro
board = MegaPiPro.create()
encoder = board.EncoderMotor(MegaPiPro.PORT1)
position = 0
def on_finished(value):
position = 5000 - position
encoder.move_to(position,100,on_finished)
on_finished(position)
Wiring Mode
Comments
Please sign in to leave a comment.