How To Add This Control To Your Project
Step #1) Load the most recent release of EZ-Builder
Step #2) Press the Project tab from the top menu bar of EZ-Builder
Step #3) Press Add Control from the button ribbon bar of EZ-Builder
Step #4) Choose the
Step #5) Press the
4 Wire HBridge PWM
icon to add the control to your project
An H-Bridge is an electronic circuit that enables a voltage to be applied across a load in either direction and is triggered by a much lower voltage from a micro controller, such as the EZ-B v4 or IoTiny. These circuits are often used in robotics and other applications to allow DC motors to run forwards and backwards from a micro controller. H bridges are available as integrated circuits, or can be built from discrete components.
Because a micro controller (EZ-B v4 or IoTiny) is a small electronic computer, the I/O ports do not provide enough current to directly power a motor. Instead, the micro controller will send signals to the H-Bridge and the H-Bridge will power the motor. Think of the H-Bridge as a worker and the micro controller is the boss.
An HBridge (such as the EZ-Robot 2.5 Amp HBRidge) can be connected to the EZ-B Robot Controller by 4 digital signal wires. 2 wires per motor are used. This Movement Panel operates like the other Movement Panels and can be controlled by scripting or other controls that interact with it. Movement Panels are controls which move your robot. The Movement Panel directions can be modified by other controls, such as camera, voice, script, joystick and radar controls
1) Connect L298 VCC to either your battery supply positive or EZ-B power (red) on pin D0
2) Connect L298 GND to either your battery supply positive or EZ-B power (gnd) on pin D0
3) Connect L298 IN1 to EZ-B Signal Pin D0 (white)
4) Connect L298 IN2 to EZ-B Signal Pin D1 (white)
5) Connect L298 IN3 to EZ-B Signal Pin D2 (white)
6) Connect L298 IN4 to EZ-B Signal Pin D3 (white)
7) Connect L298 ENA to EZ-B Signal Pin D4 (white)
7) Connect L298 ENB to EZ-B Signal Pin D5 (white)
9) Connect L298 OUT1 to Motor 1
10) Connect L298 OUT2 to Motor 2
*Note: Because the above diagram is powering the HBridge off VCC (direct from battery), the switch will need to be Pressed Down. Although, please note that some HBridge versions reverse the direction of the switch and it will operate better UP. You will know which way the switch needs to be because the motors will not turn if the switch is incorrect position.
In EZ-Builder, use the HBridge Motor Control. Press the Config button and select the pins that you connected the L298's INPUT Pins too (example D0, D1, D2, D3, etc).
If the robot moves in reverse directions, simply go back into the CONFIG menu of the HBridge Control and swap the configuration around to [D3, D2, D1, D0] or [D1, D0, D3, D2] or [D2, D3, D0, D1]. You may need to try a few combinations to get it right. Sometimes it confuses us too!
There is a great tutorial from Rich that you can find here.
The PWM in the title of this control means the HBridge will accept a PWM (pulse width modulation) signal from the EZ-B. That is how the EZ-B will control speed of the HBridge. As you recall from the How Servo Works tutorial, you know what PWM is, right? Because this control will allow speed adjustments, this gives your project the ability to use joysticks and other controls that manage speed. Read more about how Movement Panels work in the Activities Guide.
When the EZ-B connection is made, there will be no PWM signal. The PWM signal for this control is specified by the SetSpeed() command. This is usually initialized in your Init script, or in the Connection Control's Connection Established Command.
- Locate the Connection Control and press the Gear Configuration button.
- In the connection control's dialog settings window, locate the 0 - Connection Established Command. This is the script which will execute when the EZ-B Board #0 is connected to an EZ-B. Press the Script Edit button for the Board #0 Established Command.
- Insert or append the following code and press SAVE to close all dialog windows.
# This sets the speed for the HBridge Motor Controller
# The speed is a number between 0 and 255
# Setting this speed will initialize the PWM on the motor controller