0

I have been using the excellent PIGPIO (http://abyz.me.uk/rpi/pigpio/python.html) to communicate with two RFID readers. One is attached to the inbuilt UART while I have been using PIGPIO to connect to the other one.

It’s the second one I am having problems with. Reading responses is working fine. However sending serial with PIGPIO is not working for me. I can see that data is transmitted but its not ASCII and while I can read it the result is garbage.

Sending ‘Hello world\r\n’ and reading the result with PIOPIO PIGS (‘pigs –a slr 24 1000’after starting pigs with ‘pigs slro 24 9600 8’) gives the result:

13 \x90-aa}\x01r}\x91a!m\x12

The results are consistent over multiple runs, using different pins and when connected to different devices.

The RFID reader is fine – connecting to it via UART works without issues.

The GPIOs tested ok using the GPIO test on the same site.

I have tried it on a P3 and a P2 – both with the same results.

The final piece of information is that creating the wave form with:

serialpi.wave_add_serial(txPin,baudrate,b'Hello world\r\n')

Has exactly the same result as:

serialpi.wave_add_serial(txPin,baudrate, 'Hello world\r\n')

The code I am using to test is below:

import pigpio
import time

baudrate =9600

txPin=24
rxPin=21

serialpi=pigpio.pi()
serialpi.set_mode(rxPin,pigpio.INPUT)
serialpi.set_mode(txPin,pigpio.OUTPUT)

pigpio.exceptions = False
serialpi.bb_serial_read_close(rxPin)
pigpio.exceptions = True

serialpi.bb_serial_read_open(rxPin,baudrate,8)

def Sendline(serialpi):
    serialpi.wave_clear()
    serialpi.wave_add_serial(txPin,baudrate,b'Hello world\r\n')
    wid=serialpi.wave_create()
    serialpi.wave_send_once(wid)
    while serialpi.wave_tx_busy():
        pass
    serialpi.wave_delete(wid)   


Sendline(serialpi) 
print 'sent'
time.sleep(.5)

Currently the PIGPIO txPin(24) is connected to the UART rx pin, however the results are the same if I connect to the RFID reader, the PIGPIO rx or if I leave it floating.

Any help would be appreciated, I am sure I am missing something in the way I am structuring or sending the message.

Thanks in advance Tim

UPDATE: As requested running GPIO monitor.py gives the following results:

pi@raspberrypi:~/Downloads $ sudo python monitor.py

