<jupyter_start><jupyter_text>Rpi serial ports* default:   * hardware serial for BT   * miniserial for console   * swap these:   * [Official Documentation](https://www.raspberrypi.org/documentation/configuration/uart.md)   * [Detailed Instructions](https://www.circuits.dk/setup-raspberry-pi-3-gpio-uart/)  1) Remap Serial Ports (BT uses miniuart, Pi header uses main uart)Note: also fix Pi clock frequency for BT to work (havn't done that).<jupyter_code>!tail /boot/config.txt
!ls /dev/serial*<jupyter_output>/dev/serial0  /dev/serial1<jupyter_text>Pi 3, Pi Zero W: serial0->ttyS0 points to GPIO pins 8, 10.So where possible refer to the serial port via it’s alias of “serial0” and your code should work on both Raspberry Pi 3 and other Raspberry Pi’s.<jupyter_code>!ls -l /dev/serial* /dev/ttyS* /dev/ttyA*<jupyter_output>lrwxrwxrwx 1 root root          7 Mar  3 10:02 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root          5 Mar  3 10:02 /dev/serial1 -> ttyS0
crw-rw---- 1 root dialout 204, 64 Mar  3 10:02 /dev/ttyAMA0
crw-rw---- 1 root dialout   4, 64 Mar  3 10:02 /dev/ttyS0<jupyter_text>2) Disable the ConsoleBy default the Raspberry Pi uses the serial port for the “console” login and via a software service called “getty”.If you are using the serial port for anything other than the console you need to disable it. This will be slightly different depending on whether you are running a Raspberry Pi 3 or not.For non Raspberry Pi 3 machines, remember it’s /dev/ttyAMA0 that is linked to the getty (console) service.For Raspberry Pi 3’s the command is referencing /dev/ttyS0:<jupyter_code>!sudo systemctl stop serial-getty@ttyS0.service
!sudo systemctl disable serial-getty@ttyS0.service
# remove 'console=serial0,115200' from `/boot/cmdline.txt`

%cat  /boot/cmdline.txt
!sudo reboot now<jupyter_output><empty_output><jupyter_text>3) Test<jupyter_code>import serial, time

with serial.Serial("/dev/serial0", baudrate=9600, timeout=3.0) as dev:
    while True:
        dev.write(b"Hello world!")
        rcv = dev.read(10)
        print(rcv)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10009624639076034, 'fraction_numerical': 0.0370548604427334, 'mean_word_length': 4.25, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '540576', 'license': 'MIT', 'n_tokens_mistral': 758, 'n_tokens_neox': 696, 'n_words': 237, 'path': 'pi/pi_uart.ipynb', 'repo_name': 'iot49/IoT49', 'size': '2078'}