Open gregorFeigel opened 2 years ago
Hi @gregorFeigel Thanks for reporting this issue. I don't have an RPi with me anymore and it's been ages since I have touched this library.
It seems very unusual to me that running a Python script beforehand will make things work on the RPi and therefore not something I can replicate without actual RPi hardware.
If I do get to work with RPis eventually, I will keep this issue at the back of my mind and test this library again.
In the meantime I will still keep this issue open.
Issue description
After successfully compiling and testing the
SwiftSerial
package on my Mac I decided to give it a try on the Pi. Since the one and only USB port is used by my Ethernet dongle and my Arduino-based shield offers a GPIO header with RS323 support, I chose the Pi's miniUART port/dev/ttyAMA0
. In order to be able to use the port I disabled bluetooth (dtoverlay=disable-bt
), removed theconsole=serial0,115200
entry in the/boot/cmdline.txt
file, disabled all bluetooth relevant daemons and rebooted the Pi. The compiled binary ran without crashing, but I didn't get the expected result message. I double and triple checked all the connections with my multimeter but everything was fine. I decided to test the serial connection with the bash cmd from below and everything worked fine. To rule out that the error is coming from a poorly configured operating system, I ran a test using the python script form below and everything worked as expected. A little confused, I re-run the Swift binary and this time everything worked as expected. After rebooting, the swift binary serial communication failed again, so I ran another test with the python script and it worked. Now that I run the Swift binary again, I got it working too. I removed all Swift related stuff, recompiled everything, set up my oscilloscope and logic analyzer, and rebooted the Pi. I connected the probes to the Tx and Rx pin and booted the Pi. No interfering signals, so bluetooth and UART terminal function are properly disabled and not messing up my data. Next, I run the Swift binary and encounter the same transfer issues again, but this time I can see what's going on on the logic analyzer display. It seems like all data sent is received back immediately and sent again and again until an unknown timeout occurs. This unwanted loopback when sending/receiving data only occurs when using the Swift Serial or SwiftyGPIO library. Everything works fine when using bash or python. Running the swift binary after running the python script allows the binary to run without issues until the next reboot. For now I just added a cronjob to run the python script on reboot but that seems like a bad workaround. Running the binary with sudo doesn't help. Images of the logic analyser data below.How can this problem be solved ?
Working environment
Raspberry Pi
Programming languages
Connected Shield
Code Snippets
Swift code
compiled with:
swift build -c release
executed with:/home/pi/workDir/serial_Test/.build/release/serial_Test
Python Code
executed with
python testSerial.py
Shell comand
Arduino
Just a small script replying to the serial input. Sends "Unknown command:$RxData" if the command is not in the Arduinos lookup table.
Photos
Logic Analyser Colors: Red = Rx, Green/Yellow = Tx
Photo 1: This is what the communication should like.
Photo 2: Valid transmission - Tx.
Photo 3: Valid transmission - Rx.
Photo 4: Valid transmission - Rx and Tx line.
Photo 5: INVALID transmission - Rx and Tx line.
Photo 6: INVALID transmission - Logic analyser terminal.