I2C Support

Is there any way to connect a I2C Sensor to the Wixel?


The Wixel doesn’t have hardware I2C, so any I2C needs to be done in software. Fortunately, this is pretty easy if you know the Wixel will be the only I2C master in the system. A serial-to-I2C app for the Wixel is in the works, and we will be adding software i2c functions to the SDK, but I don’t have an estimate for when all that will be done.

- Ben


We have just released a Serial-to-I2C app for the Wixel, along with an I2C library.

The source code for the app is in the Wixel SDK, and information about the library has been added to the SDK documentation.

If you use a Wixel in a project involving I2C, we would love to hear about it!

- Kevin

Thank you for the wonderful library!

I am using the I2C library to read from the TC74 thermometer from Microchip.
For some reason, I get this warnings and error list:

Right now the application has been reduced to the minimum code so I can try to identify the error, but I cant find it…
Here is my code:

/* TC74_Test.c: 
This is a library to work with the TC74 Thermometer from Microchip

/* Dependencies ***************************************************************/

#include <i2c.h>

/* Pin Description */

uint8 DATA i2cPinScl = 10; // P1_0
uint8 DATA i2cPinSda = 11; // P1_1

/* Global Variables */
uint8 W = 0;
uint8 R = 1;

/* Functions ******************************************************************/

/* TC74_GetTemp: **************************************************************
Gets the temperature of the specified TC74 Address
int TC74_GetTemp(uint8 TC74_Dir)
   uint8 Temp;
   i2cWriteByte(TC74_Dir + W);
   i2cWriteByte(0x00);    //Request Temperature
   i2cWriteByte(TC74_Dir + R);
   Temp = i2cReadByte(0);
   return Temp;

Can you guys see what I am missing?

Thank you for all your help!

Hello, Mif,

Your build is failing because you are not linking i2c.lib into your program (it is not on the list of default libs, although we are considering adding it). To fix this, you can copy the options.mk from the serial_i2c app into your app’s directory; this file contains a single line that adds i2c.lib to the list of libraries linked with the app:

(If you already have an options.mk, you can edit it to produce the same effect.)

Once you link in that library, you will find that your declarations of i2cPinScl and i2cPinSda as new variables will conflict with the ones already declared in the library, so you should remove the “uint8 DATA” so that you just change the value of the library variables. (Since 10 and 11 are the default values, you could also remove those lines completely.)

- Kevin

WOW! Thank you !
That was such an easy solution!
I cant test it now, but I compiled it without any problem, so I think this should be fine :slight_smile:

I’ll let you know my progress here.


Hi Kevin,
I’m trying to use the I2C app for my Wixel, and going through the manual I would like to know if the I2C commands are all sent separately, or can be sent as one line. I’m using the Wixel with an ADXL345 Accelerometer, and need to configure the chip by setting the registers to certain values prior to reading from the chip. I have a whole bunch of lines such as:
‘S’, 0xA6, 2, 0x2E, 0x00, ‘P’
‘S’, 0xA6, 2, 0x31, 0x08, 'P’

Do I send these commands one at a time through my terminal program, or would I send the following as one line?

‘S’, 0xA6, 2, 0x2E, 0x00, ‘P’, ‘S’, 0xA6, 2, 0x31, 0x08, ‘P’


‘S’, 0xA6, 2, 0x2E, 0x00, 0xA6, 2, 0x31, 0x08, ‘P’

Lastly, if I were to write all lines in a text file and convert it to binary, how would I load this to run as a program on the Wixel?
Thanks so much.

Quick update. I’ve realized that I should be sending the S, P, and E commands without the single quotes.
Also, when I read the error I’m getting a 13 or 03 if I enable or disable the cmd_timeout_ms parameter in the Wixel Configuration utility. Also, Using the Serial Transmitter Utility will only send and receive serial data, and I’m trying to send data on the I2C data line, which leads me to believe that the Serial Transmitter Utility isn’t exactly what I should be using. I’m using the Br@y terminal recommended by the Wixel Manual and sending commands in HEX, which allows me to send the commands and receive these errors.

Hello, Albaraa,

The purpose of the Serial-to-I2C app is to receive commands from a serial interface and translate them into I2C operations (and return the I2C slave’s response over the serial interface). For example, receiving the ‘S’ command on the serial interface tells the Wixel to generate a start condition on the I2C interface, so the commands you wrote above are all sequences that you should be sending to the Wixel serially.

The reason I recommended on the phone that you use the serial transmitter utility is that you need to send some of the bytes as raw values. To send

‘S’, 0xA6, 2, 0x2E, 0x00, ‘P’

you should not be sending a single quote, S, single quote, comma, space, 0, x, A, 6, and so on (you seem to have figured out at least part of this already). Instead, you should be sending the character S (i.e. a byte with value 0x53), then a byte with value 0xA6, a byte with value 2, a byte with value 0x2E, etc. Not many terminal programs allow you to send raw bytes this way, but it looks like you can do it in Br@y Terminal by prefacing a hexadecimal value with a ‘$’, like this:


(You might also want to select the “HEX” radio button in the Receive section of the Br@y Terminal window so you can see the responses from the Wixel in hex format.)

Either sending the two commands separately or joining them together on one line (keeping the stop and start between the two commands) should work. However, the last sequence you wrote (removing the stop and start between the two commands) would probably not work, because most I2C devices use those start and stop conditions to separate different commands. I recommend that you check the datasheet of your accelerometer to make sure the format of your I2C commands matches what it expects.

If you want to write an app for the Wixel to send these commands directly (instead of using the Serial-to-I2C app to translate serial commands to I2C), you should look at the SDK documentation for i2c.h, which describes the functions in the i2c library that you can use in your app.

- Kevin

Thanks Kevin,
That was a huge help. Are you aware of any sample code out there that would let me create and compile a c program that will do my communication for me over the serial port? I see the serial_i2c.c file provided with the source code for the app, and would love to use this to send commands at a specific frequency to the devices attached to the Wixel. This may seem like a really trivial question, so I just need a resource or to be pointed in the right direction.
Thanks again,

We do not have any specific guides or example code to recommend to help you with serial communication, but you might be able to find something by doing an online search for “c serial example” or something similar. This thread has an example that shows how to use a serial port in C in Windows (it is for a Maestro servo controller, but you should be able to modify it to work). Alternatively, if you can use .NET (C++, C#, or VB) instead of C, Microsoft provides a SerialPort class that should help you.

- Kevin

Hi Kevin,
This is a huge help. I’m still stuck and struggling with exactly how to send my string over the serial port. I’m using the Serial Port Class you pointed me towards, and the line _serialPort->Write() or _serialPort->WriteLine(String::Format()), but I’m not sure exactly what to put within these strings or chars. I’ve tried putting them in double quotes, and I’m thinking the lines I’m using in Br@y terminal aren’t appropriate for this, but I’ve tried them anyway:


I’ve also tried several lines writing each segment separately, like this:

The only thing I’ve gotten to work is reading errors, by doing
and then reading the response by taking in an int through _serialPort->ReadByte()

Any help or direction would really be appreciated. Thanks again for your help previously.

You are correct that the SerialPort.Write method does not take the same format as Br@y Terminal. Also, the SerialPort methods that take strings encode all characters greater than 127 as (char)63 by default, so to send an array of arbitrary bytes, you should use the form of SerialPort.Write that takes a byte array instead (SerialPort::Write Method (array, Int32, Int32)).

I think your code should look like this (although I have not tested it):

array<unsigned char>^ buffer = {'S', 0xA6, 1, 0, 'S', 0xA7, 1, 'P'};
_serialPort->Write(buffer , 0, buffer->Length);

- Kevin

Worked like a charm… Thanks Kevin!

All I need is an I2C bridge to use a WII Nunchuck which is I2C over the wixel wireless to another wixel wireless and then in to an Ardunio.

Any ideas for the best way to do this ?


Hello, JT,

It sounds like you should be able to do what you described by using a pair of Wixels; the Wixel connected to the Wii Nunchuk should run the Serial-to-I2C app, and the Wixel connected to your Arduino should run the Wireless Serial app. The Arduino would send serial commands to the Wixel it is connected to, which would then transmit the command wirelessly to the Wixel running the Serial-to-I2C app, which would in turn translate it to an I2C communication to be sent to the Nunchuk; any responses from the Nunchuk would be translated back to serial and returned through this process in reverse. You can read the documentation for those apps in the Wixel user’s guide to learn how they work.

If you have not already seen it, you might be interested in our Wixel shield, which allows you to easily connect a Wixel to an Arduino.

- Kevin