Advice & comments on the best way to read an Arduino Uno with 92 pins!


    Feb 22 2016 | 1:41 pm
    Hi, I'm creating a creating a DJ system using Max 7.1 (mac, OS X el cap) and an Arduino Uno R3 that is being expanded to 92 I/O's. I have just received the parts to expand the Arduino and starting to create the code for addressing the expanded I/O's. The Arduino code will only send pin data to Max if its current value is different to its previous value to increase the efficiency of the system and prevent artefacts in the audio from processing input data. A DJ has only one pair of hands so a maximum of two functions, at any given , time, will be generating new values.
    Whilst the Arduino is being expanded I need to start work on how Max will handle all those inputs. This is a project for uni and am working against deadlines, this is an ambitious project but this area is where I would really appreciate some advice or comments, so that I don't spend valuable time researching the wrong/inefficient way of doing this and having to create new patches each time..
    From my understanding there are several ways of doing this (as is always the case!!) but having not used them I'm not sure which way I must do this.
    The first thing that Max must do when it loads is read all the Arduino pins (assigned) so that the values correlate to each other; i.e if a hardware fader is half way up then the fader it correlates to in the software will also be half way up. After that Max will only need to respond to the new values that are sent from the Arduino.
    There are three methods that I understand could do this but I'm not sure which is the best, or if there is a better way:
    1) I could be to read the Arduino pins and have a [router] for routing an input based on its ID. 2) expand Maxuino to take in the extra pins 3) use a matrix to store the data and send it to a function (I've never used matrices but will learn if this is the best way :) )
    Many thanks in advance

    • Feb 22 2016 | 1:59 pm
      I'd take the first approach (BTW, the object is called [route] ;) ), and write a "dump" function in the Arduino code to be called by Max when the patch opens.
    • Feb 22 2016 | 2:31 pm
      @LSKA , thanks for the advice about [route] ;) That was my original intention but felt it was better to ask and be-safe-than-sorry :)
    • Feb 22 2016 | 3:06 pm
      Me too. I'd get initial values by polling all input pins via a for loop, in the setup( ) function, the do the same inside the loop( ) function, but with a simple gate to only send if changed. Tag each sensor with a header and use [route] to parse everything out, as LSKA says.
      My concern would be the tradeoff between baud rate and latency. A delay(1) inside the for loop will obviously result in around 100ms latency - unless of course you are multiplexing. And I would guess that higher baud rates with 96 discrete sensor values would cause choking/hanging of the COM port HTH Brendan
    • Feb 29 2016 | 1:37 pm
      @ Brendan, Many thanks for that :) I agree that having a routine to poll the pin values, on the initialisation dump, is a good idea and I'll definitely look into that. You're correct about the multiplexers - I'm using a couple of Mayhew Labs, MUX Shield 2 for this project. From my conversation with the sales guy; the Arduino has an inherent delay/warm-up time when reading pins and that time can also vary. The shields can be read with a delay of 2ms (if memory serves me correctly), so all the inputs will be connected to the shields.
      You're concern about baud rate and latency are also my main concerns too. Another concern is that the CPU is processing all the audio, so I need to restrict the amount of data sent from the Arduino to keep CPU usage to a minimum.
      There's enough memory on the Arduino Uno to store the previous value of each pin for comparison, so a value is only sent if it is different. Another key factor is that a DJ has only two hands, so only two values can be changed at any given time. I will need to [ramp] the analogue input values to produce smooth control over the Max functions, so I'm hoping that this may help overcome a bit of latency?
      Once the final Arduino code is written and all the parts assembled, I'll let you know how I get on, and possibly ask a couple more questions. If you have any further comments/suggestions/advice I'd still be happy to hear it :) Cheers