Showing posts with label Adafruit. Show all posts
Showing posts with label Adafruit. Show all posts

Sunday, 24 November 2024

Adafruit RP2040 Prop-Maker Feather - Staser sound effect

This uses the Prop-Maker Feather'’s I2S audio amplifier to generate a sound effect, in this case a Gallifreyan Staser sound effect.





For testing purposes, the sound is triggered by the use of the Boot button on the board (the Boot button on the Prop-Maker Feather is connected to GPIO7 and named board.Button in CircuitPython)

For use as a prop, the trigger would be wired to the Button terminal and the Ground terminal shared with the NeoPixel.

Getting your sound effect.

The Prop-Maker Feather requires a PCM 16-bit Mono WAV files at a sample rate of 22KHz. This can be created using Audicity by following the Adafruit instructions.

Code

# Staser sound effect
import board
import digitalio
import time
import neopixel
import random
import audiocore
import audiobusio
import audiomixer
import pwmio
import keypad

keys = keypad.Keys((board.BUTTON,), value_when_pressed=False, pull=True)

# One of the features of the prop-maker is that the Neopixel
# (and the amplifier and the speaker) can be switched on and off
external_power = digitalio.DigitalInOut(board.EXTERNAL_POWER)
external_power.direction = digitalio.Direction.OUTPUT
external_power.value = True

audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)

def play(filename, audio):
    # i2s playback
    wave_file = open(filename, "rb")
    wave = audiocore.WaveFile(wave_file)
    mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1,
                         bits_per_sample=16, samples_signed=True)
    audio.play(mixer)
    mixer.voice[0].play(wave, loop=False)
    mixer.voice[0].level = 0.5
    print("Fire")
    wave_file

while True:
    event = keys.events.get()
    # event will be None if nothing has happened.
    if event:
        if event.pressed:
            play("staser.wav",audio)

print("Done")

References

https://learn.adafruit.com/adafruit-rp2040-prop-maker-feather/overview

https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython/keys-one-key-per-pin

https://learn.adafruit.com/microcontroller-compatible-audio-file-conversion

https://learn.adafruit.com/lightsaber-rp2040/code-the-lightsaber


Adafruit RP2040 Prop-Maker Feather

The Adafruit RP2040 Prop-Maker Feather is an Adafruit Feather format board using the Raspberry Pi RP2040 processor with 8MB of QSPI FLASH with a terminal block connector at one end, QWIC/STEMMA connector, Servo connector and adjacent to the USB type C connector a battery connector (with charging capability). It can be used without any soldering.


There is a slightly more in-depth discussion here.

The terminal block has three connections for the NeoPixels (5V, ground and data), two for a 4-8 ohm speaker and one for a button.

Assembly

This set up is going to use a 500mm strip of 332 LED per metre ultra dense strip.

It is supplied with a female connector and a matching male connector with wires to connect to the Feather’s terminals.

Unfortunately, due to not completely comprehending the operation of the NeoPixel driver, I went through a number of iterations on connection, including removing the connector on the strip before finally realising that the NeoPixel driver is by default OFF, and a pin needs to be set to make it (and the speaker driver) live. Once that was set and the wires appropriately connected everything was fine.

Installation

CircuitPython is derived from MicroPython and makes the device appear as a USB storage device on the host computer.

This means that any editor can be used to edit the CircuitPython source as long as when it saves, it saves everything to the device.

I use a slightly different method, I have a simple Visual Studio program that I use to copy all the required files to the device - and develop using Visual Studio Code. This means that there is always a copy of the code on the laptop in the event that the device becomes unreadable.

The alternative is to use an IDE like MU.

Download the latest version of CircuitPython for the board from the CircuitPython site.

Connect the Prop-Maker Feather to the computer with a known good data (not charge only cable).

The Prop-Maker Feather has a Reset and a Boot Select button. This makes entering the Bootloader a lot easier tan having to unplu and plug the device in while holding down a tiny button.

Hold down the BOOT button and while continuing to hold it, press and release the reset button. Keep holding the BOOT button until a RPI-RP2 drive on the computer.

Copy and paste the UF2 file into the drive. When it has finished copying, the Feather will reboot.

Coding

This program repeatedly through runs the NeoPixel strip through a number of colours. The onboard LED is flashed during each cycle.

# Imports

import board

import digitalio

import time

import neopixel


# Use the builtin LED as a pulse

led = digitalio.DigitalInOut(board.LED)

led.direction = digitalio.Direction.OUTPUT


# Set a list of colour combinations

COLORS = (

    (255,   0,   0),

    (  0, 255,   0),

    (  0,   0, 255),

    (255, 255,   0),

    (255,   0, 255),

    (  0, 255, 255),

)

# Set up Neopixels

# This is for a 0.5m Ultra-dense RGB Micro LED Strip with 332 LEDs per metre

num_pixels = 165

pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels, auto_write=True)

pixels.brightness = 0.02

# One of the features of the prop-maker is that the Neopixel 

# (and the amplifier and the speaker) can be switched on and off 

external_power = digitalio.DigitalInOut(board.EXTERNAL_POWER)

external_power.direction = digitalio.Direction.OUTPUT

external_power.value = True


# Loop indefinitely

while True:

    # Loop through the colour list

    for color in COLORS:

        # Set the built in LED on

        led.value = True

        time.sleep(0.5)

        # Set each pixel in turn

        for i in range(num_pixels):

            pixels[i] = color

        pixels.show()

        # Set the built in LED off

        led.value = False

        time.sleep(0.5)

Here is the device in action.



References

https://shop.pimoroni.com/products/adafruit-rp2040-prop-maker-feather-with-i2s-audio-amplifier?variant=41128910454867

https://shop.pimoroni.com/products/neon-like-rgb-micro-led-strip?variant=39395564585043

https://circuitpython.org/board/adafruit_feather_rp2040_prop_maker/

https://circuitpython.org/libraries

https://learn.adafruit.com/adafruit-rp2040-prop-maker-feather/overview

https://learn.adafruit.com/lightsaber-rp2040/code-the-lightsaber



Sunday, 24 December 2023

Adafruit RP2040 Prop-Maker Feather board

 The Adafruit RP2040 Prop-Maker Feather combines the RP2040 processor with a driver for Neopixels, QT Stemma socket, speaker and a battery charger socket.

The board uses a USB-C connector. 
It has a six screw terminals for the three leads for the Neopixels, two for the speaker and one for a button. 
There is a three pin connector for a servo.
The battery connection is top left. It is important to note that this board includes a charging circuit so only use chargeable LiPo batteries or follow the instructions to isolate the charging circuit.


It is important to note that as a power saving feature the Neopixel driver, the servo and the speaker amplifier are only powered when the GPIO23 pin is high (I spent a while trying to find out why the Neopixels were not lighting up until I remembered).

Here is the board operating a Neopixel strip. 


Code to follow.

ADAFRUIT Metro RP2040 Arduino UNO format microcontroller.

 The Adafruit Metro RP2040 takes the Arduino format and adds the Raspberry Pi RP2040.

In addition to the normal UNO I/O, there is a micro-SD socket and Stemma QT socket.


Sunday, 25 December 2022

Adafruit QT Py RP2040

Introduction

The Adafruit QT Py is a range of diminutive development boards. The QT Py pinout and shape is Seeed Xiao compatible and has castellated pads to allow it to be soldered to a PCB (note, some boards have components on the bottom of the board so will require a cut-out - this is one of them).

The boards have a QWIIC socket. It also has an RGB Neopixel.

Adafruit have released a version using the Raspberry Pi RP2040 processor (which requires a double-sided board to fit all the bits in the format).

It is quite a lot smaller than the Raspberry Pi PICO.
As you can see, the board, unlike the PICO is double sided. To solder it to another board, quite substantial cut outs would be required in the other board.

The QWIIC socket allows suitable I2C breakout boards to be connected without soldering. In this case a cable connected to the QT Py is connected to a PIMORONI BreakOut Garden adaptor (with a 1.12" OLED display).

Adafruit recommend CircuitPython but there is also an official MIcroPython port.However, there is little or no documentation on programming the board beyond that for a vanilla PICO.

Installing MicroPython

Download the UF2 file from the MicroPython site. If you are downloading onto a Windows machine, right click on the downloaded file, select Properties and Unblock 

Plug a USB A to USB C data cable into the board and the computer.

Hold the BOOTSEL button and press the RESET button.

The board will appear as a drive.

Copy the UF2 file to the board.

Once it has finished downloading, the board will restart.

Blink

The QT Py RP2040 has a Neopixel rather than the traditional LED on pin 13. This means that the normal Blink program does not work.

The CircuitPython UF2 specifically for the board has built in functions to operate the RGB Neopixel, and the board library has constants for the Neopixel pin.

I was unable to locate a Micropython example for the Blink program using a Neopixel.

Checking the pin-out https://learn.adafruit.com/assets/107201 shows that the RGB Neopixel is on pin 12, and the power for the Neopixel is on pin 11. To make the board more power efficient (useful for a battery powered application), the Neopixel can be unpowered in addition to not displaying a colour.

This requires both the Neopixel pin to be passed to the Neopixel constructor, and the power pin set to on.

Code

import time
import machine
import neopixel
# Set up a single Neopixel
pin = machine.Pin(12, machine.Pin.OUT)
pixel = neopixel.NeoPixel(pin, 1)
pixel.brightness = 0.3
# Set the power pin high to activate the Neopixel
power_pin = machine.Pin(11, machine.Pin.OUT)
power_pin.on()
def set_pixel(rgb):
    # Set the first pixel to rgb
    pixel[0] = rgb
    # Write the setting to the Neopixel
    pixel.write()
while True:
    # Set the first pixel to Red
    set_pixel((255, 0, 0))
    time.sleep(0.5)
    # Set the first pixel to off
    set_pixel((0, 0, 0))
    time.sleep(0.5)
    print("Blink!")


References

https://micropython.org/download/ADAFRUIT_QTPY_RP2040/

https://www.adafruit.com/category/1005

https://learn.adafruit.com/adafruit-qt-py/overview

https://shop.pimoroni.com/products/adafruit-qt-py-rp2040?variant=39341945487443

https://learn.adafruit.com/adafruit-qt-py-2040/blink

https://docs.micropython.org/en/latest/rp2/quickref.html#neopixel-and-apa106-driver

https://docs.micropython.org/en/latest/rp2/quickref.html#i2s-bus


 

Tuesday, 20 December 2022

Adafruit MacroPad RP2040 Starter Kit

Adafruit MacroPad RP2040 contains a built in Raspberry Pi 2040 processor, 3x4 Neopixel RGB keypad, a rotary encoder and a STEMMA QT connector.

The rotary encoder also functions as the Pico's BOOTSEL button.
The RP2040 processor is just to the left of the display cable. Originally I thought this used a separate Raspberry Pi Pico board and so left this until I could get a Pico W with pre-soldered headers. Once I managed to buy one, I discovered it was complete.
There is  a QWIIC/STEMMA I2C on the right hand side of the board, plus a RESET button just above it. Below the first row of keys is a buzzer.
The Starter Kit has a decorated back plate, one side includes Voyager artwork.
The other side has artwork resembling the Apollo flight computer.
There is a reinforcing plate.
The kit includes four screws to hold the boards together, plus four feet and a rotary knob.



The device is programmable either using CircuitPython or Arduino.

Friday, 21 May 2021

Adafruit Trinkey

The Adafruit Trinkey is a tiny USB key format microcontroller with four Neopixels and an M0 processor.

 


The end opposite the USB contact can function as two touch sensitive buttons.

I bought mine from Pimoroni.

When plugged into the USB port of my Debian laptop, it failed to register. I thought it might be an issue with connecting to an elderly ex-Windows laptop. So I tried it on a Windows laptop. Still it did not register. The Neopixels worked, and the touch sensors started and stopped the display.

However, when set to Boot Mode (double press on the reboot button) it registered as a USB device.

I then downloaded the latest version of CircuitPython from https://circuitpython.org/board/neopixel_trinkey_m0/

This was then copied to the device which then causes the device to restart. The device now appeared as a USB memory device.

Programming

CircuitPython devices are simple to program, appearing as a USB memory device. Saving a new file to the device causes it to restart. Generally the file code.py is executed on starting.

Adafruit's recommendation is to use the Mu editor. This writes directly to the CircuitPython device. It does however mean you need to be particularly careful that you have a copy of the code somewhere.

To make my life easier, I put together a simple Visual Studio program to copy specific code.py files from specific folders. I then edited the code using Visual Studio Code.

Example code

The example code is derived from the code from the Neo Trinkey Zoom Short Cut project (see references)

import time
import board
import neopixel

#  setup for onboard neopixels
pixel_pin = board.NEOPIXEL
num_pixels = 4

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.05, auto_write=False)

