Swiftpack.co - madmachineio/MadDrivers as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by madmachineio.
madmachineio/MadDrivers 0.0.10
MadMachine drivers for sensors and other devices based on SwiftIO
⭐️ 4
🕓 35 weeks ago
.package(url: "https://github.com/madmachineio/MadDrivers.git", from: "0.0.10")


build test codecov Discord twitter

This MadDrivers library, based on SwiftIO, provides an easy way to use all kinds of devices with your boards. You could directly use the related class to read or write data and don't need to understand the communication details.

Note: This library aims to allow you to program the devices easily, so some uncommon errors or rare situations aren't be considered. The SwiftIO library can give the messages about the communication and which error occurs if it fails. If you need more detailed results about the device status to ensure security, you can download and modify the code according to your need.


You can find some frequently-used hardware here:

Type Device Communication
Accelerometer ADXL345 I2C/SPI
Color AS7341 I2C
TCS34725 I2C
VEML6040 I2C
IS31FL3731 I2C
LCD1602 I2C
ST7789 SPI
VL53L0x I2C
Gesture APDS9960 I2C
Gyroscope BMI160 I2C/SPI
MPU6050 I2C
Light BH1750 I2C
LTR390 I2C
TSL2591 I2C
VEML7700 I2C
Magnetometer MAG3110 I2C
MLX90393 I2C/SPI
Pressure BMP280 I2C/SPI
MPL3115A2 I2C
RTC DS3231 I2C
PCF8523 I2C
PCF8563 I2C
Temperature & Humidity AHTx0 I2C
MCP9808 I2C
Thermal AMG88xx I2C
Ultraviolet VEML6070 I2C

We will keep adding more drivers. And your contributions are welcome!

Use drivers

Take the library SHT3x for example:

  1. Create an executable project. You can refer to this tutorial.

  2. Open the project and open the file Package.swift.

    The MadDrivers has already been added to your project by default. You could use all libraries in it. It's better to specify the specific library to reduce the build time for your project. Change the statement

    .product(name: "MadDrivers", package: "MadDrivers") to

    .product(name: "SHT3x", package: "MadDrivers") as shown below.

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
    name: "sht3x",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/madmachineio/SwiftIO.git", .upToNextMinor(from: "0.0.1")),
        .package(url: "https://github.com/madmachineio/MadBoards.git", .upToNextMinor(from: "0.0.1")),
        .package(url: "https://github.com/madmachineio/MadDrivers.git", .upToNextMinor(from: "0.0.1")),
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
            name: "sht3x",
            dependencies: [
                // use specific library would speed up the compile procedure
                .product(name: "SHT3x", package: "MadDrivers")
            name: "sht3xTests",
            dependencies: ["sht3x"]),
  1. Now, you can write code for your project. In the file main.swift, import the SHT3x, then you could use everything in it to communicate with the sensor.
import SwiftIO
import MadBoard
import SHT3x

let i2c = I2C(Id.I2C0)
let sensor = SHT3x(i2c)

while true {
    let temperature = sensor.readCelsius()
    let humidity = sensor.readHumidity()
    sleep(ms: 1000)

Try examples

At first, you could try demo projects in the folder Examples.

In the Examples folder, there are folders for different devices. Each folder may have one or several projects to help you get started with each device.

├── Examples
│   ├── ADXL345
│   │   ├── ReadXYZ
│   ├── DS3232
│   │   ├── Alarm
│   │   ├── ReadTime
│   │   ├── Timer
│   ├── IS31FL3731
│   ├── ├── BreathingLED
│   ├── ├── DrawPixels
│   ├── ├── Frame
│   ├── ├── ScrollingText
│   ├── ...

You could download the whole folder and try the examples. Here is a tutorial about how to run the projects on your board.


Stars: 4
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.


Release Notes

MadDrivers 0.0.10
35 weeks ago

🚀 New Drivers

  • ADXL345
  • BMP280
  • DS3231
  • MPU6050
  • PCF8523
  • PCF8563

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics