Skip to content

Commit

Permalink
Merge pull request #14 from youseetoo/mergeBD
Browse files Browse the repository at this point in the history
Merge bd
  • Loading branch information
KillerInk authored Mar 4, 2023
2 parents 13026ef + c573a3d commit e9627cf
Show file tree
Hide file tree
Showing 67 changed files with 1,941 additions and 3,338 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
# UC2-ESP Firmware for the openUC2 UC2e electronics

This repository provides the latest (`V2`) firmware that controls external hardware like Motors, LEDs, Lasers and other customized elements using an ESP32 and an adapter board. It is inspired by the [UC2-REST](https://github.com/openUC2/UC2-REST/tree/master/ESP32) firmware, but features a much more structured way of the code by dividing modules into seperated classes. A `ModuleController` ensures a proper initializiation of individual modules at runtime, which makes the entire code very modular and follows the overall UC2 principle.
This repository provides the latest (`V2`) firmware that controls external hardware like Motors, LEDs, Lasers and other customized elements using an ESP32 and an adapter board. It is inspired by the [UC2-REST](https://github.com/openUC2/UC2-REST/tree/master/ESP32) firmware, but features a much more structured way of the code by dividing modules into seperated classes. A `ModuleController` ensures a proper initializiation of individual modules at runtime, which makes the entire code very modular and follows the overall UC2 principle.

Similar to the legacy UC2-REST Firmware, the microcontroller can communicate using the wired serial and the wireless WiFi protocol. Both rely on a more-less similar `REST API` that uses endpoints to address an `act, get, set` command. For example, the information about the state of the ESP can be retrieved by issuing the code:
Similar to the legacy UC2-REST Firmware, the microcontroller can communicate using the wired serial and the wireless WiFi protocol. Both rely on a more-less similar `REST API` that uses endpoints to address an `act, get, set` command. For example, the information about the state of the ESP can be retrieved by issuing the code:

```
{"task":"/state_get"}
```

A list of all commands that can be sent via HTTP requests and serial commands (e.g. by using the Arduino IDE-contained Serial monitor at 115200 BAUD) can be found in the [RestApi.md](./RestApi.md)-file.
A list of all commands that can be sent via HTTP requests and serial commands (e.g. by using the Arduino IDE-contained Serial monitor at 115200 BAUD) can be found in the [RestApi.md](./RestApi.md)-file.

# Setting up the build environment

In order to build the code, you have to follow the following steps:

1. Install Visual Studio Code + the Extension called "Platform.io" => Restart Visual studio code to load PIO
2. Clone this repository including all the submodules: `git clone --recurse-submodules https://github.com/youseetoo/uc2-esp32`
3. Open the main folder in the Visual Studio Code
3. Open the main folder in the Visual Studio Code
4. Adjust the settings in the file `platformio.ini`-file (mostly the port)
5. Hit the `PlatformIO upload` button
6. open the PlatformIO serial monitor and check the ESP32's output
7. In case you have any problems: File an issue :-)
4.1. Go to Platformio Home and navigate to Devices
4.2 Copy the Device port (if connected) and insert that into the `platformio.ini`, e.g. `upload_port = /dev/cu.SLAB_USBtoUART` or `COM3`for windoof
5. Hit the `PlatformIO upload` button; The following task will be run: `platformio run --target upload`; The code is getting compiled and saved into `./.pio/build/`
5.1 The code will be uploaded. If eerything goes right the terminal says: `Leaving... Hard resetting via RTS pin...``
6. open the PlatformIO serial monitor (remember to also change the port in the `platform.io` accordingly) and check the ESP32's output (eventually hit the reset button)
7. In case you have any problems: File an issue :-)


In order to test several commands, you can find a useful list of `json`files in this file: [main/json_api_BD.txt](main/json_api_BD.txt)
# Flash the firmware using the Web-Tool

A new way to flash the firmware to the ESP32 is to use the open-source ESPHome Webtool. We have modified it such that the software in thi repo is compiled and uploaded to the website:
A new way to flash the firmware to the ESP32 is to use the open-source ESPHome Webtool. We have modified it such that the software in thi repo is compiled and uploaded to the website:

**[www.youseetoo.github.io]**(youseetoo.github.io)

There you can select the board you have and flash the code. If the driver is properly installed, you simply select the port and hit `start`. The firmware will automatically be downloaded and flashed through the browser.
There you can select the board you have and flash the code. If the driver is properly installed, you simply select the port and hit `start`. The firmware will automatically be downloaded and flashed through the browser.

<p align="center">
<img src="./IMAGES/webtool.png" width="550">
Expand All @@ -40,11 +45,11 @@ There you can select the board you have and flash the code. If the driver is pro
This is a fastly moving repo and the information may get outdated quickly. Please also check the relevant information in our [documentation](https://openuc2.github.io/docs/Electronics/uc2e1)


# Information about the REST commands
# Information about the REST commands

Every component can be used by calling it in a REST-ful way. A not-complete document that describes the most important functions can be found [here](./RestApi.md)

The general structure for the serial would become:
The general structure for the serial would become:

````
{"task": "/state_get"}
Expand All @@ -56,7 +61,7 @@ to get the information about the MCU. A additional cheat-sheet can be found [her

The object oriented structure of the Firmware allows one to (more-less) easily implement additional components/modules. A rough structure where to add the different components like endpoints, REST-hooks, etc. is summarized [here](DOC_Firmware.md).

# Some Arduino-CLI/ESPTOOL/PlatformIO-related commands
# Some Arduino-CLI/ESPTOOL/PlatformIO-related commands

This is a random collection of tasks/commands that are useful to compile/upload the code by hand.

Expand All @@ -68,7 +73,7 @@ cd uc2-ESP/.pio/build/esp32dev
python -m esptool --chip esp32 merge_bin -o merged-firmware.bin --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 bootloader.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 firmware.bin
```

Install the ESP32 core
Install the ESP32 core

```
arduino-cli core update-index --config-file arduino-cli.yaml
Expand All @@ -83,10 +88,10 @@ mkdir build
arduino-cli compile --fqbn esp32:esp32:esp32:PSRAM=disabled,PartitionScheme=huge_app,CPUFreq=80 ESP32/main/main.ino --output-dir ./build/ --libraries ./libraries/
```

Flash the firmware to the ESP32 board
Flash the firmware to the ESP32 board

```
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 /build/main.ino.bootloader.bin 0x8000 /build/main.ino.partitions.bin 0xe000 /build/boot_app0.bin 0x10000 /build/main.ino.bin
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 /build/main.ino.bootloader.bin 0x8000 /build/main.ino.partitions.bin 0xe000 /build/boot_app0.bin 0x10000 /build/main.ino.bin
```

Upload the firmware using the Arduino-CLI
Expand Down
30 changes: 15 additions & 15 deletions RestApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ GET
"LEDArrMode": 0,
"led_array": [
{
"blue": 255,
"green": 255,
"b": 255,
"g": 255,
"id": 0,
"red": 255
"r": 255
},
{
"blue": 255,
"green": 255,
"b": 255,
"g": 255,
"id": 1,
"red": 255
"r": 255
}
]
}}
Expand All @@ -160,9 +160,9 @@ GET
"LEDArrMode": 1,
"led_array": [
{
"blue": 255,
"green": 255,
"red": 255
"b": 255,
"g": 255,
"r": 255
}
]
}}
Expand All @@ -173,9 +173,9 @@ GET
"LEDArrMode": 4,
"led_array": [
{
"blue": 255,
"green": 255,
"red": 255
"b": 255,
"g": 255,
"r": 255
}
]
}}
Expand All @@ -190,10 +190,10 @@ POST
"LEDArrMode": 1,
"led_array": [
{
"blue": 0,
"green": 0,
"b": 0,
"g": 0,
"id": 0,
"red": 0
"r": 0
}
]
}
Expand Down
143 changes: 0 additions & 143 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,102 +62,6 @@ <h3>BT</h3>

