Skip to content

madmachineio/MadDriversSDK57

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MadDriversSDK57

build test codecov Discord twitter

This MadDriversSDK57 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.

Drivers

You can find some frequently-used hardware here:

Type Device Communication
Accelerometer ADXL345 I2C/SPI
LIS3DH I2C/SPI
Color VEML6040 I2C
TCS34725 I2C
DAC MCP4725 I2C
Dispaly
IS31FL3731 I2C
LCD1602 I2C
ST7789 SPI
Distance
HCSR04 GPIO
VL53L0x I2C
Gas
BME680 I2C/SPI
SGP30 I2C
Gesture APDS9960 I2C
Gyroscope MPU6050 I2C
Light BH1750 I2C
TSL2591 I2C
Magnetometer MAG3110 I2C
Pressure BMP280 I2C/SPI
RTC DS3231 I2C
PCF8523 I2C
PCF8563 I2C
Temperature & Humidity AHTx0 I2C
DHTxx GPIO
MCP9808 I2C
SHT3x 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 MadDriversSDK57 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: "MadDriversSDK57", package: "MadDriversSDK57") to

    .product(name: "SHT3x", package: "MadDriversSDK57") 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/MadDriversSDK57.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.
        .target(
            name: "sht3x",
            dependencies: [
                "SwiftIO",
                "MadBoards",
                // use specific library would speed up the compile procedure
                .product(name: "SHT3x", package: "MadDriversSDK57")
            ]),
        .testTarget(
            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()
    print(temperature)
    print(humidity)
    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.

About

MadDriver-sdk5.7-alpha-action

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages