其他分享
首页 > 其他分享> > Processing 串口GUI

Processing 串口GUI

作者:互联网

TFmini’s Processing Examples. TFmini, a Lidar of Benewake.

tfminiConsole

Link TFmini and PC using CP210x, CH341 etc USB to Serial (Maybe you need install their chip driver for OS):

在这里插入图片描述

myPort = new Serial(this, "COM12", 115200);
Change “COM12” to tfmini serial from device manager;

TFmini 9 bytes output:
[0x59, 0x59, distanceL, distanceH, strengthL, strengthH, Mode, 0x00, checksum]

We define a TFmini class:

class TFmini {
    int distance, strength;
    boolean complete;
    TFmini(int dist, int stre, boolean comp) {
        distance = dist;
        strength = stre;
        complete = comp;
    }
    void update(Serial port) {
        if(port.available() > 8) {
            //byte: [-128, 127]
            byte[] dataByte = port.readBytes();
            int[] data = new int[9];
            for(int i = 0; i < 9; i++) {
                //data[i]: [0, 255]
                data[i] = dataByte[i] >= 0 ? dataByte[i] : (dataByte[i] + 256);  
            }
            if(data[0] == 0x59 && data[1] == 0x59) {
                int checksum = 0;
                for(int i = 0; i < 8; i++) {
                    checksum += data[i];
                }
                if(data[8] == checksum % 256) {
                    distance = data[2] + data[3] * 256;
                    strength = data[4] + data[5] * 256;
                    complete = true;
                }
            }
        }
    }
}

update() can be used in serialEvent(). Output is (distance: cm, strength).

tfminiGUI

myPort = new Serial(this, "COM12", 115200);
Change “COM12” to tfmini serial from device manager;

在这里插入图片描述

Github

https://github.com/TFmini/TFmini-Processing

标签:strength,TFmini,int,256,GUI,Processing,COM12,串口,data
来源: https://blog.csdn.net/weifengdq/article/details/93410705