Serial Writing

Hi to all.

I am a newbie in serial monitoring of the arduino board.

I would like to know how to send integer values via the serial monitor.

A simple example that i have in mind is by writing 5 in the serial monitor and it is displayed on an lcd.

I dont know what is the coding so that the serial monitor accepts values. When i tried the serial.read it continues to scroll strange values.

I want the serial monitor to stop until i press a number from my pc and then continues with the process.

How can i do so what is the coding to do so?

Thanks & Regards
Combinu

Show us your code, but it sounds like the usual problem of not converting ASCII character codes into decimal, or vice versa

I dont know what is the coding so that the serial monitor accepts values.

There is no coding. The Serial Monitor is a standalone application.

Now, you can have the Arduino send data to the serial port (using Serial.print() or Serial.println(), and then do nothing until it receives a response (tested for using Serial.available()).

I want the serial monitor to stop until i press a number from my pc and then continues with the process.

That won't happen unless you make the Arduino quit writing to the serial port. It isn't the Serial Monitor that needs to "continue with the process". It is the Arduino that needs to.

When i tried the serial.read it continues to scroll strange values.

A "read" will return -1 if there is no new data, and printing this value (255) will produce odd results.
Always use "Serial.available" before reading.

This is a very simple code at the moment...

Ignore the pins and their state since i am going to use only serial monitor at the moment just to check.

This code is suppose to print in the serial monitor "Enter Decimal Number: ", reads the number from the pc and outputs its corresponding binary value from the array.

The code is below:

int b1 = 31;
int b2 = 33;
int b3 = 35;
int b4 = 37;

int matrix[16][4] = {0,0,0,0,
                     0,0,0,1,
                     0,0,1,0,
                     0,0,1,1,
                     0,1,0,0,
                     0,1,0,1,
                     0,1,1,0,
                     0,1,1,1,
                     1,0,0,0,
                     1,0,0,1,
                     1,0,1,0,
                     1,0,1,1,
                     1,1,0,0,
                     1,1,0,1,
                     1,1,1,0,
                     1,1,1,1};
                     
void setup()
{
  Serial.begin(9600);
  pinMode(b1, OUTPUT);
  pinMode(b2, OUTPUT);
  pinMode(b3, OUTPUT);
  pinMode(b4, OUTPUT); 

}

void loop()
{
  int z;
    Serial.print("Enter Decimal Number: ");
    z = Serial.read();
    for (int x = 0; x<4; x++)
  {
    Serial.print(matrix[z][x]);
  }

}

Even after you add a Serial.available() call, in an if statement, you need to handle input better. What happens if the idiot using the program enters Z or > or %?

No that problem is not going to happen... this is just for testing...

How can i use the code to reach my needs?

    Serial.print("Enter Decimal Number: ");
    while (Serial.available () ==0 ) ;
    int  z = Serial.read() - '0';
    for (int x = 0; x<4; x++)
  {
    Serial.print(matrix[z][x]);
  }

Ok it worked out thanks alot but if you are kind can you please explain to me these two lines that you have added i am very willing to learn it...

while (Serial.available () ==0 ) ;
z = Serial.read() - '0';

The first one waits until there is something in the receive buffer.
The second reads the ASCII value there, and converts it to decimal.

The value of the ASCII zero character is 48 decimal (0x30), so if you type '5' on the serial monitor, it sends the decimal value 53 (0x35), so 0x35 - 0x30 == 5.

As PaulS said, you should really test the value of the character you received to see if is valid.

Of course, this won't work for all the elements of your matrix - you'll have to manage 10..15 differently.

Look around the forum - this problem comes up every other day.