Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteris

Raspberry Pi 3 B+ with MAX485 module


In this post will be shown how to communicate a Raspberry Pi 3 B+ with an M-Duino by RS485 using a MAX 485 module.  


M-Duino / Ardbox family

Raspberry Pi 3 B+

MAX485 module

MAX485 Module

On-board MAX485 chip is a low-power and slew-rate-limited transceiver used for RS485 communication. Adopting half-duplex communication to implement the function of converting TTL level info into RS485 level, it can achieve a maximum transmission rate of 2.5 Mbps. 


Resultado de imagen de max485 pinout

Dependig on RE and DE connection the module works as receiver or transmitter. Connected to VCC transmits data and connected to GND receives data. 

It is a cheap module. You can find lots of 5 unit for less than one euro. 


Raspberry Pi 3 B+ Pinout

Resultado de imagen de raspberry pi 3 b+ pinout

Raspberry Pi to MAX485

Raspberry Pi 3 B+ PinsMAX485 Module Pins

Digital pins GPIO17/27 used to establish the communication type. Receiver or transmitter mode.

MAX485 to M-Duino/Ardbox 

MAX485 Module PinsM-Duino / Ardbox Pin
VCC3.3 V


 Code Python

In this code example we send a character from the PLC to the Raspberry, print it, and answer to the PLC with the same character, that is an "echo". Note that in case of receive data, pin 17 and 27 are disable and enable in case of transmit data.

#!/usr/bin/env python3

' IMPORTANT: remember to add "enable_uart=1" line to /boot/config.txt

from gpiozero import OutputDevice
from time import sleep
from serial import Serial

' RO  <-> GPIO15/RXD
' RE  <-> GPIO17
' DE  <-> GPIO27
' DI  <-> GPIO14/TXD

' VCC <-> 3.3V
' B   <-> RS-485 B
' A   <-> RS-485 A
' GND <-> GND

re = OutputDevice(17)
de = OutputDevice(27)

' enable reception mode

with Serial('/dev/ttyS0', 19200) as s:
	while True:
		' waits for a single character
		rx =

		' print the received character
		print("RX: {0}".format(rx))

		' wait some time before echoing

		' enable transmission mode

		' echo the received character

		' disable transmission mode

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.