Community
cancel
Showing results for 
Search instead for 
Did you mean: 
DDari3
Novice
1,690 Views

How to send data from Linux to Edison using serial communication?

Hi all,

I have an Intel Edison with Kit for Arduino and I'm new using this development board. I would like to start a serial communication between a computer (running Linux) and Edison. My intention is to run a C++ script on computer which sends data (numbers) to Edison. Finally I would like to read the incoming data on Edison (running a script written with Arduino IDE). I tried to run the following code, but I'm not capable to finally read data.

This is the part of the C++ code which sends data:

int main( int argc, char* argv[] )

{

std::ofstream arduino;

arduino.open("/dev/ttyUSB0"); // open the communication

arduino << "data" << std::endl; // send data</span>

arduino.close(); // close the communication

}

Where /dev/ttyUSB0 is the port displayed by the Arduino IDE (Tools > Port) when the edge port (see https://software.intel.com/en-us/appendix-connectors-on-the-intel-edison-board image) of Edison is connected to computer.

The following is the Arduino-like code which runs on Edison to read the incoming data:

void setup()

{

Serial.begin(9600);

Serial2.begin(9600);

}

void loop()

{

if(Serial2.available() > 0) // check if there are incoming data

{

input = Serial2.read(); // read incoming data

Serial.print("data: "); // print incoming data on Edison serial monitor

Serial.println(input);

}

}

I tried also to use Serial1 instead of Serial2, but it doesn't works.

Any suggestion to fix the problem would be appreciated.

9 Replies
idata
Community Manager
54 Views

Hi Space1969,

 

 

I would love to help you with this.

 

 

So, you want to use the Edge Port to send data right? Are you already using it with the serial terminal to access to the Edison?

 

 

Take a look at this thread: https://communities.intel.com/thread/54236 https://communities.intel.com/thread/54236, it has information about the serial ports of the Edison that can be helpful for you.

 

 

According to the link the Serial2 is the Linux Serial Terminal, so in order to use it you need to disable the Linux Serial Terminal. Please look at the following steps:

 

 

1. Connect the Edison through SSH and COM in 2 Putty sessions

 

 

2. Disable the serial terminal in the COM session typing these commands in the SSH session:

 

 

systemctl stop serial-getty@ttyMFD2.service  dmesg -n 1

 

 

3. I ran the following sketch but, you can use yours:

 

 

void setup() {   // put your setup code here, to run once:  Serial2.begin(115200);  Serial2.println("hola World!!!");  }

 

 

Let me know if it works.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
DDari3
Novice
54 Views

Hi Leonardo!

Thank you very much for your answer.

Waiting for a reply I tried to make some changes to my setup and I found that the Serial2 baud was incorrect, so I updated it to 115200.

With this correction everything appeared to work, I was able to read the incoming data. However, when I physically disconnected and reconnected Edison to computer, everything started to not work again.

Probably the problem is the conflict between Edison and Linux Serial Terminal. My concern is about disabling the Linux Serial Terminal, because I'm using it to run the C++ script on Linux.

Anyway I tried to apply your suggestions, but I'm not sure to understand what does it means connect the Edison through COM.

I know what is the procedure to connect the Edison through SSH using Linux Serial Terminal:

1. Open the Linux Serial Terminal

2. Type sudo screen /dev/ttyUSB0 115200

3. Press Enter two times

4. Type root

5. Type the Edison password

On the other hand I don't know how to connect the Edison through COM.

Despite that, I still tried to execute the commands you wrote in the SSH session. When I typed the first command,

systemctl stop serial-getty@ttyMFD2.service

the serial monitor stopped to work. I was unable to type any other command.

What could be the problem?

Thank you,

-space1969

idata
Community Manager
54 Views

Hi Space1969,

 

 

The COM port is the serial port, we normally used this word because it is defined in that way on Windows (My mistake because you are using Linux). It is the connection that you are doing with the steps that you gave us.

 

 

Now the SSH connection is a network protocol, so you need to connect your Edison and your computer to the same network.

 

 

To establish this connection you should open another Linux terminal and use the following command:

 

 

ssh root@IPADDRESS

 

 

Once you are connected through SSH you can follow the steps that I gave you before, when you run the command systemctl stop serial-getty@ttyMFD2.service the serial monitor will stop, but you will have the SSH connection to run the script.

 

 

I hope you find this useful.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
DDari3
Novice
54 Views

Hi Leonardo,

Thank you for clarification. Let me know if I'm correctly understanding the steps to do.

1. Open two Linux Serial Terminal.

2. In the first Linux Serial Terminal, open a serial (COM) communication between Edison and computer with the steps I wrote before.

3. Connect Edison and computer to the same network. Is it the same thing if I connect them to internet using different wifi hotspots?

4. In the second Linux Serial Terminal, open an SSH connection between Edison and computer. I should use the Edison IP address when I run the command ssh root@IPADDRESS, right?

5. In the SSH connection, run the commands you gave me. This should disable the COM connection on the first Linux Serial Terminal.

6. Use the SSH connection on the second Linux Serial Terminal to run the script on computer.

The problem is at the last point. I have an SSH connection where I can just type commands as root@edison2:~# (edison2 is the name of my Edison board). As consequence I can't access to the files on my computer. I tried to navigate to the directory where is the script that I should run, but the message No such file or directory appears.

Where is the mistake?

Thank you,

-space1969

idata
Community Manager
54 Views

Hi Space1969,

 

 

You can connect them using different hotspots, but it requires more networking knowledge to make it possible, because you have to add the iptables of each hotspot to the other to be recognized. You have to do something like this: http://askubuntu.com/questions/749230/is-it-possible-to-ssh-between-two-different-network, that's why I recommended you to connect them to the same network.

 

 

About the SSH connection, you should use the Edison IP Address, and I don't understand your issue. The SSH connection is to access to the Edison's files, it applies when you need to send data using the Serial2 and access the Edison serial terminal.

 

 

At step 6 if the script is in your computer you should run it from your computer, the SHH connection is to access to your Edison.

 

 

Let us know if you still have issues.

 

 

Regards,

 

-Leonardo
idata
Community Manager
54 Views

Hi Space1969,

 

 

Do you have any updates about this?

 

 

Let us know if you still have issues.

 

 

Regards,

 

-Leonardo
MClif
New Contributor I
54 Views

Hi All,

Question: Looking at the C++ code in the original post, how does that code, running on another PC have access to Edison's /dev/ttyUSB0?

Regards,

Bill

idata
Community Manager
54 Views

Hi Bill,

 

 

I think you are confused, the first part of the code is in the computer, so /dev/ttyUSB0 is the PC port. And it is connected to the microUSB serial port of the Edison (ttyMFD2).

 

 

Have a nice weekend.

 

 

Regards,

 

Leonardo R.
MClif
New Contributor I
54 Views

Hi Leonard,

Aha ... right you are ... I was confused.

Regards,

Bill

Reply