Arduino Mega 2560 RFID Serial Communication

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an RFID reader:

Something like same above along with ITEAD TFT shield & GSM Modem. The RFID reader has RS-232 port as well as GND,TX and 5V pins. I am using Arduino Mega 2560 Board. I have connected the TX,GND of RFID reader to RX3 pin 15 / GND (pin) of Arduino. Note I am supplying 12 V to RFID via a adapter.

Note the ITEAD TFT shield consumes TX0, RX0 pins - so I cannot make use of RX0 and TX0 pins. Though I have not written the code for GSM modem.

Now while running the below program I am getting junk output both in my TFT display as well as serila monitor:

#define __AVR__
#include <UTFT.h>


extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(ITDB24,59,58,57,56);
String myString = "";

void setup() {
   Serial3.begin(9600);
   myGLCD.InitLCD();
   myGLCD.clrScr();
}

void loop() {
  myGLCD.setFont(BigFont);
  if (Serial3.available()) {
    int inByte = Serial3.read();
     myString += String(inByte);
    }
    if(myString.length() == 10)
      myGLCD.print(myString, CENTER, 0);
}

 

TFT Screen output:

1310494848

Serial Monitor Output- non printable junk character.

The value is incorrect I am pretty sure, what wrong am I doing?

I found that ITEAD shield is sending or rather using RX0/TX0 pins very frequently - some data is going thru.

BTW what is the functionality of http://arduino.cc/en/Tutorial/So... ?

Well in all other words "How can I use 3 different Serial I/Os individually at same time without disturbing any other I/O?"

Last Edited: Wed. Nov 5, 2014 - 09:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was finally able to solve the issue. The issue is that String Object in Arduino does not supports '+' operator (I was assuming to concat the values). As such my string variable was always empty and nothing got printed in TFT.

 

The below code works fine and I am able to integrate RFID reader at Serial port 3 along with displaying of data in ITEAD TFT screen :

 

#define __AVR__
#include <UTFT.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(ITDB24,59,58,57,56);
char myString[15];
int ind = 0;

void setup() {
   Serial3.begin(9600);
   myGLCD.InitLCD();
   myGLCD.clrScr();
   myGLCD.setFont(BigFont);
}

void loop() {
  if (Serial3.available()) {
     int inByte = Serial3.read();
     if(inByte >= 33 && inByte <= 127)
       myString[ind++] = char(inByte);
    }
    if(ind >= 10)
    {
      myString[ind] = '\0';
      myGLCD.print( (char *)myString,CENTER, 0);
      memset(myString, 0 , 15);
      ind = 0;
    }
}

 

Last Edited: Wed. Nov 5, 2014 - 02:16 PM