Shop OBEX P1 Docs P2 Docs Learn Events
(Catalina) printf, serial output, i2c — Parallax Forums

(Catalina) printf, serial output, i2c

allaiksallaiks Posts: 8
edited 2011-09-08 23:49 in Propeller 1
Hello,

I have the "Propeller demo board" from Parallax, I feel comfortable using the c language and would like to use Catalina to achieve some projects.

But I don't have a tv screen, nor a vga screen, nor a keyboard, nor a mouse, dedicated to my projects, and I'm not planning to have this extra equipment.

I'm would like to use the serial line (connected to the PC and used to transfer the binaries) as the output of printf to display all sorts of data I need.

How can I do this with Catalina? Is there a terminal?

Now another question about serial communications:

Let's imagine I would like to make the Propeller communicate with some other modules which can only use serial synchronous or also asynchronous communications.

Is there an easy way to do this with with Catalina ? (a library, an example, a built in function, anything)
Just like with basic stamps serout, serin, etc.

Same question but with i2c ?
On the pins connected to the eeprom and also on any pin I'd like.

Finally, I'm not yet very familiar with the propeller yet, I have only done the complete tutorial in the help file of the "Propeller Tool" from Parallax, which is a good demonstration of the possibilities of the chip and the Spin. But I'm not comfortable with the new Spin language. I'd love to use C with this great chip, and Catalina seem to offer multi-threading, a standard c math library, and the ability to store files. To help you evaluate my knowledge for your answer, I'm a C/C++ developer on various platforms (Windows, Solaris, Mac, Linux, BSD, Microchip), and I have also developed on Parallax Javelin Stamps and Basic Stamps.

Thanks in advance for your help.

Comments

  • RossHRossH Posts: 5,549
    edited 2011-09-08 20:17
    allaiks wrote: »
    Hello,

    I have the "Propeller demo board" from Parallax, I feel comfortable using the c language and would like to use Catalina to achieve some projects.

    But I don't have a tv screen, nor a vga screen, nor a keyboard, nor a mouse, dedicated to my projects, and I'm not planning to have this extra equipment.

    I'm would like to use the serial line (connected to the PC and used to transfer the binaries) as the output of printf to display all sorts of data I need.

    How can I do this with Catalina? Is there a terminal?

    Now another question about serial communications:

    Let's imagine I would like to make the Propeller communicate with some other modules which can only use serial synchronous or also asynchronous communications.

    Is there an easy way to do this with with Catalina ? (a library, an example, a built in function, anything)
    Just like with basic stamps serout, serin, etc.

    Same question but with i2c ?
    On the pins connected to the eeprom and also on any pin I'd like.

    Finally, I'm not yet very familiar with the propeller yet, I have only done the complete tutorial in the help file of the "Propeller Tool" from Parallax, which is a good demonstration of the possibilities of the chip and the Spin. But I'm not comfortable with the new Spin language. I'd love to use C with this great chip, and Catalina seem to offer multi-threading, a standard c math library, and the ability to store files. To help you evaluate my knowledge for your answer, I'm a C/C++ developer on various platforms (Windows, Solaris, Mac, Linux, BSD, Microchip), and I have also developed on Parallax Javelin Stamps and Basic Stamps.

    Thanks in advance for your help.

    Hello allaiks,

    To use Catalina with a PC terminal emulator, you just define the PC symbol when linking your program. This works with the standard Parallax Serial Terminal, or with any other terminal emulator. To define this symbol on the command line just add -D PC to your command (the -D just means "define"). Since you have a Demo board, a complete command might look something like this (note that case is significant - so -D PC is not the same as -d PC or -D pc):
    catalina hello_world.c -lc -D DEMO -D PC
    
    From Code::Blocks, you can do exactly the same thing - just go to Project->Build Options and select the PC option from the list of available HMI options, and the DEMO board from the list of available platforms.

    As to your other questions, do you want a serial port in addition to the one you use as the HMI? There is no "out of the box" plugin to add another serial port - but with Catalina 3.1 you can now add your own serial port driver (or I2c driver) using any of the standard OBEX drivers - for examples on how to use an OBEX driver in Catalina, see the examples in the demos\spinc folder.

    If you get stuck, just ask here in the forums (or send me a message).

    Ross.
  • allaiksallaiks Posts: 8
    edited 2011-09-08 21:19
    RossH wrote: »
    To use Catalina with a PC terminal emulator, you just define the PC symbol when linking your program. This works with the standard Parallax Serial Terminal, or with any other terminal emulator. To define this symbol on the command line just add -D PC to your command (the -D just means "define"). Since you have a Demo board, a complete command might look something like this (note that case is significant - so -D PC is not the same as -d PC or -D pc):
    catalina hello_world.c -lc -D DEMO -D PC
    
    From Code::Blocks, you can do exactly the same thing - just go to Project->Build Options and select the PC option from the list of available HMI options, and the DEMO board from the list of available platforms.

    Thanks so much for your help,

    Now, since I have defined the PC symbol, I get the error:
    -------------- Build: Debug in test ---------------
    
    Compiling: main.c
            1 fichier(s) d‚plac‚(s).
    Catalina Compiler 3.2
    Linking console executable: bin\Debug\test
    Undefined or Redefined symbols:
     printf undefined
    Catalina Compiler 3.2
    Process terminated with status 1 (0 minutes, 0 seconds)
    1 errors, 0 warnings
    Build log saved as: 
    file://beeeep%5ctest_build_log.html
    
    For this code
    #include <stdio.h>
    int main(int argc, char *argv[]) {
        printf("Hello world!\n");
        while(1);
        return 0;
    }
    
    I have included stdio.h which I know contains the declaration of printf, thing I have even verified by editing the file.

    Hum, there must be an explanation here :-)
  • RossHRossH Posts: 5,549
    edited 2011-09-08 22:16
    allaiks wrote: »
    Thanks so much for your help,

    Now, since I have defined the PC symbol, I get the error:

    << snip >>

    I have included stdio.h which I know contains the declaration of printf, thing I have even verified by editing the file.

    Hum, there must be an explanation here :-)

    You have not told the linker which C libraries to include. On the command line, you would add an option like -lc or -lci. If you are using Code::Blocks, you should instead check the Project->Build Options and make sure that one of the variants of the standard C libraries is selected.

    Ross.
  • allaiksallaiks Posts: 8
    edited 2011-09-08 22:27
    Ok got it! :-) I did't take the time to read all the Build options avalaible.

    But where am I suppose to see the "Hello world!" string?
  • RossHRossH Posts: 5,549
    edited 2011-09-08 22:51
    allaiks wrote: »
    Ok got it! :-) I did't take the time to read all the Build options avalaible.

    But where am I suppose to see the "Hello world!" string?

    Since you selected the PC HMI option, it will be sent to serial output. If you open your terminal emulator you should see it - but note that the program may have already finished by the time you do so. If that is the case, make a simple modification to your program to print the output in a loop:
    #include <stdio.h> 
    int main(int argc, char *argv[]) {
        while(1) {
           printf("Hello world!\n");
        }
        return 0;
    }
    
    Now when you load it and start the program it will still be sending output when your terminal emulator starts up (make sure your terminal emulator program is set to 115,200 baud, and select the same com port you used to program the Propeller).

    Ross.
  • allaiksallaiks Posts: 8
    edited 2011-09-08 23:03
    Oh I understand, payload is the last program executed, I'd love to have a terminal automaticaly launched right after the download. Do you think it is possible? Maybe payload could have an option to launch a terminal right after the download is finished? Idealy payload could even print out what is received from the serial?
  • RossHRossH Posts: 5,549
    edited 2011-09-08 23:11
    allaiks wrote: »
    Oh I understand, payload is the last program executed, I'd love to have a terminal automaticaly launched right after the download. Do you think it is possible? Maybe payload could have an option to launch a terminal right after the download is finished? Idealy payload could even print out what is received from the serial?

    I'm working on adding my own terminal emulator into Code::Blocks to do just that!

    In the meantime, you could try a program like the following - it will wait till you press the space bar before executing:
    #include <stdio.h> int main(int argc, char *argv[]) {
       while (getchar() != ' ');
       printf("Hello world!\n");
       return 0;
    }
    

    Ross.
  • allaiksallaiks Posts: 8
    edited 2011-09-08 23:26
    All right! I Like this last idea of a getchar! In addition, I'm so lazy I'll also create a fake payload that will lauch the real payload with the options forwarded, and right after it returns, forward the output, and launch a terminal in a fork, idealy the Paralax terminal, but I don't know if there are options to lauch it at the good baudrate and enabled. :-)
  • allaiksallaiks Posts: 8
    edited 2011-09-08 23:29
    By the way, if you are the author, I must congratulate you, you have done a great job! Bravo!
  • RossHRossH Posts: 5,549
    edited 2011-09-08 23:49
    Thanks, allaiks!

    Ross.
Sign In or Register to comment.