This is the playground to start development of using UC2 modules using the HTTP REST API.
This folder contains all the code for handling actuators and sensors through HTTP requests. Please use the release versio of the Arduino code and flash it on your ESP32 wemos D1 R32. You can find the RELEASE here
We provide a simple ESP32Client.py that can be used to control the ESP32 microcontroler. We have a Jupyter-notebook based tutorial that can help you through the process.
In order to run it, clone this repository/download it and do:
conda activate $YOURENVIRONMENT$
cd PYTHON
jupyter notebook
pip install numpy requests python-opencv
pip install socket tempfile pyserial
The tutorial can be found here.
You can also install it using PIP
:
!pip install UC2-REST==0.1.0rc0
from ESP32Client import ESP32Client
ESP32 = ESP32Client(serialport="unknown")
# move and measure
print("Current position: "+ str(ESP32.get_position(axis=1)))
ESP32.move_x(steps=1000, speed=1000, is_blocking=True, is_absolute=True, is_enabled=True)
# set a funny pattern
import numpy as np
Nx=8
Ny=8
led_pattern = np.abs(np.int8(np.random.randn(3,Nx*Ny)*255))
ESP32.send_LEDMatrix_array(led_pattern, timeout=1)
It is the easiest to use the ESP32 WEMOS D1 R32 (Arduino compatible) board in combination with the CNC shield v3:
We provide two tutorials that help you installing the software:
as well as connecting the hardware:
IMPORTANT: USE THE ESP-IDF version 1.0.6 - >=2.0 has issues with the PS3 controller!
In case you use a chinese derivate Arduino or an ESP32 board, you most likely need to install the CH340 serial driver. Please have a look here
If you want an ESP32 board, please add the following sources to the preferences (Boards). More information can be found here
https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
BEST PRACTICE: Clone the following repository and copy the libraries inside the Arduino library folder: https://github.com/beniroquai/BenesArduinoLibraries
Alternatively:
Go to Tools -> Manage Libraries and add the following libraries (More information here:
ArduinoJson (Benoit Blanchon)
StepperDriver (by Laurentiu Badea)
Adafruit NeoMatrix (Adafruit) and its dependency
This code enables a rudimentary integration of the PS3/PS4 controller. For this you need to know/modify the controller's MAC address.
Add the corresponding libraries from here:
Please follow the tutorial here (similar for PS3)
The instructions on how to do this are base off what can be found here
File -> Preferences
Additional Boards Manager URLs
field:
https://dl.espressif.com/dl/package_esp32_index.json
Tools -> Board: "xxx" -> Boards Manager
esp32
(probably the last one in the list), and click install
Tools -> Board: "xxx"
under the section ESP32 Arduino
Sketch -> Include Library -> Add .ZIP Library
, then select the file you just downloadedWhen a PS4 controller is 'paired' to a PS4 console, it just means that it has stored the console's Bluetooth MAC address, which is the only device the controller will connect to. Usually, this pairing happens when you connect the controller to the PS4 console using a USB cable, and press the PS button. This initiates writing the console's MAC address to the controller.
Therefore, if you want to connect your PS4 controller to the ESP32, you either need to figure out what the Bluetooth MAC address of your PS4 console is and set the ESP32's address to it, or change the MAC address stored in the PS4 controller.
Whichever path you choose, you might want a tool to read and/or write the currently paired MAC address from the PS4 controller. You can try using sixaxispairer for this purpose.
If you opted to change the ESP32's MAC address, you'll need to include the ip address in the PS4.begin()
function during within the setup()
Arduino function like below where 1a:2b:3c:01:01:01
is the MAC address (note that MAC address must be unicast):
void setup()
{
PS4.begin("1a:2b:3c:01:01:01");
Serial.println("Ready.");
}
main.ino
in .ESP32/main // CASES:
// 1 Arduino -> Serial only
// 2 ESP32 -> Serial only
// 3 ESP32 -> Wifi only
// 4 ESP32 -> Wifi + Serial ?
// load configuration
#define ARDUINO_SERIAL
//#define ESP32_SERIAL
//#define ESP32_WIFI
//#define ESP32_SERIAL_WIFI
....
// load modules
# ifdef IS_ESP32
#define IS_DAC // ESP32-only
#define IS_PS3 // ESP32-only
#define IS_ANALOGOUT// ESP32-only
#endif
#define IS_LASER
#define IS_MOTOR
pindef.h
tools
-> Ports
and select the one that looks like your arduino/esp32115200
and enter some Json
commands to manipulate the actuators
{"task": "/state_get"}
{"task": "/laser_act", "LASERid":1, "LASERval":2}
{"task": "/motor_act", "axis":1, "speed":1000, "position":1000, "isabsolute":1, "isblocking":1}
{"task": "/analogout_act", "analogoutid": 1, "analogoutval":1000}
{"task": "/dac_act", "dac_channel": 19, "frequency":1, "offset":0, "amplitude":0, "clk_div": 10000}
pip
:
pip install requests python-opencv
serialport
:
serialport = "/dev/cu.SLAB_USBtoUART"
serialport = "/dev/cu.SLAB_USBtoUART"
serialport = "/dev/cu.wchusbserial1430"
serialport = "COM3"
The device adapter in PYTHON/ESP32RestSerialAPI.py is integrated into the open-source control and visualization software ImSwitch. A customized fork for UC2 can be found here.
In order to get it working, please follow the steps in the dedicated README
This will come soon. In principle, every actuator/sensor should have three comonents:
*_act
=> action -> do something*_set
=> set -> set parameters*_get
=> get -> get parametersThis is an experimental feature. You can access the REST API from the Swagger UI in your browser by opening the browser and connect to the ESP32 presumingly both are in the same network.