Multiple slave devices to one arduino master...

hey... i am trying to couple few sensors in arduino Uno.. my main aim is to use the lcd 1602 display a message as in "insert ur card".. thn rfid mfrc522 sacns the card.. n displays the message on lcd... also i need to activate the gsm sim900a modem and gps to take the location n speed and keep storing them...
i got success with getting the code individually but when i combine the code...

firstly the LCD and RFID when combined togethr only the lcd works and control is not passed to RFID and the same in case of GPS...

I have done quite research on this topis as well.. n i hav reached to one thing tht is SPI or I2c.. bt i dnt want to increase anothr hardware by using I2C...
so can i do something with SPI???

but even there is dbt with that cz.. SPI requires the ss pin , address of all the slave devices..
but i dont know the slave select pin for lcd , gsm and gps cz there is no CS or SS pin on their hardware... so which pin should i initialise as SS for them??
Can someone help asap... its little urgent as its my final yr projct..
i am attaching the code below fr reference...
Thanks in advance...

You need to post links to the datasheets for the different peripherals you are using (apart from the LCD device)

You need to tell us what Arduino board you are using

...R

Robin2:
You need to post links to the datasheets for the different peripherals you are using (apart from the LCD device)

You need to tell us what Arduino board you are using

...R

hey thankz fr quick response... :slight_smile:
but i have menyioned m using an Arduino UNO...
n the datasheet for MFRC522 is http://www.nxp.com/documents/data_sheet/MFRC522.pdf
n this is my gps module from whr i hav bought this... http://www.vishaworld.com/index.php/s1315rl---gps-receiver-with-external-anteena-detail

n m using gsm sim900a SIM900A Datasheet PDF - Datasheet4U.com
... will that do sir???

The first document has 95 pages and the third one seems to have more than 50. I can't see the second one - maybe because my internet connection is misbehaving.

I was hoping for a 2 or 3 page overview that would give details of how each device interfaces with the Arduino.

Can you point out the relevant pages please.

Sorry, I missed the reference to the Uno.

...R

hey... sorry for the lengthy references...

below m referencing other sites... plz kindly check out will that do... n if u want i ll also upload my wiring diagram so even tht might help...

RFID - Addicore RFID Quick Start Guide for Arduino (pdf)

LCD 16*02 -

GSM SIM900A - http://www.instructables.com/id/Interfacing-SIM900A-GSM-Modem-with-Arduino/step2/Making-Connections/

n am not getting a datasheet for gps s1315rl... :frowning: but i have done the coonnection and coding as it is said in the arduino playground - MFRC522 Arduino Playground - GPS

Thanku...

Thanks.

It seems that the RFID uses an SPI connection - that must use certain pins.
The LCD can use any pins - it is just getting HIGHs and LOWs
The SIM card and the GPS require two separate serial connections.

Because of the requirement for the two serial connections I suggest using a Mega which has 3 spare HardwareSerial connections.

You can add one extra SoftwareSerial port on an Uno and (in theory) you could use its HardwareSerial for the other serial connection. But it is very very much easier if you leave the HardwareSerial port free for uploading software and debugging and if you do that you won't have enough serial ports.

...R

I agree with Robin2.

Lets calculate
Say,
0,1 for PC to arduino
2,3 (softserial) to SIM
4,5 (softserial) to GPS
10,11,12,13 for RFID
SCL,SDA(A$,A5) for LCD with IIC backpack,which will make interface easier.

Now, We have pins 6,7,8,9 and A0,A1,A2,A3 = 8 pins in total.
In theory, We can do al this on a UNO.

You are the one who has the hardware. Try it and respond.
It'll be nice if you post the combined code and libraries you used. (compressed,as you downloaded those in the form,not links.)
Please tell the IDE version.

Maybe, You live in India.Correct me if I am wrong. It'll be nice if you tell me where.

Please try to use nicer language,without the short forms like 'u','r',etc. You are posting in an international forum, not sending a message on Whatsapp to a close friend. No offence. I know that this is arduino forum,not a language class,but it is hard to read in that format.
When you post code and links,try to use the appropriate tags.

I am really very sorry for the short forms... sorry..
and yes I am from India...

Thanku soo much for your suggestions..
I am attaching my code below with what I could come up till now... kindly have a look on it.. also I have made a rough wiring diagram...

#include <LiquidCrystal.h>
#include <SPI.h> 
#include <MMA_7455.h> 
#include <MFRC522.h> 
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

int SS_PIN = 14;  
int RST_PIN = 9;  

