My custom made Arduino Mega doesn't drive LCD

Hello wonderful members

Following to my custom made Arduino mega board which was discussed here.
I am trying to drive a generic 16x2 LCD:

However I am unable to do so and output anything on the display no matter how much I try:

  • Potentiometer can adjust contrast: showing from nothing to blank squares on the screen

  • Tried with and without connecting RW to ground

  • I tried different LCD's on the board and they didn't work

  • I made sure every pin is wired up to the microcontroller properly

  • I even tested a code to set these pins to high so I make sure the assigned pins are being used and no problem with that all pins assigned gave 4.3V

  • I tried to program it with USBASP but same problem

- I tried the LCD with an Arduino UNO I have with the same code and it worked fine!!!

Could it be something with the bootloader or the set fuses or what could it be?!

#include <LiquidCrystal.h>

const int rs = 4;
const int en = 1;
const int d4 = 5;
const int d5 = 7;
const int d6 = 24;
const int d7 = 25;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  Serial.println("Starting LCD test...");

  lcd.begin(16, 2);
  lcd.print("Test");
  Serial.println("LCD Initialized.");
}

void loop() {
  // Nothing here
}

:arrow_right: pin 1 is used for the Serial Monitor :arrow_left:

The ATmega2560 is the same AVR family microcontroller as the ATmega328P. The code should do the same.
However, the ATmega328P can deal with drops and peaks in the voltage and wrong use of the pins and can give peak currents with a pin beyond of what is in the datasheet (to some limit). The ATmega2560 can deal with nothing.

What is the 4.3V ? The ATmega2560 must have at least 4.5V, but try to bring it between 4.8 and 5.1V.

1 Like

User CrossRoads is sadly no longer among us, but his website is still up: http://www.crossroadsfencing.com/BobuinoRev17/

I took two pictures from his website that shows the absolute minimum for a custom ATmega2560 board.

Do you see the 5 decoupling capacitors ? That means you should have also 5 of those (at least).

1 Like

thank you very much..

Turns out the pin assignment was wrong, and I don't know how my physical pins don't look like what they should be on the atmeg2560!
I ended up changing the status of each pin and check all the pins on the board to find what it is assigned to:

software physical
0 4
1 3
2 6
3 7
4 1
5 5
7 16
8 17
9 18
10 23
11 24
12 25
13 26
14 64
15 63
16 13
17 -
18 46
19 -
20 44
21 43
22 78
23 -
24 76
25 75
26 74
27 73
28 72
29 71
30 60
31 59
32 58
33 57
34 56
35 55
36 54
37 53
38 26
39 -
40 52
41 51
42 42
43 41
44 40
45 39
46 38
47 37
48 36
49 35
50 22
51 21
52 20
53 19
54 97
55 96
56 95
57 94
58 93
59 92
60 91
61 90
62 89
63 88
64 87
65 86
66 85
67 84
68 83
69 82

If someone can explain how is this happening I would appreciate it!

Hi @shamooooot.

Although the physical pin number is important when designing a PCB, once you start thinking about firmware, you should focus focus on the port and bit of the I/O pins as this is the only thing that is relevant.

Arbitrary integers are assigned to each of the I/O pins and these integers are the pin numbers used in the Arduino core API functions. It is essential to understand that these integers are only arbitrary identifiers and don't necessarily have any correlation at all to physical pin number or port/bit.

You can see the Arduino pin number mapping for the Arduino Mega 2560 board here in its core variant file:

Here is the port mapping:

And here is the mapping for the pin's bit within the mapped port:

The Arduino pin number is the index of the arrays.

So for example, the 0th element of the array (Arduino pin 0) is PORTE:

and bit 0:

If you look at the pinout in the ATmega2560 datasheet for the IC package you are using, you can see which physical pin is PE0.

1 Like

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