The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Device::Firmata - module for controlling Firmata devices

DESCRIPTION

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

Version 0.69

SYNOPSIS

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;
}

METHODS

open ( serialPort , [opts] )

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.

listen ( host, port, [opts] )

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.

EXAMPLES

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.

SEE ALSO

Device::Firmata::Platform

LICENSE

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.