{"id":196,"date":"2018-04-05T09:00:31","date_gmt":"2018-04-05T09:00:31","guid":{"rendered":"http:\/\/www.hardwarehacker.co.uk\/blog\/?p=196"},"modified":"2021-04-07T08:33:13","modified_gmt":"2021-04-07T08:33:13","slug":"distance-sensing","status":"publish","type":"post","link":"https:\/\/www.hardwarehacker.co.uk\/blog\/distance-sensing\/","title":{"rendered":"Distance sensing"},"content":{"rendered":"<p>Last year we ran with ultrasonic ping sensors, but a lot of the teams were using the VL53L0X time of flight sensors with good results.\u00a0 So this year we thought we&#8217;d have a go with some of those too.\u00a0 We got the ones on a <a href=\"http:\/\/www.hobbytronics.co.uk\/vl53l0x\">pololu carrier board for about 10 quid each.<\/a><\/p>\n<p>And they&#8217;re *lovely*.\u00a0 I think that under the covers they&#8217;re doing something very complicated\/interesting and hiding all that from us, but the readings we get from them are very accurate and very consistent.\u00a0 No need for any averaging or filtering code on the Pi side.<\/p>\n<p>Its not all roses though.\u00a0 The minor downside of that complexity is that you need to initialise them with a C-library.\u00a0 If you&#8217;re using the <a href=\"https:\/\/github.com\/johnbryanmoore\/VL53L0X_rasp_python\">python library<\/a>, that&#8217;s all taken care of for you, but we are writing our code in Golang, so we had to mess about linking in that C-library.<\/p>\n<p>Another quirk to be aware of &#8211; they are an I2C device, so they all need an I2C address.\u00a0 They come with a fixed one from the factory.\u00a0If you only have one this is fine, but if you have more than one, they will all have the same address&#8230;\u00a0 Other I2C sensors usually allow you to tune the address with jumpers, but this doesn&#8217;t seem to be an option with these boards &#8211; at startup you need to hold all but one in reset (using GPIO pins) and then send it I2C commands to change the address, and repeat with a different one in reset.\u00a0 We decided we didn&#8217;t have enough GPIO pins for this.<\/p>\n<p>Alternatively, you can use an I2C multiplexer like the <a href=\"https:\/\/thepihut.com\/products\/adafruit-tca9548a-i2c-multiplexer\">TCA9548A<\/a> (adafruit do a nice carrier board for it too).\u00a0 With this, you attach the ToF sensors to the different buses coming out of the multiplexer, then you send commands to the multiplexer to change which bus you want to talk to.<\/p>\n<p>Here&#8217;s Tigerbot wearing a few sensors on its front.<\/p>\n<p><a href=\"http:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/03\/IMG_20180318_180508.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-177\" src=\"http:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/03\/IMG_20180318_180508-300x225.jpg\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/03\/IMG_20180318_180508-300x225.jpg 300w, https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/03\/IMG_20180318_180508-768x576.jpg 768w, https:\/\/www.hardwarehacker.co.uk\/blog\/wp-content\/uploads\/2018\/03\/IMG_20180318_180508-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year we ran with ultrasonic ping sensors, but a lot of the teams were using the VL53L0X time of flight sensors with good results.\u00a0 So this year we thought we&#8217;d have a go with some of those too.\u00a0 We got the ones on a pololu carrier board for about 10 quid each. And they&#8217;re &hellip; <a href=\"https:\/\/www.hardwarehacker.co.uk\/blog\/distance-sensing\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Distance sensing<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,5,11],"tags":[2],"_links":{"self":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/196"}],"collection":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":4,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/posts\/196\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hardwarehacker.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}