1

I first connected two raspberry pi, one is Model 4B(transmitter) and another Model 3 B+(receiver) via Uart. Done all uart enable steps (sudo raspi-config>Interfacing Options>Serial>Serial Interface is enabled). Connected TXD-RXD, RXD-TXD,GND-GND of transmitter and receiver pi respectively. Below is my code

Code in Transmitter Raspberry Pi

import time
import serial
ser = serial.Serial(port='/dev/serial0',baudrate = 9600,
                parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS,timeout=1)
while 1:
      ser.write('Hello \n'.encode())

Code in Receiver Raspberry Pi

import time
import serial
ser=serial.Serial(port='/dev/serial0',baudrate=9600,
              parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,
              bytesize=serial.EIGHTBITS,timeout=1)

while 1:
      x=ser.readline().decode()[:-2]
      print(x)

Output at receiver side:

Hello
Hello 
Hello
Hello
Hello
Hello...

Everything Works fine till here. But on trying same code with model of transmitter raspberry pi changed (from 4B to 3 B+) and receiver side pi same, output is not as expected. Looks like something is being printed but is blank. P.S. Done all uart enabling steps when pi was changed. Not getting Why I am not getting output when uart enbaling steps are done same way, code is the same.

| improve this question | | | | |
  • "Done all uart enable steps" - whatever these may be! This is terrible code, but seeing it does nothing useful it is difficult to suggest improvement. It is a wonder it works at all, but will certainly cause buffer overflow. – Milliways Mar 18 at 10:30
  • Edited my question and added Uart enable steps. – Jashanjot Kaur Mar 18 at 10:40
  • There is no "Enable login shell for harware use" BUT if you enabled serial console any input will be intercepted by console and output will be interspersed with console diagnostics. – Milliways Mar 18 at 10:45
  • @Milliways... Serial Interface has been enabled – Jashanjot Kaur Mar 18 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.