Its a code of W7500 board for the vending machine to vend an item to the user within the organization. When the user is identified with the help of the RFID reader and when the user choose the item . the data is sent serially to WIZ750SR and the item is vended . The LCD displays the details of the transaction.
Dependencies: HCSR04 MFRC522 TextLCD mbed-src
Fork of RFID_copy by
Revision 1:6cd395827886, committed 2018-07-17
- Comitter:
- HarshaDRAGNEEL
- Date:
- Tue Jul 17 05:59:27 2018 +0000
- Parent:
- 0:1fdb07d055b9
- Commit message:
- Its a program to identify the user using RFID tag and vend an item to the user with displaying the details in LCD and the data is serially transmitted to WIZ750SR
Changed in this revision
diff -r 1fdb07d055b9 -r 6cd395827886 HCSR04.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Tue Jul 17 05:59:27 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/antoniolinux/code/HCSR04/#86b2086be101
diff -r 1fdb07d055b9 -r 6cd395827886 MQTT.lib --- a/MQTT.lib Thu Jun 07 04:14:28 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/jamesabruce/code/MQTT/#d3feba7f242a
diff -r 1fdb07d055b9 -r 6cd395827886 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Jul 17 05:59:27 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
diff -r 1fdb07d055b9 -r 6cd395827886 WIZnetInterface.lib --- a/WIZnetInterface.lib Thu Jun 07 04:14:28 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#bda61525ac71
diff -r 1fdb07d055b9 -r 6cd395827886 main.cpp --- a/main.cpp Thu Jun 07 04:14:28 2018 +0000 +++ b/main.cpp Tue Jul 17 05:59:27 2018 +0000 @@ -1,9 +1,6 @@ -//Test of cheap 13.56 Mhz RFID-RC522 module from eBay -//This code is based on Martin Olejar's MFRC522 library. Minimal changes -//Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too - + //Connect as follows: -//RFID pins -> Nucleo header CN5 (Arduino-compatible header) +//RFID pins, motor //---------------------------------------- //RFID IRQ=pin5 -> Not used. Leave open //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 @@ -12,82 +9,76 @@ //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 //RFID RST=pin7 -> Nucleo =PA_9=D8 //3.3V and Gnd to the respective pins - +// 1st Motor transistor to Pin D9 +// 2nd Motor transistor to Pin D14 +// Pin D0 to pin 2 of the serial Cable +// pin D1 to pin 3 of the serial cable +// pin A0 to the trigger of ultrasonic sensor 1 +// pin A1 to the Echo of ultrasonic sensor 1 +// pin D2 to RS pin of LCD +// pin D3 to E pin of LCD +// pin D4 to D4 pin of LCD +// pin D5 to D5 pin of LCD +// pin D6 to D6 pin of LCD +// pin D7 to D7 pin of LCD + +//--------------------------------------------- #include "mbed.h" #include "MFRC522.h" #include "SPI.h" -#include "MQTTEthernet.h" -#include "MQTTClient.h" - +#include "hcsr04.h" +#include "TextLCD.h" #define ECHO_SERVER_PORT 7 - -// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8) -//#define MF_RESET D8 - #define SPI_MOSI D11 #define SPI_MISO D12 #define SPI_SCK D13 #define SPI_CS D10 -#define MF_RESET D9 -DigitalOut l1(D4); -DigitalOut l2(D5); -DigitalOut LedGreen(LED1); - +#define MF_RESET D8 +TextLCD lcd(D2, D3, D4, D5, D6, D7,TextLCD::LCD20x4); // rs, e, d4-d7 +DigitalOut myled(D9); +DigitalOut myled1(D14); +//DigitalOut myled2(D15); Can be enabled for 3rd motor slot. + +HCSR04 sensor(A0,A1); // Trigger , Echo +HCSR04 sensor1(A2,A3); //Trigger , Echo +//HCSR04 sensor2(A4,A5); //Trigger , Echo Can enable if needed for 3rd slot. + +void distance(); +void display(); + //Serial connection to PC for output -//Serial pc(USBTX, USBRX); - +Serial pc(USBTX, USBRX); +// Serial connection with WIZ750SR gateway for MQTT communication +Serial serial(D1,D0); //TX and RX +// Initializing RFID chip pins MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); - + char c; + int d; int main(void) { - //pc.printf("starting...\n"); - - Serial pc(USBTX, USBRX); - pc.baud(115200); - printf("Wait a second...\r\n"); - char* topic = "openhab/parents/command"; - MQTTEthernet ipstack = MQTTEthernet(); - - MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack); - - char* hostname = "172.16.73.4"; - int port = 1883; - - int rc = ipstack.connect(hostname, port); - if (rc != 0) - printf("rc from TCP connect is %d\n", rc); - - printf("Topic: %s\r\n",topic); - - MQTTPacket_connectData data = MQTTPacket_connectData_initializer; - data.MQTTVersion = 3; - data.clientID.cstring = "parents"; - - if ((rc = client.connect(data)) == 0) - printf("rc from MQTT connect is %d\n", rc); - + pc.printf("starting...\n"); + myled=0; + pc.printf("Wait a second...\r\n"); + //Init. RC522 Chip RfChip.PCD_Init(); while (true) { - //LedGreen = 1; - pc.printf("enterd loop...\n"); + pc.printf("enterd RFID reading loop...\n"); // Look for new cards if ( ! RfChip.PICC_IsNewCardPresent()) { wait_ms(500); continue; } - - // Select one of the cards + // Select one of the cards if ( ! RfChip.PICC_ReadCardSerial()) { wait_ms(500); continue; } - - //LedGreen = 0; - char data[20]=""; - char data1[20]=""; + + char data[20]=""; + char data1[20]=""; // Print Card UID pc.printf("Card UID: "); @@ -100,39 +91,101 @@ strcat(data,temp); } - /* - pc.printf("\n\r"); - printf("%s\n\r",data); - */ - // Print Card type uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); pc.printf(" \nPICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); wait_ms(1000); - if(strcmp(data,"5C02820285024502")==0) + if(strcmp(data,"BA0211026102D302")==0) //Comparing the stored data with the new data read by the RFID reader. { - strcat(data1,"fruits"); + strcat(data1,"natsu"); + wait(1); + serial.printf("%s",data1); + wait(2); + distance(); } - if(strcmp(data,"B3026802A002202")==0) - { - strcat(data1,"vegatables"); - } - if(strcmp(data,"F2029C02AC021F02")==0) + if(strcmp(data,"E8028002AC02E902")==0) { - strcat(data1,"milk"); - - MQTT::Message message; - char buf[100]; - sprintf(buf, "%s", data1); - message.qos = MQTT::QOS0; - message.retained = false; - message.dup = false; - message.payload = (void*)data1; - message.payloadlen = strlen(data1); - rc = client.publish("grocery", message); - client.yield(60000); - memset(data1, '\0',sizeof(data1)); - } + strcat(data1,"luffy"); + wait(1); + serial.printf("%s",data1); + wait(2); + distance (); + } + pc.printf("The user name is :%s \n",data1); + } } -} \ No newline at end of file + + +void distance() +{ + + pc.printf("Entered into distance loop \n"); + while(1){ + long distance = sensor.distance(); + wait(0.5); + long distance1 = sensor1.distance(); + wait(0.5); + // long distance2 = sensor2.distance(); //can be enabled if connected to 3rd Ultrasonic sensor + pc.printf("distance %d \n",distance); + pc.printf("distance %d \n",distance1); + // pc.printf("distance %d \n",distance2); //can be enabled if connected to 3rd Ultrasonic sensor to enable it in the PC. + wait(1); + + wait(1.0); // 1 sec + if(distance<=10){ + myled= 1; + wait(3); + myled=0; + serial.printf("/drink"); + c = '\0'; + c = 'd'; + d=15; + display(); + pc.printf("/ item drink /cost 15"); + break; + } + else if(distance1<=10){ + myled1= 1; + wait(3); + myled1=0; + serial.printf("/snack"); + c = '\0'; + c = 's'; + d=10; + display(); + pc.printf("/item snack /cost 10"); + break; + } + /* else if(distance2<=10){ + myled1= 1; + wait(30); + myled1=0; + serial.printf("/choco"); + c = '\0'; + c = 's'; + d=10; + display(); + pc.printf("/snack/10"); + break; + } */ //Can be enabled when 3rd ultrasonic is connected. + + } + } + + //function for LCD display .... + +void display(){ + lcd.locate(3,0); + lcd.printf("Vending Machine\n"); + lcd.locate(0,2); + if(c=='d'){ + lcd.printf("ITEM NAME: drink"); + } + else if(c=='s') + { + lcd.printf("ITEM NAME: Snack"); + } + lcd.locate(0,3); + lcd.printf("ITEM COST: %d",d); + }
diff -r 1fdb07d055b9 -r 6cd395827886 mbed-src.lib --- a/mbed-src.lib Thu Jun 07 04:14:28 2018 +0000 +++ b/mbed-src.lib Tue Jul 17 05:59:27 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-src/#2d5fc5624619 +http://mbed.org/users/mbed_official/code/mbed-src/#a11c0372f0ba