go_away

Author Topic: I2C colour sensor webbotlibs  (Read 562 times)

0 Members and 1 Guest are viewing this topic.

Offline RifRafTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
I2C colour sensor webbotlibs
« on: March 09, 2013, 12:37:50 AM »
Am trying to interface the TCS3414 RGB sensor into a webbotlibs project but cannot get started.  In Project Manager added the device as a generic i2c device from within an i2cMaster.  When doing so the list of i2c address does not include this device, being 0x39,  The closest options are 0x38 or 0x3A, so I choose one of them and then manually alter this to 0x39 in the generated lib/lib_hardware.c after making it not read only.  Is this what I should be doing or is there a better way?

The basic code so far which is just trying to read and write to a single register but fails on both.  The sensor on the same board is running fine with some arduino code which I have modified to a point where i'd like to use it for existing webbotlib projects but now need to port it over.  Any ideas welcome.

the working arduino code can be found here http://www.maxwellrosspierson.com/2012/11/18/interfacing-the-arduino-to-the-taos-tcs3414-via-i2c-continued/

the code i am trying to begin i2c communications with webbotlib.

Code: [Select]
#include "hardware.h"

// Initialise the hardware
void appInitHardware(void) {
initHardware();
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
TCS3414.writeRegister(80, 1);
delay_ms(20);
if( TCS3414.writeRegister(80, 3) ){
    rprintf("Turned On TCS3414\n");
}else{
    rprintf("Failed writing TCS3414\n");
}
return 1000000;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

// Read 1 register values starting at register 1 into response
uint8_t TCS3414_response[1];
if(TCS3414.readRegisters(1, sizeof(TCS3414_response), TCS3414_response)){
// We have successfully read the data into 'TCS3414_response'
}else{
rprintf("Failed reading TCS3414\n");
}
// -------- End   Generic I2C Device-------

return 1000000;
}

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,272
  • Helpful? 79
Re: I2C colour sensor webbotlibs
« Reply #1 on: March 09, 2013, 02:11:51 AM »
There are two ways of specifying i2c addresses. It could be that there's a mis-match between your data sheet and your library (I don't use webbotlib, so I don't know how that's supposed to be set up.)

Does your data sheet specify a different address for reading than for writing? If so, you are using the 8-bit address. If the library wants the 7-bit address, you have to shift your address right one (divide by two.)

Does the data sheet just specify one address, and keep the read/write bit separate? Then you are using the 7-bit address. If the library wants the 8-bit address, you have to shift your address left one (multiply by two.)

Offline RifRafTopic starter

  • Jr. Member
  • **
  • Posts: 10
  • Helpful? 0
Re: I2C colour sensor webbotlibs
« Reply #2 on: March 09, 2013, 02:47:28 AM »
jwatte thanks so much, i never would have guessed, i changed the slave address to 0x72 and i get "Turned On TCS3414" displayed. I got the 0x72 by using calculator in hex mode to multiply by 2 as you said. The datasheet specified a single address, as in,

The RGB values can be read in a single read cycle to minimize the number of read command protocols defined in the communication interface.
The slave address for this device is 39h (0111001b).

now to try and get the code working with webbotlibs.

 


Get Your Ad Here

data_list