genuinequality

Download free music MP3s on genuine quality, the world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, The world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, stats, charts, biographies and concerts. stats, charts, biographies and concerts.

Sunday, June 4, 2023

[New post] Arduino PCF8574 MIDI Controller

Site logo image Kevin posted: " This project uses a PCF8574 I2C digital IO expander with an Arduino as a MIDI controller. https://youtu.be/yrNB3riWBH4 Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damag" Simple DIY Electronic Music Projects

Arduino PCF8574 MIDI Controller

Kevin

Jun 4

This project uses a PCF8574 I2C digital IO expander with an Arduino as a MIDI controller.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

  • Arduino MIDI Library
  • Expanding Arduino IO: Interfacing PCF8574 with Arduino

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Arduino Uno
  • One or mode PCF8574 I2C IO expander modules (see photos)
  • Arduino MIDI OUT circuit: see Arduino MIDI Interfaces
  • Breadboard and jumper wires

The Circuit

Additional PCF8574 modules can be added by specifying a different I2C address using the three yellow jumpers on the module.

Here I've configured three modules for addresses 0x22, 0x21, 0x20 respectively:

There are 9 headers for IO connections. The left-most pin is for an interrupt connection back to the microcontroller. I've not used that here. The right-most 8 pins are for IO connections 7 down to 0 respectively.

To use the pins as inputs, just treat them as you would digital inputs in INPUT_PULLUP mode - i.e. they will read HIGH until pulled to GND via a button or other means of making a connection.

The connection to the Arduino uses 5V and GND, plus SDA and SCL either via the dedicated pins on the "digital" side or via A4 and A5 as required.

Finally a MIDI module is connected to the Arduino TX pin - in my case I'm using one of my Arduino MIDI Proto Shields.

The Code

Reading the modules is fairly straight forward - there is a single register at the provided address which when read will give the values of the 8 digital inputs and when written will set the pins as if they were digital outputs.

There are a number of libraries that exist for accessing the PCF8574, but in reality the device requires very little managing, so it is fairly easy to use the Arduino's Wire library directly as follows:

 #include <Wire.h>  #define PCF8574_ADDR  0x20 #define PCF8574_CLOCK 100000  void pcf8574setup() {   Wire.begin();   Wire.setClock(PCF8574_CLOCK); }  uint8_t pcf8574read(int device) {   if (Wire.requestFrom(PCF8574_ADDR+device, 1) != 0) {     return (uint8_t)Wire.read();   } else {     return -1;   } } 

My example code allows a number of devices to be linked together and mapped onto either MIDI Control Change, Program Change or Note messages. There is a structure at the top of the file with one entry per IO pin:

 #define NUM_BTNS (PCF8574_DEVICES*8) #define MB_CC 0 #define MB_PC 1 #define MB_N  2 int midiBtns[NUM_BTNS][2] = { // T, Value T=0 (CC), T=1 (PC), T=2 (NoteOn/Off) MB_PC, 0, MB_PC, 1, MB_PC, 2, MB_PC, 3, MB_PC, 4, MB_PC, 5, MB_PC, 6, MB_PC, 7, MB_N,  60, MB_N,  61, MB_N,  62, MB_N,  63, MB_N,  64, MB_N,  65, MB_N,  66, MB_N,  67, MB_N,  68, MB_N,  69, MB_N,  70, MB_N,  71, MB_N,  72, MB_CC, 80,  // Generic On/Off MB_CC, 81,  // Generic On/Off MB_CC, 82,  // Generic On/Off };  

The first value on each line specifies the type of message, and the second value gives the MIDI value to use as appropriate. The operation is as follows:

  • For MIDI CC messages: button press = send MIDI CC message configured in the table, with value 127; button release = send MIDI CC message with value 0.
  • For MIDI PC messages: button press = send MIDI PC message with configured value.
  • For MIDI Note messages: button press = send NoteOn with configured value and velocity 127; button release = send NoteOff with velocity 0.

The listed table allocates the first 8 IO lines (so expander 0x20) to Program Change messages selecting voices 1 to 8 (in MIDI Program Change messages are 0-indexed); then the next 13 IO lines (so expander 0x21 and some of 0x22) to MIDI notes 60 through 72; finally the last 3 lines (expander 0x22) are set as general purpose MIDI controllers for CC 80, 81 and 82.

In the photo I've used a "stylus touch" module to trigger the eight Program Change messages (only the "white notes" are connected up) and a single button keyboard for the 13 notes. I'm not using the remaining three CC buttons.

Find it on GitHub here.

Closing Thoughts

I wasn't sure what kind of performance I'd get from having to scan the I2C bus, but with three expanders I've not noticed any issues.

A key benefit of this approach is that the buttons are all independently scanned with no matrix required and no ghosting of keypresses possible. If the sound source supports it, then full polyphony is possible!

In princple up to eight of these modules can be used on the same I2C bus. There is also a PCF8575 that apparently has 16 IO channels, so that will be worth a look too.

Another benefit of course is that almost all of the Arduino's IO pins (only D0/D1 are used for MIDI and A4/A5 for I2C) are available for doing other things too.

Kevin

Comment
Like
Tip icon image You can also reply to this email to leave a comment.

Unsubscribe to no longer receive posts from Simple DIY Electronic Music Projects.
Change your email settings at manage subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
https://diyelectromusic.wordpress.com/2023/06/04/arduino-pcf8574-midi-controller/

WordPress.com and Jetpack Logos

Get the Jetpack app to use Reader anywhere, anytime

Follow your favorite sites, save posts to read later, and get real-time notifications for likes and comments.

Download Jetpack on Google Play Download Jetpack from the App Store
WordPress.com on Twitter WordPress.com on Facebook WordPress.com on Instagram WordPress.com on YouTube
WordPress.com Logo and Wordmark title=

Learn how to build your website with our video tutorials on YouTube.


Automattic, Inc. - 60 29th St. #343, San Francisco, CA 94110  

Posted by BigPalaceNews at 4:24 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

About Me

BigPalaceNews
View my complete profile

Blog Archive

  • June (76)
  • May (82)
  • April (84)
  • March (87)
  • February (90)
  • January (74)
  • December (72)
  • November (95)
  • October (105)
  • September (112)
  • August (116)
  • July (96)
  • June (100)
  • May (105)
  • April (95)
  • March (131)
  • February (111)
  • January (104)
  • December (98)
  • November (87)
  • October (126)
  • September (104)
  • August (97)
  • July (112)
  • June (113)
  • May (132)
  • April (162)
  • March (150)
  • February (342)
  • January (232)
  • December (260)
  • November (149)
  • October (179)
  • September (371)
  • August (379)
  • July (360)
  • June (385)
  • May (391)
  • April (395)
  • March (419)
  • February (356)
  • January (437)
  • December (438)
  • November (400)
  • October (472)
  • September (460)
  • August (461)
  • July (469)
  • June (451)
  • May (464)
  • April (506)
  • March (483)
  • February (420)
  • January (258)
  • December (197)
  • November (145)
  • October (117)
  • September (150)
  • August (132)
  • July (133)
  • June (117)
  • May (190)
  • January (48)
Powered by Blogger.