Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hypriot] Errors on Raspberry Pi 3 B+ #79

Open
AdrianBinDC opened this issue Dec 26, 2018 · 2 comments
Open

[Hypriot] Errors on Raspberry Pi 3 B+ #79

AdrianBinDC opened this issue Dec 26, 2018 · 2 comments

Comments

@AdrianBinDC
Copy link

Board Type

Specify which kind of ARM board you are using, e.g. RaspberryPi3, RaspberryPi1, BBB, etc...
Raspberry Pi 3 B+

Operating System

Which OS are you using? e.g. Ubuntu Mate 16.04, Raspbian, Armbian, etc...
Hypriot 1.9.0

Swift Version

Which Swift version are you using? Did you compile it yourself or did you use prebuilt binaries?
4.1.2 using pre-built binaries

Description

Describe your hardware setup (e.g. board connected to i2c sensor) and describe briefly the issue, specifying the steps needed to reproduce it, if necessary.
I have an LED on the breadboard with a resistor. The ground is connected to P6, the positive is connected to P4 on a Raspberry Pi 3 B+

I've got a project created that compiles. The code in main.swift is as follows:

import Glibc
import SwiftyGPIO

var gp4 = GPIO(name: "P4", id: 4)
gp4.direction = .OUT

repeat {
    gp4.value = (gp4.value == 0) ? 1 : 0
    usleep(150 * 1000)
} while(true)

I also tried declaring gp4 like this:

let gpios = SwiftyGPIO.GPIOs(for: .RaspberryPi3)
var gp4 = gpios[.P4]!

Please list any error message you've receveived during execution.

When gp4 is declared like this:

var gp4 = GPIO(name: "P4", id: 4)
gp4.direction = .OUT

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /home/swift/GPIOTest/.build/checkouts/SwiftyGPIO.git-1189449763/Sources/SwiftyGPIO.swift, line 104
Current stack trace:
Illegal instruction (core dumped)

When gp4 is declared like this:

let gpios = SwiftyGPIO.GPIOs(for: .RaspberryPi3)
var gp4 = gpios[.P4]!

Fatal error: Can't open /dev/mem , use sudo!: file /home/swift/GPIOTest/.build/checkouts/SwiftyGPIO.git-1189449763/Sources/SwiftyGPIO.swift, line 353
Current stack trace:
Illegal instruction (core dumped)

@uraimo
Copy link
Owner

uraimo commented Dec 26, 2018

Hi Adrian, I've never tried Hypriot but it should work.
Where are you running this, directly in Hypriot or in a docker container (gpio tutorial for docker)?
Both samples require that you launch them with root privileges using sudo, and the first should work if /sys/class/gpio/export is available.
The second one should work too if they've imported the required kernel patches from Raspbian, but I'd say it's likely that they've done it.
Can you try again using sudo and maybe with Swift 4.1.3 for Raspbian?

@uraimo uraimo changed the title Errors on Raspberry Pi 3 B+ [Hypriot] Errors on Raspberry Pi 3 B+ Dec 26, 2018
@uraimo
Copy link
Owner

uraimo commented Feb 27, 2019

Oh, and depending on the specific image, GPIO mapping could be disabled by default and could require manual activation, see: https://github.com/futurejones/swift-arm64/issues/2

Adding "iomem=relaxed" to /boot/firmware/cmdline.txt is enough to get around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants