Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Perl stdout timing/formatting

by jmlynesjr (Deacon)
on Sep 12, 2012 at 01:53 UTC ( [id://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.

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

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 www.chipkit.org and www.digilentinc.com.

      James

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://993117]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found