The Alpha Geek – Geeking Out

CircuitPython

Project #20: CircuitPython – Audio Out WAV – Mk02

——

#DonLucElectronics #DonLuc #METROM0Express #CircuitPython #Sound #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Audio Out WAV

——

Audio Out WAV

——

Audio Out WAV

——

Play a Wave File

You can use any supported wave file you like. CircuitPython supports mono or stereo, at 22 KHz sample rate, or less, and 16-bit WAV format. The METRO M0 Express boards support only mono. The reason for mono is that there’s only one analog output on those boards. The 22 KHz or less because the CircuitPython can’t handle more data than that, and also it will not sound much better, and the DAC output is 10-bit so anything over 16-bit will just take up room without better quality. Since the WAV file must fit on the CircuitPython file system, it must be under 2 MB.

HamletUMk01.wav -> 1316 KB

We’re going to play the wave file for 10 seconds, pause it, wait for a button to be pressed, and then resume the file to play through to the end. Then it loops back to the beginning and starts again. First we create the button object, assign it to pin A1, and set it as an input with a pull-up.

Now we will ask the audio playback system to load the wave data from the file HamletUMk01.wav and finally request that the audio is played through the A0 analog output pin. The audio file is now ready to go, and can be played at any time with play. Inside our loop, we start by playing the file.

DL2112Mk02

1 x Adafruit METRO M0 Express
1 x SparkFun Audio Jack Breakout
1 x Audio Jack 3.5mm
1 x Hamburger Mini Speaker
1 x Tactile Button
1 x 10K potentiometer
1 x Knob
1 x 100uF 16V Electrolytic Capacitors
1 x SparkFun Cerberus USB Cable

Adafruit METRO M0 Express

AUD – Analog A0
BUT – Analog A1
VIN – +3.3V
VIN – +5V
GND – GND

code.py

"""
***** Don Luc Electronics © *****
Software Version Information
Project #20: CircuitPython – Audio Out WAV – Mk02
12-02
DL2112Mk02
code.py
1 x Adafruit METRO M0 Express
1 x SparkFun Audio Jack Breakout
1 x Audio Jack 3.5mm
1 x Hamburger Mini Speaker
1 x Tactile Button
1 x 10K potentiometer
1 x Knob
1 x 100uF 16V Electrolytic Capacitors
1 x SparkFun Cerberus USB Cable
"""
# Module
import time
import board
import digitalio
# audiocore -> WaveFile
from audiocore import WaveFile

try:
    from audioio import AudioOut
except ImportError:
    try:
        from audiopwmio import PWMAudioOut as AudioOut
    except ImportError:
        # Not always supported by every board.
        pass  

# Button A1
button = digitalio.DigitalInOut(board.A1)
button.switch_to_input(pull=digitalio.Pull.UP)

# William Shakespeare - Hamlet
wave_file = open("HamletUMk01.wav", "rb")
wave = WaveFile(wave_file)
# audio -> A0
audio = AudioOut(board.A0)

while True:
    # Play
    audio.play(wave)

    # This allows you to do other things while the audio plays.
    t = time.monotonic()
    # -> 10 second
    while time.monotonic() - t < 10:
        pass

    audio.pause()
    print("Waiting for button press to continue.")
    while button.value:
        pass
    # Resume    
    audio.resume()
    while audio.playing:
        pass
    # Done    
    print("Done")

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc...)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae - 2021 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #20: CircuitPython – Metro M0 Express Blink – Mk01

——

#DonLucElectronics #DonLuc #AdafruitMETROM0Express #CircuitPython #Project #Programming #Electronics #Microcontrollers #Consultant

——

Metro M0 Express Blink

——

Metro M0 Express Blink

——

Metro M0 Express Blink

——

Metro M0 Express Blink

——

Metro is our series of microcontroller boards for use with the Arduino IDE. This new Metro M0 Express board looks a whole lot like our original Metro 328, but with a huge upgrade. Instead of the ATmega328, this Metro features a ATSAMD21G18 chip, an ARM Cortex M0+. It’s our first Metro that is designed for use with CircuitPython. CircuitPython is our beginner-oriented flavor of MicroPython, and as the name hints at, its a small but full-featured version of the popular Python programming language specifically for use with circuitry and electronics.

Not only can you use CircuitPython, but the Metro M0 is also usable in the Arduino IDE.

At the Metro M0’s heart is an ATSAMD21G18 ARM Cortex M0 processor, clocked at 48 MHz and at 3.3V logic, the same one used in the new Arduino Zero. This chip has a whopping 256K of FLASH and 32K of RAM. This chip comes with built in USB so it has USB-to-Serial program and debug capability built in with no need for an FTDI-like chip.

  • Power the METRO with 7-9V polarity protected DC or the micro USB connector to any 5V USB source. The 2.1mm DC jack has an on/off switch next to it so you can turn off your setup easily. The METRO will automagically switch between USB and DC.
  • METRO has 25 GPIO pins, 12 of which are analog in, and one of which is a true analog out. There’s a hardware SPI port, hardware I2C port and hardware UART. Logic level is 3.3V
  • Native USB, there’s no need for a hardware USB to Serial converter as the Metro M0 has built in USB support. When used to act like a serial device, the USB interface can be used by any computer to listen/send data to the METRO, and can also be used to launch and update code via the bootloader. It can also act like a keyboard, mouse or MIDI device as well.
  • Four indicator LEDs and one NeoPixel, on the front edge of the PCB, for easy debugging. One green power LED, two RX/TX LEDs for data being sent over USB, and a red LED connected. Next to the reset button there is an RGB NeoPixel that can be used for any purpose.
  • 2 MB SPI Flash storage chip is included on board. You can use the SPI Flash storage like a very tiny hard drive. When used in Circuit Python, the 2 MB flash acts as storage for all your scripts, libraries and files. When used in Arduino, you can read/write files to it, like a little datalogger or SD card, and then with our helper program, access the files over USB.
  • Easy reprogramming, comes pre-loaded with the UF2 bootloader, which looks like a USB storage key. Simply drag firmware on to program, no special tools or drivers needed. It can be used to load up CircuitPython, PXT/MakeCode or Arduino IDE (it is bossa-compatible)

DL2112Mk01

1 x Adafruit METRO M0 Express

Adafruit METRO M0 Express

VIN – +3.3V
VIN – +5V
GND – GND

code.py

"""
***** Don Luc Electronics © *****
Software Version Information
Project #20: CircuitPython – Metro M0 Express Blink – Mk01
12-01
DL2112Mk01
code.py
1 x Adafruit METRO M0 Express
"""
# Module
import board
import digitalio
import time

# Red LED Connected
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

# Blink
while True:
    led.value = True
    time.sleep(1.5)
    led.value = False
    time.sleep(1.5)

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2021 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Categories
Archives