Gamebuino Meta with code completion in Visual Studio

As the official Arduino IDE is quite limited in features, I tried out some alternatives. I was mostly in search for code completion. I tried PlatformIO in vscode first but apparently some configuration files for the Gamebuino board are not yet available to get it to work, so I tried Visual Studio (which I know very well anyway) and succeeded.

This blogpost runs you through the setup enabling you to program the Gamebuino Meta in Visual Studio 2019 and its rich IDE featureset (including code completion 🙂 ). This solution uses free software.

Configure the Arduino IDE

We first need to setup the regular solution as if we were going to program the GameBuino Meta using the official Arduino IDE.

To do this, do exactly what the official Gamebuino Meta installation guide says 🙂 Find it here: https://gamebuino.com/academy/standalone/arduino-manual-setup

The gist is that you have installed the 2 board packages and 1 library package.

A Board is a package of info for the Arduino compiler so it can compile our C++ programs into the specific binary format that the Gamebuino Meta hardware understands.

A Library contains a large amount of C++ code written by other people for us, so we don’t have to reinvent the wheel for common tasks you want the Gamebuino Meta to do: draw things on the screen, play sounds, etc.

You can try compiling this Gamebuino Meta sample to see if it works:

#include <Gamebuino-Meta.h>

void setup() {
  gb.begin();
}    

void loop() {
  while(!gb.update());
  gb.display.clear();
  gb.display.print("hello, world");
}

To try if this compiles correctly, press the first button in the toolbar on top of the Arduino IDE screen (“Verify”). It should say “Done compiling” in the bottom after a while. If the bottom becomes Orange, it means compilation has failed. You probably made a mistake following the Gamebuino installation guide, or maybe you copy pasted the sample code wrong?

Configure Visual Studio

  • If you haven’t already, install Visual Studio Community edition: https://visualstudio.microsoft.com/vs/
  • Start Visual Studio and install the “Arduino IDE for Visual Studio” extension from menu Extensions > Manage Extensions
  • Restart Visual Studio (a short install procedure will show up and complete)
  • Upon restarting Visual Studio, a pop up will ask you for the Arduino IDE location. It should autodetect what it is asking for, but in case it doesn’t: the default Arduino application location is C:\Program Files (x86)\Arduino

Create a new Gamebuino Meta project in Visual Studio

Create a new project from either the startup screen or from the File menu if Visual Studio is already fully started.

In the “Create a new project” dialog, use the search box to find the “Arduino Project” template and select it. Click Next:

Give the project any name you like (I chose PingPong) and click Create:

Visual Studio generates and opens your new project.

Tell Visual Studio we want to use the Gamebuino Meta library by just clicking the library from the toolbar. This may seem a bit weird, but it actually does some stuff in the background, making Visual Studio incorporate the library in its code completion etc:

Replace the generated code in the .ino file with the sample code we used earlier in this tutorial. It may still show errors about not finding the library we added in the previous step:

To remedy this issue, unload and reload the project from the Solution Explorer to fix this small issue:

Don’t forget to reload it immediately after. (Same right-click menu…)

Visual Studio is now aware of the Gamebuino library and all errors in your code should now be gone:

Build the code (Ctrl+Shift+B or menu Build > Build Solution). You should see no errors in the Output window (bottom of Visual Studio).

Testing the demo

By building for the Gamebuino Meta board, Visual Studio generates a .bin file which contains the compiled program, ready for use by a Gamebuino or an emulator.

You can grab the .bin file from your project’s folder. Access that folder from the Solution Explorer: right click your project’s node, as you have done before, and choose “Open Folder in File Explorer”. Go to the Debug or Release subfolder to find the .bin file. (PingPong.bin in my case).

Drag the .bin file on aoneill’s emulator at https://gamebuino.com/creations/meta-emulator and see the demo work:

Now, you can start programming using the full comfort of Visual Studio! For instance, by following the official tutorials at https://gamebuino.com/academy