abook
Posts: 6
Joined: Thu Nov 30, 2017 10:48 am

RS-485 and GPIO

Tue Dec 05, 2017 11:10 am

Hello. I can not figure out how to send data on the RS-485 through GPIO. Before that, I worked through a computer, I used python library pySerial, I chose the right COM-Port and sent the data using function WRITE, but how to work with the pins? Is there a special library for working with pins where you need to select two pins and say which one to read and which one to send data to? Can someone have an example of the working code on the python? Presumably the adapter UART-RS-485 will be like this https://pinout.xyz/pinout/rs485_pi# . The description says that pins 14 and 15 are used. Only they can be used for RS-485? I apologize if I ask some trivial things, but before that I did not work with the controllers and I do not know the specifics. I will be very grateful for the help.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: RS-485 and GPIO

Tue Dec 05, 2017 11:31 am

Many of the GPIO pins have a secondary function. On the Pi pins 8 and 10 (BCM 15 and 15) can either act as 'standard' on/off GPIO pins or they can be reassigned to be used as a serial port (this is their default state).
Pins 14 and 15 can be connected to the UART inside the 'chip' which is some specialised hardware specifically designed for serial communication.
You could use any other pins to send or receive data but you'd have to rely on software to replace the specialised functions that the UART performs.

The python serial library can write/read serial data on these pins just like any other serial port. On raspbian you should use '/dev/serial0' as the port name.
You just connect the TX and RX pins to your RS-485 converter.

There is more info about the Pi's serial ports here
https://www.raspberrypi.org/documentati ... on/uart.md
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

abook
Posts: 6
Joined: Thu Nov 30, 2017 10:48 am

Re: RS-485 and GPIO

Tue Dec 05, 2017 11:58 am

Thanks a lot for your answer))

Return to “General discussion”