Post by Admin on May 21, 2016 6:42:46 GMT
Today, I will introduce you to Serial Monitors in arduino and some other basic things you need to know . More of like Theory
What is Serial?
Serial may sound like a tasty breakfast food, but its actually quite different. The word serial means "one after the other." For example, a serial killer doesn't stop with one murder, but stabs many people one after the other. Serial data transfer is when we transfer data one bit at a time, one right after the other.
Information is passed back & forth between the computer and Arduino by, essentially, setting a pin high or low. Just like we used that technique to turn an LED on and off, we can also send data. One side sets the pin and the other reads it. It's a little like Morse code, where you can use dits and dahs to send messages by telegram. In this case, instead of a long cable, its only a few feet probably..
Okhay, Lets start with a few syntaxs..
BEFORE THAT!!! I FORGOT, We've actually used the Serial communications capability already quite a bit...that's how we send sketches to the Arduino! When you Compile/Verify what you're really doing is turning the sketch into binary data (ones and zeros). When you Upload it to the Arduino, the bits are shoved out one at a time through the USB cable to the Arduino where they are stored in the main chip.
Next time you upload a sketch, look carefully at the two LEDs near the USB connector, they'll blink when data is being transmitted. One blinks when the Arduino is receiving data (RX) and one blinks when the Arduino is transmitting data (TX)
OKHAY NOW FOR SOME SYNTAX...
Whats BPS?? -> This is BITS PER SECOND, Often called as Baudrate. Your internet connection? Its In BITS and not BYTES. When Someone says 1Mbps they mean 1 mega bis per second * Honestly its not that large as it sound, 9600bps. Its small but enough.. for robotics.
We definately see that there is a Serial thing going on, and it looks like there is a procedure call as well. This is a library procedure call. The library is called Serial and inside the library is a procedure called begin.
If there's no library name, it means that the procedure is in the 'default' collection of procedures we use. For example, delay() is so common, the designers of the Arduino software didn't bother putting it into a library.
OK so Serial.begin sets up the Arduino with the transfer rate we want, in this case 9600 bits per second.
Lets move on to the next line.
This starts sending HEX of
Verify and Compile the program and lets see what happens!!.
Now how do we see whats going on? Well In the Arduino software, Theres a Serial Monitor under tools. Just click on it and set the Baudrate to 9600bps like here
Mine is a old arduino software.... It should look like this.
Okhay, next stop is. A QUESTION!!! THE FIRST PERSON TO SOLVE THIS AND PUT THE CODE HERE GETS NOTHING BUT SATISFACTION ( dont take this in the wrong way )
Q ) MAKE A calculator and print if user wants to add, subtract, multiply or divide. PIN 0-9 will be the 9 digits, 10-13 will be add,subtract,multiply or divide. Print the result in the Serial MONITOR
PS : I WANT SOMEONE FROM YOU TO DO THIS , I AINT GONNA!
What is Serial?
Serial may sound like a tasty breakfast food, but its actually quite different. The word serial means "one after the other." For example, a serial killer doesn't stop with one murder, but stabs many people one after the other. Serial data transfer is when we transfer data one bit at a time, one right after the other.
Information is passed back & forth between the computer and Arduino by, essentially, setting a pin high or low. Just like we used that technique to turn an LED on and off, we can also send data. One side sets the pin and the other reads it. It's a little like Morse code, where you can use dits and dahs to send messages by telegram. In this case, instead of a long cable, its only a few feet probably..
Okhay, Lets start with a few syntaxs..
BEFORE THAT!!! I FORGOT, We've actually used the Serial communications capability already quite a bit...that's how we send sketches to the Arduino! When you Compile/Verify what you're really doing is turning the sketch into binary data (ones and zeros). When you Upload it to the Arduino, the bits are shoved out one at a time through the USB cable to the Arduino where they are stored in the main chip.
Next time you upload a sketch, look carefully at the two LEDs near the USB connector, they'll blink when data is being transmitted. One blinks when the Arduino is receiving data (RX) and one blinks when the Arduino is transmitting data (TX)
OKHAY NOW FOR SOME SYNTAX...
void setup ()
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
Whats BPS?? -> This is BITS PER SECOND, Often called as Baudrate. Your internet connection? Its In BITS and not BYTES. When Someone says 1Mbps they mean 1 mega bis per second * Honestly its not that large as it sound, 9600bps. Its small but enough.. for robotics.
We definately see that there is a Serial thing going on, and it looks like there is a procedure call as well. This is a library procedure call. The library is called Serial and inside the library is a procedure called begin.
If there's no library name, it means that the procedure is in the 'default' collection of procedures we use. For example, delay() is so common, the designers of the Arduino software didn't bother putting it into a library.
OK so Serial.begin sets up the Arduino with the transfer rate we want, in this case 9600 bits per second.
Lets move on to the next line.
void loop()
{
Serial.println("Hello test");
delay ( 1000 );
}
This starts sending HEX of
48 65 6c 6c 6f 20 74 65 73 74
to the USB of your laptop, or end devices via RX and TX in mentioned earlier at the mentioned baudrate mentioned ( Just a tip, You will learn more about Serial and Parallel communication in Microprocessors course in 2-2 for EEE/ENI/CS )> Others just can digest what i say here.. Verify and Compile the program and lets see what happens!!.
Now how do we see whats going on? Well In the Arduino software, Theres a Serial Monitor under tools. Just click on it and set the Baudrate to 9600bps like here
Mine is a old arduino software.... It should look like this.
Okhay, next stop is. A QUESTION!!! THE FIRST PERSON TO SOLVE THIS AND PUT THE CODE HERE GETS NOTHING BUT SATISFACTION ( dont take this in the wrong way )
Q ) MAKE A calculator and print if user wants to add, subtract, multiply or divide. PIN 0-9 will be the 9 digits, 10-13 will be add,subtract,multiply or divide. Print the result in the Serial MONITOR
PS : I WANT SOMEONE FROM YOU TO DO THIS , I AINT GONNA!