【问题标题】:Intel Galileo and Python - Interface英特尔 Galileo 和 Python - 接口
【发布时间】:2015-03-18 01:31:21
【问题描述】:

我正在使用英特尔 Galileo 平台开发一个园艺系统。我将本地传感器数据与来自 openweathermaps 的预测结合使用。为了显示结果,如有必要,我使用 Paraimpu 发布推文。到目前为止,一切都很好。我现在正在寻找一种方法来让我的系统对包含触发词的传入推文做出反应。我设法使用 Twython 编写了一个 python 脚本来检查这个触发词。如果有新推文(在最后一分钟内),python 脚本返回 1,如果不是 0。

[...]
if timedelta<triggertime: 
    erg = 1 #Neuer Tweet vorhanden
else: 
    erg = 0 #Kein neuer Tweet vorhanden
print erg

在这里我被困住了:当我调用 python 脚本本身时,它工作得很好。但是在 arduino 代码中使用系统函数时,我没有得到数字,只是一些奇怪的格式,比如:|cßBð¿ 这就是我在我的 arduino 代码中调用系统函数的方式:

char* checkTweets() {
  char result[1];
  system("python /media/realroot/Files/tweetcheck.py > /media/realroot/result.txt");
  FILE *tempFile;
  tempFile = fopen("result.txt", "r");
  fgets(result, 1, tempFile);
  fclose(tempFile);
  return (result);
}

我在 Arduino / Python 接口方面不是很有经验。感谢您的任何建议!

【问题讨论】:

  • 为什么不从 Python 做 IO?
  • 我的代码的主要部分是 arduino 草图。有没有办法将数据从 python 传递到 arduino 草图作为整数值?这对我来说是最方便的方式。

标签: python interface arduino intel-galileo


【解决方案1】:

我的 Galileo 与 Python 接口的代码非常相似,我注意到两个可能导致错误的差异:

当我进行系统调用时,我将其保存为文件,而不是文本文件:

system("python /media/realroot/Files/tweetcheck.py > /media/realroot/result");

也许将其保存为文本文件是导致奇怪输出的原因?

或者,错误在于读取文件。当我这样做时,我使用了 SD Arduino 库,它需要在您的程序顶部使用#include &lt;SD.h&gt;,并读取文件:

File myfile = SD.open("result");
// read from file until we hit the a newline
while (myfile.peek() != '\n') {
  result = myfile.parseInt();
}
result.close();
system("rm /media/realroot/result");

【讨论】:

  • 感谢您的回答!显然是写txt文件导致了错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多