Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
This tutorial primarily focuses on configuring ESP-NOW for the robotic arm. After configuration, the robotic arm can achieve one-to-one and one-to-many ESP-NOW communication control using JSON commands.
ESP-NOW, originally used on Espressif WiFi chips such as ESP8266 and ESP32, is a high-speed, efficient wireless communication protocol developed by Espressif Systems, aiming to provide a low-power, high-performance LAN (Local Area Network) communication solution.
RoArm-M2-S comes with ESP-NOW functionality, and by default, is in Follower mode upon factory startup. In this mode, RoArm-M2-S can be controlled by other devices or can send ESP-NOW messages to other devices to control them.
Before explaining the meanings of various functional commands, let's first introduce the ESP-NOW communication data structure of RoArm-M2-S, as follows:
typedef struct struct_message {
byte devCode;
float base;
float shoulder;
float elbow;
float hand;
byte cmd;
char message[210];
} struct_message;
In this part, the specific value for variables will be set in the JSON commands. Here, we introduce the meaning of variables:
Next, let's explore the specific meaning of the related JSON command for ESP-NOW configuration.
{"T":300,"mode":1}
{"T":300,"mode":0,"mac":"00:00:00:00:00:00"}
{"T":301,"mode":3}
Note: Only in stream multicast, stream unicast/stream broadcast modes, the master control device continuously sends its joint position information to the controlled devices. The controlled devices will mimic the same movement when the master control device is manually rotated.
{"T":302}
After inputting this command, the return value is shown below:
44:17:93:EE:FD:70
Each device has a unique MAC address. When using ESP-NOW features, except for broadcast control, you need to obtain the MAC address of the controlled device. By default, the OLED screen of each robotic arm displays its own MAC address.
{"T":303,"mac":"44:17:93:EE:FD:70"}
{"T":304,"mac":"44:17:93:EE:FD:70"}
# Control the device of peerList to rotate the joints to the specified angle in the multi-cast device.
{"T":305,"dev":0,"b":0,"s":0,"e":1.57,"h":1.57,"cmd":0,"megs":"hello!"}
# Multi-cast control, send the JSON command to turn on the LED to the devices in peerlist.
{"T":305,"dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":255}"}
Please refer to the content of #ESP-NOW Communication Data Structure. The various keys in this JSON command correspond to the structure variables as follows, with additional supplementary parts:
# Unicast control, sends the command of controlling the joint angle to the specific device.
{"T":306,"mac":"44:17:93:EE:FD:70","dev":0,"b":0,"s":0,"e":1.57,"h":1.57,"cmd":0,"megs":"hello!"}
# Broadcast control, sends the command of controlling the joint angle to all devices
{"T":306,"mac":"FF:FF:FF:FF:FF:FF","dev":0,"b":0,"s":0,"e":1.57,"h":1.57,"cmd":0,"megs":"hello!"}
Referring to #ESP-NOW Communication Data Structure, each key in this JSOB command is referenced to the following structural variables with supplements:
Note: Whether it is multicast, or unicast/broadcast, the MAC address of the controlled device should be added to peerList first.
After learning the specific meaning and usage of JSON commands, you can learn the following introduces the usage of broadcast control, unicast control, and multicast control. Here we take four robotic arms as an example, and these four robotic arms are respectively labeled as A, B, C, and D.
In this part, we use the robotic arm A to control B, C, and D to swing. It is not necessary to obtain the MAC address of robotic arms B, C, and D for broadcast control, and it is sufficient to use the broadcast MAC address, and the example is as follows: Connect the robotic arm A to the PC with a USB cable through the Type-C connector, and communicate with the robotic arm A on the computer through the serial port. We can use the serial port debugging assistant or the UART monitoring of the Arduino IDE to communicate with the robotic arm A or use the Python serial communication tutorial to communicate with the robotic arm A.
First, add the broadcast MAC address first. Use the following command to add the broadcast MAC address to the peerList of robot arm A:
{"T":303,"mac":"FF:FF:FF:FF:FF:FF"}
Once added, you can send JSON command messages to robotic arms B, C, and D using the commands for broadcast control.
For example, use the following command to send the command to turn on the LED to robotic arms B, C, and D via robotic arm A.
{"T":306,"mac":"FF:FF:FF:FF:FF:FF","dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":255}"}
After the command is successfully sent, the LEDs of robotic arms B, C, and D will be on.
The above is just an example of sending the signal for broadcasting control, you can also send other JSON commands to robotic arms B, C, and D. Please refer to the meaning of broadcasting control commands of ESP-NOW function for specific modification.
Next, use the following command to turn off the torque lock on the robotic arm A, then you can manually swing it.
{"T":210,"cmd":0}
You can turn on [stream broadcast Leader] mode by setting the "ESP-NOW working method" of the robotic arm A. (When there is only the broadcast MAC address on the peerlist, the original peerlist mode is the broadcast mode.)
{"T":301,"mode":3}
Note: All of the above JSON commands are communicating with Robot Arm A.
In this part, we introduce how the robotic arm A controls the robotic arm B only. In the unicast control mode, it requires the MAC address of the controlled device, that is, the MAC address of the robotic arm B. The MAC address can be obtained from the OLED screen of the robotic arm B, such as BB:BB:BB:BB:BB:BB.
Connect the robotic arm A to the PC with a USB cable through the Type-C connector, and communicate with the robotic arm A on the computer through the serial port. We can use the serial port debugging assistant or the Arduino IDE's serial port monitor to communicate with robotic arm A. We can also use the Python serial communication tutorial to communicate with robotic arm A.
First, add the MAC address of robotic arm B. Use the following command to add the MAC address of B to the robotic arm A's peerList:
{"T":303,"mac":"BB:BB:BB:BB:BB:BB"}
#The Mac address is specifically changed to the MAC address of the device you want to control.
After adding successfully, use the command of unicast control to send a JSON command message to the robotic arm. Note: If the MAC address of robotic arm B has been added before, adding it again will show Add Failure due to a duplicate MAC address, but as long as the MAC address of robotic arm B is correct, it will still be determined as the designated controlled device for unicast control. When the [Stream Unicast Leader] mode is turned on, only the robotic arm B will follow the joint position information from robotic arm A.
For example, using the following command of turning on the LED to the robotic arm B.
{"T":306,"mac":"BB:BB:BB:BB:BB:BB","dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":255}"}
If you have operated the broadcast control, the LED of the robotic arm B is on, and you can use the following command to turn off the LED of the robotic arm B.
{"T":306,"mac":"BB:BB:BB:BB:BB:BB","dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":0}"}
Next, you can use the following command to turn off the torque lock of the robotic am A, then you can manually swing the robotic arm A.
{"T":210,"cmd":0}
After setting the "ESP-NOW working method" of the robotic arm A to enable [stream unicast Leader] mode. If you operate the broadcast control, the new MAC address added is the robotic arm B's. Hence, the [stream unicast Leader] mode only sends the joint angle information to the robotic arm B.
{"T":301,"mode":2}
Now, the robotic arm B will swing to the same position as the robotic arm A. When rotating the robotic arm A, the robotic arm B will follow while the robotic arm C and D will not move.
NoteL the above JSON commands all are the communication with the robotic arm A.
In this part, we introduce how the robotic arm A controls the robotic arm B and C to swing. In the multicast control, it requires the MAC address of the controlled device, that is, the MAC address of the robotic arms B and C. The MAC address can be obtained from the OLED screen of the robotic arm B and robotic arm C, such as BB:BB:BB:BB:BB:BB and CC:CC:CC:CC:CC:CC.
Connect the robotic arm A to the PC with a USB cable through the Type-C connector, and communicate with the robotic arm A on the computer through the serial port. We can use the serial port debugging assistant or the Arduino IDE's serial port monitor to communicate with robotic arm A. We can also use the Python serial communication tutorial to communicate with robotic arm A.
First, add the MAC addresses of the robotic arm B and C. Use the following commands to add the MAC addresses of the robotic arm B and C to the peerList of the robotic arm A:
{"T":303,"mac":"BB:BB:BB:BB:BB:BB"}
{"T":303,"mac":"CC:CC:CC:CC:CC:CC"}
#Modify the mac to the MAC addresses of the two devices to be controlled
If you have operated the unicast control, you have added the MAC address of B to the peerList, then executing the JSON command to add the MAC address of robotic arm B may report an error, so just ignore it.
If you have added a broadcast address, you need to remove the broadcast address. Use the following command to remove the broadcast address from the peerList of robotic arm A:
{"T":304,"mac":"FF:FF:FF:FF:FF:FF"}
You can send the following commands of turn on the LED to the robotic arms B and C.
{"T":305,"dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":255}"}
If the LED is on, you can use the following commands to turn off the LED of the robotics B and C.
{"T":305,"dev":0,"b":0,"s":0,"e":0,"h":0,"cmd":1,"megs":"{\"T\":114,\"led\":0}"}
Next, you can use the following command to turn off the torque lock of the robotic arm A, and then you can manually swing the robotic arm A.
{"T":210,"cmd":0}
Turn on [stream multicast Leader] mode through setting the ESPP-NOW operation mode of the robotic arm A, and then the angle information fo the robotic arm A will be sent to the robotic arms B and C.
{"T":301,"mode":1}
Now, the robotic arms B and C will be in the same position as the robotic arm A's. If you rotate the joint of the robotic arm A, the robotic arms B and C will follow.
Note: the above JSON commands all communicate with the robotic arm A.