strcmp刹车Arduino草图

时间:2018-02-12 17:28:00

标签: c++ arduino esp8266 rfid strcmp

对于学校项目,我使用的是Arduino Uno以及Parallax RFID,LCD屏幕和esp8226-wifi模块。

我正在尝试将扫描的标记与数据库中的标记进行比较,并将标记所有者的名称发送到Blynk应用中的终端。一切正常,直到我输入比较标签的功能。如果我这样做,一切都停止工作,甚至是setup()部分中的代码。我该如何解决这个问题?

我认为这个问题与strcmp有关。

/* Libraries that need to be manually installed:
Blynk libraries: https://github.com/blynkkk/blynk-library/releases/download/v0.5.0/Blynk_Release_v0.5.0.zip
LiquidCrystal_I2C library: https://cdn.instructables.com/ORIG/FVH/K8OQ/J8UH0B9U/FVHK8OQJ8UH0B9U.zip
 */
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

//Setting up the Blynk wifi connection
#define ESP8266_BAUD 9600
char auth[] = "87b00838cd834e4e87a0422265cc7a9e";
char ssid[] = "bbox2-56b2";
char pass[] = "91C2D797F6";

//Setting up the virtual pins
WidgetTerminal terminal(V1);
BLYNK_WRITE(V1){}

//Setting up the RFID
#define RFIDEnablePin 8
#define RFIDSerialRate 2400 
String RFIDTAG=""; //Holds the RFID Code read from a tag
String DisplayTAG = ""; //Holds the last displayed RFID Tag

//Setting up the LCD
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//Setting up the serial connection
SoftwareSerial EspSerial(2, 3);
ESP8266 wifi(&EspSerial);

void setup()
{
//Serial communication
Serial.begin(RFIDSerialRate);
EspSerial.begin(ESP8266_BAUD);
Serial.begin(RFIDSerialRate);
delay(10);

//Blynk setup
Blynk.begin(auth, wifi, ssid, pass);

//LCD setup
lcd.begin(16,2);//16 kolommen, 2 rijen
lcd.backlight();

//RFID setup
pinMode(RFIDEnablePin,OUTPUT);
digitalWrite(RFIDEnablePin, LOW);

terminal.println("Terminal printing succesfull");
terminal.flush();
}

void loop()
{
  if(Serial.available() > 0)
  { 
  ReadSerial(RFIDTAG);
  }

  if(DisplayTAG!=RFIDTAG)
  {
    DisplayTAG=RFIDTAG;
// PROBLEM STARTS HERE
  //Tag database
  char tags[10][10] = {"6196", "6753", "5655", "69EC", "9FFC"};
  char owners[10][30] = {"per1", "per2", "per3", "per4", "per5"};
  int i = 0;
  int j = 0;
  int ownerLength = 0;
  char lastTag[10];

  RFIDTAG.toCharArray(lastTag, 10);

    while (i < 10)
    {
      if (strcmp(tags[i], lastTag) == 0)
      {
        ownerLength = strlen(owners[i]);
        while (j < ownerLength)
        {
          terminal.print(owners[i][j]);
        }
          terminal.println("has entered the parking\n\r");
          terminal.flush();
          break;
      }
      i++;
    }
    i = 0;
    j = 0; 
//PROBLEM ENDS HERE
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Last tag:");
    lcd.setCursor(0,1);
    lcd.print(RFIDTAG);
    digitalWrite(RFIDEnablePin, HIGH);
    delay(1000);
    digitalWrite(RFIDEnablePin, LOW);
  }
  Blynk.run();
}

//Function for reading the tag 
void ReadSerial(String &ReadTagString)
{
  int bytesread = 0;
  int val = 0; 
  char code[10];
  String TagCode="";

  if(Serial.available() > 0)
  {  
    if((val = Serial.read()) == 10)
    {
      bytesread = 0; 
      while(bytesread<10) // Reads the tag code
      { 
        if( Serial.available() > 0) 
        { 
          val = Serial.read(); 
          if((val == 10)||(val == 13)) // If header or stop bytes before the 10 digit reading
          {  
            break; // Stop reading 
          } 
          code[bytesread] = val; // Add the digit 
          bytesread++; // Ready to read next digit 
        } 
      } 
      if(bytesread == 10)  // If 10 digit read is complete
      {
        for(int x=6;x<10;x++) //Copy the Chars to a String
        {
          TagCode += code[x];
        }
        ReadTagString = TagCode; //Returns the tag ID
        while(Serial.available() > 0) //Burn off any characters still in the buffer
        {
        Serial.read();
        }

      } 
      bytesread = 0;
      TagCode="";
    } 
  } 
}

0 个答案:

没有答案