SSD1306Ascii icon indicating copy to clipboard operation
SSD1306Ascii copied to clipboard

SSD1306AsciiAvrI2c.setCursor() is using pixels instead of columns to set cursor

Open krukhlis opened this issue 6 years ago • 3 comments

I have found out that SSD1306AsciiAvrI2c.setCursor(column, row) is properly setting row properly, but for columns it uses pixels instead of columns. I.e. SSD1306AsciiAvrI2c.setCursor(10,3) will set cursor to 3rd row and 10th pixel instead of 3rd row and 10th column.

This is sample code from git( just removed 2x enlargement) to reproduce:

#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"

// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C

// Define proper RST_PIN if required.
#define RST_PIN -1

SSD1306AsciiAvrI2c oled;
//------------------------------------------------------------------------------
void setup() {

#if RST_PIN >= 0
  oled.begin(&Adafruit128x32, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
  // Call oled.setI2cClock(frequency) to change from the default frequency.

  oled.setFont(System5x7);

  uint32_t m = micros();

  oled.clear();

  // first row
  oled.println("set1X test");

  /* 
second row, this guy will show A in the middle of the screen(128x64) for the 5x7 font. For columns this coordinates are not acceptable at all. You can try setting it to setCursor(13,3) -- it will be slightly shifted from the left corner, instead of being set almost to the middle of the 128x64 screen.
*/  
oled.setCursor(62,3);
  oled.println("A");

  // third row
  oled.set1X();
  oled.print("micros: ");
  oled.print(micros() - m);
}
//------------------------------------------------------------------------------
void loop() {}

krukhlis avatar Nov 10 '18 03:11 krukhlis

Sorry, I've just figured out, this is "how it's designed" according to https://github.com/greiman/SSD1306Ascii/blob/master/doc/html/class_s_s_d1306_ascii.html#ae17ec7ca20e16fdc832ec5ff579597d6 setCursor description. It's kind of discrepancy that row is in 8-pixels-rows, but col is in pixels:

[in] col The column number in pixels.
[in] row the row number in eight pixel rows.

krukhlis avatar Nov 10 '18 04:11 krukhlis

That's how addressing works with the SSD1306.

greiman avatar Nov 10 '18 16:11 greiman

And it allows a lot of effects like smooth horizontal text or graphics movement in pixel unit.

hlide avatar Apr 06 '19 06:04 hlide