{"id":13667147,"url":"https://github.com/samco182/SwiftySHT20","last_synced_at":"2025-04-26T15:32:13.747Z","repository":{"id":63920468,"uuid":"188959287","full_name":"samco182/SwiftySHT20","owner":"samco182","description":":zap: A Swift library for the I2C SHT20 Humidity and Temperature Sensor.","archived":false,"fork":false,"pushed_at":"2020-01-16T01:15:09.000Z","size":29,"stargazers_count":20,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-21T11:58:26.126Z","etag":null,"topics":["humidity-sensor","i2c","iot","library","raspberry-pi","raspberry-pi-3","sht20","sht2x","swift","temperature-sensor"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samco182.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-28T05:22:52.000Z","updated_at":"2022-11-12T18:44:18.000Z","dependencies_parsed_at":"2022-11-29T10:45:18.214Z","dependency_job_id":null,"html_url":"https://github.com/samco182/SwiftySHT20","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samco182%2FSwiftySHT20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samco182%2FSwiftySHT20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samco182%2FSwiftySHT20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samco182%2FSwiftySHT20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samco182","download_url":"https://codeload.github.com/samco182/SwiftySHT20/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251008750,"owners_count":21522169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["humidity-sensor","i2c","iot","library","raspberry-pi","raspberry-pi-3","sht20","sht2x","swift","temperature-sensor"],"created_at":"2024-08-02T07:00:32.636Z","updated_at":"2025-04-26T15:32:13.471Z","avatar_url":"https://github.com/samco182.png","language":"Swift","funding_links":[],"categories":["Sensors"],"sub_categories":["Networking, IoT, Bus Protocols, …"],"readme":"# SwiftySHT20\n\nA Swift library for the I2C SHT20 Humidity and Temperature Sensor.\n\n\u003cp\u003e\n\u003cimg src=\"https://img.shields.io/badge/Architecture%20-ARMv6%20%7C%20%20ARMv7%2F8-red.svg\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/OS-Raspbian%20%7C%20Debian%20%7C%20Ubuntu-yellow.svg\"/\u003e\n\u003ca href=\"https://developer.apple.com/swift\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift-4x-brightgreen.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/samco182/SwiftySHT20/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/Licence-MIT-blue.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cimg src=\"https://media.rs-online.com/t_large/R1237351-01.jpg\" height=\"300\" width=\"300\"\u003e\n\n## Summary\nThis is a [SwiftyGPIO](https://github.com/uraimo/SwiftyGPIO) based library for controlling the SHT20 Humidity and Temperature sensor.\n\nYou 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.\n\nFor more information regarding the sensor's functionality, you can consult its [datasheet](https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/0_Datasheets/Humidity/Sensirion_Humidity_Sensors_SHT20_Datasheet.pdf).\n\n## Hardware Details\nThe sensor should be powered using **3.3 V**.\n\nThe 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.\n\n## Supported Boards\nEvery board supported by [SwiftyGPIO](https://github.com/uraimo/SwiftyGPIO): RaspberryPis, BeagleBones, C.H.I.P., etc...\n\nTo use this library, you'll need a Linux ARM board running [Swift 4.x](https://github.com/uraimo/buildSwiftOnARM) 🚗.\n\nThe 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.\n\n## Installation\nFirst of all, makes sure your board is running **Swift 4.x** ⚠️!\n\nSince Swift 4.x supports Swift Package Manager, you only need to add SwiftySHT20 as a dependency in your project's `Package.swift` file:\n\n```swift\nlet package = Package(\n    name: \"MyProject\",\n    dependencies: [\n        .package(url: \"https://github.com/samco182/SwiftySHT20\", from: \"1.0.0\"),\n    ]\n    targets: [\n        .target(\n            name: \"MyProject\", \n            dependencies: [\"SwiftySHT20\"]),\n    ]\n)\n```\nThen run `swift package update` to install the dependency.\n\n## Usage\nThe 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:\n```swift\nimport SwiftySHT20\n\n// You can also initialize the object with SwiftySHT20() which defaults to .RaspberryPi3\nlet sht20 = SwiftySHT20(for: .RaspberryPi3) \n\nif sht20.isDeviceReachable() {\n    let temperature = sht20.readTemperature()\n    let humidity = sht20.readHumidity()\n\n    print(String(format: \"Temperature: %.2f °C, \", temperature.cValue))\n    print(String(format: \"Humidity: %.2f\", humidity.value)+\"%\\n\\n\")\n}\n```\n\nIf 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:\n```swift\n// Reading User Register\nfunc readUserRegister() -\u003e UserRegister\n\n// Modifying User Register\nfunc setResolution(_ resolution: UserRegisterMask.Resolution)\nfunc enableOnChipHeater(_ isEnabled: Bool)\nfunc activateEndOfBatteryAlert(_ isActive: Bool)\n```\n\nIf by any chance you want to reset the sensor, you can easily do it by running the following function without removing the power source:\n```swift\nfunc softReset()\n```\n### Note 🔍\nIf you encounter some problems connecting to the sensor, or `sht20.isDeviceReachable()` keeps returning `false` you could follow [this i2c debugging guide](https://github.com/uraimo/SwiftyGPIO/blob/master/docs/i2c-debugging.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamco182%2FSwiftySHT20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamco182%2FSwiftySHT20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamco182%2FSwiftySHT20/lists"}