How to send string from Serial to Oled without line breaks?

Hello. I have difficulty with the following, I hope someone can help me.

The string is limited to 9 characters which enter just the width of the oled screen, if I send the data only once it is correct but if I send them two or more times they are accommodated with line break which is how it works. normal but as the data below is fixed it creates a problem for me so I need not to skip the line for any reason. Attached code snippet. I am very new to this.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

char controlsynth; // this is the string you can't have
String string;          //  Variable to convert the data to Strig
                                 //  and send tol Oled I2C 

if (Serial.available() && bank1.getSelection() == 1) {
                
        controlsynth = Serial.read();
        string+=controlsynth;
                
        }
               
            
if (bank1.getSelection() == 0) {
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 15);
  
  display.print(string[0]);   // this is the string that cannot have a 
  display.print(string[1]);    //newline for any reason
  display.print(string[2]); 
  display.print(string[3]);
  display.print(string[4]); 
  display.print(string[5]);
  display.print(string[6]); 
  display.print(string[7]);
  display.print(string[8]); 
 
  display.setFont(&FreeMono9pt7b);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 27);
  display.println("BANK 1");
   }

You can set the print position at any time you want by using the setCursor() function so just change it when you need/want to

Thank you very much sir, you made me happy!

  display.setCursor(0, 15);
  display.print(string[0]); 
  display.setCursor(14, 15);
  display.print(string[1]);
  display.setCursor(28, 15);
  display.print(string[2]); 
  display.setCursor(42, 15);
  display.print(string[3]);
  display.setCursor(56, 15);
  display.print(string[4]); 
  display.setCursor(70, 15);
  display.print(string[5]);
  display.setCursor(84, 15);
  display.print(string[6]); 
  display.setCursor(98, 15);
  display.print(string[7]);
  display.setCursor(112, 15);
  display.print(string[8]); 

I am glad that it worked, but do you really need to position the cursor before every character ?

Please delete your duplicate topic in the International section

It's the only way I could avoid the line break. It is not perfect because depending on the typeface it can give an error.

In that case it sounds like the Strings have linefeeds on the end of them

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