2

Coming from JS, I find it very difficult to program Arduino in C++ (not even knowing which version or what features are supported), being bound to the loop and delay, not being able to (easily) use anonymous functions in parameters or async code.

I know JS isn't natively supported by Arduino, but I know languages can be transpiled.

I have seen many solutions, so just to pick few:
JohnnyFive J5, which runs via cable on a host PC,
NectarJS with their arduino-uno target,
or andrei-markeev/ts2c which converts ES3 to C89.

Each of them come with their own limitations and it's very difficult to find the right without prior experience with IoT. Did anyone walk this path already and found a viable solution?

  • 1
    Forgive me if this question is inappropriate for this site. This is my first Q here and I am totally new to IoT. However, outright downwoting, without providing a feedback isn't really constructive and welcoming to new members. – Qwerty Feb 14 at 22:18
  • 1
    I suggest you look at the boards and components that are supported by these frameworks before you commit to any one. Maybe start here, johnny-five.io/api and see if the supported components will cover what you are trying to achieve. – Eat at Joes Feb 14 at 22:35
  • 1
    my recommendation is, learn C++ – Juraj Feb 15 at 5:37
  • Just dive in and learn C++ while you go. You could also try learning Python so you can program your Teensy in Circuitpython or Micropython (although I now see it might not be easy to get it going on the Teensy). – StarCat Feb 15 at 8:56
2

Even if such a transpiler exists (which I don‘t know) you will still have to deal with the loop structure and the fact that you should avoid using delays. On a microcontroller you have to forget about things like multithreading and even dynamic memory allocation should be used carefully. Most of those things that make a programmer‘s life easy on bigger systems are usually paid with ram or cpu power, but on a microcontroller with some kB RAM there are only few resources to pay with.

So my recommendation is to learn C++ instead of looking for ways to convert code from another language, which will probably introduce its own problems. You‘ll soon find yourself one layer below and there are exciting things that higher languages hide from you.

| improve this answer | |
  • Is it possible that some of the C++ constructs are valid, but not working specifically on IoT devices? (In my case the Teensy LC or 3.2.) – Qwerty Feb 17 at 13:26
0

Why don't you just start with a microcontroller that supports Javascript?

I find the Adafruit Circuit Playground Express quite fun to work with. You can still connect sensors and other hardware, the same as you can do with Arduino. It also has a bunch of sensors built-in.

You can try it out right now without owning a hardware board at adafruit.makecode.com. Click the Javascript tab on the top of the page.

Using a JS>Arduino transpiler will probably cause a lot of headache, since it often won't do what you expect it to do.

| improve this answer | |
  • I bought the Teensy specifically because it's best for HID. I want to repurpose an old keyboard, but if I were to do something larger, I would probably choose a board that supports node.js and JavaScript. – Qwerty Feb 17 at 13:22
  • 1
    There aren't any boards that support node.js sadly. You can run Johnny Five with almost every board, but that runs on your PC. It allows you to read the board through the USB cable. – Kokodoko Feb 18 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.