NXShield Driver Suite

This NXShield Driver Suite is specifically for an Arduino with a NXShield, and to be used along-side of the NXShield drivers provided by OpenElectrons.com.

Included are the driver files, example programs for each of the devices supported, keywords file (for syntax highlighting in the Arduino IDE), a ReadMe file (with directions for installing), a change log, and doxygen HTML documentation.

All drivers and examples have been tested with arduino-1.0.1, NXShield-0.1.01, and an Arduino Mega 2560 with NXShield-M. You need to be using at least version 0.1.01 of the NXShield library.

The current version of the driver suite is V1.12, and supports the following devices:

Dexter Industries:

	Color Sensor v1
	IR Receiver
	IR Seeker v1
	Magnetic Compass

	Sound sensor

Here is the complete change log:

Version 1.0

	Support for HiTechnic Accelerometer
	Support for HiTechnic Color Sensor
	Support for HiTechnic Gyro
	Support for HiTechnic IR Receiver
	Support for HiTechnic IR Seeker
	Support for HiTechnic Magnetic Compass

Version 1.1

	Functionality changes to existing drivers:

		Added HiTechnic Gyro calibration support
		Added HiTechnic Compass calibration support
		Removed HiTechnic IR Receiver function "ReadValue"
	New device support:

		Dexter Industries dIMU
		Lego Sound sensor

	Changes to all device drivers:

		Added doxygen (HTML) documentation support for all drivers
		Prefix all class names with "Class", e.g. "HTAC" > "ClassHTAC"
		Postfix all driver file names with "_driver", e.g. "HTAC" > "HTAC_driver"

Version 1.11

	Fixed an error in the calculation of the SoundLevel in ClassNXTSound

Version 1.12

	Lego Sound sensor - Removed the work-around previously needed for setting the type.
	Lego Sound sensor - Added function init.

35 Responses to NXShield Driver Suite

  1. Christian says:

    Very good project.
    I want use dexter dimu on nxschield and arduino , where download this library for dimu.

  2. Daniel says:

    We dont get any values from the IR Seeker. Is there annother IR Seeker Version? If I plug the compass on the BAS1, where the Seeker should be, then we get values from the compass. But 3 IR Seeker dont give any numbers. ONly zeros…

    • mattallen37 says:

      I think you are using the IR Seeker V2. V2 of that specific sensor uses I2C address 0x10, instead of the standard 0x02. I don’t have an IR Seeker V2, so I didn’t make a library for it. If you are okay with only having access to the DC signal related values, in “HTIRS.h” you can change line 21 from “HTIRS(uint8_t i2c_address = 0x02);” to “HTIRS(uint8_t i2c_address = 0x10);”. If you want the AC values, in “HTIRS.cpp” you can change line 23 from “return readByte(0x42);” to “return readByte(0x49);”, and line 28 from “readRegisters(0x42, 6, HTIRS_I2CReply);” to “readRegisters(0x49, 6, HTIRS_I2CReply);”. In theory both of these suggestions should work for you, but I can’t test them to be sure.

  3. Pingback: NXShield dIMU Segway | mattallen37

  4. joe says:

    Hi there. Im currenlty working on a color sorting project with the hitechnic color sensor and i was just wondering if you knew how to control the bytes when you read the color. Cause what i wanted to do is if it sensed red, a motor would go to a certain angle, if it sensed blue, my motor would go to a different angle..

    • mattallen37 says:

      The functions ReadColor and ReadRGB both return the color value, 0-17, based on the color it detects. Look at or run the example program to see what I mean. You can use that value for whatever you want in the program.

      • joe says:

        yeah i get to print that but how can i compare that data with an int?

        This doesn’t work:
        if (Color = 6)
        Serial.println (“Good”);

        even if i wasn’t detecting anything… it still prints Good…

      • mattallen37 says:

        If you are comparing an equals, you need to use == not =. Using = will set the left value (color) to the value on the right (6), and will always return true.

  5. Alex says:

    Hi I was just wondering how i would be able to calibrate my compass sensor using the NXshield-m, your help would be greatly appreciated, also thanks heaps for this library suit 🙂

    • mattallen37 says:

      I actually have never calibrated any of the HT compass sensors (even using the NXT), so I’m not entirely sure. I think there is a simple write then read process you can do, but my suite doesn’t support it at this time (frankly, because I haven’t ever needed it to).

      Adding support for it is one of many additions I would like to do eventually, but I’m unsure if I’ll find the time.

  6. Alex says:

    Okay thats fine thanks for the help, i have calibrated the sensor with my nxt before. The reason why i need to calibrate is because i’m doing robot soccer and the magnetic fields change often with the change in field location etc… so i will calibrate the senor with my nxt for now then get back to you with a library that does calibrate it for others who might need it. 🙂 thanks anyway mate.

    • mattallen37 says:

      I’m working on adding support for calibration (practically done now), but I need to find a little more information before I release it.

      • Alex says:

        hey i was wondering if you have finished that calibration program, i have one for the nxt brick that calibrates a compass sensor just need the Arduino one 🙂 could you send me what you have done so far? that would be awesome if its not a bother 🙂

      • mattallen37 says:

        Version 1.1 introduced compass calibration (read the change log). Get the latest version of the drivers, which is currently V1.11, and you should be able to calibrate your compass. Run the example program called “Example_HiTechnic_Compass_Calibrate”.

  7. Pingback: NXShield Lego Arduino Drivers V1.1 released | mattallen37

  8. alfredo says:

    Hi Matt, does the driver suite version 1.11 can control IR seeker V2? I have one and I am going to try it with arduino

  9. alfredo says:

    But with seeker V1 is functional?
    I´m trying with V2, in case I had some problems, can you help me in how to create the program for V2?
    Please is very important for me, cause I am working in a seeker robot

    • mattallen37 says:

      Check out the product page for the sensor: http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NSK1042

      On that page you will find a chart of the I2C register layout. IIRC, the registers of V1 are the same as the DC registers of V2. That means that the existing V1 support should (in theory) be compatible with V2’s DC mode, but they have different I2C addresses. You will need to change the I2C address to 0x10 (from 0x02). In order to read the AC values from V2, you will need to read a different set of registers.

  10. alfredo says:

    Hi, do you know how can I connect a IR Seeker directly to arduino mega without using the nxshield?

    • mattallen37 says:

      You need to connect pin 2 and or 3 of the IR Seeker to Gnd, pin 4 to 5v, pin 5 to SCL, and pin 6 to SDA. I suggest using either an NXT wire cut in half, or else an NXT socket breakout sold by mindsensors, for the physical connection.

      For SW, you will need to use the Wire library, and read from the appropriate registers (documented on the HT product page).

  11. alfredo says:

    ok, I´ll try it

  12. alfredo says:

    I did what you did but nothing, do you have a routine for test the conexion between arduino and the irseeeker, for example for gettting the vendor ID, Firmware version, etc…

    remember i dont have the nxshield

    • mattallen37 says:

      I don’t have any programs for that already made. I’m currently on vacation without access to an Arduino, an IR Seeker, or my programming computer. If you would like to try working on it on your own, I suggest you take a look at Clinton Blackmore’s work. He wrote the “BaseI2CDevice” library, which seems to be a HW I2C library based on the Lego register structure for I2C. I haven’t used the library as a stand-alone I2C function interface, but it is one of the two low-level I2C libraries used by the NXShield drivers.

      If you want more help let me know, but I won’t be able to work on it ’til at least next week.

  13. alfredo says:

    hi, sorry for interrupt your vacation. Well some questions, as you recommended I am now working with clinton blackmore´s BaseI2C function, first when you say be carefull in reading the appropiate registers of the V2 you mean the list of addresses (p.e address 08-0Fh for type sensor, etc).
    second how I must interpret those values? some appear like ranges 08-0F and another with a single value (p.e 41H)


    • mattallen37 says:

      The first three sets of registers (of the IR Seeker V2), are strings of characters (as shown on the product page). You can read e.g. 0x00-0x07 into a char array, and then the string will contain whatever text is stored in those registers (the sensor version number).

      Register 0x42 contains the current DC direction (a value of 0-9, based on the direction of the DC IR light hitting the sensor).

      Play around with it, reading different registers.

  14. Fede says:

    Hi, Excelent work!!! Let´s see If U can help me with HTIRR…

    When I upload the example, it looks for “SH_Mode_ANALOG_9VOLTS” and the compiler stops.


  15. Fede says:

    Thanks for your replay.

    I´m running the library NXShield-0.1.01.zip 2012-06-07 1.4 MB
    provided as the “latest”… The problem in V1.11 is in 2 variables not declared in ClassNXTSound.
    I´ve desinstalled both libraries and started from scratch but it looks like the problem isn´t solved.

    I appreciate your works, and I believe it´s very usefull.
    Thank U again…

    • mattallen37 says:

      I’m quite confident that having the latest version of drivers from OpenElectrons.com and the latest version of my drivers, that it will not cause problems. Are you sure that you have installed the latest versions, and removed all older versions? Are you using Arduino IDE 1.0.1?

  16. Fede says:

    Thank U. Everything checked twice…Versions, Libraries…
    Here´s a copy from compiler.

    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp: In member function ‘bool ClassNXTSound::SetDB()’:
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp:88: error: ‘SH_Mode_ANALOG_9VOLTS’ was not declared in this scope
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp:88: error: ‘SH_Mode_DATABIT_HIGH’ was not declared in this scope
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp:88: error: ‘setMode’ was not declared in this scope
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp: In member function ‘bool ClassNXTSound::SetDBA()’:
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp:121: error: ‘SH_Mode_ANALOG_9VOLTS’ was not declared in this scope
    C:\Users\Bichito\Documents\Fede\Personal\Arduino\Arduino 1.0.1\libraries\NXShield_Lego_Arduino_Drivers\NXTSound_driver.cpp:121: error: ‘setMode’ was not declared in this scope

    Please see it…
    Thanks again.

    • mattallen37 says:

      That is impossible. According to those errors, you likely have the correct version of drivers from OpenElectrons.com, but certainly you have an old version of my drivers. Remove all of my drivers, and re-install version 1.11, and it will be impossible for those errors to exist.

      If you need further assistance, please email me, and I will be happy to continue trouble-shooting.

  17. Fede says:

    Hi!! I´ve been working on projects using your amazing library. I need some help on using HTTIR. The thing is I can´t find the way to “reset” the values, cause everytime i call the methods ReadAllChannels or ReadChannel, the values are updated from readRegisters() buffer.
    So, I´ve tried to modify the library to access to the clear_buffer parameter in BaseI2CDevice, but althoght I manage to compile w/o errors, those changes didn’t made it functional.

    uint8_t* BaseI2CDevice::readRegisters(
    uint8_t start_register, // start of the register range
    uint8_t bytes_to_read, // number of bytes to read
    uint8_t* buffer, // (optional) user-supplied buffer
    uint8_t buffer_length, // (optional) length of user-supplied buffer
    bool clear_buffer) // should we zero out the buffer first? (optional)

    Is there a way to reset the array (buffer) values while using the PF Remote Control between calls for ReadAllChannels or ReadChannel. It seems to me that Remote Control writes values on register and it gets fixed (logically) until it is modified by another written value. But it remains “bypassing” the sensor initializing and keeps the values for “Left and Right” dials in every channel (cool! –> but i dont want to,,,)

    Thanx in advance for your time….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s