-
-
I looked into the mentioned sections but did not find anything applicable.
Just to stop being abstract: here is my code for the MDBT42Q
let Neopixel = require("neopixel"); let DisplaySize = 16*16; let Display = new Uint8ClampedArray(DisplaySize*3); let PixelOffset = new Int16Array(256); for (let i = 0; i < 16; i++) { for (let j = 0; j < 16; j++) { let Index = i*16 + j; if (i % 2 === 0) { PixelOffset[Index] = Index*3; } else { PixelOffset[Index] = (i*16 + 15 - j)*3; } } } let normalized = new Uint8ClampedArray(16*16); for (let i = 0; i < 256; i++) { normalized[i] = ( i === 0 ? 0 : Math.round(1 + 256/4*(i/256)*(i/256)) ); } let TemperatureMap = new Uint8ClampedArray(DisplaySize); for (let i = 0; i < 256; i++) { TemperatureMap[i] = 0; } let ColorMap = new Array(16); for (let i = 0; i < 16; i++) { ColorMap[i] = E.HSBtoRGB(i/16, 1, 1, true); } /**** processNextFrame ****/ let HeatX = Math.round(16*Math.random()); // where to insert new intensity let HeatCount = Math.round(12*Math.random()); // how long to heat there let normalizedRGB = new Uint8ClampedArray(3); // used by "processNextFrame" function processNextFrame () { "compiled"; let i,j,k,l; for (i = 15; i > 0; i--) { // intensity diffusion for upper rows k = i*16; TemperatureMap[k] = Math.round(( 6*TemperatureMap[k] + 2*TemperatureMap[k-16] + TemperatureMap[k-15] )/9); for (j = 1; j < 15; j++) { k++; TemperatureMap[k] = Math.round(( 6*TemperatureMap[k] + TemperatureMap[k-17] + 2*TemperatureMap[k-16] + TemperatureMap[k-15] )/10); } k++; TemperatureMap[k] = Math.round(( 6*TemperatureMap[k] + TemperatureMap[k-17] + 2*TemperatureMap[k-16] )/9); } /**** heat around HeatX, cool elsewhere ****/ HeatCount -= 1; if (HeatCount < 0) { HeatX = Math.round(16*Math.random()); HeatCount = Math.round(12*Math.random()); } l = HeatX-4; for (i = 0 /*, l = HeatX-4*/; i < l; i++) { TemperatureMap[i] = TemperatureMap[i] - 8; // exploits clamping } i = HeatX-4; i++; if (i >= 0) { TemperatureMap[i] = TemperatureMap[i] + 2; } // dto. i++; if (i >= 0) { TemperatureMap[i] = TemperatureMap[i] + 5; } // dto. i++; if (i >= 0) { TemperatureMap[i] = TemperatureMap[i] + 7; } // dto. i++; TemperatureMap[i] = TemperatureMap[i] + 8; // dto. i++; if (i < 16) { TemperatureMap[i] = TemperatureMap[i] + 7; } // dto. i++; if (i < 16) { TemperatureMap[i] = TemperatureMap[i] + 5; } // dto. i++; if (i < 16) { TemperatureMap[i] = TemperatureMap[i] + 2; } // dto. i++; for (; i < 16; i++) { TemperatureMap[i] = TemperatureMap[i] - 8; // exploits clamping } /**** prepare display ****/ let RGB /*, normalizedRGB = new Uint8ClampedArray(3)*/; let RowStart, RowEnd; for (i = 0; i < 16; i++) { // row-wise RowStart = i*16; RowEnd = RowStart + 15; for (j = 0, k = RowStart; j < 16; j++, k++) { // column-wise RGB = ColorMap[j]; Temperature = TemperatureMap[k]; if (Temperature < 16) { Temperature = 0; } else { Temperature = Math.max(48,Temperature)/256; } normalizedRGB[0] = normalized[Math.round(RGB[1]*Temperature)]; normalizedRGB[1] = normalized[Math.round(RGB[0]*Temperature)]; normalizedRGB[2] = normalized[Math.round(RGB[2]*Temperature)]; Display.set(normalizedRGB, PixelOffset[k]); } } /**** show display ****/ Neopixel.write(D22,Display); /**** wait for next frame and proceed ****/ let now = Date.now(); if (Timestamp > 0) { print(now-Timestamp); } Timestamp = now; setTimeout(processNextFrame,0); } let Timestamp = 0; setTimeout(processNextFrame,100); // give Espruino some time to start up
it runs even without an attached Neopixel matrix display - but having one is far more impressive...
-
By the way: I just added some timing measurements to my code and found out that the MDBT42Q is almost twice as fast as the ESP32!
However, an acceleration by the factor of 3 would still be desirable...
Addendum: I also found a continuous slow-down while the program was running (regardless of the platform)
-
I briefly looked through the build instructions for Espruino under macOS - and it looked like too much effort for the limited time I have - thus, I'll have to stick with double precision floats.
Using "compiled" failed with the message
WARNING: Function marked with "compiled" uploaded in source form [ COMPILER MESSAGE ] : TypeError: Cannot read property 'type' of null
which I do not understand right now
-
indeed, I forgot about "compilation" when optimizing my code for the ESP32 (well, as you said, it's not supported anyway)
While there is indeed no explicit integer arithmetics in JavaScript, there are still tricks to inform JavaScript about the preference of integer arithmetics (these are used by ASM.js, e.g.).
And, perhaps, there is any other hidden (or less documented) "trick" to speed things up, e.g., by using single-precision FP rather than double-precision etc.
Performance of the RasPi pico is, nevertheless, impressive! (particularly when compared with its price!)
-
Hello,
are there any tips how I may speed up numeric computations (particularly basic integer arithmetics) on an ESP32 running Espruino?
My current project basically mimics a cellular automaton modeling s.th. like thermal diffusion and visualizing the result on a Neopixel matrix display. Numerics is limited to basic integer arithmetics but involves a lot of Math.round/min/max calls. Colors and brightnesses are then looked up using tables built using Uint8ClampedArray.
The program is running, but turns out to be surprisingly slow - especially when compared with a similar implementation for a Raspberry Pi Pico running Kaluma (and the latter has not yet been optimized in any way!) By the way: running the same code on an Espruino MDBT42Q gives a performance comparable to the ESP32 (which surprised me as I expected the ESP32 to run faster)
Are there any tips what I could do to speed the program up?
(if my description sounds to abstract, I could also share my code - approx. 120 lines)
Thanks in advance for any help!
With greetings from Germany,
Andreas Rozek
-
Ok,
I meanwhile managed to pair the HC-05 with my Mac.
It seems that the intensity of the chip's BT signal is so low (especially compared to all other BT devices I'm currently using) that my Mac simply did not receive it properly. Bringing it closer to my computer solved the "problem".
Keep that in mind when you try yourself!
Additional note: once paired, the special "trick" for macOS mentioned in the original instructions does not seem to be necessary any longer: Chrome now properly recognizes Bluetooth serial ports as well.
-
-
well, but the official instructions mention the HC-05 explicitly and my intention was to program an original Espruino via Web BT from a Mac using the Web IDE - as shown
-
Will Bluetooth automatically be activated after soldering the HC-05 module onto the board (and resetting, of course)? Or is a special firmware required (the IDE let's me choose between three different versions - I tried all three, but none worked)?
I also just equipped two original Espruinos with HC-05s - but neither my Mac nor any BT scanner shows any reaction
-
I just completed a little project with the RasPi Pico, Kaluma and a 16x16 Neopixel matrix. While I had to write a Neopixel driver myself (see GitHub), I was really impressed by the overall performance of the RP2040 running Kaluma (roughly 5x compared to an MDBT42Q)
The Kaluma Web IDE technically resembles that of Espruino (Web Serial API used for communication, REPL, integrated Editor with syntax highlighting, code folding and linting) Note: you do not have to sign up in order to use the Kaluma IDE.
There also seems to exist some kind of (yet undocumented) code ecosphere that allows to "require" external modules.
Concerning the business aspects of having Espruino boards with the RP2040: Arduino also already sells such boards (incl. Wifi, BT and sensors) for much more than a single RasPi Pico costs.
I'll still use my Espruino boards (and the Bangle.js, of course) but having RP2040s and Kaluma raises the limit of what is possible without having to program in C/C++ or Python
-
-
-
I just tried to test a recently bought Neopixel RGB LED matrix. Since first experiments with an obniz board could test up to 85 LEDs only (but they were working fine), I though it might be a good idea to reactivate a MDBT42Q (after a firmware update to 2v10).
A very first attempt
let Neopixel = require("neopixel") Neopixel.write(D22, [255,0,0])
showed a green(!) pixel - and
let Neopixel = require("neopixel") Neopixel.write(D22, [0,255,0])
turned it red(!) - blue seems to be fine.
Are "R" and "G" just switched? That would sound strange...
-
I tried as you said, but my bangle rebooted in the middle of the transfer. Nothing bad happened, just the transfer got stuck...
I then tried again, but with the same result.
Anyway, my "100-retries-approach" seems to work "reliably" and gives my the bleeding edge firmware (i.e., my thumb is bleeding)
-
Thus, my current tips are:
- if nrfTools give you the message
xxx bytes were sent while 0 bytes were reported as received
just retry - even if you have to retry approx. 100 times! (it still only takes a few minutes - after completion, connect the Espruino Web IDE with your Bangle.js and check, that the terminal displays the correct (i.e. new) firmware version!
- if nrfTools give you the message
-
Ok, I found out that every retry added approx. 1% of the firmware, so I had to retry approx. 100x in order to get everything sent to my device~~ - at least, it claimed so, but my firmware is still the old one.~~
Correction: no, it did update my firmware, I just looked at the wrong place. The best place to see the current firmware version is in the Web IDE console after connecting to the watch
-
-
-
-
-
although we don't add VAT any more so the actual extra charge is probably around €6
Well, actually, I had to pay much more as DHL Express handled customs for me - but I don't care too much as this will be the only developer device I'll buy and the Kickstarter edition was promised to not require extra customs
I'd have thought for now the Bangle.js 1 forum would be ok.
Ok, but good to know.
It'd be well worth upgrading to a recent cutting edge build of the firmware
I'll do so after charging.
Thanks for your responses!
-
-
Hello,
I just got my Bangle.js v2 Developer Edition from the Espruino shop - it came quite quickly, but I had to pay customs extra as the UK is no longer part of the EU...
Here are my first questions:
- is there a dedicated forum page for Bangle.js v2, perhaps even one for the Developer Edition (just in case that there are some differences between Kickstarter and Developer edition)?
- do I still have to care about the orientation of the magnetic charging plug (I tried the same orientation as for Bangle.js v1 and fortunately did not break my device)
- how long does it take for the device to get fully charged?
Thanks in advance for your effort!
With greetings from Germany,
Andreas Rozek
- is there a dedicated forum page for Bangle.js v2, perhaps even one for the Developer Edition (just in case that there are some differences between Kickstarter and Developer edition)?
Just to let you know: binding
Math.round
to a variablerounded
and callingrounded(...)
rather thanMath.round
speeds my code up by approx. 100/1500 = approx. 7%! Additionally bindingMath.max
tomax
gave me a total of roughly 10% speedup(!)