Pin 1 conflict between 16x2 screen and MIDI library

I'm having the same problem as this poster:
https://forum.arduino.cc/t/pin-1-conflict-using-lcd-and-midi-library/158064

I see someone had suggested a solution (UCSR0B &= ~B00001000) in the last post of the thread, but I have no idea where those command lines would have to be coded. Can anyone please guide me?

The problem in the other topic was caused by the use of pin 1, which is used by the Serial interface.

Do you have to use pin 1 in your project ? Have you used all of your analogue pins ? Could you use an LCD with an I2C interface to save pins ?

Just initialize the MIDI library first. It will set up Pin 1 for serial output but since you are not sending any MIDI, just receiving with Pin 0, it may not be a problem that the LiquidCrystal library takes over Pin 1.

void setup() 
{
  MIDI.begin();
  lcd.begin(16,2);  
}

Thanks, guys. I really appreciate the input.

I'm using every single available pin of the Arduino, so using a different pin is not an option.

As soon as I add the initialise of the MIDI library (I do it in the order such that the 16x2 is initialised last) the 16x2 corrupts and remains corrupted. If I don't init the MIDI library, and only use MIDI over USB, then everything works fine. Although this proves the source of the problem, not using 5-pin MIDI is not an option.

I am considering looking at an option for reducing the number of pins I need to support the 16x2, but that's not ideal - I will have to completely redesign my circuitry and enclosure.

We will never know, because you have not demonstrated what you are actually doing. :roll_eyes:

Six arcade lights/buttons, using all of the PWM and analogue pins, one 16x2 display, one MIDI input port. These take up all the Arduino pins. Not sure what else you would need to know that would make a difference?


The bottom line is that I would ideally like to prevent the MIDI library from interfering with pin 1, so that I can use it for the 16x2.

How many pins does the LCD use ?

The exact pin use, as requested before. It is very possible we may know a way around what you've done, but without knowing what you've done it is a lot harder and just 'guess work' really. Also your code would really help !
You don't need to send Midi, but have you turned Midi-thru 'Off' ?
With the component you say you have connected, i don't see how you could have run out of pins really. Even if you use the LCD in 8-bit mode there should still be a few left (6 PWM + 10 LCD) but running it in 4-bit mode leaves even more.

The 16x2 uses 7 pins (plus 5V/ground), including pin 1.

In summary:
0 - MIDI input
1 - display
2 - display
3 - LED
4 - display
5 - LED
6 - LED
7 - display
8 - display
9 - LED
10 - LED
11 - LED
12 - display
13 - display (backlight control)
A0-A5 - switches

I only use 6 pins on my LCD

I have to have the backlight on a pin (13), such that it automatically turns on/off when buttons are selected.

How do I turn MIDI thru off?

You could consider a multiplexer for your switches. But show us the code. If hwSerial is to much of a hassle, we can maybe try swSerial as well.

  MIDI.begin(MIDI_CHANNEL_OMNI);   // Launch MIDI and listen to channel Omni
  MIDI.turnThruOff();

If using pin 1 is an issue, i would use pin 1 for that purpose and switch them over. Now the LCD library has no conflict.

Doesn't help.

I think using pin 1 for the backlight will simply shift the problem and I will then have a flickering backlight, but if anyone else thinks it's worth a shot?

Try it. It shouldn't result in a flickering backlight if you are not sending anything out over Serial.

Without your code there is no way for me to see what else you may be sending.

I'm not sending anything. Simply initialising the MIDI library causes the display corruption.

Use a single analogue pin and a resistor ladder for the switches ?
Use an I2C LCD ?