Ultrasonic sensor

Hi Team Robotical

Is it possible to connect a simple US sensor such as the HC-SR04 directly to the Rick board? Documentation on the pinouts seems a little sparse right now :)


Leave a comment and join the discussion here

Please Log In or Sign Up to write a comment response

14 Responses


I found I had an HC-SR04 in my collection of bits and had a play with it recently: https://learn.adafruit.com/distance-measurement-ultrasound-hcsr04

17:54:11, 27th September 2018   |   Permalink   |   View Source
sandy STAFF

Hi folks,

We're just getting some distance sensor PCBs made up now with the VCNL4200 sensors - hopefully ready soon. I have a prototype one down with me for BETT now - we have a couple of spare prototypes in the office - if you want one let me know by e-mail.

If you've already got one, the v1.1 boards that went out recently (Dec onwards) have firmware loaded on them to support it. Pinout wise, you should connect the i2c SCL and SDA pins next to the GPIO to the VCNL's SCL and SDA pins, connect the grounds, and you can use the 5v line as a power source if your breakout board is 5v tolerant - check that as the chip itself is 3v3 logic; our breakouts have a little LDO on them to step down.

After that - if you've got a pi connected you'll see a new topic appear in ROS for the distance sensor, otherwise for Scratch, I've got a local dev version which has the distance sensor working. I'll push that out very shortly

We're also investigating the ST VL53L0X, which is the sensor the tinylidar uses. Clock stretching shouldn't be an issue on Marty's control board. In general terms, we're starting to have a think about how to better generalise to be able to cope with (almost) any i2c sensor. If I get a chance to do some proper firmware work I should be able to make something nicer...


00:37:28, 26th January 2018   |   Permalink   |   View Source

FYI, full Lego compatibility is a bit more complicated than just i2c as they appear to have deviated a bit with EV3, see fourth column on this very useful page: Mindstorms Sensors / Input Devices

11:07:21, 13th January 2018  *   |   Permalink   |   View Source
22:50:35, 11th January 2018   |   Permalink   |   View Source

Hi Sandy -

Just exactly what I am looking for! To be able to use my VCNL4200 sensors with a Marty and with the Robotical Scratch interface. Thank you so much for your development work on this.

And on the hardware side, can you offer some advice for pinout connections from the VCNL4200 to either Rick or the Pi3 (or both...).

Many thanks,

Richard J.

18:38:47, 11th January 2018   |   Permalink   |   View Source
Klauscon OP

Great stuff Sandy. Really looking forward to this.. The IR sensor is already a great start. I mentioned the HC only because it is dirt cheap and already used in so many other projects that it seemed like a good choice. But as long as we can extend the functionality of Marty easily and with little cost I think many people, myself included, will be very happy and grateful.

15:18:07, 15th December 2017   |   Permalink   |   View Source
sandy STAFF

Hi guys,

Thanks so much for this feedback

I agree completely that Marty needs more sensors to work natively, without requiring a pi or arduino

The firmware on the new boards that are about to go out is compatible with an infrared distance sensor (the VCNL4200 - i2c distance sensor with roughly 3cm-1m range), and I've just finished porting that through to the scratch interface - update coming shortly. We'll be putting some of the actual sensors out early next year, but I'll try and arrange to send you both some of our prototypes so you can test

(as an aside, I'm also going to be adding a bit more control over connections to the Scratch interface, and making it work a bit harder to maintain a persistent connection)

For the ultrasonic sensors, they're a bit bulky to easily mount, which is one reason we decided to go for the little IR sensors. However, I would like to be compatible with both, so I'll bump that feature up the priority list. In general, I'd like it to be possible to connect nearly any i2c sensor to Rick and have that appear in Scratch/Python - we'll need to think a little bit about the best way to implement that, but it's not insurmountable.

All the best,


14:29:18, 15th December 2017   |   Permalink   |   View Source
Klauscon OP

Just to add a little bit more - the way I am using Marty right now is to have students explore a more complicated robot, with multiple servos, to understand motion, dependency of movements etc. We use scratch and Python to do the basic move , dance, sequential pattern type coding. However when it comes to more sophisticated problems, like object avoidance we currently switch to other robots. The bump switch is not really a replacement for understanding how to read sensor ranges, do cyclic checks for sensor data etc. But at the age group we are using Marty with now, explaining (or even just using) a Raspi interface would be too complicated. I would love to have a simple way for example to have a US sensor mounted to the head, and have multiple martys walking around in an arena, avoiding each other. Or hijacking one of the servo connectors, and mounting the sensor on a platform, and now Marty can actively look for viable paths with an active radar.

06:59:59, 15th December 2017   |   Permalink   |   View Source
Klauscon OP

Have to agree with kjw here - I think you need to look into this issue a little bit more. Out of the box Marty is a great experience, but going from Marty to integrating a RaspPi or Arduino is jumping a few levels that many students will struggle with. Having an intermediary step where Marty alone can have sensors added, with simple Scratch blocks to control behaviour would add so much value to the overall experience. It would also help to clearly delineate where additional boards are needed (e.g. more than sensor 1 input, more than two etc). I do not think this needs to be a super sophisticated solution - a limited i2c support for example, that allows us to read data from simple sensors like the HC-SR04 would be absolutely ideal.

06:52:12, 15th December 2017   |   Permalink   |   View Source

The Raspberry Pi sounds nice for one part of the userbase but it would be great to facilitate a few easy sensor additions and have those accessible from Scratch for those less familiar with electronics and the younger programmers.

Some of your users and some schools will already have the sensors from Lego Mindstorms. There's also Seeed Studio Grove system which I've just started reading about.

15:30:33, 14th December 2017   |   Permalink   |   View Source
angus STAFF

@kjw basically, we think it'll be easier for those looking to start adding sensors to stick a RaspberryPi or Arduino in Marty's head and use Rick just as the interface/API for making Marty do things, and do your own sensor processing - this of course makes it easier for you to use whichever sensor you so choose, and removes the need for us to bake-in code in the firmware to handle pulling info out of a load of different sensors...

We will eventually get around to fleshing out a Arduino Library and our Pi-based code to make this a lot easier than it is now, but at the moment the lowest-level interface to Rick over Serial that our ROS library uses to talk from Pi to Rick is view-able on GitHub

14:51:50, 14th December 2017   |   Permalink   |   View Source

A related question, have you looked at providing partial (i2c only) or full compatibility with the Lego Mindstorms NXT/EV3 sensors?

14:42:57, 14th December 2017   |   Permalink   |   View Source

I have an i2c capable sensor (tinyLiDAR) and would be interested in connecting it to Marty's rick board. Is is possible to interact with it using the existing python library? Would this ever be possible from Scratch?

Is Raspberry Pi addition the only way to add in i2c things at the moment?

On Rick - Ratings and Maximums it refers to SDA_1 and SCL_1 being 3.3v only. Is that also true for SDA_2 and SCL_2?

22:25:33, 12th December 2017  *   |   Permalink   |   View Source
sandy STAFF

Hi Klaus!

Short answer - yes, kinda

We're working on support for two different types of distance sensor, one of which will be a simple ultrasonic like the HC-SR04, an the other which will be an i2c IR distance sensor.

We'd hoped to have the ultrasonic support in at launch but didn't quite get it there, so it will require a firmware upgrade to run natively on Rick. That'll be a little bit tricky for Martys already out in the wild, but we'll sort something out ;-)

We will hopefully have some news on the ultrasonic sensor by the end of the week!


13:19:33, 09th August 2017   |   Permalink   |   View Source