Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Using hardware post and replies

Return to the Using hardware thread
Login to post to this thread

Using Arduino boards with EJS - Feb 2, 2013 at 11:55AM
Francisco Esquembre
192 Posts

EJS has now new a Model Elements to control Arduino boards.

The best way to learn how to use it is to inspect an examples. See attached zip with an example.

Before you start, you need to download and install Arduino standard software from This allows you to install the drivers for your computers AND install in your Arduino board the script StandardFirmata. Both things are a must before using the example attached. You install the script by running the Arduino software and selecting "File->Examples->Firmata->StandardFirmata. Then, click the "Upload" icon (looks like a small right arrow) in the task bar of the Arduino software. This step needs to be done only once (per board).

Now, open the attached Arduino example in the latest EJS and inspect the example (in particular, the Model -> Elements tab).

You need additional hardware for making things work. The boards just act as I/O boards. Whatever software you attach to them makes the real work. But if you are playing with these boards, you know this already.

Good luck!


Attached File:

Replies to Using Arduino boards with EJS

Re: Using Arduino boards with EJS - Mar 25 2013 8:03PM
Diego Racero
11 Posts

Hi Franciso, I`m now experimenting wiht Arduino Leonardo and I have a question.
In your example you're using linux and the following sentence


Should ¡ld I replace It for


Because I'm using windows and my Arduino board was installed in COM6 and connected through USB port.

Thank in advance for your help.

Re: Re: Using Arduino boards with EJS - Mar 26 2013 3:45AM
Francisco Esquembre
192 Posts

Yes, that should be it. Remember to install the Arduino drivers.
I don't think we have tested the Leonardo board, though...


Re: Re: Re: Using Arduino boards with EJS - Mar 27 2013 8:48AM
Diego Racero
11 Posts

Paco, thank you for your help. I replaced the line you suggested and It works perfectly well.
I used the temperture example but with some modifications because I´m tryin to perform a remote laboratory turning on and turning off a laser diode and illuminate a difraction slit.
Now I´m moving to work in the Moodle integration.

Surely I´ll be requesting for your help again.

Thank you very much in advance for that.

Re: Re: Re: Re: Using Arduino boards with EJS - Mar 02 5:35AM
Daniel Romero
3 Posts

Hello Paco,

I'm trying to do an easy control application with EJS to arduirno. I downloaded your example LedTempServo and I read it carefully. My application is easier than your example. I try to put high some digital arduino outputs, but in your example, when i want to put the output led1on (digital output 8 in aerduino board) and I put to true the checkbox, the digital output 8 remains in a low level.

Could yoy say me why I can't change the value of the digital output in you example with the checkbox?

Re: Re: Re: Re: Re: Using Arduino boards with EJS - Mar 02 6:53AM
Francisco Esquembre
192 Posts

Hello Daniel,

Did you install the StandardFirmata software in the Arduino card (using the software provided by Arduino)?

This Firmata is somewhere under the Examples menu of the Arduino software.


Re: Re: Re: Re: Re: Re: Using Arduino boards with EJS - Mar 02 9:35AM
Daniel Romero
3 Posts

No, I didn`t. Finally this was the problem, I did that and all was ok. Thank you for your help Paco.

Now, I´m trying to control the arduino PWM output using a wheel, for that I wrote the following instruction:

arduino.writeDigitalServo(9, value); (value was configured as int)

I configured the pin 9 as pwm mode using the following instruction:


In the visual folder, I put the fllowing conditions (see attached image), but when I modify the value with the wheel the board doesn`t work in PWM mode.

With this conditions we can not control the pin 9 output, so I changed the instruction "arduino.writeDigitalServo(9, value);" by "arduino.writeDigital(9, value);" and I have a compilation error in this line.

Do you know the reason of this?

Thank you.


Post edited March 2, 2015 at 9:36 AM EST.

Post edited March 2, 2015 at 11:12 AM EST.

Post edited March 2, 2015 at 11:14 AM EST.

Attached File: Servo.jpg

Re: Re: Re: Re: Re: Re: Re: Using Arduino boards with EJS - Mar 02 11:36AM
Francisco Esquembre
192 Posts

Hello again,

Did you use the setDigitalServoMode() method in the Initialization?

This is what is written in the documentation of the Arduino model element.

boolean boolean setDigitalServoMode(int digitalPin, int minPulse, int maxPulse);
Configures a digital pin to control a servo. Parameter minPulse, resp. maxPulse, is the pulse width, in microseconds, corresponding to the minimum (0 degree), resp. maximum (180 degrees), angle on the servo.


Re: Re: Re: Re: Re: Re: Re: Re: Using Arduino boards with EJS - Mar 03 3:34AM
Daniel Romero
3 Posts

Hello Again Paco,

Yes, I used the setDigitalMode(int digitalPin, int mode) in the initialization to configure the pin 9 as mode nº3 (PWM mode). The arduino help documentation shows this:

boolean setDigitalMode(int digitalPin, int mode); Sets the mode of a digital pin. The mode must be one of:
3 = PWM

boolean writeDigital(int digitalPin, int value); Sets the (PWM-wave) value of a digital pin, from 0 (always off) to 255 (always on). Returns true if successful.

I put in the initialization the sentence "arduino.setDigitalMode(9,3);" and in fixed relations I put"arduino.writeDigital(9, value);". Is it corret? I think that it is correct according to arduino help documentation.


Post edited March 3, 2015 at 3:34 AM EST.

The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics