-
• #2
Hi! When you get this working it'd be great to turn it into a module for Espruino!
So I think it'd be really helpful to know when the screen turns blank. Maybe you could run the commands one after the other - is it after
connect
,on
, orflip
?It all looks quite good, but only thing right now is I'm wondering if:
flipCmds.forEach(function(d) {i2c.writeTo(addr, [0,d]);});
should actually be:
i2c.writeTo(addr, [0].concat(flipCmds));
So instead of writing
0,data1,0,data2,...
you do0,data1,data2,...
-
• #3
Thanks for the quick reply!
That actually seemed to be thé problem! I still had to adjust line 37 to0, 127
to fix the height
of the display which also fixed the screen turning off.I'm only now getting sometimes issues with my board kinda randomly resetting or giving seemingly random errors when trying to upload the code. Perhaps I've already used up all the RAM or something?
Hi! When you get this working it'd be great to turn it into a module for Espruino!
Yes, I plan to (at least with i2c support) once I'm sure it's working fine.
-
• #4
(EDITED) Randomly resetting could come from the fact that sometimes an 'uninterruptible' application part of the code is completing within the time window that ESP8266 firmware allows and starves ESP8266 of processing cycles for the Wifi communication code.
-
• #5
Another issue can be the insufficient power supply. ESP8266 has some surges that can be countered by a cap on the rails.
-
• #6
re post #4, bullet point 1 and 3 - as taken from https://stackoverflow.com/questions/31083757/esp8266-constantly-restarting
Get the serial terminal program named "terminal v1.9b by br@y++". While I wrote this answer I was not able to download. When I find the link I'll add in a comment. Run the program and set the baud rate to custom and enter the value 74880 or 74400. With this you'll be able to see the fw messages. In this messages there is the reboot reason code. The codes are :
0 -> normal startup by power on
1 -> hardware watch dog reset
2 -> software watch dog reset (From an exception)
3 -> software watch dog reset system_restart (Possibly unfed wd got angry)
4 -> soft restart (Possibly with a restart command)
5 -> wake up from deep-sleep
Looking at the provided code you can decide from what reason the chip is restarting. -
• #7
Thanks for your replies. I tried the above but the only readable I got back was something about
cal sector 1019
andfreq trace enable 0
.Below code seems to work pretty consistant without resets. Start gets called and I can send additional graphics commands to the screen via the left side of the IDE and they work :
var exports={}; var C = { OLED_WIDTH : 128, OLED_CHAR : 0x40, OLED_CHUNK : 128 }; // commands sent when initialising the display var initCmds = new Uint8Array([ 0xAE, // 0 Display off (all pixels off) 0xA0, 0x53, // 1 Segment remap (com split, com remap, nibble remap, column remap) 0xA1, 0x00, // 3 Display start line 0xA2, 0x00, // 5 Display offset 0xA4, // 7 Regular display 0xA8, 0x7F, // 8 Set multiplex ratio: 127 0xB3, 0x00, // 10 Front clock divider: 0, Fosc: 0 0xAB, 0x01, // 12 Enable internal Vdd 0xB1, 0xF1, // 14 Set phase periods - 1: 1 clk, 2: 15 clks 0xBC, 0x08, // 16 Pre-charge voltage: Vcomh 0xBE, 0x07, // 18 COM deselect voltage level: 0.86 x Vcc 0xD5, 0x62, // 20 Enable 2nd pre-charge 0xB6, 0x0F, // 22 2nd Pre-charge period: 15 clks 0xA4, // 24 normal display 0xAF, // 25 display on ]); // commands sent when sending data to the display var flipCmds = [ 0x15,// columns 0, C.OLED_WIDTH - 1, 0x75, // rows 0, 127 ]; function update(options) { //TODO } exports.connect = function(i2c, callback, options) { update(options); var oled = Graphics.createArrayBuffer(C.OLED_WIDTH,128,4); var addr = 0x3C; if(options) { if (options.address) addr = options.address; // reset display if 'rst' is part of options if (options.rst) digitalPulse(options.rst, 0, 10); } setTimeout(function() { // configure the OLED initCmds.forEach(function(d) {i2c.writeTo(addr, [0,d]);}); }, 50); // write to the screen oled.flip = function() { // set how the data is to be sent (whole screen) //i2c.writeTo(addr, [0].concat(flipCmds)); setTimeout(function() { flipCmds.forEach(function(d) {i2c.writeTo(addr, [0,d]);}); }, 50); setTimeout(function() { var chunk = new Uint8Array(C.OLED_CHUNK+1); chunk[0] = C.OLED_CHAR; for (var p=0; p<this.buffer.length; p+=C.OLED_CHUNK) { chunk.set(new Uint8Array(this.buffer,p,128), 1); i2c.writeTo(addr, chunk); } print("flip runs"); }.bind(this), 100); //wait for flipcmds to run }; // set contrast, 0..255 oled.setContrast = function(c) { i2c.writeTo(addr, 0, 0x81, c); }; // set off oled.off = function() { i2c.writeTo(addr, 0, 0xAE); }; // set on oled.on = function() { i2c.writeTo(addr, 0, 0xAF); }; // if there is a callback, call it now(ish) if (callback !== undefined) setTimeout(callback, 100); //TODO test // return graphics return oled; }; function start(){ print("this runs"); g.clear(); g.setContrast(128); g.setColor(1); g.drawString("Hello world 123!",32,32); g.drawRect(0,0, 127, 127); g.flip(); } I2C1.setup({scl:D5,sda:D4,bitrate:400000}); var g = exports.connect(I2C1, start);
However if I modify just a bit on this code things get weird. Trying to minify this code gives errors. For example, just commenting the print on line 70 breaks it. When I upload that it returns:
this runs F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 F 17 >F 17 F 0 Uncaught SyntaxError: Got '@' expected EOF at line 68 col 12 i2c@(addr, chunk); ^ in function called from system
So, it's really confusing to me what's going on exactly...
-
• #8
Thanks, it's great you got it working!
However that
F
message is concerning. That's not a print in your code is it?If not I think it's called when an assertion fails inside Espruino, which is a sign that somehow the RAM has got corrupted. What version of Espruino are you running on the ESP8266? Maybe you could try and cutting edge build, or if that is broken the 2v19 build.
It's a bit hard for me to track down here as I can't run it without having one of those displays, but if you could find a way of changing your code so it'll run without external hardware and still show the error then I can try and track it down here
-
• #9
No, I don't print it.
I'm running 2v19 which I flashed on it using this command:python "../esptool/esptool.py" --port COM6 --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size detect 0x0000 espruino_2v19_esp8266_4mb_combined_4096.bin
I now downloaded a cutting edge build from here: https://www.espruino.com/binaries/travis/master/espruino_2v19.99_esp8266_4mb.tgz
and installed it with the following command:python "../esptool/esptool.py" --port COM6 --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size 4MB-c1 0x0000 "boot_v1.6.bin" 0x1000 espruino_esp8266_user1.bin 0x3FC000 esp_init_data_default.bin 0x3FE000 blank.bin
However I get the same problem.
I modified my code a bit to "work" without the screen (just commenting all the writeTo calls):var exports={}; var C = { OLED_WIDTH : 128, OLED_CHAR : 0x40, OLED_CHUNK : 128 }; // commands sent when initialising the display var initCmds = new Uint8Array([ 0xAE, // 0 Display off (all pixels off) 0xA0, 0x53, // 1 Segment remap (com split, com remap, nibble remap, column remap) 0xA1, 0x00, // 3 Display start line 0xA2, 0x00, // 5 Display offset 0xA4, // 7 Regular display 0xA8, 0x7F, // 8 Set multiplex ratio: 127 0xB3, 0x00, // 10 Front clock divider: 0, Fosc: 0 0xAB, 0x01, // 12 Enable internal Vdd 0xB1, 0xF1, // 14 Set phase periods - 1: 1 clk, 2: 15 clks 0xBC, 0x08, // 16 Pre-charge voltage: Vcomh 0xBE, 0x07, // 18 COM deselect voltage level: 0.86 x Vcc 0xD5, 0x62, // 20 Enable 2nd pre-charge 0xB6, 0x0F, // 22 2nd Pre-charge period: 15 clks 0xA4, // 24 normal display 0xAF, // 25 display on ]); // commands sent when sending data to the display var flipCmds = [ 0x15,// columns 0, C.OLED_WIDTH - 1, 0x75, // rows 0, 127 ]; function update(options) { //TODO } exports.connect = function(i2c, callback, options) { update(options); var oled = Graphics.createArrayBuffer(C.OLED_WIDTH,128,4); var addr = 0x3C; if(options) { if (options.address) addr = options.address; // reset display if 'rst' is part of options if (options.rst) digitalPulse(options.rst, 0, 10); } setTimeout(function() { // configure the OLED //initCmds.forEach(function(d) {i2c.writeTo(addr, [0,d]);}); }, 50); // write to the screen oled.flip = function() { // set how the data is to be sent (whole screen) //i2c.writeTo(addr, [0].concat(flipCmds)); setTimeout(function() { flipCmds.forEach(function(d) {/*i2c.writeTo(addr, [0,d]);*/}); }, 50); setTimeout(function() { var chunk = new Uint8Array(C.OLED_CHUNK+1); chunk[0] = C.OLED_CHAR; for (var p=0; p<this.buffer.length; p+=C.OLED_CHUNK) { chunk.set(new Uint8Array(this.buffer,p,128), 1); //i2c.writeTo(addr, chunk); } //print("flip runs"); }.bind(this), 100); //wait for flipcmds to run }; // set contrast, 0..255 oled.setContrast = function(c) { /*i2c.writeTo(addr, 0, 0x81, c);*/ }; // set off oled.off = function() { /*i2c.writeTo(addr, 0, 0xAE);*/ }; // set on oled.on = function() { /*i2c.writeTo(addr, 0, 0xAF);*/ }; // if there is a callback, call it now(ish) if (callback !== undefined) setTimeout(callback, 100); //TODO test // return graphics return oled; }; function start(){ print("this runs"); g.clear(); g.setContrast(128); g.setColor(1); g.drawString("Hello world 123!",32,32); g.drawRect(0,0, 127, 127); g.flip(); } I2C1.setup({scl:D5,sda:D4,bitrate:400000}); var g = exports.connect(I2C1, start);
Flashing this returns "this runs", but if I then run start() manually from the left side, it returns the following:
>start(); this runs =undefined >F 15 F 15 F 15 F 17 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0 F 0
-
• #10
Hi - thanks for stripping that back! I can reproduce here. It seems to all fall apart right after
var initCmds = new Uint8Array([...
.I've just looked into this and it was a problem with how ArrayBuffers were handled when using the very compact memory layout that ESP8266 uses with 12 byte vars. I believe I've fixed it now if you use a cutting edge build
-
• #11
Thanks for looking into it, that indeed solved it! :D
-
• #12
I just created a pull request to add this module :)
-
• #13
Thanks! Just merged - I'll update the website with this soon!
Hey everyone!
For a project I'm working on I decided I'd like to use Espruino so I flashed it on an ESP8266.
I have a GME128128-02 1.5" OLED display that is powered by a SSD1327 that I'd like to use. For my purposes I don't need any grayscale usage, only monochrome and only I2C is relevant for this specific screen.
There doesn't seem to be a module for this specific screen model, and none of the ones I tried worked so I decided to try and modify the SSD1306 module. I've already looked at some Arduino/C libraries for the SSD1327 driver and had a peek at the datasheet but after some evenings experimenting I have to admit I'm quite stuck. When I flash the current code I have, I get a bunch of vertical lines for a few seconds, before the screen seemingly turns off.
I feel like I'm probably not too far off but perhaps anyone here can immediately spot my mistakes and help me out. Thank you in advance!
My code:
1 Attachment