Analog to Midi sensors
John V
Posts: 8
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.
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 Williams
Applications Engineer, Parallax
Dallas, TX· USA
John
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
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.·
John
Post Edited (John V) : 4/6/2005 1:50:19 PM GMT
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
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:
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··
John·
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
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:
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!
John
· 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
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
John
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
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 Williams
Applications Engineer, Parallax
Dallas, TX· USA