Question about screen error of Arduino OLED

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include "class_kproject_device_nrf.h"
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// nrf24l01
#define CE_PIN 8
#define CSN_PIN 7
#define data_pin 2
#define latch_pin 3
#define clock_pin 4
#define sending_btn 5
class_kproject_device_nrf nrf(CE_PIN, CSN_PIN, true);

// TinyGPS
#define RXPIN 10
#define TXPIN 9
#define GPSBAUD 9600
TinyGPS gps;
SoftwareSerial uart_gps(RXPIN, TXPIN);
void getgps(TinyGPS &gps);

#define SCREEN_WIDTH 128 //OLED 가로 길이 설정
#define SCREEN_HEIGHT 64 //OLED 세로 길이 설정
#define OLED_RESET 4

void setup()
    Serial.begin(9600); //시리얼 통신 속도 설정
    pinMode(data_pin, OUTPUT); //data핀 설정
    pinMode(latch_pin, OUTPUT); //latch핀 설정
    pinMode(clock_pin, OUTPUT); //clock핀 설정
    pinMode(sending_btn, INPUT_PULLUP); //전송 버튼 핀 설정
    nrf.power_down(); //nrf24l01 전력 off
    nrf.power_up(); //nrf24l01 전력 on
    nrf.begin(); //nrf24l01 시작
    nrf.set_payload_length(0, 32); //nrf24l01 전송 자료 크기 설정
    nrf.set_channel(0); //channel 변경후 rx 모드로 설정해야 수신 가능
    nrf.read_mode(); //수신 모드로 전환

    uart_gps.begin(GPSBAUD); //GPS 통신 시작
    Serial.println("Start GPS");
    Serial.println("waiting for lock");

    if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //OLED 접속에 실패했을 경우
      Serial.println(F("SSD1306 allocation failed"));
      for(;;); //무한 반복
    display.display(); //OLED 디스플레이 활성화
    display.clearDisplay(); //OLED 디스플레이 비활성화

//nrf24l01 추가 설정
unsigned long count = 0; //count 변수 설정
unsigned int prev_btn_status = HIGH; //전송 버튼의 이전 값 설정

void loop()
    int val; //val 변수 생성
    val = digitalRead(sending_btn); //val의 값을 전송 버튼의 값으로 설정
    if (( prev_btn_status == HIGH ) && ( val == LOW )) { //이전 값이 on, 현재 값이 off일 경우
        nrf.write_mode(); //송신 모드로 전환

    if (( prev_btn_status == LOW ) && ( val == HIGH )) { //이전 값이 off, 현재 값이 on일 경우
        nrf.read_mode(); //수신 모드로 전환
    if ( val == HIGH ) {
        int received =;
        if ( received != -1 ) {
            for ( int i = 0; i < 32; i++) {
                digitalWrite(latch_pin, LOW);
                shiftOut(data_pin, clock_pin, MSBFIRST, nrf.rx_buf[i]*4);
                digitalWrite(latch_pin, HIGH);
    else {
        unsigned char val[32];
        for ( int i = 0; i < 32; i++) {
            val[i] = map(analogRead(A0), 0, 1023, 0, 255);
        nrf.write((char*)val, 32);
    prev_btn_status = val;

    while(uart_gps.available()) {
      int c =;
      if(gps.encode(c)) {

void getgps(TinyGPS &gps)
  float latitude, longitude;
  gps.f_get_position(&latitude, &longitude);

  Serial.print("Latitude/Longitude : ");
  Serial.print(latitude, 5);
  Serial.println(longitude, 5);

  int year;
  byte month, day, hour, minute, second, hundredths;

  Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); 
  Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(hour, DEC); Serial.print(":"); 
  Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
  Serial.print("."); Serial.println(hundredths, DEC);

  Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
  Serial.print("Course (degrees): "); Serial.println(gps.f_course());
  Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());

  display.print(" Date : "); display.print(year); display.print("/"); display.print(month, DEC); display.print("/"); display.println(day, DEC);
  display.print(" Time : "); display.print(hour, DEC); display.print(" : "); display.print(minute, DEC); display.print(" : "); display.println(second, DEC);
  display.print(" Latitude/Longitude : "); display.print(latitude, 5); display.print("/");display.println(longitude, 5);
  display.print(" Altitude (meters) : "); display.println(gps.f_altitude());
  display.print("Course (degrees) : "); display.println(gps.f_course());
  display.print("Speed (km/h) : "); display.println(gps.f_speed_kmph());

  unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);


“class_kproject_device_nrf.h” is a personally created header file.
If I upload this, the screen of OLED will stop from the moment it is uploaded.
If I run this code after I run the example, it stops as it was.
If I write the basic code, it works normally.
I think it is a conflict with TinyGPS or an error that cannot be executed.
My intention is to mark the latitude/longitude, speed, altitude, etc. obtained by TinyGPS on OLED.
What should I do…?

I think it is a conflict with TinyGPS or an error that cannot be executed.
My intention is to mark the latitude/longitude, speed, altitude, etc. obtained by TinyGPS on OLED.
What should I do...?

Maybe the conflict is with softwareSerial, have you tried using hwSerial for the GPS ? (and obviously commenting out all other reference to hwSerial)

I can’t find any information about HwSerial…
Will using the GwSerial reduce the risk of collision?

hwSerial is short for Hardware Serial, the hardware UART you refer to when using the Serial object. softwareSerial disables interrupts for extended periods of time, and that may cause conflicts. Of course you are using 'Serial' already to send some information from the program to the Serial monitor, and you can not really use the same port for both things.