Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

James

# 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. http://www.arduino.cc/en/Tutorial/Graph 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); }

In reply to Re^2: Perl stdout timing/formatting by jmlynesjr
in thread Perl stdout timing/formatting by dburke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 00:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found