14. Interface and Application Programming.

This week, we were asked to implement a user interface (UI) that can interact with hardware. For that, I will use QtDesigner to create the interface for my project, which needs to be capable of controlling the speed, direction, and start of two independent step motors, turning on and off a 12-volt fan and display the temperature of the extruder. In this instance even though there will be a section called extruder it will work to turn ON or OFF an LED. GROUP PAGE .

Qt Designer

Qt is an open-source framework for designing graphical user interfaces (GUIs) that can be easily implemented in cross-platform applications. While Qt is primarily based on C++, it can also be used with other programming languages, such as Python, through bindings like PySide and QtPy. Qt Designer is a GUI design tool that uses a drag-and-drop approach. It includes a wide variety of pre-designed widgets, allowing users to focus on the creative aspects of interface design rather than the underlying code.

Templates

When opening Qt Designer it will show the next window, where one can create a new form based on different Templates, open an specified one or open a recently worked form.

Main toolbar

Contains the most common actions in the program:

  • Creating, saving and opening forms.
  • Editing various factors including widgets.
  • Setting and breaking layouts.

Widget Box

Organizes available widgets by category. widgets like Frames, Push Buttons, Sliders, Group Boxes and LCD Numbers will be used on the interface.

Form

Serves as the canvas where you design your GUI by dragging and dropping widgets onto it.

Object inspector

Displays the hierarchical relationship of all widgets in the design. A right-click on a widget opens a menu where one can modify this hierarchy.

Property Editor

Shows the properties of a selected widget, allowing you to modify them as needed. This includes options such as size, position, text content, color, font, alignment, and more.

StyleSheet

Doing a right-click on a widget and selecting change styleSheet, will open a window. In this window you can modify the appearance and interactions of the widgets with a language similar to CSS. When a parent styleSheet is changed it reflects on it's children, unless their styleSheet specifies otherwise.


My design

For the interface I decided that there should be 5 buttons, 1 for the toggle of each device (2 motors, a fan and an LED) and one to update the speed of both motors. Two sliders with a minimum value of 600 and a maximum value of 8000 will be implemented to control the speed of the motors. The next video shows visually the interface and highlights the different components. their use and their stylesheet:

The Code

The interface will be saved as a .ui file, which can be converted to a .py file. To do this, either PyQt6 or PySide needs to be implemented as a Python package through pip. I will be using PyQt6, which can be installed with pip install PyQt6. Then, in the CMD, one can convert the file using the following command:
pyuic6 -x "name.ui" -o "name.py"

It is recommended not to modify the generated .py file because if changes are made to the interface and it needs to be converted again, either the .py file will be overwritten (if "name.py" is the same as the filename) or the changes made will need to be added manually to the new file. This can be easily solved by creating a different .py file and importing all the elements that compose the interface into it.

I decided to create a python code that could communicate the actions in the interface to an Arduino code though serial communication, the codes and a more detailed break down can be found below:

Prototype

Before creating the PCB, I decided to test the code by creating a simple circuit on a breadboard that can demonstrate that the different code coordinate to make the two motors work as instructed.

Here you can see a simple diagram of the connections and the pins that will be used to connect the microcontroller to the board with drivers.

Three PCBs were designed to communicate with each other and an external device (in this case, an Arduino). The main PCB has a driver for each motor. Due to time constraints, the LED will not be tested as the fan follows a similar logic of only changing states. PCB NEMA

Test

This video shows the operation of all the components in tandem:

PCB

designing

I designed a simple board with output for some pins. I used the RP2040 microcontroller from SID Studio. This board is basic, with output for the pins I use and some more if needed for future practices.PCB

manufacturing

For the manufacturing process, you can visit WEEK 4 to see more about the manufacturing.

FINAL

Here, I used the board I made with my board to place the motor drivers. By using a motor and the interface, I changed the direction of the motor.