Program size of Johnny Five?

Hi there, newbie here!

I'm new to engineering, but not new to neither Java nor JavaScript. I'm fine with using the IDE that's so easily downloaded from here, but since I'm also more comfortable with Node.js, Johnny Five looks very interesting to me. However, to run a J5 program, I first have to install a Firmata program (let alone using a compatible firmware).

I wonder what the impact on program size and CPU is by using a secondary system like Johnny Five?

I don't know anything about Johnny Five but you can be assured that an Arduino cannot run Javascript.

...R

Robin2:
Arduino cannot run Javascript.

I know, that's what Johnny Five is for. It converts ECMAscript to executable code. I don't know what it does in the background except that it interfaces with Firmata.

My question is regarding if a transcoded program is larger by default (regardless of program complexity) than just using the Arduino IDE.

J5 runs Javascript on a PC or ARM board running Linux. J5 does not download code into the Arduino. The Arduino must be pre-programmed with the Firmata sketch using the Arduino IDE. In the simplest case, J5 and Firmata communicate over USB serial. J5 sends commands to the Arduino that map to pinMode, digitalRead, and digitalWrite which the Arduino performs and returns results.

An Arduino programmed with Firmata can be used with Python, for example, so J5/Javascript is not required. The language used to communicate with the Arduino makes no difference on the Arduino code size or performance.

gdsports:
The language used to communicate with the Arduino makes no difference on the Arduino code size or performance.

But surely, Firmata adds some overhead to your program? Every byte counts, but are you saying the overhead is insignificant?

designbyadrian:
But surely, Firmata adds some overhead to your program? Every byte counts, but are you saying the overhead is insignificant?

I have never used it, but my understanding is that Firmata is the complete Arduino program, rather than being an addition to some other program.

Of course there is nothing to stop you writing a different Arduino program that is specific to your needs as a complete alternative to Firmata, However my guess is that the Javascript program you plan to use expects to see Firmata on the Arduino.

...R

Firmata is loaded onto the Arduino.

Johnny Five takes Node.js code and feeds it into Firmata, which turns it into code the Arduino understands.

Would such a program take up a lot more memory on the Arduino, than if I'd just kept with Java in the Arduino IDE in the first place?

designbyadrian:
Johnny Five takes Node.js code and feeds it into Firmata, which turns it into code the Arduino understands.

I don't think that is correct.

My understanding is that Firmata can respond to various commands that are sent to it - for example to report the state of a particular digital I/O pin.

To do that does not require any code to be sent to Firmata for conversion to Arduino commands. AFAIK all the commands are already in Firmata.

...R

What difference does it make to you if Johnny Five adds some overhead (I'm sure it does)? If it does what you want, the size of the code is irrelevant (as long as it fits in the Arduino).
This smells of an X/Y problem.

Pete

Johnny Five takes Node.js code and feeds it into Firmata, which turns it into code the Arduino understands.

No, J5/node.js code sends messages (data, not code) to firmata running inside the Arduino. The firmata code interprets the messages, performs the requested operations such as reading the state of a digital pin, then returns the result as firmata response messages to J5/node.js. A robot built with J5/firmata is a two headed monster. The J5/node.js head is the master and the firmata head is the slave. The node.js code and the firmata code need continuous communication to operate. Even if the Arduino is battery powered, unplugging the USB serial connection causes the Arduino to stop operating because it no longer receives messages from the node.js code.

The firmata protocol specification is available.

Would such a program take up a lot more memory on the Arduino, than if I'd just kept with Java in the Arduino IDE in the first place?

The Arduino language is not Java but C/C++ with a few simplifications.

J5/node.js does not compile and inject code into the Arduino so there is no easy way to compare code and memory sizes. A J5/node.js robot requires the PC to be running and communicating with the Arduino at all times.

el_supremo:
This smells of an X/Y problem.

I prefer writing efficient programs, both in terms of CPU and memory, and so should you.

designbyadrian:
I prefer writing efficient programs, both in terms of CPU and memory, and so should you.

I think that that has increased the odour :slight_smile:

...R

@Robin2 :slight_smile:

designbyadrian:
I prefer writing efficient programs, both in terms of CPU and memory, and so should you.

I do "prefer" to write efficient programs but I don't obsess over every microsecond and byte. If I were using someone else's program (such as the unlikely case of J5) it wouldn't bother me that there's overhead - it goes with the territory. I certainly would not be looking at rewriting it just to satisfy some compulsion for temporal and spatial efficiency.
If you are that concerned over efficiency and write your own program, are you also going to take apart every Arduino library to make sure that not a microsecond or byte is, in your view, wasted before you use it? Or would you just rewrite any and all libraries as well?
Seems to me that when you get a job, you aren't going to last long because you won't be spending your time effectively.

Pete