Python - UCUq

Online demonstrations of UCUq with Python #

Here are a few programs using UCUq to control a simulation of various components connected to an ESP32.

If you haven’t already done so, launch below two applications for the use of the Wokwi simulation (more details here):

Click on the inserts below and observe the result in the simulator. Programs are launched automatically.

You can modify a program directly in the navigator and/or relaunch it with the run button.

Reset #

import ucuq lcd = ucuq.HD44780_I2C(ucuq.SoftI2C(6, 7), 4, 20).backlightOn() oled = ucuq.SSD1306_I2C(128, 64, ucuq.I2C(8,9)).fill(1).show() ring = ucuq.WS2812(20, 8).fill((255,)*3).write() servo = ucuq.PWM(21, freq=50).setNS(500000) sevseg = ucuq.GPIO(2).high() ucuq.PWM(5, freq=500).setNS(0) ucuq.sleep(0.5) lcd.backlightOff() ring.fill([0,0,0]).write() oled.fill(0).show() servo.setNS(1500000) sevseg.low()

GPIO (7-segment display) #

Lights the 7-segment display.

import ucuq ucuq.GPIO(2).high()

SSD1306 (OLED) #

Displays a message on the small OLED display at top left.

import ucuq, datetime ucuq.SSD1306_I2C(128, 64, ucuq.I2C(8, 9))\ .text('Hello, World!', 0, 15)\ .text(f"{datetime.datetime.now().strftime('%d/%m/%Y %H:%M')}", 0, 35)\ .show()

PWM (buzzer) #

Sound emission by the passive buzzer.

FREQ = 440 import ucuq buzzer = ucuq.PWM(5)\ .setFreq(FREQ)\ .setU16(32000) ucuq.sleep(1) buzzer.setU16(0)

WS2812 (RGB LEDs) #

Lights the RGB LED ring and the small attached RGB LED.

# 0 to 255 R = 255 G = 0 B = 255 import ucuq ucuq.WS2812(20, 8).fill([R,G,B]).write()

PWM (servo) #

Servomotor rotation.

ANGLE = 135 # 0 to 180 import ucuq ucuq.PWM(21)\ .setFreq(50)\ .setNS(int(ANGLE * 31000 / 3 + 540000)) # NOTA! 0°: .54 ms; 180°: 2.4 ms

HD44780 (LCD) #

Displays a message on the LC display.

import datetime LINE_1 = "Hello, World!" LINE_2 = f"{datetime.datetime.now().strftime("%d/%m/%Y %H:%M")}" import ucuq lcd = ucuq.HD44780_I2C(ucuq.SoftI2C(6, 7), 4, 20) lcd\ .putString(LINE_1)\ .moveTo(0,1)\ .putString(LINE_2)

For other examples of UCUq use, see here.