Examples | Shop
 
DC Motors with OOPic-R
 
This example application demonstrates how DC motors can be controlled using an OOPic-R connected to the Dual Channel PWM DC Motor Driver Board.

In this example a 12V DC motor with sumo tyre and hub is connected to one of the driver ports on the Motor Driver Board. The OOPic then controls the motors direction, speed and brake status.

The OOPic-R and Driver Board are connected very simply using the Dual DC Motor IO pins that are set-aside on the board. They are connected as follows:
 
    OOPic-R   Driver Board Pin
Dir.Right Motor - 26 - 36
Brake Right Motor - 24 - 40
Speed Right Motor - 18 (PWM1) - 29
Dir.Left Motor - 27 - 34
Brake Left Motor - 25 - 38
Speed Left Motor - 17 (PWM2) - 27
+5 Volts - +5v - 21 or 22
Ground - GND - 23 or 24
         
In this example the right motor is used.

Connect 12-55v to the +12V and GND connections on the X3 header in the middle of the board. The right and left motors are isolated from each other but a single battery can be used to power both sides as long as it can take the voltage and current demands.

Do not take power from the OOPic to power the motors!

The 12v DC Motor should have a 0.1uf capacitor connected across its two legs to smooth the signal and reduce electrical noise. The two pins should then be connected to the Right motor connection (the outer connectors). The middle one is used if your motor has a ground wire connected to its casing.
When you are connected, power up the OOPic and download the program.

After a 2 second delay, the motors will move at full speed in one direction. 3 seconds later it brakes and goes full speed in the reverse direction again for 3 seconds. It brakes again then goes into a loop that accelerates and decelerates the motor.

Download the code here.

 

'**************************************************************************
'**************************************************************************
'Description: This example code shows simple routines to drive a 12V DC Motor connected to the Dual ‘Channel PWM DC Motor Driver Board (magnevation) and controlled by the OOPic-R.
'It demonstrates how ‘to set up the Driver Board and how to set the speed of the motor, the brake function and a speed step loop.
'
'Compiler Version: 5.0.1 (B2.2.x+) OOPic-R
'Created: 18/02/03 Revision: 1.0
'Written by: Total Robots
'TR-33
'
'**************************************************************************
'**************************************************************************
Dim RMotor as new oDCMotor 'DCMotor object used with the Dual PWM Board
Sub Main()
RMotor.IOLineP = 18 'Set up the PWM IOLine
RMotor.IOLineD = 26 'Set up the Direction IOLine
RMotor.IOLineB = 24 'Set up the Brake IOLine
RMotor.Unsigned = 0 'Set up values of -128 to 127
'To use 0-255 set to 1.
RMotor.Operate = 1 'Set operate value to on
RMotor.Brake = 0 'Brake is off
RMotor.Mode = 1 'PWM gets +5v when brake is 1.
‘To use a mechanical brake, set to
'0 so the PWM will get 0v.
oopic.delay = 200 ‘2 second delay
RMotor = 127 'Motor at full speed in one direction
oopic.delay = 300 '3 second delay
RMotor.Brake = 1 'Set the brake to on
oopic.delay = 100 '1 second delay
RMotor.Brake = 0 'Brake is off
RMotor = -128 'Motor at full in the oposite direction
oopic.delay = 300 '3 second delay
RMotor.Brake = 1 'Set the brake to on
oopic.delay = 100 '1 second delay
RMotor.Brake = 0 'Brake is off
Do
For RMotor = -127 to 126 'This loop steps the speed up and down
OOPic.Delay = 2 'forwards and backwards.
Next RMotor
For RMotor = 126 to -127 step -1
OOPic.Delay = 2
Next RMotor
Loop
End Sub
'**************************************************************************
'**************************************************************************


Examples | Shop