0

I'm following the sparkfun tutorial for connecting an arduino to electric imp. I only have one arduino and imp, so I'm trying to get whatever I type in the arduino serial monitor to display in the imp node using server.show().

I've modified one of the functions in the sparkfun code to look like this:

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) is only displaying seemingly random numbers. I have an idea of why this is, I just don't know how to fix it because I'm not that familiar with UARTs and squirrel.

local byte = hardware.uart57.read(); reads in the ascii characters from the arduino in byte form (I think), and they're not being 'translated' into their ascii characters before I use server.show(byte). How do I do this in squirrel? Also, I think polling every 10us is the wrong way to go here. I'd like to only poll when there's new information, but I also don't know how to do that in squirrel. Can someone point me to an example where this happens?

Thanks!

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
Mike
  • 117
  • 1
  • 1
  • 8
  • Were you able to connect your Electric Imp to Wireless router as i wasn't able to configure Electric Imp with my wifi router. – shailendra Nov 22 '13 at 06:13

1 Answers1

1

I think you are passing the wrong data type to the show method of the server object. The electric imp docs state that it takes a string, server.show(string). I think that local is the correct type to receive the value from hardware.uart57.read(). You can tell from the docs as well. So, you need to find a way to cast your byte to a string. I bet you could find the answer here. From what I read Squirrel use's Unicode so there is a probably a function that takes Unicode bytes and loads them into a string object.

jophde
  • 444
  • 1
  • 5
  • 13