Go Down

Topic: OLED Library Messing Up RFID (Read 1 time) previous topic - next topic

Artie

Hello, I'm trying to get my Grove 128*64 OLED to display a message when a given RFID card is placed up against the RFID reader. I'm using the Seeeduino V3.0 and an RDM630 RFID reader.
The serial monitor prints out the ID number of each different card, but every single card is displayed with the same ID number. I know the issue is not the equipment, as I've used them with a number of different RFID projects. The problem is very strange and is within the code
I was using the <GOFi2cOLED> library to display the images, and when that library is enabled, the RFID works improperly, reading the same values for every RFID card. However, when I get rid of the library, all of a sudden the serial monitor produces the proper ID numbers. I don't know why the <GOFi2cOLED> would effect the RFID reader.
When I used the <SeeedOLED> library, everything worked fine, but I would prefer to use the <GOFi2cOLED> one because I can easily manipulate the fonts.
Maybe the <GOFi2cOLED> has a redeclaration of certain variables within the other libraries provided? I'm not sure. Thanks.

Code: [Select]

#include <SoftwareSerial.h>
#include <String.h>
#include <GOFi2cOLED.h>
#include <Wire.h>
#include <avr/pgmspace.h>

SoftwareSerial mySerial(2, 3);

char RFID_Buffer [20];
int  RFID = 0;

/*GOFOLED Images programed here, but I took them out for the sake of this forum*/

int doorstrike = 4;
int doorswitch = 5;
int buzzer = 6;



void setup()
{
  RFID = 0;
  int TO; char c=0; char d=0;

for(int pin = 14; pin <= 17; pin++) // initiallize green leds
{
   pinMode(pin, OUTPUT);
   digitalWrite(pin, HIGH);
}

for(int pin = 8; pin <= 11; pin++) // initiallize red leds
{
   pinMode(pin, OUTPUT);
   digitalWrite(pin, HIGH);
}

  pinMode(doorstrike, OUTPUT); digitalWrite(doorstrike, HIGH);
  pinMode(doorswitch, INPUT);
  pinMode(buzzer, OUTPUT);

  mySerial.begin(19200);  // the SIM900 baud rate   
  Serial.begin(9600);     // the RDM6300 baud rate
  delay(500);             // control output is there too


// Clear buffer
  RFID = 0;
  RFID_Buffer [0] = 0;
 
  Wire.begin();

  /*------------Initializing GOFoled--------------------*/
//default slave address is 0x3C
GOFoled.init(0x3C);  //initialze  OLED display

GOFoled.display(); // show splashscreen
delay(2000);
GOFoled.clearDisplay(); 
 
GOFoled.drawBitmap(0, 0, heart2, 128, 64, WHITE);
GOFoled.display();  // RFID logo
 
}

void loop()
{
  char c;
 
  LOOP:
    // OVERRIDE SWITCH :: if the switch is closed then energize relay
    if (digitalRead(doorswitch))
    {
      for(int i = 0; i < 2; i++) // toggle buzzer 2 times
      {     
        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);
      }
      digitalWrite(doorstrike,LOW);    // energize relay
      // flash notification LED - keep relay open for 2 seconds
      blinkGreenLED(4, 100);
      delay(5000);
      digitalWrite(doorstrike,HIGH);    // cut-off the relay

     
      digitalWrite(buzzer, HIGH);
      delay(100);
      digitalWrite(buzzer, LOW);
      delay(100);     

    }
    else
    {
      digitalWrite(doorstrike,HIGH);    // cut-off the relay
    }
    //delay(2);    // give the circuit time to reset


  // Check if there is any comm from RFID
  if (Serial.available())
  {
   
    c = Serial.read();

    if (c >= '0' && c <= 'F')
    {     
      RFID_Buffer [RFID] = c;
      Serial.write (c);
      if (RFID < 20) RFID++;
      RFID_Buffer [RFID] = 0;
    }

    if (c < '0' && RFID > 0)
    {
      RFID_Buffer [RFID] = 0;
      Serial.println ("*");
      Serial.print ("RFID Tag ID Read: ");
      Serial.println (RFID_Buffer);
      RFID = 0;


    // authenticate tag IDs
    if (String(RFID_Buffer)==String("3E008F6BC319"))
    {
      for(int i = 0; i < 2; i++) // toggle buzzer 2 times
      {     
        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);
      }
        digitalWrite(doorstrike,LOW);    // energize relay
       
       
        // flash notification LED - keep relay open for 2 seconds
        blinkGreenLED(4, 100);
        delay(5000);
        digitalWrite(doorstrike,HIGH);    // cut-off the relay

        digitalWrite(buzzer, HIGH);
        delay(100);
        digitalWrite(buzzer, LOW);
        delay(100);       
    }
    else
    {
      // NOT AUTHORIZED
      digitalWrite(buzzer, HIGH);

GOFoled.drawBitmap(0, 0, heart2, 128, 64, WHITE);
     

      delay(200);
      digitalWrite(buzzer, LOW);
      delay(100);
      delay(500);
      blinkRedLED(3, 100);

      GOFoled.display();
      delay(100);
   
    }
 

     
/*
      if (RFID_Buffer [1] > '0') {  // temp auth - just looking to see if a tag was read
        Serial.println ("Tag is authorized.");

        Serial.println ("Open Relay");

        digitalWrite(7,HIGH);  // Open relais
        delay (1000);
        digitalWrite(7,LOW); 
        Serial.println ("Close Relay");
      } else
        Serial.println ("Tag *NOT* authorized");
*/
  }

   while (Serial.available())
   {
     c = Serial.read();
   }
  } 
 

Grumpy_Mike

Quote
Maybe the <GOFi2cOLED> has a redeclaration of certain variables within the other libraries provided?

If it did it wouldn't matter C++ isolates such things.

The problem is with the GOFi2cOLED however. Does it use a timer or in some way interfere with the baud rate of the serial port? I suspect it is fighting for some hardware resource with the SoftwareSerial.

MarkT

Also check if there's enough spare memory perhaps?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Artie

Thank you Grumpy_Mike. You were correct. The OLED is working alongside the RFID now. I appreciate your comment immensely.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy