User Tools

Site Tools


arduino-call-python

Arduino code calling a Python script

#include <FileIO.h>
#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  Serial.begin(9600);
//
//  // Wait until a Serial Monitor is connected.
  while (!Serial);
  Serial.println("pythonic");
  FileSystem.begin();
  runPaj();

}

void loop() {

    // execute the script every (1)seconds
 // runPaj();
 // delay(1000);

//no need to do that if the script is running in a loop and it only closes the port when it is stopped
}

void runPaj() {
Process p;
p.begin("python");
p.addParameter("/mnt/sd/arduino/www/python-test.py");
//p.addParameter("foo"); // A command line parameter for the script
p.addParameter("&2>1"); // pipe error output to stdout
p.run(); // blocking call to run python; ATMega execution halts until complete

//while(p.available()>0) {
//    Console.print(p.read());
//}
}
arduino-call-python.txt · Last modified: 2014/05/26 16:11 by zoza