SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By fsmithus
#191739
I am trying to read distances from a Maxbotix LV-EZ3 range finder https://www.sparkfun.com/products/8501 using a SparkFun Block for Intel Edison - GPIO https://www.sparkfun.com/products/13038. (My Edison has the June 2016 firmware.)

The LV-EZ3 can output analog, PWM, and RS232 serial. The block does not support analog, so serial seemed the easiest way to go. I powered the sensor from the block, and connected RX (GP130) on the block to TX on the sensor.

The data stream is supposed to be of the form "R###\n", where ### are ASCII digits representing inches. Instead, I am reading digital sequences like 43,6,38,86,0 ("+[ACK]&V[NULL]"). Exact values seem to change with range. I have tried using Node.js in the Intel XDK, the command line "cat /dev/ttyMFD1", and wrote my own code (see below), all with similar results.

BTW, I tried both 3.3V and VSYS (~4V) power to the sensor. Same results.

I contacted Maxbotix Technical Support and they sent me to this article http://www.maxbotix.com/articles/034.htm and suggested that I confirm that the device is configured for 9600-8-0-1. I'm not exactly sure how to do this, but tried the following commands:
Code: Select all
stty -F /dev/ttyMFD1 cs8 -cstopb evenp raw ispeed 9600
cat /dev/ttyMFD1
You can also see how I tried to configure the device in the code below. Neither approach worked, but I'm not sure if I am doing either one right. Maxbotix apparently does not have an Edison or block to troubleshoot, so I'm hoping someone on this forum has solved this problem, or one very similar.

Thanks in advance.

++++++++++
Code: Select all
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

// g++ readdist.cpp -o readdist

void settty(int dev) {
        struct termios tty;
        memset(&tty,0,sizeof tty);

        fcntl(dev,F_SETFL,0);                           // not sure what this does, but seems necessary

        cfsetispeed(&tty,B9600);                        // set speed 9600 baud
        tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
        tty.c_cflag &= ~(PARENB | PARODD);              // shut off parity
        tty.c_cflag &= ~CSTOPB;                         // 1 stop bit
        tty.c_iflag &= ~(IXON | IXOFF | IXANY);         // no xon/xoff ctrl
        tty.c_cc[VTIME] = 5;                            // 0.5 seconds read timeout
        if (tcsetattr(dev,TCSANOW,&tty) != 0) {
                printf("error on setup");
        }
}

int main() {
        char buf[16];
        int dev = open( "/dev/ttyMFD1", O_RDONLY | O_NOCTTY | O_NDELAY );
        if (dev == -1) {
                printf("error on open\n");
        }
        else {
                settty(dev);
                int n = read(dev,&buf,sizeof buf);
                if (n > 0) {
                        printf("%s\n",buf);
                }
                else {
                        printf("error on read\n");
                }
                close(dev);
        }
}