WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Enable UART serial communications while mainainting wifi  (Read 1060 times)

Offline eSPee

  • Newbie
  • *
  • Posts: 23
Enable UART serial communications while mainainting wifi
« on: September 20, 2024, 07:54:00 AM »
Hi all,

Can anybody help?
I found a great (silent) stepper motor driver:
TMC2209 V4.0 https://wiki.fysetc.com/Silent2209/#wiring-diagram and i would love to use this python library to run it:
https://github.com/Chr157i4n/TMC2209_Raspberry_Pi especially for enabling the stallguard functionality.

The library requires the serial port to be enabled for UART communication. However i am finding this difficult to get working on the piCore 14.1 & Raspberry Pi Zero w.
In this thread enabling the serial functionality is explained: https://forum.tinycorelinux.net/index.php/topic,24825.0.html

Steps taken so far:
1. In /opt/bootlocal.sh uncommened the line that starts serial console
2. In cmdline.txt changed console to: console=serial0,115200
3. In config.txt added this at the end:

Code: [Select]
[PI0]                                                                         
dtoverlay=disable-bt

When i get at step 3 the Pi losses wifi and i can't connect to it anymore. (It runs headless on wifi)  When step3 is omitted i test the serial functionality with minicom:

Code: [Select]
sudo tce-load -wi minicom
minicom -D /dev/serial0 -b 115200

Which gives me an error:

Code: [Select]
minicom: cannot open /dev/serial0: No such file or directory
Adding
Code: [Select]
enable_uart=1 to config.txt doesn't seem to help either.

Can anybody point me in the right direction to get serial over UART working while mainainting wifi functionality on the raspberry pi zero w?
Many thnx!

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #1 on: September 20, 2024, 08:02:09 AM »
If you want to use the serial port for your program, you need to disable the serial console.

Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #2 on: September 28, 2024, 08:58:06 AM »
Thnx Paul! ;)

The UART is now working. What i did:

1. Added this to config.txt:
Code: [Select]
enable_uart=1
2. Changed the console entry in cmdline.txt to (not sure if this is actual required):
Code: [Select]
serial0,115200
No other changes were made. I tested the UART communications with a USB to TTL adapter (FTD1232).
I can connect by SSH through Wifi and from there send commands to the UART serial port:
Code: [Select]
echo "Hello!" > /dev/ttyS0

Which shows up in the serial port console.

Unfortunately, it is not possible to send commands from the serial port console to the raspberry.

Does anybody know if / how this can be enabled?
« Last Edit: September 28, 2024, 09:03:00 AM by eSPee »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #3 on: September 28, 2024, 09:41:39 AM »
From cmdline, it is only a readonly console.   You need to attach getty to the serial port to be able use it.

I think there is a script called startserialconsole to facilitate this.  But it may need tweaked for your port

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #4 on: September 28, 2024, 11:48:03 AM »
Just looked at the startserialtty script.  It was never updated for the pi4/cm4/pi5   but it should work for the zero

Make sure you have read through this https://www.raspberrypi.com/documentation/computers/configuration.html#configure-uarts

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #5 on: September 28, 2024, 11:53:11 AM »
Just looked at the startserialtty script.  It was never updated for the zero/pi4/cm4/pi5

should be able to just use.
Code: [Select]
/sbin/getty -L serial0 115200 vt100 &

Make sure you have read through this https://www.raspberrypi.com/documentation/computers/configuration.html#configure-uarts

you may need to reference ttyS0 instead of serial0.
« Last Edit: September 28, 2024, 11:57:31 AM by Paul_123 »

Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #6 on: September 29, 2024, 11:50:02 AM »
Hi Paul,

Again thnx for helping. Next weekend I will check if this works ;)

Some other strange think i noticed, with the TMC2209 stepper driver connected to the Pi, the pi won't boot properly.
When i remove the cable from the driver to the pi's UART-Rx it does boot. The Pi is sufficiently powered with 1.5 amps so i don't think it is a powered.
Any ideas how to overcome this issue?

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #7 on: September 29, 2024, 02:07:06 PM »
Is the stepper 3.3 volts?    What powers the stepper?

Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #8 on: October 05, 2024, 10:21:38 AM »
Hi Paul,

The input voltage of the stepper is between 3 to 5.2 volt, so it can't go wrong ;)

Thank you for showing me how to get the serial console working. With this command:
Code: [Select]
/sbin/getty -L ttyS0 115200 vt100 &I can login (username & psswd) from serial and type commands. that's great!


So now the USB to TTL adapter (FTD1232) is working, however i can't get the TMC2209 V4.0 communicating with the pi.
The command:
Code: [Select]
$ ls -l /dev
doens't show me any serial0 -> ttyS0 symlinks, is that right?


Code: [Select]
dmesg | grep ttyshows me:
Code: [Select]
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_headphones=0 snd _bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macad dr=B8:27:EB:12:71:21 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  zswap.compressor=lz4 zswap.z                                        pool=z3fold console=tty1 root=/dev/ram0 rootwait quiet nortc loglevel=3 noembed
[    0.001125] printk: console [tty1] enabled
[    4.233192] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2

Shouldn't the serial0 pop-up here as well?

Maybe my TMC2209 driver UART ports are fried...

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #9 on: October 05, 2024, 10:57:25 AM »
serial0 is an alias created by udev, the kernel only knows the real names.   However, while working on your issue, I noticed the serialx links were not getting created.  This is due to a udev rule issue.  I will fix it in the final 15.0 release.

Uart configuration is really confusing.  You have a Pi ZeroW.  The Primary PL011 UART is assigned to bluetooth, unless you have disabled bluetooth  (Add dtoverlay=disable-bt to your config.txt)

Please read the above linked document at Raspi.  Read the whole thing, noting Primary/secondary uarts, Mini vs PL011 uart, and all of the caviats and configuration options.


Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #10 on: October 06, 2024, 08:02:57 AM »
Hi Paul,

Again, thnx for helping. Reading the document i did try some other settings, however with no result.
Straightly enough (when i just about thinking to just give up) the driver communication worked one time!

Code: [Select]
tc@testpi:~/www/TMC2209$ sudo python3 debug_script_01_uart_connection.py
---
SCRIPT START
---
2024-10-06 11:49:52,192 - TMC2209 0 - INFO - Init
2024-10-06 11:49:52,196 - TMC2209 0 - INFO - GPIO Init finished
2024-10-06 11:49:52,198 - TMC2209 0 - INFO - Init finished
---
---
2024-10-06 11:49:52,219 - TMC2209 0 - INFO - ---
2024-10-06 11:49:52,227 - TMC2209 0 - INFO - TEST UART
2024-10-06 11:49:52,242 - TMC2209 0 - DEBUG - received 12 bytes; 96 bits
2024-10-06 11:49:52,244 - TMC2209 0 - DEBUG - hex: 550006e81b5b30313b33326d
2024-10-06 11:49:52,246 - TMC2209 0 - DEBUG - bin: 010101010000000000000110111010000001101101011011001100000011000100111011001100110011001001101101
2024-10-06 11:49:52,254 - TMC2209 0 - DEBUG - length snd: 4
2024-10-06 11:49:52,262 - TMC2209 0 - DEBUG - length rtn: 12
2024-10-06 11:49:52,268 - TMC2209 0 - DEBUG - complete messages:
2024-10-06 11:49:52,274 - TMC2209 0 - DEBUG - 550006e8
2024-10-06 11:49:52,282 - TMC2209 0 - DEBUG - 550006e81b5b30313b33326d
2024-10-06 11:49:52,288 - TMC2209 0 - DEBUG - just the first 4 bits:
2024-10-06 11:49:52,295 - TMC2209 0 - DEBUG - 550006e8
2024-10-06 11:49:52,301 - TMC2209 0 - DEBUG - 550006e8
2024-10-06 11:49:52,308 - TMC2209 0 - DEBUG - the Raspberry Pi received the sent
                            bits and the answer from the TMC
2024-10-06 11:49:52,317 - TMC2209 0 - DEBUG - the Raspberry Pi received exactly the bits it has send.
                    the first 4 bits are the same
2024-10-06 11:49:52,327 - TMC2209 0 - INFO - ---
2024-10-06 11:49:52,334 - TMC2209 0 - INFO - UART connection: OK
2024-10-06 11:49:52,340 - TMC2209 0 - INFO - ---
---
---
2024-10-06 11:49:52,353 - TMC2209 0 - INFO - Deinit
2024-10-06 11:49:52,359 - TMC2209 0 - INFO - Motor output active: False
2024-10-06 11:49:52,365 - TMC2209 0 - INFO - GPIO cleanup
2024-10-06 11:49:52,373 - TMC2209 0 - INFO - Deinit finished
---
SCRIPT FINISHED
---


a second later it didn't work anymore...  ??? :o

Code: [Select]
tc@testpi:~/www/TMC2209$ sudo python3 debug_script_01_uart_connection.py
---
SCRIPT START
---
2024-10-06 11:50:26,716 - TMC2209 0 - INFO - Init
2024-10-06 11:50:26,725 - TMC2209 0 - INFO - GPIO Init finished
2024-10-06 11:50:26,733 - TMC2209 0 - INFO - Init finished
---
---
2024-10-06 11:50:26,751 - TMC2209 0 - INFO - ---
2024-10-06 11:50:26,758 - TMC2209 0 - INFO - TEST UART
2024-10-06 11:50:26,773 - TMC2209 0 - DEBUG - received 12 bytes; 96 bits
2024-10-06 11:50:26,779 - TMC2209 0 - DEBUG - hex: 6d20306d306d306d306d306d
2024-10-06 11:50:26,787 - TMC2209 0 - DEBUG - bin: 011011010010000000110000011011010011000001101101001100000110110100110000011011010011000001101101
2024-10-06 11:50:26,798 - TMC2209 0 - DEBUG - length snd: 4
2024-10-06 11:50:26,800 - TMC2209 0 - DEBUG - length rtn: 12
2024-10-06 11:50:26,802 - TMC2209 0 - DEBUG - complete messages:
2024-10-06 11:50:26,803 - TMC2209 0 - DEBUG - 550006e8
2024-10-06 11:50:26,805 - TMC2209 0 - DEBUG - 6d20306d306d306d306d306d
2024-10-06 11:50:26,806 - TMC2209 0 - DEBUG - just the first 4 bits:
2024-10-06 11:50:26,808 - TMC2209 0 - DEBUG - 550006e8
2024-10-06 11:50:26,823 - TMC2209 0 - DEBUG - 6d20306d
2024-10-06 11:50:26,830 - TMC2209 0 - DEBUG - the Raspberry Pi received the sent
                            bits and the answer from the TMC
2024-10-06 11:50:26,839 - TMC2209 0 - DEBUG - the Raspberry Pi did not received the bits it has send.
                    the first 4 bits are different
2024-10-06 11:50:26,847 - TMC2209 0 - INFO - ---
2024-10-06 11:50:26,855 - TMC2209 0 - ERROR - UART connection: not OK
2024-10-06 11:50:26,862 - TMC2209 0 - INFO - ---
---
---
2024-10-06 11:50:26,875 - TMC2209 0 - INFO - Deinit
2024-10-06 11:50:26,880 - TMC2209 0 - INFO - Motor output active: False
2024-10-06 11:50:26,886 - TMC2209 0 - INFO - GPIO cleanup
2024-10-06 11:50:26,895 - TMC2209 0 - INFO - Deinit finished
---
SCRIPT FINISHED
---

Could this be caused by a bad UART connection?


Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #11 on: October 06, 2024, 08:48:57 AM »
Or could it be that the ttyAMA0 which i am now using needs an --autologin addition somehow?
When i connect the ttl adapter to the RX & TX GPIO's it does ask for a user & psswd before any commands can be given or received.

Offline eSPee

  • Newbie
  • *
  • Posts: 23
Re: Enable UART serial communications while mainainting wifi
« Reply #12 on: October 06, 2024, 09:22:10 AM »
Running:

Code: [Select]
sudo hexdump -C /dev/ttyAMA0
Confirms that indeed the ttyAMA0 asks for a user & password...

I am now checking this post https://forum.tinycorelinux.net/index.php/topic,21129.0.html to see if this can be resolved somehow. Although i am not sure if this is the actual problem communication with the TMC driver.
Just trail & error approach i am afraid  :-\
« Last Edit: October 06, 2024, 09:44:53 AM by eSPee »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1264
Re: Enable UART serial communications while mainainting wifi
« Reply #13 on: October 06, 2024, 09:58:20 AM »
I think you have some confusion.  If you are using a program to control the driver on the serial line, you cannot have anything else accessing the serial port.  No console, no tty.  Do not reference the serial port on cmdline.txt and do not start a serial tty.  Just add enable_uart=1 to config.txt

Just use a normal ssh session or connect a usb keyboard and display, and run your script.

Offline Stefann

  • Jr. Member
  • **
  • Posts: 78
Re: Enable UART serial communications while mainainting wifi
« Reply #14 on: October 06, 2024, 11:03:25 AM »
oops wrong thread