Using the ultrasonic sensor with other controllers

Discussion specific to the intelligent brick, sensors, motors, and more.
nxtboy
Posts: 29
Joined: 29 Sep 2010, 18:15
Location: Cambridge, UK
Contact:

Using the ultrasonic sensor with other controllers

Post by nxtboy »

I've been trying to interface the Lego Ultrasonic sensor with a different microcontroller (namely the mbed), but so far all I've managed to do is break the sensor, as it now no longer works with the NXT brick. I suspect it's something to do with my wiring.

Unfortunately, the data sheet is useless in that respect, as it contradicts itself. In one place, the green wire is labelled VCC_5V, and in another, a mysterious 4.3V_Power is shown. How much should I be providing?

Currently, I've wired it up as follows:
  1. White -> NC (firstly, I don't have 9V, and secondly, that's for analog sensors, right?)
  2. Black -> Ground
  3. Red-> Ground
  4. Green -> +5V
  5. Yellow -> SCL -> 2.2k resistor -> 5V
  6. Blue -> SDA -> 2.2k resistor -> 5V
I can confirm that my wire is behaving correctly. I'd rather not plug my remaining US sensor in until I'm sure that it's correct

What did I do that managed to burn out the sensor?
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: Using the ultrasonic sensor with other controllers

Post by gloomyandy »

Hi,
You need to supply the 9V to the device, this is what is used to power the output side of the sensor. Without the 9V supply you will not get any pings from the device. However if it no longer works with your NXT then you may have damaged it...

The written NXT hardware documentation shows the green pin as a nominal 4.3V supply, but actually measuring the output on my NXT shows it at 4.75V (with no load). I doubt if providing 5V on this line will have damaged the sensor. The sensor schematic may well be correctly showing 4.3V at that point on the diagram as it is on the other side of a 100R resistor which may be dropping the voltage from the nominal supply to 4.3V...

Finally you may have problems talking to this sensor using a standard i2c interface. The i2c interface implemented in the Lego firmware has extra timing delays and reset states that seem to be required to make the Ultrasonic sensor function...

Andy
nxtboy
Posts: 29
Joined: 29 Sep 2010, 18:15
Location: Cambridge, UK
Contact:

Re: Using the ultrasonic sensor with other controllers

Post by nxtboy »

gloomyandy wrote:Hi,
You need to supply the 9V to the device, this is what is used to power the output side of the sensor. Without the 9V supply you will not get any pings from the device. However if it no longer works with your NXT then you may have damaged it...

The written NXT hardware documentation shows the green pin as a nominal 4.3V supply, but actually measuring the output on my NXT shows it at 4.75V (with no load). I doubt if providing 5V on this line will have damaged the sensor. The sensor schematic may well be correctly showing 4.3V at that point on the diagram as it is on the other side of a 100R resistor which may be dropping the voltage from the nominal supply to 4.3V...

Finally you may have problems talking to this sensor using a standard i2c interface. The i2c interface implemented in the Lego firmware has extra timing delays and reset states that seem to be required to make the Ultrasonic sensor function...

Andy
Thanks. I was aware of the problems with the I2C.

Do the Hitechnic use this strange protocol, or is it only the US sensor?

Also, do the Hitechnic sensors require the 9v supply line?
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: Using the ultrasonic sensor with other controllers

Post by gloomyandy »

I'm pretty sure it is only the Lego sensor that has the rather odd i2c. Can't be sure about the 9V supply I don't know of any hiTechnics sensors that require it (though they may use the 5V that is supplied on that pin when the sensor is set to normal mode)... Possibly the (non hiTechnics) RFID sensor uses the 9v supply as well...

Andy
nxtboy
Posts: 29
Joined: 29 Sep 2010, 18:15
Location: Cambridge, UK
Contact:

Re: Using the ultrasonic sensor with other controllers

Post by nxtboy »

So my compass sensor should just work if I plug it in?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Using the ultrasonic sensor with other controllers

