Can I run an LCD on an UNO and everything else on a MEGA?

HI everyone!

I have an Arduino mega, and it's got plenty of pins - but I'm getting a little concerned about the power draw that I'm going to be using for a project (I've posted about it a couple time here and here, but trying to keep separate issues... well, separate! hehe).

I'm running a 16x2 LCD for display on that project, and I had a thought that maybe I could send info from the MEGA to the UNO that will run the LCD. I have plenty of room for both the Uno and Mega. Any thoughts / info?

Here's a link to the project: https://wokwi.com/projects/386665695414235137

Here's my code currently:

#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Keypad.h>


LiquidCrystal lcd(19, 18, 17, 16, 15, 14);

# define rHot  LOW
# define rGnd HIGH

// WTF
void setupRelays();
void switchRelay(int, int);

const int bankButton = A15; //blue button
const int downButton = A12; //red button
int progButton = A14; //program button (green) - matches LED
int saveButton = A13; //save button (yellow) - matches LED
const byte rows = 3;
const byte cols = 3;
char keys[rows][cols] = {
{'a','f','k'}, 
{'b','g','l'},
{'c','h','m'}
};
byte rowPins[rows] = {2,3,4}; /* buttons or momentary switches - grey colors */
//byte colPins[cols] = {5,6,7}; /* rotary switch - pin 7 is read/use, pin 5 is program/choose effects, pin 6 is save to a preset. */
byte colPins[cols] = {46,48,44}; /* Green and Yellow Buttons - pin 44 is read/use, pin 46 is program/choose effects, pin 48 is save to a preset. */
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int OneRelayPin[3] = {8,9,10}; /* pin 1 on relay - reset/default has pin 1 at 0v - RED LED */
int TenRelayPin[3] = {11,12,13}; /* pin 10 on relay - reset/default has pin 10 at 5v - BLUE LED */
int presetLEDPin[3] = {A0,A1,A2}; /* shows which preset is engaged - GREEN LED */
int effectLEDPin[3] = {A3,A4,A5}; /* shows which effects are engaged - YELLOW LED */
int progRelay = 53;
int saveRelay = 51;

byte midiChannel = 0;

int numberOfPedal = 3;

int bankVariable = 9;
int numberOfBanks = 9;
int bank = 0; //Starting Bank Number

boolean lastBankButton = LOW;
boolean currentBankButton = LOW;

boolean lastDownButton = LOW;
boolean currentDownButton = LOW;

boolean lastProgButton = LOW;
boolean currentProgButton = LOW;
boolean progOn = true;

boolean lastSaveButton = LOW;
boolean currentSaveButton = LOW;
boolean saveOn = true;


/******************************************************/
void setup()
{
  lcd.begin (16, 2);
  lcd.print("You are a fat");
  lcd.setCursor(0, 1);
  lcd.print("sausage bitch!");

  setupRelays();  // pins and initial state

  for(int cc=0; cc<numberOfPedal; cc++) /* setup device */
  {
    pinMode(presetLEDPin[cc], OUTPUT);
    pinMode(effectLEDPin[cc], OUTPUT);
    digitalWrite(presetLEDPin[cc], LOW);
    digitalWrite(effectLEDPin[cc], LOW);
    delay(100);
  }
  delay(100);
  for(int ee=0; ee<numberOfPedal; ee++)
  {
    digitalWrite(presetLEDPin[ee], HIGH);
    digitalWrite(effectLEDPin[ee], HIGH);
    delay(100);
  }
  pinMode(progRelay,OUTPUT);
  pinMode(saveRelay,OUTPUT);
  digitalWrite(progRelay,LOW);
  digitalWrite(saveRelay,LOW);
delay(1000);
  //readPreset((bank * bankVariable), 1, 0); /* pulls first saved preset in memory */
  Serial.begin(31250); /* for midi communication - pin 1 TX */
  /*for (int i = 0; i < 10; i++) // erase eeprom (optional)
   // EEPROM.write(i, 0); */
   // initialize serial communication:
  Serial.begin(9600);
}
/* Bank Button Debounce */

boolean bankdebounce(boolean last) {
  boolean current = digitalRead(bankButton);
  if (last != current) {
    delay(5);
    current = digitalRead(bankButton);
  }
  return current;
}
boolean downdebounce(boolean last) {
  boolean current = digitalRead(downButton);
  if (last != current) {
    delay(5);
    current = digitalRead(downButton);
  }
  return current;
}
/* Program and Save Button Debounce */

