Adafruit is open and shipping! Let's build back better, together!
0

SSD1306 OLED 128x64 - display.getPixel?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SSD1306 OLED 128x64 - display.getPixel?

by StefanPetrick on Sat Jan 02, 2016 6:59 am

Hello,

a question about the SSD1306 library: is there any function like display.getPixel? If not how can I access the screen buffer globally?

I need to move data within the screen buffer in order to produce scolling charts.

Thanks for any hint!

StefanPetrick
 
Posts: 15
Joined: Fri Dec 26, 2014 3:26 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by adafruit_support_bill on Sat Jan 02, 2016 7:43 am

There is no getPixel function defined, but the display buffer is in memory, so you can manipulate it directly.

I need to move data within the screen buffer in order to produce scolling charts.

There are some scrolling functions built-into the library: https://github.com/adafruit/Adafruit_SS ... _SSD1306.h

Code: Select all | TOGGLE FULL SIZE
  void startscrollright(uint8_t start, uint8_t stop);
  void startscrollleft(uint8_t start, uint8_t stop);

  void startscrolldiagright(uint8_t start, uint8_t stop);
  void startscrolldiagleft(uint8_t start, uint8_t stop);
  void stopscroll(void);

adafruit_support_bill
 
Posts: 79406
Joined: Sat Feb 07, 2009 10:11 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by StefanPetrick on Fri Jan 29, 2016 11:11 am

Thanks for the reply. I want to realize some data charts scrolling trough "windows" (rectangular parts of the screen).

So the build in scroll functions which move the complete content don't help here.

I really need to access (read) single pixels in order to move them correctly.

but the display buffer is in memory, so you can manipulate it directly.


Great, but where in memory? Or what's the name of the array? This one?

Code: Select all | TOGGLE FULL SIZE
// the memory buffer for the LCD
static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = ...


It cannot be accessed from the scetch.

Could you give a little example, how to read one single pixel? For example how to find out, if the pixel at the xy position (42, 23) is currently white or black?

StefanPetrick
 
Posts: 15
Joined: Fri Dec 26, 2014 3:26 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by adafruit_support_bill on Fri Jan 29, 2016 11:38 am

The addressing for a 'getPixel' function would be identical to the setPixel. Something like this should do it. Don't forget, you'll need to add that prototype to the header also.

Code: Select all | TOGGLE FULL SIZE
bool Adafruit_SSD1306::getPixel(int16_t x, int16_t y)
{
  if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
    return;

  // check rotation, move pixel around if necessary
  switch (getRotation())
  {
  case 1:
    ssd1306_swap(x, y);
    x = WIDTH - x - 1;
    break;
  case 2:
    x = WIDTH - x - 1;
    y = HEIGHT - y - 1;
    break;
  case 3:
    ssd1306_swap(x, y);
    y = HEIGHT - y - 1;
    break;
  }

  return buffer[(x + (y/8)*SSD1306_LCDWIDTH]) & (1 << (y&7));
}

adafruit_support_bill
 
Posts: 79406
Joined: Sat Feb 07, 2009 10:11 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by StefanPetrick on Sat Jan 30, 2016 6:15 am

Thanks you very much, that works!
Code: Select all | TOGGLE FULL SIZE
bool Adafruit_SSD1306::getPixel(int16_t x, int16_t y)
{
  if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
    return false;

  // check rotation, move pixel around if necessary
  switch (getRotation())
  {
  case 1:
    swap(x, y);
    x = WIDTH - x - 1;
    break;
  case 2:
    x = WIDTH - x - 1;
    y = HEIGHT - y - 1;
    break;
  case 3:
    swap(x, y);
    y = HEIGHT - y - 1;
    break;
  }

  return buffer[(x + (y/8)*SSD1306_LCDWIDTH)] & (1 << (y&7));
}

StefanPetrick
 
Posts: 15
Joined: Fri Dec 26, 2014 3:26 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by StefanPetrick on Sat Jan 30, 2016 9:42 am

Just to show what I do with this:

Video - Realtime Audio Visualisation

https://www.youtube.com/watch?v=hvbIZPFd3bk&feature=youtu.be

StefanPetrick
 
Posts: 15
Joined: Fri Dec 26, 2014 3:26 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by adafruit_support_bill on Sat Jan 30, 2016 10:25 am

Awesome! Thanks for posting the video.

adafruit_support_bill
 
Posts: 79406
Joined: Sat Feb 07, 2009 10:11 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by adafruit_support_rick on Sat Jan 30, 2016 10:38 am

Wow! That's great work!

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: SSD1306 OLED 128x64 - display.getPixel?

by StefanPetrick on Sat Jan 30, 2016 11:05 am

Thanks, guys! Basically it is just a development tool for designing sound-responsive leds animations.

Stuff like this: https://www.youtube.com/watch?v=il5wc79k8LA

StefanPetrick
 
Posts: 15
Joined: Fri Dec 26, 2014 3:26 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by bonjurroughs on Mon Feb 01, 2016 4:14 am

Is there are way to apply this technique to the SSD1351 also?

bonjurroughs
 
Posts: 7
Joined: Sat Oct 26, 2013 11:16 pm

Re: SSD1306 OLED 128x64 - display.getPixel?

by adafruit_support_bill on Mon Feb 01, 2016 6:56 am

It should be. The SSD1306 has its own buffer, so you do not have direct access to the buffer RAM. But it does support both ReadRAM and WriteRAM commands over the SPI interface (see page 40) https://www.adafruit.com/datasheets/SSD ... %201.3.pdf

You would just need to write the complementary function to drawPixel :
https://github.com/adafruit/Adafruit-SSD1351-library

adafruit_support_bill
 
Posts: 79406
Joined: Sat Feb 07, 2009 10:11 am

Re: SSD1306 OLED 128x64 - display.getPixel?

by bonjurroughs on Mon Feb 08, 2016 2:37 pm

I have not been able to figure out the readRAM command for the SSD1351. The datasheet for this display is a 2-3 sentence regarding this command but it doesn't elaborate on how to retrieve the data after this command is sent. How do I readRAM on the display to determine if it is lit or not?

bonjurroughs
 
Posts: 7
Joined: Sat Oct 26, 2013 11:16 pm

Re: SSD1306 OLED 128x64 - display.getPixel?

by bonjurroughs on Mon Feb 08, 2016 7:48 pm

adafruit_support_bill wrote:It should be. The SSD1306 has its own buffer, so you do not have direct access to the buffer RAM. But it does support both ReadRAM and WriteRAM commands over the SPI interface (see page 40) https://www.adafruit.com/datasheets/SSD ... %201.3.pdf

You would just need to write the complementary function to drawPixel :
https://github.com/adafruit/Adafruit-SSD1351-library


On page 20 of the datasheet, "Under serial mode, only write operations are allowed. " There is no way possible to readRAM() with this board configuration.

bonjurroughs
 
Posts: 7
Joined: Sat Oct 26, 2013 11:16 pm

Please be positive and constructive with your questions and comments.