• Ok, so I just looked at your code, and it looks like you'd disabled playing sound in it? I had to remove a return statement in playSoundFile. I'll post up here as I think it's useful for everyone though.

    Also just a note - I'd avoid putting save() at the end of the code you upload as it upsets the Web IDE. To test, add 'setTimeout(onInit,100);` if you have to - otherwise just type it on the left-hand side.

    I got the out of memory error you were having, but I think that's because just because you were using up all the memory rather than an actual bug in your code. If I deleted the two images and drawImage statements you had it seemed pretty reliable (I'd also replaced the DS18B20 code with E.getTemperature() to use the internal sensor - as I couldn't be bothered to wire a sensor up :).

    Memory goes up a bit when playing, and then drops off when it's finished - but it always goes back to the same base level after startup, and it's been working for about an hour now without issues.

    So it's basically just a matter of making your code use a bit less space...

    • Try with a smaller waveform buffer (var w = new Waveform(1024, {doubleBuffer:true}); still seems to work well for me). You might be able to get away with 512, but it's possible you'd find the waveform stutters a bit.
    • You can put comments in, but it's best to put them outside your functions. Putting them inside uses space (unless you minify!).
    • Or turn on minification in settings (using Esprima is fastest) - that drops memory usage from 1700 to 1470ish
    • Turn on 'save on send' in settings. This saves your complete source code into flash memory when you send it over (so has the same sort of effect as save() - which you should remove). However, it executes the functions straight from flash memory if it can. It means the memory usage (with minification) drops to under 1000 vars and gives you a lot of leeway. Only issue is you're best using it with minification, as otherwise all comments get saved, including the ones outside functions.
    • There's some info on writing code to make it more memory efficient in Espruino here: http://www.espruino.com/Performance - it might help, but I'm not sure there any many easy fixes for you, apart from maybe trying to keep function/variable names a bit shorter (but there's no need if you're using minification).

    Hope that helps - but yeah, I think you're basically fine. If you absolutely need more then there's always the Pico - it'd need more wiring but it does have a bit more RAM. There's also the WiFi board too, which has even more RAM available.

About

Avatar for Gordon @Gordon started