Digital Music Programming II: flex sensor continuous controller




    This lab demonstrates how to read a variable resistance and extract continuous control data from a sensor using an A/D converter. In this case a flex sensor is used as the sensor. The flex sensor was first used commercially in the Power Glove (1989) by Mattel for Nintendo games where the sensors were used to monitor the positions of the human hand for display in realtime on a TV screen.

    In the rcfsr you learned how to use an RC circuit to measure the resistance of a potentiometer (in that case, a force-sensing resistor). The measurement was done by measuring the discharge time of the capacitor after charging it for 1 millisecond.

    A more sophisticated and faster method for measuring the resistance of a potentiometer is to use an A/D converter. In this case we will use the Maxim MAX1270 8-channel, 12-bit A/D converter, although most any will work, depending on your application criteria.

    The MAX1270 takes a measurement of the voltage on each channel in 3 microseconds or less, and has a maximum sampling rate of 110,000 samples per second (which is faster than the Basic Stamp and MIDI can process). The input voltages can range between +/- 16.5 volts, and the expected voltage range can be programed to: -10/+10, -5/5, 0/10 or 0/5.

    Here is a schematic of the circuitry connecting the MAX1270 A/D converter to the Basic Stamp IIsx for use with this program:

    Into the MAX1270 channel 0, plug in a flex sensor using one of the following two circuits:

    The Basic Stamp and the MAX1270 chip use serial communication to talk to each other. To read a sample, you send a control byte to the MAX1270 telling it which channel to measure, and what voltage range to use. The Basic Stamp then receives the measured data from the MAX1270 chip.

    Communication between the Basic Stamp and MAX1270 is done synchronously. The MAX1270 is a slave to the Basic Stamps clock which is sent out on P11 from the Basic Stamp and received on pin 5 of the MAX1270. Any clock speed up to 2.0 MHz can be used to communicate with the MAX1270.

    Multiple MAX1270 chips can all share the same three wires of clock, digital input and digital output. Each must have a separate Chip Select connection to the Basic Stamp. When the Basic Stamp wants to use a particular MAX1270 chip, it sets the Chip Select connection to 0 volts. This activates that particular chip for use on the other three wires. In this way, you can (easily) hook up 8 MAX1270 chips (64 sensor inputs total), plus one MIDI output on one Basic Stamp.

    adflex.bsx
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    
    
    sleeptime    con   100    
    bytea        var   byte     
    byteb        var   byte     
    midicommand  con   $A0    
    midioutpin   con   7    
    midirate     con   60    
    clockpin     con   11    
    cspin        con   10    
    outputpin    con   9    
    inputpin     con   8    
    msb          con   1    
    behindclock  con   2    
    controlbyte  con   %10000001
    
    top:
       gosub ReadSensorData         
       gosub SendSensorData         
       pause sleeptime
    goto top
    
    ReadSensorData:
       bytea = 0
       byteb = 0
       shiftout  outputpin, clockpin, msb, [controlbyte \ 8]
       shiftout  outputpin, clockpin, msb, [0 \ 4]
       shiftin   inputpin,  clockpin, behindclock, [bytea \ 7]
       shiftin   inputpin,  clockpin, behindclock, [byteb \ 5]
    return
    
    SendSensorData:
       serout midioutpin, midirate, [midicommand, bytea, byteb]
    return

    Resources