My name is Peter and I'm a newcomer to the whole Arduino game. So please be patient with me, if I am rather slow on the uptake when it comes to transistors and capacitors.
I'm in the early stages of a project which is doomed to failure if it weren't for your advice. I'm sure I'm going to have a lot of questions along the way, and I'd be thankful if you could give me some pointers about this first one.
Here's what I want to build: The working title is "modular modulator" (picture attached). It is a box I want to use alongside my midi keyboard to modulate sounds by sending midi cc data. In addition to a standard mod wheel (a rotary potentiometer fixed to a wheel), I plan to install a couple of din 5 sockets, so that I can plug in different little gadgets when needed, for instance a breath sensor, a nunchuck controller, or an ultrasonic distance sensor. I did some prototyping using the Arduino Uno, but when I make the actual build I will switch to a Teensy 2.0 for its Midi-USB compatibility.
Now, here's my first question: For test purposes I soldered a potentiometer to a Din 5 cable, and plugged it into the socket, and it worked fine. However, the trouble is, when I unplug it, the socket keeps sending absolutely random data. Is there a way I can avoid this, or do I have to install mountain switches "upstream"?
but when I make the actual build I will switch to a Teensy 2.0 for its Midi-USB compatibility.
You can use an Arduino Leonardo or Micro with the same capability.
the socket keeps sending absolutely random data
Yes it will do. This is known as a floating input and will happen with digital and analogue inputs.
The simplest cure is to just put a high value pull down resistor on the input as well as your pot. That has the side effect of reducing your pot's range a bit.
One way round it is not to disconnect your pot at all.
Finally the real, but complex way round it is to connect the two ends of your pot to two digital output pins. Then before you do a reading set one high and the other low and take a reading. Then reverse the high and low and take the reading again. Now if the two readings are the inverse of each other then you have a pot connected otherwise don't use that reading to send the value.
The inverse means reading1 = 1024 - reading2
But there is a bit of wriggle room here which is what makes it complex.
I think I will opt for the simplest cure, but being an electronics-simpleton I still don't quite know what it entails. From what I understand, to install a pull-down resistor means to connect to ground via e.g. a 4.7 kΩ resistor, right?
I just tried putting together a wiring scheme for my project. Could you maybe have a look at it, and let me know if I'm terribly far out?
A little explanation: The first din 5 socket I intend to use with sensors running on 3.3V and one or two analog outputs, for example the nunchuck controller. That's why I patched in a voltage regulator there.
The other two sockets I am going to use with 5V sensors, for example the breath sensor. The wiring in the cables doesn't really follow a standard procedure, but it shouldn't really matter as long as I'm consistent in my project, or would it?
The last four switches (in reality on-off mountain switches) I hope to be able to connect directly to the digital inputs without experiences floating, because all of the digital pins on the teensy have a pullup resistor built in.
From what I understand, to install a pull-down resistor means to connect to ground via e.g. a 4.7 kΩ resistor, right?
That resistor is a bit low. What you need is something like a 47K to 100K resistor, this will have less effect on your sensor when it is plugged in.
I just tried putting together a wiring scheme for my project.
No that is not a schematic, that is a physical layout diagram and it is useless for seeing if the circuit is OK. You have to convert it into a schematic in your head and for anything more complected that you have here it is useless.
I can't see how the resistor you have pulls down your analogue inputs. Also that regulator needs decoupling capacitors on both the input and output. See the data sheet of your specific manufacturer for the values to use. It also looks wired up wrong as regard to pinout. Note you should not feed a 5V signal into a 3V3 processor.
all of the digital pins on the teensy have a pullup resistor built in.
They do but you have to enable them in software for them to work. The circuit is wrong here anyway as you need to connect the push switches between the input and ground NOT the +ve supply voltage.
Here's another shot at (what I hope really is) a schematic. For simplicity's sake I limited it to the hook-up of the 3.3V Din5 connector. I think if I understand this part in its entirety, the rest should fall into place.
Does it look okay? (The values of the capacitors are only exemplary, because I haven't settled on a particular voltage regulator yet.)
Is there a way I can use one pull-down resistor for multiple outputs?
So, I decided on a voltage regulator, completed the schematic, and ordered the missing parts. If everything goes well, I will build the thing next week. In the meantime I will work out my first plug-in gadgets and dabble in code-writing. So, more likely than not, I'll come around for more questions before the solder is dry.
Alright, I'm back. The build turned out a little more complex than I anticipated. Who would have thought, for instance, that the weight distribution in a mod wheel would be such a big issue. But I'm on the home stretch as far as building goes, so now it's time to tackle the code writing. Hopefully someone can help me a little bit, because I'm as inept there as I am with electronics.
I tried a little code to test my mod wheel. And it works fine when I choose "USB-Type: Serial" and then process it with the Hairless MIDI Serial bridge. The trouble is, when I use "USB-Type: MIDI" it doesn't work. I do find the "Teensy MIDI" in my device manager, and also in the Hairless MIDI Serial bridge, but it doesn't appear to send any data. Midi-Ox even crashes, lamenting: "Teensy MIDI: There is not enough memory available for this task. Quit one or more applications to increase available memory, and then try again".
Here's the code in case it's relevant:
int controlChange = 176;
int controllerNumber = 21;
int controllerValue = 0;
int potiValue = 0;
int controllerValueOld = 0;
void setup() {
Serial.begin(31250);
}
void loop() {
potiValue = analogRead(A0);
controllerValue = map(potiValue, 510, 29, 0, 127);
if (potiValue > 28 && potiValue < 511) {
if (controllerValue != controllerValueOld) {
Serial.write(controlChange);
Serial.write(controllerNumber);
Serial.write(controllerValue);
}
}
controllerValueOld = controllerValue;
}
I might as well address my next problem right away. (Or is it better to start a thread for each problem?)
The A1 to A4 pins behave very odd. Pins A1, A2 and A4 display default values of around 312. When I plugin a potentiometer I only receive values between 312 and 318 max. The same happens when I plug-in the pressure sensor.
(Pin 3 is a whole other story. Default value of sometimes 0, sometimes 1023. When the pot is plugged in I get values between 872 and 876, and sometimes nothing at all. So I probably messed up soldering here.)
So how could that be? Why so little range?
My first idea is that I've bungled the wiring of the pull-down resistors. Here's a physical layout with the actual stripboard I'm using, limited to the wiring of the 5V socket. Do you see a mistake there?
I suppose not, because I don't even understand what you mean by "the other end of the pull". I have it wired as depicted in the jpeg I attached. The resistors branch off from the analog input wires to ground. Is there something missing in the picture? Or is your question whether I established these connections successfully?
because I don't even understand what you mean by "the other end of the pull".
You have a resistor going to the analogue input to the ground. The other end is the sensor wire connected to this input.
If you are not seeing a zero on the analogue input with just the pull down resistor then you have not wired this bit up correctly. You say you are seeing a "default" value of 300 or so. I assume this default value is with nothing plugged into your DIN socket. If this is so you have not wired it like you think you have. In otherwise there is a miss match between your schematic and your wiring, somewhere. Take your voltage meter and measure the input on the processor pin and on your DIN socket, these should be the same values. If you haven't got a meter then $5 at the thrift store will get you one.
You were spot on! I had botched it.
But I found and fixed my silly mistakes and touched up a couple of solder joints, and now the default values are down to 0 and the breath controller works like a charm.
So again, thank you so very much!
I will build a case for the sensor and the valve now, close up the case of the main device, round out the code, somehow establish true midi, and eventually present the finished project to you and the forum.