1
0
A collection of my MicroPython tests for cheap TTL-UART to RS485 converters, the ping-pong program requiring 4 converters at all.
Go to file
2024-09-15 19:47:55 +00:00
LICENSE.md Added LICENSE.md file (gpl-3.0) 2024-09-14 23:10:33 +02:00
README.md Fixed typo and completed information in Wiring section in README.md 2024-09-15 19:47:55 +00:00
rs485_pingpong.py Removed unnecessary lines at the end of rs485_pingpong.py 2024-09-14 22:05:12 +00:00
rs485_receive.py Added the programs described in README.md 2024-09-14 23:09:27 +02:00
rs485_send.py Added the programs described in README.md 2024-09-14 23:09:27 +02:00
wiring_breadboard_example.jpg Added image of a sample wiring on a breadboard 2024-09-14 22:00:49 +00:00

micropython-rp2-rs485-examples

What's this?

This is a small collection of some programs I wrote to test the functionality of some cheap TTL-UART to RS485 converters, written in MicroPython

Here's a short list of the different programs and what they do:

  • rs485_send.py: sends a incrementing counter (starting at 0) as an UTF-8 encoded string with \r\n as delimiter over rs485

  • rs485_receive.py: receives utf-8 encoded strings and prints them out as soon as a \n is received.

  • rs485_pingpong.py: this implements a simple ping-pong over two channels (4 converters needed). For more information, see Wiring.

Prerequisites

To be able to run all the examples successfully, you need two MicroPython-enabled microcontrollers (Raspberry Pi Pico 1 tested) and 4 TTL-UART to RS485 converters, with two of them connected to each μController (see Wiring). Also, both microcontrollers should have MicroPython running on them (at time of writing this the latest tested version was 1.23.0).

If you met all these requirements, let's start wiring the parts together!

Wiring

For the (simple) send and receive programs, theres just to devices with MicroPython (rp2 flavor tested) needed, as well as two TTL-UART to RS485 converters, one connected to each of them. For the ping-pong example, you will need two channels (one for sending and one for receiving) for each MicroPython device. When using WaveShares Pico 2-Channel HAT, no wiring (between converters and microcontroller) is needed at all!

Just wire two MicroPython devices as shown below (obviously connect different converters to the different microcontrollers ;)

Converter Pin on converter Pin on Pi Pico1
TTL-UART to RS485 converter 1 VCC 3v3 Out
TTL-UART to RS485 converter 1 GND GND
TTL-UART to RS485 converter 1 DI (driver in) GP0 (UART0 TX)
TTL-UART to RS485 converter 1 RO (receiver out) GP1 (UART0 RX)
TTL-UART to RS485 converter 1 DE3 (driver enable) GP2 (set HIGH/LOW)
TTL-UART to RS485 converter 1 RE3 (receiver enable) GP2 (set HIGH/LOW)
TTL-UART to RS485 converter 22 VCC 3v3 Out
TTL-UART to RS485 converter 22 GND GND
TTL-UART to RS485 converter 22 DI (driver in) GP4 (UART1 TX)
TTL-UART to RS485 converter 22 RO (receiver out) GP5 (UART1 RX)
TTL-UART to RS485 converter 22 DE3 (driver enable) GP3 (set HIGH/LOW)
TTL-UART to RS485 converter 22 RE3 (receiver enable) GP3 (set HIGH/LOW)

[1] as I used the Pico, adjust for your favourite microcontroller (but don't forget also changing the pinout in the programs as well1)

[2] only needed for the ping pong example

[3] as the driver/receiver enable pins respond at opposite logic levels (receive enable turns on receiver output when LOW, while driver enable enables driver output when set HIGH), they can be shortened together and be controlled by only one pin on our microcontroller

Then, connecting the A+, B- and GND wires of the respective converters together (converter 1 of μC1 to converter 1 of μC2, converter 2 of μC1 to converter 2 of μC2), you've just created a simple RS485 bus! Now upload the scripts to both microcontrollers and try what you want to try!

Example wiring on a breadboard, one Pico backed with WaveShares HAT, the other one connected to two MAX485 breakout boards:

This is an example on how to wire two microcontrollers to the converters on a breadboard

License

see LICENSE.md