UART .read difficulty

I currently have my electric imp connected (through a level shifter circuit and USB to Serial Adapter) to my computer. I’m want to use goSerial (essentially, a terminal) to communicate to my Imp.

Using the code below, I can successfully write “Hello, World!” to goSerial. But my readSerial function does nothing even after entering text into goSerial…

// UART Communication Code

// function that reads data from Serial port
function readserial()
local b =;
if(b >= 0)
server.log(“no data to retrieve”);

// configure a pin pair for UART TX/RX
hardware.uart12.configure(38400, 8, PARITY_NONE, 1, NO_CTSRTS);

// Connect to server
imp.configure(“Serial RX”, [], []);

//Write hello world
hardware.uart12.write(“Hello, World!\r



Everyone has been so knowledgeable and helpful here!!

I just realized what was wrong. My code should have been:

local b =;


local b =;

Thanks all!

Have you tried using a callback for the uart?

I love it!

I just used the callback. It’s great!! Thanks!

Along those lines, when I enter text like “hi”, my Imp prints the following:

Wed Jul 17 2013 13:49:09 GMT-0400 (EDT): 13 Wed Jul 17 2013 13:49:09 GMT-0400 (EDT): 48

Is this hex??

You’re logging it in decimal (you can do it in hex if you want - change your server.log(b) to server.log(format("%02x", b)) …)

13 = newline (you hit return at some point, or had a “\r” in the data from the arduino)
48 = ‘0’… unless you are logging hex already and then thats ‘H’.


If you want to see them as Squirrel strings:


Ah. I totally understand now. Thanks so much Hugo and Peter!