uraimo / SwiftyGPIO

A Swift library for hardware projects on Linux/ARM boards with support for GPIOs/SPI/I2C/PWM/UART/1Wire.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading from serial port hangs once I try to interact with GPIO pin

MihaelIsaev opened this issue · comments

Board Type

RaspberryPi4

Operating System

Ubuntu 20.04

Swift Version

Swift 5.3.3 precompiled from swift-arm.com

Description

I use uhf-rfid R2000 reader connected via /dev/ttyUSB0 and I'm continuously reading tags from it.
To connect to R2000 and read tags I use SwiftSerial lib.

The problem is that once I try to interact with GPIO pin

either

SwiftyGPIO.GPIOs(for:.RaspberryPi4)[.P22]!.value = 1

or

SwiftyGPIO.GPIOs(for:.RaspberryPi4)[.P22]!.value = 0

I see that SwiftSerial hangs on POSIX read command.

If I don't interact with GPIO then everything works without any issues.

I tried to call all the commands inside one DispatchQueue with .sync { ... } block, to be sure that they're calls one by one synchronously (like not in parallel), but it doesn't help cause it still hangs.

I also created an issue in SwiftSerial repo

Trying to figure out what's wrong, any help would be appreciated!

Hi, just to be 100% sure and ignore this if you already checked, but can you double check that when you enabled the uart you also disabled the login+kernel messages on the uart port in raspi-config?
Also, running the program with strace could give us more info on what the program is doing after that gpio setting, but the output will be messy.
Other than this, that gpio is just connected to an external device that gives no feedback back to the pi, correct?
And again, I'm just suggesting random thing that could give us more info to debug this :) , have you tried connecting the serial to your pc, using minicom and printing the data you read in a while loop? To see if it stops in this case too?

@uraimo thank you for the response and sorry for the long silence. I tried a lot of things and login+kernel on uart is disabled for sure. External device works pretty well, so the problem is only with hanging gpio on raspberry. A week ago I switched from RPi to ESP32 and here everything works well without and hanging. So I'm giving up with raspberry and its glitches...