Getting the firmware (code on the Pico) into shape was one of the more interesting parts of this project.
The code shared alongside the HackSpace magazine article is incomplete, forked and modified from a repo that is primarily in Chinese, and over a year old.
I've created my own fork of Ben's fork, and inside that right now there's a pico-w-build branch which is getting commits as I get to grips with the code.
Quick run-down of changes and approach:
- I primarily code for the Pico using MicroPython (and I may come back to this project with some MicroPython another day), this is based on Arduino, so to get started I needed to install the RP2040 / Pico W support for the Arduino IDE. The repo didn't contain specific instructions, but I've noted that I needed to install the board support by adding https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json to the Arduino Boards Manager preferences.
- The repo contains various libraries, I chose to install the TinyStepper driver "properly" via the Arduino IDE.
- I moved the .ino file containing a datestamped filename up out of the WallDrawGCODERP2040 sketch directory, to avoid compilation collisions.
- I chose to step through the whole of the source code and translated the Chinese versions of the comments using Google Translate, to help myself to understand the control flow.
- As noted in the previous log, I added the Fritzing schematic to the hardware folder.
- I added a small piece of code to switch the onboard LED on when the start button is pressed for long enough to move the Pico from "buttons control the pen and gears" mode (how it starts up), to "ready to receive gcode commands" mode.
- I made a couple of adjustments to hack in some additional "pretend" GRBL command parsing. As noted in the original article, the initial serial output from the Pico is supposed to trick the GCode sender software into thinking the plotter is running GRBL (a CNC firmware), I extended this very slightly in an effort to get things to work (see the log on Software support); in the end this has probably been a bit of a waste of time so far.
- This was all rebuilt with the latest Pico W SDK / Arduino board support, vs the ~May 2022 .uf2 file supplied with magazine article.
All of this took a fair bit of build/reset/upload work, with the motors and servo wired to the Pico, in order to confirm that the firmware is good. That's a large part of why I ended up adding the (white) reset button to the protoboard.
At this stage I'm able to compile and upload the sketch to the Pico W, and also, have the buttons trigger the expected actions (motor 1 & 2 up and down, pen up and down, and switching into GCode command receiver mode). I've been checking serial output using tio, Serial.app for macOS, and Arduino Serial Monitor. Assuming that the code supplied with the article will in fact plot from a GCode file as intended, this means that I'm most of the way there.
In theory, the final steps here are getting desktop software to talk to the plotter, and having the plotter do something useful.
I have some ideas for changes to the firmware if I stick with this minimal, sub-GRBL implementation:
- Ben's repo has notes on a potential use of an SD card, that could be useful
- Wifi upload of GCode (?? I now think that's a lot more effort than I initially thought, largely because I've now dug into GRBL and CNC software more than I expected to...)
- Improvements around homing and control
- (maybe??) MicroPython rewrite, but that will involve having to properly understand the GCode translation into stepper control logic, which I haven't gone anywhere near as yet.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.