ColorPAL arduino problem >.<

2»

Comments


  • I wired up two pines en parrallel with resistor of 2kohms [img][/img]

    could you show me your code
  • It's in this thread a few posts before my last one.
  • HELLO MARTIN I THINK THAT THIS IS YOUR CODE, SO DOESNT WORK ME, SO WHEN RUN YOUR CODE ITS OK, BUT ON SERIAL PORT DOESNT SHOW ME ANYTHING


    /* ColorPal Sensor Example for Arduino
    Author: Martin Heermance, with some assistance from Gordon McComb
    This program drives the Parallax ColorPAL color sensor and provides
    serial RGB data in a format compatible with the PC-hosted
    TCS230_ColorPAL_match.exe color matching program.
    */

    #include <SoftwareSerial.h>

    #define sio 6 // ColorPAL connected to pin 6
    #define unused 255 // Non-existant pin # for SoftwareSerial
    #define sioBaud 4800

    // Received RGB values from ColorPAL
    int red;
    int grn;
    int blu;

    // Set up two software serials on the same pin.
    SoftwareSerial serin(sio, unused);
    SoftwareSerial serout(unused, sio);

    void setup(){
    reset();


    Serial.begin(9600);
    // Send reset to ColorPal
    serout.begin(sioBaud);
    pinMode(sio, OUTPUT);
    serout.print("=(00 $ m)!"); // Loop print values, see ColorPAL documentation
    serout.end(); // Discontinue serial port for transmitting

    pinMode(sio, INPUT);
    serin.begin(sioBaud); // Set up serial port for receiving
    }

    void loop() {
    readData();
    }

    // Reset ColorPAL; see ColorPAL documentation for sequence
    void reset() {
    delay(200);
    pinMode(sio, OUTPUT);
    digitalWrite(sio, LOW);
    pinMode(sio, INPUT);
    while (digitalRead(sio) != HIGH);
    pinMode(sio, OUTPUT);
    digitalWrite(sio, LOW);
    delay(80);
    pinMode(sio, INPUT);
    delay(200);
    }

    void readData() {
    char buffer[32];

    if (serin.available() > 0) {
    // Wait for a $ character, then read three 3 digit hex numbers
    buffer[0] = serin.read();
    if (buffer[0] == '$') {
    for(int i = 0; i < 9; i++) {
    while (serin.available() == 0); // Wait for next input character
    buffer = serin.read();
    if (buffer == '$') // Return early if $ character encountered
    return;
    }
    parseAndPrint(buffer);
    delay(10);
    }
    }
    }

    // Parse the hex data into integers
    void parseAndPrint(char * data) {
    sscanf (data, "%3x%3x%3x", &red, &grn, &blu); // Pull the R, G, and B values from the data string

    char buffer[48]; // create a buffer
    sprintf(buffer, "r = %4.4d g = %4.4d b = %4.4d", red, grn, blu); //print the values into a buffer as formatted integers
    Serial.println(buffer);
    }
  • Make sure you connect the colorPal data pin to pin 6 on the Arduino. You only need a single wire since the colorPal is half duplex.
  • yes i connect to colorPal with pin 6(digital pin 6) on arduino, its ok, so im using resistor of 2k in parallel with pin 6
  • masalcido wrote: »
    yes i connect to colorPal with pin 6(digital pin 6) on arduino, its ok, so im using resistor of 2k in parallel with pin 6

    You can not post the same questions in two threads. Please pick one and stick with that thread.


    Infernal Machine
  • masalcido wrote: »
    yes i connect to colorPal with pin 6(digital pin 6) on arduino, its ok, so im using resistor of 2k in parallel with pin 6

    I am not sure what you mean by using a 2k resistor in parallel. Do you mean a pull up resistor?
  • Hi, I'm currently working on creating a prototype for a sensor module that uses ColorPAL (#28380). I used the example code by Martin Heermance and did a minor modification to the code; specifically changing the serout.print("= (00 $ m) !") line to serout.print("= (00 $ m) #00"). So my code looked like this when I first ran it:

    #include <SoftwareSerial.h>

    const int sio = 2; // ColorPAL connected to pin 2
    const int unused = 255; // Non-existant pin # for SoftwareSerial
    const int sioBaud = 4800;
    const int waitDelay = 200;

    // Received RGB values from ColorPAL
    int red;
    int grn;
    int blu;

    // Set up two software serials on the same pin.
    SoftwareSerial serin(sio, unused);
    SoftwareSerial serout(unused, sio);

    void setup() {

    Serial.begin(9600);
    reset(); // Send reset to ColorPal
    serout.begin(sioBaud);
    pinMode(sio, OUTPUT);
    serout.print("=(00 $ m) #00"); // Loop print values, see ColorPAL documentation
    serout.end(); // Discontinue serial port for transmitting

    serin.begin(sioBaud); // Set up serial port for receiving
    pinMode(sio, INPUT);
    }

    void loop() {
    readData();
    }

    // Reset ColorPAL; see ColorPAL documentation for sequence
    void reset() {
    //delay(200);
    Serial.println("Reset ColorPal");
    pinMode(sio, OUTPUT);
    digitalWrite(sio, LOW);
    pinMode(sio, INPUT);
    while (digitalRead(sio) != HIGH);
    pinMode(sio, OUTPUT);
    digitalWrite(sio, LOW);
    delay(80);
    pinMode(sio, INPUT);
    delay(waitDelay);
    }

    void readData() {
    char buffer[32];

    if (serin.available() > 0) {
    // Wait for a $ character, then read three 3 digit hex numbers
    buffer[0] = serin.read();
    if (buffer[0] == '$') {
    for(int i = 0; i < 9; i++) {
    while (serin.available() == 0); // Wait for next input character
    buffer = serin.read();
    if (buffer == '$') // Return early if $ character encountered
    return;
    }
    parseAndPrint(buffer);
    delay(10);
    }
    }
    }

    // Parse the hex data into integers
    void parseAndPrint(char * data) {
    sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
    char buffer[32];
    sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
    Serial.println(buffer);
    }


    However, I want to change the settings of the sensor to increase the amount of time the LED takes to transit between shining different colors, and I haven't been able to reprogram the sensor ever since. It behaves the exact same way it did when the code above was programmed into the sensor initially.

    Some of the variations that I've tried includes (Only this portion of the code had been modified, the rest of the code was kept the same as it is in the example code above):

    void setup() {

    Serial.begin(9600);
    reset(); // Send reset to ColorPal
    serout.begin(sioBaud);
    pinMode(sio, OUTPUT);
    serout.print("= R pC8 !"); //Just to see whether the sensor responds to the change in commands but it continues to flash 3 different colors in sequence
    serout.end(); // Discontinue serial port for transmitting

    serin.begin(sioBaud); // Set up serial port for receiving
    pinMode(sio, INPUT);
    }

    I have read the datasheet and it told me that the EEPROM of the sensor has limited capacity and can only store information up to 64 bytes. I suspect that when I used the first code (serout.print("=(00 $ m) #00"), the EEPROM was filled up and thus it could not take in new instructions. May I also know how to rewrite the EEPROM of the sensor? I tried serout.print("= R pC8 #00") but it did not work.
  • Try saving a blank program in EEPROM first to erase what's there.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
Sign In or Register to comment.