Engineerish is back with another Raspberry Pi–based project that you didn’t know you needed until now.
Mattias Jahnke, better known as Engineerish to his online followers, was asked by his nephew to draw labyrinth mazes for the youngster to complete. While the task was fun to do by hand, Mattias soon found himself wondering what code and technology he could use to automate it. He soon hit upon the idea of using a Raspberry Pi, a thermal printer, and the recursive backtracking algorithm to produce mazes.
What is recursive backtracking?
The latter of these links provides the following summary of backtracking:
Backtracking problems are solved one step at a time. Literally! Here’s the general algorithm:
1) Is where I am a solution?
2) No. OK, where can I go from here? If I can go somewhere, choose a place to go.
3) Go there.
5) Was that a solution? If yes, return true!
5) If there are remaining places to go, choose one and go to #3.
6) Out of places to go. Return false.
Building an automated maze printer
To fit the Raspberry Pi and printer, as well as an arcade button and a power supply, Engineerish built a custom wooden box.
The arcade button is wired to GPIO pin 16, and pressing it starts a Python script that runs the recursive backtracking algorithm and lets the thermal printer produce the finished maze.
Engineerish has provided the complete code for the project on his GitHub account, allowing everyone to try their hand at printing (and completing) these awesome mazes.
And be sure to also check out his Raspberry Pi Binary Clock, which we covered here on the blog in January.