Shop OBEX P1 Docs P2 Docs Learn Events
Analog Encoder to System Exclusive MIDI messaging — Parallax Forums

Analog Encoder to System Exclusive MIDI messaging

TheVigTheVig Posts: 41
edited 2011-12-11 09:43 in Propeller 1
I'm looking start working with a Parallax 40000-RT Propeller and want to make sure it can do what I need before I waste tons of money and time. (I think I freaked out the guy at the local Radio Shack today, so I'm asking the forum. He was actually pretty helpful)

I may purchase a different model/product if my needs can be better met. (Suggestions ?)

Here is the outline of my task:
I've been working with computer programs to send system exclusive midi message via a USB midi interface.
So a slider in a GUI on the computer transmits a corresponding SysEx message based on the sliders position.
This all works fine and dandy until I have lug a computer around and I don't have any real knobs so I can't tweak more than one parameter at a time.

So I would like to build an interface that is stand-alone with variable resisters (pots) that can be used to transmit specific system exclusive midi messages to my midi capable devices based on the amount of resistance from the pot.

Some general questions:
0) Is it possible to TX and RX System Exclucsive Midi messages with the Parallax Propeller products?

1) Would any additional electronics be required to send MIDI messages or would the board be capable of transmitting them itself?

2) Is it possible to have the Parallax perform tasks in response to the value of the resistance of a variable resistor?

3) How many variable resistors could be used to encode with various Parallax Propeller products. I actually would only need about 6 pots to make me happy, but why not shoot for the moon! Remember I would need to leave enough pins for MIDI RX and TX?

4) What would be the appropriate resistance for the potentiometer? I know a lot of MIDI interface boards use 20K to 50K linear taper potentiometer.

5) Is there any way I could write a "Learn" function for capturing SysEx messages with the board directly from a devices? (See Note below)
*Learn - Just wondering if I could reprogram the SysEx on the fly by capturing the SysEx output from a device with the Propeller board without using a computer?

This is an example of how a "Learn" button might work:
a) Push "Learn" button
b) LED flash once
c) Move variable resistor to minimum value and push "Learn" button
d) LED flash once
e) Move variable resistor to maximum value and push "Learn" button
f) LED flash twice
g) Send System Exclusive MIDI message string and push "Learn" button
h) LED flash three times to signify button has been programmed.

This is an example of a SysEx MIDI message string containing 97 different messages outputted from a device:
F0 06 09 00 01 01 00 00 00 06 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0C 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0D 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0E 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 07 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 08 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 09 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0A 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0B 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0C 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0D 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0E 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 0F 0F 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 00 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 01 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 02 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 03 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 04 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 05 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7
F0 06 09 00 01 01 00 00 00 06 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7

NOTE: MIDI OX (http://midiox.com) was used to capture the above string from a Lexicon MPX Pro-1 interfaced to a computer using an M-Audio Fast Track Pro.
QuickMacros (http://quickmacros.com) was used to parse out the string and also build the GUI to transmit the SysEx message.
Here's a link to the QuickMacros SysEx forum post: http://quickmacros.com/forum/viewtopic.php?f=4&t=4271&p=18995

So the above string has 97 possible messages. So each 206 ohm change in resistance of 20k linear taper potentiometer would transmit a specific message. Some message strings would contain more individual messages depending on the parameter. Since I would imagine the Propeller (if a learn function is possible) would hold the whole string in volatile memory until the whole process was complete and then store it to permanent memory. Assuming

So the Propeller would need to parse the above string using F0 as the start and F7 as the end and assign those values ranges of resistance within the minimum and maximum values of the variable resistor. So moving the resistor would playback the SysEx message.

Thanks,
Jim

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-01 12:08
    Hi Jim,

    Welcome to the forum. The short answer is. Yes, the Parallax Propeller can do all those things (at least the ones I understood).

    While the Prop can do analog to digital with a couple of resistors and capacitors, I like to use a MCP3208 analog to digital chip with my Propeller projects.

    I haven't used MIDI with the Prop yet, but it's on my todo list (which is getting very long). I know there are several people who have done MIDI projects with the Prop.

    As for as linear pots go, have you seen these? I have a couple but I haven't found a project to use them with yet. They look like they'd work well in your project.

    I know I didn't answer all your questions but you wont be wasting time or money learning to program the Prop.
  • AribaAriba Posts: 2,690
    edited 2011-12-01 13:52
    Hello Jim

    What you describe is certainly doable with the Propeller, it's just a question of the programming skills.
    I think the 40000 is the QuickStart board, which is a good board for your project because it has already some buttons and LEDs.
    And you can add the needed hardware on the 40pin header relatively easy.

    0) MIDI is just a form of serial communication, like RS232. There are several objects for the Propeller which can do that.
    If you send Notes, Controller data or SysEx is just a question of the byte values you send, so the Spin code decides this.

    1) You will need some additional hardware for MIDI OUT and IN. The MIDI Out can be as simple as a single 100 Ohm resistor and the MIDI-Jack.
    A MIDI IN needs an Optocoupler and 2 resistors.

    2) Yes, you need to measure the value of the Potis and detect a change in software, by comparing the new values with the previous measured ones.

    3) This depends on the hardware you add. You can have a matrix of Potis and a fast ADC chip, so you can measure much more then 6 (also 100 if you want).
    The Propeller has 32 pins (28..30 usable on the QuickStart), 6 Potis you can measure with 6 pins (and 6 capacitors + 6 resistors). With an additional ADC (Analog to Digital Converter) you need only 4 pins.

    4) Depends on the harware you add, but both Poti-values are OK.

    5) Yes, this is all just a question of the software you write.


    Andy
  • TheVigTheVig Posts: 41
    edited 2011-12-02 11:08
    Well I think I'm going to start working towards this. Thanks for the answers!

    Posting some links here:
    http://forums.parallax.com/showthread.php?118144-MIDI-Output-%28Via-USB-or-MIDI%29&highlight=Midi+Schematic
    http://forums.parallax.com/showthread.php?128443-Newb-looking-to-make-a-MIDI-controller.&highlight=midi

    I'm going to do this project and probably some more. Any other resources involving prop and midi would be greatly appreciated up front here! I'm gonna buy the board today!

    Thanks,
    Jim
  • TheVigTheVig Posts: 41
    edited 2011-12-05 07:50
    Step 1: Potentiometers
    Getting a reading from a Potentiometer and outputting to the Serial Terminal program window.

    1. What size resistance is appropriate? (I have a box of 20K pots)
    2. What power supply is appropriate? (I have a collection of wall warts in all sorts of voltages, I don't have a very fancy electronics workstation)
    3. How do I physically connect it all together?
    I'm starting work with a single variable resistor to keep it simple. Then I'll build it up to using a matrix with some diodes to minimize the number of used pins
  • TheVigTheVig Posts: 41
    edited 2011-12-05 17:59
    I think this http://forums.parallax.com/showthread.php?111176-PE-Kit-Tools-Measure-Resistance-and-Capacitance&p=791692#post791692 gives me the whole picture for doing what I need. Now to build the circuit and test.

    Using the "RC Resistance Meter" function downloaded from the above URL I was easily able to wire up a 22K potentiometer, a 0.1uF cap, and a 150ohm resistor. Connected the 40000-RT to computer, hit F10 and boom output in the Serial Terminal. Easy 123!
  • TheVigTheVig Posts: 41
    edited 2011-12-05 19:26
    Step 2: Parsing SysEx String
    Take a SysEx String and parse it into its individual commands and distribute them in between the minimum and maximum values of the resistor.

    This will really start to test my ability to learn the syntax and layout of the SPIN program.
    I could easily do this in a few different programming languages, but this SPIN stuff is a lot different than what I'm used to.

    I could use some help ;)
  • AribaAriba Posts: 2,690
    edited 2011-12-05 23:29
    I don't know what you mean with: "parse it into its individual commands "
    You need to know the structure of the sysEx string (or you need to analyze it), there is no common format. There are some rules: All the bytes between F0 and F7 must have bit 7 cleared, but every vendor can define a sysEx string as he wants.

    Anyway here is code that should let you receive such a string over MIDI IN, and show it on the Terminal:
    CON
      _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000
    
      MIDI_RX  = 0                  'MIDI in/out pins
      MIDI_TX  = 1
    
    OBJ
      midi :  "FullDuplexSerial"    'MIDI serial driver
      term :  "FullDuplexSerial"    'Terminal serial driver
    
    VAR
      byte  buffer[40]
            
    PUB Main  | i,b
      midi.start(MIDI_RX,MIDI_TX,0,31250)   'start serial driver with 31.25 kBaud
      term.start(31,30,0,115200)
    
      repeat
         b := midi.rx
    
         if b == $F0                        'sysEx?
           buffer[0] := $F0
           repeat i from 1 to 39            'receive into buffer
             b := midi.rx
             buffer[i] := b
             if b == $F7
               quit
    
           repeat i from 0 to 39            'show on Terminal
             term.hex(buffer[i],2)
             term.tx(" ")
             if buffer[i] == $F7
               quit
           term.tx(13)
    

    And here is a code that sends a sysEx string as you show in your first post, but replaces byte 10 and 11 with a value fom a Poti (these bytes seem to be the only that change):
    _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000
    
      MIDI_RX  = 0                  'MIDI in/out pins
      MIDI_TX  = 1
    
    OBJ
      midi :  "FullDuplexSerial"    'MIDI serial driver
    
    VAR
      long  poti, oldpoti
            
    PUB Main
      midi.start(MIDI_RX,MIDI_TX,0,31250)   'start serial driver with 31.25 kBaud
    
      oldpoti := poti
      repeat
         'get a Poti value here to variable poti
    
         if oldpoti <> poti                 'changed?
           sysEx1[9]  := poti & $7F         'write new value into sysEX string
           sysEx1[10] := poti >> 7 & $7F
           sendSysEx(@sysEx1)               'and send sysEx string
           oldpoti := poti
           
    
    PUB sendSysEx(pointer) | i,b
      i := 0
      repeat
        b := byte[pointer][i++]
        midi.tx(b)
      until b == $F7
    
    DAT
    sysEx1  byte  $F0,$06,$09,$00,$01,$01,$00,$00,$00,$06,$0A,$04,$00,$00,$00,$00
            byte  $00,$00,$00,$04,$00,$00,$00,$01,$00,$00,$00,$01,$00,$00,$00,$F7
    
    I hope this helps to understand the way how it's done in Spin.

    Andy
  • TheVigTheVig Posts: 41
    edited 2011-12-09 14:45
    It all actually looks pretty straight forward so far. I haven't had nearly enough time to play with this section of code (although I did buy a bunch of parts to prep for the job).

    By "Parsing" out the data I mean like this:
    In the SysEx text in the previous post, this would all be one file. I would need to programatically count the number of individual commands, which would be 97 and then assign them to ranges of the resistor. So in the my case, the 22K poti gave a max resistance of 24500 (uncalibrated because I don't really care about the actual value, just the result of the movement) and a minimum resistance of around 150ish (I forgot the actual value). So I would want to distribute the 97 individual commands among the range of the poti. The resolution is not extremely critical.

    So R=24500 would be 97 and send the very last line of the string:
    F0 06 09 00 01 01 00 00 00 06 00 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7

    and R=150 would be the 1st line:
    F0 06 09 00 01 01 00 00 00 06 0A 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7

    Each 251 ohm resitance change would send the corrisponding line of SysEx.

    For example, a value of 3765 ohms would send the 15th line of SysEx:[ SysEx Line = Rv / ((Rmax - Rmin) / n) where n = number of lines in SysEx file]
    F0 06 09 00 01 01 00 00 00 05 0B 04 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 F7

    I guess maybe a bit more information, some SysEx files will be a couple hundred lines while others may only be 50 - 60 lines.


    Thanks for all of your help so far. This has been an awesome project!!
    -Jim
  • TheVigTheVig Posts: 41
    edited 2011-12-09 14:54
    Also, for the MIDI output circuit http://forums.parallax.com/attachment.php?attachmentid=65639&d=1260149221, does it have to be a 3.3V power supply or can I use a 5V power supply?

    I'm having troubles finding anything online about midi voltage supplies. I have seen some folks saying 5V is what they use...so I'm just questioning before I build. I do like to keep the smoke inside my gear!!

    -jim
  • AribaAriba Posts: 2,690
    edited 2011-12-10 00:11
    The MIDI OUT from your link is meant for 3.3V. If you want a 5V version, which is also more safe, you can use such a circuit: (see attachment)

    MIDI works not with voltage levels, but with a current loop of 5mA. That is: a logic 1 is no current, a logic 0 is 5mA current through a 220 Ohm resistor and a LED of the Optocoupler in the MIDI IN circuit.
    So the voltage is not important, only the current that a OUT circuit produces.

    Regarding SysEx strings:
    So you need a lookup table of 97 sysEx strings which are selected by the value of the Poti.
    You can make some changes in my second example above:
    ...
      i := (potiValue - 150) * 97 / (24500 - 150)   'calc sysEx index
      sendSysEx(table[i] - table[0] + @sysEx0)
      ...
    
    DAT
    table long @sysEx0,@sysEx1,@sysEx2, ......., @sysEx7
          long @sysEx8,@sysEx9, ....
    
    sysEx0 byte $F0,$06,$09,$01,.......,$7F
    sysEx1 byte $F0,$06,$09,$01,.......,$7F
    sysEx2 byte $F0,$06,$09,$01,.......,$7F
    ....
    sysEx96 byte $F0,$06,$09,$01,.......,$7F
    
    The calculation of the address looks a bit strange: (table - table[0] + @sysEx0) but this is necessary because you get no absolute addresses with @ inside a DAT section.

    Andy

    Edit: To use the 5V MIDI circuit, you need to invert the TX output of the Propeller, for that you start the MIDI serial driver with: midi.start(MIDI_RX, MIDI_TX, %10, 31250)
    370 x 160 - 2K
  • TheVigTheVig Posts: 41
    edited 2011-12-11 09:43
    Darn.
    I built the circuit for RC decay to measure the value of a poti, I also built the circuit for transmitting midi.

    I put together all of the code from the little snippets in this threads. When I hooked it all up with a MIDI cable to a computer interface and opened up MIDI OX to monitor what MIDI commands are being transmitted by the Propeller, so far it is all gibberish with no SysEx at all.

    I was really optimistic after my really smooth experience with measuring the value of a potentiometer, that I would be able to build the circuits and write the code and get it all working.
    Bummer.

    It is at least transmitting something.
    My heart jumped the first time I turned the knob on the resistor and started seeing movement in the MIDI OX input window.

    Right now I don't know if my code is shotty as I'm still struggling with the SPIN syntax and structure (which is to be expected when switching to a new language).
    Also I can't be sure my circuits are built right because my experience with electronics is pretty low.

    I think I want to see the SysEx message being outputted by the Propeller in the Serial Terminal window so I have something to compare. I'm probably going to pull the whole breadboard apart and start over fresh on the circuits.

    The best part of everything is, No smoke yet ;-)
Sign In or Register to comment.