Search

Recent Posts

Tags


« | Main | »

Arduino – serial time with ‘screen’ and other tools

By Dale Reagan | June 13, 2011

Ever need/want to ‘listen’ to serial output from Arduino and not use the built-in serial monitor?   Or perhaps, you want to ‘talk’ directly via a serial stream to both send ‘commands’ and read ‘results’.  How?

I am currently working with an Uno board (boards vary along with OS ‘flavours’ so results will vary as you try ‘standard’ tools for serial communication.)  On Linux/Unix systems the “everything is a file” approach usually provides a simple means to connect to any attached device, including devices providing serial communications (i.e. 9 pin serial port, USB devices, etc.)

After trying a number of standard Linux/Unix ‘serial tools’ (think back – modem/phone line networking…) I found this to work instantly with my Arduino Uno:

screen /dev/ttyACMx BAUD_RATE

Note that you will need to replace /dev/ttyACMx with whatever tty your Arduino board is using and match the BAUD_RATE with the rate used in your Arduino code.  Of course, ‘screen’ must also be installed on  your system.

Why bother? Why not just add an ethernet/wireless component?  Any Options?

Arduino SimpleMessageSystem Library

Well, it’s a simple solution:

 

if (messageBuild() > 0) { // Checks to see if the message is complete and erases any previous messages
     switch (messageGetChar()) { // Gets the first word as a character
          case 'P': // you sent a 'P' - and Arduino Says
               Serial.println("\n=============================");
               Serial.println("\t\tHey, Arduino got a 'P'...");
               Serial.println("=============================\n");
               break; // Break from the switch
         case 'x':
               Serial.println("You sent 'x' - stopping program...");
               exit(0);
               break;
     }
}

 

In my sample code I am reading a 1-Wire micro-lan; the code above did not work with the built-in Arduino Serial Monitor; it did work with a ‘screen session’…

Sample output from my 1-Wire, on-board (well, it’s on a bread board…), Micro-lan, sensor net follows:

Run time (sec/min/hr/9cycs): 974/16/0/0 |  Elapsed: 954 | Cnt: 55
>> 18:28:12 Friday 10 Jun 2011 | Started: 18:12:00 Friday 10 Jun 2011 <<
|  # # # # # # # # # # # # # # # |
Requesting temperatures… Sleep ticks: 15500
Temp. device: 1 | 2890576103000090 | T-C: 26.56 T-F: 79.81
Temp. device: 2 | 28E8E26F03000021 | T-C: 26.75 T-F: 80.15
Temp. device: 3 | 28F649610300003F | T-C: 26.56 T-F: 79.81
Temp. device: 4 | 281BF36F030000BB | T-C: 26.87 T-F: 80.37

> b < is not a valid menu option…
Valid options:  s, p, P, x.

> X < is not a valid menu option…
Valid options:  s, p, P, x.

X  # # # # #X
Pausing for extra delay
X # # # # # X

Run time (sec/min/hr/9cycs): 1008/16/0/0 |  Elapsed: 972 | Cnt: 56
>> 18:28:45 Friday 10 Jun 2011 | Started: 18:12:00 Friday 10 Jun 2011 <<
|  # # # # # # # # # # # # # # # |
Requesting temperatures… Sleep ticks: 15500
Temp. device: 1 | 2890576103000090 | T-C: 26.56 T-F: 79.81
Temp. device: 2 | 28E8E26F03000021 | T-C: 26.81 T-F: 80.26
Temp. device: 3 | 28F649610300003F | T-C: 26.62 T-F: 79.93
Temp. device: 4 | 281BF36F030000BB | T-C: 26.94 T-F: 80.49

=====================
Hey, Arduino got a ‘P’…
=====================

Run time (sec/min/hr/9cycs): 1026/17/0/0 |  Elapsed: 1005 | Cnt: 57
>> 18:29:03 Friday 10 Jun 2011 | Started: 18:12:00 Friday 10 Jun 2011 <<
|  # # # # # # # # # # # # # # # |
Requesting temperatures… Sleep ticks: 15500
Temp. device: 1 | 2890576103000090 | T-C: 26.62 T-F: 79.93
Temp. device: 2 | 28E8E26F03000021 | T-C: 26.81 T-F: 80.26
Temp. device: 3 | 28F649610300003F | T-C: 26.62 T-F: 79.93
Temp. device: 4 | 281BF36F030000BB | T-C: 26.94 T-F: 80.49

You sent ‘x’ – stopping program…
=====================
Use CTRL+a, then ‘k’, answer ‘y’ to exit the ‘screen’ program…
=====================

Of course, your mileage should vary – at least a little. 🙂

Next up – Arduino and SLIP (Serial Line IP)

Related Arduino Playground Links

http://www.arduino.cc/playground/Interfacing/LinuxTTY

Notes from:  http://at.or.at/hans/pd/objects.html

This is a [arduino] object for Pd and a matching firmware. The firmware could be used from any program, really. The idea is that everything is controlled from the host program rather than having to update the firmware. For complete documentation on the protocol, see firmata.org, for the Arduino library, see: arduino.cc/en/Reference/Firmata

Download Pduino-0.5beta8.zip (Pd object and examples + Arduino library and examples)

Download Firmata-2.2.zip (only the Arduino library and example sketches)

“The Firmata library implements the Firmata protocol for communicating with software on the host computer. This allows you to write custom firmware without having to create your own protocol and objects for the programming environment that you are using.”

Another solution – http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/

Topics: 1-Wire, Computer Technology, Problem Solving, Unix-Linux-Os | Comments Off on Arduino – serial time with ‘screen’ and other tools

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________