Skip to main content

Run your first project

Now let's learn how to program your board and run your first project. You will start with a hello world project - LED blink.

Step 1: Install the MadMachine extension in Visual Studio Code#

At first, you need a tool to deal with your code. You could install the MadMachine extension for Visual Studio Code. It allows you to create a new project, compile and download it to your board.

  1. In the Visual Studio Code, click the Extension icon on the left activity bar.
  2. Enter madmachine in the search box to find the extension in its marketplace.
  3. Click the Install button.
Install the MadMachine extension

When you install the MadMachine extension, the extension Serial Port Helper will be installed as well. It allows you to view values or debug. Of course, you could use other similar tools instead.

The MadMachine extension and serial port has been installed
info

For advanced users, you could edit your code wherever you like and use the mm-sdk to compile your code.

Step 2: Set the extension#

The extension relies on the mm sdk to do all its work. So you need to indicate its path before using the extension. You only set it the first time you use this extension.

  1. Download the latest sdk according to your operating system and unzip it.

  2. Then come back to the VS code. In the menu bar, select Code / Preferences / Settings.

Set the MadMachine extension
  1. In the Settings, select Extensions / MadMachine. Enter the path of the sdk in the box that matches your operating system. Windows is not supported since we are waiting for the Window support of Swift language...
Indicate the path of sdk.

Step 3: Write code#

Now, you're ready to code.

  1. Click the Explore icon on the left bar. Then click the MadMachine extension on the bottom to show three buttons. Click New Project.
Create a new project.
  1. Choose the project as an executable.
Choose project type.
  1. Choose the board you are going to use.
Choose the board.
  1. Name the project. You could choose any descriptive name you like for the project. Then press the Enter key.
Enter project name.
  1. Choose a location to store the project and press Open.
Choose a file location.
  1. The project will open in a new window. Click on the Explorer Sources / Blink / main.swift to open the file. You will always edit the code in the file main.swift for your future projects. Copy and paste the following sample code into the file.
import SwiftIOimport MadBoard
let led = DigitalOut(Id.BLUE)โ€‹while true {    led.write(true)    sleep(ms: 1000)
    led.write(false)    sleep(ms: 1000)}
code

Step 4: Prepare SD card and confirm USB connection#

After finishing the code, you need to download it to your board. So follow the steps below to connect the board to your computer first.

  1. Make sure that you have inserted an SD card into the slot.
Insert SD card
  1. Connect the board to your computer through the Download port using a USB cable. SwiftIO Feather board has only the download port. SwiftIO board has both download and serial ports, so make sure you connect the correct port.
Connect board to computer
  1. Press the Download button. Once pressed, your board will appear as a USB Drive on your computer. There are two buttons on your board. The one labeled "Download" or "DL" is the correct one.
Press download button
note

Bad quality USB cable or some third-party USB hub may cause connection failure. If the board still fails to connect to your computer, you can refer to FAQ.

  1. The onboard RGB LEDs will show the current status of the USB connection. Wait for several seconds until the LED turns to steady green.
LED StateREDGREENBLUE
OnUSB communication failedUSB connection established-
Slow flashingFail to verify bin file--
Fast flashingFail to open bin fileDetecting USB connectionDetecting SD card
Green LED is on

Step 5: Download code to your board#

  1. Click MadMachine / Build to build the project. It will generate a file that could run on your board.
Build the code
  1. Click Download on the MadMachine extension to download the file to your board.
Download the code

If it says it cannot find the board, you could wait a little longer. Maybe your board is building the connection with your computer. And make sure you have followed step 3 above.

After the code is downloaded to your board successfully, the USB drive will be removed automatically.

Congratulations! The onboard green LED begins to blink per second.