SoftwareSerial gsm(10,9);
SoftwareSerial mySerial(16,15 );
MMA_7455 tilt = MMA_7455();                                                                  //Make an instance of MMA_7455
LiquidCrystal lcd(0, 1, 5, 4, 3, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 
Adafruit_GPS GPS(&mySerial);
char xVal, yVal, zVal;                                                                                   
int backLight = 6;
int TRIGPIN =  7;
int ECHOPIN = 8;                                                                                     
int pir = 17;                                                                                      
int pirState = LOW;                                                                                 
int val = 0;                                                                                       
int speaker = 13;     
int red = 12;
int green = 11;

#define GPSECHO  true
#define MASTERCARD  4294943745


void setup() {
  SPI.begin();  
  Serial.begin(9600);
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print(F("Please Insert Ur"));
  lcd.setCursor(2,1);
  lcd.print(F("MASTERCARD"));
  delay(10000);
  digitalWrite(backLight, LOW);
  delay(2000);
  digitalWrite(backLight, HIGH);
  delay(1000);
  digitalWrite(backLight,LOW);
  delay(100);
  tilt.initSensitivity(2);   
  mfrc522.PCD_Init(); // Init MFRC522 
  mfrc522.PCD_DumpVersionToSerial();  
  Serial.println(F("PLease Scan Your MASTERCARD...")); 
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(red, OUTPUT);  
  pinMode(green,OUTPUT);    
  pinMode(pir, INPUT);     
  pinMode(speaker, OUTPUT);
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  GPS.sendCommand(PGCMD_ANTENNA);
}
/*Code to get Card UID */

unsigned long getID(){ 
if ( ! mfrc522.PICC_ReadCardSerial()){
return -1; 
}
unsigned long hex_num; 
hex_num = mfrc522.uid.uidByte[0] << 24; 
hex_num += mfrc522.uid.uidByte[1] << 16; 
hex_num += mfrc522.uid.uidByte[2] << 8; 
hex_num += mfrc522.uid.uidByte[3]; 
mfrc522.PICC_HaltA(); // Stop reading 
return hex_num; 
}

void loop() {
  analogWrite(SS_PIN,100);
  
unsigned long uid; 
if(mfrc522.PICC_IsNewCardPresent()) { 
uid = getID(); 
if(uid != -1)
    { 
    Serial.print(F("Card detected, UID: ")); Serial.println(uid); 
    if(uid==MASTERCARD){
        delay(10);
        lcd.clear();
        lcd.print(F("Enjoy Your Drive.. "));
        lcd.setCursor(0,1);
        lcd.print(F(":)"));
        pinMode(backLight,HIGH);
        delay(10000);
        lcd.clear();     
        digitalWrite(green,HIGH);
        delay(1000);
        digitalWrite(green,LOW);
        delay(1000);
        digitalWrite(green,HIGH);
            xVal = tilt.readAxis('x'); //Read out the 'x' Axis
            yVal = tilt.readAxis('y'); //Read out the 'y' Axis
            zVal = tilt.readAxis('z'); //Read out the 'z' Axis
              if (xVal < -20 || xVal >  20 || zVal < -45 )
                   {
                      Serial.println("");
                      tone(speaker, 500, 1000);
                      lcd.clear();
                      lcd.setCursor(2,0);
                      lcd.print(F("Accident")); 
                      lcd.setCursor(2,1);
                      lcd.print(F("Detected")); 
                      digitalWrite(red,HIGH);// turn LED On
                      delay(1000);
                      digitalWrite(red,LOW);// turn LED On
                   
     //GPS CODING...!!!!!
  /*
    if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {  
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
    return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2500) { 
    timer = millis(); // reset the timer
    
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 
*/
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", "); 
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", "); 
      Serial.println(GPS.longitudeDegrees, 4);
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      //delay(10000);
      Serial.println("");
      Serial.println("Sending to Database...");
      Serial.println("");
      Serial.println("");
  }
  
    // Ultrasonic Sensor...!!!!
      digitalWrite(TRIGPIN, LOW);
      delayMicroseconds(1000);
      digitalWrite(TRIGPIN, HIGH);
      delayMicroseconds(1000);
      digitalWrite(TRIGPIN, LOW);
      
      //Distance calculation
      float distance = pulseIn(ECHOPIN, HIGH);
      distance= distance/58;
      delay(1000);
      if (distance>=2 && distance<=50){
      lcd.clear();
      lcd.setCursor(1,0);
      lcd.print(distance);
      lcd.println(F(" cm"));
      lcd.setCursor(3,1);
      lcd.print("DANGER");
      digitalWrite(red,HIGH);
      tone(speaker, 500, 500);
      Serial.println("");
      
  }
  else {
      lcd.clear();
      digitalWrite(red,LOW);
      noTone(speaker);
  }
  }
  }
  
  // IF FAKE CARD INSERTED...!!!
    else {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.println(F("Access Denied..."));
        lcd.clear();
        lcd.setCursor(0,1);
        lcd.println(F(":( ..."));
        digitalWrite(TRIGPIN, LOW);
        tone(speaker, 500, 500);
        exit;
        }
    }  
    

  // PIR MOTIION SENSOR WHEN CARD IS ABSENT....!!!
    else
        {
        digitalWrite(TRIGPIN, LOW);
        val = digitalRead(pir);             // read Sensor_Pin
        if (val == HIGH)                        // check if the input is HIGH
          {            
          digitalWrite(red,HIGH);          // turn LED On
          tone(speaker, 500, 500);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(F("UNAUTHORISED"));
          lcd.setCursor(2,1);
          lcd.print("ACCESS...");
}
        else {
              digitalWrite(red,LOW);
              noTone(speaker);
             }
          }
}

I am using the ICSP pins for RFID

MalharD:
2,3 (softserial) to SIM
4,5 (softserial) to GPS

Two instances of SoftwareSerial will not work.

...R

Robin2:
Two instances of SoftwareSerial will not work.

...R

You mean I can use only one software serial instance??
So what if I use - softwareserial gps (3,2);
and sim by default uses 0 and 1 right, so let them be?
I guess that will do..
Also i just tested my gps and rfid together and they work properly.. :slight_smile:

Pratz:
and sim by default uses 0 and 1 right, so let them be?

I dealt with that in Reply #5. Among other things you will have to remove it to upload programs.

...R

There are too many peripherals.
Just go with MEGA,I found one on flipkart only for RS.900(~$15),shipping included(clone,obviously).
this solves the problem of pins and serial ports readily.
Which project you planned with all those things ?

MalharD:
There are too many peripherals.
Just go with MEGA,I found one on flipkart only for RS.900(~$15),shipping included(clone,obviously).
this solves the problem of pins and serial ports readily.
Which project you planned with all those things ?

actually the thing is its my final year project for diploma... and I have already spent too much buying so many peripherals so I cant buy a new Mega nowz... I have to try doing it UNO itself...

And I am basically making a device for vehicles which works on rfid.. when rf is not inserted the PIR will be active and detect if there is any motion of the vehicle and sends message to owner... and if a fake RF is inserted it denies the access and again notifies the owner... and lastly when a proper rf is inserted the GPS, Tilt, ultrasonic sensor gets activated and the information of vehicle's location ,speed etc are stored in database frequently.... The ultrasonic sensor notifies the user inside the car if some object comes infront of it.. and lastly the tilt sensor detects any tilt of car and if it detects, it sends message to nearby hospital and registered contacts...
So for notifying user inside the vehicle I need LCD interfaced...

Can you provide some suggestions???

What if someone disables that all ???
If I were the thief and found a 1602 LCD on dashbord,I will pull the LCD out and short its Power pins. Bingo! I have disabled all security you fitted in.
What if the tilt sensor misbehaves in case of aggressive breaking or hard turns ?
What if the vehicle is in remote areas where range is not avaliable?

Can't you spare a 1000?? Just don't buy new shoes or skip a trip to restaurant for your Diploma/Future !

Your Location?

haha... :slight_smile:

Yeahh you are right... But I am just trying if it works on arduino UNO... atleast I should give it a try right??
Moreover... I am actually much sorted nows after your and Robin2 advices...
I tried with the RFID, GPS and LCD and they are going good...
lastly I'll be left with the GSM... which I'll be experimenting on today...
Its just that... all these components working effeciently on an arduino UNO board is tough challenge and I wont to do it because its gonna teach me a lot.. as it will get very simplified with arduino mega but UNO is a challenge... :slight_smile: No offenses...
and my location I mentioned previously INDIA- Mumbai... :slight_smile:
Thankyou...

1 Like

Pratz:
haha... :slight_smile:

Yeahh you are right... But I am just trying if it works on arduino UNO... atleast I should give it a try right??
Moreover... I am actually much sorted nows after your and Robin2 advices...
I tried with the RFID, GPS and LCD and they are going good...
lastly I'll be left with the GSM... which I'll be experimenting on today...
Its just that... all these components working effeciently on an arduino UNO board is tough challenge and I wont to do it because its gonna teach me a lot.. as it will get very simplified with arduino mega but UNO is a challenge... :slight_smile: No offenses...
and my location I mentioned previously INDIA- Mumbai... :slight_smile:
Thankyou...

Yeah. I like that approach.
Best luck.
Sorry, I wasn't reading carefully.Mumbai. I get it.

If you can't get it working on UNO,you can find a MEGA easily in Mumbai.
I was asking about location because I wanted to see how easily you can get the components.
Great. Keep up and tell us your success story.

MalharD:
Yeah. I like that approach.
Best luck.
Sorry, I wasn't reading carefully.Mumbai. I get it.

If you can't get it working on UNO,you can find a MEGA easily in Mumbai.
I was asking about location because I wanted to see how easily you can get the components.
Great. Keep up and tell us your success story.

Thankz alot seriously... for such a great response... And yes will surely post if i succeed and also if i dont , with another doubt... Thankyou... :slight_smile: