Skip to content
This repository was archived by the owner on Aug 23, 2024. It is now read-only.

Latest commit

 

History

History
59 lines (38 loc) · 1.83 KB

File metadata and controls

59 lines (38 loc) · 1.83 KB

Using the U097 "I2C 4 relays" (Grove connector) with MicroPython

The "U097: 4-Relay Unit" from M5Stack is a 4 relays module that can be controlled via I2C. This unit fits a Grove connector to ease the connection on Grove's compatible plateforms.

U097: 4 relays unit

It is possible to add Grove to your favorit plateform by wiring your own connector with a Grove to Pin (or Grove to Pad).

Remarks: This driver is sourced from esp8266-upy GitHub maintained by MCHobby

Wire

Wire to Pico

U097 to pico

Wire to M5Stack Core

U097 to core

Test

First, copy the library lib/m4relay.py on your plateform. Then you can execute the examples scripts.

The test_simple.py script (visible here below) explains hos to contole the U097 relays.

from machine import I2C
from m4relay import Relays
from time import sleep

# Pico - I2C(0) - sda=GP8, scl=GP9
i2c = I2C(0)
# M5Stack core
# i2c = I2C( sda=Pin(21), scl=Pin(22) )

rel = Relays(i2c)

# The LED is controled with the Relay

# Switch all relay ON
for i in range(4): # from 1 to 3
	rel.relay( i, True )
	sleep( 1 )

# Switch All relay OFF
for i in range(4): # from 1 to 3
	rel.relay( i, False )
	sleep( 1 )

The test_async.py script would allows to control :

  • the LEDs with Relays.led(index=0..3, state=True/False) and
  • the Relays with Relays.relay(index=0..3, state=True/False)

... independantly from each other when LEDs and Relays are desynchronized with ( Relays.synchronize( False ) ).