Go Down

Topic: Lighting up one pixel on a OLED (Read 408 times) previous topic - next topic

UNI-T

Hi,

Like the title says I'd like to only light up one pixel on a SSD1306 OLED (Standard Chinese OLED). I want to do this to plot bars and similar things real time.

I'm currently using the MultiLCD library and it's been working great, however I don't see any straight forward way to only light up on pixel and remove pixels in front of it in a controlled way.

One semi working way around this has been to replace an unused character with just keep some pixels lit while some dim, this kind of works but it still acts like an 8x8 character and removes pixels around it and doesn't really look niceā€¦

Could anybody help me out with this?
Thanks!

UKHeliBob

Looking at the .h file for the library I see this function
Code: [Select]

 void setPixel(uint16_t poX, uint16_t poY,uint16_t color);

I did not look any further but it looks as though you can turn a single pixel on/off
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UNI-T

Looking at the .h file for the library I see this function
Code: [Select]

 void setPixel(uint16_t poX, uint16_t poY,uint16_t color);

I did not look any further but it looks as though you can turn a single pixel on/off
Thanks but it doesn't seem to work, im not a good programmer.
This is how I implemented it.


Code: [Select]


#include "MicroLCD.h"


void setPixel(uint8_t poX, uint8_t poY,uint8_t color);



void setup(){

Init everyting

}

void loop(){

setPixel(64, 15, 255)

}



GypsumFantastic

There's quite a lot of stuff missing from that code.

How did you set up the OLED? (How did you instantiate the MultiLCD object).

How did you "init everything"?

you can't just put setPixel on its own. It needs to act on an object of the MultiLCD class.

Something like this

myOLED.setPixel(X, Y, colour);

It won't necessarily be called "myOLED" - that depends on how you set up the OLED at the beginning.

The library comes with example code. Have a look and see how they do all this stuff in there.

UNI-T

The OLED is initiated as "lcd" so the code should be something like "lcd.setPixel(64, 5, 255);"

It gives me a error "'class LCD_SH1106' has no member named 'setPixel'" so I assume there is no such thing as setPixel in the library.

The setup code is as following

Code: [Select]
LCD_SH1106 lcd;


void setup(){


    lcd.begin();

    lcd.setPixel(64, 5, 255);


}


The code works fine with the normal print functions.

GypsumFantastic

Where did LCD_SH1106 come from? What happened to the SSD1306?

What library are you actually using?

It's a lot easier if you just post the whole code.

UNI-T

#6
Dec 10, 2018, 11:01 am Last Edit: Dec 10, 2018, 11:05 am by UNI-T
Where did LCD_SH1106 come from? What happened to the SSD1306?

What library are you actually using?

It's a lot easier if you just post the whole code.

Sorry I must have mistaken the module I was using. It is a SH1106 but they are pretty much identical.
There is nothing spectacular with the code but here it is.


Code: [Select]

#include <Wire.h>
#include "MicroLCD.h"

#define F_CPU 1000000UL

LCD_SH1106 lcd;

void setPixel(uint8_t poX, uint8_t poY,uint8_t color);

void setup() {
 
 lcd.begin();

 lcd.setFontSize(FONT_SIZE_LARGE);
 lcd.setCursor(20, 2);
 lcd.print("Hello World");
 delay(1000);
 lcd.clear();
 
}

void loop() {
 
  //Just things that arnt working
 
  //lcd.setPixel(64, 5, 255);
  //lcd.draw(0xFF, 1, 1);

}


GypsumFantastic

OK, so it looks like you are using the MicroLCD library. This doesn't have the setPixel method. I don't know why they would have omitted that.

It has a draw method that might be useful.

Are you committed to using the MicroLCD library? Just that I noticed there's an Adafruit library for the SH1106 that has a setpixel function.

UNI-T

OK, so it looks like you are using the MicroLCD library. This doesn't have the setPixel method. I don't know why they would have omitted that.

It has a draw method that might be useful.

Are you committed to using the MicroLCD library? Just that I noticed there's an Adafruit library for the SH1106 that has a setpixel function.
I'm not really committed to use it; I'd just prefer to not change a lot of code for my other projects that use the MicroLCD library. I have optimized the SH1106 and SSD1306 configuration (For power consumption).
It wouldn't be too much of a hassle to move it over; otherwise I could port the pixelDraw to the MicroLCD library.

PaulS

Just out of curiosity, what happens if you draw a line starting and ending at the pixel you want to light up?
The art of getting good answers lies in asking good questions.

UNI-T

So I tried the Adafruit library and the "drawPixel" seems to work just fine. IL either port it to the MultiLCD library or convert my other projects to the Adafruit library.

So far I'm a little annoyed with the Adafruit library over the following.

Adafruit splash screen at startup. (I have to do an unassay clear in the setup)

Adafruit SH1106 driver doesn't care for custom contrast settings and other power saving things. Even if I add it in the code it doesn't do anything.

No clear way to clear just small part of the screen. If I print a value from the ADC and I want to update it I'll have to clear the entire screen and redraw everything else. This is annoying and slows everything down a lot since I'm running on 1 MHz.

Is there any way to solve these things?

UKHeliBob

Quote
No clear way to clear just small part of the screen.
No rectangle drawing function, or could you print spaces in the background colour ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Slumpert

What happened to using the adafruit code as a example to add the function to your MicroLCD library?

wildbill

You can edit the library to get rid of the Adafruit logo.

UNI-T

So I finished porting the function to the MultiLCD/MicroLCD library's!
I made two functions:


setPixel(x, y);
clearPixel(x, y);

Like the names state one clears just one pixel and one adds one pixel.


Code for "MicroLCD.h"
Code: [Select]
   
void setPixel(int8_t x, int8_t y);
void clearPixel(int8_t x, int8_t y);


Add these under public for LCD_SH1106(Row#79) or SSD1306(Row#62)

Code for "SH1106.cpp" or "SSD1306.cpp"
Code: [Select]

void LCD_SH1106::setPixel(int8_t x, int8_t y) {
 
  m_col = x + 2;
  m_row = y;
  WriteCommand(0xb0 + m_row);
  WriteCommand(m_col & 0xf);
  WriteCommand(0x10 | (m_col >> 4));
 
  Wire.beginTransmission(I2C_ADDR);
   
  Wire.write(0x40);
  Wire.write(0x01);
  Wire.endTransmission();
   
}

void LCD_SH1106::clearPixel(int8_t x, int8_t y) {
 
  m_col = x + 2;
  m_row = y;
  WriteCommand(0xb0 + m_row);
  WriteCommand(m_col & 0xf);
  WriteCommand(0x10 | (m_col >> 4));
 
  Wire.beginTransmission(I2C_ADDR);
   
  Wire.write(0x40);
  Wire.write(0x00);
  Wire.endTransmission();
   
}





Just add these some ware that's not in another class, directly under all the imports would be easiest.

Go Up