Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Homepage
Hokuyo Library¶
This is an example of using the Hokuyo library for the Hokuyo URG-04LX 2 dimensional LIDAR (range finder) with the mbed.
Above is the Hokuyo attached to the mbed WSE Project board (https://developer.mbed.org/users/jebradshaw/code/mbedWSEsbc/). I'm using a xbee form factor RS-232 level converter with a male DB9 (DTE). The on board 5V 1.5A OKI-78SR-5/1.5-W36-C switching regulator is more then sufficient for powering the LIDAR.
O'scope capture of the serial data. This is using a cluster size of 3, about a degree resolution at 19200 baud gives an update rate of about 3.3Hz.
Above is a screen capture of the data being transmitted to Tera-terminal.
include the mbed library with this snippet
// J Bradshaw 20160304 Hokuyo Lidar interface library example // cluster - groups together points, each point is .351 degrees #include "mbed.h" #include "hokuyo.h" DigitalOut led1(LED1); Hokuyo lidar(p13, p14); // tx, rx for Xbee header (RS232 board for Hokuyo) Serial pc(USBTX, USBRX); int main() { float scan_width = 180.0; //scan X number of degrees int cluster = 3; //~degree 1 accuracy with every 3 samples at .351/sample pc.baud(921600); if(!lidar.Init()) pc.printf("Hokuyo Init successful\r\n"); else{ pc.printf("Error Initializing Hokuyo!\r\n"); wait(10); } while(1) { if(!lidar.Read_Scan(scan_width, cluster)){ //scan 30deg wide, cluster of 5 points //pc.printf("total points read = %d\r\n\r\n", lidar.numPts); for(int i=0;i<lidar.numPts;i++){ pc.printf("%5.2f %05d\r\n", lidar.angle[i], lidar.dist_mm[i]); wait(.0001); } led1=!led1; } else pc.printf("Error Scanning Hokuyo!\r\n"); } }