使用ElectricImp server.show()和Arduino

时间:2013-07-23 20:53:20

标签: arduino uart imp

我正在关注sparkfun tutorial for connecting an arduino to electric imp。我只有一个arduino和imp,所以我试图得到我在arduino串行监视器中输入的任何内容,以使用server.show()在imp节点中显示。

我已经修改了sparkfun代码中的一个函数,如下所示:

function pollUart()
{
    imp.wakeup(0.00001, pollUart.bindenv(this));  // schedule the next poll in 10us

    local byte = hardware.uart57.read();  // read the UART buffer
    // This will return -1 if there is no data to be read.

    while (byte != -1) // otherwise, we keep reading until there is no data to be read.
    {
        // server.log(format("%c", byte));  // send the character out to the server log. Optional, great for debugging
        // impeeOutput.set(byte);  // send the valid character out the impee's outputPort

        server.show(byte)
        byte = hardware.uart57.read();  // read from the UART buffer again (not sure if it's a valid character yet)
        toggleTxLED();  // Toggle the TX LED
    }
}

server.show(byte)仅显示看似随机的数字。我知道为什么会这样,我只是不知道如何修复它因为我不熟悉UART和松鼠。

local byte = hardware.uart57.read();以字节形式从arduino中读取ascii字符(我认为),并且在我使用server.show(byte)之前,它们没有被'翻译'成ascii字符。 我如何在松鼠身上做到这一点? 此外,我认为每10年进行一次投票是错误的方式。我想只在有新信息的时候进行民意调查,但我也不知道如何在松鼠身上做到这一点。有人能指出我发生这种情况的例子吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为您将错误的数据类型传递给服务器对象的show方法。电子imp docs声明它需要一个字符串server.show(string)。我认为local是从hardware.uart57.read()接收值的正确类型。你也可以从docs看出来。因此,您需要找到一种将字节转换为字符串的方法。我打赌你能找到答案here。从我读的Squirrel使用的Unicode开始,所以可能有一个函数接受Unicode字节并将它们加载到字符串对象中。