Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micheltlutz/DHT-SwiftyGPIO
SwiftyGPIO with RaspberryPi + DHT11 Module
https://github.com/micheltlutz/DHT-SwiftyGPIO
dht11 dht22 gpio iot raspberry-pi swift swiftygpio
Last synced: about 1 month ago
JSON representation
SwiftyGPIO with RaspberryPi + DHT11 Module
- Host: GitHub
- URL: https://github.com/micheltlutz/DHT-SwiftyGPIO
- Owner: micheltlutz
- Created: 2019-03-10T15:37:09.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2020-04-10T19:39:11.000Z (over 4 years ago)
- Last Synced: 2024-08-02T07:01:52.376Z (4 months ago)
- Topics: dht11, dht22, gpio, iot, raspberry-pi, swift, swiftygpio
- Language: Swift
- Homepage: https://micheltlutz.me/post/raspberry-pi-dhtswiftygpio
- Size: 85.9 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-embedded-swift - DHT-SwiftyGPIO - SwiftyGPIO with RaspberryPi + DHT11 Module (Sensors / Networking, IoT, Bus Protocols, …)
README
# DHT-SwiftyGPIO
Using Swift to display temperature and humidity of a DHT11 module
## Requirements
Raspberry Pi 2+ or Raspberry Pi 3 Model B
Model DHT11 or DHT22
## Installing Dependencies
To use the provided prebuilt binaries you'll need the install the following dependencies:
```sudo apt install clang libicu-dev libcurl4-nss-dev```
## Starting
[https://github.com/uraimo/SwiftyGPIO](https://github.com/uraimo/SwiftyGPIO)
Download last version swift ARM compatible with your board, see table:
[Build Swift On ARM prebuilt-binaries](https://github.com/uraimo/buildSwiftOnARM#prebuilt-binaries)
and Download
```wget https://github.com/uraimo/buildSwiftOnARM/releases/download/4.2.3/swift-4.2.3-RPi23-RaspbianStretch.tgz```
Unzip the files to a folder of your choice:
For example: /home/michel/swift-4.2.3/
After unzip, export path:
``` export PATH=/home/michel/swift-4.2.3/usr/bin:"${PATH}" ```
Test if everything went right run command:
``` swift --version ```
And the output should be like this:
```
Swift version 4.2.3 (swift-4.2.3-RELEASE)
Target: armv7-unknown-linux-gnueabihf
```# Clone and run project
```$ git clone https://github.com/micheltlutz/DHT-SwiftyGPIO ```
```$ cd DHT-SwiftyGPIO```
```$ swift run ```
Waiting output should be like this:
```Temperatura: 25.0 Humidade: 41.0```
## Reference files
The DHT.swift was based on the project [dhtxx](https://github.com/pj4533/dhtxx) But with modifications
DHT class init allows you to select the sensor type and data conversion by default is used Celcius
### Enums Types
```swift
public enum SupportedSensor {
case dht11, dht22
}public enum ConversionType {
case Fahrenheit, Celsius
}init(pin: GPIO, for sensor: SupportedSensor, conversion: ConversionType = .Celsius) { }
...
```
### Example create module DHT11 Object
```swift
let dht = DHT(pin: gpios[.P4]!, for: .dht11)```
### Issues
Initial reading errors occur due to initial pulse failure
Usually get a good reading within the past 60s, many times more often than that
I hope this project helps start with the creation of IoT projects with Swift
[My Blog Post](https://micheltlutz.me/post/raspberry-pi-dhtswiftygpio)