A computer has provision for input and output, and a way to store the programs which process the input and determine the output.
An Arduino with one push button and one LED is a computer... but even your friends may ask you what that's good for.
You can make a quantum leap on the output front without buying anything beyond the basic Arduino. This How To tells you how to use the output half of the serial stream.
"Serial" and "RS-232" are NOT just two ways of saying the same thing. RS-232 comms do use serial data, so you might think that you can hook up the serial "stuff" I'm going to talk about... including your Arduino... to RS-232 devices. Or to the RS-232 port of a big PC. NOT SO!!
All the ins and outs of that are beyond the scope of this tutorial. I've inserted this warning just in case someone is tempted to "extend" the ideas here, hook an Arduino directly to something RS-232... and fry their Arduino! (If you want to connect to RS-232, search on "Arduino MAX323".)
The serial monitor lets you see anything the Arduino sends to its serial port, the "good" one built into pins 0 and 1. These pins are also connected to the electronics which the Arduino development environment uses for programming the Arduino. Don't worry... you can use them for both things (and more, but that's a story for another page) at (almost) the same time.
Enter the following and run it. We'll do something more useful in a moment, don't worry.
int x = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Hello world");
delay(2000);// Give reader a chance to see the output.
}
void loop()
{
Serial.println(x);
delay(500);
x=x+1; // (Yes, I know there's a clever way.)
if (x>5) {x=0;};
}
Wait until the usual "Binary sketch size..." message comes up in the pane at the bottom of the Arduino development environment. Then click on the "Serial Monitor" button on the toolbar which is across the top of the Arduino IDE window....
The "Serial Monitor" button is the right hand icon, the one like an upside down window shade.
After you click on the right icon, the bottom pane of the Arduino development environment will clear, and after a short wait... 6 seconds on my BBB just now... you should see "Hello world". Two seconds later you should see 0, then 1, then 2, then 3... each on their own line. The Arduino will count to 5, and then start again at zero.
Most of us can count to 5, on a good day, without the computer.
The reason I've shown you the serial monitor is that it can be very helpful when debugging things.
Imagine that you are working on a large Arduino program, and it isn't doing what you want. Say the program looked like.....
void setup()
{
}
void loop()
{
for (int i=0; i <= 25; i++){
analogWrite(PWMpin, i);
delay(10);
for (int i=50; i <= 100; i++){
analogWrite(PWMpin, i);
delay(10);
for (int i=150; i <= 200; i++){
analogWrite(PWMpin, i);
delay(10);
}
.... and you're not able to deduce how many of the "for" loops it is completing, not able to deduce if the loop function is executing more than once.
Add.....
Serial.begin(9600);
... to the setup function, and then alter the loop function, making it....
void loop()
{
for (int i=0; i <= 25; i++){
analogWrite(PWMpin, i);
Serial.println("First loop done");
delay(10);
for (int i=50; i <= 100; i++){
analogWrite(PWMpin, i);
Serial.println("Second loop done");
delay(10);
for (int i=150; i <= 200; i++){
analogWrite(PWMpin, i);
Serial.println("Third loop done");
delay(10);
}
Now as the program executes, you'll get messages which will tell you how far it has progressed.
Not only can you output simple text messages like "First loop done", but you can tell the program to output the values in variables which you are interested in.
I hope this tool proves useful to you in your development work. There may even be times when you find it useful in a finished project, but of course that would only be a project where your PC remained connected to the Arduino while the Arduino did whatever you set it up to do. Perhaps not a scenario which is going to arise often, but there's no reason it couldn't ever arise.
If someone is using a Windows PC driven by an Arduino, I wonder if they've found a way to capture the stream of data from the Arduino. I suspect it can be done, crudely, with Hyperterminal. I'd be interested in seeing the sourcecode of something that could work a bit like Hyperterminal in "data capture" mode, especially if that source code was in Delphi or C, not using the dreaded .Net.
If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.
Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages.
Click here to visit the homepage of my biggest site.
Click here to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmAht" I added to that link causes your browser problems. Please let me know, if so?
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org
....... P a g e . . . E n d s .....