Need help to read RX from imp001 with a April

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 = maxbotix.read();
    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 = maxbotix.read();
    }
}

…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