# Perl serial interface to Arduino Example # Reads characters being sent from the chipKIT UNO and prints them to the screen. # The output looks like the mpide serial monitor. # Use mpide to compile and run the communications->graph example to generate the character stream. # From the CPAN Perl module Device::SerialPort::Arduino # Written by Simone Marzulli # Modified for USB interface and annotated by James Lynes, Jr. June 5,2012 # Tested under Ubuntu 10.10 and Perl v5.10.1 on the chipKIT UNO board (communicate as yet untested - requires # a modified chipKIT sketch that expects an incoming message. "graph" only transmits characters. # Documentation under: Perldoc Device::SerialPort # Perldoc Device::SerialPort::Arduino # Uncomment the section below which you would like to test: receive(), receive(with delay), communicate use strict; use warnings; # Initialize the serial port - creates the serial port object $Arduino use Device::SerialPort::Arduino; my $Arduino = Device::SerialPort::Arduino->new( port => '/dev/ttyUSB0', baudrate => 9600, databits => 8, parity => 'none', ); # Reading from Arduino via Serial - uses Device::SerialPort "lookfor" method while (1) { print $Arduino->receive(), "\n"; } # Reading from Arduino via Serial with a delay - uses Device::SerialPort "lookclear" method and a sleep call # Argument is number of seconds to sleep between receives # while (1) { # print $Arduino->receive(5), "\n"; # } # Send something via Serial - uses Device::SerialPort "write" method # $Arduino->communicate('oh hi!!11') # or die 'Warning, empty string: ', "$!\n";