Arduino Interface Question

Hi Chris,

We’re going to need to interface with Arduino through Firmata for our experiment’s juice reward, and I have looked at the documentation and am still unsure how to put this into practice. How do I, from the MWorks side, interface with an Arduino board that has Firmata on it already?

Thank you,
Yvonne

Hi Yvonne,

How do I, from the MWorks side, interface with an Arduino board that has Firmata on it already?

First, you need to add a Firmata device to your experiment. Then, for every input or output you want to use, you need to attach an appropriate channel to the device. The available channel types are

When adding a channel, you need to specify the pin number you want to use. This will normally be the number printed next to the pin connector on the Arduino board (e.g. 7, A3). You also need to specify a variable for the “value” parameter. For input channels, the pin value will be stored in the variable. For output channels, the pin value will be read from the variable.

I’ve attached a short example experiment that configures digital pin 13 as an output and toggles its state every second. (On an Arduino Uno, this pin is tied to the built-in LED, which should light up when the pin value is high.) Because the device declaration omits both the serial_port and bluetooth_local_name parameters, MWorks looks for a single connected serial device and, if it finds one, assumes it’s the Firmata device. If you have multiple devices connected via serial-over-USB, or if you want to use a Firmata device connected via Bluetooth, you’ll need to include one of those parameters.

Hopefully this makes sense. If you have any questions, please let me know.

Chris

Attachment: blink.mwel.zip (310 Bytes)

Hi Chris,

This is great, thank you. I had another question about MWorks’ Arduino
integration. Does MWorks support servo commands? I couldn’t find anything
about it on the forums or documentation.

Thanks,
Yvonne

Hi Yvonne,

Does MWorks support servo commands?

Not at present, but I can add support if you need it.

Chris

Hi Chris,

That would be great. We want to use servo commands to integrate with some
custom equipment built by our staff scientist, so that would be very
helpful.

Yvonne

Hi Yvonne,

As of the current nightly build, MWorks now supports servo control via the new Firmata Servo Channel. Usage is pretty straightforward (example). If you have any questions, please let me know.

Chris