boolean progdebounce(boolean last) {
  boolean current = digitalRead(progButton);
  if (last != current) {
    delay(5);
    current = digitalRead(progButton);
  }
  return current;
}

boolean savedebounce(boolean last) {
  boolean current = digitalRead(saveButton);
  if (last != current) {
    delay(5);
    current = digitalRead(saveButton);
  }
  return current;
}
/*********************************************************/
void midiProg(byte status, int data) 
 {
  Serial.write(status);
  Serial.write(data);
 }
 /*********************************************************/
void memory(int addr, int led)
{
  for(int ff=0; ff<numberOfPedal; ff++)
  {
    EEPROM.write((addr) + ff, digitalRead(effectLEDPin[ff]));
    digitalWrite(presetLEDPin[ff], HIGH); // turns off all preset LEDs
  }
  lcd.clear();
  lcd.print("Program saved to");
  lcd.setCursor(0, 1);
  lcd.print("Bank ");
  lcd.print(bank);
  lcd.print(" Preset ");
  lcd.print(led + 1);
  /* Preset LED will flash when saving effects loops */
  delay(100); 
  digitalWrite(presetLEDPin[led], LOW);
  delay(100); 
  digitalWrite(presetLEDPin[led], HIGH);
  delay(100);
  digitalWrite(presetLEDPin[led], LOW);
  delay(100); 
  digitalWrite(presetLEDPin[led], HIGH);
  delay(100);
  digitalWrite(presetLEDPin[led], LOW);
  delay(100); 
  digitalWrite(presetLEDPin[led], HIGH);
  delay(100);
  digitalWrite(presetLEDPin[led], LOW);
  delay(100);
  digitalWrite(presetLEDPin[led], HIGH);
  saveOn = !saveOn;
  delay(2000);
  lcd.clear();
  lcd.print("To Exit, Hit PRG");
  lcd.setCursor(0, 1);
  lcd.print("Or Choose Loops");
}

/*********************************************************/
void resetAllRelays()
{
  for (int ii = 0; ii < numberOfPedal; ii++)
    switchRelay(ii, LOW);     //... whatever the reset state is
}
/*********************************************************/
void resetAllLeds()
{
  for(int ii=0; ii<numberOfPedal; ii++)
  {
    digitalWrite(presetLEDPin[ii], HIGH);
  }
}
/*********************************************************/
void writeOut(int relay)
{
  resetAllLeds();
  digitalWrite(effectLEDPin[relay], !digitalRead(effectLEDPin[relay]));
  /*digitalWrite(ledPin[relay], !digitalRead(relayPin[relay]));
  /* thanks to  anton.efremoff.1 for this tip */
  lcd.clear();
  lcd.print("Current Bank: ");
  lcd.print(bank);
  lcd.setCursor(0, 1);
  lcd.print("Choose Loops: ");
  lcd.print(relay + 1);
}
/*********************************************************/
void readPreset(int addr, int pcNum, int led)
{
  for(int jj=0; jj<numberOfPedal; jj++)
  {
    digitalWrite(effectLEDPin[jj], EEPROM.read((addr)+jj));
    digitalWrite(presetLEDPin[jj], HIGH);
    int kPreset = EEPROM.read((addr) + jj);
    switchRelay(jj, kPreset ? HIGH : LOW);
  }
    digitalWrite(presetLEDPin[led], LOW);
  
  lcd.clear();
  lcd.print("             B-");
  lcd.print(bank);
  lcd.setCursor(0, 1);
  lcd.print("Preset ");
  lcd.print(led + 1);
  delay(100);
}

/*********************************************************/
void loop()
{
  currentBankButton = bankdebounce(lastBankButton);
  if (lastBankButton == LOW && currentBankButton == HIGH) {
    bank ++;
    for (int zz = 0; zz < numberOfPedal; zz++) {
      digitalWrite(presetLEDPin[zz], HIGH); //turn OFF all preset LEDs
      digitalWrite(effectLEDPin[zz], HIGH);
    }
    lcd.clear();
    lcd.print("             B-");
    lcd.print(bank);
    lcd.setCursor(0, 1);
    lcd.print("Press Any Preset");
    if (bank >= numberOfBanks) {
      bank = 0;
    }
  }
  lastBankButton = currentBankButton;

  currentDownButton = downdebounce(lastDownButton);
  if (lastDownButton == LOW && currentDownButton == HIGH) {
    bank --;
    for (int zz = 0; zz < numberOfPedal; zz++) {
      digitalWrite(presetLEDPin[zz], HIGH); //turn OFF all preset LEDs
      digitalWrite(effectLEDPin[zz], HIGH);
    }
    lcd.clear();
    lcd.print("             B-");
    lcd.print(bank);
    lcd.setCursor(0, 1);
    lcd.print("Press Any Preset");
    if (bank <= 1) {
      bank = numberOfBanks + 1;
    }
  }
  lastDownButton = currentDownButton;

  currentProgButton = progdebounce(lastProgButton);
  if (lastProgButton == LOW && currentProgButton == HIGH) {
    progOn = !progOn;
    if (progOn == HIGH){
    lcd.clear();
    lcd.print("Program Mode:");
    lcd.setCursor(0, 1);
    lcd.print("Select Loops");
    } else {
    lcd.clear();
    lcd.print("             B-");
    lcd.print(bank);
    lcd.setCursor(0, 1);
    lcd.print("Press Any Preset");
    if (bank >= numberOfBanks) {
      bank = 0;
    }
    }
  }
  lastProgButton = currentProgButton;
  digitalWrite(progRelay, progOn);
  

  currentSaveButton = savedebounce(lastSaveButton);
  if (lastSaveButton == LOW && currentSaveButton == HIGH) {
    saveOn = !saveOn;
    if (saveOn == HIGH){
    lcd.clear();
    lcd.print("Save Mode:");
    lcd.setCursor(0, 1);
    lcd.print("Select Preset");
    } 
  }
  lastSaveButton = currentSaveButton;
  digitalWrite(saveRelay, saveOn);
   

  char key = keypad.getKey();
  if(key)  // Check for a valid key.
  {
   switch (key)
      { 
    case 'a': writeOut(0); // relay
      break; 
    case 'b': writeOut(1);
      break;
    case 'c': writeOut(2);
      break;
    case 'd': writeOut(3);
      break;
    case 'e': writeOut(4);
      break;  
    /****************************** STORE PRESET MODE */       
//. case 'q': storePreset((bank * bankVariable), 0);
    case 'f': memory((bank * bankVariable), 0);  //addr, led
      break; 
    case 'g': memory(100 + (bank * bankVariable), 1);
      break;
    case 'h': memory(200 + (bank * bankVariable), 2);
      break;
    case 'i': memory(300 + (bank * bankVariable), 3);
      break;
    case 'j': memory(400 + (bank * bankVariable), 4);
      break;
    /****************************** READ PRESET MODE */      
    case 'k': readPreset((bank * bankVariable), 1, 0); // addr, pcNum, relay
      break; 
    case 'l': readPreset(100 + (bank * bankVariable), 2, 1);
      break;   
    case 'm': readPreset(200 + (bank * bankVariable), 3, 2);
      break;
    case 'n': readPreset(300 + (bank * bankVariable), 4, 3);
      break;
    case 'o': readPreset(400 + (bank * bankVariable), 5, 4);
      break;   
      }
   }
}

void setupRelays()
{
  for (int ii = 0; ii < numberOfPedal; ii++) {
    //digitalWrite(OneRelayPin[ii], LOW);
    //digitalWrite(TenRelayPin[ii], LOW);   // they will be, but here explicitly so no one wonders

    pinMode(OneRelayPin[ii], OUTPUT);
    pinMode(TenRelayPin[ii], OUTPUT);

    initRelay(ii, LOW); // HIGH or LOW as desired
  }
}

void setupRelays(); 

// this driver
// gives him a little jolt left to right, or right to left. careful how you fix things, think it out
void switchRelay(int relayNumber, int onOff)
{
  if (onOff) {  // close the contacts current flows 1 to 10
    digitalWrite(OneRelayPin[relayNumber], rHot);
    digitalWrite(TenRelayPin[relayNumber], rGnd);
  }
  else {  // open the contacts
    digitalWrite(TenRelayPin[relayNumber], rHot);
    digitalWrite(OneRelayPin[relayNumber], rGnd);
  }

  // if we have additional tell-tale lamps for the relays
  //    digitalWrite(tellTale[relayNumber], onOff ? HIGH : LOW);

//  delay(7);    // give peace a chance. implement the "stab" function

  //delay(75);    // let us see the pulse for now

  digitalWrite(OneRelayPin[relayNumber], rGnd);
  digitalWrite(TenRelayPin[relayNumber], rGnd);      // always return to
}

void initRelay(int relayNumber, int onOff)
{
  if (onOff) {  // close the contacts current flows 1 to 10
    digitalWrite(OneRelayPin[relayNumber], rHot);
    digitalWrite(TenRelayPin[relayNumber], rGnd);
  }
  else {  // open the contacts
    digitalWrite(TenRelayPin[relayNumber], rHot);
    digitalWrite(OneRelayPin[relayNumber], rGnd);
  }
    delay (50);

  // if we have additional tell-tale lamps for the relays
  //    digitalWrite(tellTale[relayNumber], onOff ? HIGH : LOW);

//  delay(7);    // give peace a chance. implement the "stab" function

  //delay(500);    // let us see the pulse for now

  digitalWrite(OneRelayPin[relayNumber], rGnd);
  //delay(100);
  digitalWrite(TenRelayPin[relayNumber], rGnd);      // always return to
  //delay(100);    // let us see the pulse for now
}

How will this solve the power consumption problem?

1 Like

What’s drawing current - and remember the Arduino IS NOT A POWER SUPPLY
What is your project

1 Like

How will adding an extra microcontroller help that? That will create even more current draw.

If you're drawing power through the Mega then that's the actual problem you need to fix. An Arduino is NOT a power supply.

Sorry folks, I should clarify (but also, thank you @cedarlakeinstruments, @lastchancename and @Delta_G for jumping on the thread! I really appreciate the help :slight_smile: )...

I'm talking solely about the per-pin power draw. when it comes to powering the varied parts (LCD, arduinos, relays, etc.), everything would be powered by 5v supply. The only things connected to the 5V or GND on the Arduino are debounced buttons/switches or the other side of some optocouplers. (I've corrected my simulator, fwiw).

There will be up to 20 optocouplers (PC817 + 1k resistor) driving relays (the relays are connected to 5v separate from Arduino - the optos only pulse to switch invert the coil and trigger the relays). There are also 18 LEDs that show what's what (though not all will be on at once), as well as the LCD connections.

I don't foresee a situation where all of them are on at the same time - at most, it would be half and that would be rare - but I also don't want to be down the road and some weird situation arises.

I read that the MEGA suggests no more than 200mA total draw, and recommended 20mA per pin (no more than 40mA max). Between the LCD pins, LED pins and the OPTOs that are driving the relays, and since I have an UNO I'm not using, I figured the LCD could run on the UNO to ease any per-pin draw on the Mega if they could communicate.

Maybe I'm off-base - but that was my thinking. If it's not anything to worry about, I won't - but I'm just trying to be buttoned up.

Does that clear it up a bit? Let me know! and thank you all, once again. :slight_smile:

That's on a per pin basis though. How will disconnecting something from one pin affect the current on another pin. If you're talking about the total current draw, then again the question is why are you powering things from digital pins.

I think you're chasing a phantom that doesn't exist. I'm usually asking people to show their code. I guess this time it's "Show your math".

Again, I don't understand how this will reduce the current draw. Now you have to power not only the LCD but the UNO as well. That takes even MORE current. Wherever you're planning to get power for the UNO, just give that to the LCD and forget the UNO.

I think you have some serious misunderstanding about something. I'm not sure exactly what. But I think you're chasing a problem that isn't a problem. If it is an actual problem then it's something else that you're doing wrong. Moving some stuff to an UNO isn't going to help.

The power pins for the LCD are where all the current goes. They should NOT be going to digital pins. They should be coming from the power supply. The rest of the pins are just data. They move microamps. Maybe even less. They're not something to worry about.

All control-signals are connected to IO-pins
and power comes from an external power-source. With the same principle as shown for this servo

The only devices that will draw a reasonable amout of current from the IO-pins are the optocouplers.

If you are concerned that you will go over the summarised current of all IO-pins by driving 20 optocouplers
the way to go is to use drivers or transistors

IO-pin-------->------driver----->---------Optocoupler-LED

IO-pin-------->------transistor----->---------Optocoupler-LED

For example ULN2003

ULN2003A.PDF (333.6 KB)

best regards Stefan

Can you post an abbreviated annotated schematic of what you are proposing?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.