The library version 0.0.5 for the DualMCU ONE board enables control of the RGB LED, buzzer, SSD1306 OLED display via I2C, and SD card via SPI.
Project description
DualMCU v0.0.5
The current version of the library is 0.0.5. The library is compatible with the DualMCU ONE board.
Available features:
- Control of the RGB LED.
- Control of the buzzer.
- Control of the SSD1306 OLED display using I2C.
- SDCard SPI support.
Installation
- Open Thonny.
- Go to Tools -> Manage Packages.
- Enter
dualmcu
in the search bar and click Install.
Example of use
- Connect Multi-purpose Shield to DualMCU ONE
- Open Thonny and connect to the DualMCU ONE board.
- Run the following code:
from machine import Pin, PWM
from dualmcu import D5
import time
# Configuración del pin D5 para PWM
buzzer = PWM(Pin(D5))
def play_tone(frequency, duration):
buzzer.freq(frequency)
buzzer.duty_u16(32768) # Configura el duty cycle al 50%
time.sleep(duration)
buzzer.duty_u16(0) # Apaga el buzzer
try:
while True:
# Toca una secuencia de tonos
play_tone(262, 0.5) # Do
time.sleep(0.1)
play_tone(294, 0.5) # Re
time.sleep(0.1)
play_tone(330, 0.5) # Mi
time.sleep(0.1)
play_tone(349, 0.5) # Fa
time.sleep(0.1)
play_tone(392, 0.5) # Sol
time.sleep(0.1)
play_tone(440, 0.5) # La
time.sleep(0.1)
play_tone(494, 0.5) # Si
time.sleep(0.1)
play_tone(523, 0.5) # Do
time.sleep(0.1)
except KeyboardInterrupt:
# Detener el buzzer cuando se interrumpe el programa
buzzer.deinit()
- You should hear a sequence of tones.
Examples of use of the RGB LED and the buzzer
The following example shows how to use the RGB LED and the buzzer of the Multi-purpose Shield.
from dualmcu import D5, D9, D10, D11, Shield
# Crear una instancia de Shield
my_shield = Shield(pin_red=D9, pin_green=D10, pin_blue=D11, pin_buzzer=D5)
try:
while True:
# Toca una secuencia de tonos y cambia los colores del LED
my_shield.set_led('red')
my_shield.play_tone(262, 0.5) # Do
time.sleep(0.1)
my_shield.set_led('green')
my_shield.play_tone(294, 0.5) # Re
time.sleep(0.1)
my_shield.set_led('blue')
my_shield.play_tone(330, 0.5) # Mi
time.sleep(0.1)
my_shield.set_led('yellow')
my_shield.play_tone(349, 0.5) # Fa
time.sleep(0.1)
my_shield.set_led('cyan')
my_shield.play_tone(392, 0.5) # Sol
time.sleep(0.1)
my_shield.set_led('magenta')
my_shield.play_tone(440, 0.5) # La
time.sleep(0.1)
my_shield.set_led('white')
my_shield.play_tone(494, 0.5) # Si
time.sleep(0.1)
my_shield.set_led('off')
my_shield.play_tone(523, 0.5) # Do
time.sleep(0.1)
except KeyboardInterrupt:
# Detener el shield cuando se interrumpe el programa
my_shield.deinit()
Code example I2C
Code example
'''
Unit Electronics 2024
(o_
(o_ //\
(/)_ V_/_
tested code mark
'''
import machine
from dualmcu import SSD1306_I2C
i2c = machine.SoftI2C(scl=machine.Pin(5), sda=machine.Pin(4))
oled = SSD1306_I2C(128, 32, i2c)
oled.fill(1)
oled.show()
oled.fill(0)
oled.show()
oled.text('UNIT', 50, 10)
oled.text('ELECTRONICS', 25, 20)
oled.show()
SDCard SPI example
The following example shows how to use the SDCard SPI support.
import machine
import os
from dualmcu import sdcard
# Initialize SPI interface for the SD card
spi = machine.SPI(2, baudrate=1000000, polarity=0, phase=0, sck=machine.Pin(14), mosi=machine.Pin(15), miso=machine.Pin(2))
# Initialize the SD card
sd = sdcard.SDCard(spi, machine.Pin(13))
# Mount the filesystem
vfs = os.VfsFat(sd)
os.mount(vfs, "/sd")
# List files in the root of the SD card
print("Files in the root of the SD card:")
print(os.listdir("/sd"))
os.umount("/sd")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file dualmcu-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: dualmcu-0.0.5-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efe387bd1299b4722ad3bb2ab81c5579b48e1a54aeeac2f09dbb862d718f72fc |
|
MD5 | 1c377163a58c7e99782f97dba3808b21 |
|
BLAKE2b-256 | 713cba26f00decacf2e2e1b1efea3b73f1aa1ab7a3f125c51669c3550a952d46 |