In this project, we will use a stepper motor control driver with which the 3 degrees of freedom plus the clamp will be controlled and through an Electronic Cats, the Bast BLE board we will be able to control the arm robot through an application created in app inventor.
**The board that was selected will be used because it has internal bluetooth on the board in addition to the board and its Bluetooth is Bluetooth energy efficient.
ARM RobotThis type of robotic arm has been selected for its simplicity and you can find it in some open publications. This type of robot has 3 degrees of freedom and 1 axis of action or work. Each of its joints works using a stepper motor, so it is a good practice to learn to control this type of motor using any of the commercial controllers, later on, I will tell you which one is used in this practice.
The Bast BLE is the new Feather family member with Bluetooth Low Energy in my projects because it is open-source, has native USB support featuring the nRF52840! It’s our take on an all-in-one Arduino-compatible + Bluetooth Low Energy with built-in USB plus battery charging. With native USB it’s even ready to join the CircuitPython party.
Bast BLE will accompany you in your most demanding projects. This board features a Nordic Semiconductors nRF52840 microcontroller, a 32-bit ARM® microcontroller that features low-power Bluetooth communication, NFC pairing, and powerful 1Mb FLASH memory internal + 1Mb Flash external and 256Kb of RAM for larger programs.
If you want to know more about this board add a link here
Stepper motor 28byj-48This small motor is very common in projects with small robots and simple homemade positioners, because although it is not too powerful or fast, it has several more than nice characteristics, as well as being very cheap.
It is a unipolar motor with the following characteristics:
- Nominal voltage between 5V and 12V.
- 4 Phases.
- Resistance 50 Ω.
- Motor torque of 34 Newton / meter plus or minus 0.34 Kg per cm.
- Consumption of about 55 mA.
- 8 steps per turn.
- Reduction of 1/64.
Translating it means that since it is 4 steps (Steps), or 8 half steps (O half Steps) per turn and uses a 1/64 reducer, so we need to give 8 * 64 = 512 impulses to complete a full turn in half steps.
I know it seems confusing.
There are 4 coils, if we excite them one by one we have 4 steps x 64 = 256 steps per turn. But we can also excite the coil through half steps, as we saw in the tables of the previous session (which is the example that we are going to do) and that is why at half steps one turn is 8 * 64 = 512 pulses.
ULN2003 driverThe internal diagram of the driver.
This driver is used to control a stepper motor through a lower voltage card or chip already amplifies the output by its internal construction
The driver can be controlled full-step or middle-step
For full pitch control 2 of the 4 coils are energized to travel a complete step and to travel the entire lap of the motor shaft we depend on the engine reduction factor to calculate the steps we require to move usually the motors is between 100 and 2000 steps take a complete turn
This full-pass configuration is used to get more torque in the engine.
How the coils are energized is illustrated in the table of image 4.
Half-step configuration is used when greater accuracy but less torque or torque is desired in the engine
How to activate the coils is shown in table 1.
Code to control the step of the motor by step in the Arduino interface using the serial monitorint x;
char dato;
//Gripper pins
#define IN1 15
#define IN2 16
#define IN3 17
#define IN4 18
//Arm pins
#define IN5 2
#define IN6 3
#define IN7 5
#define IN8 6
//Elbow pins
#define IN9 10
#define IN10 11
#define IN11 12
#define IN12 13
//Base pins
#define IN13 19
#define IN14 20
#define IN15 4
#define IN16 7
int paso [4][4] =
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 1},
{1, 0, 0, 1}
};
int paso2 [4][4] =
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 1},
{1, 0, 0, 1}
};
int paso3 [4][4] =
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 1},
{1, 0, 0, 1}
};
int paso4 [4][4] =
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 1},
{1, 0, 0, 1}
};
Variables used
int x;
variable x will allow us to move in the cycles faster and move to declare it individually in each cycle
char dato;
the variable "dato" will allow us to have the reading of the serial monitor
Statement of entries
#define IN1 15
#define IN2 16
#define IN3 17
#define IN4 18
For this apartment the command wild divide for the explanation
#define
This statement is used to define and leave constant a value for a variable in all code
IN4
This section gives the name by which we can call that pin defined within the code
18
That number is editable and you can take the values of the digital pins with which the board has except the number 0 and the number 1 as they will be used for communication through the serial monitor
Statement of steps using arrays
int paso [4][4] =
{
{1, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 1},
{1, 0, 0, 1}
};
In this part, we make use of matrices and arrays to indicate the activation sequence of the coils.
If you want to download the complete code you can find it in the download section.
Pin and card configurations
for (x = 2; x <= 13; x++) {
pinMode(x, OUTPUT);
}
for (x = 15; x <= 18; x++) {
pinMode(x, OUTPUT);
}
Serial.begin(115200);
while(!Serial);
For cycles allow us to quickly set the pins to output mode.
The serial.begin instruction allows us to initialize and configure the serial monitor at the speed of reading and tracking that we want within the parameters that Arduino gives us the instruction while(!Serial); wait for the serial monitor instructions.
Main code and key functions
if (Serial.available() > 0)
This instruction allows us to verify if the serial monitor is active and ready to detect the values
dato = Serial.read();
This instruction indicates that the data will be equivalent to reading the serial monitor
if (dato == 'O' )
This instruction allows us to compare the value obtained on the serial monitor with that of an action to be performed
for (x = 0; x < 15; x++)
With this cycle for we declare the number of steps you will take each time you receive the order by the serial
for (int i = 0; i < 4; i++)
In this cycle for we declare the position of the matrix and its path so that it is interpreted and can be given a step
digitalWrite(IN1, paso[i][0]);
digitalWrite(IN2, paso[i][1]);
digitalWrite(IN3, paso[i][2]);
digitalWrite(IN4, paso[i][3]);
delay(5);
with these instructions, we can tell you which pin is activated, and with that part of the matrix
Serial.println(" GRIPPER aumento");
With this, we project what action is done on the serial monitor.
Bluetooth LE implementation
BLEService greetingService("180C");
With this instruction, you configure you get the services.
BLEStringCharacteristic greetingCharacteristic("2A56", BLERead, 13);
With this instruction, you get the necessary features for the operation of Bluetooth Low Energy.
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214");
With this instruction, the services are configured for the communication of the instructions received by Bluetooth Low Energy.
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
This instruction configures the features for Bluetooth communication.
These instructions configure all the parameters necessary for the operation of Bluetooth Low Energy from name features and other parameters necessary for its proper functioning.
Void loop
BLEDevice central = BLE.central();
if (central) {
Serial.print("Connected to central MAC: ");
}
Serial.println(central.address());
digitalWrite(8, HIGH);
while (central.connected()){
With these instructions we define the Bluetooth device and verify that it is connected correctly otherwise it does not begin the main code.
Playback capture selector and manual control
if (y == 0)
With this instruction, we identify if the arm is in motion playback mode capture mode or in manual control since by default the variable becomes manual control
the values for this are
0 = control manual
1= capturing movements
2 = Reproducing movements
if (switchCharacteristic.written()) {
if (switchCharacteristic.value() == 'O' )
These instructions check the reception status and the value received by Bluetooth Low Energy.
The received variable manages to control a number of specific steps or actions to be performed with the arm.
else if (switchCharacteristic.value() == 'G' ) {
// a 0 value
y = 1;
b = 0;
Serial.println(F("RECORDING MOVIMENTS"));
}
With this function, we put the robot in moves listening mode to perform the saving of movements in a matrix by setting the auxiliary variable to 0 to move within the matrix.
Now that you understand the part of the main code, it is time to upload your program to the Bast BLE board and continue with the preparation of the Android application in APP Inventor.
APK in APP-InventorIn this part of the practice, it is necessary that you have knowledge in the creation of applications for android using the MIT App Inventor platform to understand how the application has been created, if you only want to replicate the practice you will be able to find the.apk file for you to install it and try.
Before starting to create the application it is important that you have the extension installed to be able to use the function blocks for BLE. Download the extension and read more information here.
In the previous image, a red box is shown where you must add the BLE extension.
The diagram to programming blocksIn this section, I will briefly explain how some blocks of the application should be built if you want to learn more I recommend you look for a tutorial for creating applications with this platform.
With this block, we configure a global variable called to service with which we will quickly configure in the other commands.
With this block, you configure a global variable called features with which you can configure it in the later blocks.
With these commands we configure the disconnection of the Bluetooth device.
With these commands, we configure the list selector based on the devices found to be able to establish a Bluetooth connection.
With these instructions, we set up the scan button as well as give the data to the list selector so that we can show the available devices.
With these commands, we select the Bluetooth device as well as establish communication with it.
With this script, we configure the buttons and the connection of the Bluetooth device.
With this command, we send for each button a statement or command through Bluetooth for every click on the button
With this command, we set the motion engraving status as well as send the same command.
With this script, we configure the stop button with which the recording status is configured and in turn, the stop command is sent.
This script sends the command required for the operation of the Arduino code as well as all instructions or actions to be performed.
In the following image, I show you how the application should look in its final form and which you can download in our Github repository or in the code section in this practice.
As you can see, this practice will help you learn about programming microcontrollers with Arduino, creating an application for android, and controlling a 3-axis robot arm with a stepper motor.
If you have any recommendations or comments about this practice, leave them in the comments. I hope you like it and that you have fun doing it.
Comments