Author Topic: Cheap microcontroller for JavaScript or fast interpreter.  (Read 4173 times)

0 Members and 1 Guest are viewing this topic.

Offline qqclient

  • Newbie
  • Posts: 4
  • Country: cn
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #25 on: December 30, 2024, 02:16:30 pm »
you may try the project names Espruino, which utilizes ESP32 to implement javascript engine parsing js.
 

Offline qqclient

  • Newbie
  • Posts: 4
  • Country: cn
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #26 on: January 03, 2025, 04:46:31 pm »
how about Espurino?
it is a project that implements a interpreter on some MCUs such as ESP32,ESP8266 and stm32 etc.
 

Offline Fire Doger

  • Regular Contributor
  • *
  • Posts: 209
  • Country: 00
  • Stefanos
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #27 on: January 04, 2025, 05:58:59 pm »
For similar processing (sound reactive RGB) I used C# and win forms.

Autogain, FFT, binning etc was done with simple functions using exactly uint32, 16, etc.. to be able to directly copy it to MCU.
result graphs was done on a canvas pixel by pixel.

It wasn't pretty but in a day I could fast experiment with code and adjust real-time the coefficients with sliders and view the result.
 

Offline bson

  • Supporter
  • ****
  • Posts: 2505
  • Country: us
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #28 on: January 04, 2025, 08:27:05 pm »
Obviously, any interpreter for a dynamically typed language with managed memory is going to be orders of magnitude slower than a language like C/C++ that's designed to be statically typed and analyzed (more so C++) at compile time, but on a fast modern processor it can still be fast enough.  Just probably not for any sort of DSP applications, but it's not beyond the realm of possibility with a 400MHz CM7.  However, this assumes it doesn't do things like garbage collect at the wrong time, and doesn't expect the interpreter to run out of RAM.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6314
  • Country: 00
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #29 on: January 06, 2025, 05:27:59 am »
Have you tried to ask chatgpt to translate it for you?  You can give it as many hint as you need, and then review the code and tweak.

May be a time saver.
 

Online Georgy.MoshkinTopic starter

  • Regular Contributor
  • *
  • Posts: 218
  • Country: hk
  • R&D Engineer
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #30 on: January 07, 2025, 04:40:14 am »
Have you tried to ask chatgpt to translate it for you?  You can give it as many hint as you need, and then review the code and tweak.
Instead, I ask it to find errors in my translation. It has spotted type casting and signed/unsigned problems several times.
Translation from C to JavaScript itself is very easy for me.
I do things like this:
Code: [Select]
// JavaScript:
maxIndHistory.splice(0,1); // shift
maxIndHistory.push(curSpectrumMaxInd); // store

// C:
memmove(&maxIndHistory[0],
&maxIndHistory[1],
sizeof(maxIndHistory)-sizeof(maxIndHistory[0])); // <--- shift
maxIndHistory[HISTORY_SIZE-1]=curSpectrumMaxInd; // <--- store

Problems often emerge from things like this:
Code: [Select]
// JavaScript arm_sqrt_q31() "simulation"
deviation=Math.round(Math.sqrt((deviation/2)/0x7FFFFFFF)*0x7FFFFFFF);
deviation=deviation/32768/16; // /32768 - convert to normal sqrt output /16 to scale into 0.255 range

// C:
deviation = deviation >> 1;
arm_sqrt_q31((q31_t)deviation,(q31_t *) &deviation);
deviation = deviation >> 19; // SHR 15+4 /32768 / 16
I need to maintain this stuff. Plus, I have a separate MATLAB-like script to calculate some coefficients. I'm in the process of eliminating this stuff. Will take some time, but it's worth it.
better late than never
 
The following users thanked this post: Siwastaja

Online Georgy.MoshkinTopic starter

  • Regular Contributor
  • *
  • Posts: 218
  • Country: hk
  • R&D Engineer
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #31 on: January 08, 2025, 01:29:54 pm »
Here is proof of concept of my DIY data visualization.
STM32 C code: macros DBG() passes variable name, size and data over serial connection to HTML web page
HTML+Javascript: using Web Serial API to receive commands sent by STM32 and dynamically create canvases to display data.
I think it's already better than STM32CubeMonitor :-DD
I just put DBG_1D() for any array and instantly see how it updates in Realtime in my web browser.
It would be perfect if everything can be done using single DBG(), but I haven't figured how to distinguish between variables/1d/2d arrays using plain C macros. That's why there are three macros DBG, DBG_1D and DBG_2D. As you can see, I made DBG_MAX() to implement scaling. The same way graph colors may be directly controlled from STM32 application. Any suggestions how to make it better?


better late than never
 

Offline shabaz

  • Frequent Contributor
  • **
  • Posts: 602
Re: Cheap microcontroller for JavaScript or fast interpreter.
« Reply #32 on: January 08, 2025, 02:17:34 pm »
It's possible to do things pretty much like that with zero (or almost zero) code, using (say) Kst.
All you need to do is log your serial data (if your serial console software supports that). Kst will act on file changes and plot in real-time.

I've tried doing it in Python in the past too, and it's possible to send the configuration over serial too. I chose to send out JSON from the microcontroller (not really a serial streaming protocol! there will be better options), and then the Python code self-creates charts according to what's coming over the JSON-over-serial (say, writing the following over the UART: {“temperature”: 21.7, “sound”: 45} {“sound”: 47} {“sound”: 44} {“temperature”: 21.5, “sound”:43} and so on).
Screenshot example below in case it gives you ideas.

Sometimes it's easier to do something custom for the task-at-hand, for instance using WebSerial and JavaScript as you have done, although just a personal preference, I don't do anything except simple displaying of values etc with JavaScript, I'd rather do any data work with Python or Matlab etc.
 
The following users thanked this post: georgd, pastaclub


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf