Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep theĀ Forum RulesĀ in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For exampleĀ “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post willĀ not bring you to the same post, in Dutch, as there is no translation for that post!



SSD1306Ascii SetCur...
 
Share:
Notifications
Clear all

[Solved] SSD1306Ascii SetCursor not working

10 Posts
3 Users
0 Reactions
5,031 Views
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

I have a sketch that I am using to learn the screen positions for a GPS Logger.
I want to learn how to place characters in specific positions on the screen.

This is running on an Arduino Nano and SSD1306 display SPI.

It seems to be ignoring the setcursor and place characters based on println instead.

The display should look like this
AAA BBB CCC
1 2 3

Then is should wait 2 seconds then over write the " 1 2 3"
with " 4 5 3"

The display should look like this
AAA BBB CCC
4 5 6

Any help is greatly appreciated

Ā 

Code is below
-------------------

#include "SSD1306Ascii.h"
#include "SSD1306AsciiSpi.h"

#define CS_PIN Ā 10
#define RST_PIN 9
#define DC_PIN Ā 8

#include <SoftwareSerial.h>

SSD1306AsciiSpi oled;

#define OLED_RESET 9

void setup() {
Ā Ā Serial.begin(9600);
Ā Ā  Ā oled.begin(&Adafruit128x64, CS_PIN, DC_PIN, RST_PIN);
Ā Ā  Ā oled.setFont(System5x7);
Ā Ā  Ā oled.print("TESTING");
Ā Ā  Ā delay(2000);
Ā Ā  Ā oled.clear();
}


void loop() { Ā 
Ā Ā  Ā oled.setCursor(0 , 0);
Ā Ā  Ā oled.print("AAA ");
Ā Ā  Ā oled.print("BBB Ā ");
Ā Ā  Ā oled.println("CCC Ā ");
Ā Ā  Ā 
Ā Ā  Ā oled.setCursor(10 , 30);
Ā Ā  Ā oled.print("1");
Ā Ā  Ā oled.setCursor(50 , 30);
Ā Ā  Ā oled.print("2");
Ā Ā  Ā oled.setCursor(100 , 30);
Ā Ā  Ā oled.println("3");
Ā Ā  Ā delay(2000);
Ā Ā  Ā 
Ā Ā  Ā oled.setCursor(10 , 50);
Ā Ā  Ā oled.print("4");
Ā Ā  Ā oled.setCursor(50 , 50);
Ā Ā  Ā oled.print("5");
Ā Ā  Ā oled.setCursor(100 , 50);
Ā Ā  Ā oled.println("6");
Ā Ā  Ā 
Ā Ā  Ā delay(2000);
Ā Ā  Ā }

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Just being curious, since I do not have this display;
What is happening when you use your current code?

If I'd have to guess, you code writes "AAA BBBĀ  CCC", underneath that "123" and underneath that line "456".
(so you have 3 lines in total)

Also: try using print instead of println - maybe the println" variant conflicts with the setCursor function?


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

You are right on both counts.Ā  That is what I wanted the display to do.

If I change the println to print the display ignores the row positioning and everything prints on one line


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Hmm, that is weird indeed, I'd assume setCursor(x,y) would correct for that 🤔Ā 

Looking at the Github page of the library, I see this is a text driven library, not sure if that could be an issue though.
I also noticed that setCursor works like this:

oled.setCursor( Column, Row );

where Column is expressed in pixels, but Row in rows of 8 pixels.

So when I see you code:

oled.setCursor(100 , 30);
oled.println("3");
...
oled.setCursor(100 , 50);
oled.println("6");

Then the "3" will be printed at 100, 240 (both in pixels), and the "6" will be printed at 100, 400 (both in pixels as well).
I don't know if this would exceed the display, and if this would be the intended location?


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

@hans

That was it!Ā  I forgot about the 8 pixel rows.Ā  The original code I was working with was wrong.
That was why I created the test sketch to figure out the code.

I also looked through the documentation and found a useful function oled.clearToEOL();

You set the cursor position then call this and it clears the remaining portion of the line.Ā 

So this way when it displays "1 2 3", I can set the cursor to the beginning of the line,
then call the oled.clearToEOL(); and it will be clear to printĀ  "4 5 6" at the same spot.

The concept will be used to display GPS altitude, speed and number of satellites on the same line.Ā  These will be updated as the hardware moves around.

Below that will be the actual GPS cordinates.

Thanks for the help.Ā  Now on the figuring out the SD card module.Ā  I will create another thread for that issue


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Cool 👍Ā 

I would probably have made the same mistake (not sure why one would different "units" for X and Y anyway). 😋Ā 


   
ReplyQuote
 tvr4
(@tvr4)
Estimable Member
Joined: 5 years ago
Posts: 122
Topic starter  

@hansYou are correct, it is different.Ā  I put some note comments in my code to remind me


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

👍 😉Ā 


   
ReplyQuote
(@mellilewis)
New Member
Joined: 5 years ago
Posts: 1
 

Hi...i also have the similar trouble. If I write a line or two of text and then use display.setCursor() to move to a blank region of the screen and then write an additional character, the character does not end up at the new coordinates, instead it shows up in the same region as the existing text. I've double checked the coordinates to be fine.

Is this a bug, or am I missing some key steps? I can spend the time to make specific examples if this is a rare issue.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

It's been a while that I have played with displays ... (maybe tvr4 can chime in as well).

Did you take this in consideration when positioning the text?

Posted by: @hans

where Column is expressed in pixels, but Row in rows of 8 pixels.

Ā 


   
ReplyQuote
Share: