Need help to read RX from imp001 with a April

Hello, im very new to this language. Trying a code from:

But i cant get any readings. Get a strange 0 reading. but i assume im not reading the correct pin. I need to read pin 9, how can i be certain i use pin 9 with this code?
Adding a picture where i think its actually missing something like hardware.pin9.configure(somethingsomething?) ?

Any help at all would be greatly appreciated.

Regards Magnus.

No, that’s the correct way to configure the UART for receive only on pin 9.

Things to check:

  • you’re using a 3.3v UART to feed this pin, not raw RS232 (which is +/-12v levels and will fry the imp). Which model of maxbotix are you using?

  • check to see if pressure on the SD socket above the imp helps. There were some imp001’s made where, depending on the SD socket type, the pressure from the socket pins bent the imp PCB enough that pin 9 didn’t always touch.

  • I’d also add some logging of the raw uart read data just to check it looks valid rather than waiting to see what gets sent to the agent :slight_smile:

1 Like

Thanks Hugo.

Darn then thats not the problem.

Using 5v on to the april, then 3.3v from the april to sensor.

The SD card trick dident help.

I dont grasp how to log raw uart data :confused: yet.

So, that should be ok on power wiring (3.3v has spare capacity on the April devkit - the 7589 appears to take ~34mA @ 3.3v).

Can you send a picture of the wiring? Seems like stuff is right.

To log bytes, I’d do this:

// ---Callback Functions---
function maxbotixData() {
    // Read the UART for data sent by Maxbotix sensor.
    //server.log("UART read");
    local b =;
    while (b != -1) {
        // Log raw received data as binary and printable ASCII
        server.log(format("RX %02x %c", b, (b>=32 && b<127)?b:'#'));

        // As long as UART read value is not -1, we're getting data
        if (b == 'R') stringBuffer = "";
        if (b >= '0' && b <= '9') stringBuffer += b.tochar();
        if (b == '\r') {
            server.log("Got string: "+stringBuffer);
            latestMeasurement.distance = stringBuffer.tointeger();
            latestMeasurement.timeTaken = time();
        b =;

…I’ve also made the code a little clearer (well, to me) in that I use C-style character bytes (eg ‘R’) and avoided turning the byte into a string everywhere except where we concatenate it.

You could also try using a different UART - there are 3 on the imp - just in case it is the connection issue. Just change your maxboxtix <- global init.

1 Like

Jesus christ…

It have been working for all this time…
I just havent understood the sequence of numbers coming from the agent. just thought it was random startup numbers. But ofcorse they are readings. When i filled in the API to thingspeak i get readings like charm. All tho i do get some 0 readings, wonder why this happens.

Thanks for teaching me to log raw data. This is what made me actually understand anything. Coding is hard for a simple electrician :smile:

Now of to the secound hard thing. To log and visualize these readings.

Thanks alot Hugo, you got yourself a fan-boy :wink:

Interesting that you get zero readings; if you comment out the “RX” log line, and just have the “got string” ones, do you see blank strings?

Thought it would give you readings more often than that but didn’t look super closely at the datasheet :slight_smile: