0

I am trying to use Process.h library to run a shell command. Here is my code. I am using Arduino Uno.

#include <Process.h>
#include <Bridge.h>

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

  // Initialize Serial
  Serial.begin(115200);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  // run various example processes
  runPythonFunction();
}

void loop() {
  // Do nothing here.
}


void runPythonFunction() {

  Process p;        // Create a process and call it "p"
  //p.begin("/usr/bin/python /home/kairos/Arduino/codes/sketch_jan26a/tweet.py");
  p.runShellCommandAsynchronously("/usr/bin/python -U /path/to/tweet.py");      // Run the process and wait for its termination
  //p.run();
  // Print command output on the SerialUSB.
  // A process output can be read with the stream methods
  while(p.available() > 0) {
     char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
  delay(300000);
}

If I do not comment the Bridge.begin() line, then in monitor display reverse question marks are displayed. And after commenting that, I am getting some garbage on the serial monitor. Also, my python script makes a new file in the same directory, which runs fine if I run it using a terminal. But if I run it using Arduino code, I am not able to see that new file being generated.

Even using p.begin() and p.run()it does not run. Nor using p.runShellCommandAsynchronously().

So how can I run that python script?

6
  • Do you have a Yun shield on your Uno?
    – Majenko
    Jan 27 '18 at 17:35
  • 1
    I am actually using SparkFun Redboard, same as this robotshop.com/en/…
    – Riken Shah
    Jan 27 '18 at 17:36
  • Do you have a Yun shield plugged into your SparkFun Redboard?
    – Majenko
    Jan 27 '18 at 17:38
  • No, I have directly connected the board to the computer.
    – Riken Shah
    Jan 27 '18 at 17:38
  • Was your intention to make your Arduino trigger the execution of a Python script which is on your computer?
    – per1234
    Jan 27 '18 at 23:34
3

The Uno cannot run python.

The Bridge library is intended for communication either between the two MCUs of the Yun, or between an Arduino board and the MCU on a Yun shield.

It is literally a Bridge between the two systems - Arduino and the Linux system in the Yun.

4
  • Is there any way I can run a python script?
    – Riken Shah
    Jan 27 '18 at 17:41
  • 2
    I knew you were going to ask that. Buy a Yun.
    – Majenko
    Jan 27 '18 at 17:42
  • Don't buy a Yún, it is an endless source of troubles. Buy a Raspberry Pi, and you have a full linux operating system for less money.
    – Jot
    Jan 27 '18 at 21:32
  • Tried it with Rpi, completed it in 20min, the same task that I was trying from two days #hackathon
    – Riken Shah
    Jan 28 '18 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.