Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Perl stdout timing/formatting

by jmlynesjr (Hermit)
on Sep 12, 2012 at 01:53 UTC ( #993117=note: print w/replies, xml ) Need Help??

in reply to Re: Perl stdout timing/formatting
in thread Perl stdout timing/formatting

Have you looked at Device::SerialPort::Arduino? See example below. Seems to work fine through a chipKIT Uno USB port.


# 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 ge +nerate 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::SerialPo +rt "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";

"Processing" code that is downloaded into the chipKIT UNO for use with the above sample code.

Graph A simple example of communication from the Arduino board to the compu +ter: the value of analog input 0 is sent out the serial port. We call thi +s "serial" communication because the connection appears to both the Arduino and +the computer as a serial port, even though it may actually use a USB cable. Bytes are sent one after another (serially) from the Ard +uino to the computer. You can use the Arduino serial monitor to view the sent data, or it c +an be read by Processing, PD, Max/MSP, or any other program capable of r +eading data from a serial port. The Processing code below graphs the data r +eceived so you can see the value of the analog input changing over time. The circuit: Any analog input sensor is attached to analog in pin 0. created 2006 by David A. Mellis modified 14 Apr 2009 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. void setup() { // initialize the serial communication: Serial.begin(9600); } void loop() { // send the value of analog input 0: Serial.println(analogRead(A0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(10); }

Replies are listed 'Best First'.
Re^3: Perl stdout timing/formatting
by dburke (Novice) on Sep 12, 2012 at 17:37 UTC
    @ jmlynesjr, Woah! I was not aware that this existed. Hm, not sure how I missed it either! Thank you for bringing that to my attention; I will definitely be trying it out soon.

      I hope it helps. I didn't want to learn "Processing", so I went with the perl module from cpan.

      The chipKIT mpide comes with lots of example code in "Processing" for the PC and "Arduino" for download into the chipKIT board. Checkout and


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993117]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2018-05-24 10:40 GMT
Find Nodes?
    Voting Booth?