Shop OBEX P1 Docs P2 Docs Learn Events
Analog to Midi sensors — Parallax Forums

Analog to Midi sensors

John VJohn V Posts: 8
edited 2005-04-22 05:46 in BASIC Stamp
Hi. I'm new to this forum - and electronics in general - so I apologize in advance if this question is too basic or, in any way, inappropriate.

I'm wondering if it's possible to use a Basic Stamp to process analog input (e.g., light sensor), digitize it, and then send a midi continuous controller message (cc) to midi-capable music software running on my PC?

I'd like to make an interactive exhibit that alters music in relation to the viewer's position.

I'm currently using a retail knob box·midi controller to adjust a variety of knobs, switches, sliders in the music software and would like to do the same sort of thing with sensors.

Would a Basic Stamp work for·something like this? If so, is it something a beginner could tackle with a little persistence and determination? Or is it way out of my league?

Thanks in advance for any help.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-03-24 04:23
    Yep ... have a look at this thread: http://forums.parallax.com/showthread.php?p=529442

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John VJohn V Posts: 8
    edited 2005-03-25 04:52
    Thanks a lot, Jon. I'll take a look at those articles. smile.gif

    John
  • dufflingduffling Posts: 73
    edited 2005-03-25 07:01
    Yes i made a project that did this and it was quite easy really check out this page also :

    http://www.audiomulch.com/midipic/

    MIDI INPUT is a bit more tricky and requires a UART or in the case of the SX you can do it using a software UART although im still working this out [noparse]:)[/noparse]

    as far as MIDI out goes its quite straitforward you should have no problems at all with any of the BASIC stamps , i used the BS2PE for its extra memory and setup a PATCH storage type system with my stamp , so you can customize the various controller numbers for different setups
    works great!
  • John VJohn V Posts: 8
    edited 2005-03-28 02:03
    Thanks, duffling! The site you referenced looks like a great resource. smile.gif

    John
  • John VJohn V Posts: 8
    edited 2005-04-06 13:42
    Hi again. I went out and bought a Basic Stamp 2 and some of the other stuff needed to do a few simple experiments (What’s a Microcontroller? v. 2.2). After getting comfortable with basic circuits, I took a shot at some MIDI·projects and was able to successfully send MIDI note on/off·messages to music software running on my PC (Jon Williams, Nuts and Volts, Column #94). The next step was to try and set up some potentiometers to remotely control virtual knobs and sliders in FLStudio and Ableton Live.

    My plan was to use an ADC0831 analog to digital converter (Jon Williams, Nuts and Volts, Column #95), but I’ve yet to find one over here in Korea. So I figured I’d try to set up some pots using an RC Time Circuit (What’s a Microcontroller, pages 150-151) and code linked to from the Audiomulch site mentioned above. (http://www.interaccess.org/arg/arg-knowledge/MIDI.BS2)

    I set up three single-turn pots, ran the program, and checked the pot values in the Debug Terminal. Each had a reading somewhere between 120 and 692 through full rotation, although the values weren’t stable. For example, one pot would fluctuate between 120 and 121 when rotated extreme clockwise.

    The problem arose when I tried to use the pots with software. Both FLStudio and Ableton Live have a controller auto detect feature. Usually, I just click on a virtual knob and then rotate a hardware knob on a midi remote control unit. The software automatically recognizes the hardware controller and assigns it to that software parameter. It didn’t work with my pots, though. The controller number wouldn’t stabilize. I used pins 0-2 for the pots, and I could see the controller number listed in the software repeatedly zooming through those numbers: 0 – 1 – 2, 0 –1- 2, etc. How can I get the software to read only one pot at a time, the pot that I turn? Anyone know?

    Thanks in advance for any·help.·smile.gif

    John

    Post Edited (John V) : 4/6/2005 1:50:19 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-06 14:15
    When using RCTIME you will see these fluctuations due to circuit noise and component characteristics What you might want to do is a bit of digital filtering. This would be good for two reasons: 1) you can minimize the noise, and 2) you can scale the pot value to 0 - 127 (or whatever works best for your software).

    A simple way to do the filtering is like this:

    · newValue = (newValue / 2) + (oldValue / 2)

    Of course this means you have to keep track of the old value. Actually, you could use just one temporary variable grabbing the current pot value before doing the new read. Once you have a filtered value then you can scale it. Let's say your filtered value is from 120 to 620, and you'd like that to be 0 to 127. Here's the math.

    · scaleVal = (newVal - 120) */ $0041

    The latter par of the equation is the same as multiplying by 0.254 (127/500).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John VJohn V Posts: 8
    edited 2005-04-08 18:41
    Thanks for your help, Jon.

    Unfortunately, I'm still in the dark (through no fault of your own:-)

    I wasn’t sure how to use the variables for filtering – particularly the part about “keeping track of the old value” - so I looked around the Internet for some program examples. I came across another one of your articles (N&V, column #37) that included code similar to what you posted above and was wondering if I could adapt this to my project:

    HIGH FloSnsr·············· ' discharge RC cap
    PAUSE 5
    RCTIME FloSnsr,1,rawFlow·· ' read the sensor
    rawFlow = rawFlow */ $0043 ' scale to 0 - 1600 (approx)
    ·························· ' (rawFlow * 0.26)

    ' filter by combining in 60/40 (old/raw) ratio
    newFlow = (oldFlow */ $009A)+(rawFlow */ $0066)

    ' flow is too high -- shut down
    IF newFlow > HiFlow THEN OvrFlo
    GOSUB ShoFlo ' update the display

    oldFlow = newFlow········· ' save last flow reading
    PAUSE 500················· ' delay between readings
    GOTO Main················· ' do it all again


    Could I use the above construction to filter and keep track of the old value (e.g., "oldFlow = newFlow"), so that it'd look something like this:
    ···· DEBUG HOME
    ···· FOR pins = lowpot TO hipot
    ···· HIGH pins················· ' read value of the pot
    ···· PAUSE 1
    ···· RCTIME pins, 1, value
    ···· ' drop the least significant bit
    ···· value = value >> 1
    ···· ' filter by combining 50/50 (old/raw) ratio
    ···· newValue = (oldValue / 2) + (value / 2)
    ·····oldValue = newValue········' save last reading
    Or should I stick to this:
    ······ ' filter by combining in 50/50 (new/old) ratio
    ···· newValue = (newValue / 2) + (oldValue / 2)
    I fooled around with different code variations, but wasn't successful, maybe in part because I couldn't figure out how to set up the Debug terminal to read the "newValue." Whenever I ran the program, the Debug terminal would read "0" for all pots ... or all pot values would change when rotating a single pot (depending on which of the above code versions I used).
    I'm starting to feel like I'm in way over my head. Is there any hope? Or am I a lost cause? :-)·(It's·quickly getting WAY too Greek!)
    Thanks again·smile.gif·
    John·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-08 19:35
    Take you're time you'll get it -- Rome wan't built in a day.· Perhaps you should put this project down for a couple weeks and work your way through our "What's A Microcontroller?" text.· The time spent with WAM will save you a lot of frustration.· After that we have several other books that are also very good and quite useful.· The key thing is to be patient with yourself so that you don't get overwhelmed.

    On your other questions, after calculating your new value, you must save that to the old value variable -- otherwise the filtering won't work.

    To display, DEBUG is quite simple:

    Show_Readings:
    · DEBUG DEC newVal, CLREOL, CR,
    ········DEC oldVal, CLREOL

    When you add that to your program you can watch the filtering in real-time; the percentage of old-to-new will affect how fast the new reading reaches the actual wiper position.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John VJohn V Posts: 8
    edited 2005-04-10 11:08
    Hi, Jon. Thanks again for your help.

    I think I figured out a big part of my problem. It helped to change the program so it was reading only 1 pot instead of the 3 I had set up on the breadboard. By doing this, I got a better handle on what was happening in the Debug Terminal.

    The software was also able to recognize a single pot, and I was able to use·that pot to control virtual knobs/parameters in the software after scaling the value like this:

    scaleValue = value * 100

    From there, I think I figured out how to begin fixing the program to deal with the controller autodetect feature of the software. As it is, the program is always sending midi signals from 3 different pots, which confuses the autodetect feature because it's designed to detect movement of a single pot. What I need to do is figure out a way to only send midi signals when there's a change in pot value. Seems like something that's very doable, maybe with some sort of IF/THEN construction? Any ideas or article references?·I know next to nothing about programming, so maybe it's a simple solution?

    Thanks again for your help! smile.gif

    John
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-10 11:19
    Yes, IF-THEN will work for you:

    · IF (lastValue1 <> newValue1) THEN
    ··· ' send newValue1
    ··· lastValue1 = newValue1
    · ENDIF

    Where lastValue1 is the value last transmitted to your MIDI device.· Note that this is not the same as your raw reading used for filtering.· It would seem to me that using an ADC0834 would simplify your process, and also speed it up.· RCTIME takes time, and the filtering requires variable space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John VJohn V Posts: 8
    edited 2005-04-19 09:19
    Hi, Jon. As always, thanks for your help.

    I haven't figured out how to get the midi controller auto-detect feature of my software to work with multiple pots, but I think I found a place where I can buy an ADC0831 over here.

    Would I be able to set up multiple pots/sensors with a single Stamp·and·one·ADC0831?

    (One reason I was trying to figure out how get that RCtime circuit/program to work is because it supports up to 15 pots/sensors.)

    Cheers smile.gif
    John
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-19 11:13
    You would need some sort of analog multiplexer to select the pot being fed into your ADC0831.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John VJohn V Posts: 8
    edited 2005-04-22 03:27
    I got ahold of an ADC0831 CCN and set it up with a photocell to control midi notes (your N&V article #95), and that was very cool ... and something that'll definitely help me achieve my ultimate goal of creating an interactive music exhibit. So thanks a lot·for that!·smile.gif

    I guess the next step is to look into the analog multiplexer you mentioned.

    The programming aspect is going to be an uphill battle, though.

    For someone with no background in programming, like me, would you recommend learning about BASIC in order to get a better handle on PBASIC? (My understanding is that PBASIC is a simplified version of BASIC?)

    Thanks and have a good day!

    John
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-22 05:46
    In some ways, PBASIC is more sophisticated because it is designed for small-scale embedded systems. Don't worry though, people learn programming every single day. Download our "What's A Microcontroller?" book and work your way through it; that's the best place to start.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.