element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
MusicTech
  • Challenges & Projects
  • Design Challenges
  • MusicTech
  • More
  • Cancel
MusicTech
Blog Kazumi - 05 - Using multiple MPR121 boards
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: luiszayas
  • Date Created: 4 Mar 2016 12:58 PM Date Created
  • Views 784 views
  • Likes 0 likes
  • Comments 1 comment
  • music tech
  • music_tech
  • mtc
  • bbb
  • project_kazumi
  • musictech
  • music
  • music-tech
  • kazumi
Related
Recommended

Kazumi - 05 - Using multiple MPR121 boards

luiszayas
luiszayas
4 Mar 2016

Hi everyone,

 

I feel like I have been stuck in the world of Pure Data for most the past three days. *head spinning*

 

I have managed to get values from all four MPR121s flowing into Pd (again with the help of Chris from the Bela platform team). Unfortunately, the results aren't as great as I was expecting so I might have to change part of how the pads work.

 

Changing the C code

I started off looking at the example for the MPR121 (which doesn't use Pd) and looked for anything that said "0x5a" as this is the default I2C address for the boards.

 

I found this in the setup part of the code:

  if(!mpr121.begin(1, 0x5A)) {
  rt_printf("Error initialising MPR121\n");
  return false;
  }

 

So I looked for where the mpr121 object had been setup and found this:

I2C_MPR121 mpr121; // Object to handle MPR121 sensing

 

I created 4 different objects like this:

I2C_MPR121 cap; // Object to handle MPR121 sensing
I2C_MPR121 cap1; // Object to handle MPR121 sensing
I2C_MPR121 cap2; // Object to handle MPR121 sensing
I2C_MPR121 cap3; // Object to handle MPR121 sensing

 

And modified the if statement, creating one for each of the I2C addresses used by the MPR121s (I had previously soldered the address pins on the boards to change them):

  if(!cap.begin(1, 0x5A)) {
  rt_printf("Error initialising MPR121\n");
  return false;
  }

  if(!cap1.begin(1, 0x5B)) {
  rt_printf("Error initialising MPR121\n");
  return false;
  }

  if(!cap2.begin(1, 0x5C)) {
  rt_printf("Error initialising MPR121\n");
  return false;
  }

  if(!cap3.begin(1, 0x5D)) {
  rt_printf("Error initialising MPR121\n");
  return false;
  }

 

I then copied all of these back to my custom render.cpp file and added some more scheduled messages to get all of this data into Pd:

void readMPR121()
{
  for(int i = 0; i < NUM_TOUCH_PINS; i++) {
  sensorValue[i] = -(cap.filteredData(i) - cap.baselineData(i));
  sensorValue[i] -= threshold;
  if(sensorValue[i] < 0)
  sensorValue[i] = 0;
        hv_vscheduleMessageForReceiver(gHeavyContext, "sensorValues", 0, "fff", (float)0, (float)i, (float)sensorValue[i]);
  }

  for(int i = 0; i < NUM_TOUCH_PINS; i++) {
  sensorValue1[i] = -(cap1.filteredData(i) - cap1.baselineData(i));
  sensorValue1[i] -= threshold;
  if(sensorValue1[i] < 0)
  sensorValue1[i] = 0;
        hv_vscheduleMessageForReceiver(gHeavyContext, "sensorValues", 0, "fff", (float)1, (float)i, (float)sensorValue1[i]);
  }

  for(int i = 0; i < NUM_TOUCH_PINS; i++) {
  sensorValue2[i] = -(cap2.filteredData(i) - cap2.baselineData(i));
  sensorValue2[i] -= threshold;
  if(sensorValue2[i] < 0)
  sensorValue2[i] = 0;
        hv_vscheduleMessageForReceiver(gHeavyContext, "sensorValues", 0, "fff", (float)2, (float)i, (float)sensorValue2[i]);
  }

  for(int i = 0; i < NUM_TOUCH_PINS; i++) {
  sensorValue3[i] = -(cap3.filteredData(i) - cap3.baselineData(i));
  sensorValue3[i] -= threshold;
  if(sensorValue3[i] < 0)
  sensorValue3[i] = 0;
        hv_vscheduleMessageForReceiver(gHeavyContext, "sensorValues", 0, "fff", (float)3, (float)i, (float)sensorValue3[i]);

 

Back in Pure Data

In order to organise the data streams, I created an abstraction to use for the different pads. The creation arguments specify the midi note and ADC input.

 

This is what the main patch looks like:

image

And this is is what the pad abstraction looks like:

image

As you can see, I have set it up so that when each electrode is touched, a different midi note goes into the karplusS abstraction. However, I have bypassed this for the time being. The reason is that the trigger from touching an electrode has more latency than the one from the piezo transducer. This results in a weird effect, similar to a hammer-on on guitar which I don't really like. This was somewhat perceivable when there was only one MPR121 board but with all four boards it seems to have gotten worse.

 

I am not doing anything with the sixth inlet at the moment. I will explain more about this in a future post but these will be used to transpose all of the notes to change the key of the scale.

 

The subpatches on the lower right-hand corner receive the bangs from touched electrodes for different effects. This is what they look like (pd damp is bypassed).

image

Demo

This is a test using three pads. For some reason, I am getting a Segmentation fault when I use more than three so I will have to look into that.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Bela on Kickstarter

Lastly, great news for the Bela platform as it is now over 500% funded on Kickstarter. They have announced two stretch goals which are also brilliant news, especially the Multiplexer Capelet as it will enable use of up to 64 analog inputs!

  • Sign in to reply
Parents
  • DAB
    DAB over 9 years ago

    Nice update.

     

    You provide good explanations for your Pure Data code, which is nice others to see how it is used and the power hidden within it.

     

    Thanks,

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 9 years ago

    Nice update.

     

    You provide good explanations for your Pure Data code, which is nice others to see how it is used and the power hidden within it.

     

    Thanks,

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube