Pages: [1]   Go Down
Author Topic: ONBOARD PASSENGER INFORMATION SYSTEM FOR BLIND AND DEAF (help)  (Read 832 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I intend to implement a system that will inform the blind through speaker and the deaf through lcd display in passenger vehicles.The different rfid tags represent different stages and hold the info about what to display through lcd and say through speakers.
Its a school project.
My code was able to display the different stages but not say the differnt stages. Code 1 is the code of the program while code2 is for the speaker through speakjet incase you want to have a look.

Code:
/**
 * ONBOARD PASSENGER INFORMATION SYSTEM FOR BLIND AND DEAF
 *
 * RFID tags initiate display of different towns on lcd.
 * Iam unable to make the speakjet say the respective towns please help
 * The code compiled without an error in arduino program. Attached find also the working code of speakjet
 * http://www.practicalarduino.com/projects/medium/rfid-access-control
 */

// Set up the serial connection to the RFID reader module. In order to
// keep the Arduino TX and RX pins free for communication with a host,
// the sketch uses the SoftwareSerial library to implement serial
// communications on other pins.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 4, 5, 6, 7, 8);
// The RFID module's TX pin needs to be connected to the Arduino.

 #define rxPin 9
 #define txPin 5
#define TxPin 10
#define RxPin 11

// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );
SoftwareSerial SpeakJetSerial =  SoftwareSerial(RxPin, TxPin);

// Set up outputs
#define futureOutput 12
#define ledPin 13

// Specify how long the output should be held.
#define unlockSeconds 2

// The tag database consists of two parts. The first part is an array of
// tag values with each tag taking up 5 bytes. The second is a list of
// names with one name for each tag (ie: group of 5 bytes). You can expand
// or shrink this as you see fit. Tags 2 and 3 are only there for example.
char* allowedTags[] = {
  "4500F34653",         // Tag 1
  "4500F38746",         // Tag 2
  "ABC123DE45",         // Tag 3
};

// List of names to associate with the matching tag IDs
char* tagName[] = {
  "Juja",      // Tag 1
  "Thika",      // Tag 2
  "NAME 3",       // Tag 3
};

char* SayIt[] = {
"20, 96, 21, 114, 22, 128, 23, 5, 165, 138, 165, 132",
"191, 129, 195, 135",
"45,556,35,33,56,09",
};

// Check the number of tags defined
int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);

int incomingByte = 0;    // To store incoming serial data

/**
 * Setup
 */
void setup() {
  lcd.clear(); //Clears LCD
 lcd.setCursor(0, 0);
 lcd.print("  Please Swipe");

  pinMode(ledPin, OUTPUT);
  pinMode(TxPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(futureOutput, OUTPUT);
  digitalWrite(futureOutput, LOW);
  SpeakJetSerial.begin(9600);

  Serial.begin(9600);   // Serial port for connection to host
  rfid.begin(9600);      // Serial port for connection to RFID module

//  Serial.println("RFID Reader Initialized");
}

/**
 * Loop
 */
void loop() {
  byte i         = 0;
  byte val       = 0;
  byte checksum  = 0;
  byte bytesRead = 0;
  byte tempByte  = 0;
  byte tagBytes[6];    // "Unique" tags are only 5 bytes but we need an extra byte for the checksum
  char tagValue[10];

  // Read from the RFID module. Because this connection uses SoftwareSerial
  // there is no equivalent to the Serial.available() function, so at this
  // point the program blocks while waiting for a value from the module
  if((val = rfid.read()) == 2) {        // Check for header
    bytesRead = 0;
    while (bytesRead < 12) {            // Read 10 digit code + 2 digit checksum
      val = rfid.read();

      // Append the first 10 bytes (0 to 9) to the raw tag value
      if (bytesRead < 10)
      {
        tagValue[bytesRead] = val;
      }

      // Check if this is a header or stop byte before the 10 digit reading is complete
      if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) {
        break;                          // Stop reading
      }

      // Ascii/Hex conversion:
      if ((val >= '0') && (val <= '9')) {
        val = val - '0';
      }
      else if ((val >= 'A') && (val <= 'F')) {
        val = 10 + val - 'A';
      }

      // Every two hex-digits, add a byte to the code:
      if (bytesRead & 1 == 1) {
        // Make space for this hex-digit by shifting the previous digit 4 bits to the left
        tagBytes[bytesRead >> 1] = (val | (tempByte << 4));

        if (bytesRead >> 1 != 5) {                // If we're at the checksum byte,
          checksum ^= tagBytes[bytesRead >> 1];   // Calculate the checksum... (XOR)
        };
      } else {
        tempByte = val;                           // Store the first hex digit first
      };

      bytesRead++;                                // Ready to read next digit
    }

    // Send the result to the host connected via USB
    
    if (bytesRead == 12) {                        // 12 digit read is complete
      tagValue[10] = '\0';                        // Null-terminate the string

      lcd.clear(); //Clears LCD
 lcd.setCursor(0, 1);
// lcd.print("  Please Swipe");

      lcd.print("Tag read: ");
      for (i=0; i<5; i++) {
        // Add a leading 0 to pad out values below 16
        if (tagBytes[i] < 16) {
          lcd.print("0");
        }
        lcd.print(tagBytes[i], HEX);
      }
     // lcd.println();

    //  Serial.print("Checksum: ");
      //Serial.print(tagBytes[5], HEX);
   //   Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");

      // Show the raw tag value
   //   Serial.print("VALUE: ");
     // Serial.println(tagValue);

      // Search the tag database for this particular tag
      int tagId = findTag( tagValue );

      // Only fire the strike plate if this tag was found in the database
      if( tagId > 0 )
      {
       // lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Welcome to ");
      //  Serial.print(tagId);
      //  Serial.print(": unlocking for ");
        lcd.print(tagName[tagId - 1]);   // Get the name for this tag from the database
         SpeakJetSerial.println(SayIt[tagId - 1]);  //say the name of the stage      
                                
      } else {
        lcd.print("Tag not authorized");
      }
     // Serial.println();     // Blank separator line in output
    }

    bytesRead = 0;
  }
}

/**
 * Fire the relay to activate the strike plate for the configured
 * number of seconds.
 */


/**
 * Search for a specific tag in the database
 */
int findTag( char tagValue[10] ) {
  for (int thisCard = 0; thisCard < numberOfTags; thisCard++) {
    // Check if the tag value matches this row in the tag database
    if(strcmp(tagValue, allowedTags[thisCard]) == 0)
    {
      // The row in the database starts at 0, so add 1 to the result so
      // that the card ID starts from 1 instead (0 represents "no match")
      return(thisCard + 1);
    }
  }
  // If we don't find the tag return a tag ID of 0 to show there was no match
  return(0);
}


****************************************************************************
Code:

// letsmakerobots demo
// code to make speaker say letsmakerobots

// set up a new software serial port
//rxPin: the pin on which to receive serial data
//txPin: the pin on which to transmit serial data
#include <SoftwareSerial.h>
#define txPin 2
#define rxPin 3
// set up the SoftwareSerial port to connect to the SpeakJet
SoftwareSerial SpeakJetSerial =  SoftwareSerial(rxPin, txPin);

void setup()
{
  // define pin modes for tx, rx pins:
  //pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  SpeakJetSerial.begin(9600);
 
  // char array holding the 'lets make robots' string we want to speak
  char SayIt[] = {20, 96, 21, 114, 22, 88, 23, 5, 145, 131, 193, 6, 140, 154, 196, 6, 148, 7, 137, 7, 164, 18, 171, 136, 193};//codes from phrasealator
  SpeakJetSerial.println(SayIt); // send it to the SpeakJet
}

void loop()
{
  // infinite do-nothing loop
}
« Last Edit: November 22, 2011, 02:49:32 am by AWOL » Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assuming that the second piece of code works with the speakjet, your issue with the first one may be that you've converted the byte data into strings - they're not the same. The working(?) code sends characters 20, 96,21 etc. For the first tag, yours sends characters 50, 48, 44, 32 etc. which is '2' '0' ',' ' '. Not the same thing at all. Also, shouldn't there be a null at the end of the char array in the second example?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define rxPin 9
 #define txPin 5
#define TxPin 10
#define RxPin 11
It is a poor practice to create variable names that differ only in case. Use meaningful names.

Quote
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );
SoftwareSerial SpeakJetSerial =  SoftwareSerial(RxPin, TxPin);
Obsolete. Use NewSoftSerial, instead.

You have way too much going in loop. Put the code to read the RFID tag in a function.

Code:
     // lcd.println();
Don't need it? Delete it!!!!

Your real problem, as wildbill points out, is that your SayIt array is crap.
Logged

Western New York, USA
Online Online
Faraday Member
**
Karma: 40
Posts: 4399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Off Topic:
Quote
Obsolete. Use NewSoftSerial, instead.
I wonder what they are going to call the next version....

Don
Logged

Western New York, USA
Online Online
Faraday Member
**
Karma: 40
Posts: 4399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

Code:
    // lcd.println();

Don't need it? Delete it!!!!

It's worse than that ... there is no lcd.println() function.

Don
Logged

Pages: [1]   Go Up
Jump to: