de-vraag
  • 質問
  • タグ
  • ユーザー
通知:
報酬:
登録
登録すると、質問に対する返答やコメントが通知されます。
ログイン
すでにアカウントをお持ちの方は、ログインして新しい通知を確認してください。
追加された質問、回答、コメントには報酬があります。
さらに
ソース
編集
Tony M
Tony M
質問

シリアルデバイスに1文字を渡そうとする

こんにちは。 ハイパーターミナルで接続したシリアルデバイスで、 'd&#39 を押すとステータスレポートが表示されるものがあります。

Arduinoに接続されたボタンを押し、シリアルデバイスにbを送信し、そこから戻ってくるステータス情報を見たいと思います。

この時点でシリアルデバイスをarduinoに接続し、メッセージを見ることができますが、ピン2に接続したスイッチを押しても、シリアルデバイスは期待通りのステータス出力を送ってくれず、ハイパーターミナルでコンピュータと直接シリアル接続しても、ステータス出力は見られません。

どなたか、この件に関する経験やご意見をお持ちの方はいらっしゃいますか?

#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
 SoftwareSerial portOne(10, 11);
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int button1Pin = 4;
 const int ledPin =  13;      // the number of the LED pin
//define char to send to serial

char stat = 'd';
char route = '\x14';
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int button1State = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
                pinMode(ledPin, OUTPUT);
                pinMode(buttonPin, INPUT);
                pinMode(button1Pin, INPUT);
                Serial.begin(4800);
                while (!Serial) {; // wait for serial port to connect. Needed for native USB port only
                }
                // Start each software serial port
                portOne.begin(4800);
                while (!portOne) {; // wait for serial port to connect. Needed for native USB port only
                }
              }

// the loop function runs over and over again forever
void loop() {
            static int Once = 0;
            static int Once1 = 0;
            buttonState = digitalRead(buttonPin);
            button1State = digitalRead(button1Pin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
            if (buttonState == HIGH ) { 
                                      if (Once == 0) {
                                                        Once = 1;
                                                        // turn LED on so I can tell the button is working
                                                        digitalWrite(ledPin, HIGH);
                                                        // send d to Radio
                                                        portOne.write(stat);
                                                        // send d to serial monitor so I can see the charector
                                                        Serial.print(stat);
                                      }
                                      }

if (buttonState == LOW) {
                          // turn LED off:
                          Once = 0;
                          digitalWrite(ledPin, LOW);

                          }

  // check if the other pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (button1State == HIGH) {
    if (Once1 == 0) {
          Once1 = 1;
    // turn LED on:
   // digitalWrite(ledPin, HIGH);
    // send ctrl-t to radio
    portOne.write(route);
    } 
  }
  if (button1State == LOW) {
    // turn LED off:
    //digitalWrite(ledPin, LOW);
    Once1 = 0;
  }
    portOne.listen();
      // read data from the Software Serial portOne
   // and send to the hardware serial port:
   while (portOne.available() > 0) {
     char inByte = portOne.read();
     Serial.print(inByte);
   }
}

Breadboard

1 2016-03-09T17:38:40+00:00 0
Tony M
Tony M
編集された質問 9日 3月 2016 в 8:45
Arduino
softwareserial
質問の追加
カテゴリ
すべて
技術情報
文化・レクリエーション
生活・芸術
科学
プロフェッショナル
事業内容
ユーザー
すべて
新しい
人気
1
Roxana Elizabeth CASTILLO Avalos
登録済み 1週間前
2
Hideo Nakagawa
登録済み 1週間前
3
Sergiy Tytarenko
登録済み 1週間前
4
shoxrux azadov
登録済み 1週間前
5
Koreets Koreytsev
登録済み 2週間前
JA
© de-vraag :年
ソース
arduino.stackexchange.com
ライセンス cc by-sa 3.0 帰属