<div id="Motor" class="tabcontent">
<h3>Motor</h3>
<button onclick="hideOrShow('motorpins')">Pins</button>
<div class="container" id="motorpins">
<form class="pin">
<label>Stepper X</label><br>
<label for="steppinx">Step Pin</label><br>
<input type="text" id="steppinx" name="steppinx"><br>
<input type="checkbox" id="steppinxinvert">
<label for="steppinxinvert">Inverted</label><br>

<label for="dirpinx">Dir Pin:</label><br>
<input type="text" id="dirpinx" name="dirpinx"><br>
<input type="checkbox" id="dirpinxinvert">
<label for="dirpinxinvert">Inverted</label><br>

<label for="powerpinx">Power Pin:</label><br>
<input type="text" id="powerpinx" name="powerpinx"><br>
<input type="checkbox" id="powerpinxinvert">
<label for="powerpinxinvert">Inverted</label><br>
</form>
<form class="pin">
<label>Stepper Y</label><br>
<label for="steppiny">Step Pin</label><br>
<input type="text" id="steppiny" name="steppiny"><br>
<input type="checkbox" id="steppinyinvert">
<label for="steppinyinvert">Inverted</label><br>

<label for="dirpiny">Dir Pin:</label><br>
<input type="text" id="dirpiny"><br>
<input type="checkbox" id="dirpinyinvert">
<label for="dirpinyinvert">Inverted</label><br>

