Ebay Classic organs

Collapse

Announcement

Collapse
No announcement yet.

Using an Arduino to wire Allen Keyboards and Pedalboard for MIDI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using an Arduino to wire Allen Keyboards and Pedalboard for MIDI

    I have been posting about my progress with an Arduino project on another forum thread, but I thought I would also make an update here. My project uses an Arduino Mega to add midi capability to the keyboards and pedalboard of an Allen 225-RTC MOS-2 organ. Unfortunately, it doesn't preserve the existing hardware, or use the expression pedals or combination action, but it does otherwise work very well for MIDI on the three divisions, and the Arduino Mega it uses is quite affordable compared to some of the other similar MIDI solutions out there. Here is the link:

    https://create.arduino.cc/projecthub...-organs-f3756c

    Let me know what you think of the project!

    -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
    -Website: https://www.exercisesincatholicmythology.com

  • #2
    Excellent project write-up on the project hub! Very well done.

    Your code, however, could stand some simplification to improve readability and perhaps optimize performance. Take for example,
    Code:
    if (keysC[0][0] == 0) {  
       keysC[0][0] = 1;
    }
    else if (keysC[0][0] == 1) {
       keysC[0][0] = 0;
    }
    The value of keysC[0][0] is a boolean ( value limited to 1 or 0) so the else if is unnecessary and could be re-written as
    Code:
    if (keysC[0][0] == 0){
       keysC[0][0] = 1;
    }
    else {          // no need to read & test value of keysC again, if it's not zero it has to be 1
       keysC[0][0] = 0;
    {
    Since keysC[0][0] is a boolean value, with 1 = TRUE and 0 = FALSE the test for the value of keysC[0][0] can be expressed as
    Code:
    if (keysC[0][0]){  // if it'sTRUE set it to FALSE
       keysC[0][0] = 0;
    }
    else {       // it's FALSE so set it to TRUE
       keysC[0][0] = 1;
    {
    This could more concisely be expressed in tertiary form as
    Code:
    keysC[0][0] = keysC[0][0] ? 0 : 1;
    which means if keysC[0][0] is 1 set it to 0 otherwise set it to 1.

    Since the code is simply toggling the state of keysC[0][0] between two boolean values the most efficient replacement expression for your block of code would be this:
    Code:
    keysC[0][0] = ~keysC[0][0];
    which means set it to what is currently it is not.

    I've been coding for nearly fifty years, so my intent here is not to disparage your code, but to point out more efficient ways of accomplishing the same thing that can lead to better performance in time sensitive applications and easier debugging.

    The important thing though is that you got it working! Congratulations! Good job.
    Last edited by Admin; 02-05-2021, 02:24 PM.
    -Admin

    Allen 965
    Zuma Group Midi Keyboard Encoder
    Zuma Group DM Midi Stop Controller
    Hauptwerk 4.2

    Comment


    • Larason2
      Larason2 commented
      Editing a comment
      Thanks! That’s actually very useful. I figured there was an easier way to do it, but I couldn’t figure it out. I will definitely incorporate this into version 2!

    • Larason2
      Larason2 commented
      Editing a comment
      Hi Admin, I tried to implement some of your suggestions, but I had a lot of trouble! The first suggestion didn't work, because it doesn't invert the notes so that whenever you get a 1, it changes it to a zero, and vice versa. I think the trouble I had with the other suggestions has to do with the keysC[x][x] array being an array of bytes, so that for instance if you use the "~" operator, it changes 0001 into 1110, and I assume it would be the same if you use boolean operators. So, I have kept the code the way it is! I still want to learn how to use bitwise operators as you are suggesting, but the problem when I have been trying to code it is to find a way to get "digitalRead" to modify only one bit. If you have any insight into how to get that to work, I would appreciate it!

    • Admin
      Admin commented
      Editing a comment
      digitalRead(pin) returns a boolean value, HIGH or LOW. Sorry, I didn't notice that you are assigning digitalRead(pin) to a BYTE so the HIGH value is being stored as 0000 0001 and negating that will not result in a zero value. Your array should be of type bool, the same type that is returned by digitalRead.

      https://forum.arduino.cc/t/integer-v...and-low/109329

      I think the compiler will produce the same result for a bool whether you use bitwise or logical negation, but, as you observed, that's not true of non-boolean types and my example code is technically incorrect and should read keysC[0][0] = !keysC[0][0]. The more verbose form of this would be keysC[0[[0] = keysC[0][0] == HIGH ? LOW:HIGH; Try changing your array to bool.

  • #3
    Just wanted to let everyone know that I updated my Arduino hub page! I now have code and schematics for potentiometers, and bussed as well as matrixed keyboards.

    https://create.arduino.cc/projecthub...-organs-f3756c

    -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
    -Website: https://www.exercisesincatholicmythology.com

    Comment


    • #4
      Hi Larason2,
      Thank you for the great work on the Arduino keyboard scanner.
      I've tried both the Matrix and Bussed versions and they both seem to suffer the same problem. They send the correct midi notes most of the time, but occassionally send the wrong note, an extra note or most worryingly don't send the "NoteOff" message or sends "NoteOff" for the wrong note - equally worrying as it results in a hung-note.

      I've attached a screen grab of the midi messages which shows the problem. I'm activating the same note each time and you can notice that the first few messages are correct with the correct matching On/Off messages, but then you can see there is an additional NoteOn sent for a wrong note and sometimes the NoteOff is missing.

      This seems to happen equally with the bussed or matrix version. I'm testing it right on the Arduino board with nice short wires so I don't think it's induced noise or stray capacitance etc.

      Any thoughts or ideas you have on how to fix the wrong notes and missing NoteOff messages would be greatly appreciated.
      Click image for larger version

Name:	Arduino Midi Scanner Bussed false message sample.JPG
Views:	212
Size:	37.4 KB
ID:	772510Click image for larger version

Name:	Arduino Midi Scanner Matrix false message sample.JPG
Views:	208
Size:	46.7 KB
ID:	772511
      Thanks again for a great project.
      Best regards,
      Fiona

      Comment


      • #5
        At least for the matrixed version, I’ve been running the identical code for over a month, and I have no such problems as you’re describing. However, you have to be very careful how you’re wiring it. If any metal from the circuit is touching any other metal part, you can get the problems as you are describing. Also, it depends how the contacts are wired. Some switches have a common ground, and if that is the case, it would be very difficult to get a matrix to work. Even for the bussed design, you have to be sure to isolate the busbar from each manual from the busbar from other manuals, for instance. It would help if you sent us a picture of how your circuit is wired.

        Another problem for your circuit are the notes with velocity that aren’t 100. My program only sends notes with velocity 100, so all of those extraneous notes of other velocities were generated some other way, or corruptions of the signal. I mentioned in the text of the project that this project doesn’t work at the same time as the original keying, so if you want it to work without errors, you’ll have to remove the original circuits, and may have to desolder some of the original wiring.

        Another possibility too is that the midi messages are somehow getting scrambled. This can happen for instance if the midi baud rate isn’t right. What hardware are you using to connect the Arduino to your computer? Also, did you make sure to put the resistor on the 5v going to the Midi connector? A lot of Midi designs also put a 220 ohm resistor on the Midi Tx wire, but this didn’t work with my hardware. It would also be helpful to know what arduino exactly you are using, and how it is wired up.

        -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
        -Website: https://www.exercisesincatholicmythology.com

        Comment


        • #6
          Hi Larason, Thank you so much for your prompt reply. I'm thrilled that you have this working without errors because it's something I really want to get going; and I'm very grateful for you work. Thank you.

          I've attached a picture of my test rig. As you can see it's just the Arduino Mega 2560 board, with the 220Ohm resistor from the +5V to the midi DIN plug, the Tx data to the midi DIN plug, a diode straight to one of the inputs and a 'wander' lead (red) to make/break as required. The other leads just tie the pot wiper inputs to ground to stop lots of spurious CC messages. This is the simplest test rig I can think of. I think it rules out metal or wiring errors etc. It's just the board with one diode and one lead.

          But it produces the error messages posted earlier. I don't know what else to do to simplify the test setup and I guess my problem is that I don't want to invest the time and effort to wire up keyboards if I can't get even the simplest rig to work.

          I'd really appreciate any other thoughts you may have ?

          It does seem to smack of some sort of timing error to me (gut feeling only). How can you check the scan rate, or the midi data clock rate (which I assume are different and independent ?)

          I really appreciate your work and would love to get this working so any thoughts you have would be wonderful.

          Thank you again !

          Best regards,
          Fiona

          Click image for larger version

Name:	20210531_172843[1].jpg
Views:	215
Size:	270.7 KB
ID:	772528

          Comment


          • #7
            I'm also in the process of adding Midi to my Concorde 2107. I'm designing keyer boards that will supply the necessary diode/matrix and utilizing the MIDI/USB Arduino Mega board from Midikits.net. The operator of the Dublin, Ireland based website, Tom Scarff, is also adding code to scan for a sustain pedal plus pitch and mod wheels. The board can encode for two 61-note keyboards and a 32-note pedal board. In fact, if anyone has parted out a Concorde, I need a right side end block. Anybody? Please? Hmm? Thanks!
            Over the years: Hammond M3, BC, M102, B3, four X77s and three PR-40s, a Thomas Electra and a Celebrity, three Fender Rhodes, Roland HS-10, HP-2000, HP-600, RD-600, JV-880, a thing made by Korg (?), two Leslie 910s, 122, 257, 258, 247, two 142s, and three custom-built Leslies. Wow, way too much money spent!

            Comment


            • #8
              Thanks Fiona,

              The first thing I can think to do is to disable the code that controls the potentiometers and upload it again. To do this, just put “/*” above the code, and “*/“ after it, upload it, then disconnect the wires going from the analog inputs to ground. Even like this, the wires can still act like an antenna and send spurious messages.

              Once that’s been sorted out, It may also be your midi interface. What interface are you using? If it’s one of the very inexpensive ones, it may be corrupting the messages. If you can try another one, that may help. Another thing to try is putting another 220 ohm resistor between the Tx and the data wire of the midi port to see if that improves fidelity.

              Let us know how that turns out!

              -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
              -Website: https://www.exercisesincatholicmythology.com

              Comment


              • #9
                Brilliant ! Thanks Larason2. It was the midi interface.

                Very weird however - I've used the midi to USB interface for probably around 10years and never had a problem with any other keyboard or midi device, but it's definitely faulty. I swapped the crook one for an identical interface and it worked fine. I bought both interfaces from the same supplier at the same time (I actually bought 6 at that time as they were only about $6 each and never had a problem with any of them) so it would be reasonable to assume they are all identical. See picture. But, windows reports the faulty one as being "USB MIDI INTERFACE" and the one that works properly as being "USB2.0-MIDI", so presumably they have different firmware (?). And the other thing that is weird is that the faulty interface power indicator lamp acts normally (i.e. lights up when USB power is present) but the GOOD one behaves strangely....... if the midi cable is plugged into this arduino project and the metal outside shield of the USB plug is touched on to the PC earth the power led lights up (!) even if there is no USB power available (i.e. the USB plug is not even plugged in)........ Very strange. Anyway, not to worry. I've got it working properly now - so no worries with the code. Great work. Thank you.

                By the way, your Arduino project also works faultlessly with a professional multi-channel USB audio interface that has 5pin Midi In/Out. So it was definitely the interface.

                Thank you so much for sharing your work and project with us.
                Being able to scan 4 x 61note keyboards with just one Ardunio is brilliant !

                Thanks again.

                Best regards,
                Fiona
                Click image for larger version

Name:	Midi_Usb_Interface[1].jpg
Views:	200
Size:	319.9 KB
ID:	772566
                Attached Files

                Comment


                • Larason2
                  Larason2 commented
                  Editing a comment
                  My pleasure, glad you got it working.

                • edkennedy
                  edkennedy commented
                  Editing a comment
                  Those Midi adapters do not work well. I'm experimenting with the Pipe Organ for Mac app from Omenie.com, and in their writeup, they comment that those small generic MIDI adapters fail to honor 'running status' and miss notes, miss 'note off' or play random notes. I tried one and had those issues. I switched to a M-Audio Uno, and had no further problems
                  I wonder if we need a "Sticky" posting to highlight the problem with these cheap MIDI adapters.

                • myorgan
                  myorgan commented
                  Editing a comment
                  Ed Kennedy,

                  Create a post providing the details of the potential MIDI issues. Once you have, please let a moderator know, and we can make it a sticky on a particular Forum. Thanks for the offer.

                  Michael

              • #10
                Hello Larason2,
                I've had a lot of success with your code now. Thank you.

                I've also come across a midi keyboard scanner (8x8 Matrix = 64notes only on one kbd) but it sends the data over the on-board USB port.
                Having the midi data out on the USB port is very useful as it removes the need for the MIDI to USB interface completely.

                Would/could you have a look at modifying your software to send the data on the USB port instead of the Tx pin and 220Ohm+5v ?

                I've included the 8x8 Midi on USB sketch as a text file to have a look at. It uses some existing libraries - "TimerOne", "MIDI", "MIDIUSB", and "MIDI Library".

                I'm sorry this is beyond my level of programming knowledge but if you (or anyone ?) has any ideas on how to send the Midi data stream on the USB port that would be greatly appreciated.
                Thank you.
                Attached Files

                Comment


                • #11
                  The Teensy folks at www.pjrc.com pioneered the easy use of USB-MIDI by hobby level developers although the more adventurous had been doing the same with PIC MCUs for the past ten years or so. The Teensy 4.1, for example, uses the Arduino IDE with some extensions and provides a 600 Mhz MCU at a slightly higher cost than the Arduino Mega. I've published code for matrix and bus encoders on this site and on my own web site so feel free to copy and reuse any of it. This is time tested code that performs really well so give it a try. There is no excuse to be using the sluggish 5-pin MIDI cables in modern products.
                  http://www.kinkennon.com

                  Comment


                  • tbeck
                    tbeck commented
                    Editing a comment
                    I can vouch for that. I use a Teensy 4.1 for my MIDI controller.

                • #12
                  To use the USB port on an Arduino Mega as a MIDI port you will need to reprogram the interface (ATmega16U2) as described in this article https://create.arduino.cc/projecthub...arduino-740fe7. It's a lot easier to use the USB port as a Serial port and convert to MIDI using a software solution like Hairless-MIDI. However, I did manage to convert the USB ports on mine to MIDI.

                  Comment


                  • #13
                    I believe Sandstone is right. The problem is needing to reprogram the board, which I don’t really want to do. If you would like to use USB only, give hairless midi a try, or something similar. It should work with my code without any modification, since I send the midi messages on the Tx port. I’ve tried working with libraries before, but it is not as easy as it looks. You really need to understand how they are programmed to use them effectively. After having tried Teensy I’m very happy with how it works, so I may try that in the future, and/or post some teensy code somewhere. The main problem for me right now is that Teensy has way fewer pins and I’ve had limited success getting I/O expanders to work so far. So I’m afraid I probably wouldn’t be able to include code that allows USB Midi on the Arduino in the near future, but I’ll continue working on it and I’ll post it if I can ever get it working! I wouldn’t mind posting some 8x8 code along the lines of what I have already posted if someone finds that useful.

                    -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
                    -Website: https://www.exercisesincatholicmythology.com

                    Comment


                    • #14
                      Thanks Larason2,
                      All good.
                      I uploaded a fully working and tested 8x8 MATRIX which sends MIDI data on the USB Port a few days ago right here, on 06_03_2021.

                      The pin layout is set up for an Ardunio Leonardo. I can post the pin-outs (basically the circuit diagram) here if there is any interest.
                      Please just let me know.
                      Thanks and best regards.

                      Comment


                      • #15
                        Thanks Fiona,

                        I took a look at the code you posted, and it is also beyond my level of programming knowledge! I basically only figured out the minimum needed to get my system working, and elements they use like for() loops still confuse me. The Arduino Leonardo is like the Teensy, in that it has onboard USB Midi, so that is why it would work on that board without reprogramming. However, none of the other Arduino's do that, to my knowledge, and definitely not the Mega or Uno. Glad you got it working for you!

                        -Current Instruments: Allen Mos-2 225 RTC,1870's W. Bell Reed organ, 1890's Singer Chicago upright grand piano Former Instruments: Yamaha Electone E3R
                        -Website: https://www.exercisesincatholicmythology.com

                        Comment

                        Working...
                        X