Skip to content

Commit e37632e

Browse files
Project/matei.lazarescu (#1285)
* Adaugare documentatie proiect Matei Lazarescu * Adaugare documentatie proiect Matei Lazarescu * Actualizare diagrama bloc si schema electrica + schimbare log + poze hardware * Redimensionare imagini --------- Co-authored-by: Irina Bradu <72762129+irina-b-dev@users.noreply.github.com>
1 parent bd6d1cc commit e37632e

4 files changed

Lines changed: 115 additions & 28 deletions

File tree

Lines changed: 82 additions & 0 deletions
Loading
48.3 KB
Loading
50.3 KB
Loading
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CNC Pen Plotter
22

3-
An autonomous 2D plotting machine that translates digital coordinates into physical drawings on paper using a synchronized dual-stepper Cartesian mechanism and a servo-actuated pen.
3+
An autonomous 2D plotting machine that translates digital coordinates into physical drawings on paper using a synchronized triple-stepper Cartesian mechanism for all axes (X, Y, and Z).
44

55
:::info
66

@@ -13,66 +13,70 @@ An autonomous 2D plotting machine that translates digital coordinates into physi
1313

1414
The CNC Pen Plotter is an embedded real-time device designed to physically draw graphics onto a sheet of paper. The system acts as a precise executor for coordinate data sent from a PC via USB (UART). Instead of relying on a high-level operating system, the STM32 Nucleo-U545RE-Q microcontroller uses DMA to receive a continuous stream of coordinates without blocking the CPU.
1515

16-
Once the data is parsed, the firmware utilizes Bresenham's line algorithm to calculate the exact interpolation needed to draw straight lines. The X and Y axes are driven by two NEMA 17 stepper motors controlled via A4988 motor drivers, ensuring millimeter precision. An SG90 micro servo is mounted on the toolhead acting as the Z-axis; it receives PWM signals to lower the pen when drawing or lift it when moving between shapes. The entire motion system is strictly synchronized using hardware timers to prevent step loss and maintain smooth kinematics.
16+
Once the data is parsed, the firmware utilizes Bresenham's line algorithm to calculate the exact interpolation needed to draw straight lines. All three axes (X, Y, and Z) are driven by **28BYJ-48 unipolar stepper motors**, controlled via **ULN2003 drivers**. The Z-axis motor rotates a mechanism to lower the pen when drawing or lift it when moving between shapes. The entire motion system is strictly synchronized using asynchronous Embassy tasks and hardware timers to generate specific step sequences, preventing step loss and maintaining smooth kinematics.
1717

1818
## Motivation
1919

20-
Translating digital graphics into physical reality requires a deep understanding of hardware-software synchronization. While commercial plotters or 3D printers handle this using advanced, pre-built frameworks, building one from scratch entirely in bare-metal Rust (`no_std`) represents a significant engineering challenge. This project was chosen to demonstrate the capability of handling asynchronous real-time communications, strict hardware timer management, and mathematical motion control (linear interpolation) on a highly resource-constrained embedded system.
20+
Translating digital graphics into physical reality requires a deep understanding of hardware-software synchronization. While commercial plotters or 3D printers handle this using advanced, pre-built frameworks, building one from scratch entirely in bare-metal Rust (`no_std`) represents a significant engineering challenge. This project was chosen to demonstrate the capability of handling asynchronous real-time communications, software-defined stepping sequences (Half-Step/Full-Step) for geared motors, and mathematical motion control (linear interpolation) on a highly resource-constrained embedded system.
2121

2222
## Architecture
2323

24-
![Architecture Diagram](images/architecture_diagram.svg)
24+
![Architecture Diagram](images/diagram.svg)
2525

2626
- **Communication Module** — Handles the asynchronous serial communication (UART over USB) between the PC and the STM32 microcontroller. It uses DMA and ring buffers (via `heapless`) to safely store incoming coordinate commands without risking memory overflow or dynamic allocation crashes.
27-
- **Motion Control Module** — The core logical component. It reads the target coordinates and applies Bresenham's line algorithm to determine the exact sequence of steps for the X and Y motors. It configures the MCU's hardware timers to generate precise microsecond pulses sent to the `STEP` and `DIR` pins of the A4988 drivers.
28-
- **Toolhead Module** — Controls the Z-axis actuation. It uses a hardware timer configured for PWM signal generation to rotate the SG90 micro servo, effectively lifting or dropping the pen onto the paper at the start or end of a drawing path.
29-
- **Power & Drive Module** — A 12V 2A power supply feeds the A4988 stepper drivers, providing the necessary current to the NEMA 17 motors. The logic side of the drivers and the MCU run safely isolated at 3.3V/5V.
27+
- **Motion Control Module** — The core logical component. It reads the target coordinates and applies Bresenham's line algorithm to determine the exact sequence of steps for the X and Y motors. Since 28BYJ-48 motors require sequential coil activation, this module cycles through a defined boolean matrix (step sequence) and sets the appropriate STM32 GPIO pins HIGH/LOW to drive the ULN2003 inputs.
28+
- **Toolhead Module** — Controls the Z-axis actuation. It reuses the stepper motor task logic to drive a third 28BYJ-48 motor, effectively turning a mechanical gear to lift or drop the pen onto the paper at the start or end of a drawing path.
29+
- **Power & Drive Module** — A 5V 2A power supply feeds the ULN2003 stepper drivers and motors directly, connected via a screw-terminal DC barrel jack adapter on a 400-point breadboard. The MCU logic runs safely isolated at 3.3V/5V via USB, sharing only the common ground (GND) with the power circuit.
3030

3131
## Log
3232

33-
### Week 14 - 20 April
33+
### April 14 - 20
3434
- Finalized project theme and received approval.
3535
- Researched kinematics and ordered the stepper motors, drivers, and mechanical components.
3636

37-
### Week 4 - 8 May
37+
### May 4 - 10
38+
- All the hardware components finally arrived.
39+
- Started researching datasheets and figuring out how to correctly wire the STM32, the ULN2003 drivers, and the power supply on the breadboard.
3840

41+
### May 11 - 17
42+
- Finished the physical hardware assembly and all the electronic wiring.
43+
- Wrote the initial testing code and successfully got all three stepper motors spinning.
3944

40-
### Week 12 - 18 May
45+
### May 18 - 24
4146

4247

43-
### Week 19 - 25 May
44-
4548

4649
## Hardware
4750

51+
![Electric Scheme](images/schema_electrica.webp)
52+
4853
The main controller is the **STM32 Nucleo-U545RE-Q**, chosen for its hardware FPU (useful for kinematic math), advanced hardware timers, and robust support within the Rust Embassy async ecosystem.
4954

50-
The physical movement is achieved using two **NEMA 17 Stepper Motors**, which provide excellent torque and step precision. These are driven by two **A4988 Stepper Motor Drivers**, which handle the high-current demands and translate simple digital HIGH/LOW signals from the STM32 into complex motor coil energizing phases.
55+
The physical movement is achieved using three **28BYJ-48 Stepper Motors**. These are 5V geared unipolar stepper motors known for their high precision (due to the internal 1:64 gear ratio). They are driven by three **ULN2003 Motor Drivers**, which act as high-current switches, translating the 3.3V logic signals from the STM32 into the 5V high-current pulses required by the motor coils.
5156

52-
The toolhead features an **SG90 Micro Servo**, connected directly to an STM32 PWM pin, providing a simple yet effective mechanism to raise and lower the drawing instrument.
57+
Power is managed separately to protect the microcontroller: the motors are powered by a dedicated **5V 2A Power Supply**, connected to the circuit using a **screw-terminal DC barrel jack adapter**. The power distribution and driver logic connections are routed on a **400-point breadboard** using standard **jumper wires**. The STM32 shares a common GND with the motor circuit but draws its own logic power via USB.
5358

54-
Power is managed separately to protect the microcontroller: the motors are powered by a dedicated **12V 2A Switched-Mode Power Supply**, while the STM32 logic operates on standard USB 5V/3.3V. The mechanical structure consists of GT2 timing belts, pulleys, and linear guide rods to ensure smooth and accurate translations.
59+
![Hardware_1](images/hardware_1.webp)
5560

5661
### Bill of Materials
5762

5863
| Device | Usage | Price |
5964
|--------|--------|-------|
60-
| [STM32 Nucleo-U545RE-Q](https://www.st.com/en/evaluation-tools/nucleo-u545re-q.html) | Main microcontroller | ~85 RON |
61-
| [NEMA 17 Stepper Motor x2](https://www.optimusdigital.ro/ro/motoare-pas-cu-pas/143-motor-pas-cu-pas-nema-17-42shd0001-24.html) | X and Y axis movement | ~100 RON |
62-
| [A4988 Stepper Motor Driver x2](https://www.optimusdigital.ro/ro/drivere-de-motoare-pas-cu-pas/123-driver-motor-pas-cu-pas-a4988.html) | Power switching for stepper motors | ~30 RON |
63-
| [SG90 Micro Servo](https://www.emag.ro/servomotor-sg90-180-de-grade-ai156-s297/pd/D33V1GMBM/) | Pen lifting mechanism (Z-axis) | ~15 RON |
64-
| 12V 2A Power Supply | Powering the A4988 drivers & motors | ~40 RON |
65-
| Mechanical Kit (GT2 Belts, Pulleys, Rods) | Cartesian frame assembly | ~100 RON |
66-
| Breadboard + Jumper Wires | Prototyping electronic connections | ~20 RON |
67-
| **Total** | | **~390 RON** |
65+
| STM32 Nucleo-U545RE-Q | Main microcontroller | From Faculty |
66+
| [3x 28BYJ-48 Stepper Motors + ULN2003 Drivers](https://www.emag.ro/search/motor+pas+cu+pas+28byj-48+uln2003) | X, Y, and Z axis movement & switching | ~60 RON |
67+
| [5V 2A Power Supply](https://www.emag.ro/search/alimentator+5v+2a) | Powering the ULN2003 drivers & motors | ~25 RON |
68+
| [DC Barrel Jack Adapter (Female)](https://www.emag.ro/search/mufa+alimentare+mama+surub) | Connecting the power supply to the breadboard | ~5 RON |
69+
| [Breadboard 400 points](https://www.emag.ro/search/breadboard+400) | Prototyping electronic connections | ~10 RON |
70+
| [Jumper Wires (M-M / M-F)](https://www.emag.ro/search/set+fire+jumper+arduino) | Routing signals between MCU, drivers, and power | ~15 RON |
71+
| **Total** | | **~120 RON** |
6872

6973
## Software
7074

7175
| Library | Description | Usage |
7276
|---------|-------------|-------|
73-
| [embassy-stm32](https://github.com/embassy-rs/embassy) | Async HAL for STM32 | Managing UART (DMA), Timers, GPIO pins, and PWM for the servo |
74-
| [embassy-executor](https://github.com/embassy-rs/embassy) | Async task executor | Running concurrent tasks (e.g., listening to UART while stepping motors) |
75-
| [embassy-time](https://github.com/embassy-rs/embassy) | Timekeeping | Managing microsecond delays between motor steps and system timeouts |
77+
| [embassy-stm32](https://github.com/embassy-rs/embassy) | Async HAL for STM32 | Managing UART (DMA), Timers, and Standard GPIO pins |
78+
| [embassy-executor](https://github.com/embassy-rs/embassy) | Async task executor | Running concurrent tasks (e.g., listening to UART while stepping all 3 motors) |
79+
| [embassy-time](https://github.com/embassy-rs/embassy) | Timekeeping | Managing microsecond delays between motor steps to control speed |
7680
| [heapless](https://github.com/japaric/heapless) | `no_std` data structures | Creating ring buffers for storing incoming coordinates without dynamic allocation |
7781
| [defmt](https://github.com/knurling-rs/defmt) | Lightweight logging framework | Structured debug output (e.g., coordinate parsing status) |
7882
| [defmt-rtt](https://github.com/knurling-rs/defmt) | RTT logging transport | Streaming logs to the PC via the debug probe |
@@ -83,5 +87,6 @@ Power is managed separately to protect the microcontroller: the motors are power
8387
1. [Embassy-rs documentation](https://embassy.dev)
8488
2. [STM32U5 Reference Manual](https://www.st.com/resource/en/reference_manual/rm0456-stm32u5-series-advanced-armbased-32-bit-mcus-stmicroelectronics.pdf)
8589
3. [Bresenham's Line Algorithm Explanation](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)
86-
4. [A4988 Stepper Motor Driver Datasheet](https://www.pololu.com/file/0J450/a4988_DMOS_microstepping_driver_with_translator.pdf)
87-
5. [defmt logging framework](https://defmt.ferrous-systems.com)
90+
4. [28BYJ-48 Stepper Motor Datasheet](https://components101.com/motors/28byj-48-stepper-motor)
91+
5. [ULN2003 Driver Datasheet](https://www.st.com/resource/en/datasheet/uln2001.pdf)
92+
6. [defmt logging framework](https://defmt.ferrous-systems.com)

0 commit comments

Comments
 (0)