Hey,
I am slightly new to Arduino and their products but one of my friends at University got me into it, and I am using it to do a Uni project.
I am using a serial enabled LCD from Seeeduino ( Backpack (
http://littlebirdelectronics.com/products/serial-enabled-lcd-backpack) and just a normal 2x16 5V LCD screen attached) and also a RFID module (
http://littlebirdelectronics.com/products/125khz-rfid-module-uart).
I have got both code of these elements working on their own, thanks to the internet, but am currently struggling to get them to work together.
I am not exactly sure what the issue is. But it only stops working when i include the LCD coding, including LCD.begin etc.
At the moment I am only trying to make the LCD output the value of the RFID card.
Thanks for your help in advance!
Willing to read anything you have to throw at me!
#include <SoftwareSerial.h>
SoftwareSerial RFID = SoftwareSerial(2, 2);
SoftwareSerial LCD = SoftwareSerial(0, 3);
const int LCDdelay=100;
void lcdPosition(int row, int col)
{
LCD.write(0xFE); //command flag
LCD.write((col + row*64 + 128)); //position
delay(LCDdelay);
}
void clearLCD()
{
LCD.write(0xFE); //command flag
LCD.write(0x01); //clear command.
delay(LCDdelay);
}
void backlightOn()
{ //turns on the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(157); //light level.
delay(LCDdelay);
}
void backlightOff()
{ //turns off the backlight
LCD.write(0x7C); //command flag for backlight stuff
LCD.write(128); //light level for off.
delay(LCDdelay);
}
void serCommand()
{ //a general function to call the command flag for issuing all other commands
LCD.write(0xFE);
}
void setup()
{
pinMode(3, OUTPUT);
Serial.begin(9600);
RFID.begin(9600);
LCD.begin(9600); // maximum bandwidth issue
}
void loop()
{
receiveRFIDCardInfo();
}
void receiveRFIDCardInfo()
{
static byte data[4];
static byte temp[14];
byte len;
static int i = 0;
unsigned long currentId;
if(RFID.available())
{
temp[i++] = RFID.read();
if(14 == i)
{
if( 0x02 == temp[0] && 0x03 == temp[13])
{
data[0] = Transform(temp[3])*16 + Transform(temp[4]);
data[1] = Transform(temp[5])*16 + Transform(temp[6]);
data[2] = Transform(temp[7])*16 + Transform(temp[8]);
data[3] = Transform(temp[9])*16 + Transform(temp[10]);
currentId = (unsigned long)data[0]*16777216 + (unsigned long)data[1]*65536 + (unsigned long)data[2]*256 + (unsigned long)data[3];
Serial.println("\nCurrentID:");
Serial.print(currentId,DEC);
i=0;
clearLCD();
lcdPosition(0,0);
LCD.print(currentId, DEC);
}
}
}
}
byte Transform(byte dat)
{
if(dat >= 0x30 && dat <= 0x39)
{
return (dat - 0x30);
}else if(dat >= 0x41 && dat <= 0x46)
{
return (dat - 55);
}
}