SensorBox and more analog inputs with Arduino Mega


    Jun 16 2012 | 5:59 am
    Hi
    I am trying to get more than 6 analog inputs, into max from my Arduino Mega board (It has 16 , I want to use eight for now)
    I have tried fiddling with both the sensorbox patches, with no luck
    Do I need to change the arduino code maybe? (I took a look at it, but couldn´t figure out what needed to be changed if anything (to be honest my programming skills with the arduino are quite limited))
    Anyone have any clue?
    All the best

    • Jun 16 2012 | 8:27 am
      Hi I'm not familiar with Sensorbox, but look for the statements
      analogRead() and Serial.write().
      Depending on the version of the Arduino IDE you use it may be
      analogRead(A0); //for pin 0 and
      Serial.print(foo, BYTE); //or Serial,write(foo);
      You simply need to add further read and write statements for the extra input pins; the Mega (and Arduino 1.0) use A0-A15 (or 0-15).
      Maybe show us the Sensorbox Arduino sketch?
      Brendan
    • Jun 16 2012 | 8:43 am
      Slightly off-topic: Brendan, I think it's about time you put together a tutorial for the front page. It seems that every Arduino question ends up being answered by you. I know I'm mainly a Maxuino man, but I reckon a comprehensive tutorial specifically about interfacing with Max would get me rolling my own Arduino sketches more often!
    • Jun 16 2012 | 9:50 am
      Hi dickmedd not OT; in fact good call.
      If this idea receives any +1's then I'll certainly put a short toot together. Meanwhile, there's some serial interfacing instructions on my blog
      Brendan
    • Jun 16 2012 | 12:26 pm
      Hi Meister Noob
      Thanks for the reply
      this is the SensorBox I am talking about
      Can´t seem to find (in the proccessing/arduino code) where I can specify more analog inputs.
    • Jun 16 2012 | 12:34 pm
      + 1 :)
      mat
    • Jun 17 2012 | 1:19 pm
      I had a brief (and inexpert) glance at Andrew's Arduino sketch, and he is using an array to store/read/send values from the input pins, digital and analog. He's also doing some bit-manipulation to get the full 10-bit resolution into Max; this method is a little unfamiliar to me, but I see what he's doing.
      Besides writing a complete sketch and patch to access the extra analog inputs for you, the only thing I can suggest is you might try changing the local variable "g" range here:
      //read analog pins for (int g = 0;g packValue(g); } char total = current+1;
      Which is filling the array with analogValues from pins 0 -5
      from g
      for (int g = 0; g
      This MAY help address inputs 0-15 BUT it may well break the sketch too, and furthermore you'll have to make changes to the Max patch to accommodate the extra input. Do so at your own risk, sorry I don't have more time to solve this for ya. And I also hope Andrew doesn't chip in to WAIL on me, for dispensing ignorance.
      Brendan
      ps Anymore +1's and I'll post a short toot on accessing all analog inputs via a DIY Arduino sketch and Max patch. On my new ASUS n-series. And Max6. :p
    • Jun 17 2012 | 2:12 pm
      Load this onto your board:
      //read all analog inputs on the Mega 2560; //check inputs using Serial Monitor; //then delete/paste some code to send output to MaxMSP
      int touchVal;//sensor reading
      void setup(){ Serial.begin(9600); }
      void loop(){ //n00bs array for(int x=0; x touchVal=analogRead(x); //scale 0-1024 (10-bit) input to 0-c.200 (8-bit) output; //depends entirely on the given circuit/current touchVal/=5; ////////////////////////////////////////////////////////// //replace all the following lines with those at the bottom //when you are finished using Arduino serial monitor //to check everything, and ready to send to Max: Serial.print(x);//print "header" identifier, followed by... Serial.print(" = "); Serial.print(touchVal);//the sensor value Serial.print(" ");//i forget how to print a tab } Serial.println(); delay(50); }
      /* void loop(){ Serial.write(x);//print "header" identifier, followed by... Serial.write(touchVal);//the sensor value } delay(50); } */
      In Max all you need is:
      [metro 20]
      [serial c 9600] (port identifier will obviously differ)
      [zl group 2]
      [route 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
      Brendan
      ps rarely, I may have to send these messages to the serial object:
      1. close 2. open port c
      to get the stream to settle down, but only like once in 100 times.
    • Jun 17 2012 | 2:26 pm
      +1
    • Jun 17 2012 | 4:23 pm
      Thanks NoobMeister :)
      Ill try what you suggest later on
      I will also give you a +1 (the analog pins are the only thing I use on my arduino)
      All the best
    • Jun 18 2012 | 3:13 pm
      Hi As requested, I've posted a very short and simple (and silent) toot on my blog and youtube, demonstrating the code and patch I wrote to access all 16 analog pins of the Arduino in MaxMSP.
      Haven't got a decent soundcard yet for my brand spanking new rocket-ship ASUS, so apologies for the silent video.
      Brendan