Use TX and/or RX for SPST switch WHILE sending OUT data? - I've searched - sorry

Can I be sending OUT MIDI data -
WHILE using -- Digital Pin 0 (RX) AND/OR Digital Pin 1 (TX) as switch inputs?

In other words can I hook up an SPST momentary to either RX or TX pin 0 and/or 1 and with standard/correct sketch
hit the SPST switch and transmit MIDI data??

IF YES does it require clever code to do it or code-wise would I use exactly what I'd use for the OTHER digital pin inputs?
Can all code be the same for each pin INCLUDING either pin 0 or pin 1.

All digital inputs (or as many as possible) will be connected to SPSTs and all will be sending almost identical MIDI data when pressed.

hope as asked that well enough.

thank you

ioflex:
Can I be sending OUT MIDI data -
WHILE using -- Digital Pin 0 (RX) AND/OR Digital Pin 1 (TX) as switch inputs?

Depends. Where is your MIDI being output? If on pin 0 or Pin 1, then no.
Also, if you're using the serial monitor the answer is no.
When you're loading a sketch, the switch will have to be disconnected.

You don't need to use an interrupt to watch the switch be moved at human speed.
Just debouncing the switch will take a few millis.

ioflex:
All digital inputs (or as many as possible) will be connected to SPSTs and all will be sending almost identical MIDI data when pressed.

Well now, clearly you are using the serial port connections 0 and 1 for MIDI communication.

If you are connecting one switch to each input and running out of inputs, you are clearly doing it wrong. You need to multiplex the switches (or keys) in a matrix - 16 port lines will give you 64 possible keys though if it is to be polyphonic (which is to say, if you ever expect more than one key to be pressed at a time, and you probably do), each key in the matrix has to have a diode.

Not only does this simplify the code (which may not be obvious at first glance), but it actually simplifies your wiring as well.

MUCH appreciated gents!

So, As I'm only using up to 11 momentaries perhaps I can give a miss to the multiplexing magic for now.

Based on the stock midi-OUT diagram it appears that only TX (digital pin 1) is used for midi out (all i need)
There's fore I COULD use RX (digital pin 0) as well as digital pins 2-13 as inputs --

YET, there something I still don't understand: the point about upping the code AND whether the pin 13 which is used with a cap and an LED to display activity.

So, Questions I guess

1- can I use RX pin 0 and 2-12 with EXACTLY the same code for each pin -- OR, would pin ) (RX) need some extra code
to turn it into an input that works the SAME as pins 2-12 ??

2- I've stumbled across mention that there's a hardware (and/or possible software) mod that needs to be done if one
is using pin 13? WHILE the capacitor and LED are connected. I'm wiring up a bare-bones board on perfboard so flexible.
Actually I'm probably inaccurate on that.

I'm confused as to whether uploading my sketch will be fine with PIN 13 wired up with the LED I figure YES. (and I guess I'll upload the bootloader as well - i have usbASP and FTDI cable etc)

So, to attempt clarity -- I would leave the LED hooked up to pin 13 for upping my sketch and then to use pin 13 as an input I'd disconnect the capacitor and LED on 13?

MAINLY interested in whether I can use RX pin0 as a stock input with same MDID out code I'm planning to use for pins 2-12.

NOTE: haven't got the code/sketch yet.

I can stumble forward based on your great assists. Just writing the above in the hopes it'll add something perhaps.

ALL good.

With an UNO you have 2 ports with 6 open pins each without touching RX/TX.
You could read 12 switches very quickly using port reads.

great - that's what I'm understanding.
just use digital pins 2-14 - leave pins 0 and 1 (tx/rx) for now and all will be revealed down the road
when i learn and try various sketches.

So, I could use pin 13 as an input and ignore that Digital pin 13 has a red LED and a 150 ohm resistor
attached to it currently. or not. I'm certain to be fine without using pin 13 as well as i don't need as the pins.

Eleven inputs? No trouble!

Use digital 2 to 12 - that makes eleven.

Digital 13 is connected to a LED, but on a UNO R3 it is buffered by an op-amp (no capacitor in any version - you may be thinking of a resistor :D) so it does not interfere in any way. Since it is useful as a indicator however, it is as well to reserve it for that function.

If you want a few more inputs, you use the six "analog" inputs remembering that these are in fact, digital inputs exactly the same as the others.

Connect your switches from the inputs to ground, not Vcc, and use the internal pullup function.

Paul__B !! MOST interesting...!!

One of the head-scratches is how i should wire the momentaries to the digital inputs.

I figured wire one side of them ALL together in a chain and solder to any ground -- (parallel? series? :slight_smile: (they're 2 pole SPSTs) -- and then for EACH of the switches use the REMAINING as yet unsoldered pole, and wire each one of them to a SEPARATE digital pin.. ??

Now, you've said:

"Connect your switches from the inputs to ground, not Vcc, and use the internal pullup function."

Thanks for that -- I HAVE heard about using the internal pullup function many times , and I'm interested in practical wiring stuff at this point. Therefore, I'm perhaps confused. May I ask how one attaches inputs to ground?

Perhaps I've just not though enough.

You DO mean that one side of each SPST switch goes to a digital pin.
AND the entire loop (soldered together) of the other switches' pole(s) goes to GROUND and not Vcc (which is 5 volts?)

So, if that's the case I understand - wire ALL of one side of the switches together and connect to the whole loop of 'em
to ANY ground on arduino pins, THEN take each individual 'other side' for each switch and connect EACH to a digital pin, 2-12.

ASIDE: There's that clever method for using different value resistors and connecting a bunch of SPSTs to a single digital pin -- Though, that's not what you're saying I believe anyways. And, I don't want to try that on my first board.

NOTE: yes, I have mentioned capacitor above (for pin 13 wiring) though having checked on my barebones perfboard arduino it's indeed a RESISTOR I'm using :slight_smile:

Reading a pin for INPUT tells you if it is HIGH or LOW.

INPUT_PULLUP puts 5V through a 20k to 50k resistor on the pin, enough to make it read HIGH if not grounded, or LOW if it is grounded through much less resistance (needs none at all).

INPUT read only takes in a tiny bit of current, keep it 5V or less.

OUTPUT can be LOW or HIGH.
If HIGH it will source power which you should keep the current drawn out to 20mA or less.
If LOW it will sink power which you should keep the current drawn in to 20 mA or less.
The total output through the pins should be kept to 200 mA or less.
Less current drawn through the chip is better.

FANTASTIC REFERENCE -- thank you!!

SO, do i connect all one side of all the momentaries and then connect single wire (of them all) to ground, any ground?

Then EACH of the other poles for EACH SPST momentary to a single digital pin EACH, 2-12 ?

woohoo -- really looking forward to trying this over next few days.

One wire from ground to each switch is the same as many wires, one from each switch to ground.

When you get the time, start learning basic electricity starting with conductors and Ohm's Law.

If you are in school and have taken algebra then take physics or at least physical science (then physics).
If not then include the word tutorial in your search words and find places that you can start learning.

Absolutely ! very solid comments - thanks.

I asked as, while understanding enough i have more experience in learning the long-way and was keen to cover that there's nothing out of the ordinary as far as wiring each (say the left side of each) to one another and then the final wire to ground (any ground on my barebones arduino)

then, each if the remaining solder points on the SPSTs would be for the digital pins and they go one for one to any of the digital pins 2-12 and this allows the internal resistors to function.

all good

great thanks on all this

IIRC you're using an UNO but jic here's the products page where I will click on the UNO:

and when I click on the pin mapping I get:

Pins 2,3,4,5,6,7 are open Port D pins.
Pins 8,9,10,11,12,13 are open Port B pins.

I can read either Port in a single operation but that will get 8 pins data.

Whoa - very interesting - didn't realize the Port D and Port B designations.
Thanks!

This page may be helpful.

Wow, lifesize!

Big Thankx to Pighixxx!

SOoo fabulous
-- best to all.