Berry Script: lightweight embedded scripting language for microcontrollers

hasheddan | 104 points

A similar project: https://toitlang.org (or https://toit.io).

Currently it's only targeting the ESP32 family, but the code is pretty portable. By default, it probably also needs more resources due to OS-like abstractions, allowing for multiple containers to run on parallel, etc. Obviously that also brings some nice advantages. For example, installing or updating, a new container is just a few lines of code.

We have been working on it for more than 5 years now, and it's definitely at a stage where lots of projects would benefit from it.

floitsch | 23 days ago

Embedded Rust alternative: https://github.com/rhaiscript/rhai

ost-ing | 23 days ago

This seems to have almost the exact same feature set and use-case as Lua. How does it compare in performance? I doubt it can be faster than Lua 5.5

90s_dev | 23 days ago

I looked at a bunch of these tiny languages, and ported several of them to the ESP32, contributed some enhancements for CircuitPython.... but eventually settled on tinyexpr, and just... Not having any data types besides numbers.

TinyExpr is very fast, it's just an expression parser, and when you pair it with a state machine engine, you can do stuff like:

"While you are in state 4, if pin Y changes, set machines.foo.state5 to 1".

Which is perfectly sufficient for most "Add a bit of configurability" tasks, I can edit behavior from my phone and make small tweaks.

Anything beyond that I would much rather just do in C++, with access to all my nice dev tools and LLMs and debuggers and linters and version control.

I really like the idea of a full language on a microcontroller, but... You usually need so many bindings and application specific functions that you always wind up needing some C++ code anyway.

I also looked at ESPHome, which is super impressive, very nice to use, but light on runtime web UI configurability, the protocol is nonstandard, and the Python client libs used to have frequent breaking changes.

https://github.com/EternityForest/ArduinoCogs

eternityforest | 21 days ago

Doesn't seem to have received any updates in the last 2 years. I'm wondering what the use cases are for this type of scripting in embedded systems, though?

sagacity | 23 days ago

A microcontroller project I use has made use of JerryScript [1] instead. It uses JavaScript and is much more common and approachable to beginners. I have never heard of Berry.

[1] JerryScript https://jerryscript.net/

[2] Traquito: https://traquito.github.io/tracker/source/

[3] https://traquito.github.io/copilot/walkthrough/#step-3-desig...

firesteelrain | 22 days ago

Embedded GCs will never take off, waste of power. Everyone whose tried is either completely niche or out of the game. People should stop reinventing the wheel and just use C.

halfmatthalfcat | 22 days ago

Why can't this just be an embeddable subset of some other well-known language instead of a brand new language?

I've learned two dozen programming languages. I'm so tired.

eric-p7 | 22 days ago

why not use Moddable's [1] xs engine [2]? it's JavaScript ...

[1] https://www.moddable.com/ [2] https://github.com/Moddable-OpenSource/moddable/tree/public/...

abdellah123 | 23 days ago

Reminds me a lot of Ruby! Gorgeous.

Alifatisk | 23 days ago

The very first feature listed is "nil." No thanks.

jelder | 22 days ago

> Ideal for use in microprocessors.

Seems to be targeted at microprocessors not microcontrollers per the title.

thebruce87m | 23 days ago