Serial Communication

Hi,

I just began with my course control technology of a microcontroller ( with arduino)
I completed a step of my homework called doing math with serial communication. see the attachment ‘doing math’
The next task is to use the serial monitor and type in a value in this case 12 press send and it’ll calculate. see the attachment ‘‘uncompleted example’’ for what i mean
By using if(serial.available) and serial.parseInt, but i dont have any idea of how to do it.

anyone here can help me out?

thnx

Have you looked up the Serial library and looked at what serial.available does?

Serial.available() will return the number of bytes available to read from the serial port.

To save you some time, try and get one arduino to keep saying "Hello World!" and have the other that is receiving the data keep looping:

//On receiving arduino.

if (Serial.available()>0){
Serial.println(serial.available());
}
//On sending arduino.
delay(500);
Serial.println("Hello World!");

See what you notice and come back to us ;).

the only thing that i notice is that it keeps saying ''hello world''

void setup() {
  Serial.begin(9600);

}
   
  
  
 void loop() {
  if (Serial.available()>0){
Serial.println(Serial.available());
}
   delay(500);
Serial.println("Hello World!");
  }

@Alexlauman, It must be my day to bitch, so: If you are in school, college, or whatever, I would expect you could use correct grammar. Sentences start with capital letters, and end with proper punctuations.

thnx is not a word.

Just my minute to bitch I guess!

I don't think that's too much to ask. Really, programming languages and compilers are even more concerned with things like grammar, capitalization, and punctuation than even the most strident grammar nazi.

It would be really nice if the people coming here to ask for our help had enough respect to write to us like grownups and not like they are sending a text message to their girlfriend. It's hard enough sorting through code that doesn't make sense without trying to figure out what the person is trying to say about it.

Alexlauman: the only thing that i notice is that it keeps saying ''hello world''

Read my post again.

One should have the Serial.available() loop.

The other Arduino the Serial.println("hello world"); loop.

Will not be doing your homework for you, but as an actual teacher...I will give you a small exercise in order for you to understand the principle out of context for you to apply to another...

Hi,

Perhaps, the code on the following pages (especially the first one) can also hopefully shed some light on the use of Serial.available(). I think the example for the Uno is quite simple and is well explained...

https://www.arduino.cc/en/Serial/Available https://www.arduino.cc/en/Reference/Serial (there is a link for parseInt() which could be useful to read as well)

dan

Have a look at the examples in Serial Input Basics. One of them is likely to meet your need.

...R