# ePaper Maze Maker

## Overview

This project generates random mazes and their solution using an Adafruit Metro M4 Express and an Adafruit ePaper shield. This is a fun, no-solder project suitable for all ages with three difficulty levels to choose from. You will have some a- **maze** -ing fun with it!

This project does not use WiFi, so it will work with either the Metro M4 Express or the Metro M4 Express Airlift. This project can be made portable by adding a battery, making it a great activity to take on a long car ride to minimize hearing "Are we there yet?" from the back of the car.

The original maze generator code this project is based on was written over 20 years ago in C for printing random mazes on paper. The use of the ePaper shield in this project brings a modern touch to this classic code.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/322/medium800/eink___epaper_3mazes.jpg?1563419790 There are 3 levels of maze difficulty to choose from)

## Parts

Building this project requires no soldering and uses just two parts: the Adafruit Metro M4 Express and the Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM.&nbsp; Either the Metro M4 or Metro M4 Airlift Express can be used. To make this project portable, you could use a [9V battery](https://www.adafruit.com/product/1321) and [adapter](https://www.adafruit.com/product/67) (shortest battery life) or add&nbsp;[a USB battery pack](https://www.adafruit.com/product/1959)&nbsp;and [adapter cable](https://www.adafruit.com/product/2697)&nbsp;(longer life and rechargeable).

If you are interested in ePaper displays for other projects, check out the entire line of&nbsp;[Adafruit's ePaper displays](https://www.adafruit.com/category/150).

### Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM

[Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM](https://www.adafruit.com/product/4229)
Easy e-paper finally comes to microcontrollers, with this breakout that's designed to make it a breeze to add a tri-color eInk display. Chances are you've seen one of those new-fangled 'e-readers' like the Kindle or Nook. They have gigantic electronic paper 'static'...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4229)
[Related Guides to the Product](https://learn.adafruit.com/products/4229/guides)
![Top down view of a Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM - Red Black White. ](https://cdn-shop.adafruit.com/640x480/4229-05.jpg)

### Adafruit Metro M4 feat. Microchip ATSAMD51

[Adafruit Metro M4 feat. Microchip ATSAMD51](https://www.adafruit.com/product/3382)
Are you ready? Really ready? Cause here comes the fastest, most powerful Metro ever. The **Adafruit Metro M4** featuring the **Microchip ATSAMD51**. This Metro is like a bullet train, with its 120MHz Cortex M4 with floating point support. Your code will zig and zag...

In Stock
[Buy Now](https://www.adafruit.com/product/3382)
[Related Guides to the Product](https://learn.adafruit.com/products/3382/guides)
![Angled shot of a Adafruit Metro M4 feat. Microchip ATSAMD51. ](https://cdn-shop.adafruit.com/640x480/3382-13.jpg)

### Adafruit Metro M4 Express AirLift (WiFi) - Lite

[Adafruit Metro M4 Express AirLift (WiFi) - Lite](https://www.adafruit.com/product/4000)
Give your next project a lift with _AirLift_ - our witty name for the ESP32 co-processor that graces this Metro M4. You already know about the&nbsp; **Adafruit Metro M4** &nbsp;featuring the&nbsp; **Microchip ATSAMD51** , with it's 120MHz Cortex M4 with...

In Stock
[Buy Now](https://www.adafruit.com/product/4000)
[Related Guides to the Product](https://learn.adafruit.com/products/4000/guides)
![Adafruit Metro M4 Airlift Lite dev board with SAMD51 an ESP32 Wifi Co-processor.](https://cdn-shop.adafruit.com/640x480/4000-08.jpg)

### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
![USB cable - USB A to Micro-B - 3 foot long](https://cdn-shop.adafruit.com/640x480/592-01.jpg)

### 9V battery holder with switch &  5.5mm/2.1mm plug

[9V battery holder with switch &  5.5mm/2.1mm plug](https://www.adafruit.com/product/67)
This is a 9V battery pack with on/off switch and a pre-attached 5.5mm/2.1mm center-positive barrel plug. Use this to battery-power your Arduino (or other electronic projects) - it's ready to go out of the box!

Battery & screw not included.

![]()

In Stock
[Buy Now](https://www.adafruit.com/product/67)
[Related Guides to the Product](https://learn.adafruit.com/products/67/guides)
![Angled shot of black 9V battery holder with on-off switch and 5.5mm/2.1mm plug.](https://cdn-shop.adafruit.com/640x480/67-03.jpg)

### Alkaline 9V Battery

[Alkaline 9V Battery](https://www.adafruit.com/product/1321)
Battery power for your portable project! These batteries are high quality at a good price and work fantastic with any of the kits or projects in the shop that use 9V.

These batteries are Alkaline (MnO2) chemistry, with a voltage range of 9.6V (fresh) to 4.8V (dead). The mAh capacity...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1321)
[Related Guides to the Product](https://learn.adafruit.com/products/1321/guides)
![Angle Shot of PKcell 9V battery.](https://cdn-shop.adafruit.com/640x480/1321-02.jpg)

# ePaper Maze Maker

## The Maze Algorithm

For those interested in how the program creates a random maze, this section is for you!

There are two algorithms used here, a maze generator and a maze solver. The maze consists of a grid of boxes. Each box is numbered sequentially and initially contains 4 walls surrounding each grid. Using a random number generator, a box is selected from the grid and one of the 4 walls is removed making an opening with an adjacent box.&nbsp; The adjacent box receives the same sequence number as the selected box as well as all the other boxes sharing the same sequence number. This ensures that a maze loop is not created, which will cause a problem with the maze solver algorithm. Also, walls are not removed if the adjacent box has the same sequence number or is on the border. Breaking walls on random boxes continues until all boxes have the same sequence number. This ensures all boxes are connected to each other.

Since the boxes are all connected, any location along the perimeter can act as a start and end location. The algorithm puts the start and end location on opposite sides, but it does not matter which end you start from.

For the maze solver, it traverses through the maze from the start of the maze, making right turns at every intersection, until it reaches the end. This may cause some backtracking when a dead end is encountered, but it eventually finds the end of the maze. After removing the backtracking moves, the solution path is then overlaid on top of the maze.

# ePaper Maze Maker

## Arduino Setup

f you don't have it already, you will need the Arduino IDE installed on your computer to upload this sketch to the Metro M4 .&nbsp;[You will find information on installing Arduino in this learning guide](https://learn.adafruit.com/lesson-0-getting-started/overview). You will also need to configure the Metro M4 to work with the Arduino IDE. There are articles for setting up the [Metro M4 Express](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51) and [M4 Express Airlift](https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi)&nbsp;with Arduino and other environments in the [Adafruit Learning Guides site](https://learn.adafruit.com/).

## Installing The Libraries

For this sketch, you will need to install these libraries:

- Adafruit EPD (ePaper display) library
- Adafruit GFX library
- Adafruit BusIO library
- Adafruit NeoPixel library

All of these libraries can be installed directly from the IDE. Select the menu item,&nbsp; **Sketch** &nbsp;-\>&nbsp; **Include Library** &nbsp;-\>&nbsp; **Manage Libraries**. From the Library Manager Window, enter the words&nbsp; **adafruit epd** &nbsp;in the search box and you should see the Adafruit EPD library appear. Click the box where the library appears and then click the "Install" button to install the library. Be sure to install the latest version of the library.

In the same manner, install the&nbsp; **Adafruit GFX** &nbsp;and&nbsp; **NeoPixel** &nbsp;libraries by searching the words&nbsp; **adafruit gfx** &nbsp;and&nbsp; **neopixel,** &nbsp;respectively, to install the latest versions of these libraries.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/180/medium800/eink___epaper_feather_arduino_ide_epd.png?1562991483)

Once you have the Arduino IDE setup, you are ready to install the ePaper Maze Maker. It is available from GitHub by clicking the links at the top of the code below.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/EInk_EPaper_Maze/airlift_epaper_maze/airlift_epaper_maze.ino

# ePaper Maze Maker

## Use

![](https://cdn-learn.adafruit.com/assets/assets/000/078/358/medium800/eink___epaper_3mazes.jpg?1563482313 There are 3 levels of maze difficulty to choose from.)

The ePaper shield contains 4 programmable buttons and a reset button at the bottom of the display. For this sketch, buttons **A** , **B** and **C** select the difficulty level, with **A** being the easiest level, **B** the medium level and **C** the difficult level.

Button **D** toggles the solution on and off in case you get stuck solving it. The solution is overlaid on top of the maze in red ink, thanks to the tri-color feature of the ePaper shield.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/357/medium800/eink___epaper_IMG_20190717_222618.jpg?1563480898 Having trouble solving the maze? Just press the "D" button to display the maze with the solution (hard maze shown))

The built-in color LED NeoPixel on the Metro M4 Express displays green when the display is being updated for either the maze or the solution. Note that the buttons are disabled while the display is being updated, which could take a few seconds as is true for all ePaper displays.

The maze difficulty is based on the number of squares in the grid. When more squares are used in the grid, the maze becomes more complex and harder to solve. More squares are added to the maze by making them smaller in order to fit them on the fixed size of the ePaper display. Here is the breakdown of the 3 maze sizes:

- Easy Maze: 12 x 18 (14 pixels per box)&nbsp;
- Medium Maze: 17 x 26 (10 pixels per box)
- Hard Maze: 25 x 37 (7 pixels per box)

For example, at 14 pixels per box, this gives enough room on the ePaper shield for a maze size of 12 x 18, allowing for 4 pixels for the maze wall width.

Have fun solving mazes!


## Featured Products

### Adafruit Metro M4 feat. Microchip ATSAMD51

[Adafruit Metro M4 feat. Microchip ATSAMD51](https://www.adafruit.com/product/3382)
Are you ready? Really ready? Cause here comes the fastest, most powerful Metro ever. The **Adafruit Metro M4** featuring the **Microchip ATSAMD51**. This Metro is like a bullet train, with its 120MHz Cortex M4 with floating point support. Your code will zig and zag...

In Stock
[Buy Now](https://www.adafruit.com/product/3382)
[Related Guides to the Product](https://learn.adafruit.com/products/3382/guides)
### Adafruit Metro M4 Express AirLift (WiFi) - Lite

[Adafruit Metro M4 Express AirLift (WiFi) - Lite](https://www.adafruit.com/product/4000)
Give your next project a lift with _AirLift_ - our witty name for the ESP32 co-processor that graces this Metro M4. You already know about the&nbsp; **Adafruit Metro M4** &nbsp;featuring the&nbsp; **Microchip ATSAMD51** , with it's 120MHz Cortex M4 with...

In Stock
[Buy Now](https://www.adafruit.com/product/4000)
[Related Guides to the Product](https://learn.adafruit.com/products/4000/guides)
### Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM

[Adafruit 2.7" Tri-Color eInk / ePaper Shield with SRAM](https://www.adafruit.com/product/4229)
Easy e-paper finally comes to microcontrollers, with this breakout that's designed to make it a breeze to add a tri-color eInk display. Chances are you've seen one of those new-fangled 'e-readers' like the Kindle or Nook. They have gigantic electronic paper 'static'...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4229)
[Related Guides to the Product](https://learn.adafruit.com/products/4229/guides)
### USB cable - USB A to Micro-B

[USB cable - USB A to Micro-B](https://www.adafruit.com/product/592)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or microcontroller

Approximately 3 feet / 1 meter long

Out of Stock
[Buy Now](https://www.adafruit.com/product/592)
[Related Guides to the Product](https://learn.adafruit.com/products/592/guides)
### 9V battery holder with switch &  5.5mm/2.1mm plug

[9V battery holder with switch &  5.5mm/2.1mm plug](https://www.adafruit.com/product/67)
This is a 9V battery pack with on/off switch and a pre-attached 5.5mm/2.1mm center-positive barrel plug. Use this to battery-power your Arduino (or other electronic projects) - it's ready to go out of the box!

Battery & screw not included.

![]()

In Stock
[Buy Now](https://www.adafruit.com/product/67)
[Related Guides to the Product](https://learn.adafruit.com/products/67/guides)
### Alkaline 9V Battery

[Alkaline 9V Battery](https://www.adafruit.com/product/1321)
Battery power for your portable project! These batteries are high quality at a good price and work fantastic with any of the kits or projects in the shop that use 9V.

These batteries are Alkaline (MnO2) chemistry, with a voltage range of 9.6V (fresh) to 4.8V (dead). The mAh capacity...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1321)
[Related Guides to the Product](https://learn.adafruit.com/products/1321/guides)
### USB Battery Pack - 2200 mAh Capacity - 5V 1A Output

[USB Battery Pack - 2200 mAh Capacity - 5V 1A Output](https://www.adafruit.com/product/1959)
A smaller-sized rechargeable battery pack for your&nbsp;[Raspberry Pi](http://www.adafruit.com/raspberrypi)&nbsp;or [Raspberry Pi B+](https://www.adafruit.com/product/1914)&nbsp;(or&nbsp;[Arduino](http://www.adafruit.com/arduino), or&nbsp;<a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1959)
[Related Guides to the Product](https://learn.adafruit.com/products/1959/guides)
### USB to 2.1mm Male Barrel Jack Cable

[USB to 2.1mm Male Barrel Jack Cable](https://www.adafruit.com/product/2697)
There's two standard ways to power electronics - USB or 5.5mm/2.1mm DC barrel jack. This or that! With this **USB to 2.1mm Male Barrel Jack Cable** , you can now power 5V DC powered electronics that have a DC jack from a USB jack with a handy 1 meter long...

In Stock
[Buy Now](https://www.adafruit.com/product/2697)
[Related Guides to the Product](https://learn.adafruit.com/products/2697/guides)

## Related Guides

- [Adafruit Metro M4 Express featuring ATSAMD51](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51.md)
- [Adafruit Metro M4 Express AirLift (WiFi)](https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi.md)
- [Adafruit 2.7" eInk Display Breakouts and Shields](https://learn.adafruit.com/adafruit-2-7-eink-display-breakouts-and-shields.md)
- [eInk / ePaper Weather Station](https://learn.adafruit.com/epaper-weather-station.md)
- [3D Printed LED Microphone Flag](https://learn.adafruit.com/3d-printed-led-microphone-flag.md)
- [Quickstart using Adafruit eInk/ePaper displays with CircuitPython](https://learn.adafruit.com/quickstart-using-adafruit-eink-epaper-displays-with-circuitpython.md)
- [ePaper Calendar Featuring Metro M4 Express Airlift and Tri-Color ePaper Shield](https://learn.adafruit.com/epaper-calendar-featuring-metro-m4-express-airlift-and-epaper-shield.md)
- [Which CircuitPython Board is Right for You?](https://learn.adafruit.com/choose-your-circuitpython-board.md)
- [CircuitPython 101: Functions](https://learn.adafruit.com/circuitpython-101-functions.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [Halloween Countdown Display Matrix](https://learn.adafruit.com/halloween-countdown-display-matrix.md)
- [CircuitPython Connected Weather Cloud Lamp](https://learn.adafruit.com/circuitpython-connected-weather-cloud.md)
- [Stream Deck controlled RGB Message Panel using Adafruit IO](https://learn.adafruit.com/stream-deck-controlled-rgb-message-panel-using-adafruit-io.md)
- [Ethernet for CircuitPython with Wiznet5K](https://learn.adafruit.com/ethernet-for-circuitpython.md)
- [Purple Air AQI Display](https://learn.adafruit.com/purple-air-aqi-display.md)
- [Adafruit IO Basics: Schedule Actions](https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers.md)
- [MIDI for Makers](https://learn.adafruit.com/midi-for-makers.md)
- [Custom Scrolling Quote Board Matrix Display](https://learn.adafruit.com/aio-quote-board-matrix-display.md)
