Pages: 1 [2] 3   Go Down
Author Topic: Using the RDM630 RFID Tag Reader and NewSoftwareSerial library  (Read 3037 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because it is mostly unnecessary (I have written one in the last thirty years, but it was deep in a Linux device driver, and required to be signed-off by a director), and has the potential of producing spaghetti code.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
SoftwareSerial RFID =  SoftwareSerial(RFID_RX, RFID_TX);

  pinMode(RFID_TX, OUTPUT);//Define RFID TX pin as OUTPUT (Not nessesary)
  pinMode(RFID_RX, INPUT);//Define RFID RX pin as INPUT (Nessesary)
You have told the SoftwareSerial instance that the pins are its to manage. So, why are you diddling with them?
I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial:
http://arduino.cc/en/Reference/SoftwareSerialAvailable
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because it is mostly unnecessary (I have written one in the last thirty years, but it was deep in a Linux device driver, and required to be signed-off by a director), and has the potential of producing spaghetti code.
Fair enough.  It just seemed convenient and quick.  Its not like I used it a lot, only once.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Once is once too many.
Simply a GOTO is not a structured piece of code, it can be used to jump into the middle of structures that have not been set up with totally unpredictably consequences.
If you feel the need to use a GOTO then you have not thought out the problem correctly.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See what I mean about attracting flak?   smiley-wink
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See what I mean about attracting flak?   smiley-wink
Yep smiley-wink  I didn't realise that Goto was such a taboo!  It must be drilled into your heads at uni!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial:
It's on the internet. It must be right. Not in this case:

Code:
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) :
  _rx_delay_centering(0),
  _rx_delay_intrabit(0),
  _rx_delay_stopbit(0),
  _tx_delay(0),
  _buffer_overflow(false),
  _inverse_logic(inverse_logic)
{
  setTX(transmitPin);
  setRX(receivePin);
}

And, what does setTX do?
Code:
void SoftwareSerial::setTX(uint8_t tx)
{
  pinMode(tx, OUTPUT);
  digitalWrite(tx, HIGH);
  _transmitBitMask = digitalPinToBitMask(tx);
  uint8_t port = digitalPinToPort(tx);
  _transmitPortRegister = portOutputRegister(port);
}

And setRX?
Code:
void SoftwareSerial::setRX(uint8_t rx)
{
  pinMode(rx, INPUT);
  if (!_inverse_logic)
    digitalWrite(rx, HIGH);  // pullup for normal logic!
  _receivePin = rx;
  _receiveBitMask = digitalPinToBitMask(rx);
  uint8_t port = digitalPinToPort(rx);
  _receivePortRegister = portInputRegister(port);
}

So, the pin modes have already been set when you diddle with them.
« Last Edit: July 12, 2012, 09:40:00 am by PaulS » Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm changing their pinModes (even though its not really needed) because thats what it does in the SoftwareSerial tutorial:
It's on the internet. It must be right. Not in this case:

Code:
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) :
  _rx_delay_centering(0),
  _rx_delay_intrabit(0),
  _rx_delay_stopbit(0),
  _tx_delay(0),
  _buffer_overflow(false),
  _inverse_logic(inverse_logic)
{
  setTX(transmitPin);
  setRX(receivePin);
}

And, what does setTX do?
Code:
void SoftwareSerial::setTX(uint8_t tx)
{
  pinMode(tx, OUTPUT);
  digitalWrite(tx, HIGH);
  _transmitBitMask = digitalPinToBitMask(tx);
  uint8_t port = digitalPinToPort(tx);
  _transmitPortRegister = portOutputRegister(port);
}

And setRX?
void SoftwareSerial::setRX(uint8_t rx)
{
  pinMode(rx, INPUT);
  if (!_inverse_logic)
    digitalWrite(rx, HIGH);  // pullup for normal logic!
  _receivePin = rx;
  _receiveBitMask = digitalPinToBitMask(rx);
  uint8_t port = digitalPinToPort(rx);
  _receivePortRegister = portInputRegister(port);
}

So, the pin modes have already been set when you diddle with them.
Well it was on the official Arduino page, which is supposed to be moderated by experts like you and your counterparts, so it's not like I grabbed it off Wikipedia and stuck it in my code.  Either way, nowhere have I read that you don't need to do that (At least anywhere on here), so obviously I'm not the only one, and no harm was done - the code works perfectly fine - so I don't think that any of this matters.
« Last Edit: July 12, 2012, 09:47:32 am by Koop » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well it was on the official Arduino page, which is supposed to be moderated by experts like you and your counterparts
The official Arduino page contains many, many errors. Not a one of us "experts" or moderators can change the official Arduino page.

I didn't mean to come across too hard on the issue. The pins belong to the instance (and it doesn't matter what the instance is an instance of), so they should not be diddled with by you (or any one else). Only the class that you give them to should diddle with them.

You can, of course, look at the code, like I did, to see what is necessary, and what isn't, in the future.

(That has to be a record for the number of commas I've ever put in one sentence.)
Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I didn't mean to come across too hard on the issue. The pins belong to the instance (and it doesn't matter what the instance is an instance of), so they should not be diddled with by you (or any one else). Only the class that you give them to should diddle with them.

You can, of course, look at the code, like I did, to see what is necessary, and what isn't, in the future.
Thanks for that.  Its hard to 'read' a person's emotions with only text to go by, and I thought that you were being one of those annoying nit-pickers, but you weren't so thats good smiley

Quote
The official Arduino page contains many, many errors. Not a one of us "experts" or moderators can change the official Arduino page.
Well that's not good is it :/  It should be checked for errors more frequently... and all examples I've ever seen do the same thing I did so it must be stemming from that one coding mistake.  Thanks for all your help.  I'll be sure to read the header files before I do anything with libraries again.

Thanks to you all,
Koop
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It must be drilled into your heads at uni!
A bit condescending.
When I went to Uni there was no instruction about code. We had to learn it ourselves.

When I taught at Uni, I never introduced it as a valid instruction.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some of us never attended a university.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me neither.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At my first technical programming job I handed in my first piece of code to my supervisor. He said "rewrite it without the gotos". I did that, and haven't used them since.

I can think of one place where a goto might be useful, and that is in the regular expression library where an expert (Roberto Ierusalimschy) used it in one place in order to avoid consuming the stack when doing tail recursion. This is a guy who knows what he is doing. He is an associate professor of Informatics and a compiler-writer (Lua).

If you are trying to avoid using the stack, when doing tail recursion, fair enough.

For other cases, you don't need goto, and they obscure what the code is doing.

Logged

Australia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
char CoolThings[] = "Vegemite", "Swimming", "Arduino";
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A bit condescending.
Quote
Some of us never attended a university.
Sorry, Grumpy_Mike, AWOL and dxw00d!  In no means was that meant to be condescending, I just assumed that seeing as though you guys are so good at this, and you knew to never, EVER, use a goto (except in the circumstance said by Nick) you had some form of tertiary education on the matter.  Being a schoolkid, I've never experienced uni or TAFE or community college or any tertiary education, so I have no idea of how or what they teach you there.  It was just an (obviously uneducated) guess smiley-razz
« Last Edit: July 13, 2012, 02:09:35 am by Koop » Logged

Pages: 1 [2] 3   Go Up
Jump to: