julianaklulo / mearm-mqtt

Control a MeArm robotic arm using 2 ESP32 via MQTT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MeArm MQTT

Control a MeArm robotic arm via MQTT using MicroPython.

Context

MeArm

MeArm is an open source and open hardware pocket sized robotic arm.

There are many versions available, the one used in this project is the MeArm V0.4.

Any other version can be used as well.

ESP32

ESP32 is a low-cost microcontroller with integrated WiFi and Bluetooth.

The version used in ths project is the ESP32-DEVKIT-V1 with 30 pins.

It can be replaced by any other microcontroller that supports MicroPython and MQTT.

MicroPython

MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.

Hardware

Using two ESP32 microcontrollers, it is possible to create a remote control for the MeArm via MQTT.

One ESP32 connected to 2 joysticks publishes the data to the MQTT broker, while the ESP32 connected to the MeArm receives the joystick values and controls the servo motors accordingly.

Components

  • 1x MeArm robotic arm
    • 4 Servo motors
    • Power supply for the servos
  • 2x ESP32-DEVKIT-V1 microcontroller
  • 2x Analog joysticks

Circuit Diagram

Publisher

Subscriber

Software

Flash the MicroPython firmware

Follow the instructions on the MicroPython ESP32 page to flash the firmware.

Setup a local MQTT broker

You can use a public MQTT broker, but it is recommended to use a local one for testing.

  1. Download the Mosquitto MQTT broker and install it on the machine you want to use
  2. Enable the service and start it
sudo systemctl enable mosquitto.service
sudo systemctl start mosquitto.service
  1. Check if the service is running correctly
sudo systemctl status mosquitto.service
  1. Edit the configuration file (/etc/mosquitto/mosquitto.conf) to allow anonymous connections
echo "allow_anonymous true" >> /etc/mosquitto/mosquitto.conf
echo "listener 1883" >> /etc/mosquitto/mosquitto.conf
  1. Restart the service
sudo systemctl restart mosquitto.service
  1. Get the IP address of the machine and note it down
  2. Test the connection to the broker by opening two terminals and running the following commands
mosquitto_sub -h <IP address> -t test
mosquitto_pub -h <IP address> -t test -m "Hello World"
  1. If the message is received correctly, the broker is working correctly

Configure the ESP32

  1. Modify the boot.py to connect to your WiFi network. Change the following lines
SSID = "your-wifi-ssid"
PASSWORD = "your-wifi-password"
  1. Modify the main.py to connect to your MQTT broker
SERVER = "your-mqtt-broker-ip"
PORT = 1883 # default MQTT port
  1. Install the ampy tool to manage the files on the ESP32
pip install adafruit-ampy
  1. Connect both ESP32 to your computer via USB
  2. Copy the files from the publisher folder to the ESP32 connected to the joysticks
ampy --port /dev/ttyUSB0 put publisher/boot.py
ampy --port /dev/ttyUSB0 put publisher/main.py
ampy --port /dev/ttyUSB0 put publisher/lib /lib
  1. Copy the files from the subscriber folder to the ESP32 connected to the MeArm
ampy --port /dev/ttyUSB1 put subscriber/boot.py
ampy --port /dev/ttyUSB1 put subscriber/main.py
ampy --port /dev/ttyUSB1 put subscriber/lib/ /lib
  1. Reboot both ESP32
ampy --port /dev/ttyUSB0 reset
ampy --port /dev/ttyUSB1 reset
  1. Check if the ESP32 connected to the joysticks is publishing the joystick values
sudo screen /dev/ttyUSB0 115200
  1. Check if the ESP32 connected to the MeArm is receiving the joystick values
sudo screen /dev/ttyUSB1 115200
  1. Move the joysticks and check if the values are changing
  2. If everything is working correctly, the MeArm should move accordingly

Demo

mearm-mqtt.mp4

About

Control a MeArm robotic arm using 2 ESP32 via MQTT


Languages

Language:Python 100.0%