Contents

Setting Up Your Microcontroller Development Environment

Introduction

Hello again! As we gear up for 2024, I’ve got some exciting projects in the pipeline. While I’m waiting for parts to arrive, I thought it would be a great time to help you set up your microcontroller development environment.

Having a robust Integrated Development Environment (IDE) is crucial for efficient software development. An IDE, much like our homes, provides us with essential tools and features that streamline our workflow. Think of code autocompletion, syntax highlighting, debugging tools, and version control systems as the modern appliances, efficient heating and cooling systems, and a reliable security system for developers. Today, I’ll guide you through setting up your development environment using Visual Studio Code and PlatformIO.

Goals for Today

  1. Install the necessary tools.
  2. Get familiar with the tools.
  3. Create a simple ‘Hello World’ project.
  4. Upload our sketch to a microcontroller.

Setting the Stage

The microcontroller I’ll be using is the STM32 ‘Blue Pill.’ These ST devices are powerful development boards, similar to Arduino Nano but with significantly more processing capabilities. I chose it mainly because I accidentally ordered a bunch a few months ago—lesson learned. However, you can follow along with almost any microcontroller supported by the Arduino framework.

Why PlatformIO and Arduino framework? The answer is simple: cross-platform support. PlatformIO offers compatibility with a wide range of microcontrollers, and the Arduino framework is beginner-friendly, making it an excellent choice for our initial coding adventures.

Installing PlatformIO

PlatformIO is a plugin for Visual Studio Code. Here’s how you can set it up:

  1. Download and install Visual Studio Code.
  2. Open VS Code, go to Extensions, and search for ‘PlatformIO IDE.’
  3. Install “PlatformIO IDE” by PlatformIO.
  4. Reload VS Code to enable the plugin.

Creating a New Project

Let’s familiarize ourselves with the PlatformIO interface. While we won’t dive deep today, we’ll cover some essential aspects:

  • Navigating to the PlatformIO home.
  • Connecting an account (optional).
  • Exploring tools, libraries, boards, platforms, and devices.

Now, let’s create our first project:

  1. Click “New Project” on the home page.
  2. Enter a project name.
  3. Select your microcontroller board.
  4. The framework will auto-generate (Arduino framework for today).
  5. Leave the default location checked.

Configuring the Toolchain

Take a quick look at the project structure:

  • The .gitignore file keeps unwanted files out of the repository.
  • The include folder is for OOP classes (we’ll explore this later).
  • The lib folder is for private libraries.
  • The src folder contains your code (main.cpp).
  • The test folder is for unit testing.

Platform Configuration with platform.ini

The platform.ini file allows manual project configuration. While PlatformIO provides a user-friendly UI, understanding this file enhances your project management skills.

Let’s create a simple “Hello World” by making an LED blink. The non-blocking code structure uses a timer instead of a traditional “delay()” function:

#include <Arduino.h>

const int ledPin = LED_BUILTIN;
unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (digitalRead(ledPin) == LOW) {
      digitalWrite(ledPin, HIGH);
    } else {
      digitalWrite(ledPin, LOW);
    }
  }
}

Uploading and Verifying

To upload the code to your microcontroller:

  1. Click the check icon for compilation.
  2. Click the right arrow ‘->’ to upload the code.
  3. Use the plug icon for the serial monitor (debugging tool).

And there you have it—a simple blinky light! But fear not; blinky lights are just the beginning. In the upcoming videos, we’ll delve into more advanced projects, covering gate and control voltage signals, MIDI, audio generation, and more.

Recap and Closing

Today turned out to be more than a simple setup guide. We configured VS Code and PlatformIO, explored the UI, and created a working sketch for our microcontroller. The journey doesn’t end here; we’re just scratching the surface. Join me in future posts as we build the knowledge needed for exciting microcontroller-based musical projects.

I encourage you to follow along. If you have an Arduino or another microcontroller, give PlatformIO a try. Together, we can turn a hobby into a more professional experience, opening up new possibilities for microcontroller programming.

Until next time! Stay curious, and don’t hesitate to try something new!