我正在关注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年进行一次投票是错误的方式。我想只在有新信息的时候进行民意调查,但我也不知道如何在松鼠身上做到这一点。有人能指出我发生这种情况的例子吗?
谢谢!