SwiftIO: The Swift Playground for Hardware | Swift Safari

Discover a new project working to build up an embedded Swift ecosystem from scratch!

Ocean Paradise (they/them)
SwiftSafari
10 min readJun 13, 2023

--

Screenshot of the MadMachine Website via MadMachine.io

In the vast, interconnected world of microcontrollers and embedded systems, programming languages play a key role in defining the overall project experience, with their safety, efficiency, and ease of use. As we previously discovered in our exploration of the Swift4Arduino project and microSwift, Swift’s power extends beyond creating beautiful iOS applications, reaching into the heart of microcontroller programming.

But as the river of technological innovation continues to flow, new tributaries emerge, bringing forth exciting new avenues for exploration. Today, we’re embarking on yet another journey, diving into the uncharted waters of the MadMachine project, a groundbreaking initiative that aims to further bring the elegance and safety of the Swift language to microcontroller programming.

In this comprehensive guide, we will delve into MadMachine’s universe, unveiling its extraordinary ability to allow Swift programming for microcontrollers in a more user-friendly and accessible manner. We will break down the project’s key components: SwiftIO and SwiftIO Feather, two microcontroller boards that offer the uniqueness of Swift programming. We’ll also explore the MadMachine extension for VS Code, which simplifies the process of creating, compiling, and downloading Swift code.

Whether you’re an Arduino enthusiast intrigued by the lure of Swift or a seasoned Swift developer keen to understand the magic of microcontroller programming, this guide is designed to enlighten and inspire. We hope to build on the knowledge you’ve gained from our previous article on Swift4Arduino and microSwift, further expanding your understanding of the application of Swift in hardware.

Swift Language and Microcontrollers: A Match Made in Silicon

So, Why Swift for Microcontrollers?

At first glance, one might question the pairing of Swift — a programming language commonly associated with macOS and iOS application development — with the domain of microcontrollers. What makes Swift a viable and attractive option for this field, typically dominated by languages like the C’s, Ada, Rust, and even *gasps* Python?

To answer this, we need to delve into the key strengths of Swift as a language. Swift was developed with a focus on safety, performance, and software design patterns. Its strong typing and error handling abilities allow for safer, more predictable coding. This means less time spent debugging and more time for actual development, a critical advantage when working with microcontrollers where debugging can be quite a hassle.

In terms of performance. . . I mean just look at it’s name! Purists might fight me on this, but for many, many applications, Swift offers comparable performance to C! Swift’s ability to manage memory automatically without sacrificing speed is a huge plus, especially in the context of microcontrollers which usually operate under memory constraints. The powerful, yet easy-to-read syntax of Swift makes the code cleaner and reduces the chances of error.

Swift’s modern features like optionals, generics, tuples, and closures (all of which I’ve written about in Swift Safari’s introductory articles!) help developers write flexible and safe code, reducing common programming errors. The elegant syntax of Swift also improves readability and makes it an easier language to learn and use for new programmers.

But the beauty of Swift in microcontrollers goes beyond its technical prowess. Swift has a huge community of developers, thanks to its widespread use in iOS development. This leads to a wealth of resources and a strong support network that can assist in troubleshooting and learning.

On top of all these, Swift’s integration with microcontrollers has been getting better and more efficient over time, thanks to projects like Swift4Arduino, microSwift, and now the MadMachine project. They bring Swift’s safety, performance, and expressive syntax to the world of microcontrollers, making it easier than ever to use Swift for such hardware-centric applications.

In summary, Swift presents an attractive blend of efficiency, safety, and readability, further strengthened by a robust community and growing platform support. These factors make it a compelling choice for microcontroller programming, promising to redefine our engagement with embedded systems. As we journey deeper into the MadMachine project, you’ll discover how these advantages of Swift translate into a user-friendly and innovative microcontroller experience.

The Vision and Objective of the MadMachine Project

At the intersection of innovation and practicality, the MadMachine project stands tall. Born from a desire to bring the dynamism and elegance of Swift to the world of microcontrollers, MadMachine is an initiative driven by passion and a futuristic vision. Its primary objective is clear: to make Swift a first-class citizen in the domain of microcontroller programming. This project not only caters to the seasoned Swift developer eyeing the realm of embedded systems but also extends a welcoming hand to Arduino enthusiasts curious about the wonders of Swift. It paves the way for a harmonious marriage between the powerful features of Swift and the hands-on, hardware-centric world of microcontrollers.

The MadMachine Project: A Brief Overview

MadMachine encompasses four key components that work together to provide a seamless and intuitive Swift programming experience for microcontrollers.

  1. SwiftIO: A microcontroller board designed from the ground up to provide Swift developers an easy entry point into the world of embedded systems.
  2. SwiftIO Feather: A compact, lightweight version of SwiftIO, compliant with the Feather standard for microcontroller boards. It serves as an attractive option for small-scale and space-critical applications.
  3. SwiftIO Playground: This offers a complete package for Swift programming on microcontrollers, including the board and several add-on modules. It is designed to aid newcomers to easily start experimenting and learning.
  4. MadMachine extension for VS Code: This revolutionary tool simplifies the process of writing, compiling, and downloading Swift code to SwiftIO boards, making it a vital part of the MadMachine ecosystem.

Each of these components provides unique benefits, and together they form an ecosystem that is greater than the sum of its parts.

Revolutionizing Swift Programming for Microcontrollers

The MadMachine project is a game-changer, not just for the Swift community but for the whole landscape of microcontroller programming. By bringing the safety, performance, and clean syntax of Swift to the realm of embedded systems, MadMachine opens a new era of innovation and creativity. It brings the robustness and modernity of software development to hardware programming, making it more accessible and user-friendly.

Through SwiftIO and SwiftIO Feather, the project offers a tangible platform for Swift developers to explore the fascinating world of microcontrollers, breaking the barriers that once existed between these two fields. With the MadMachine extension for VS Code and SwiftIO Playground, it goes a step further by providing the tools necessary for an efficient and smooth coding experience.

As we continue our journey into the MadMachine project, you’ll get a closer look at each of these components and understand their role in redefining the world of microcontroller programming with Swift.

MadMachine’s Core: SwiftIO and SwiftIO Feather Boards

In this section, we’ll provide an in-depth overview of the two key components of the MadMachine project: the SwiftIO and SwiftIO Feather microcontroller boards. These boards are designed to facilitate Swift programming for embedded systems, and they form the backbone of the MadMachine ecosystem.

The SwiftIO Board

SwiftIO Board via MadMachine.io

The SwiftIO board is the foundational microcontroller board developed as part of the MadMachine project. Designed specifically for Swift programming, the SwiftIO board combines power and functionality, making it ideal for a wide variety of projects.

At the heart of the SwiftIO board is the i.MX RT1052 Crossover Processor with an Arm® Cortex®-M7 core. This 32-bit microcontroller unit (MCU) runs at an impressive clock speed of 600MHz, enabling quick and efficient data processing.

The SwiftIO board is equipped with 8MB of external flash memory and 32MB SDRAM. This ample memory allows for the storage and execution of more complex Swift programs. Two buttons on the board facilitate code downloading and resetting, while two USB ports enable serial communication and code downloading. The board can be powered via either of these USB ports.

A built-in RGB LED indicates the status of the board, and users can control its color by setting digital levels. There are 45 digital input/output pins that can be used to interface with other circuits. In addition, there are 12 analog input pins and 14 PWM output pins.

The SwiftIO board also supports I2C, SPI, UART, and CAN protocols for communication with external devices. The board can be powered via an external source through the Vin pin, and the Vout pin will provide the higher output voltage between Vcc and USB voltage. Additionally, the IOREF pin provides a voltage corresponding to the board’s input and output, which is 3.3V.

The SwiftIO Feather Board

SwiftIO Feather Board via MadMachine.io

The SwiftIO Feather board is a compact, lightweight version of the SwiftIO board. Despite its smaller size, the Feather board packs a powerful punch, making it a capable choice for any project.

The SwiftIO Feather board features an i.MX RT1062 Crossover Processor with an Arm® Cortex®-M7 core. Like the SwiftIO board, the MCU operates at a high clock speed of 600MHz.

In terms of memory, the Feather board matches its larger counterpart with 8MB of flash memory and 32MB SDRAM. The board has one USB-C port for code downloading and power supply, along with a LiPo battery connector for powering projects on the go.

The Feather board also includes a built-in RGB LED for status indication and user control, as well as a range of digital, analog, and PWM pins. Communication with external devices can be achieved via I2C, SPI, UART, and CAN protocols.

