I have my code working well, only one issue. When my Impee sends a number (629), planner and the log show it as three separate numbers (6, 2, 9) on separate lines. Not sure what i have wrong, i think it is with the UART somewhere. Here is my code: By the way I am loving Imp so far!
// impeeIn will override the InputPort class.
// Whenever data is received to the impee, we’ll jump into the set© function defined within
class impeeIn extends InputPort
{
name = “UART Out”;
type = “number”;
function set(c)
{
hardware.uart57.write(c);
}
}
local impeeInput = impeeIn(); // assign impeeIn class to the impeeInput
local impeeOutput = OutputPort(“UART In”, “number”); // set impeeOutput as a string
function initUart()
{
hardware.configure(UART_57); // Using UART on pins 5 and 7
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS); // 19200 baud deault, no parity, 1 stop bit, 8 data bits
}
// UART polling function.
function pollUart()
{
imp.wakeup(0.1, 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
server.show(format("%c", byte));
impeeOutput.set(byte); // send the valid character out the impee's outputPort
byte = hardware.uart57.read(); // read from the UART buffer again (not sure if it's a valid character yet)
}
}
// impee config
imp.configure(“PSIG”, [impeeInput], []);
initUart(); // Initialize the UART, called just once
pollUart(); // start the UART polling, this function continues to call itself
// End