Convert code from nano to work on mega2560

I have some code that was made to operate the Waveshare 1.3" OLED display on an Arduino.
The code works 100% on the Nano, but the identical code does not work on the Mega2560.
The display board uses pins 7, 8, 10, 11, 13 ( being DC, RST, CS, DIN, CLK, as marked on the board) as well as GND and 3.3V on the Nano, and I used the same pins on the Mega, but the display remains blank.
The code also operates the XY-LPWM PWM module, and both work together on the Nano, the PWM using SoftwareSerial.h and the OLED board SPI 4. The PWM board works always on both Nano and Mega2560.
Any idea why OLED on Nano but not Mega ?

The SPI pins are in a different location on the Mega. See the SPI reference.

There is no need to use SoftwareSerial on the Mega. The Mega has 3 extra hardware serial ports (Serial1, Serial2 and Serial3).

If you still have trouble, post your code and any error messages. Read the how to get the best of the forum post to see how to properly post code. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) before posting code.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

1 Like

Thanks, I learned a lot from the SPI reference. I tried the equivalent pins before, but that still would not work.

Then I found that in the library Dev_Config.h that was written for the display, they define CS as 10, so instead of 53 I used 10 and then it worked. Great, I can continue with my PEMF project.

I will try and use the built-in serial ports on the Mega as opposed to using SoftwareSerial.h and get that to work as well for more experience.
Once again thanks, I will study all the references first before asking questions again.

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