We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I have this SparkFun RFID Starter Kit (https://www.sparkfun.com/products/13198?_ga=1.242738306.1686357739.1444361942), I followed the steps in the HookUp guide (https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide?_ga=1.177165093.1278763627.1444260091), and It seems that is working fine, although I'm not getting the same reads as the guide.
Example: The guide shows this screenshot of the Arduino serial port while reading the card:
And I get this value:
If I swipe the card another time, I get this reading:
What are those little squares? I guess is some kind of character but I don't know which, or why is there.
Any ideas?
I am also trying this RFID reader in Processing. To change a message in the screen if someone swipes the card.
Initial screen:
After one read:
The text "saldo en 0" should have changed to "deposito $50"", but it shouldn't.
Any ideas?
Thanks!!
The code:
import processing.serial.*;
Serial myPort;
String inString = "texto inicial";
String mensaje;
void setup () {
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
background(0);
String s = inString;
String comparador = "4500B8C02A17";
textSize(24);
fill(100);
text(s, height/3, width/3);
if (comparador.equals(s) == true) {
mensaje = "deposito $50";
} else {
mensaje = "saldo en 0";
}
text(mensaje, height/3, width/3+30);
}
void serialEvent (Serial myPort) {
inString = myPort.readStringUntil('\n');
}
Answers
@GoToLoop it works! =D> now I need an explanation! :-?
You'd have to be more specific where you don't get it... >-)
@GoToLoop please see my comments in the code, thanks!
// forum.processing.org/two/discussion/12920/problem-reading-a-rfid-reader // 2015-Oct-09
https://processing.org/reference/final.html
https://processing.org/reference/static.html
Yes, ENTER = '\n' = 10 = 0xA. ;)
Though I'm not using a variable, I'm calling bufferUntil() over the newly created Serial.
setTitle() changes window bar's title.
frameCount: https://Processing.org/reference/frameCount.html
B/c Serial is programmed to
bufferUntil(ENTER);
. So we need to trim() that ending\n
: :-Bhttps://Processing.org/reference/trim_.html
It's what redraw() does internally: https://processing.org/reference/redraw_.html
Since noLoop() was issued in setup(), the auto-draw() has been turned off.
So every time serialEvent() is called back by the Serial's instance, we need to redraw() once.
@GoToLoop You are the man! ^:)^
Two more questions: 1) Why to set the title with the frame count? 2) I didn't know about the noLoop(). Why did you use it? I mean Why no leave the program running the draw automatically like usuall?
(sorry for my non-native english)
It's just informative. So we know how many times serialEvent() has happened. :P
By default Processing calls back draw() at about 60 FPS.
We can change that via frameRate() though: https://Processing.org/reference/frameRate_.html
We could just let it roll of course. But why waste CPU/GPU/APU to display the same thing?
Variable mensaje only changes inside SerialEvent() after all.
Until then text() is gonna display the same thing over & over @ 60 FPS.
It only makes sense to update the canvas once it actually has something new to display!
Besides, I wanted frameCount to represent how many times serialEvent() had happened.
W/o noLoop(), frameCount would increase at about 60 each second!
I'm Brazilian and speak Portuguese! :-h
Again, obrigado! =D> very helpful and explicative. Cheers from Argentina. :-h
Uma última pergunta: I want that when mensaje is the same as COMPARADOR, the text Deposito $50 is displayed only for 5 seconds and then go back to Saldo en 0 is this OK?
synchronized ()
in order to "atomize" the entire steps.@GoToLoop Again, thanks! very clear and explicative. Now I'll continue a bit by myself :P Have a nice weekend!
I'm trying to change the code a bit but with no success L-)
Why this:
Is no the same as this:
text(COMPARADOR.equals(mensaje)? DEPOSITO : SALDO, height/3, width/3 + 30);
I mean... I guess is not the same because the program does different things using one or the other. And the thing is that now I need more things to happen (displaying an image among other simple things) if COMPARADOR equals mensaje, rather than displaying some text.
Any ideas?
My mystake, I've updated the code: