May 8, 2014 0 Comments in Learning, Mega 2560, Tips & Tricks by
Getting access to Mega 2560 serial port from Linux serial console

If you have a ready-to-run Arduino Mega 2560 application that is managed by an external program running on a PC and you wish using it on Cosino’s Mega 2560 extension you may wish get access to the standard Arduino serial port… of course you can do it by getting access to Cosino’s /dev/ttyS3 device but, in this case, the program should run on top of Cosino! While if your application is designed for a x86 GNU/Linux platform and/or Windows OS your (may) have a problem!

In reality it is not a problem at all… it’s quite easy to resolve it! You just need few steps. Let’s see how.

With a standard Arduino board you have the following configuration:

while with a Cosino’s Mega 2560 extension you have:

In the latter scenario you have to connect Cosino’s ttyS0 serial port to ttyS3 in order to reproduce the former one as shown below:

So Cosino Mega 2560 USB serial console connector can be used to get access to Arduino Mega 2560 serial port.

In order to do it we must first disable the Linux serial console and then using the socat program.

warning Note: disabling the serial console you cannot get access to the system via the serial port anymore! So you need a second access to the system as, for instance, the SSH daemon.

To disable the Linux serial console we can use the command:

then we must edit the file /etc/inittab and then commenting the following line by adding a # char:

At this point we must reload the init program by using:

If you executed this command from the serial console you should notice that you cannot use it anymore, so considering to continue by using a SSH login from another terminal.

Ok, now the device /dev/ttyS0 is free and can be safely connected to the Arduino Mega 2560 serial port on /dev/ttyS3. However, before doing it, is better to fix the baud rate for both serial ports:

Ok, now we are ready to connect Mega 2560 serial port with the Linux serial console by using socat as follow:

that’s all!

FAQ

1) I forgot to enable an SSH daemon and/or I can login on the system anymore! How I can restore factory defaults without reformatting the microSD?

You can use your host PC. Just remove the microSD and plut it into your host PC, then open the inittab file (on my Ubuntu the file is /media/giometti/root/etc/inittab) and re-enable the line:

than save all settings and replug the microSD into your Cosino board, the serial console should be available again.

Facebooktwitterlinkedin
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

40 − 33 =