New Espruino - Testers Needed!

Posted on
  • Hi,

    Yesterday I completed some pretty big changes to Espruino that allow built-in functions to be referenced. This means you can now do some of the more interesting JavaScript stuff, like:

    >[1,2,3,4].map(console.log) 
    1 0 [1,2,3,4]
    2 1 [1,2,3,4]
    3 2 [1,2,3,4]
    4 3 [1,2,3,4]
    =[]
    >[1,2,3,4].map(Math.sin)   
    =[0.841470984807896549284,0.909297426825­681576190,0.141120008059867219074,-0.756­80249530792824685]
    >Math.min.apply(undefined,[1,2,3,4]) 
    =1
    

    As I said, they're pretty big changes. I've tested it against the tests that I have, but I'd be pretty sure that there were still outstanding problems, so I don't want to make a new release until it has been tested some more.

    Please can you help me out and let me know if anything's broken that was working before?

    Because you can now take the built-in functions and use them in ways that weren't intended (eg. SPI1.send.apply(I2C1,"foo")) you may be able to get some instability/odd errors when doing things like that and it'd be great if you could help find those. Even better if you can fix them too ;)

    To test the newest version, just flash via the Web IDE in the normal way, but copy and paste this URL into the flasher:

    http://www.espruino.com/binaries/git/com­mits/74d4bc574cfed38d0fc0d99f4d8b8ca07c0­c677a/espruino_1v60_espruino_1r3.bin
    

    Anyway, it'll be great to get this all released - I think this fixes the biggest incompatibility that Espruino had with normal JavaScript code.

  • I have tried the DS18B20 example code which since the setInterval fix (1v59) has worked faultlessly:-

    var ow = new OneWire(A1);
    var sensor = require("DS18B20").connect(ow);
    setInterval(function() {
      console.log(sensor.getTemp());
    }, 1000);
    
    However it now breaks after a couple of minutes with the following:-
    
    ERROR: Out of Memory!
    ERROR: Out of Memory!
    WARNING: Out of memory while appending to array
    ERROR: Out of Memory!
    at line 1 col 188
    {var a=[];this.bus.reset();this.bus.select(th­is.sCode);b&&(this.bus.write(68,!0),this­.bus.reset(),this.bus.select(this.sCode)­);this.bus.write(190);for(b=0;9>b;b++)a.­push(this.bus.read());return a}
                                                                                                                                                                                                ^
    in function "_readSpad" called from line 1 col 78
    in function "getTemp" called from line 2 col 30
    undefined
    in function called from system
    ERROR: Error processing interval - removing it.
    Execution Interrupted during event processing.
    
  • Installed and running fine. Not pushing it just now, but will have a prod and see what can be done.

  • Installed and tested with the code I've been working with lately (it's a control panel - takes input from a keypad, displays data on a PCD8544, and allows the user to set brightness of 5 channels of LEDs (output via analogWrite) for my desk lamp project. And it reads from a DHT11 (would be a DHT22, except I fried mine) and displays the temperature and "humidity".

    v60 seems to work without issue. I'm going to leave it running while I'm out with my code running on it (it's updating a display and reading a dht - though not logging anything - I've yet to move the PCD8544 off of SPI and onto a soft-SPI, though i'll do that later and see if that works reliably).

    The new PCD8544 driver doesn't work (rows after the first block of 8 are shifted left and slowly walk across the screen as flip() is called) , but that's unrelated to this - I'll take a look at it tonight. Edit: Looked, fixed, pull requested.

    After letting it run a few hours - no dice - same thing happens to me - after running for a while, it suddenly runs out of memory and dies. This happened at some point between 35 mins and 4.5 hrs. getTime() is returning accurate results (ie, that bug hasn't returned). The same code was running flawlessly overnight yesterday.

    ERROR: Out of Memory!
    WARNING: Out of memory while appending to array
    at line 1 col 92
    {pinMode(b.pin,"input_pullup");b.watch=s­etWatch(function(a){b.onwatch(a)},b.pin,­{repeat:!0})}
                                                                                                ^
    in function called from system
    Execution Interrupted during event processing.
    ERROR: Unknown Watch
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Got INT expected ')' at line 1 col 230
    {this.onreadf=a;this.i=0;this.out=1;pinM­ode(this.pin);var b=this;setTimeout(function(){digitalWrit­e(b.pin,0)},2);setTimeout(function(){pin­Mode(b.pin,"input_pullup");b.watch=setWa­tch(function(a){b.onwatch(a)},b.pin,{rep­eat:!0})},5);setTimeout(function(){b.onr­ead(b.endRead())},50)}
                                                                                                                                                                                                                                          ^
    at line 1 col 229
    {this.onreadf=a;this.i=0;this.out=1;pinM­ode(this.pin);var b=this;setTimeout(function(){digitalWrit­e(b.pin,0)},2);setTimeout(function(){pin­Mode(b.pin,"input_pullup");b.watch=setWa­tch(function(a){b.onwatch(a)},b.pin,{rep­eat:!0})},5);setTimeout(function(){b.onr­ead(b.endRead())},50)}
                                                                                                                                                                                                                                         ^
    in function "read" called from line 1 col 76
    in function "onread" called from line 1 col 22
    in function called from system
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Out of Memory!
    WARNING: Out of memory while appending to array
    ERROR: Out of Memory!
    at line 1 col 279
    {this.onreadf=a;this.i=0;this.out=1;pinM­ode(this.pin);var b=this;setTimeout(function(){digitalWrit­e(b.pin,0)},2);setTimeout(function(){pin­Mode(b.pin,"input_pullup");b.watch=setWa­tch(function(a){b.onwatch(a)},b.pin,{rep­eat:!0})},5);setTimeout(function(){b.onr­ead(b.endRead())},50)}
                                                                                                                                                                                                                                                                                           ^
    in function "read" called from line 1 col 38
    ERROR: Error processing interval - removing it.
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    at line 1 col 21
    {for(var a=0;6>a;a++)digitalWrite(d,0),b.send(64|­a,c),b.send(128,c),digitalWrite(d,1),b.s­end(new Uint8Array(this.buffer,84*a,84),c)}
                         ^
    in function "flip" called from line 2 col 219
    in function "uplcd" called from line 1 col 8
    in function called from system
    ERROR: Error processing interval - removing it.
    Execution Interrupted during event processing.
    >
    

    Code that made it:

    var rh=-1;
    var t=-1;
    var statusview=1;
    var menustate=0;
    var menuopt=0;
    var inval="";
    var colors=["BLUE","COOL","WARM","YELL","PIN­K"];
    var ledstate=[0.4,1,0.8,0,0.2];
    var menu=[0,4];
    var ledpins=[B0,C9,C8,C7,C6];
    
    var kp=require("KeyPad").connect([C12,C15,C0­,C1],[C2,C3,A0,A1], function(e) {onKey(e);});
    require("Font8x12").add(Graphics);
    
    function onKey(e){
    	var k="123A456B789C*0#D"[e];
    	if (e==12){
    		if (menustate==2){
    			menustate=0;
    		} else {
    			menustate++;
    		}
    		menuopt=0;
    		inval="";
    		uplcd();
    	} else if (e==14 && menustate) {
    		if (menustate==1) {
    			var v=E.clip(parseInt(inval),0,100);
    			v=v/100;
    			ledstate[menuopt]=v;
    			inval="";
    			uplcd();
    			setTimeout("upled();",500);
    		}
    	} else if (e==3 && menustate) {
    		if (menuopt>=menu[menustate]) {
    			menuopt=0;
    		} else {
    			menuopt++;
    		}
    		inval="";
    		uplcd();
    	} else if ((e&0x03)==3) {
    		console.log(k);
    	} else if (menustate==1) {
    		if (inval.length < 3) {
    			inval=inval+k;
    		} else {
    			inval="";
    		}
    		uplcd();
    	}
    
    	g.backlighton();
    }
    
    digitalWrite(A13,0);
    var g=require("PCD8544").connect(SPI2,C4,C5,­A3, function() {
            g.clear();
            g.setFont8x12();
            g.drawString("LCD OK",0,0);
            g.flip();
            g.bktim=0;
    });
    
    g.backlighton = function() {
    	digitalWrite(A2,1);
    	if (this.bktim) {
    		clearTimeout(this.bktim);
    		this.bktim=0;
    	}
    	this.bktim=setTimeout("digitalWrite(A2,0­);g.bktim=0;",5000);
    };
    
    var e=require("DHT11").connect(B0);
    
    setInterval("e.read(function(a){rh=a.rh;­t=a.temp;});",30000);
    
    setTimeout("setInterval(function(){uplcd­();},30000)",15000);
    
    function uplcd() {
    	g.clear();
    	g.setFont8x12();
    	g.drawString(t.toFixed(1)+" C "+rh.toFixed(1)+"%",0,0);
    	if (statusview==1) {
    		g.drawRect(3,14,8,39);
    		g.drawRect(12,14,19,39);
    		g.drawRect(23,14,30,39);
    		g.drawRect(34,14,39,39);
    		g.drawRect(43,14,48,39);
    		g.fillRect(3,(39-ledstate[0]*25),8,39);
    		g.fillRect(12,(39-ledstate[1]*25),19,39)­;
    		g.fillRect(23,(39-ledstate[2]*25),30,39)­;
    		g.fillRect(34,(39-ledstate[3]*25),39,39)­;
    		g.fillRect(43,(39-ledstate[4]*25),48,39)­;
    		g.setFontBitmap();
    		g.drawString("B",4,41);
    		g.drawString("C",14,41);
    		g.drawString("W",25,41);
    		g.drawString("Y",35,41);
    		g.drawString("P",44,41);
    	}
    	if (menustate==1) {
    		g.setFont8x12();
    		g.drawString(colors[menuopt],52,13);
    		g.drawString((100*ledstate[menuopt]).toF­ixed(),60,24);
    		if (inval) {
    			g.drawString(inval,60,35);
    		}
    	}
    	g.flip();
    }
    
    function upled() {
    	for (var i=0;i<5;i++) {
    		analogWrite(ledpins[i],ledstate[i]);
    	}
    }
    
    

    Also, sometimes the IDE just hangs while sending code to it - showing echo(0), and doing nothing. I'm not quite sure what it's doing, but it does it first thing when it runs, because if I send over code where echo(1); is the first line, it still hangs showing echo(0); until I ctrl+c, which breaks it out of whatever it's doing and it then successfully runs all the code I sent it.

  • I do also have the problem with the IDE Upload. Even with the old IDE. It has something todo with the Chrom/Serial/USB connection. My workaround is the connect and reconnect until i see the ESPRUINO Version information:

    Connected
    =undefined

    =undefined
    Connected
    =undefined

    =undefined
    Connected
    =undefined

    =undefined
    Connected
    =undefined
    echo(0);
    <<<<<{"VERSION":"1v59","BUILD_DATE":"Mar­ 25 2014","BUILD_TIME":"17:17:20","BOARD":"E­SPRUINOBOARD","CHIP":"STM32F103RCT6","CH­IP_FAMILY":"STM32F1","FLASH":262144,"RAM­":49152,"SERIAL":"33FFD705-41573033-2762­0843","CONSOLE":"USB"}>>>>>

    After that procedure uploading works as expected but much slower.

    Sacha

  • Great - thanks... I think I've tracked the memory leak down now. I'll post up when there's another version with it fixed.

    For upload, does this also happen with the old Espruino version or just the new one? It seemed to be an issue with all versions on some people's PCs. On the new Web IDE, go to Settings,Communications, and click 'throttle send'. It'll be slower but it shouldn't break.

  • Problem happens on old and new Web IDE for me too.
    BTW, flashing works fine at high speed in both versions.
    Throttle makes flashing horibbly slow, 30 minutes instead of seconds.
    So I take the same way Sacha does.

  • Ctrl + C , echo(1) , return will probably fix the issue too. But am I right in thinking that this is not anything to do with the recent change?

    New Espruino version is:

    http://www.espruino.com/binaries/git/com­mit_date/2014-04-02%2007:58:25%20+0100/e­spruino_1v60_espruino_1r3.bin
    

    That hopefully won't have the out of memory issue.

  • You are right, it is an old problem.
    Would it be an option to have 2 throttle buttons ?

    • one for flash
    • one for sending code

    The problem with terminal stopping to listen (or stop to receive) seems to be Chrome related. This happens very often from terminal window, not only after connecting. Is there any known bypass, which can run in the background ?

  • Can we talk about this on http://forum.espruino.com/conversations/­834? This thread is really just for the new firmware version - so I can be sure that I don't release something with a bunch of regressions in.

  • I never saw that behavior I described, with the console hanging at echo(0); and needing ctl+c to get the console to work, before trying with this version.

    Just happened with the new build, never seemed happen before.

    Edit - Oh, I think I see what's happening here - it's not showing anything returned until it's done sending entirely, and I started having problems with lost characters last night, and had to turn on the throttling. Sorry about that. I feel like I remember it showing output from the espruino while sending code with throttling....

    I've left it running my control panel code whole I'm at work.

    (Also, I seem to have screwed up on the pcd8544 driver - it works better, but still walks two pixels every time the screen is refreshed, I'll try again tonight, and see if I can get it to both not cut off the first two bytes and to refresh correctly)

    edit:

    Came home to this:

    =undefined
    ERROR: Out of Memory!
    WARNING: Out of memory while appending to array
    at line 1 col 104
    {pinMode(dht.pin,'input_pullup');dht.wat­ch=setWatch(function(t) {dht.onwatch(t);},dht.pin,{repeat:true})­;}
                                                                                                            ^
    in function called from system
    Execution Interrupted during event processing.
    ERROR: Unknown Watch
    ERROR: Out of Memory!
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Got INT expected ')' at line 8 col 135
        setTimeout(function() {pinMode(dht.pin,'input_pullup');dht.wat­ch=setWatch(function(t) {dht.onwatch(t);},dht.pin,{repeat:true})­;},5);
                                                                                                                                           ^
    at line 8 col 134
        setTimeout(function() {pinMode(dht.pin,'input_pullup');dht.wat­ch=setWatch(function(t) {dht.onwatch(t);},dht.pin,{repeat:true})­;},5);
                                                                                                                                          ^
    in function "read" called from line 6 col 33
    in function "onread" called from line 1 col 26
    in function called from system
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Out of Memory!
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Out of Memory!
    WARNING: Unable to create string as not enough memory
    ERROR: Out of Memory!
    WARNING: Out of memory while appending to array
    ERROR: Out of Memory!
    at line 9 col 58
        setTimeout(function() {dht.onread(dht.endRead());},50);
                                                              ^
    in function "read" called from line 1 col 38
    ERROR: Error processing interval - removing it.
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    at line 7 col 63
          spi.send(new Uint8Array(this.buffer,i*84,84+2*(i<5)),­ ce);
                                                                   ^
    in function "flip" called from line 31 col 12
    in function "uplcd" called from line 1 col 8
    in function called from system
    ERROR: Error processing interval - removing it.
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    at line 2 col 41
        g.setFontCustom(font, 32, widths, 12);
                                             ^
    in function "setFont8x12" called from line 24 col 23
    in function "uplcd" called from line 12 col 15
    in function "onKey" called from line 1 col 9
    in function "callback" called from line 8 col 27
    in function called from system
    ERROR: Out of Memory!
    ERROR: Invalid height
    at line 2 col 41
        g.setFontCustom(font, 32, widths, 12);
                                             ^
    in function "setFont8x12" called from line 3 col 19
    in function "uplcd" called from line 12 col 15
    in function "onKey" called from line 1 col 9
    in function "callback" called from line 8 col 27
    in function called from system
    ERROR: Error processing Watch - removing it.
    Execution Interrupted during event processing.
    ERROR: Out of Memory!
    ERROR: Invalid height
    at line 2 col 41
        g.setFontCustom(font, 32, widths, 12);
                                             ^
    in function "setFont8x12" called from line 3 col 19
    in function "uplcd" called from line 12 col 15
    in function "onKey" called from line 1 col 9
    in function "callback" called from line 8 col 27
    in function called from system
    ERROR: Error processing Watch - removing it.
    Execution Interrupted during event processing.
    
  • Math.round(47) returns 4631811479262199808
    Test runs with link from #8

  • @DrAzzy was this with the link from #8, or the one from before? Do you think you'd be able to track down exactly what was causing the memory leak? (by checking process.memory().usage after each call).

    @JumJum: thanks! I'll look into it.

  • @JumJum: fixed! Turns out that was the only function that had that problem, so good spot ;)

  • Tested directly from last nightly and works fine, thanks

  • Testing with http://www.espruino.com/binaries/git/com­mit_date/2014-04-03%2015:05:30%20+0100/ binary (wiznet version - I can't connect to normal version over USB - I get a "this device has malfunctioned" when I plug it in, and it's not visible to IDE)

    Using the above code, with the PCD8544.js from the website (that would be this version, to be perfectly clear)

          spi.send(new Uint8Array(this.buffer,i*84,84+2*(i<5)),­ ce);
    

    There is a memory leak, though.

    Edit: Tracked down the memory leak - maybe this isn't new in v60, though. Loses 2 memory units every time it changes font.

    >process.memory();
    ={"free":558,"usage":1242,"total":1800,"­history":378,"stackEndAddress":536909768­,"flash_start":134217728,"flash_binary_e­nd":134385804,"flash_code_start":1344430­08,"flash_length":262144}
    >g.setFontBitmap();
    =undefined
    >g.setFont8x12();  
    =undefined
    >process.memory()  ;
    ={"free":554,"usage":1246,"total":1800,"­history":378,"stackEndAddress":536909768­,"flash_start":134217728,"flash_binary_e­nd":134385804,"flash_code_start":1344430­08,"flash_length":262144}
    >
    

    Also, I've been occasionally seeing the wrong character come through in text sent from the espruino. For example:

    >process.memory();
    ={"free":678,"usage":1122,"total":1800,"­history":575,"stackEndAddress":536909768­,gflash_start":134217728,"flash_binary_e­nd":134385804,"flash_code_start":1344430­08,"flash_length":262144}
    

    Note where a " has been replaced with a g.

  • The USB issue seems to be because I switched to using the -Os compile flags. No idea why it's so unreliable (some builds work, some don't!). I've just switched back to -O3 and tweaked the size down in other ways.

    Thanks for tracking the leak down (it would have been from before) - it makes my life so much easier (just fixed it in a few minutes). Hopefully I've managed to so something about the odd characters too.

  • In new IDE sometimes, the list of ports is not refreshed.
    In my case it shows available port, but does not connect.
    Even after removing USB cable, it still lists the port.
    Restarting WebIDE does not change this, port is still listed.
    Sometimes then disconnecting USB cable and connecting again helps.
    Sometimes it needs an additional reset on Espruino.
    Never had this problem with old version.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

New Espruino - Testers Needed!

Posted by Avatar for Gordon @Gordon

Actions