1

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.

paulc1111
  • 631
  • 3
  • 14
  • 32
  • Is that arduino UNO? If yes, then what kind? what's the clock and memory, what microcontroller does it use (Atmega328??)? Please add more details! – Ubdus Samad Jan 02 '18 at 06:02
  • @UbdusSamad I'm using Arduino Yun. and plugged sd card on the YUN. I'm trying to check my python script from SD card runs appropriately or not. :) Thanks for replying! :) – paulc1111 Jan 02 '18 at 06:04
  • 1
    Also , in sample.py , replace the last line with `while 1 : ser.write('g')` – Ubdus Samad Jan 02 '18 at 06:04
  • Ah, actually I solved my question.. haha.. I was soooooo stupid.. I don't have to use Serial package in the python code. – paulc1111 Jan 02 '18 at 06:06
  • I just checked with creating text file. like `file = open(full-path, "w")` `file.write("Hello World")` `file.close()` and it worked creating text file in the path that I wrote in full path! :) – paulc1111 Jan 02 '18 at 06:07
  • 1
    So you directly use print? And please answer your own question formally by writing an answer below! – Ubdus Samad Jan 02 '18 at 06:08

1 Answers1

1

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.

Ubdus Samad
  • 1,218
  • 1
  • 15
  • 27
paulc1111
  • 631
  • 3
  • 14
  • 32