GR-ADZUKI SERIAL SAMPLE

Pocket

GR-ADZUKIでは、プログラム書き込み用のUSBでシリアル通信ができます。

シリアル通信ができるとパソコンで動作の確認しやすくなります。
動作の順番、アナログ入力の確認、計算結果などが確認できます。
プログラムが思った通り動いているかが確認できるようになります。

まず、アナログピンとアナログ値保持用の変数を定義します。
int sensorPin = A2; // select the input pin for the light sensor
int lightSensor = 0; // first analog sensor

通信確認は、IDE for GRのシリアルモニタから行います。
「ツール」メニューの「シリアルモニタ」を選択するとモニタ画面が表示されます。

setup()関数で、シリアルの初期化をします。
Serial.begin(9600);
引数の9600は、通信速度です。9600bpsで通信します。bpsは、bit per secondの略で
1秒間に9600ビットを通信できます。1文字送るのに10ビットかかるので9600bpsでは、1秒間に最大、960文字送受信できます。

establishContact()関数は、文字が入力されるのを待つ関数です。
Serial.available()は、GR-ADZUKIが文字を受信したいるかどうかを確かめる関数です。
受信がるとSerial.available()が1以上になります。

何か受信があるとloop()関数に移動します。
lightSensor = analogRead(sensorPin);
ライトセンサの値を読み込みます。
Serial.println(lightSensor);
センサ値をパソコンに送ります。

delay(500);
500msecごとにこの処理を繰り返します。

以下にサンプルがあります。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Serialout/Serialout.ino

With GR-ADZUKI, serial communication can be performed with USB for programming.

If serial communication is possible, it will be easier to check the operation on the PC.
You can check the order of operations, confirmation of analog input, calculation result and so on.You will be able to see if the program is working as expected.

First, define analog pins and variables for holding analog values.
int sensorPin = A2; // select the input pin for the light sensor
int lightSensor = 0; // first analog sensor

Communication confirmation is done from IDE for GR serial monitor.
Select “Serial monitor” from the “Tools” menu to display the monitor screen.

In the setup()function, initialize the serial.
Serial.begin(9600);
The argument 9600 is the communication speed. Communicate at 9600 bps. bps stands for bit per second, and it can communicate 9600 bits per second. Since it takes 10 bits to send one character, at 9600 bps, it can transmit and receive up to 960 characters per second.

The establishContact() function is a function that waits for characters to be input.
Serial.available() is a function that checks whether GR-ADZUKI has received a character. Serial.available() becomes 1 or more when receiving.

If something is received, it moves to the loop() function.
lightSensor = analogRead(sensorPin);
Read the value of the light sensor.
Serial.println(lightSensor);
Send sensor value to PC.

delay(500);
Repeat this process every 500 msec.

Below is a sample.
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Serialout/Serialout.ino

使用GR-ADZUKI,串行通信可以通過USB進行編程。

如果可以進行串行通信,則可以更容易地檢查PC上的操作。
您可以查看操作順序,模擬輸入確認,計算結果等。
您將能夠看到該程序是否按預期工作。

首先,定義用於保持模擬值的模擬引腳和變量。
int sensorPin = A2; // select the input pin for the light sensor
int lightSensor = 0; // first analog sensor

通訊確認是從GR串行監視器的IDE完成的。
從“工具”菜單中選擇“串行監視器”以顯示監視器屏幕。

在setup()函數中,初始化串行。
Serial.begin(9600);
參數9600是通信速度。 溝通在9600 bps。 bps代表每秒的位數(bits per second),並且可以每秒傳送9600位。 由於發送一個字符需要10位,以9600bps的速度發送和接收每秒960個字符。

establishContact()函數是一個等待字符輸入的函數。
Serial.available()是一個函數,用於檢查GR-ADZUKI是否收到一個字符。
Serial.available()在接收時變為1或更多。

如果收到某個東西,它會移到loop()函數。
lightSensor = analogRead(sensorPin);
讀取光線傳感器的值。
Serial.println(lightSensor);

將傳感器值發送到PC。

delay(500);
每500毫秒重複這個過程。

下面是一個例子。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Serialout/Serialout.ino

Post Tagged with ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください