Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding SSD1306 64x48 functionality #522

Merged
merged 2 commits into from Sep 24, 2019
Merged

Conversation

thedamian
Copy link
Contributor

Adding the 64x48 OLED to the amazing SSSD1306

This has been tested on a D1 oled shield v2 (64x48) and with the HELTEC 128x32 (for backward compatibility) with the code below:

NOTE. Only lines 65 and 68-72 where changed is the JS file.
Silly Git doesn't realize only these changes were made because of spacing or CR/LF issues.

I've also added the notes to the Espruino/SSD1306 MD file and examples to the top of the JS file

function start(){
  g.clear();
  g.drawString("Hello",0,0);
  g.drawLine(0, 20, g.getWidth(), 20);
  g.setFontVector(10);
  g.drawString("123456789",0,7);
  g.drawString("123456789",0,22);
  g.drawString("123456789",0,35);
  g.flip();
}
// HELTEC 128x32
let SCL = D5;
let SDA = D4;
I2C1.setup({scl:SCL,sda:SDA});
var g = connect(I2C1, start, { height : 32 });

//D1.Mini OLED 64x48
let SCL = NodeMCU.D1;
let SDA = NodeMCU.D2;
I2C1.setup({scl:SCL,sda:SDA});
var g = connect(I2C1,start, { height : 48, width:64 });

@thedamian
Copy link
Contributor Author

Code to test can be tested ahead of time (if you have a 64x48 OLED like this:

let SCL = NodeMCU.D1;
let SDA = NodeMCU.D2;
I2C1.setup({scl:SCL,sda:SDA});
var g = require("https://raw.githubusercontent.com/thedamian/EspruinoDocs/master/devices/SSD1306.js").connect(I2C1,start, { height : 48, width:64 });

@gfwilliams
Copy link
Member

Thanks!

It looks like what happened with whitespace is every line is padded with an extra space...

Does it work on your heltec if you specify { width:128, height : 32 }? It seems that width=128 is specified, flipCmds ends up at 0x21,128,127 rather than 0x21,0,127 which is what it was before.

Please could you try this and see if it works? If so I'd feel happier putting it in.

      flipCmds[1] = options.width < 128 ? options.width/2 : 0; // 0x20 for 64, 0 for 128;
      flipCmds[2] = flipCmds[1]+options.width-1; // 0x5f for 64, 127 for 128;

@fanoush
Copy link

fanoush commented Sep 23, 2019

Too bad with the white spaces, it is really hard to see what has changed. As for the computation of flipCmds[1] I think it is too simple because 64 looks like easy case - 128/2. There is SSSD1306 display with width of 72 - there it would fail. At least with that display the right computation is (128-options.width)/2 =28 as visible memory is in the middle from 28 to 99. And BTW that would work for original value of 128 too since (128-128)/2=0.

@gfwilliams
Copy link
Member

You can always add ?w=1 to the github diff to turn off whitespace, but I'll indent back in before merging anyway.

The centering sounds good. So you could try:

flipCmds[1] = (128-options.width)/2; // 0x20 for 64, 0 for 128;
flipCmds[2] = flipCmds[1]+options.width-1; // 0x5f for 64, 127 for 128;

@thedamian
Copy link
Contributor Author

thedamian commented Sep 23, 2019

Here's a quick link to see the difference without the whitespace as gordon suggests:
https://github.com/espruino/EspruinoDocs/pull/522/files

@gfwilliams I did check the code with my 128x32 screen and it worked, but I will double check later tonight.

@thedamian
Copy link
Contributor Author

Super suggestion by @gfwilliams implemented for cleaner easier to read code

@gfwilliams gfwilliams merged commit 8bddf6b into espruino:master Sep 24, 2019
@gfwilliams
Copy link
Member

Thanks! Just merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants