uraimo / SwiftyGPIO

A Swift library for hardware projects on Linux/ARM boards with support for GPIOs/SPI/I2C/PWM/UART/1Wire.
MIT License
1.35k stars 135 forks source link

Pi 4 1wire issue #119

Closed gregorFeigel closed 2 years ago

gregorFeigel commented 3 years ago

Board Type

Raspberry PI 4 4GB ram

Operating System

Debian Buster, TwisterOS (on both not working)

Swift Version

Swift version 5.1.5 (swift-5.1.5-RELEASE) prebuild binarys

Description

Im trying to read the value from a DS18b20 sensor. The sensor is connected to pin 4. with: cat /sys/bus/w1/devices/28-00000cb40e9c/w1_slave I receive: c0 01 4b 46 7f ff 10 10 8f : crc=8f YES c0 01 4b 46 7f ff 10 10 8f t=28000 So the sensor is fine.

I tried the 1wire example but it crashes when using .RaspberryPi4 in.

let onewires = SwiftyGPIO.hardware1Wires(for:.RaspberryPi4)! // .RaspberryPi2 
let onewire = onewires[0]

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /home/pi/.../ReadDS18b20swift, line 2 Current stack trace: Illegal instruction

When using .RaspberryPi3 it somehow works, but cant read anything:

["28-00000cb40e9c\n"] Slave: 28-00000cb40e9c


Couldn't open 1-Wire device: /sys/bus/w1/devices/28-00000cb40e9c /w1_slave: No such file or directory

Anny ideas?

uraimo commented 2 years ago

Both issues causing this, missing Pi4 enum and unhandled \n in the 1Wire slaves list, have been resolved with 1754dc31e4d648c6999b3e664d8669d1a87c22eb , i.e. 1.3.9.