1

I got some trouble with my sample code while trying to use pigpio as software UART implement. I can read from RX pin but write to TX pin became unreadable Those are my code:

#!/usr/bin/python

import pigpio
import time
import sys

TXPin=24
RXPin=18
serialpi = pigpio.pi()
serialpi.set_mode(18, pigpio.INPUT)
serialpi.set_mode(TXPin, pigpio.OUTPUT)

TEXT = 'ATH\n' 
msg = bytearray()
msg.extend(TEXT)
baudrate = int(sys.argv[1])

serialpi.wave_add_new()
serialpi.wave_add_serial(TXPin, baudrate, msg, 8, 8)
wid = serialpi.wave_create()
serialpi.wave_send_once(wid)
serialpi.wave_delete(wid)
serialpi.stop()

And this is the output when I try execute it:

�������������������������������������������������������������������������������������������������������������������������80�80�00�80�80�80�80�80�80�00�80�00�00�80�00�80�80�80�80�00�80�80�80�80�00�00�80�80�80�80������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

RING

NO CARRIER

Appreciate your help and time,

1

It works for me.

ATH\n is written to GPIO24.

You can use piscope to check the transmission.

Alternatively use the following pigs commands (change 9600 to the baud rate you are using).

pigs slro 24 9600 8 # bit bang read serial data from GPIO24

Call your script several times and then

pigs -a slr 24 1000 # read up to 1000 characters of bit bang data

$ pigs slro 24 9600 8
$ pigs slr 24 1000
0
$ ./q.py  9600
$ ./q.py  9600
$ ./q.py  9600
$ ./q.py  9600
$ ./q.py  9600
$ pigs -a slr 24 1000
20 ATH
ATH
ATH
ATH
ATH

I did modify your script slightly to make sure the wave is transmitted before the program is exited.

serialpi.wave_send_once(wid)

while serialpi.wave_tx_busy():
   time.sleep(0.01)

serialpi.wave_delete(wid)
  • Thank you joan, I can also can read from pin 24 but mine cannot display as string like yours: pi@raspberrypi:~ $ pigs -a slr 24 1024 25 \x81\xa1\x0d\x9a\xc1\x81\xa1\x0d\x9a\xc1\x81\xa1\x0d\x9a\xc1\x81\xa1\x0d\x9a\xc1\x81\xa1\x0d\x9a\xc1 – Phuong Tran Jul 13 '16 at 13:08
  • Im using a SIM900A gsm module with tx connect to rpi2 pin 18, rx connect to pin 24. I tried screen /dev/ttyAMA0 9600 with default rpi2 rx tx pins, everything work fine and clear , do I have to do some more convert before pass TEXT into serial? – Phuong Tran Jul 13 '16 at 13:24
  • 1
    Your string doesn't look like ASCII text. Make sure your GSM module uses 3V3 levels. Have you also connected the grounds? – joan Jul 13 '16 at 14:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.