caramoan tour package

caramoan tour package

caramoan tour package

Author Topic: Egizmo Color detector not working!!!!  (Read 783 times)

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Egizmo Color detector not working!!!!
« on: January 25, 2013, 09:22:23 PM »
helo mga sis tanong ko lng kung meron na bng nakagamit dto nung color dtctor sa gizmo. nkaorder kasi ako ng 2 eh mkhang tama nmn ung code bkit ndi xa ng rerespond??? :( :(
"The truth of a theory is in your mind, not in your eyes."

Philippine Electronics Forum

Egizmo Color detector not working!!!!
« on: January 25, 2013, 09:22:23 PM »

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #1 on: January 25, 2013, 09:30:29 PM »
first things first...

paano connection sa MCU?
paki post ng code?
8)

Philippine Electronics Forum

Re: Egizmo Color detector not working!!!!
« Reply #1 on: January 25, 2013, 09:30:29 PM »

Offline insomartin

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 5484
  • Pogi/Ganda Points: 367
  • Gender: Male
  • Design, Engineer, Create electronics circuits.
Re: Egizmo Color detector not working!!!!
« Reply #2 on: January 25, 2013, 09:43:49 PM »
sa flowcode ko ginawa yung code nito. nahirapan ako intindihin yung nasa e-gizmo. Happy camper. daming features nitong color sensor. :D share ko later yung code.

Philippine Electronics Forum

Re: Egizmo Color detector not working!!!!
« Reply #2 on: January 25, 2013, 09:43:49 PM »

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #3 on: January 25, 2013, 10:35:36 PM »
slmat po s mga reply! dto po ako ngbase ng conn. saka code..
Code: [Select]
/*
  ADJD-S311 Color Sensor Breakout Example Code
  by: Jim Lindblom
  SparkFun Electronics
  date: 8/9/11
  License: MIT license (http://www.opensource.org/licenses/mit-license.php) 
  This code is slightly modified from that posted on bildr.org's
  excellent tutorial (http://bildr.org/2011/01/adjd-s371-tutorial/), which
  was taken from Marcus' great initial code
  (http://interactive-matter.eu/2008/08/tinkering-with-adjd-s371-q999/).
  Thanks to Adam and Marcus for the initial code! I'd definitely recommend checking out
  their tutorial/posts.

  This example code initializes and calibrates the sensor upon startup. When calibrating
  the code is assuming the sensor is faced with a stable WHITE source. To best calibrate
  the sensor's capacitor and integration registers, it needs to be looking at a usual white
  object at calibration.
 
  After start-up, the sensor will wait for serial input. Open up the serial
  monitor at 9600 bps. A space ' ', will prompt the sensor for all of it's register
  values. 'c' will perform calibration (make sure it's aimed at a white object. 'o'
  will get the offset values (these are not trimmed, see getOffset() function). And 'l'
  will continously get the sensor readings and output them to an RGB LED.
 
  You may want to try with the sensor's LED (connected to Arduino pin 2) both on and off.
  I usually get better results with the LED off, but it depends on the object being sensed.
  It does a really good job of sensing colors off my LCD monitor.

  the hookup:
  ADJD-S311 Breakout ------------- Arduino
  ----------------------------------------
      LED ---------------------------D2
      3.3V -------------------------3.3V
      GND -------------------------- GND
      SCL -------------------------- A5
      SDA -------------------------- A4
      GND -------------------------- GND 
      SLP --------------------- Not connected
      CLK --------------------- Not connected
*/
#include <Wire.h>  // We use Wire.h to talk I2C to the sensor

// ADJD-S311's I2C address, don't change
#define ADJD_S311_ADDRESS 0x74

#define RED 0
#define GREEN 1
#define BLUE 2
#define CLEAR 3

// ADJD-S311's register list
#define CTRL 0x00
#define CONFIG 0x01
#define CAP_RED 0x06
#define CAP_GREEN 0x07
#define CAP_BLUE 0x08
#define CAP_CLEAR 0x09
#define INT_RED_LO 0xA
#define INT_RED_HI 0xB
#define INT_GREEN_LO 0xC
#define INT_GREEN_HI 0xD
#define INT_BLUE_LO 0xE
#define INT_BLUE_HI 0xF
#define INT_CLEAR_LO 0x10
#define INT_CLEAR_HI 0x11
#define DATA_RED_LO 0x40
#define DATA_RED_HI 0x41
#define DATA_GREEN_LO 0x42
#define DATA_GREEN_HI 0x43
#define DATA_BLUE_LO 0x44
#define DATA_BLUE_HI 0x45
#define DATA_CLEAR_LO 0x46
#define DATA_CLEAR_HI 0x47
#define OFFSET_RED 0x48
#define OFFSET_GREEN 0x49
#define OFFSET_BLUE 0x4A
#define OFFSET_CLEAR 0x4B

// Pin definitions:
int sdaPin = A4;  // serial data, hardwired, can't change
int sclPin = A5;  // serial clock, hardwired, can't change
int ledPin = 2;  // LED light source pin, any unused pin will work

// RGB LED pins, should all be PWM output pins:
int redledPin = 9;
int greenledPin = 10;
int blueledPin = 11;
int rgbPins[3] = {redledPin, greenledPin, blueledPin};

// initial values for integration time registers
unsigned char colorCap[4] = {9, 9, 2, 5};  // values must be between 0 and 15
unsigned int colorInt[4] = {2048, 2048, 2048, 2048};  // max value for these is 4095
unsigned int colorData[4];  // This is where we store the RGB and C data values
signed char colorOffset[4];  // Stores RGB and C offset values

void setup()
{
  pinMode(ledPin, OUTPUT);  // Set the sensor's LED as output
  digitalWrite(ledPin, HIGH);  // Initially turn LED light source on
 
  for (int i=0; i<3; i++)
  {  // Set up the RGB LED pins
    pinMode(rgbPins[i], OUTPUT);
    digitalWrite(rgbPins[i], LOW);
  }
 
  Serial.begin(9600);
 
  Wire.begin();
  delay(1);  // Wait for ADJD reset sequence
  initADJD_S311();  // Initialize the ADJD-S311, sets up cap and int registers
 
  /* First we'll see the initial values
  getRGBC();  // Call this to put new RGB and C values into the colorData array
  printADJD_S311Values();  // Formats and prints all important registers of ADJD-S311
  */
  Serial.println("\nHold up a white object in front of the sensor, then press any key to calibrate...\n");
  while(!Serial.available())
    ;  // Wait till a key is pressed
  Serial.flush();
 
  Serial.println("\nCalibrating...this may take a moment\n");
  calibrateColor();  // This calibrates R, G, and B int registers
  calibrateClear();  // This calibrates the C int registers
  calibrateCapacitors();  // This calibrates the RGB, and C cap registers
  getRGBC();  // After calibrating, we can get the first RGB and C data readings
  printADJD_S311Values();  // Formats and prints all important ADJD-S311 registers
 
  Serial.println("\nAll values should be under 1000. If they're not, try calibrating again, or decreasing the ambient brightness somehow. ");
  Serial.println("\nPress SPACE to read, \"c\" to calibrate, \"o\" to get offset, \"l\" to go to LED mode");
}

void loop()
{
  while(!Serial.available())
    ;  // Wait till something's pressed
  char inKey = Serial.read();
 
  if (inKey == ' ')
  {  // If SPACE is pressed, get one reading and print it
    getRGBC();
    printADJD_S311Values();
  }
  else if (inKey == 'c')
  {  // If c is pressed, calibrate int and cap registers, then get a reading and print it
    Serial.println("\nCalibrating...\n");
    calibrateColor();
    calibrateClear();
    calibrateCapacitors();
    getRGBC();
    printADJD_S311Values();
  }
  else if (inKey == 'o')
  {  // if o is pressed, get the offset values
    getOffset();
    Serial.print("Offset: \t ");
    for (int i=0; i<4; i++)
    {
      Serial.print(colorOffset[i], DEC);
      Serial.print("\t ");
    }
    Serial.println();
  }
  else if (inKey == 'l')
  {  // if l is pressed, output color readings to an RGB LED
     // We'll assume the sensor is calibrated
    Serial.println("\nReplicating color on RGB LED, press any key to stop...\n");
    Serial.println("\t Red \t Green \t Blue");
    int averageData[3] = {0, 0, 0};  // We'll averaged the data
    while(!Serial.available())
    {  // Run continuously, until a key is pressed
      for (int i=0; i<4; i++)
      {  // Average the data four times
        getRGBC();  // Get data values
        for (int j=0; j<3; j++)
          averageData[i] += colorData[i];
      }
      for (int i=0; i<3; i++)
        averageData[i] /= 4;  // data averaging
       
      for (int i=0; i<3; i++)
      {  // print out the data, and send it to the RGB LED
        Serial.print("\t");
        Serial.print(averageData[i], DEC);
        analogWrite(rgbPins[i], map(averageData[i], 0, 1024, 0, 255)); 
      }
      Serial.println();
    }
    // When exiting this mode, turn off the RGB LED
    for (int i=0; i<3; i++)
      digitalWrite(rgbPins[i], LOW);
  }
  else
    Serial.println("\nPress SPACE to read, \"c\" to calibrate, \"o\" to get offset, \"l\" to go to LED mode");
  Serial.flush();
}

/* printADJD_S311Values() reads, formats, and prints all important registers
of the ADJD-S311.
It doesn't perform any measurements, so you'll need to call getRGBC() to print
new values.
*/
void printADJD_S311Values()
{
  Serial.println("\t\t Red \t Green \t Blue \t Clear");
  Serial.print("Data: \t\t ");
  for (int i=0; i<4; i++)
  {
    Serial.print(colorData[i]);
    Serial.print("\t ");
  }
  Serial.println();
  Serial.print("Caps: \t\t ");
  for (int i=0; i<4; i++)
  {
    Serial.print(readRegister(CAP_RED+i), DEC);
    Serial.print("\t ");
  }
  Serial.println();
  Serial.print("Int: \t\t ");
  for (int i=0; i<4; i++)
  {
    Serial.print(readRegisterInt(INT_RED_LO+(i*2)), DEC);
    Serial.print("\t ");
  }
  Serial.println();
  Serial.print("Offset: \t ");
  for (int i=0; i<4; i++)
  {
    Serial.print((signed char) readRegister(OFFSET_RED+i), DEC);
    Serial.print("\t ");
  }
  Serial.println();
}

/* initADJD_S311() - This function initializes the ADJD-S311 and its
capacitor and integration registers
The vaules for those registers are defined near the top of the code.
the colorCap[] array defines all capacitor values, colorInt[] defines
all integration values.
*/
void initADJD_S311()
{
  /*sensor gain registers, CAP_...
  to select number of capacitors.
  value must be <= 15 */
  writeRegister(colorCap[RED] & 0xF, CAP_RED);
  writeRegister(colorCap[GREEN] & 0xF, CAP_GREEN);
  writeRegister(colorCap[BLUE] & 0xF, CAP_BLUE);
  writeRegister(colorCap[CLEAR] & 0xF, CAP_CLEAR);

  /* Write sensor gain registers INT_...
  to select integration time
  value must be <= 4096 */
  writeRegister((unsigned char)colorInt[RED], INT_RED_LO);
  writeRegister((unsigned char)((colorInt[RED] & 0x1FFF) >> 8), INT_RED_HI);
  writeRegister((unsigned char)colorInt[BLUE], INT_BLUE_LO);
  writeRegister((unsigned char)((colorInt[BLUE] & 0x1FFF) >> 8), INT_BLUE_HI);
  writeRegister((unsigned char)colorInt[GREEN], INT_GREEN_LO);
  writeRegister((unsigned char)((colorInt[GREEN] & 0x1FFF) >> 8), INT_GREEN_HI);
  writeRegister((unsigned char)colorInt[CLEAR], INT_CLEAR_LO);
  writeRegister((unsigned char)((colorInt[CLEAR] & 0x1FFF) >> 8), INT_CLEAR_HI);
}

/* calibrateClear() - This function calibrates the clear integration registers
of the ADJD-S311.
*/
int calibrateClear()
{
  int gainFound = 0;
  int upperBox=4096;
  int lowerBox = 0;
  int half;
 
  while (!gainFound)
  {
    half = ((upperBox-lowerBox)/2)+lowerBox;
    //no further halfing possbile
    if (half==lowerBox)
      gainFound=1;
    else
    {
      writeInt(INT_CLEAR_LO, half);
      performMeasurement();
      int halfValue = readRegisterInt(DATA_CLEAR_LO);

      if (halfValue>1000)
        upperBox=half;
      else if (halfValue<1000)
        lowerBox=half;
      else
        gainFound=1;
    }
  }
  return half;
}

/* calibrateColor() - This function clalibrates the RG and B
integration registers.
*/
int calibrateColor()
{
  int gainFound = 0;
  int upperBox=4096;
  int lowerBox = 0;
  int half;
 
  while (!gainFound)
  {
    half = ((upperBox-lowerBox)/2)+lowerBox;
    //no further halfing possbile
    if (half==lowerBox)
    {
      gainFound=1;
    }
    else {
      writeInt(INT_RED_LO, half);
      writeInt(INT_GREEN_LO, half);
      writeInt(INT_BLUE_LO, half);

      performMeasurement();
      int halfValue = 0;

      halfValue=max(halfValue, readRegisterInt(DATA_RED_LO));
      halfValue=max(halfValue, readRegisterInt(DATA_GREEN_LO));
      halfValue=max(halfValue, readRegisterInt(DATA_BLUE_LO));

      if (halfValue>1000) {
        upperBox=half;
      }
      else if (halfValue<1000) {
        lowerBox=half;
      }
      else {
        gainFound=1;
      }
    }
  }
  return half;
}

/* calibrateCapacitors() - This function calibrates each of the RGB and C
capacitor registers.
*/
void calibrateCapacitors()
{
  int  calibrationRed = 0;
  int  calibrationBlue = 0;
  int  calibrationGreen = 0;
  int calibrated = 0;

  //need to store detect better calibration
  int oldDiff = 5000;

  while (!calibrated)
  {
    // sensor gain setting (Avago app note 5330)
    // CAPs are 4bit (higher value will result in lower output)
    writeRegister(calibrationRed, CAP_RED);
    writeRegister(calibrationGreen, CAP_GREEN);
    writeRegister(calibrationBlue, CAP_BLUE);

    // int colorGain = _calibrateColorGain();
    int colorGain = readRegisterInt(INT_RED_LO);
    writeInt(INT_RED_LO, colorGain);
    writeInt(INT_GREEN_LO, colorGain);
    writeInt(INT_BLUE_LO, colorGain);

    int maxRead = 0;
    int minRead = 4096;
    int red   = 0;
    int green = 0;
    int blue  = 0;
   
    for (int i=0; i<4 ;i ++)
    {
      performMeasurement();
      red   += readRegisterInt(DATA_RED_LO);
      green += readRegisterInt(DATA_GREEN_LO);
      blue  += readRegisterInt(DATA_BLUE_LO);
    }
    red   /= 4;
    green /= 4;
    blue  /= 4;

    maxRead = max(maxRead, red);
    maxRead = max(maxRead, green);
    maxRead = max(maxRead, blue);

    minRead = min(minRead, red);
    minRead = min(minRead, green);
    minRead = min(minRead, blue);

    int diff = maxRead - minRead;

    if (oldDiff != diff)
    {
      if ((maxRead==red) && (calibrationRed<15))
        calibrationRed++;
      else if ((maxRead == green) && (calibrationGreen<15))
        calibrationGreen++;
      else if ((maxRead == blue) && (calibrationBlue<15))
        calibrationBlue++;
    }
    else
      calibrated = 1;
     
    oldDiff=diff;

    int rCal = calibrationRed;
    int gCal = calibrationGreen;
    int bCal = calibrationBlue;
  }
 
}

/* writeInt() - This function writes a 12-bit value
to the LO and HI integration registers */
void writeInt(int address, int gain)
{
  if (gain < 4096)
  {
    byte msb = gain >> 8;
    byte lsb = gain;

    writeRegister(lsb, address);
    writeRegister(msb, address+1);
  }
}

/* performMeasurement() - This must be called before
reading any of the data registers. This commands the
ADJD-S311 to perform a measurement, and store the data
into the data registers.*/
void performMeasurement()

  writeRegister(0x01, 0x00); // start sensing
  while(readRegister(0x00) != 0)
    ; // waiting for a result
}

/* getRGBC() - This function reads all of the ADJD-S311's
data registers and stores them into colorData[]. To get the
most up-to-date data make sure you call performMeasurement()
before calling this function.*/
void getRGBC()
{
  performMeasurement();
 
  colorData[RED] = readRegisterInt(DATA_RED_LO);
  colorData[GREEN] = readRegisterInt(DATA_GREEN_LO);
  colorData[BLUE] = readRegisterInt(DATA_BLUE_LO);
  colorData[CLEAR] = readRegisterInt(DATA_CLEAR_LO);
}

/* getOffset() - This function performs the offset reading
and stores the offset data into the colorOffset[] array.
You can turn on data trimming by uncommenting out the
writing 0x01 to 0x01 code.
*/
void getOffset()
{
  digitalWrite(ledPin, LOW);  // turn LED off
  delay(10);  // wait a tic
  writeRegister(0x02, 0x00); // start sensing
  while(readRegister(0x00) != 0)
    ; // waiting for a result
  //writeRegister(0x01, 0x01);  // set trim
  //delay(100);
  for (int i=0; i<4; i++)
    colorOffset[i] = (signed char) readRegister(OFFSET_RED+i);
  digitalWrite(ledPin, HIGH);
}

/* I2C functions...*/
// Write a byte of data to a specific ADJD-S311 address
void writeRegister(unsigned char data, unsigned char address)
{
  Wire.beginTransmission(ADJD_S311_ADDRESS);
  Wire.send(address);
  Wire.send(data);
  Wire.endTransmission();
}

// read a byte of data from ADJD-S311 address
unsigned char readRegister(unsigned char address)
{
  unsigned char data;
 
  Wire.beginTransmission(ADJD_S311_ADDRESS);
  Wire.send(address);
  Wire.endTransmission();
 
  Wire.requestFrom(ADJD_S311_ADDRESS, 1);
  while (!Wire.available())
    ;  // wait till we can get data
 
  return Wire.receive();
}

// Write two bytes of data to ADJD-S311 address and addres+1
int readRegisterInt(unsigned char address)
{
  return readRegister(address) + (readRegister(address+1)<<8);
}

prehas po ba to sa gizmo color detect? nkha ko po to sa sparkfun web. tnx
"The truth of a theory is in your mind, not in your eyes."

Philippine Electronics Forum

Re: Egizmo Color detector not working!!!!
« Reply #3 on: January 25, 2013, 10:35:36 PM »

Offline insomartin

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 5484
  • Pogi/Ganda Points: 367
  • Gender: Male
  • Design, Engineer, Create electronics circuits.
Re: Egizmo Color detector not working!!!!
« Reply #4 on: January 25, 2013, 11:23:08 PM »
binasa mo ba kung anong color sensor meron ka talaga? kasi sa website nila...
http://www.e-gizmo.com/KIT/COLOR%20SENSOR.html
and yung ginagamit ko is TCS3471 color sensor chip.

ano bang nabili mo?

Philippine Electronics Forum

Re: Egizmo Color detector not working!!!!
« Reply #4 on: January 25, 2013, 11:23:08 PM »

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #5 on: January 25, 2013, 11:39:48 PM »
hindi ko maintindihan why would you take a code from certain site then expect it to work on a HW na nabili sa iba?

unless sa e-gizmo cd siguro nangaling yung code, there's no guarantee na magwowork yun, kahit sa egizmo cd nga galing code minsan di rin nagwowork...
8)

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #6 on: January 25, 2013, 11:56:01 PM »
@glutnix_neo sir nagpasend ako ng code keh sir tron kaso pang i2c accelerometer nmn sinend nya. nakita ko kasi sa sparkfun ung color dtctor  module nila eh halos parehas ng sa gzmo kya ngbakasakali akong gumana ung code eto po link >>https://www.sparkfun.com/products/10701
"The truth of a theory is in your mind, not in your eyes."

Offline sgboy

  • CR2032 Battery
  • **
  • Posts: 39
  • Pogi/Ganda Points: 25
Re: Egizmo Color detector not working!!!!
« Reply #7 on: January 26, 2013, 12:01:31 AM »
RK17. next time, check mong mabuti details before posting with a title something like this. hindi maganda para sa isang produkto yan.
hindi ung produckto ang not working. kundi ikaw.

well, reminder na din to para sa ating lahat....

Offline insomartin

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 5484
  • Pogi/Ganda Points: 367
  • Gender: Male
  • Design, Engineer, Create electronics circuits.
Re: Egizmo Color detector not working!!!!
« Reply #8 on: January 26, 2013, 12:13:48 AM »
sino ba si "SIR TRON" kung si e-tronics yan.. malamang working code ang binigay nya.
yung nasa sample code nang nasa e-gizmo is for accelerometer talaga.
but they modified it as a quick test code.

sana pa linaw kung sinong tao yung involved.

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #9 on: January 26, 2013, 12:25:59 AM »
@sgboy ok sori sir. mejo nadisappoint lng kasi ako sa naorder ko. nakadalawa na kasi akong module na nabili same result. kaya ko po natanong kung meh nakapagpagana na po. kung meron man sana po pashare para nmn po di magkaroon ng negative feedbak sa color detector ng gzmo. wala po kasing sample code na ksma ung cd. iba po kasi ung code na pangaccelerometer although same na i2c xa. kahit po chek nyu snd ko po sa email nyu. sir sgboy kung meh sample code po kau jan rgarding sa color detect i would really appreciate it kung maishashare po ninyu. The good thing kung maishashare po natin ung code masmarami pong kukuha sa product na to sa gizmo cause weve proved it working
"The truth of a theory is in your mind, not in your eyes."

Offline insomartin

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 5484
  • Pogi/Ganda Points: 367
  • Gender: Male
  • Design, Engineer, Create electronics circuits.
Re: Egizmo Color detector not working!!!!
« Reply #10 on: January 26, 2013, 12:51:04 AM »

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #11 on: January 26, 2013, 02:02:45 AM »
ayun oh! :D sir pashare naman po ng code please .  ;D kelangan ko po tlga para sa proj. namen. pliz sir kahit basic lng po.. +1 sir inso
"The truth of a theory is in your mind, not in your eyes."

Offline tiktak

  • Gas Turbine
  • **
  • Posts: 2885
  • Pogi/Ganda Points: 208
  • Gender: Male
    • Tiktakx's Blog
Re: Egizmo Color detector not working!!!!
« Reply #12 on: January 26, 2013, 09:01:07 AM »
the problem is lagi dependent sa sample code then copy paste
8051 stuff

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #13 on: January 26, 2013, 10:04:45 AM »
@sgboy ok sori sir. mejo nadisappoint lng kasi ako sa naorder ko. nakadalawa na kasi akong module na nabili same result. kaya ko po natanong kung meh nakapagpagana na po. kung meron man sana po pashare para nmn po di magkaroon ng negative feedbak sa color detector ng gzmo. wala po kasing sample code na ksma ung cd. iba po kasi ung code na pangaccelerometer although same na i2c xa. kahit po chek nyu snd ko po sa email nyu. sir sgboy kung meh sample code po kau jan rgarding sa color detect i would really appreciate it kung maishashare po ninyu. The good thing kung maishashare po natin ung code masmarami pong kukuha sa product na to sa gizmo cause weve proved it working

again as mention by sgboy, hindi yung color detector ang not working, bakit ka magbibigay ng negative feedback sa kanila? tatawanan ka lang ng mga nakakabasa...

have you googled the IC? may datasheet yan na pwede mo matutunan kung paano magcommunicate then yung sample code from tron using I2C should be enough..


papost naman po nung sample code from TRON para makilatis din...
8)

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #14 on: January 26, 2013, 10:14:48 AM »
@glutnix_neo sir nagpasend ako ng code keh sir tron kaso pang i2c accelerometer nmn sinend nya. nakita ko kasi sa sparkfun ung color dtctor  module nila eh halos parehas ng sa gzmo kya ngbakasakali akong gumana ung code eto po link >>https://www.sparkfun.com/products/10701

Ang layo pre, as in miles away... sa perspective na board layout at schematic, ibang iba...





positioning na lang ng header at number of pins iba na eh...

pati name magkaiba, nagkapareho lang sila eh sa word na color 
"Color Light Sensor" yung isa eh "Color Detector"
8)

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #15 on: January 26, 2013, 11:40:37 AM »
lets be honest ndi naman lahat ng codes eh nanggagaling sa utak naten lalo na kung 1st tym naten gamitin ang isang bagay.  Kung bumili ka nga ng  gamit o gadget na bago diba laging meh kasama syang manual? kasi ung gumawa lang ang nakakaalam. Same case dto all im asking is basic code lng which shows how the color detector communicates with the serial port. Kung wala kaung maishare edi wag nalang kaung magreply kasi sayang lng pagod nyu sa pagtype. @sir insomartin maraming salamat sa video really appreciate it na pinakita nyung gumagana sya. Ok na po un try ko nlng pong pag aralan ng mabuti ung code.  For the meantime eto muna po ang gagamitin kong color detector hanggang sa mapagana ko ung  detector ng gizmo slmat sir!

 
"The truth of a theory is in your mind, not in your eyes."

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #16 on: January 26, 2013, 11:44:21 AM »
there are things kasi na inaassume ng manufacturer na dapat alam mo na...

for example sa mouse, hindi na sasabihin ng manual alin ang right at left click button(kung may extra buttons possible pa)...


sa case ng color sensor, inassume siguro ng e-gizmo na maalam ka naman siguro magbasa ng datasheet at schematic diagram... dahil kung hindi, baka di ka nababagay sa field na kinuha mo... and you should be using a color sensor in the first place  ;D ;D ;D

(Mas grabe term ng mga hackers dyan, RTFM)
8)

Offline nympha

  • Size C Battery
  • *****
  • Posts: 226
  • Pogi/Ganda Points: 6
  • nympha
Re: Egizmo Color detector not working!!!!
« Reply #17 on: January 26, 2013, 12:13:25 PM »
@glutnix_neo un nga po ung pinopoint out ko na wala po sa manual na bngay ng gzmo ung code.Meh manual pero walang sample code.  Kung meron lang edi sana ndi na po ako ngpost sir.  Eto po ung code na sinend saken
Code: [Select]
#include <I2C.h>

#define __AVR_ATmega328P__

#include <Arduino.h>
#include <math.h>

//<editor-fold defaultstate="collapsed" desc="PIN Defenitions">
const int PIN_GYRO_X = 0; //analog 0
const int PIN_GYRO_Z = 1; //analog 1

const int PIN_MOTOR_1 = 3;
const int PIN_MOTOR_2 = 5;

const int PIN_MODE_SWITCH = 2;
const int PIN_MODE_LED = 13;
const int BACK_LED = 7;
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Accelerometer Register Defenitions">
const byte COMMAND = 0x80; //(W) Real time status
const byte REPEATED_BYTE = 0x00; //(W) Real time status
const byte AUTO_INC = 0x20; //(W) Real time status
const byte SPECIAL_FUNC = 0x60; //(W) Real time status
const byte RGBC_INT_CLR = 0x06; //(W) Real time status

const byte REG_ENABLE = 0x00; //(R/W) Real time status
const byte REG_ATIME = 0x01; //(R/W) [7:0] are 8 MSBs of 10-bit sample
const byte REG_WTIME = 0x03; //(R/W) [7:6] are 2 LSBs of 10-bit sample
const byte REG_AILTL = 0x04; //(R/W) [7:6] are 2 LSBs of 10-bit sample
const byte REG_AILTH = 0x05; //(R/W) [7:0] are 8 MSBs of 10-bit sample
const byte REG_AIHTL = 0x06; //(R/W) [7:6] are 2 LSBs of 10-bit sample
const byte REG_AIHTH = 0x07; //(R/W) [7:6] are 2 LSBs of 10-bit sample
const byte REG_PERS = 0x0C; //(R/W) Interrupt status
const byte REG_CONFIG = 0x0D; //(R/W) Device ID (0x3A)
const byte REG_CONTROL = 0x0F; //(R/W) cut-off frequency is set to 16Hz @ 800Hz
const byte REG_ID = 0x12; //(R) Landscape/Portrait debounce counter
const byte REG_STATUS = 0x13; //(R) Back-Front, Z-Lock trip threshold
const byte REG_CDATA = 0x14; //(R) Portrait to Landscape trip angle is 29 degree
const byte REG_CDATAH = 0x15; //(R) Freefall/motion functional block configuration
const byte REG_RDATA = 0x16; //(R) Freefall/motion event source register
const byte REG_RDATAH = 0x17; //(R) Freefall/motion threshold register
const byte REG_GDATA = 0x18; //(R) Freefall/motion debounce counter
const byte REG_GDATAH = 0x19; //(R) Transient functional block configuration
const byte REG_BDATA = 0x1A; //(R) Transient event status register
const byte REG_BDATAH = 0x1B; //(R) Transient event threshold

const byte I2C_ADDR = 0x29;
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Accelerometer Scale Defenitions">
const byte FULL_SCALE_RANGE_2g = 0x0;
const byte FULL_SCALE_RANGE_4g = 0x1;
const byte FULL_SCALE_RANGE_8g = 0x2;
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Wheel Directions">
//jenum WheelDirection {
const byte DIR_FORWARD = 0x01;
const byte DIR_BACKWARD = 0x02;
const byte DIR_STOP = 0x00;
//};
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Gyro initial value">
float GYRO_X_INIT_VAL = 450.0;
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Other Constants"> */
//gyro: 500 dps
//acc: 2g -256,256
const float INIT_ANGLE = -0.005;
const int ANGLE_BUFFER_LENGTH = 3;
const float SumErrMax = 3;
const float SumErrMin = -3;
//</editor-fold>

// <editor-fold defaultstate="collapsed" desc="Global Variables">
unsigned int CDATA = 0, RDATA = 0, GDATA = 0, BDATA = 0;
int VxGyro = 0, VzGyro = 0;
byte STAT;
byte ID;

float degX = 0.0f, degY = 0.0f, degZ = 0.0f;
float throttle = 0.0;

float accAngle = 0.0, currAngle = 0.0, prevAngle = 0.0, elapsedTimeSec=0.0;
unsigned long prevTimeStamp = 0, currTimeStamp = 0, elapsedTime = 0;
boolean isFirstTime = false;

float angleBuffer[ANGLE_BUFFER_LENGTH];
int angleBufferIndex = 0;

boolean MotorOff = false;

float curErr = 0, prevErr = 0, SumErr = 0;
float integralTerm = 0, derivativeTerm = 0;
float Kp = 30000.0, Ki = 50000,  Kd = 500;
float Cn = 0;
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Accelerometer Functions">

/*
  Read register content into buffer.
  The default count is 1 byte.
 
  The buffer needs to be pre-allocated
  if count > 1
 */
void regRead(byte reg, byte *buf, byte count = 1) {
  byte command;
  command = COMMAND | AUTO_INC | reg;
    I2c.write(I2C_ADDR, command);
    I2c.read(I2C_ADDR, reg, count);

    for (int i = 0; i < count; i++)
        *(buf + i) = I2c.receive();
}

/*
  Write a byte value into a register
 */
void regWrite(byte reg, byte val) {
  byte command;
  command = COMMAND | AUTO_INC | reg;
    I2c.write(I2C_ADDR, command, val);
}

/*
  Put MMA8453Q into standby mode
 */
void standbyMode() {
    byte reg;
    byte activeMask = 0x01;

//    regRead(REG_CTRL_REG1, &reg);
//    regWrite(REG_CTRL_REG1, reg & ~activeMask);
}

/*
  Put MMA8453Q into active mode
 */
void activeMode() {
    byte reg;
    byte activeMask = 0x01;

//    regRead(REG_CTRL_REG1, &reg);
//    regWrite(REG_CTRL_REG1, reg | activeMask);
}

/*
  Use fast mode (low resolution mode)
  The acceleration readings will be
  limited to 8 bits in this mode.   
 */
void lowResMode() {
    byte reg;
    byte fastModeMask = 0x02;

//    regRead(REG_CTRL_REG1, &reg);
//    regWrite(REG_CTRL_REG1, reg | fastModeMask);
}

/*
  Use default mode (high resolution mode)
  The acceleration readings will be
  10 bits in this mode.   
 */
void hiResMode() {
    byte reg;
    byte fastModeMask = 0x02;

//    regRead(REG_CTRL_REG1, &reg);
//    regWrite(REG_CTRL_REG1, reg & ~fastModeMask);
}

/*
  get accelerometer readings (x, y, z)
  by default, standard 10 bits mode is used.
 
  if accelerometer is initialized to use low res mode,
  isHighRes must be passed in as false.
 */
void getAccXYZ(unsigned int *C, unsigned int *R, unsigned int *G, unsigned int *B) {
    byte buf[8];

    digitalWrite(PIN_MODE_LED, HIGH);
    regRead(REG_STATUS, buf, 1);
    STAT = buf[0];
    regRead(REG_ID, buf, 1);
    ID = buf[0];
    regRead(REG_CDATA, buf, 8);
    *C = buf[0] << 8 | buf[1];
    *R = buf[2] << 8 | buf[3];
    *G = buf[4] << 8 | buf[5];
    *B = buf[6] << 8 | buf[7];

//    if (*x > 8191) *x = *x - 16384;
//    if (*y > 8191) *y = *y - 16384;
//    if (*z > 8191) *z = *z - 16384;
    digitalWrite(PIN_MODE_LED, LOW);
}

//</editor-fold>

// <editor-fold defaultstate="collapsed" desc="Calibrate Gyro">

float CalGyro() {
    float val = 0.0;
    digitalWrite(PIN_MODE_LED, HIGH);
    delay(500);
    for (int i = 0; i < 25; i++) {
        val += analogRead(PIN_GYRO_X);
        delay(10);
    }

    val /= 25.0;

//    Serial.print("GyroX Stationary=");
//    Serial.println(val);
    digitalWrite(PIN_MODE_LED, LOW);

    return val;
}// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Angle estimation">
float GetAvgAngle() {
    int count = 0;
    float a = 0;

    for (int i = 0; i < ANGLE_BUFFER_LENGTH; i++) {
        if (angleBuffer[i] != 0) {
            count++;
            a += angleBuffer[i];
        }
    }

    if (count > 0)
        return a / float(count);
    else
        return 0.0;
}

float GetAccAngle() {
    getAccXYZ(&CDATA, &RDATA, &GDATA, &BDATA);

//    float r = sqrt((float) VzAcc * (float) VzAcc + (float) VyAcc * (float) VyAcc);
//    accAngle = (float) VzAcc / r; //approximates sine

    return accAngle;
}

float EstimateAngle() {
    currTimeStamp = micros();
    elapsedTime = currTimeStamp - prevTimeStamp;
    prevTimeStamp = currTimeStamp;

    elapsedTimeSec = (float) elapsedTime / 1e6f;

    float angle = GetAccAngle();
    if (isFirstTime) {
        currAngle = angle;
        isFirstTime = false;
    } else {
        VxGyro = analogRead(PIN_GYRO_X);
        degX = (float) (VxGyro - GYRO_X_INIT_VAL) * 3300.0f / 512.0f / 180.0f * (float) elapsedTimeSec;
        currAngle = 0.95 * (prevAngle + degX) + 0.05 * angle;
    }

    prevAngle = currAngle;

//    if (MotorOff) { //for debugging purposes
//        Serial.print("\tcurrAngleAvg=");
//        Serial.print(GetAvgAngle(), 4);
//        Serial.print("\tcurrAngle=");
//        Serial.print(currAngle, 4);
//        Serial.print("\taccAngle=");
//        Serial.print(accAngle);
//        Serial.print("\tgyroAngle=");
//        Serial.print(degX);
//        Serial.print("\tVxGyro=");
//        Serial.print(VxGyro);
//        Serial.print("\telapsedTime=");
//        Serial.print(elapsedTime);
        Serial.print("\tID = ");
        Serial.print(ID);
        Serial.print("\tSTATUS = ");
        Serial.print(STAT);
        Serial.print("\tC_DATA = ");
        Serial.print(CDATA);
        Serial.print("\tR_DATA = ");
        Serial.print(RDATA);
        Serial.print("\tG_DATA = ");
        Serial.print(GDATA);
        Serial.print("\tB_DATA = ");
        Serial.println(BDATA);
        delay(1000);
//    }

    return currAngle;
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Drive">
void MoveWheels(byte dir, int speed) {
    if (MotorOff) return;

    if (speed > 255) speed = 255;
    else if (speed < 0) speed = 0;

    if (dir == DIR_STOP) {
        digitalWrite(PIN_MOTOR_1, LOW);
        digitalWrite(PIN_MOTOR_2, LOW);
    } else if (dir == DIR_FORWARD) {
        digitalWrite(PIN_MOTOR_2, LOW);
        analogWrite(PIN_MOTOR_1, speed);
    } else if (dir == DIR_BACKWARD) {
        digitalWrite(PIN_MOTOR_1, LOW);
        analogWrite(PIN_MOTOR_2, speed);
    }
}
// </editor-fold>

void setup() {
    I2c.begin();
    Serial.begin(9600);

//    standbyMode(); //register settings must be made in standby mode
//    regWrite(REG_XYZ_DATA_CFG, FULL_SCALE_RANGE_2g);
//    hiResMode();
//    activeMode();
    regWrite(REG_ENABLE, 0x03);

    pinMode(PIN_MOTOR_1, OUTPUT);
    pinMode(PIN_MOTOR_2, OUTPUT);

    digitalWrite(PIN_MOTOR_1, LOW);
    digitalWrite(PIN_MOTOR_2, LOW);

    pinMode(PIN_MODE_LED, OUTPUT);
    pinMode(BACK_LED, OUTPUT);

    pinMode(PIN_MODE_SWITCH, INPUT);
    digitalWrite(PIN_MODE_SWITCH, HIGH);

//    Serial.print("Motor is ");
    if (digitalRead(PIN_MODE_SWITCH) == HIGH) {
        MotorOff = true;
//        Serial.println("OFF");
    }
    else {
        MotorOff = false;
//        Serial.println("ON");
    }

    byte b;
//    regRead(REG_WHO_AM_I, &b);
//    Serial.println(b, HEX);

    for (int i = 0; i < ANGLE_BUFFER_LENGTH; i++) angleBuffer[i] = 0;

    GYRO_X_INIT_VAL = CalGyro();
    digitalWrite(BACK_LED, HIGH);
}

void loop() {
    float a = EstimateAngle() - INIT_ANGLE;

    angleBuffer[angleBufferIndex] = a;
    angleBufferIndex = (angleBufferIndex + 1) % ANGLE_BUFFER_LENGTH;
    float ang = GetAvgAngle();
    byte dir;

    curErr = ang - INIT_ANGLE; //error   
    SumErr += curErr;
   
    if (SumErr > SumErrMax) SumErr = SumErrMax;
    else if (SumErr < SumErrMin) SumErr = SumErrMin;
   
    //Ki*SumE/(Kp*Fs*X)
    integralTerm = SumErr * elapsedTimeSec * Ki / Kp * 10.0;
    derivativeTerm = curErr - prevErr;
   
    if(derivativeTerm > 0.1) derivativeTerm = 0.1;
    else if (derivativeTerm < -0.1) derivativeTerm = -0.1;
   
    // Kd(curErr-prevErr)*Ts/(Kp*X)
    derivativeTerm = derivativeTerm * Kd * elapsedTimeSec / Kp;
   
    if(derivativeTerm > 120) derivativeTerm = 120;
    else if (derivativeTerm < -120) derivativeTerm = -120;
   
    Cn = (curErr + integralTerm + derivativeTerm) * Kp / 10.0;
//    Serial.println(Cn);
//    WheelDirection dir;
   
    if (Cn > 0) dir = DIR_FORWARD;
    else if (Cn < -0) dir = DIR_BACKWARD;
    else dir = DIR_STOP;
       
    throttle = abs(Cn);
       
    if (abs(ang) > 0.7)  MoveWheels(DIR_STOP, 0); //if angle too large to correct, stop motor       
    else MoveWheels(dir, throttle);
   
    prevErr = curErr;
}

*eto nmn po ung connections based sa manual.


*Notice ung pin connections eh hindi nag coincide sa pin config sa program
Code: [Select]
const int PIN_GYRO_X = 0; //analog 0
const int PIN_GYRO_Z = 1; //analog 1

const int PIN_MOTOR_1 = 3;
const int PIN_MOTOR_2 = 5;

const int PIN_MODE_SWITCH = 2;
const int PIN_MODE_LED = 13;
const int BACK_LED = 7;

"The truth of a theory is in your mind, not in your eyes."

Offline alyas

  • Hydroelectric
  • ***
  • Posts: 3091
  • Pogi/Ganda Points: 209
Re: Egizmo Color detector not working!!!!
« Reply #18 on: January 26, 2013, 12:38:35 PM »
matagal ko ng iniisip anong practical application ang meron sa color detector/sensor na non-manufacturing related?

@ts,  I checked the cd from egizmo and you are right  ... it seems the code is originally for the accelerometer.  Siguro parehong i2c ang interface.  It seems to be a quick edit (w/o changing the rest of the code) just to show the color sensor is working.  Irregardless if the results is accurate or not, you should be getting something out of the serial port.   

Have you selected the correct baud rate settings ng serial port?

Offline glutnix_neo

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6017
  • Pogi/Ganda Points: 192
  • Gender: Female
  • Useless
    • Underground Workbench
Re: Egizmo Color detector not working!!!!
« Reply #19 on: January 26, 2013, 12:43:16 PM »
eto baka makatulong...

Code: [Select]
// http://www.ams.com/eng/content/download/250256/975981/file/TCS3471.pdf&ei=tQLPT7zCJq_HmQXh4ZXECg&usg=AFQjCNEKWWRLEthxn5_X2M_AiTThoC-JvQ
// http://www.i2cprotocol.com/
// http://arduino.cc/en/Reference/Wire
8)

Philippine Electronics Forum

Re: Egizmo Color detector not working!!!!
« Reply #19 on: January 26, 2013, 12:43:16 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com