Arduboy on ATMega4809

Porting Arduboy to the ATMega4809 and making it run on a Arduino Nano Every.

Arduboy on ATMega4809


Breadboard Arduboy4809


If you build the custom PCB version the battery charging (MCP7383) and boost converter (MCP1640) functions are nicely integrated. We used PCBgogo to manufacture the boards and they came out very nice. PCBgogo can also supply you with a stencil to apply the solder paste. In our case we just used a syringe and gently applied the paste to the pads. The surface mount components where then placed using some tweezers. Soldering of the components was done with a hot air rework station. Below are some photos taken during the build:


The board is powered up by moving the power switch to the happy face. In this mode the battery voltage is boosted to 5V and supplied to the 5V pin of the Nano Every and the OLED display. While switched on the battery charging circuit is disabled. To charge the battery you need to switch the power switch to the unhappy face and connect through the Nano Every USB to a power source (e.g computer, power bank, etc.). The “CHRG” LED will light up while charging and goes out when charging is done.

NOTE: double check the polarity of the battery connector before connecting it for the first time!

When using a 0.96″ display the four holes can be used to secure the display. Since we later decided to use a 1.3″ display we repurposed the holes to secure the battery with cable ties.

The slightly off-centered through hole pads for the Nano Every works okay but if you want it bullet proof then you should consider soldering it.

Using a battery:

 If you use a battery (like Lithium-Ion or Lithium Polymer) you should also think about charging it and protecting it against over charging/discharging. The easiest way to handle protection of the battery is by just using one which already has protection build into it. It typically comes as a small PCB which acts as a kind of BMS (Battery Management System) and shrink wrapped with the battery.

Lithium-Ion battery with protection circuit

As for charging, the PCB version uses the MCP7383 chip to charge a single cell Lithium Ion battery. If you built the breadboard version you could also use a separate charger (there are cheap one available on ebay). When using a Lithium Ion battery the fully charged voltage sits at 4.2V and can quickly drop down to 3.7V during operation. As we want 5V at the Nano a small boost converter is needed. The PCB version uses MCP1640 chip to boost the battery voltage to 5V. On the breadboard version you could use whatever you have laying around. We tested with a MT3608 module which worked pretty well.

How to build games for ARDUBOY4809

Once your hardware is ready you would surely want to try out some games on it, right. So let’s go through the steps needed to do so while using the Shadow Runner game as an example. As we are using a different microcontroller we need to build the game code specifically for our hardware. So far the approach which worked the best for us was to use PlatformIO running on top of Visual Studio Code to build the game source code. So the first thing to do is to install Visual Studio Code and then add the PlatformIO extension. If you have it running already you can skip the step below.

Installing Visual Studio Code & PlatformIO

Visual Studio Code is a very powerful code editor (not to be confused with Visual Studio, the “Code” part makes the difference) which you can download and install free from here. Once installed run it and on the menu bar click View -> Extensions. In the extensions search field type “platformio ide” and install it.

Installing Visual Studio Code & PlatformIO

As you can see PlatformIO is an extension that runs on top of Visual Studio Code. It is a great tool for embedded development and also supports the Arduino framework. It provides a more enjoyable programming experience with advanced features like auto code completion and syntax highlighting.

Create a new project

Next you have to create a new project in PlatformIO which will be used to build the game code. If you have VS Code running then click the PlatformIO icon (looks like an ants head) in the vertical bar on the left of the window.

A menu should appear and under “PIO Home” click “Open” which will bring up the PlatformIO welcome screen.

On the right of the welcome screen are some “Quick Access” buttons, select “New Project”.

New Project

Now give the project a name, I used “TestShadowRunner”. Then select “ATmega4809 (Microchip)” as board and “Arduino” as framework. If you don’t want to use the default project folder (..\Documents\PlatformIO\Projects) then uncheck the location box and specify your own folder. When you are ready click “Finish” to start the creation of the project. The very first time you do this it might take some time as PlatformIO downloads some dependencies.

Project Wizard

When the new project is created you should see the project folders in the Explorer view on the left side of the screen. Click the “src” folder and inside it you should see “main.cpp” which was automatically created.

project folders

Since we don’t need this file you can right click it and select “Delete”.

Add game source code to project

Next we need to add the source code of our game to the “src” folder. Since we are using Shadow Runner in this example, download the source and extract it to the “src” folder. It should look something like this:

Shadow Runner in src folder

Add libraries to project

Now we need to add the ARDUBOY4809 libraries to the project. For Shadow Runner you will need both the Arduboy4809 and ArduboyTones libraries. Download the library source code to the “lib” folder of your project. The easiest way is to just download the zip file (using the Code button as shown below) and extract it to the “lib” folder.

Download the library source code

After you have extract the zip files the folder structure should look something like this:

project lib folder

Notice that we have downloaded and extracted both Arduboy4809 and ArduboyTones. At this point you don’t need the zip files anymore and could remove them if you like.



Build configuration

The next step is to configure the “platformio.ini” file and we start by pointing to the source files which PlatformIO should use by adding:

src_dir = src\ID-15-Shadow-Runner-qr-removal\SHRUN_AB

Then we add the build flags which makes sure that we build the Arduboy4809 version of the code with:

build_flags = -D ARDUBOY4809
-D OLED_SH1106

If you are using a SSD1306 display then remove the second line (-D OLED_SH1106).

Putting everything together it should look something like this:

src_dir = src\ID-15-Shadow-Runner-qr-removal\SHRUN_AB

platform = atmelmegaavr
board = ATmega4809
framework = arduino

build_flags = -D ARDUBOY4809
-D OLED_SH1106

Source: Arduboy on ATMega4809

About The Author

Ibrar Ayyub

Ibrar Ayyub is an experienced technical writer with a Master's degree in computer science from BZU Multan University. He has written for various industries, mainly home automation, and engineering. He has a clear and simple writing style and is skilled in using infographics and diagrams. He is a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top