G-code XY Pen Plotter with Raspberry Pi 5 (Proteus Simulation): the Raspberry Pi 5, two A4988 drivers, the 100 mm linear stage, the micro linear stepper, the L12 pen and the OLED paper

G-code XY Pen Plotter with Raspberry Pi 5 (Proteus Simulation)

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the G-code XY Pen Plotter with Raspberry Pi 5 in Proteus Simulation, the fifty-sixth project of our IoT Projects series. If you have searched for a Raspberry Pi pen plotter, a G-code interpreter in Python, or a Proteus simulation of two stepper axes drawing together, here is a complete one. A 100 mm linear stage moves the pen left and right, a small linear stepper riding on it moves the pen forward and back, and a linear servo lifts and lowers the pen. The Raspberry Pi 5 reads G-code, the language of CNC machines and 3D printers, homes both axes, and drives them so that every line comes out straight. An OLED screen is the paper: every line the pen draws appears on it, and a web dashboard on a laptop or a phone picks the drawing and shows the sheet as it grows.

Pen plotters were the first machines that drew computer graphics on paper, and the same idea, two axes and a tool, runs every CNC router, laser cutter and 3D printer today. In this tutorial, we will go through the circuit, work out how many steps a millimetre each axis needs from its lead screw and its driver, set the current of a TMC2209 and an A4988, home one axis with a limit switch and the other against its end stop, move both axes at once so that a slanted line stays straight, lift the pen with an RC servo pulse, read G-code line by line, walk through the Python program, and then run the simulation: homing, a square, a star and the letters TEP. At the end, you can download the project with the program and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the XY pen plotter on the Raspberry Pi 5 in Proteus simulation:

G-code XY Pen Plotter with Raspberry Pi 5 (Proteus Simulation): the Raspberry Pi 5, two A4988 drivers, the 100 mm linear stage, the micro linear stepper, the L12 pen and the OLED paper
Figure: The XY pen plotter in a Proteus simulation: the letters TEP drawn on the OLED paper.
Raspberry Pi 5 XY pen plotter Proteus simulation: homing, then a square, a star and TEP drawn on the OLED paper by the linear stage and the micro stepper
Figure: The XY pen plotter working in the Proteus simulation: homing, then the square, the star and the letters TEP appearing on the OLED paper.

What Does This Pen Plotter Do?

  • Two axes: X is a 100 mm linear stage, a NEMA 17 stepper on a T8 lead screw driven by a TMC2209; Y is a micro linear stepper, the kind that moves the laser in a DVD drive, riding on the X carriage and driven by an A4988.
  • A pen that goes up and down: an L12 linear servo pushes the pen onto the paper and lifts it 6 mm for every move between lines.
  • Homing: at power on, X runs to its MIN limit switch, Y runs into its end stop, and both back off 3 mm: that point is X0 Y0.
  • Straight lines: both axes start together, each at its own step rate, and arrive together, so a slanted line is straight.
  • G-code: G28 (home), G0 and G1 (move with the pen up or down, X and Y in millimetres, F in mm/min), M3 and M5 (pen down and up), G4 (wait).
  • Three drawings: a square, a five-pointed star and the letters TEP, each on a new sheet; the jobs queue up if you ask for more than one, and a drawing that follows another waits 5 s for the paper to be changed.
  • The paper: an SSD1306 128x64 OLED shows every line as it is drawn; the dashboard shows the sheet as a picture, with the pen's moves and where it is now.

It is a great project for learning stepper motors and their drivers, lead screws and steps per millimetre, homing, coordinated motion, RC servo pulses, I2C displays, G-code, threads and a small web server, all in Python on a Raspberry Pi. In the simulation, the stage's pop-up shows the carriage on its track with both switches and the coil currents; the micro stepper's pop-up shows its slider, its steps and the steps it lost at the end stop; the L12's pop-up shows the rod and the pulse it reads; the TMC2209's and the A4988's pop-ups show their current setting and the coil currents.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEPPi runtime that runs Python in Proteus.

The parts of the XY pen plotter and their library posts
PartProteus deviceLibrary postConnection
Raspberry Pi 5RASPBERRY PI 5Raspberry Pi 5 Library for ProteusPI1, plotter.py, Ethernet 192.168.1.51
TMC2209 stepper driverTMC2209TEPTMC2209 Stepper Driver LibraryU1, the X axis: 1/8 microsteps, 1.2 A peak
A4988 stepper driverA4988ADVTEPA4988 / DRV8825 Stepper Driver LibraryDRV1, the Y axis: full steps, 0.33 A
NEMA 17 100 mm linear stageSTAGE100TEPNEMA 17 Linear Stage LibraryM2, the X axis; MIN switch to GPIO17
Micro linear stepperMICROLINSTEPTEPMicro Linear Stepper Motor LibraryM1, the Y axis, 80 mm
L12 linear servoL12SERVOTEPL12 Linear Servo LibrarySERVO1, the pen, SIG to GPIO18
SSD1306 128x64 OLEDOLED12864WHITEADVTEPOLED SSD1306 LibraryOLED1, the paper, I2C1 at 0x3C
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the Pen Plotter: the Circuit

XY pen plotter Proteus simulation circuit: Raspberry Pi 5, a TMC2209 and an A4988, the NEMA 17 linear stage, the micro linear stepper, the L12 servo and the OLED
Figure: The complete circuit of the pen plotter on an A3 Proteus sheet.
The connections of the pen plotter
PartPinsRaspberry Pi 5 / supply
U1 TMC2209 (X)STEP / DIR / ENGPIO20 (pin 38) / GPIO21 (pin 40) / GPIO16 (pin 36)
U1MS1, MS2 / VDD / VMGND (1/8 microsteps) / 3.3 V / +12 V
DRV1 A4988 (Y)STEP / DIR / ENGPIO19 (pin 35) / GPIO26 (pin 37) / GPIO16 (pin 36)
DRV1MS1 - MS3 / RST, SLP, VDD / VMOTGND (full steps) / 3.3 V / +12 V
M2 stageA+ A- B+ B- ; MIN ; COMU1 A1 A2 B1 B2 ; GPIO17 (pin 11) ; GND
M1 micro stepperA+ A- B+ B-DRV1 1A 1B 2A 2B
SERVO1 L12SIG / V+ / GNDGPIO18 (pin 12) / 5 V / GND
OLED1SDA / SCL / VCCGPIO2 (pin 3) / GPIO3 (pin 5) / 3.3 V

Each axis has its own driver, and both share one enable line: EN is active low on both chips, so the Pi holds GPIO16 high to switch both drivers off between jobs, and low while it moves. The TMC2209's MS1 and MS2 are tied to ground, which selects 1/8 microsteps; the A4988's MS1 to MS3 are tied to ground, which selects full steps. The X stage's MIN switch closes to COM near the motor end; COM is grounded and the Pi reads MIN on GPIO17 with its internal pull-up, so the input reads LOW when the carriage reaches the switch. The micro stepper has no switch at all, and the pen servo needs only one pulse line.

How the Pen Plotter Works

Steps per Millimetre from the Lead Screw

A stepper turns a fixed angle for every pulse on STEP, and a lead screw turns that angle into a distance. The X stage's motor makes 200 full steps a turn (1.8 degrees a step) and drives a T8 screw with an 8 mm lead: one turn moves the carriage 8 mm. Its TMC2209 splits every full step into 8 microsteps, so one turn takes 200 x 8 = 1600 pulses and one millimetre 1600 / 8 = 200 pulses, 5 microns each. The Y axis is very different: a tiny can stepper of 18 degrees a step, 20 steps a turn, on an M3 screw that moves only 0.5 mm a turn; its A4988 makes full steps, so one step is 0.5 / 20 = 0.025 mm and one millimetre is 40 steps. The program keeps both numbers at the top, STEPS_X = 200 and STEPS_Y = 40, and turns every millimetre of a move into pulses with them.

Setting Each Driver's Current

Both drivers are current choppers: they switch the 12 V supply on and off fast to hold each coil's current at a limit set by the voltage on a VREF trimmer, so the motor gets the current it is rated for, not 12 V divided by its 1.5 ohm. On this TMC2209 module the peak current is simply VREF in volts (its 0.11 ohm sense resistors): VREF 1.2 V gives 1.2 A peak, 0.85 A RMS, well inside the stage motor's 1.7 A rating, and plenty for a light pen carriage. On the A4988 the limit is VREF / (8 x Rs), with Rs its 0.068 ohm sense resistor; the micro stepper's coils take 0.33 A, so DRV1's VREF is 0.18 V: 0.18 / (8 x 0.068) = 0.33 A. A driver set for the big motor would burn the small one, which is why the two axes have two drivers: a TMC2209 with smooth, quiet microsteps for the NEMA 17, and a simple A4988 for the little stepper.

Homing: a Switch on X, the End Stop on Y

A stepper does not know where it is; it only counts the steps it was given. So at power on the plotter finds a known point. X runs toward the motor end at 8 mm/s until its MIN switch closes, then moves 3 mm back. Y has no switch: the program drives it 82 mm toward its motor end, more than its 80 mm stroke, so the slider is sure to reach the end stop, and the steps that are left are simply lost against it, the grinding you hear when a cheap linear stepper homes. Then Y also moves 3 mm back. That point, 3 mm off the X switch and 3 mm off the Y end stop, is X0 Y0, and from there the program counts every step.

Moving Both Axes at Once: a Straight Line

If X and Y moved one after the other, a slanted line would come out as an L. To draw it straight, both axes must start together and finish together, so each gets its own step rate. The program works out the length of the line, the time it takes at the feed rate, and then each axis's rate: its steps divided by that time. Worked example, the star's first line, from X45 Y65 to X27.4 Y10.7 at 8 mm/s: X moves 17.6 mm = 3520 pulses and Y 54.3 mm = 2172 steps; the line is the square root of 17.6 squared plus 54.3 squared = 57.1 mm long, 7.14 s at 8 mm/s; so X pulses at 3520 / 7.14 = 493 Hz and Y at 2172 / 7.14 = 304 Hz. Both step trains come from the Pi's hardware PWM and start together. Each is stopped half a step after its last rising edge, in the middle of the gap before the next one, so a little timing jitter can neither add a step nor lose one: every axis gets exactly the steps it needs.

The Pen: an RC Servo Pulse

The L12 linear servo is a small DC motor, a gearbox and a lead screw with its own controller: it reads an RC servo pulse every 20 ms and puts its rod where the pulse says, 1000 us fully in (0 mm) and 2000 us fully out (30 mm). The program sends 1600 us for pen down, the rod at 18 mm, and 1400 us for pen up, 12 mm: a 6 mm lift. The rod moves about 19 mm/s at 5 V, so 6 mm takes about 0.32 s, and the program waits 0.4 s after each change before it moves the axes.

G-code, Line by Line

G-code is a list of short lines, each a letter and a number per word. "G1 X75 Y10 F480" means: move in a straight line to X 75 mm, Y 10 mm, at 480 mm a minute (8 mm/s). G0 is the same move at the travel speed. M3 lowers the pen and M5 lifts it; G28 homes; G4 P500 waits half a second. The program splits each line into its words, keeps the last feed rate for the next G1 that has none, and leaves out an axis that is not given (it stays where it is). A move outside the 90 x 70 mm area is refused with a message.

An OLED as the Paper

Instead of real paper, every pen-down line is drawn on an SSD1306 OLED, 128 x 64 pixels. The paper takes its left 64 x 64 pixels, the same scale on both axes: 90 mm across 61 pixels, so the 90 x 70 mm area fills 61 x 47 pixels inside a frame. The program keeps a copy of the screen in memory, a 1024-byte frame buffer of 8 rows of 128 bytes, sets the bits of each line in it, and sends the whole buffer over I2C. Every drawing starts by clearing it: a new sheet of paper.

The Python Code Explained

The program is plotter.py. It uses lgpio, the GPIO library of Raspberry Pi OS, for the pins, the step trains, the servo pulses and the I2C bus, and Python's own http.server for the dashboard. The machine's numbers are at the top:

