2013-07-23 32 views
0

我正在關注sparkfun tutorial for connecting an arduino to electric imp。我只有一個arduino和imp,所以我試圖通過使用server.show()來獲得我在arduino串行監視器中輸入的內容,以便在imp節點中顯示。使用ElectricImp server.show()和Arduino

我修改在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字符。 我該如何做松鼠? 另外,我認爲每10us輪詢是錯誤的方式去這裏。我只想在有新信息時進行輪詢,但我也不知道如何以松鼠的方式做到這一點。有人能指出我發生這種情況的一個例子嗎?

謝謝!

+0

您是否能夠將您的Electric Imp連接到無線路由器,因爲我無法使用我的無線路由器配置Electric Imp。 – shailendra

回答

1

我想你是錯誤的數據類型傳遞給服務器對象的show方法。電動imp docs指出它需要一個字符串,server.show(string)。我認爲local是從hardware.uart57.read()收到價值的正確類型。你也可以從docs知道。所以,你需要找到一種方法將你的字節轉換爲字符串。我敢打賭,你可以找到答案here。從我讀的Squirrel use的Unicode中,可能有一個函數需要Unicode字節並將它們加載到一個字符串對象中。