element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum Help: Multiple problems with project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 3 replies
  • Answers 2 answers
  • Subscribers 391 subscribers
  • Views 438 views
  • Users 0 members are here
  • classroom
  • synth
Related

Help: Multiple problems with project

pathfider1998
pathfider1998 over 7 years ago

So I'm making a small piano project (with or without Mozzi library) using Arduino UNO or Pro Mini for the class (as a part of STEM education we are having here), but I have encountered some issues:

  1. I can't figure out how to read 13 keys (single octave C~B, and black keys) without freezing the tone every time key is being read or restarting the waveform each time the function is called.
  2. Using resistor array worked, but its tone drifted too much for the kit and it only allowed one tone to play even with multi-key polyphony code. Now I divided the button into four sections shown below (in image) to try to minimize pitch drift, but now I have to read 4 analog input (or 3 if I omit second octave C and don't use 13th button)
  3. Since Arduino's built-in Tone function only has single tone and there is no way around it (and you know how awful single tone synth sounds when it outputs pure PWM straight into that tiny Mylar speaker), we attempted to use Mozzi because it supports FM and sine output through PWM (and some LP filter if it's absolutely necessary), a sound synthesis library. But then I have to rewrite the entire code. (The code I used is lifted straight from https://www.arduino.cc/en/Tutorial/toneKeyboard) Could somebody help me a bit? It does not have to sound absolutely beautiful (basic waveforms are just fine) and it just has to have at least two-note polyphony.

Any help is appreciated!

image

p.s. Values of resistors on buttons (except for pull-down resistors) are placeholders.

Actual values from left to right on each row are: 4.7K, 1K, 470R, 100R

  • Sign in to reply
  • Cancel

Top Replies

  • pathfider1998
    pathfider1998 over 7 years ago in reply to ntewinkel +1
    Yep, I'm using the 4x4 keypad that comes with education kit. I'm thinking of reading analog voltage from each 4 (or 3) lines, creating the possibility of at least two-tone polyphony. But the problem still…
  • ntewinkel
    0 ntewinkel over 7 years ago

    For reading the keys, have you tried the Arduino Keypad library?

    https://playground.arduino.cc/Code/Keypad

     

    Their example only shows 12, but I see you can purchase keypads with 16. Or more likely you can probably hook up your piano keys in a similar circuit.

     

    edit: The keypad tutorial shows more on how to use it, including the detail that the circuit is basically rows and columns of buttons connected to pins for rows and pins for columns. Physically you can of course make it one straight line, but to get your 13 keys you need 4x4 = 8 pins to get 16 possible buttons.

    https://playground.arduino.cc/Main/KeypadTutorial

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • pathfider1998
    0 pathfider1998 over 7 years ago in reply to ntewinkel

    Yep, I'm using the 4x4 keypad that comes with education kit. I'm thinking of reading analog voltage from each 4 (or 3) lines, creating the possibility of at least two-tone polyphony.

     

    But the problem still remains -- how do I read each pin and apply variables to the library I'm trying to use because built-in tone library is a no-go?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • pathfider1998
    0 pathfider1998 over 7 years ago

    Currently, I got everything nailed down to produce perfect value every time button is pressed if Keypad library cannot be used.

    C: 0 0 0 706

    C#: 0 0 705 0

    D: 0 705 0 0

    D#: 705 0 0 0

    E: 0 0 0 330

    F: 0 0 330 0

    F#: 0 330 0 0

    G: 330 0 0 0

    G#: 0 0 0 186

    A: 0 0 186 0

    A#: 0 186 0 0

    B: 186 0 0 0

    C: 0 0 0 44 (Limit for 12-key implementation)

    C#: 0 0 44 0

    D: 0 44 0 0

    D#: 44 0 0 0

     

    Using following code:

     

    void setup() {

      Serial.begin(9600);

    }

     

    void loop() {

      int sensorValuea = analogRead(A0);

      int sensorValueb = analogRead(A1);

      int sensorValuec = analogRead(A2);

      int sensorValued = analogRead(A3);

      Serial.print("Line 1: ");

      Serial.print(sensorValuea);

      Serial.print(", ");

      Serial.print("Line 2: ");

      Serial.print(sensorValueb);

      Serial.print(", ");

      Serial.print("Line 3: ");

      Serial.print(sensorValuec);

      Serial.print(", ");

      Serial.print("Line 4: ");

      Serial.print(sensorValued);

      Serial.println(". ");

      delay(10);

    }

     

    This is the requirement for the code:

    • Be able to read multiple buttons, doesn't matter if it's one of each group of buttons or individually, within 6 analog pins (and 9 digital pins except 9, 10 and/or 11) limit (I will be using the layout from 4x4 button board)
    • Preferably no shift registers, but it can be used if it's absolutely required
    • Be able to produce at least two-tone polyphony
    • Optionally use Mozzi library to generate sound, waveform really doesn't matter, be it FM synth or just basic waveform with fixed ADSL setting
    • Sound should not restart while button is held down (just like any digital pianos)
    • Sound does not have to stop exactly when the key is released, it just has to end before 30ms
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
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