2017-03-09 5 views
-2

こんにちは私は2つの異なるコードを行い、それらが動作することを確認した後、それらを結合しようとすると問題が発生しました。私はGSMモジュールを制御するためにGSM.hを使用していましたが、私はSoftwareSerial.hを使用しました。定義Pin RX、TXなしSoftwareSerial Arduino

これらをコードに組み合わせようとしましたが、この2つのライブラリは互いに競合しています。

誰かが私を助けることができますか?

これは私が代わりにSoftwareSerialのAltSoftSerialライブラリを使用しようと私のコード

//GSM 
#include <GSM.h> 
#define PINNUMBER "3805" 
GSM gsmAccess; // include a 'true' parameter for debug enabled 
GSM_SMS sms; 
//N de telefone de envio 
char remoteNumber[20]= "914181875"; 
//Conteudo do SMS 
char txtMsg[200]="Tester"; 
int val = 0; 
//GPS 
//#include <SoftwareSerial.h> 
#include <TinyGPS.h> 
TinyGPS gps; 
SoftwareSerial ss(4, 3); 

static void print_float(float val, float invalid, int len, int prec); 

int button = 7; 

void setup() 
{ 
    // initialize serial communications 
    pinMode(button, INPUT); 
    Serial.begin(9600); 

    Serial.println("SMS Messages Sender"); 

    // connection state 
    boolean notConnected = true; 

    // Start GSM shield 
    // If your SIM has PIN, pass it as a parameter of begin() in quotes 
    while(notConnected) 
    { 
    if(gsmAccess.begin(PINNUMBER)==GSM_READY) 
     notConnected = false; 
    else 
    { 
     Serial.println("Not connected"); 
     delay(1000); 
    } 
    } 
    Serial.println("GSM initialized"); 
} 

void loop() 
{ 
val = digitalRead(button); 
if (val == HIGH){ 
    sendSMS(); 
    } 
} 

void sendSMS(){ 

    Serial.print("Message to mobile number: "); 
    Serial.println(remoteNumber); 

    // sms text 
    Serial.println("SENDING"); 
    Serial.println(); 
    Serial.println("Message:"); 
    Serial.println(txtMsg); 

    // send the message 
    sms.beginSMS(remoteNumber); 
    sms.print(txtMsg); 
    sms.endSMS(); 
    Serial.println("\nCOMPLETE!\n"); 
} 
+0

。 [良い質問をする方法](http://stackoverflow.com/help/how-to-ask)を参照して、あなたの問題が何であるか、どのようなエラーが発生しているか、期待していることをより明確にするように質問を編集してください取得するなど。 –

答えて

0

です:

https://github.com/PaulStoffregen/AltSoftSerial

このライブラリの欠点は、シリアルのための特定のピンを使用する必要がありますGPSハードウェアとの通信は、現在使用しているピンと異なります。

// AltSoftSerial always uses these pins: 
// 
// Board   Transmit Receive PWM Unusable 
// -----   -------- ------- ------------ 
// Teensy 3.0 & 3.1 21  20   22 
// Teensy 2.0   9  10  (none) 
// Teensy++ 2.0  25   4  26, 27 
// Arduino Uno  9   8   10 
// Arduino Leonardo 5  13  (none) 
// Arduino Mega  46  48  44, 45 
// Wiring-S   5   6   4 
// Sanguino   13  14   12 

は、私がテストしたハードウェアを持っていないが、次のコードはコンパイルん:あなたが求めているものは不明である

//GSM 
#include <GSM.h> 
#define PINNUMBER "3805" 
GSM gsmAccess; // include a 'true' parameter for debug enabled 
GSM_SMS sms; 
//N de telefone de envio 
char remoteNumber[20]= "914181875"; 
//Conteudo do SMS 
char txtMsg[200]="Tester"; 
int val = 0; 
//GPS 
#include <AltSoftSerial.h> 
AltSoftSerial ss; 
#include <TinyGPS.h> 
TinyGPS gps; 

static void print_float(float val, float invalid, int len, int prec); 

int button = 7; 

void setup() 
{ 
    // initialize serial communications 
    pinMode(button, INPUT); 
    Serial.begin(9600); 

    Serial.println("SMS Messages Sender"); 

    // connection state 
    boolean notConnected = true; 

    // Start GSM shield 
    // If your SIM has PIN, pass it as a parameter of begin() in quotes 
    while(notConnected) 
    { 
    if(gsmAccess.begin(PINNUMBER)==GSM_READY) 
     notConnected = false; 
    else 
    { 
     Serial.println("Not connected"); 
     delay(1000); 
    } 
    } 
    Serial.println("GSM initialized"); 
} 

void loop() 
{ 
val = digitalRead(button); 
if (val == HIGH){ 
    sendSMS(); 
    } 
} 

void sendSMS(){ 

    Serial.print("Message to mobile number: "); 
    Serial.println(remoteNumber); 

    // sms text 
    Serial.println("SENDING"); 
    Serial.println(); 
    Serial.println("Message:"); 
    Serial.println(txtMsg); 

    // send the message 
    sms.beginSMS(remoteNumber); 
    sms.print(txtMsg); 
    sms.endSMS(); 
    Serial.println("\nCOMPLETE!\n"); 
} 
+0

あなたの助けにThx、はいそれはコンパイルしますが、ハードウェアはそれらの間のポートの競合を開始します。どのように私はそれを停止するのですか? –

関連する問題