Little problem

Status
Not open for further replies.

Dan

Active member
Hello,

I am converting a volume pedal to usb/midi controllers messages with the Teensy 2 and latest Arduino/Teensy software

The pedal is a simple 10k potentiometer connected with a jack plug to teensy

One pin goes to +5V VCC
One pin goes to 0V GND
One pin goes to an anlogo input (pullup)

Everything is working perfect, but if I unplug/replug the pedal while midi softawre is running, the teensy program does no work anymore

I need to close and start again the midi software to be able to work again

Any idea on this?


My code is :



byte analog1=7;
long t2=0;
long oldval=0;
long newval=0;
long oldvalmidi=0;
long newvalmidi=0;
byte first=1;

...........................................


void loop() {
if (first==1){
first=0;
newval= analogRead(analog1);
}
else
{
newval +=analogRead(analog1);
newval=(newval/2);
}

if (millis()-t2>30) {
t2=millis();

newvalmidi=(((newval+1)*128)/1024);
if (newvalmidi>127) newvalmidi=127;
if (newvalmidi<0) newvalmidi=0;
if (newvalmidi!=oldvalmidi){
oldvalmidi=newvalmidi;
usbMIDI.sendControlChange(11,newvalmidi,1);
}

}
 
If by 'unplug/replug the pedal' you mean that you cause the analog input to 'float' temporarily while the pedal is disconnected then perhaps the (effectively) random stream of values that it returns makes the receiving software (basically) defend itself by ignoring the messages till some sort of reset - there may be another way to reset it (some menuitem etc) but restarting it (obviously) works to reset it when/if this is the case.

Assuming that your project simply must have this functionality, being able to 'put up with' the pedal being disconnected and reconnected, then a way to mitigate this problem (if I am right about cause) is to get a socket which is capable of grounding the pin (which is being read by the ADC) while nothing is plugged in - software in Teensy reads steady stream of 0 and does not bombard the other software with random looking 'choices' while pedal is unplugged.

any good?
 
Thank you for answering

With the input_pullup, I don't have any floating data when it is not plugged in

My problem is not that I receive tons of unwanted data.
My problem is that I don't receive anything more, like if there is a bug on the program, and it stops working

Why?
 
Is it when you unplug/replug the USB connector from your host that program stops working ?

In that case you probably have to reselect the USB MIDI device in your MIDI software, perhaps ask
the software to scan for connected midi devices again. It shouldnt be necessary to restart the software.

If you only have to restart the midi software on the PC side, that is a sign that the Teensy part is still
working.
 
Of course, it is not when I unplug/replug the USB connector, but when I unplug/replug the pedal jack. (anaolg input pullup on it and VCC and GND)

It is very strange

733934_BB_00_FB.EPS_1000.jpg
 
If you are saying that in the setup() function you are hiding from us that you have 'pinMode(analog1,input_pullup);' then I wonder if that works how you hope it will - pins on Teensy 3.1's processor can be configured in some pretty advanced ways and it would not surprise me to learn that the pin is deconfigured as anything digital before being read by the ADC module - easy enough way to test this is to measure the voltage at that pin while the pedal is disconnected and the software is running; if it isn't a steady 3.3V (or reasonably close at least) then 'input_pullup' isn't working.

If you are saying that you have a resistor placed to pull it up then I can't help but feel compelled to advise you to 1) pull it down instead and 2) you are better off not 'pulling' it whilst trying to read the pedal, the right version of that jack you picture there makes it easy to ground the ADC input while the plug isn't in.


I cannot see the problem in the code you have posted, maybe it is in your setup() function.
 
For testing, I'd replace that USB MIDI message with Serial.print() and watch what happens in the Arduino Serial Monitor as you plug and unplug and reconnect the pedal. Maybe even add more Serial.print() in other places in the code, as necessary, for example to see what analogRead numbers you're actually getting.
 
Yes I set this,

void setup()
{
pinMode(14, INPUT_PULLUP); //14=Analog input 7
}

I am using Teensy 2 and I get 4.85V on the unplugged pin and 5.04V on the VCC PIN




mmmm..... It seems that while connecting on this jack socket, there is a short cut between the GND and the VCC, and this reboot the Teensy 2 (usb sound on Windows that I was not able to hear with pro audio sound card)

This is crazy ! I don't know what to do

This jack socket is smart. In fact, you have 6 pins. 3 in each side

When jack is unplugged, The 3 pins from the right,(that you see on the picture), are touching the 3 other from the left.

When you plug the pedal, only the 3 pins from the right touch the pedal pins, and the 3 other get nothing

Do you have any idea of what I can do?
 
Yes I set this,

void setup()
{
pinMode(14, INPUT_PULLUP); //14=Analog input 7
}

I am using Teensy 2 and I get 4.85V on the unplugged pin and 5.04V on the VCC PIN




mmmm..... It seems that while connecting on this jack socket, there is a short cut between the GND and the VCC, and this reboot the Teensy 2 (usb sound on Windows that I was not able to hear with pro audio sound card)

This is crazy ! I don't know what to do

This jack socket is smart. In fact, you have 6 pins. 3 in each side

When jack is unplugged, The 3 pins from the right,(that you see on the picture), are touching the 3 other from the left.

When you plug the pedal, only the 3 pins from the right touch the pedal pins, and the 3 other get nothing

Do you have any idea of what I can do?
Ok, sorry, missed Teensy 2.0 spec; you are right and looks like input_pullup is working for you - I personally don't like it, I think it will be making the range your pedal can 'present' (to the ADC) be shortened.

About your jack/socket which connects VCC to GND while unplugged: You want the 'left' hand pin which is nearest the VCC pin to have no wire going to it, you want the right hand pin of the 'signal' (wiper on pot in pedal) to go to Teensy 2.0 and you want GND to be on the remaining pin on the right hand side - if you will take my advice then remove the 'input_pullup' code and wire GND to the right hand pin facing the 'signal' pin which should zero your ADC reading from the pin quite precisely.

Checking your ADC results with some serial output will tell what is and isn't working so well for you in regard to your wiring for it.
 
It seems that serial monitor does not work with USB MIDI mode. I have nothing on it

But, I hear the windows USB unplugging noise exactly when the jack is in a position in between the VCC and GND pins. So I am 99% sure it is a shortcut there.

This is strange. How all midi keyboards are doing for reading a pedal if when you plug it, it short cut its 5V pins
 
oh, it is not because you wired GND to too many places on socket - it is because barrel of plug connects the two terminals momentarily - soz.

That is going to be hard to beat, maybe you just need a seperate power supply for the pedal.

Edit: A 1K resistor between jack 'V in' pin and Teensy 5V pin will modify the range read from the pot in the pedal but it should be enough to keep the Teensy running while the plug is moving in the socket.
 
Last edited:
Input pullup was tested one year ago to give more accurate reading.

You can see here this plug with many pictures http://www.thomann.de/fr/neutrik_nys216g.htm

The stereo Jack has 3 pins. tip is variable potentiometer middle ring is 5V sleeve is GND

The problem is when I plug the jack, there is a little touch between GND and 5V when it is half connected

Maybe there is a way to unconnect the 5V, until I detect that the jack is fully plugged in?


When the jack is deconnected, the pins from left and right touch each other
 
You could connect a 100 ohm resistor in series with the 5V line. It will limit the current to 50 mA when the plug momentarily shorts 5V to GND.

It will also limit the analog values you'll read. If the pot is 10K, the effect should be only a 1% loss of the measurement range.
 
Hey this is perfectly working :)
I had only 220 ohm resistors, so I used it.
It reduce a bit the range, but a midi controller is value from 0 to 127 so we don't really loose precision

By the way, I have done my first soldiering :) woow :)
 
Very old thread, but is there any software solution for this? without adding a resistor ?
I mean. to read my "volume" pedal , I use 3 pins : the +5V, the GND and one analog input pin
The problem was that connecting the pedal jack while teensy is running was causing a short cut, and reboot the teensy USB/MIDI
Is it possible to set the voltage at 0, until the pins detects it is connected, then open the 5V ?
 
adding A resistor is the easiest solution. If you don’t want this, you could use a socket with an extra switch (expensive and hard to find) which would only let the 5V through when the plug is fully inserted.
 
Did you ever confirm that it was a short between hot and ground that was causing Teensy to crash? The other possibility is that your code sends so much data when the wiper is allowed to float that the event queue fills up and freezes usbMIDI communications making appear your device has crashed.

I can't see how HIGH is getting to ground as ground is always the sleeve and should never see the hot (which can be in the ring or tip position).

My Footsy controller uses extension pedals and I've never crashed it pulling the plug.

It pulls HIGH (as I didn't have the flexible jack with six contacts you have and mine only allowed me to pull to HIGH) but it works fine even if the controller will jump to 127 instead of 0 when you pull the plug when it's running.

If the current limiting resistor is needed and impacts the voltage range (prevents the voltage divider from providing the full analog range) you should be able to remap the output to give you full MIDI range.
 
Status
Not open for further replies.
Back
Top