MIDISID Monday: When the Pico's 30 GPIO aren't enough

This is the first of a weekly roundup of progress and problems with this project.  (An introduction is here if you need it.)  Two decent steps forward this week are arpeggios and GPIOs

More GPIOs! 

Being short on Pico GPIO pins felt wrong but I have been struggling.  First of all, of the theoretical ~30 on the RP2040, 'only' 26 are easily available to the user.  This project already uses quite a few for SID addressing and data.  We want to be able to add more SIDs in future and each SID requires a chip select.  There just aren't enough available for the push-switch rotary encoders that I'd like for this project.

Playing with so many settings using a single knob with push switch is fiddly and would spoil what could be a useful and usable module.  Ideally, I'd love four knobs - to play with A/D/S/R at the same time, or filter/PWM  etc.   

Picos are cheap, and the idea of using another to manage the inputs and the display did cross my mind! 

Perhaps the answer lies in the MCP23017 'Port Expander'.  It hooks up to the I2C and so won't use additional pins.  (the OLED display is already hooked up to the I2C, but has a different address to this chap.)  So for no additional pins used on the Pico, you gain 16 GPIO pins, configurable for input or output. (They have 3 address pins, so you can stack up to 8 of these, for 128 extra GPIOs!)

I've mounted the 4 rotary encoders and OLED onto a piece of plastic to help keep them under control while I'm working.  All encoders, their push buttons and the screen will all work off just two i2c pins.

I've spent too much time getting the port expander working. Of course there are libraries but these tend to be for circuit python etc. I'm using C and the closest I could find was one for Raspberry Pi. I couldn't just drop it in but it was a good reference. 

I then had trouble getting interrupts to work. Sometimes it takes longer to understand someone else's code / library and use it properly than it does to understand the data sheet for the chip and write your own code.

Eventually I got the interrupt working but for some reason I don't understand, my program hangs if I try to use i2c from within said interrupt.  (The chip only gives you a signal that something's changed.  As a minimum you have to get the state of all its pins.)  For now I've fallen back on simply polling the MCP's pins.  I have a reasonably tight loop (a benefit of using a multi-core microcontroller).  It feels very good, more responsive than when I had one encoder connected to the Pico's own GPIOs and was using an interrupt.  It's working well, here's a demo:

With those problems solved, it's full steam ahead on getting all four encoders hooked up and more work on the menu system.

Arpeggiator!

On the musical front, arpeggiation is an important part of the SID's distinctive sound.  When you have just three voices on one SID in a Commodore 64, you need to use tricks like this to make the sound fuller and richer.  I've written that feature into the MIDISID code this week. 

In 'general MIDI' mode it'll allow multiple notes on the same channel to be played.  (in this mode one channel is mapped to one voice, so without arpeggiation, notes would be dropped.) 

To use arpeggiation as an effect, all you have to do is write 2, 3 or 4 simultaneous notes in the same midi channel.  Here's a demo:


That's it for this week, thanks for your interest.  I'll tweet fun titbits at various times but stick to the routine of posting full weekly roundups here.

Comments

Popular posts from this blog

Building a Brachiograph

e-ther 2 - Announcement and full rundown of features

Enclosures for MIDISID