このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Using the Arduino serial 監視する for debugging and more- aht1serimoni.htm HOME - - - - - - - - (米)棚上げする/(英)提議する of contents, my Arduino "How To" articles
Other 構成要素 for programmers   

Arduino Serial 監視する

A 資源 for debugging and more

A computer has 準備/条項 for input and 生産(高), and a way to 蓄える/店 the programs which 過程 the input and 決定する the 生産(高).

The text you see in the serial 監視する window, the one shown 大きくするd, at the 権利, is just a 見本. That text was 明示するd in the code 存在 put into the Arduino under 開発. And what if, later, nothing is connected to the 関連した pins? Nothing! The Arduino won't "care" if you aren't "listening" when it "speaks".

(If you already know about this use of the Serial 監視する, what about using it to send data to the connected Arduino? I also have 公式文書,認めるs for you on using the Arduino IDE Serial 監視する to send data to the Arduino from the 開発 machine.

An Arduino with one 押し進める 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 生産(高) 前線 without buying anything beyond the basic Arduino. This How To tells you about using the 生産(高) half of the serial stream.

Before we start: A WARNING!! ....

"Serial" and "RS-232" are NOT just two ways of 説 the same thing. RS-232 comms do use serial data, so you might think that you can just hook up the serial "stuff" I'm going to talk about... 含むing your Arduino... to RS-232 装置s. Or to the RS-232 port of a big PC. NOT SO!! (They can be connected... but there are a few 詳細(に述べる)s to get 権利.)

All the ins and outs of that are beyond the 範囲 of this tutorial. I've 挿入するd this 警告 just in 事例/患者 someone is tempted to "延長する" the ideas here, hook an Arduino 直接/まっすぐに to something RS-232... and fry their Arduino! (If you want to connect to RS-232, search on "Arduino MAX323".)



The serial 監視する lets you...

The serial 監視する lets you see anything the Arduino sends to its serial port. (When I speak here of "its port", I mean one built into most (all?) Arduinos (and clones), used for programming the 装置s. On 伝統的な Arduinos (Uno, プロの/賛成の 小型の, etc), it uses pins 0 and 1.

diagram to show where Serial Monitor fits in bigger picture

As I just said: These pins are also connected to the electronics which the Arduino 開発 環境 uses for programming the Arduino. Don't worry... you can use them both for the programming 仕事, and for the serial 監視する at (almost) the same time. (With care, they can even be used for more things, but that's a story for another page.)

Before I go on... this page is about the 比較して simple... and 概して useful... use of the serial 監視する. Other "stuff" can be sent to and from other 金物類/武器類, 含むing big PCs, over a serial channel, to a program running in the other 金物類/武器類. That is all a bit beyond just using the serial 監視する, but I について言及する it in passing, in 事例/患者 you wondered. I have pages for you on serial communications between Arduinos and other 金物類/武器類. (anywhere you see "Delphi" there, you can probably 代用品,人 "Lazarus".)

As I said, this page is about using the serial 監視する to watch "stuff" going to the 開発 PC from the Arduino.

Enter the に引き続いて and run it. We'll do something more useful in a moment, don't worry.

int x = 0;

無効の  体制/機構()
{
  Serial.begin(9600);
  Serial.println("Hello world");
  延期する(2000);// Give reader a chance to see the 生産(高).
}


無効の 宙返り飛行()
{
  Serial.println(x);
  延期する(500);
  x=x+1; // (Yes, I know there's a more clever way....
      //this page is about the serial 監視する, remember?)
  if (x>5) {x=0;};
}

Wait until the usual "Binary sketch size..." message comes up in the pane at the 底(に届く) of the Arduino 統合するd 開発 環境 ("IDE"). Then click on the "Serial 監視する" button, the "magnifying glass" I 示すd "6" in the diagram below. (It shows the 最高の,を越す of the Arduino IDE window.)

Image of Arduino interface

(And, just in 事例/患者, below: The old interface. The "Serial 監視する" button was the 権利 手渡す icon, the one like an upside 負かす/撃墜する window shade.)

Image of Arduino interface

After you click on the 権利 icon, the 底(に届く) pane of the Arduino 開発 環境 will (疑いを)晴らす, 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 無.

Why should I care?

The example above counts from 1 to 5. Most of us, on a good day, can do that without the computer! The example was just to get you started with serial 監視する.

You should care because the serial 監視する 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 looks like.....

無効の  体制/機構()
{
}

無効の 宙返り飛行()
{
  for (int i=0; i <= 25; i++){
        analogWrite(PWMpin, i);
      延期する(10);
  for (int i=50; i <= 100; i++){
          analogWrite(PWMpin, i);
        延期する(10);
  for (int i=150; i <= 200; i++){
          analogWrite(PWMpin, i);
        延期する(10);
}

.... and you're not able to 人物/姿/数字 out how many of the "for" 宙返り飛行s it is 完全にするing, not able to deduce if the 宙返り飛行 機能(する)/行事 is 遂行する/発効させるing at all? More than once? What!?

追加する.....

  Serial.begin(9600);

... to the 体制/機構 機能(する)/行事, and then alter the 宙返り飛行 機能(する)/行事, making it....

無効の 宙返り飛行()
{
  for (int i=0; i <= 25; i++){
        analogWrite(PWMpin, i);
  Serial.println("First 宙返り飛行 done");
      延期する(10);
  for (int i=50; i <= 100; i++){
          analogWrite(PWMpin, i);
  Serial.println("Second 宙返り飛行 done");
        延期する(10);
  for (int i=150; i <= 200; i++){
          analogWrite(PWMpin, i);
  Serial.println("Third 宙返り飛行 done");
        延期する(10);
}

Now as the program 遂行する/発効させるs, you'll get messages, on the serial 監視する, which will tell you how far it has 進歩d.

Not only can you 生産(高) simple text messages like "First 宙返り飛行 done", but you can tell the program to 生産(高) the values in variables which you are 利益/興味d in.

Having 設立するd and filled a variable called "iTmp", you can do....

Serial.println(iTmp);

(Contrary to my usual 政策, that snippet wasn't checked. Do please get in touch if you discover a typo or "gotcha".)



"And another thing"... data from 開発 PC...

We've seen how data can be sent from the Arduino to the 開発 PC... the "big computer" where the code is written, 収集するd, etc.

It is also possible to send data the other way. Let's say you are building a system to 支配(する)/統制する a fan. The system will "watch" a 気温 sensor, and turn the fan on when the 気温 rises above some value.

While building this 事業/計画(する), you could program everything so that things typed on the 開発 PC while the Arduino program was running would pass to the Arduino 経由で the serial 監視する, and be seen, 行為/法令/行動するd upon, by the Arduino program.

Look at the image at the 最高の,を越す of the page, the screenshot at the 権利 of that. See the edit box at the 最高の,を越す of the dialog, the one to the left of the "Send" button? That's where you put the stuff you want sent.



特別手当- 内部の documentation...

Once you get into the habit of using the serial 監視する, consider 本気で 含むing something like the に引き続いて in your code, 権利 after the serial stream is 始める,決める up...

Serial.begin(9600);//始める,決める up serial stream
延期する(100);
Serial.print("Welcome to ");Serial.println(sPrgmName);
Serial.print("見解/翻訳/版: "); Serial.println(sVersID);

To support that, elegantly, someplace else, 近づく 最高の,を越す of program code is good place, you 持続する....

String sPrgmName="MouseTrap Number 99"
String sVersID="vers 20 Feb 17"

Or, not as elegant, just make the first bit of code...

Serial.begin(9600);//始める,決める up serial stream
延期する(100);
Serial.print("Welcome to MouseTrap Number 99");
Serial.print("見解/翻訳/版: vers 20 Feb 17")

The 推論する/理由 I call this more "direct" 解答 inelegant is that the 関連した lines will be buried 深い within your code, and when it is time to change the 見解/翻訳/版 ID, laziness may 勝利,勝つ. By using the strings, as long as you fill them 近づく the 最高の,を越す of the code, it is 平易な to find them when it is time for a change.

No, of course, you won't always have the Arduino connected to a big PC and the serial 監視する turned on. But the code above does no 害(を与える) in those circumstances. (Unless you want to use the pins associated with it for other things.) And when you DO have the serial 監視する connected, the program and 見解/翻訳/版 (警察などへの)密告,告訴(状) can be very useful.

(You can, however, connect something simpler in it's place, if all you need is to see 内部の documentation messages.)


I hope this 道具 証明するs useful to you in your 開発 work. There may even be times when you find it useful in a finished 事業/計画(する), but of course that would only be a 事業/計画(する) where your PC remained connected to the Arduino while the Arduino did whatever you 始める,決める it up to do. Perhaps not a シナリオ which is going to arise often, but there's no 推論する/理由 it couldn't ever arise.




   Search this 場所/位置 or the web        力/強力にするd by FreeFind
 
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search

The search engine is not intelligent. It 単に 捜し出すs the words you 明示する. It will not do anything sensible with "What does the 'could not 収集する' error mean?" It will just return 言及/関連s to pages with "what", "does", "could", "not".... etc.
In 新規加入 to the tutorials for which this page serves as (米)棚上げする/(英)提議する of Contents, I have other 場所/位置s with 構成要素 you might find useful.....

Sequenced 始める,決める of tutorials on Arduino programming and electronics interfacing.
Tutorials about the 解放する/自由な database 供給(する)d with Open Office 見解/翻訳/版 2. (If you experienced Adabas with 星/主役にする Office, ooBase is nothing like it!)
Some pages for programmers.
Using the 平行の port of a Windows computer.


If you visit 1&1's 場所/位置 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.




広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!

Click here to visit editor's Sheepdog ソフトウェア (tm) freeware, shareware pages.


And if you liked that, or want different things, here are some more pages from the editor of these tutorials....

Click here to visit the homepage of my biggest 場所/位置.

Click here to visit the homepage of Sheepdogsoftware.co.uk. 陳謝s if the "?FrmAht" I 追加するd to that link 原因(となる)s your browser problems. Please let me know, if so?

Click here to visit editor's pages about using computers in Sensing and 支配(する)/統制する, e.g. 天候 logging.



To email this page's editor, Tom Boyd.... Editor's email 演説(する)/住所. Suggestions welcomed!



Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Why do I について言及する the script? Be sure you know all you need to about spyware.

Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND (almost!) passes... Valid CSS!

....... P a g e . . . E n d s .....