<label for="powerpiny">Power Pin:</label><br>
<input type="text" id="powerpiny"><br>
<input type="checkbox" id="powerpinyinvert">
<label for="powerpinyinvert">Inverted</label><br>
</form>

<form class="pin">
<label>Stepper Z</label><br>
<label for="steppinz">Step Pin</label><br>
<input type="text" id="steppinz"><br>
<input type="checkbox" id="steppinzinvert">
<label for="steppinzinvert">Inverted</label><br>

<label for="dirpinz">Dir Pin:</label><br>
<input type="text" id="dirpinz"><br>
<input type="checkbox" id="dirpinzinvert">
<label for="dirpinzinvert">Inverted</label><br>

<label for="powerpinz">Power Pin:</label><br>
<input type="text" id="powerpinz"><br>
<input type="checkbox" id="powerpinzinvert">
<label for="powerpinzinvert">Inverted</label><br>
</form>
<form class="pin">
<label>Stepper A</label><br>
<label for="steppina">Step Pin</label><br>
<input type="text" id="steppina"><br>
<input type="checkbox" id="steppinainvert">
<label for="steppinainvert">Inverted</label><br>

<label for="dirpina">Dir Pin:</label><br>
<input type="text" id="dirpina"><br>
<input type="checkbox" id="dirpinainvert">
<label for="dirpinainvert">Inverted</label><br>

<label for="powerpina">Power Pin:</label><br>
<input type="text" id="powerpina"><br>
<input type="checkbox" id="powerpinainvert">
<label for="powerpinainvert">Inverted</label><br>
</form>
<div>
<button id="setmotorsettings" onclick="setMotorSettings()">Set Motor Settings</button>
</div>
</div>

