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.
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. (It is to the right of the "Upload to I/O board" button. Hover your mouse pointer over if you wish to confirm that you have the right one.)
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?
Link to editor's oldest homepage.
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 .....