The aim here is to read 16 pots into the Arduino using a single analog input and to send this data to Max/MSP. Two hardware multiplexers are used for this (4021s). Max then does software-based demultiplexing. The process consumes two analog inputs and three digital pins on the Arduino (plus the RX and TX pins of course).
The 4021 (in multiplex mode) has 3 control pins, 8 inputs and 1 output. The control pins set which input channel is presently routed to the output. 3 Arduino digital pins (2,3 and 4) are controlling this process. 8 pots are connected to the 8 channels on each 4021. The output of one 4021 is connected to Arduino analog input pin 0, the other to 1.
Max "requests" to see data from the Arduino. This is achieved by sending the byte "76" ('L' is for Listen'). Upon receiving a 76 from the host computer, the Arduino goes through a loop of 16 cycles in length. Each repetition reads from a different pot and prints the data back to the host computer.
Max waits for a small amount of time, and groups 16 bytes together in a list that can then be used elsewhere.
In the example video, the bytes are used to control the amplitude of 16 harmonics starting with 100Hz.
By using this "call and response" type setup, the computer knows which byte is which when it is coming out of the computer ie. it's not just a stream of never-ending numbers.
more info:
http://little-scale.blogspot.com/2007/09/multiplexy.html
http://little-scale.blogspot.com/2007/06/arduino-midi-out-example.html
http://little-scale.blogspot.com/2007/06/16-step-microtonal-digilog-sequencer...
http://little-scale.blogspot.com/2007/06/16-to1-hard-mux-soft-demux.html
http://little-scale.blogspot.com/2007/06/hard-mux-soft-demux.html
-------------------------
http://little-scale.blogspot.com
nice job. i'm not familiar with the arduino. So basically, when you send "76", the arduino cycles through all eight selection states on pins 2-4? can you control the speed at which it steps through the states? and can you adjust the A2D resolution on the arduino? and will it work with Pd the same as it does in Max?
badbobbyhughes 4 years ago
You can control the speed at which it steps through the pots by placing a delay(); command in the code, but currently it is just going as fast as it can (for the quickest response across the eight pots). The max ("default") resolution for the Arduino is 10 bits. But because this is sending MIDI control data, the Arduino shifts the analog to digital value left by three bits.
littlescale 4 years ago
If Pd supports a Serial object, then it is possible. Otherwise, it is also possible to send the data over a MIDI interface (with the right code on the Arduino). ;-)
littlescale 4 years ago
would it be possible to use another 3 pairs of 4021s for the analog in 3,4 and 5 on the arduino board? or are there any complications?
sorisos 4 years ago
furthermore, it is then possible to connect the output of a multiplexer into the input of a multiplexer, essentially chaining them together. this allows one to have, say, 256 inputs connected to 9 x 4051s (8 of them connected to 1) and controlled by 8 digital pins.
etc etc.
littlescale 4 years ago
the only complication would be the sampling rate of the multiplexed inputs -- which of course goes down with the number of inputs and multiplexed inputs used in a system.
littlescale 4 years ago