STEPS_X, STEPS_Y = 200, 40                                       # pulses a millimetre: 200 x 8 / 8 mm (X), 20 / 0.5 mm (Y)
AREA_X, AREA_Y = 90.0, 70.0                                      # the drawing area after homing, mm

The drawings are plain G-code, the square in seven lines:

    'square': ['G0 X15 Y10', 'M3', 'G1 X75 Y10 F480', 'G1 X75 Y60', 'G1 X15 Y60', 'G1 X15 Y10', 'M5'],

A move turns millimetres into steps for each axis, then gives both axes the same time:

    nx, ny = round(abs(x - x0) * STEPS_X), round(abs(y - y0) * STEPS_Y)
    length = math.hypot(nx / STEPS_X, ny / STEPS_Y)
    t = length / speed                                           # the time for the whole line: both axes take exactly this long
    fx = max(1, round(nx / t)) if nx else 0
    fy = max(1, round(ny / t)) if ny else 0

Both step trains start together, and each gets its stop time: half a step after its last rising edge:

    if nx: lgpio.tx_pwm(chip, X_STEP, fx, 50); stops.append((time.monotonic() + (nx - 0.5) / fx, X_STEP))
    if ny: lgpio.tx_pwm(chip, Y_STEP, fy, 50); stops.append((time.monotonic() + (ny - 0.5) / fy, Y_STEP))
    for t, pin in sorted(stops):
        time.sleep(max(0.0, t - time.monotonic()))
        lgpio.tx_pwm(chip, pin, 0, 0)

Homing X waits for the switch; homing Y just drives past the end stop:

    while lgpio.gpio_read(chip, X_MIN) == 1 and time.monotonic() - t0 < 110 * STEPS_X / HOME_X:
    run(Y_STEP, Y_DIR, 0, Y_STALL_MM * STEPS_Y, HOME_Y)

The pen is one servo pulse:

    lgpio.tx_servo(chip, PEN, PEN_DOWN if down else PEN_UP, 50)

One G-code line becomes a dictionary of its words:

    words = {w[0]: w[1:] for w in line.upper().split() if w}

A drawn line goes onto the OLED paper, from millimetres to pixels:

        def px(x, y): return int(round(1 + x * 61 / AREA_X)), int(round(62 - y * 61 / AREA_X))

The jobs run one after another in their own thread, so the dashboard answers while the pen draws; a job asked for during a drawing waits in the queue. The pages are / (the dashboard), /draw?square, /draw?star and /draw?tep (a drawing), /home, /pen (up or down), /paper.bmp (the sheet as a picture) and /data (everything as JSON). Every step of the story is printed on the Pi's terminal.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
  2. Open Pi-5-XY-Plotter.pdsprj from the Proteus Simulation folder. Keep plotter.py and the DLL files next to it.
  3. Press Play. The Pi homes both axes: the stage's carriage runs to its MIN switch, the micro stepper's slider into its end stop.
  4. Open the Laptop or the Mobile WiFi Monitor and press Go for the dashboard.
  5. Tap SQUARE, STAR or TEP: watch the carriage, the slider and the pen on the sheet, and the drawing on the OLED.
  6. Tap Refresh to see the sheet on the dashboard.

Simulation Results: the Pen Plotter in Proteus

Here is the run that made the screenshots of this tutorial, 162 seconds of simulation: homing, then a square from the laptop, a star from the phone and the letters TEP asked for while the star was still being drawn. The times are the program's own clock, as it printed them on the Pi's terminal; the parts' numbers come from their pop-ups.

Homing at Power On

The program homes before anything else. X runs toward the motor end at 8 mm/s, 1600 pulses a second, from where the carriage stood, 40 mm. At 4.8 s: "homing X: the MIN switch closed after 4.8 s", and the carriage moves 3 mm back; the stage's pop-up catches it at 5.00 mm moving towards MAX, 1.20 A in the coils. Then Y runs 82 mm toward its end stop at 400 steps a second. The slider started at 30 mm, so after 30 mm it reached the stop and simply stayed there: the pop-up, caught during the grinding, says "AT THE INNER STOP". By the end of the run, 2080 steps were lost, 52 mm, exactly the 82 - 30 mm the slider could not go. The micro stepper's pop-up then shows a red LOSING STEPS banner; here that is the homing working, not a fault. Y moves 3 mm back, and at 14.1 s: "homed: X0 Y0, 3 mm off the X switch and the Y end stop".

