I am using a Yukon with 4 big motor modules, 1 regulated servo module, and a prototype module using 2 Fast pins for a uart interface. This all works fine, but I cannot init an encoder on any of the motors without getting an error message explaining there are no resources. I tried the garbage collection advice from the error message but to no avail.
Has anyone encountered this before and how do i find the resource limitations of the Yukon board
Just so you know, I don’t own a Yukon. But I’ll still see if I can help. You may need to post more info? Like when you get the error message, what triggers it for example.
You might even want to post the code your running. Click the preformatted text button, the </> and it will wrap it in code tags to keep the formatting and make it easy to read.
@ZodiusInfuser is the guy to help you out with this.
Hi @rickmini,
I have been on holiday for the past 2 weeks, so have only just seen this.
From what you describe, I assume the error message was this one?
"unable to allocate the hardware resources needed to initialise this Encoder. Try running 'import gc' followed by 'gc.collect()' before creating it"
The hardware resources this is referring to is PIO state machines (there are 8 in total, 4 per PIO unit). Each encoder instance requires its own state machine. This error can therefore appear:
- if you are trying to use the same state machine for multiple purposes
- if you have run a program, stopped, and rerun, but the previous Encoder object is still in memory, hence the garbage collection note.
Given that garbage collecting didn’t work for you, and there are certainly enough state machines for 4 encoders, I suspect your issue is the former.
Can you post your setup code for the four encoders?
Yukon’s resource limitations are primarily those of the RP2040, that being:
- 2x UARTs
- 2x SPI
- 2x I²C
- 16x PWMs
- 8x PIO state machines
The first four of these have fixed pins they can be used on, introducing further limitations.
You can see how some PWMs repeat on this diagram: https://cdn.shopify.com/s/files/1/0174/1800/files/yukon_pinout_diagram.png
There are also specific limitations mentioned in the Notes sections on module pages:
Given your specific selection of modules, the only thing I see you needing to work around is the PWMs, which using a ServoCluster to drive your servos will solve: yukon/examples/modules/quad_servo/all_servos.py at main · pimoroni/yukon · GitHub