def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if pos < 0 or pos > 255:
        return (0, 0, 0)
    if pos < 85:
        return (255 - pos * 3, pos * 3, 0)
    if pos < 170:
        pos -= 85
        return (0, 255 - pos * 3, pos * 3)
    pos -= 170
    return (pos * 3, 0, 255 - pos * 3)

def rainbow_cycle(wait):
    for j in range(255):
        for i in range(num_pixels):
            rc_index = (i * 256 // num_pixels) + j
            pixels[i] = wheel(rc_index & 255)
        pixels.show()
        time.sleep(wait)

while True:
    rainbow_cycle(0.001)

References

https://www.adafruit.com/product/4870
https://circuitpython.org/board/neopixel_trinkey_m0/

Wednesday, 25 December 2019

Merry Christmas

At this festive time of year, here is a flashing Christmas ornament.


This is an Adafruit Circuit Playground Express in an enclosure powered by a USB power block.

Wednesday, 19 September 2018

CircuitPython: writing to the file system.

Circuitpython has a very easy way of uploading code and data to the microcontroller, the microcontroller's storage appears as a USB storage device on the host's operating system. To move code and data to the microcontroller, you simply copy everything to the volume.

Unfortunately this does mean that, by default, Circuitpython cannot write data to its own storage (it is read only) and so it cannot write data that will visible to the host.

However it is possible to change that in the optional boot.py code file.

The boot.py file is only run on the first boot of the device (power up) and not when REPL is restarted or when you save a file. The microcontroller needs to be Ejected as a USB device and the reset button pressed.

Note: When you change it from read only, it is not possible to update the code on the microcontroller - including the boot.py.

The boot.py file needs to contain the following code:
import storage
storage.remount("/", False)

The first line imports the storage module, allowing access to OS functions.
The second line remounts the storage with readonly set to false.

The boot.py file can be "removed" via REPL (Read - Evaluate - Print - Loop). This is very like a command line interface combined with an (xPython) interpretor.

To access REPL on Mu:
Click on the Serial button on the ribbon. This will open a serial connection to the connected microcontroller.
Press CTRL-C (keyboard interrupt) to stop CircuitPython from continuing with whatever it is doing.
Press any key (as instructed).
Use the REPL.

To remove the boot.py, you need to rename the file via REPL:
import os
os.listdir("/")
os.rename("/boot.py", "/boot.bak")

The first line imports the storage module, allowing access to OS functions.
The second lists the contents of the root of the microcontoller's storage.
The third renames the boot.py file to boot.bak.

The microcontroller needs to be ejected (as a USB device) and the reset button pressed (physically unplugging it after ejecting it will also work).

References

https://codewith.mu/en/tutorials/1.0/repl
https://learn.adafruit.com/cpu-temperature-logging-with-circuit-python/writing-to-the-filesystem
https://circuitpython.readthedocs.io/en/2.x/shared-bindings/storage/__init__.html