Calling python script from Arduino Yun using Process.h

607 Views Asked by At

I'm a newbie in Arduino and trying to check my python script in Arduino is running or not.

I placed the python script(sample.py) in /mnt/sda1/arduino/www/ which is in SD card.

From the scratch file, I wrote it like below,

Process p;

void setup() {
  // put your setup code here, to run once:
  Bridge.begin();
  Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:
  p.runShellCommandAsynchronously("/usr/bin/python -U /mnt/sda1/arduino/www/sample.py");
  while(p.running());
  if(p.available()>0){
    userInput = p.read();
    Serial.println(userInput);
  }
}

And here is my python script code(sample.py) on below,

import serial

ser = serial.Serial('COM5', baudrate = 115200, timeout=1)
ser.write('g')

What I'm trying to do here is checking my python script is running. However, it shows nothing on Serial monitor.

What am I doing wrong here..?

Can Anybody help me out here??

Or can anybody give me an example code(scratch code) to check python script is running or not?

Thanks in advance.

1

There are 1 best solutions below

0
paulc1111 On

OK, I made a mistake, I thought I had to use serial package for checking my python script runs or not. Rather, I just used below code for checking.

file = open("/mnt/sda1/arduino/www/testfile.txt", "w")

file.write("Hello World")

file.close()

Be careful that we have to use full path!!

If you don't, then it will not create a text file.