Arduboy on ATMega4809

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

Arduboy on ATMega4809

Story

Breadboard Arduboy4809

PCB:

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:

PCB

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:

[platformio]
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:

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

[env:ATmega4809]
platform = atmelmegaavr
board = ATmega4809
framework = arduino

build_flags = -D ARDUBOY4809
-D OLED_SH1106

Source: Arduboy on ATMega4809


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top