O'Reilly logo

Arduino Sketches: Tools and Techniques for Programming Wizardry by James A. Langbridge

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER16

Firmata

This chapter discusses the following functions of the Firmata library:

  • begin()
  • sendAnalog()
  • sendDigitalPorts()
  • sendDigital()
  • sendString()
  • available()
  • processInput()
  • attach()
  • detach()

The hardware needed to use the example in this chapter includes:

  • Arduino Uno
  • Computer
  • USB cable
  • Breadboard
  • 4.7-kΩ resistor
  • LED

Introducing Firmata

Arduinos are used in a wide variety of projects, from the most simple to some extremely complex devices. In most cases, their exact use is known; you know beforehand that digital pin 3 will be used to light an LED, and that analog input 4 will read the value of a light sensor. For some projects, you may not know what is connected, but you will still need to set pins as input or output, depending on the situation. Imagine a laboratory setup, one where you can study how new components work before deciding to use them in your projects. You could write a quick sketch each time to see how a component works, but this isn't always the best solution and certainly not the easiest. One way to easily set up your laboratory is to use Firmata.

Firmata is a protocol that communicates between computers and microcontrollers to easily access the Arduino hardware from software on a host machine. It uses standard serial commands and as such can be used on several different Arduino models. Messages are sent serially to and from the host computer, indicating pin status or requesting a pin to change state.

Firmata Library

To use the Firmata library, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required