[m3pi] Interacting with Paralax ColorPAL

I have been unable to successfully incorporate http://mbed.org/forum/mbed/topic/2018/ into my program. I am trying to use the Paralax ColorPAL with mbed in the m3pi. I was wondering if anyone was sure on how to use this code snippet properly/interface with the ColorPAL which uses a 1-pin serial interface.

Hello.

Can you please post the simplest code that causes your problems, or share it with the mbed website, and tell us what error messages you are getting, or what behavior you are expecting and what behavior you are actually seeing?

- Ryan

Hi, sorry for not replying earlier I haven’t had access to a working computer (or rather working laptop charger) in about a week.

This code doesn’t make specific use of the code snippet but it still fails to compile with it in it.

#include "mbed.h"
 
Serial pc(USBTX, USBRX);
SerialHalfDuplex RGB_master(p9, p10); // this is the color sensor 
 
DigitalOut pc_activity(LED1);
DigitalOut RGB_master_activity(LED2);

 // RGB comm rate
     RGB_master.baud(2400);
     RGB_master.format(8,Serial::None,2); 
 
 // To Read and format as 24 bit RGB in 32 bits
     RGB_master.putc('=');
     RGB_master.putc('m');
     RGB_master.putc('!');
     
     c1=RGB_master.getc(); // R
     if((c1-'A') >= 0) color = c1-'A'; else color = c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();  // discard since we have 8 bits of color
     
     
     c1=RGB_master.getc(); // G
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color
     
     c1=RGB_master.getc(); // B
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color 
int main() {
     pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
     RGB_master.putc('=');
     RGB_master.putc('R');
     RGB_master.putc('!');
    while(1) {
        if(pc.readable()) {
            RGB_master.putc(pc.getc());
            pc_activity = !pc_activity;
        }
        if(RGB_master.readable()) {
            pc.putc(RGB_master.getc());
            RGB_master_activity = !RGB_master_activity;
        }
    }
}

Only saying something fails to compile is not very useful. If you don’t post the entire error message, it is usually hard to help. In this case, it looks like you have a bunch of code that is not inside of a method, which is not allowed in C++. The code below the comment “// RGB comm rate” needs to go inside the main method.

- Ryan

Okay, thanks and I have fixed the code (so that it compiles).

#include "mbed.h"

Serial pc(USBTX, USBRX);

DigitalOut pc_activity(LED1);
DigitalOut RGB_master_activity(LED2);
SerialHalfDuplex RGB_master(p9, p10); // this is the color sensor 
int color;
int c1;

int main() {
 
 // RGB comm rate
     RGB_master.baud(2400);
     RGB_master.format(8,Serial::None,2); 
 
 // To Read and format as 24 bit RGB in 32 bits
     RGB_master.putc('=');
     RGB_master.putc('m');
     RGB_master.putc('!');
     
     c1=RGB_master.getc(); // R
     if((c1-'A') >= 0) color = c1-'A'; else color = c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();  // discard since we have 8 bits of color
     
     
     c1=RGB_master.getc(); // G
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color
     
     c1=RGB_master.getc(); // B
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc();
     if((c1-'A') >= 0) color += c1-'A'; else color += c1-'0';
     color = color << 4;
     c1=RGB_master.getc(); // discard since we have 8 bits of color 
    while(1) {
        if(pc.readable()) {
            RGB_master.putc(pc.getc());
            pc_activity = !pc_activity;
        }
        if(RGB_master.readable()) {
            pc.putc(RGB_master.getc());
            RGB_master_activity = !RGB_master_activity;
        }
    }
}

Although even with that code I am unable to do anything as of yet (unless you count making it print pinmap not found to pc) as nothing is recieved and it doesn’t respond to simple commands like “=R!” (make rgb led red).

It is not clear to me what problem you are having. For example, what do you mean when you refer to “pinmap not found to pc”? For me to help you, you need to describe your problem fully. What is happening and what are you expecting to happen?

Also, if you are trying to control the LED, you should try a much simpler program first. I have not tested this, but something like:

#include "mbed.h"
SerialHalfDuplex RGB_master(p9, p10); // this is the color sensor 
int main() {
// RGB comm rate
     RGB_master.baud(2400);
     RGB_master.format(8,Serial::None,2); 
// To Read and format as 24 bit RGB in 32 bits
     RGB_master.putc('=');
     RGB_master.putc('R');
     RGB_master.putc('!'); 
}

- Ryan

By using pin 9 for TX and RX I can make it say “pinmap not found” on the pc side. And I will try that code but I ultimately want to read colour sensor readings.