Page 2 of 3

Re: serial data reading with pico

Posted: Wed Jul 20, 2022 3:20 pm
by scruss
filip12241224 wrote:
Tue Jul 19, 2022 5:07 pm
I have a device with rs232 output
What do you know about the device? Does it have a manual or datasheet?

If you don't know what baud rate (bit rate) and how characters are sent (7/8 bits, 1/2 start bits, 1/2 stop bits, No/Even/Odd/Mark/Space parity bit, you're probably going to have to spend some tedious time with a logic analyzer working out the protocol

Re: serial data reading with pico

Posted: Wed Jul 20, 2022 8:14 pm
by karfas
filip12241224 wrote:
Wed Jul 20, 2022 10:24 am
today even the old code returns "none" so i think the connection may be bad
Maybe you should check first if your signal really reaches the UART ?

I usually have a few LEDs soldered to a 100 Ohm resistor in my toolbox. They are a very simple, very low-cost way to detect whether some signal arrives at a specific point in your circuit.

This works well with relatively low transfer speeds (19k2) for RS232, RS485, UART, whatever. You can correlate your actions (e.g. typing in putty) with the short flashes of the LED...

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 2:16 pm
by filip12241224
.

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 2:28 pm
by Roberthh
What's puzzling me is that the loopback test does not work. That is the minimal test case. Until that one does works, is make no sense to connected external data sources.

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 2:40 pm
by Roberthh
So the wiring for loopback should be as in the sketch below:
loopback.jpg
loopback.jpg (148.49 KiB) Viewed 2697 times

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 3:03 pm
by TheSilverBullet
Once the hardware stuff is sorted out, maybe this one will be helpful: 8-)

Code: Select all

import machine
import time

baudratelist = [300*2**i for i in range(8)]
baudratelist.extend([57600*2**i for i in range(2)])
bitlist =[7,8,9]
paritylist = [None,0,1]
stoplist = [1,2]

print(baudratelist)
print(bitlist)
print(paritylist)
print(stoplist)

for baudrate in baudratelist:
    for bits in bitlist:
        for parity in paritylist:
            for stop in stoplist:
                try:
                    u = None
                    u = machine.UART(0, baudrate)
                    u.init(baudrate=baudrate, bits=bits, parity=parity, stop=stop)
                    print(baudrate,bits,parity,stop)
                    for t_ms in range(1000):
                        if u.any():
                            value = u.read(1)
                            if type(value) is bytes:
                                value = ord(value)
                                c = chr(value) if 32 <= value <= 127 else '.'
                                print(f'  {c}  Bin:{value:08b}   Dec:{value:3d}   Hex:{value:02x}')
                        else:
                            time.sleep_ms(1)
                except Exception as e:
                    print(e)
                    if u:
                        u.deinit()

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 3:35 pm
by filip12241224
.

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 3:56 pm
by Roberthh
Good. Now you know it works up to the RS232 side. Next: what is connected to the RS232 side?

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 5:02 pm
by filip12241224
.

Re: serial data reading with pico

Posted: Fri Jul 22, 2022 6:44 pm
by Roberthh
Is the device connected with the RJ11 or the DB9 connector?
Did you check the silent voltage levels at the RS232 side? These should be -5 to -12 V.
Does the device need control signals at a specific level? Like RTS and DTR?