Wiring Forum
Programming Questions & Help >> Syntax >> Serial port questions

Message started by Juraj on 09/14/08 at 17:07:59

Title: Serial port questions
Post by Juraj on 09/14/08 at 17:07:59

I am starting with serial port and Ive found no reference about it, so I have few questions. I am begginer with the serial port communication so please be patient...
Sorry of little bit biger question ::)

Here are some of the questions:

1.) when I want to print data to Serial1 port can I use this command: Serial1.print ?
    Can I send different data to serial and serial1 ?

2.) when I start also serial1 port - do I need to write Serial1.begin(9600);  command also?

3.) it seems there is no Serial.printIn - but I need to make something like enter and space (10,13) after the message for the device driven by serial port. How to do it?

4.) I would like to print the whole array into Serial port. How to do it?

here is the structure of the code (maybe with some syntax-logical mistakes / please inform me / it s new for me)

int zones[] = (zone1, zone2, zone3......,zone 10);  // the array of all zones values

int zone1 = 0;  // declare  variable for zone1  
int zone2 = 0;
etc....  till zone 10
int zone1Pin = 1; // declare zone1 input as pin1
int zone2Pin =2;
etc... till zone10Pin

void setup() {
     pinMode ( zone1Pin, INPUT);
     etc... all 10 zones declared as input

void loop () {

zone1 = digitalRead (zone1Pin);  // here I expect, that if the value
                                                  on pin will be HIGH, the value zone1 will be 1,
                                                   else 0 / is it right?
zone2 = digitalRead (zone1Pin);

Serial1.print (zones);  // now I expect that this will send the whole
                                   array if numbers - something like (1,0,0,0,1,0,1,0,1,1) - is
                                   it right?

delay (25);  // here I expect, that the values will be hold and  
                    sending about 25ms untill new measure loop / is it right?


maybe it totally bullshit, but how to do something like this?

5.) and last question:

I want to send  in Serial port somthing like this:

extract of the code:

mainvolume= 0000;   // I need to keep and send all four numbers,
                                  even if it means just 0... will this work, or I need to declare
                                   it in a different way?

if (sensPin == HIGH && mainvolume <1000)
{ mainvolume += 100;
   Serial.print ("W");  // this is the command for the driven device,  
                                 that volume will be set - I want to send the char W
   Serial.print (mainvolume, mainvolume);  // here I want to send
                                                                 something like                                                              
                                                                 for example (05000500) is it

and now here I need to send <cr><lf>(10,13) for completing the message / how to do it?
/so the complete message might be W05000500<cr><lf>

Uf! :)

Sorry for so long question, but all these thing are unclear for me now.
Thanks very very very much for any advice! ;)

Title: Re: Serial port questions
Post by barragan on 09/14/08 at 23:12:04
Here is the reference for Serial1 http://wiring.org.co/learning/libraries/Serial/Serial1_.html

Title: Re: Serial port questions
Post by Juraj on 09/15/08 at 07:58:50
:-[ sorry I just look at language and not to libraries.

But the shown syntax for print() and printIn() is the same - what does it mean?
When Itried to write Serial.printIn  the software doesnot recognize this syntax...

So it is not possible to print the array to Serial port?

I want to send the number (something like this: 00011010110) where each digit is telling that the digital input is HIGH or LOW.

Please can you help me how to do it?

Thanks a lot!

Title: Re: Serial port questions
Post by barragan on 09/16/08 at 16:53:39
the difference is that println sends a new line character (enter) at the end, the print command doesn´t.

Title: Re: Serial port questions
Post by Juraj on 09/21/08 at 10:44:28
now it works! I read and write bad syntax: In instead of ln - that was that mistake.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.