Post by HaWe »

according to the colors and voltages, maybe this could help:
Pins-and colors:
(danke an sebi!)

Sensor:
Pin1 White ANA Analog
Pin2 Black GND (-)
Pin3 Red GND (-)
pin4 Green +4,3V
Pin5 Yellow SCL (digital, I²C: Serial CLock Line)
Pin6 Blue SDA (digital, I²C: Serial DAta Line)

Motor:
Pin1 White Motor +9V; PWM-control
Pin2 Black Motor -9V; PWM-control
Pin3 Red GND
pin4 Green +4,3V
Pin5 Yellow Motorencoder (channel a; Schmitt-Trigger-Function)
Pin6 Blue Motorencoder (channel b; Schmitt-Trigger-Function)
nxtboy
Posts: 29
Joined: 29 Sep 2010, 18:15
Location: Cambridge, UK
Contact:

Re: Using the ultrasonic sensor with other controllers

Post by nxtboy »

doc-helmut wrote:according to the colors and voltages, maybe this could help:
Pins-and colors:
(danke an sebi!)

Sensor:
Pin1 White ANA Analog
Pin2 Black GND (-)
Pin3 Red GND (-)
pin4 Green +4,3V
Pin5 Yellow SCL (digital, I²C: Serial CLock Line)
Pin6 Blue SDA (digital, I²C: Serial DAta Line)

Motor:
Pin1 White Motor +9V; PWM-control
Pin2 Black Motor -9V; PWM-control
Pin3 Red GND
pin4 Green +4,3V
Pin5 Yellow Motorencoder (channel a; Schmitt-Trigger-Function)
Pin6 Blue Motorencoder (channel b; Schmitt-Trigger-Function)
Yep, I found that, it's just inconsistent with other bits of the hardware specification.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Using the ultrasonic sensor with other controllers

Post by mattallen37 »

Lego uses pin 5 as a logic IO pin (such as to turn on the light on the light sensor). Pin 1 is the analog pin, but it can be driven high (supply voltage). Lego does some nonstandard things that really don't make sense.

Also, you noted that you used 2k2 pullups. Why such low values? The NXT uses 82k, and unless you are going into insane speeds, 10k should be the lowest value you will ever need (for non NXT stuff). If you really did mess up (or "burn out") the sensor, it is likely because the pullups are way too "strong".
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: Using the ultrasonic sensor with other controllers

Post by gloomyandy »

mattallen37 wrote:Lego uses pin 5 as a logic IO pin (such as to turn on the light on the light sensor). Pin 1 is the analog pin, but it can be driven high (supply voltage). Lego does some nonstandard things that really don't make sense.
A little more information...
The power supplied to pin 1 has three possible states...
1. Pulsed 9V the pin is driven to 9V for approx 3mS then allowed to float to the 5V pull up for approx 0.1mS during which time an analogue reading is taken.
2. The pin is driven at 9V all of the time (but the analogue reading still happens 333 times a second).
3. The pin is pulled up to 5V constantly and again read 333 times a second.
Although this may seem a little odd, Lego had good reason to do it to allow compatibility with the old RCX sensors.

Pin 6 as well as being a digital output pin can also be used as an analogue input pin (but this is read by the NXT Arm chip rather than the ATmega which reads pin 1). This pin can be sampled by the firmware at a much higher sample rate, and is currently used to read data from the Lego color sensor
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Using the ultrasonic sensor with other controllers

Post by mattallen37 »

Although this may seem a little odd, Lego had good reason to do it to allow compatibility with the old RCX sensors.
I know, and I am glad it IS backwards compatible, I just think they made a few weird decisions (partly in the RCX design). The "official" term for the 3ms then .1 ms thing is "active" (vs "passive"), used by lego only for the legacy light and rotation sensors (for those who didn't know). Active is indeed an ingenious way to power and read an analog sensor with only two wires, but it does have it's downsides.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests