【问题标题】:How do I compile the hello world program for Arduino ADK?如何为 Arduino ADK 编译 hello world 程序?
【发布时间】:2012-08-23 15:23:10
【问题描述】:

我要做的只是将“使用 Arduino 开始 Android ADK”一书中的 Arduino 编译为 Android 的“hello world”程序。

这里是代码

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define ARRAY_SIZE 12

AndroidAccessory acc("Manufacturer", "Model", "Description",
                     "Version", "URI", "Serial");

char hello[ARRAY_SIZE] = {'h','e','l','l','o',' ',
                          'w','o','r','l','d','!'};

void setup() {
  Serial.begin(115200);
  acc.powerOn();
}

void loop() {
  if (acc.isConnected()) {
    for(int x = 0; x < ARRAY_SIZE; x++) {
      Serial.print(hello[x]);
      delay(250);
    }
    Serial.println();
    delay(250);
  }
}

我的错误

C:\Users\efossum\arduino-1.0.1\libraries\UsbHost/AndroidAccessory.h: In function 'void setup()':
C:\Users\efossum\arduino-1.0.1\libraries\UsbHost/AndroidAccessory.h:68: error: 'void AndroidAccessory::powerOn()' is private
sketch_aug23a:14: error: within this context

我查看了 AndroidAccessory.h 并确定它是私有的,但我应该更改什么才能使其正常工作?我认为使函数 pulic 不是答案。

【问题讨论】:

  • 嗨,埃里克。您是否设法编译代码?我尝试在 IDE v22 和 v1.0.2 上使用第 1 步中的库在 arduino 实验室网站 labs.arduino.cc/ADK/AccessoryMode 上进行编译。我在 Windows 8 和 ubuntu 12.10 上尝试过与您一样的错误。这真是令人沮丧

标签: android arduino adk


【解决方案1】:

看来:

  acc.powerOn()

可以替换为:

  acc.begin();

【讨论】:

    【解决方案2】:

    我做到了!我刚刚公开了&lt;AndroidAccessory.h&gt; 标头中read() 函数的可见性,并使用begin() 而不是像Mickaël 所说的powerOn(),现在代码编译成功。

    【讨论】:

    • begin 和 poweron 有什么区别?
    • @Eric Fossum - 在最新库的 AndroidAccessory.cpp 中,我看到添加了 powerOn() 以将返回类型从 void 更改为 boolean(true)。除了破坏向后兼容性之外,我不明白为什么这是必要的。
    • 另一件事要提的是,在我编译代码之后,我使用了这个博客allaboutee.com/2011/12/31/… 中的android部分代码,虽然它在一年前对我有用,但它不再适用了Xperia Play 运行 android 2.3.4。我很难阅读引发的异常,因为手机连接到 arduino 而不是 PC-eclipse
    • 向函数添加返回值不会降低向后兼容性,但删除它会。
    • 我选择接受您的回答,因为它比您使用的更深入。我的项目碰壁了哈哈我开始做其他事情,但也许我应该回到它。你在做什么?
    【解决方案3】:

    尝试使用 Arduino 0.22 或 0.23 IDE

    【讨论】:

    • 上面写着1.0.1,我怎么知道是哪个0.xx号?
    • 虽然我不能证明这是答案,但我有相同的代码并且它可以工作。
    【解决方案4】:

    答案也可能是编译期间选择了错误的板。如果您选择了错误的电路板,Arduino 软件将无法确定您拥有的芯片或引脚。

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 2012-10-24
      • 2021-12-07
      • 1970-01-01
      • 2016-01-04
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多