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? Commented Jan 27, 2018 at 17:35
  • 1
    I am actually using SparkFun Redboard, same as this robotshop.com/en/… Commented Jan 27, 2018 at 17:36
  • Do you have a Yun shield plugged into your SparkFun Redboard? Commented Jan 27, 2018 at 17:38
  • No, I have directly connected the board to the computer. Commented Jan 27, 2018 at 17:38
  • Was your intention to make your Arduino trigger the execution of a Python script which is on your computer? Commented Jan 27, 2018 at 23:34

1 Answer 1

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? Commented Jan 27, 2018 at 17:41
  • 2
    I knew you were going to ask that. Buy a Yun. Commented Jan 27, 2018 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. Commented Jan 27, 2018 at 21:32
  • Tried it with Rpi, completed it in 20min, the same task that I was trying from two days #hackathon Commented Jan 28, 2018 at 3:26

Your Answer

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.