G=15 l=1 d=470
G=24 l=1 d=470
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=230
G=24 l=1 d=230
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=115
G=24 l=1 d=115
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=115
G=24 l=1 d=115
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=235
G=24 l=1 d=235
G=15 l=0 d=240
G=24 l=0 d=240
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=115
G=24 l=0 d=115
G=15 l=1 d=360
G=24 l=1 d=360
G=15 l=0 d=235
G=24 l=0 d=235
G=15 l=1 d=115
G=24 l=1 d=115
G=15 l=0 d=235
G=24 l=0 d=235
G=14 l=1 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=0 d=100
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=420
G=15 l=1 d=350
G=24 l=1 d=350
G=14 l=0 d=205
G=15 l=0 d=240
G=24 l=0 d=240
G=14 l=1 d=105
G=15 l=1 d=115
G=24 l=1 d=115
G=14 l=0 d=130
G=14 l=1 d=105
G=15 l=0 d=235
G=24 l=0 d=235
G=14 l=0 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=1 d=415
G=14 l=0 d=210
G=14 l=1 d=105
G=15 l=0 d=475
G=24 l=0 d=475
G=15 l=1 d=115
G=24 l=1 d=115
G=14 l=0 d=270
G=14 l=1 d=105
G=15 l=0 d=235
G=24 l=0 d=235
G=14 l=0 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=1 d=105
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=0 d=520
G=14 l=1 d=106
G=15 l=1 d=710
G=24 l=1 d=710
G=15 l=0 d=115
G=24 l=0 d=115
G=15 l=1 d=240
G=24 l=1 d=240
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=115
G=24 l=1 d=115
G=15 l=0 d=355
G=24 l=0 d=355
G=14 l=0 d=1224
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=1 d=210
G=14 l=0 d=100
G=15 l=0 d=350
G=24 l=0 d=350
G=15 l=1 d=115
G=24 l=1 d=115
G=14 l=1 d=210
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=0 d=315
G=14 l=1 d=100
G=15 l=0 d=470
G=24 l=0 d=470
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=235
G=24 l=0 d=235
G=15 l=1 d=121
G=24 l=1 d=121
G=15 l=0 d=119
G=24 l=0 d=119
G=14 l=0 d=925
G=14 l=1 d=105
G=15 l=1 d=235
G=24 l=1 d=235
G=14 l=0 d=105
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=105
G=15 l=1 d=235
G=24 l=1 d=235
G=14 l=0 d=520
G=15 l=0 d=350
G=24 l=0 d=350
G=14 l=1 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=355
G=24 l=1 d=355
G=15 l=0 d=235
G=24 l=0 d=235
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=0 d=885
G=14 l=1 d=105
G=14 l=0 d=106
G=15 l=0 d=236
G=24 l=0 d=236
G=15 l=1 d=114
G=24 l=1 d=114
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=414
G=15 l=1 d=350
G=24 l=1 d=350
G=14 l=0 d=210
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=105
G=14 l=0 d=220
G=15 l=1 d=235
G=24 l=1 d=235
G=14 l=1 d=105
G=14 l=0 d=105
G=15 l=0 d=235
G=24 l=0 d=235
G=15 l=1 d=120
G=24 l=1 d=120
G=15 l=0 d=120
G=24 l=0 d=120
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=1 d=415
G=15 l=0 d=115
G=24 l=0 d=115
G=14 l=0 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=1 d=205
G=15 l=0 d=235
G=24 l=0 d=235
G=14 l=0 d=235
G=14 l=1 d=105
G=14 l=0 d=105
G=14 l=1 d=105
G=15 l=1 d=470
G=24 l=1 d=470
G=14 l=0 d=105
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=205
G=15 l=1 d=235
G=24 l=1 d=235
G=14 l=0 d=210
G=15 l=0 d=115
G=24 l=0 d=115
G=14 l=1 d=105
G=15 l=1 d=120
G=24 l=1 d=120
G=14 l=0 d=115
G=15 l=0 d=120
G=24 l=0 d=120
G=14 l=1 d=315
G=14 l=0 d=105
G=15 l=1 d=470
G=24 l=1 d=470
G=14 l=1 d=205
G=14 l=0 d=105
G=14 l=1 d=105
G=14 l=0 d=220
G=14 l=1 d=420
^C
Tidying up
3
  • The actual baud rate appears to be 8333 rather than 9600. This seems to be the same as this issue. To date I have only seen this issue on a Pi3. You say you get it on a Pi2 as well? Try baudrate=11000 in your script to see if that gives you an actual baud rate of 9600.
    – joan
    Feb 28, 2017 at 22:34
  • I cannot thank you enough. I have only tested very quickly and will test properly tomorrow but it would appear that changing baudrate= 11000 has fixed the issue (confirmed with PIG). I will update the Q once I have confirmed. Can I ask how you worked this out? I have been stuck on this for several months :(
    – Tim
    Feb 28, 2017 at 22:52
  • Serial data is sent in bits and the level transitions are multiples of the bit time. For 9600 you expect 1000000/9600 µs per bit so units of 104µs. The timings you gave seemed to be multiples of 120µs, 104/120 too slow. So increasing the speed by 120/104 should get about the right speed. I still don't know the root cause of this problem.
    – joan
    Feb 28, 2017 at 23:14

1 Answer 1

1

That is odd as the code works fine for me.

  1. I copied the script to an original Pi B
  2. connected pin 18 to pin 10 (GPIO 24 to GPIO 15 UART RXD).
  3. set the UART baud rate to 9600 (stty -F /dev/ttyAMA0 9600)
$ for ((;;)); do python q.py; sleep 1; done
sent
Hello world
sent
Hello world
sent
Hello world
sent
^C
3
  • Thank you for the quick response Joan. Today I removed a breakout board I was using, double checked I wasn’t being an idiot and using the wrong pins and then rebuilt my OS, sadly all to no effect - I get exactly the same result. Do you have any other advice as to what I could be doing wrong? I am at a loss. Kind regards Tim
    – Tim
    Feb 27, 2017 at 21:12
  • @Tim Some people have wave timing problems on a Pi3 (waves are used to send bit banged serial data). But I've not heard of any problems on a Pi2. Are you sure you are not playing any audio or anything which is touching PWM/PCM in the background? That could change the clocks. Could you try to capture the serial data with abyz.co.uk/rpi/pigpio/examples.html#Python_monitor_py (just GPIO24) and add a sample to your question?
    – joan
    Feb 27, 2017 at 21:53
  • Thank you again Joan, your help is very much appreciated. Nothing else is running on the Pi. I have run the monitor and added the output (I hope it means more to you than it does to me!)
    – Tim
    Feb 28, 2017 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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