One significant feature of the SwiftIO Feather board is its compatibility with the Adafruit Feather system. This compatibility allows for seamless integration with the wide range of hardware modules available within the Adafruit ecosystem, opening up a myriad of possibilities for Swift developers.

A Revolution in Microcontroller Programming: MadMachine Extension for VS Code and SwiftIO Playground

With the hardware groundwork established, it’s time to delve into the software components that make the MadMachine project a true revolution in microcontroller programming. This section will introduce the MadMachine extension for Visual Studio Code (VS Code) and the SwiftIO Playground.

MadMachine Extension for VS Code

The MadMachine extension for VS Code is a game-changer for Swift developers interested in microcontroller programming. It simplifies the process of creating, compiling, and downloading Swift code, allowing developers to focus on writing code rather than wrestling with the intricacies of hardware programming.

The extension provides a specialized Integrated Development Environment (IDE) within VS Code, streamlining the development process. It features syntax highlighting, automatic code completion, and debugging tools tailored for Swift programming. You can directly compile and download your Swift code to the SwiftIO boards right from the IDE. This integration makes it possible for developers to switch seamlessly between writing code and testing it on their hardware.

For beginners, the MadMachine extension includes several sample projects that offer a hands-on introduction to Swift-based microcontroller programming. These samples cover a range of applications, helping new users get acquainted with the capabilities of the SwiftIO boards.

SwiftIO Circuit Playground

SwiftIO Playground via MadMachine.io

Taking another significant leap towards simplifying microcontroller programming, MadMachine introduces the SwiftIO Circuit Playgrounds. This starter kit is designed for seamless, easy-to-use access to Swift-based microcontroller programming. It is an all-in-one board version of the MakerKit (which comes with all the modules separately) where all modules are connected to the central shield. For those of you who’ve still got their Blockbuster member tag on their keychain, it’s kind of like a RadioShack Learning Lab! The benefit of this design is its straightforwardness — there is no need for individual circuit building. Simply download the code, and if error-free, the devices immediately come to life.

Let’s delve into the specifics of the modules that comprise the SwiftIO Circuit Playgrounds:

  1. SwiftIO Feather board: This is the control center that manages all other modules.
  2. Shield: This component enables the SwiftIO Feather board to connect to the entire board.
  3. LED: This module can be toggled on and off or adjusted to any desired brightness.
  4. Button: The button allows you to control the circuit based on your press or release actions.
  5. Potentiometer: This device allows for varying the resistance connected in the circuit.
  6. Buzzer: The buzzer generates alert or confirmation sounds.
  7. Humiture: This module measures temperature and humidity.
  8. Color sensor: This sensor can detect the color of an object and light intensity.
  9. Accelerometer: It detects movement by measuring acceleration across the x, y, and z-axes.
  10. Speaker: The speaker generates sounds or plays back audio files.
  11. Microphone: The microphone is used to record sound and store audio data.
  12. LCD: This module is used to display graphics or images.

The SwiftIO Circuit Playgrounds comes packed with these commonly used modules, enabling you to create an array of projects. Moreover, it forms the foundation of the ‘Learning A-Z’ material, which guides you from the most basic concepts, making this a perfect tool for beginners in Swift-based microcontroller programming. The SwiftIO Circuit Playgrounds, alongside the MadMachine extension for VS Code, contributes to breaking down barriers and opening up the world of microcontroller programming to a broader audience.

The SwiftIO Playground, along with the MadMachine extension for VS Code, breaks down the barriers that often deter developers from delving into microcontroller programming. These tools make it easier than ever for Swift developers to bring their skills into the world of embedded systems, opening up a world of opportunities for innovation and creativity.

Community

You can find the discord community here, their twitter here, their GitHub here, their Youtube here, and their website here (where you can order kits and find their documentation!). Check them out on their social and seriously give them some due applause because this is one epic project!

I am so excited about this project! They are currently on sold out, and I can’t wait for them to stock back up so I can get my hands on the hardware and start writing some follow along projects for everyone (although the existing stuff in their documentation is excellent already!).

So what did you think about this project? Do you want me to cover similar projects? Do you want to see more embedded Swift? Let me know your thoughts below!

--

--

Ocean Paradise (they/them)
SwiftSafari

amateur computational biologist & software engineer |sentient astrolotl | open-source enthusiast | let's tinker together!