All Projects → samco182 → SwiftySHT20

samco182 / SwiftySHT20

Licence: MIT license
⚡ A Swift library for the I2C SHT20 Humidity and Temperature Sensor.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to SwiftySHT20

arduino-sht
Repository for Sensirion humidity and temperature sensor support on Arduino
Stars: ✭ 43 (+126.32%)
Mutual labels:  i2c, temperature-sensor, humidity-sensor
AHT10
This is an Arduino library for Aosong ASAIR AHT10, AHT15 Digital Humidity & Temperature Sensor
Stars: ✭ 32 (+68.42%)
Mutual labels:  temperature-sensor, humidity-sensor
Si7021 Breakout
A breakout board for the Si7021 Temperature and Humidity sensor.
Stars: ✭ 24 (+26.32%)
Mutual labels:  temperature-sensor, humidity-sensor
embedded-sht
Embedded SHT Drivers for Sensirion Temperature and Humidity Sensors - Download the Zip Package from the Release Page
Stars: ✭ 53 (+178.95%)
Mutual labels:  i2c, temperature-sensor
i2c-exp-driver
Driver to program I2C based Onion Expansions
Stars: ✭ 33 (+73.68%)
Mutual labels:  i2c
BeerBot
A never-ending supply of cold beer at KI labs to maintain employee happiness
Stars: ✭ 30 (+57.89%)
Mutual labels:  raspberry-pi-3
bno055
ROS2 driver for Bosch BNO055 using UART or I2C
Stars: ✭ 25 (+31.58%)
Mutual labels:  i2c
EEGwithRaspberryPI
Open-Source board for converting RaspberryPI to Brain-computer interface
Stars: ✭ 402 (+2015.79%)
Mutual labels:  raspberry-pi-3
Object-sorting-using-Robotic-arm-and-Image-processing
Sorting objects of different colors using robotic arm and using computer vision (image processing).
Stars: ✭ 21 (+10.53%)
Mutual labels:  raspberry-pi-3
u8g2-arm-linux
U8g2 for arm linux - a monochrome graphics library
Stars: ✭ 37 (+94.74%)
Mutual labels:  i2c
gobot
Golang framework for robotics, drones, and the Internet of Things (IoT)
Stars: ✭ 7,869 (+41315.79%)
Mutual labels:  i2c
gfx demo
GFX Demo for Arduino and the ESP-IDF
Stars: ✭ 63 (+231.58%)
Mutual labels:  i2c
motor-hat
Node Module to control Adafruits MotorHAT for the RaspberryPi
Stars: ✭ 28 (+47.37%)
Mutual labels:  raspberry-pi-3
Linux-System-Info-Webpage
Material Design Dashboard for Linux System Info. Great for RPi and other linux Distros
Stars: ✭ 19 (+0%)
Mutual labels:  raspberry-pi-3
Realtek-USB-Wireless-Adapter-Drivers
Realtek USB Wireless Adapter Drivers [0bda:f179] (Kernel 4.15.x ~ 5.9.x)
Stars: ✭ 34 (+78.95%)
Mutual labels:  raspberry-pi-3
MyIoT
[MyIoT] A start with personal server for home automation
Stars: ✭ 14 (-26.32%)
Mutual labels:  raspberry-pi-3
aprenda-python
Aprendizado, dicas e projetos sobre Python
Stars: ✭ 22 (+15.79%)
Mutual labels:  raspberry-pi-3
i2c-swift-example
Use I2C bus device with Swift
Stars: ✭ 19 (+0%)
Mutual labels:  i2c
adafruit-i2c-pwm-driver
Node.js implementation for the Adafruit 16-Channel 12-bit PWM/Servo Driver
Stars: ✭ 25 (+31.58%)
Mutual labels:  i2c
MMM-OpenmapWeather
This module loads current weather as images on Magic Mirror
Stars: ✭ 18 (-5.26%)
Mutual labels:  raspberry-pi-3

SwiftySHT20

A Swift library for the I2C SHT20 Humidity and Temperature Sensor.

Summary

This is a SwiftyGPIO based library for controlling the SHT20 Humidity and Temperature sensor.

You will be able to read via I2C the sensor's humidity and temperatures values, its internal User Register data, write different configuration to the User Register, and soft reset the device.

For more information regarding the sensor's functionality, you can consult its datasheet.

Hardware Details

The sensor should be powered using 3.3 V.

The I2C pins on the RaspberryPi (pin 3 SDA, pin 5 SCL) need to be enabled via raspi-config before you can use them (restart required), and by enabling the I2C pins you will lose the ability to use the pins as standard GPIOs.

Supported Boards

Every board supported by SwiftyGPIO: RaspberryPis, BeagleBones, C.H.I.P., etc...

To use this library, you'll need a Linux ARM board running Swift 4.x 🚗.

The example below will use a Raspberry Pi 3B+ board, but you can easily modify the example to use one of the other supported boards. A full working demo project for the RaspberryPi3B+ is available in the Example directory.

Installation

First of all, makes sure your board is running Swift 4.x ⚠️!

Since Swift 4.x supports Swift Package Manager, you only need to add SwiftySHT20 as a dependency in your project's Package.swift file:

let package = Package(
    name: "MyProject",
    dependencies: [
        .package(url: "https://github.com/samco182/SwiftySHT20", from: "1.0.0"),
    ]
    targets: [
        .target(
            name: "MyProject", 
            dependencies: ["SwiftySHT20"]),
    ]
)

Then run swift package update to install the dependency.

Usage

The first thing is to initialize an instance of SwiftySHT20. Once you have your sht20 object, you can obtain the sensor's humidity and temperature readings:

import SwiftySHT20

// You can also initialize the object with SwiftySHT20() which defaults to .RaspberryPi3
let sht20 = SwiftySHT20(for: .RaspberryPi3) 

if sht20.isDeviceReachable() {
    let temperature = sht20.readTemperature()
    let humidity = sht20.readHumidity()

    print(String(format: "Temperature: %.2f °C, ", temperature.cValue))
    print(String(format: "Humidity: %.2f", humidity.value)+"%\n\n")
}

If you want to read the sensor's User Register or modify any of its configurable values, you can easily do it by using the following functions:

// Reading User Register
func readUserRegister() -> UserRegister

// Modifying User Register
func setResolution(_ resolution: UserRegisterMask.Resolution)
func enableOnChipHeater(_ isEnabled: Bool)
func activateEndOfBatteryAlert(_ isActive: Bool)

If by any chance you want to reset the sensor, you can easily do it by running the following function without removing the power source:

func softReset()

Note 🔍

If you encounter some problems connecting to the sensor, or sht20.isDeviceReachable() keeps returning false you could follow this i2c debugging guide.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].