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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值