The Raspberry Pi 5 XY pen plotter Proteus simulation homing: the stage at its MIN switch, the micro stepper running into its end stop
Figure: Homing: X has found its switch, Y is at its end stop.
NEMA 17 linear stage pop-up in the Proteus simulation: homed on the MIN switch near 2 mm, backing off to 5.00 mm at 1.20 A
Figure: The stage backing off its MIN switch.
Micro linear stepper pop-up in the Proteus simulation: the slider at its inner stop during homing, the extra steps lost
Figure: The Y axis homing against its end stop: the steps it cannot make are lost.
Laptop WiFi Monitor in the Proteus simulation: the XY plotter dashboard READY at X0 Y0, an empty sheet
Figure: The dashboard: ready, an empty sheet.

A Square from the Laptop

At 16.7 s SQUARE is tapped on the laptop: "a new sheet of paper", "job SQUARE: 7 lines of G-code". The pen travels up to the corner X15 Y10, goes down, and draws the four sides at F480, 8 mm/s. The L12's pop-up shows the pen down: 1600 us, the rod at 17.93 mm of its 18.00 mm target, 8 mA. On the right side only Y moves: the A4988 runs at 320 steps a second, 320 / 40 = 8 mm/s, at its 0.33 A limit, and the stage holds X75, 80.00 mm on its own scale, with 1.20 A. A line appears on the OLED paper when it is finished, so halfway up the right side the paper shows the bottom side.

The Raspberry Pi 5 XY pen plotter Proteus simulation drawing a square: the bottom side on the OLED, the pen on the right side
Figure: The square: the bottom side drawn, the right side under way.
SSD1306 OLED pop-up in the Proteus simulation: the square's first side on the paper, inside its frame
Figure: The OLED paper: the first side.
L12 linear servo pop-up in the Proteus simulation: the pen down, 1600 us, the rod at 17.93 mm
Figure: The pen down: 1600 us, 18 mm.
A4988 pop-up in the Proteus simulation: the Y axis at 320 full steps a second, 0.33 A per coil, VREF 0.18 V
Figure: The Y axis driver at 320 steps a second.
Micro linear stepper pop-up in the Proteus simulation: the Y slider moving out at 8 mm/s while the square is drawn
Figure: The Y axis moving out at 8 mm/s.

At 47.5 s: "SQUARE done: 220 mm drawn in 30.7 s". 220 mm at 8 mm/s is 27.5 s; the rest is the 18 mm move to the corner at 9 mm/s and the pen going down and up. The dashboard shows the sheet: the square in dark blue, the move from the origin dashed, the pen as a red cross at the corner.

The Raspberry Pi 5 XY pen plotter Proteus simulation: the square drawn on the OLED paper, the pen lifted
Figure: The finished square.
Laptop dashboard in the Proteus simulation: READY at X15 Y10, 1 drawing, 220 mm, the square on the sheet
Figure: The dashboard's sheet: the square.

A Star from the Phone, TEP in the Queue

At 50.3 s STAR is tapped on the phone. The square's sheet is used, so the program says "STAR next: 5 s to change the paper", and the phone shows the job waiting. Every line of a star is slanted, so here both axes work together. Take the second line, from X27.4 Y10.7 to X73.5 Y44.3: X moves 46.1 mm and Y 33.6 mm of a 57.1 mm line, so X runs at 46.1 / 57.1 x 8 = 6.46 mm/s, 1293 pulses a second, and Y at 4.71 mm/s, 188 steps a second. The TMC2209's pop-up shows exactly that: STEPPING 1.29 kHz at 1/8, 1.25 A in the coils, the current vector turning on its microstep circle; the stage moves towards MAX at 63.05 mm.

Mobile WiFi Monitor in the Proteus simulation: STAR asked from the phone, waiting in the queue
Figure: The phone: STAR in the queue.
The Raspberry Pi 5 XY pen plotter Proteus simulation drawing a star: X and Y moving together on a slanted line
Figure: The star: both axes together.
TMC2209 pop-up in the Proteus simulation: the X axis stepping at 1.29 kHz, 1/8 microsteps, 1.25 A in the coils
Figure: The X axis driver: 1.29 kHz at 1/8 microsteps.
NEMA 17 linear stage pop-up in the Proteus simulation: the carriage on the star's slanted line at 63.05 mm
Figure: The stage on a slanted line.

At 75.2 s, while the star is drawn, TEP is tapped on the laptop. One plotter draws one thing at a time, so it waits: the laptop shows "DRAWING STAR", "Queue: TEP", and the star's first line on the sheet. At 99.4 s: "STAR done: 285 mm drawn in 44.0 s", then "TEP next: 5 s to change the paper". The phone, refreshed in those 5 s, shows CHANGE THE PAPER, 2 drawings, 505 mm drawn, and the star on the sheet.

Laptop dashboard in the Proteus simulation: DRAWING STAR with TEP waiting in the queue
Figure: The laptop: the star under way, TEP in the queue.
The Raspberry Pi 5 XY pen plotter Proteus simulation: the five-pointed star drawn on the OLED paper
Figure: The finished star.
SSD1306 OLED pop-up in the Proteus simulation: the five-pointed star on the paper
Figure: The OLED paper: the star.
Phone dashboard in the Proteus simulation: CHANGE THE PAPER before TEP, the star on the sheet
Figure: The phone: time to change the paper.

The Letters TEP

At 104.5 s TEP starts on a new sheet: 26 lines of G-code, five pen strokes (two for the T, two for the E, one for the P), each with the pen lifted for the move to the next. Between strokes the L12's pop-up shows the pen up: 1400 us, the rod at 12.07 mm, 6 mm clear of the paper. At 158.7 s: "TEP done: 250 mm drawn in 54.2 s". The dashboard's sheet shows the letters and, dashed, every move made with the pen up.

The Raspberry Pi 5 XY pen plotter Proteus simulation writing TEP: the T drawn, the E under way
Figure: TEP: the T done, the E under way.
L12 linear servo pop-up in the Proteus simulation: the pen up between strokes, 1400 us, the rod at 12.07 mm
Figure: The pen up: 1400 us, 12 mm.
The Raspberry Pi 5 XY pen plotter Proteus simulation: the letters TEP drawn on the OLED paper
Figure: The letters TEP on the paper.
SSD1306 OLED pop-up in the Proteus simulation: the letters TEP on the paper
Figure: The OLED paper: TEP.
Laptop dashboard at the end of the XY pen plotter Proteus simulation: 3 drawings, 755 mm, 41 lines of G-code
Figure: The dashboard at the end.

Where did the axes end? The last point of TEP is X65 Y40. The stage's pop-up reads 70.000 mm, X65 plus the 5 mm of the origin, and the micro stepper's 43.000 mm, Y40 plus its 3 mm: after 755 mm of lines, neither axis has lost a single step, and the A4988 counted exactly the 1560 net steps the Pi sent.

Raspberry Pi 5 terminal in the Proteus simulation: homing, the square, the star, TEP and the paper changes
Figure: The terminal: the whole run.
The results of the XY pen plotter simulation
WhatResult
Homing Xthe MIN switch at 4.8 s (8 mm/s), 3 mm back
Homing Y82 mm toward the stop; 2080 steps lost = the 52 mm it could not go; homed at 14.1 s
Square (laptop)220 mm in 30.7 s; Y at 320 steps/s = 8 mm/s
Star (phone)285 mm in 44.0 s; a slanted line: X 1.29 kHz and Y 188 steps/s together
TEP (queued)waited for the star and a 5 s paper change; 250 mm in 54.2 s, 5 strokes
The pendown 17.93 mm at 1600 us, up 12.07 mm at 1400 us
The endX 70.000 mm, Y 43.000 mm = X65 Y40 exactly; no step lost
Simulation162 s; 3 drawings, 755 mm, 41 lines of G-code

Download the Project Files

Click the button below to download G-code-XY-Pen-Plotter-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 14.7 MB, without the source code of the models):

G-code XY Pen Plotter with Raspberry Pi 5 (Proteus Simulation) V1.0
  • Proteus Simulation: Pi-5-XY-Plotter.pdsprj, plotter.py and copies of the models.
  • Python Code: plotter.py, the program.
  • Proteus Library Files: the LIB files of the Raspberry Pi 5, the TMC2209, the A4988, the linear stage, the micro linear stepper, the L12 servo, the OLED and the two WiFi Monitors.
  • Proteus Model Files: the DLL models and the TEPPi folder (Python 3.11 and the runtime).
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy the files and the TEPPi folder from Proteus Model Files into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

plotter.py is plain Python: edit it next to the project and press Play again; PI1's PROGRAM property names the file it runs. Add your own drawing to PROGRAMS as a list of G-code lines and a link for it on the dashboard; the steps a millimetre, the area, the speeds and the pen's two pulses are at the top. The same program runs on a real Raspberry Pi 5 with Raspberry Pi OS, where lgpio is already installed.

Ideas to Extend the Project

  • Accept G-code over the network: a page that takes a whole file and draws it.
  • Draw arcs with G2 and G3, cut into short straight lines.
  • Add acceleration ramps, so the axes can run faster without losing steps.
  • Microstep the Y axis too (the A4988's MS1 - MS3) for smoother slanted lines.
  • Add a switch to the Y axis, so homing does not grind the end stop.
  • Turn text into G-code with a simple stroke font, and plot any word typed on the dashboard.

From Simulation to Real Hardware

  • Mount the Y axis on the carriage: the micro stepper rides on the stage's carriage, with its cable free to move 100 mm.
  • Set VREF first: measure each driver's VREF with a meter before connecting the motors: 1.2 V on the TMC2209 for the stage, 0.18 V on the A4988 for the micro stepper.
  • Power: both drivers' VMOT from a 12 V supply of at least 2 A with a 100 uF capacitor at each driver; the servo from 5 V; the Pi from its own supply; the grounds joined.
  • Pen holder: a light spring between the L12's rod and the pen keeps an even pressure on uneven paper.
  • Never connect or disconnect a motor while its driver is powered: the coil's energy can destroy an A4988.

Troubleshooting

  • NO SWITCH on homing X: MIN must reach GPIO17 and COM must be grounded.
  • An axis does not move: EN (GPIO16) must be low during moves, RST and SLP high, VMOT on +12 V.
  • A drawing is the wrong size: STEPS_X and STEPS_Y must match the screws and the microstep setting.
  • The Y axis loses steps: lower the speed; the micro stepper tops out near 10 mm/s.
  • The pen drags between lines: raise PEN_UP's lift or the wait after it.
  • A blank OLED: SDA and SCL on GPIO2 and GPIO3, the address 0x3C.

Limitations of the Simulation

  • The paper is the OLED: it shows the program's idea of the drawing, at 61 pixels for 90 mm; there is no real pen on real paper.
  • The axes start at their full speed without a ramp; the loads are light, so they keep their steps here, but a real plotter needs ramps for speed.
  • The step rates are whole hertz, so the two axes of a slanted line finish within a few milliseconds of each other, not at exactly the same moment.
  • The network to the laptop and the phone is simulated inside Proteus.
  • Raspberry Pi is a trademark of Raspberry Pi Ltd; the TMC2209 is a driver of Analog Devices (Trinamic), the A4988 a driver of Allegro MicroSystems and the SSD1306 a controller of Solomon Systech; this project is not made or endorsed by them or by Labcenter.

So, that was all about the G-code XY Pen Plotter with Raspberry Pi 5 in Proteus Simulation. I hope it helps you understand how a lead screw sets the steps a millimetre, how an A4988 limits a stepper's current, how a machine finds its home with and without a switch, how two axes share one straight line, and how G-code tells a machine what to draw, all tested in a simulation before you build a real plotter. More IoT projects with the Raspberry Pi 5 and the ESP32 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation