Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl stdout timing/formatting

by shijiang1130 (Initiate)
on Sep 12, 2012 at 01:03 UTC ( #993101=note: print w/ replies, xml ) Need Help??


in reply to Perl stdout timing/formatting

have you tried " my $char = $port->lookfor(); " to "my $char = $port->lookfor($count)" . the $count is numbers of charactors


Comment on Re: Perl stdout timing/formatting
Re^2: Perl stdout timing/formatting
by jmlynesjr (Pilgrim) on Sep 12, 2012 at 01:53 UTC

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

Re^2: Perl stdout timing/formatting
by dburke (Novice) on Sep 12, 2012 at 17:35 UTC

    This seems very clunky and leaves me reluctant to implement it. Already I have message coming from the arduino that are of differing lengths and it seems very cumbersome to change the code every time I add a new message to the system or change my messages.

    Am I understanding that right? Is there something I'm missing? Thank you for your suggestion; I do believe this part of the code can be improved upon.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-16 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (158 votes), past polls