Lego / HiTechnics angle sensor

I’m fairly new to both NXT and Arduino, but experimenting with my NXT sensors and an Arduino Mega with Bricktronics Shield. Can anyone give me any guidance about how to get data from the Lego or HiTechnics angle sensor with a Mega and Bricktronics Shield?

Thanks!

Hello Axe, it looks like this page has some sample code for using the rotation sensor with NXC language (scroll down near the bottom). It looks like this sensor is just an I2C device, so it shouldn’t be difficult to access from an Arduino. Here’s what I can glean from the code:

  • The sensor has I2C address 0x02, and supports three commands:
  • Command 0x42 means “read data”, it returns 8 bytes, which are interpreted as follows:
  • angle = byte0 * 2 + byte1
  • accumulated angle = byte2 * 0x1000000 + byte3 * 0x10000 + byte4*0x100 + byte5
  • RPM = byte6 * 0x100 + byte7
  • Command 0x41 means “reset sensor”, and has two sub-commands (the next byte):
  • Sub-command byte 0x43 means “calibrate this position as zero”, and you need to delay 50 milliseconds after this command to allow the sensor to update the stored “zero” value
  • Sub-command byte 0x52 means “reset accumulated rotation count to zero”

If you just want to get this sensor working with your Arduino, I’d suggest connecting your board’s I2C signals to pins 5 and 6 of the sensor, and then try some basic I2C transactions to see what you get back from the sensors.

If you want to get it working with a Bricktronics Shield or Megashield, I’d suggest taking the Ultrasonic CPP and H files and modifying them for this new sensor. Shouldn’t be too difficult. I’d start with sensor ports 3 and 4, since the sensor pins 5/6 are connected to Arduino pins, not I/O expander pins, so they’ll be faster and will work with the software I2C library we’re using.

If you really want to get it working but can’t or don’t want to do it yourself, let me know and I can try to modify the Ultrasonic code for you to test out. I might need to purchase one of these sensors to get it working, or maybe I can borrow one from someone…

Also, I just wanted to let you know that the Bricktronics Shield won’t always work with the Arduino Mega, since the I2C pins are not located on A4/A5 like the Uno and compatibles. If you have the rev3 of the Mega board, you can try setting the switch to “rev3” which determines where the I2C signals are connected. Even then, it’s not something we’ve tested, but do let us know if you find anything that does or doesn’t work when using a Mega with a regular Bricktronics Shield.

Thanks for the quick reply, Layne!