Device::Firmata - module for controlling Firmata devices
This module allows a computer running Perl to connect to Firmata devices (Arduinos and compatible, including ESP8266), either via serial I/O (RS-232, USB, etc.) or TCP/IP (LAN, WiFi). Protocol details can be found at https://github.com/firmata/protocol.
Version 0.69
use strict; use warnings; use Device::Firmata::Constants qw/ :all /; use Device::Firmata; use Time::HiRes 'sleep'; $|++; my $led_pin = 13; my $device = Device::Firmata->open('/dev/ttyUSB0') or die "Could not connect to Firmata Server"; $device->pin_mode($led_pin=>PIN_OUTPUT); my $iteration = 0; while (1) { my $strobe_state = $iteration++%2; $device->digital_write($led_pin=>$strobe_state); sleep 0.5; }
Establish a serial connection with a Firmata device. The first parameter is the name of the serial device connected with the Firmata device, e.g. '/dev/ttyUSB0' or 'COM9'. The second parameter is an optional hash of parameters for the serial port. The parameter baudrate is supported and defaults to 57600. Returns a Device::Firmata::Platform object.
baudrate
57600
Start a TCP server bound to given local address and port for the Arduino to connect to. Returns a Device::Firmata::IO::NetIO object. An implementation example can be found in file examples/example-tcpserver.pl.
In the folder examples you will find more than 15 implementation examples for various Firmata I/O operations including digital I/O, PWM, stepper and encoder as well as bus I/O for I2C and 1-Wire.
Device::Firmata::Platform
Copyright (C) 2010 Aki Mimoto
Copyright (C) 2012 Norbert Truchsess
Copyright (C) 2016 Jens B.
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/ for more information.
To install Device::Firmata, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Firmata
CPAN shell
perl -MCPAN -e shell install Device::Firmata
For more information on module installation, please visit the detailed CPAN module installation guide.