This article describes how to interface your MTi 1-series Development Kit with an Arduino for prototyping and testing. Xsens plans on releasing example code for interfacing with an Arduino soon. Alternatively, embedded examples for I2C and SPI communication with an STM32 Nucleo board are available as part of the MT Software Suite. For more information, see this article.
We recommend to start by reading the MTi 1-series datasheet as well as chapters 4.1-5.2 of the LLCP document and this article to learn about how to communicate with the MTi 1-series using low-level communication, and I2C/SPI in particular. Note that I2C/SPI communication uses reduced Xbus messages; that is, Xbus messages with Preamble and busID removed.
I2C and SPI communcation with an Arduino is usually done using the Wire.h and SPI.h libraries respectively. It is important to start by reading these pages for a general introduction to these libraries and to determine the pin connections for connecting the MTi 1-series (Development Kit) to your Arduino board.
- For I2C communication:
- You will need to at least connect the SCL, SDA, GND and VDD lines. See the table below.
- In addition, pull-up resistors are required for the SCL and SDA lines. These pull-up resistors are already included in MTi 1-series Development Kits of hardware revision 2.4 and later. For hardware revisions 2.3 and below, it is required to add these resistors of 2.7 kΩ externally, connecting SCL/SDA to IOREF of the Arduino. The hardware revision is printed on the bottom side of the Development Kit.
- For SPI communication:
- You will need to at least connect the MOSI, MISO, SCK, nCS (Arduino: SS), GND and VDD lines. See the table below.
- In addition, as indicated in the MTi 1-series datasheet, the MTi uses SPI mode 3 and outputs MSB first. The Arduino needs to be configured for this by using the command:
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3));
MTi 1-series DK
|nCS||(any digital I/O pin)|
In order to enable I2C or SPI communication, the selection switches PSEL0 and PSEL1 on the DK board need to be set. The correct settings are printed on the DK. The address of the DK shield for I2C communication can be set using the ADD0, ADD1 and ADD2 selection pins. When left unconnected, the default address will be 111 (0x6B). For more information, refer to the MTi 1-series DK User Manual.
The correct operation of this setup has been tested and verified with the Arduino Uno and Arduino Due.
- Why is my Arduino not receiving all data packets sent by the MTi?
The MTi 1-series feature a maximum output frequency of 100 Hz for most outputs. If the Arduino is not able to keep up with reading all these data packets, it will skip some of them and data overflow messages (0x42 0x01 0x29 0x95) will be generated in the Notification Pipe. You will need to lower the output frequency of the device, or speed up the Arduino code (for example by reducing the amount of Serial print commands).
- Why are the data packets I receive corrupted?
Improper wiring may cause communication issues. We recommend not using wires longer than 20 cm.
- Why are the data packets I receive incomplete?
By default the Wire.h library makes use of 32-byte buffers. This means that the last part of packets with a length of more than 32 bytes will be dropped. It is possible to increase the buffer size, i.e. by modifying the Wire.h library files. For further help, please refer to the Arduino forums.
- I cannot upload my Arduino code when the MTi 1-series Shield Board is mounted onto the Arduino.
The UART pins of the Development Kit can interfere with the Arduino programmer. Ensure that the selection switches PSEL0 and PSEL1 on the DK board are set correctly. If the problem persists, instead of stacking the Development Kit onto the Arduino directly, try using wires to connect the necessary I2C/SPI lines and check whether that solves the issue.
- How can I change the address for I2C communication using my Arduino?
Connect the ADD# pins of your MTi 1-series DK to digital I/O pins of your Arduino and in your Sketch configure these I/O pins as output. You can then use digitalWrite() to set the address for I2C communication. Note that the MTi determines its address directly upon startup. This means that when the DK powers up (i.e. using the supply of the Arduino or through a reset of the MTi), the digital I/O pins must already be defined and configured.
- I am still having problems with this example or low-level communication in general.
Feel free to ask your questions on our Community Forum. Xsens staff will try to help you as soon as possible. Alternatively, you can request private technical support here.