Yukon : conflict when using Audio amp + 2 BigMotor modules


I’m trying to use the Audio amp and 2 Bigmotors modules and it does not seem to work. They do work separatley but when not when the 3 re pluged-in. Anyone having this problem ?

The Python script freeze just after the module enable.

Thanks for your help !


— Here’s the script

from pimoroni_yukon import Yukon

from pimoroni_yukon.modules import BigMotorModule
from pimoroni_yukon.timing import ticks_ms, ticks_add
from motor import MotorCluster

import time
import utime
from pimoroni_yukon import SLOT5 as SLOT
from machine import Pin

from pimoroni_yukon import SLOT1 as SLOT_AUDIO
from pimoroni_yukon.modules import AudioAmpModule

# Main
yukon = Yukon()                         # Create a new Yukon object
modules = []                            # A list to store QuadServo module objects created later

# Motors
CURRENT_LIMIT = 0.5                     # The maximum current (in amps) the motors will be driven with
CLUSTER_PIO = 0                         # The PIO system to use (0 or 1) to drive the motor cluster
CLUSTER_SM = 0                          # The State Machines (SM) to use to drive the motor cluster

# Ultrasound
trigger = SLOT.FAST1
echo = SLOT.FAST3

# Sound
I2S_ID = 0                  # The I2S instance to use for audio (only 0 and 1 supported)
WAV_FILE_A = "ahoy.wav"     # The first wave file. Make sure this file is present in the root directory of your Yukon
VOLUME_A = 0.8              # The volume (between 0.0 and 1.0) to play the first file at
amp = AudioAmpModule(I2S_ID)                    # Create an AudioAmpModule object
yukon.register_with_slot(amp, SLOT_AUDIO)

# ultrasound sensor read
def ultra():
   while echo.value() == 0:
       signaloff = utime.ticks_us()
   while echo.value() == 1:
       signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   print("The distance from object is ",distance,"cm")

    # Find out which slots of Yukon have BigMotorModule attached
    for slot in yukon.find_slots_with(BigMotorModule):
        module = BigMotorModule(init_motor=False,       # Create a BigMotorModule object
        yukon.register_with_slot(module, slot)          # Register the BigMotorModule object with the slot
        modules.append(module)                          # Add the object to the module list

    yukon.verify_and_initialise()                   # Verify that BigMotorModules are attached to Yukon, and initialise them

    motors = MotorCluster(CLUSTER_PIO, CLUSTER_SM,
                          pins=[module.motor_pins for module in modules])

    # enableS
    yukon.enable_main_output()                      # Turn on power to the module slots
    amp.enable()                            # Enable the audio amplifier
    for module in modules:
        module.enable()                             # Enable the motor driver on the BigMotorModule

    # play a welcome sound
    SPEED = 0.5
    amp.player.play_wav(WAV_FILE_A)     # Play file A
    amp.set_volume(VOLUME_A)            # Set the volume to play file A at
    # Loop until the BOOT/USER button is pressed
    while not yukon.is_boot_pressed():
        motors.speed(0, SPEED)
        motors.speed(1, -SPEED)
        motors.speed(1, SPEED)
        motors.speed(0, -SPEED)



Yukon developer here. From looking at your code my guess of your issue would be a PIO conflict between the Audio Amp and your MotorCluster. The RP2040 does not have native I2S hardware, but it can be replicated using PIO. I am unsure of the exact PIO instance MicroPython uses for its two supported I2S instances though.

My suggestion would be to try a different PIO and SM for your MotorCluster, or if you are only intending to drive those two motors, use the regular PWM approach as shown in this example (which is good for up to 4 motors) yukon/examples/modules/big_motor/multiple_motors.py at main · pimoroni/yukon · GitHub

Hope that helps. I can also be reached in the Yukon channel on our Discord.

1 Like

Hello! Thanks for your advice, I used the PWM approach and everything is working together now. Thanks again! Best, Olivier