RS-485 Communication

../../../../_images/rs485_communication.png

Overview

RS-485 communication module, connects the weather station kit (including wind speed and direction), and transmits RS-485 signals to the main controller via serial port.

Technical Specifications

Operating voltage: VCC 3.3V -5V

Module dimensions: 32*48mm

Mounting: 2 plastic building block compatible through-holes

Communication: Serial port, baud rate 4800

Pin Definition

Pin

Definition

GND

Ground

VCC

Power

TX

Serial transmit

RX

Serial receive

Example Code

Weather station code

from mpython import *

from bluebit import WEATHER

w = WEATHER(uart_num=1,pin_tx=Pin.P16,pin_rx=Pin.P15)

import time

def get_wind_dir():
    try:
        direction = w.read_wind_direction()[0]
        if(direction == 0):
            return "N"
        elif(direction == 1):
            return "NE"
        elif(direction == 2):
            return "E"
        elif(direction == 3):
            return "SE"
        elif(direction == 4):
            return "S"
        elif(direction == 5):
            return "SW"
        elif(direction == 6):
            return "W"
        elif(direction == 7):
            return "NW"
    except:
        pass

def get_wind_power(arg):
    try:
        wind_power = w.read_wind_power()
        if(arg==0):
            return wind_power[0]
        else:
            return wind_power[1]
    except:
        pass

def get_rainfall():
    try:
        rainfall = w.read_rainfall()
        return rainfall
    except:
        pass
while True:
    print('Wind direction: ' + str(get_wind_dir()))
    time.sleep(0.5)
    print('Wind speed: ' + str(get_wind_power(0)))
    time.sleep(0.5)
    print('Rainfall: ' + str(get_rainfall()))
    print('===')
    time.sleep(1)
../../../../_images/weather_station.png