Hi, iv been working on a project for school where Im using the arduino as a microcontroller hooked up to 24 potentiometers as im trying to build a controller for my Pure data patch. The patch itself is on a seperate raspberry pi, but i was wondering since im new at programming/electronics whether the arduino mega can handle reading from 24 potentiometers? this might be a very stupid question and i apologise for that.
If i had to make a circuit with these 24 pots, would i need to take any special considerations ? such as the value of the pots since i'll be hooking up so many together. What would be the correct circuit for such an application, or a starting point for building such a circuit? i understand how to connect the potentiometers but im uncertain if hooking up so many potentiometers together would create power issues due to too much resistance in the circuit?
Your help is much appreciated!
THanks
-A fellow Noob trying to build his first pedal
Look at the data sheet . How many analog inputs on a mega?
When you've done that , come back and tell us what you want to do with all those readings. It may be possible.
Allan
Thanks your reply Allan!
Im aware the the mega only has 16 analog inputs but i plan on expanding that using one of these to expand the analog inputs:
I would like to send the readings into a pure data patch(A programming enviornment for Audio processing applications) to change parameters within my patch. so in i have some ranges of numbers that need to be swept through using the potentiometers (example, range between 0-2000, with the pot choosing numbers in between, with the value 0 at 0 resistance, and the value 2000 when the pot is turned all the way to the right and letting through full resistance.
Sorry for my wording, im very new to programming
Such a shield would work fine. If you use pots of a fairly high value - I suggest 10k - there is no problem with excessive power consumption.
You'll need a software driver for the shield, which can be downloaded.
Regards
Allan.
whats the cost to add another mega instead ?
Another Mega is way more than just an analog switch like 3x DG408, each one feeding an analog input.
Or two of DG406
analogRead() outputs 0 to 1023, if you wan 2000 you'll have to manipulate the results a little, like multiply by 2.
Either way, set 3 or 2 output bits to select a channel, then read from the 3 or 2 parts.
Thanks for the advice guys! so hooking up 24 x 10K Pots through a ground and 5v rail will work fine? no additional things needed?
As for the shield, i still need to dig into it and see how it works properly, will get back to you once i hook up a bunch and test things out!
MUX speed and on-state resistance seem like rather unimportant specs for this application. I'd be temped to buy three $0.20 4051 ICs and be done. While breadboarding, maybe stick a few hundred ohms of extra resistance between the MUXs and the Arduino, just in case a code bug has you turning one of your analog inputs into a digital output while a pot is pegged to either 5V or GND.
Thanks for the input guys, iv been testing things out and iv gotten Pure data on the PI to communicaet with the arduino using the Firmata library, there is an object in pure data that allows for easy communication between them through the serial port(usb), but i was thinking when i add the MUX Shield and upload its own sketch for controlling the analog ins, i wont be able to upload the firmata communication protocol than would i? i mean i can only have one sketch at a time on the arduino, is there someway i could merge the two sketches for my own application? in this instance that would mean have firmata allow the inputs on the MUX Shield to communicate with the pduino object. Is that possible?
I appologise again if these are extremely newbie questions but coding is a completely new area for me, Hence its difficult trying to word and explain problems correctly so i do apologise
So heres the sketch for the MUX Shield im using, it seems the codes pretty short:
//This example shows how to use the Mux Shield for analog inputs
#include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
void setup()
{
//Set I/O 1, I/O 2, and I/O 3 as analog inputs
muxShield.setMode(1,ANALOG_IN);
muxShield.setMode(2,ANALOG_IN);
muxShield.setMode(3,ANALOG_IN);
Serial.begin(28800);
}
//Arrays to store analog values after recieving them
int IO1AnalogVals[16];
int IO2AnalogVals[16];
int IO3AnalogVals[16];
void loop()
{
for (int i=0; i<16; i++)
{
//Analog read on all 16 inputs on IO1, IO2, and IO3
IO1AnalogVals = muxShield.analogReadMS(1,i);
_ IO2AnalogVals = muxShield.analogReadMS(2,i);_
_ IO3AnalogVals = muxShield.analogReadMS(3,i);
* }*_
* //Print IO1 values for inspection*
* Serial.print("IO1 analog values: ");*
* for (int i=0; i<16; i++)*
* {*
_ Serial.print(IO1AnalogVals*);
Serial.print('\t');
}
Serial.println();
}*
is there someway i could merge this code with the StandardFirmata Sketch somehow so that it reads the correct pins (the ones on the mux shield rather than the analog IN's on the arduino itself) ?_
is there someway i could merge this code with the StandardFirmata Sketch
Sure it can be done, but can you do it?
The source code is available for both so their is nothing stopping you, apart from the fact that the concept of Firmata is that the Arduino becomes a lobotomized I/O unit and it would help you enormously to use some of the intelligence inside the Arduino to reduce the load on PD.
For example you have 24 pots, you need to read them often to see if anything has changed. With a Firmata type lobotomization that involves sending a command to read and getting the value back, then having PD do something with that value. Most of the time that will be nothing of any consequence but you have wasted time doing it.
But if you let the Arduino code look at the pots and only when a value changes send that information to PD. It cuts down on the traffic and lets PD have more of its own time doing the sound processing stuff.
Using two Arduinos is only a popular solution amongst beginners, it often causes more problems than it solves.
Why did you not post this in the Audio section?
Thanks for your reply Mike! much appreciated
And that is a brilliant piece of advice on saving some cpu there, since this is my first project on something like this i decided to go at it one step at a time and test things before i proceed further, i just wanted to see if it was possible and then was going to look into how i could optimize it further. But after your explanation of firmata it seems using it would effectively put more stress on the arduino rather then putting in custom code for forwarding pot values onto PD (Have i understood this correctly?).
As for why i had not posted this in the audio section, Sorry im new here and I i started out this thread a while back when i was still tryign to figure out what value pots were commonly used and if i'd need to put any special attention to the circuit if i was going to wire so many.
But after your explanation of firmata it seems using it would effectively put more stress on the arduino rather then putting in custom code for forwarding pot values onto PD (Have i understood this correctly?).
Well I would not have expressed it that way. You are taking the load off PD and as you know, or should know if you have used it much, needs all the cpu cycles that it can.
void loop()
{
for (int i=0; i<16; i++)
{
//Analog read on all 16 inputs on IO1, IO2, and IO3
IO1AnalogVals= muxShield.analogReadMS(1,i);
IO2AnalogVals = muxShield.analogReadMS(2,i);
IO3AnalogVals = muxShield.analogReadMS(3,i);
}
//Print IO1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO1AnalogVals;
Serial.print('\t');
}
Serial.println();
}
At the risk of seeming picky, surely this should be :
void loop()
{
for (int i=0; i<16; i++)
{
//Analog read on all 16 inputs on IO1, IO2, and IO3
IO1AnalogVals[i] = muxShield.analogReadMS(1,i);
IO2AnalogVals[i] = muxShield.analogReadMS(2,i);
IO3AnalogVals [i]= muxShield.analogReadMS(3,i);
}
//Print IO1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO1AnalogVals[i);
Serial.print('\t');
}
Serial.println();
}
Allan
Grumpy_Mike:
But if you let the Arduino code look at the pots and only when a value changes send that information to PD. It cuts down on the traffic and lets PD have more of its own time doing the sound processing stuff.
this is the part im trying to work on, where should i be looking to start on coding something like that
Start by writing some code that looks at all the Arduino analogue inputs and only prints them out when the values change.
So you have to save the value from last time you read them and compare it to this time and if they are not the same then print it out. Start off with one pot.
You might want to improve it so you look for a change of say two in the reading before you send it in which case the "abs" function is worth looking at.
Thanks for the help guys, this thread can be closed. Im at the point where i need to condense my modified firmata protocol with the Mux Shields library, so that Firmata can detect the inputs/outputs off my MuxShield rather then the arduinos on Analog Inputs.
AdamBlaze:
this is the part im trying to work on, where should i be looking to start on coding something like that
Create intermediary tracking variables which "remember" the value of the previous loop iteration and only output over serial if the previous tracking variable is different than the new analog read value.
Something like this I believe:
#include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
//Arrays to store analog values after recieving them
int IO1AnalogVals[16];
int IO2AnalogVals[16];
int IO3AnalogVals[16];
//Arrays to store the previous analog values into for tracking reasons
int IO1PreviousVals[16];
int IO2PreviousVals[16];
int IO3PreviousVals[16];
void setup()
{
//Set I/O 1, I/O 2, and I/O 3 as analog inputs
muxShield.setMode(1,ANALOG_IN);
muxShield.setMode(2,ANALOG_IN);
muxShield.setMode(3,ANALOG_IN);
Serial.begin(28800);
}
void loop()
{
for (int i=0; i<16; i++)
{
//Store the old values from last loop for tracking reasons
IO1PreviousVals[i] = IO1AnalogVals[i];
IO2PreviousVals[i] = IO2AnalogVals[i];
IO3PreviousVals[i] = IO3AnalogVals[i];
//Analog read on all 16 inputs on IO1, IO2, and IO3
IO1AnalogVals[i] = muxShield.analogReadMS(1,i);
IO2AnalogVals[i] = muxShield.analogReadMS(2,i);
IO3AnalogVals[i] = muxShield.analogReadMS(3,i);
}
//Print IO1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
//Only print the output to Serial if the value has changed since the last reading
if(IO1PreviousVals[i] != IO1AnalogVals[i])
{
Serial.print(IO1AnalogVals[i]);
Serial.print('\t');
}
}
//Print IO2 values for inspection
Serial.print("IO2 analog values: ");
for (int i=0; i<16; i++)
{
//Only print the output to Serial if the value has changed since the last reading
if(IO2PreviousVals[i] != IO2AnalogVals[i])
{
Serial.print(IO2AnalogVals[i]);
Serial.print('\t');
}
}
//Print IO3 values for inspection
Serial.print("IO3 analog values: ");
for (int i=0; i<16; i++)
{
//Only print the output to Serial if the value has changed since the last reading
if(IO3PreviousVals[i] != IO3AnalogVals[i])
{
Serial.print(IO3AnalogVals[i]);
Serial.print('\t');
}
}
}