<h3>Motor Drive Range</h3>
<button onclick="hideOrShow('motorrange')">Drive Range</button>
<div class="container" id="motorrange">
<label>X</label><br>
<button onclick="setMotorRangeCalibration(0, 1)">Min Range</button><button
onclick="setMotorRangeCalibration(1, 1)">Max Range</button><label id="posx_max">0</label><button
onclick="setMotorRangeCalibration(2, 1)">Reset</button><br>
<label>Y</label><br>
<button onclick="setMotorRangeCalibration(0, 2)">Min Range</button><button
onclick="setMotorRangeCalibration(1, 2)">Max Range</button><label id="posy_max">0</label><button
onclick="setMotorRangeCalibration(2, 2)">Reset</button><br>
<label>Z</label><br>
<button onclick="setMotorRangeCalibration(0, 3)">Min Range</button><button
onclick="setMotorRangeCalibration(1, 3)">Max Range</button><label id="posz_max">0</label><button
onclick="setMotorRangeCalibration(2, 3)">Reset</button><br>
<label>A</label><br>
<button onclick="setMotorRangeCalibration(0, 0)">Min Range</button><button
onclick="setMotorRangeCalibration(1, 0)">Max Range</button><label id="posa_max">0</label><button
onclick="setMotorRangeCalibration(2, 0)">Reset</button><br>
</div>
<div>
<h3>Motor Control</h3>
<form>
Expand Down Expand Up @@ -185,16 +89,6 @@ <h3>Motor Control</h3>

<div id="LED" class="tabcontent">
<h3>LED</h3>
<button onclick="hideOrShow('ledpins')">Pins</button>
<div class="container" id="ledpins">
<form>
<label for="ledcount">LED Count:</label><br>
<input type="text" id="ledcount"><br>
<label for="ledpin">PIN:</label><br>
<input type="text" id="ledpin">
</form>
<button id="setledsettings" onclick="setLedSettings()">Set Led Settings</button>
</div>
<form>
<input type="checkbox" id="enableled" onclick='enableLeds(this)'>
<label for="enableled">Enable Leds</label><br>
Expand All @@ -215,16 +109,6 @@ <h3>LED</h3>
</div>

<div id="Laser" class="tabcontent">
<h3>Laser Setup</h3>
<label for="laser1pin">Laser1 Pin:</label>
<input type="text" id="laser1pin">
<button id="setlaser1pin" onclick="setLaserPin('1')">Set Laser1 Pin</button><br>
<label for="laser2pin">Laser2 Pin:</label>
<input type="text" id="laser2pin">
<button id="setlaser2pin" onclick="setLaserPin('2')">Set Laser2 Pin</button><br>
<label for="laser3pin">Laser3 Pin:</label>
<input type="text" id="laser3pin">
<button id="setlaser3pin" onclick="setLaserPin('3')">Set Laser3 Pin</button><br>

<h3>Laser Control</h3>
<label for="laser1value">Laser1:</label>
Expand Down Expand Up @@ -255,33 +139,6 @@ <h3>Laser Control</h3>
<button id="apply2" onclick="setLaserAct('3')">Apply</button><br>
</div>

<div id="Modules" class="tabcontent">
<h3>Modules</h3>
<input type="checkbox" id="m_enable_analog">
<label for="m_enable_analog">Enable AnalogIn</label><br>
<input type="checkbox" id="m_enable_dac">
<label for="m_enable_dac">Enable Dac</label><br>
<input type="checkbox" id="m_enable_digitalout">
<label for="m_enable_digitalout">Enable DigitalOut</label><br>
<input type="checkbox" id="m_enable_led">
<label for="m_enable_led">Enable Led</label><br>
<input type="checkbox" id="m_enable_motor">
<label for="m_enable_motor">Enable Motor</label><br>
<input type="checkbox" id="m_enable_laser">
<label for="m_enable_laser">Enable Laser</label><br>
<input type="checkbox" id="m_enable_pid">
<label for="m_enable_pid">Enable Pid</label><br>
<input type="checkbox" id="m_enable_scanner">
<label for="m_enable_scanner">Enable Scanner</label><br>
<input type="checkbox" id="m_enable_sensor">
<label for="m_enable_sensor">Enable Sensor</label><br>
<input type="checkbox" id="m_enable_slm">
<label for="m_enable_slm">Enable Slm</label><br>
<input type="checkbox" id="m_enable_analogjoystick">
<label for="m_enable_analogjoystick">Enable Analog Joystick</label><br>
<button id="setmodules" onclick="setModuleSettings()">Set Module Settings</button>
</div>

</body>

</html>
Loading

0 comments on commit e9627cf

Please sign in to comment.