2

The linux processor runs a Python script from which I would like to send an array of integers to the Yun microprocessor. How can I do that?

And then, how can I retrieve and then use this array in my Arduino Sketch?

asked Nov 23, 2015 at 14:29

3 Answers 3

1

Given that my Python script printed the following

[10, 20, 30, 40]

This is the sketch I used to retrieve the array

#include <Bridge.h>
#include <Process.h>
void setup()
{
 Bridge.begin();
 Serial.begin(19200);
}
void loop()
{
 Process proc;
 int i=0;
 size_t dim = 1;
 int* array = (int*)malloc(dim);
 Serial.print("Running process...");
 Serial.println("done!");
 proc.runShellCommand("python /script.py");
 while (proc.available()){
 if((char)proc.read() != ']'){
 array[i] = proc.parseInt();
 dim++;
 array = (int*)realloc(array,dim);
 Serial.println(array[i]);
 i++;
 }
 else
 break;
 }
 Serial.println();
 delay(1000);
}
answered Nov 25, 2015 at 9:21
1

The Yun makes communication between the microprocessor and the Linux side easy. On the Arduino side, use the Bridge library in your "processing script" to read (or write) Bridge values set by the python program running on the Linux side. From the linux side, the bridge looks like a web address and you set values by addressing a URL with a get or put url http request. You can also manipulate these values from another computer on the network as well if you like.

I have some Arduino Yun dataloggers that use the Linux side to communicate via wifi with an ftp server that serves several Yun dataloggers. The arduino script reads the sensors, creates the records, etc. You can also have the microprocessor side write files that are used by the linux side of the Yun.

I find the Yun's combination of Linux and the regular arduino in one package makes the overall system easier to program and to interface with the rest of the web.

answered Dec 20, 2015 at 20:38
0

Serial1 on the Arduino side is connected to a serial console on the Linux side.

So, you could use calls on the Arduino to run your Python script on the Linux side and then listen to the output of the script to come back though the serial port and part it.

Here is an example of a project where I used a Yun like this. The Arduino side interfaces to some temperature sensors, and then types commands into the Linux side over the serial connection to run CURL and report data to internet URLs.

http://wp.josh.com/2014/06/05/tempurature-logging-to-a-google-spreadsheet-with-an-arduino-yun/#more-1797

I am going to warn you that this is very ugly. Then Yun itself is quite ugly too. There were so many problems that I ended up giving up on this platform completely.

answered Nov 24, 2015 at 22:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.