replacement for BYTE?

Hey guys. Having a bit of trouble with the new arduino 1.0. I am trying to interface with a parallax rfid module (28440) and up until now I had been Using the following code:

 //Code to read data from Parallax RFID reader/writer 28440 via Arduino //Program reads data from one of the 29 user-defined addresses (3-31) as define by whichSpace //Writen by vgrhcp based on codeby uberdude

#include <NewSoftSerial.h> #define RFID_READ 0x01 #define txPin 6 #define rxPin 8

#define whichSpace 4

NewSoftSerial mySerial(rxPin, txPin); int val; int runs = 0;

void setup() { Serial.begin(9600); Serial.println("RFID Read Test"); mySerial.begin(9600); pinMode(txPin, OUTPUT); pinMode(rxPin, INPUT); }

void suppressAll() //suppresses the "null result" frombeing printed if no RFID tag is present { if(mySerial.available() > 0) { mySerial.read(); suppressAll(); } }

void loop() { int val; mySerial.print("!RW"); mySerial.print(RFID_READ, BYTE); mySerial.print(whichSpace, BYTE);

if(mySerial.available() > 0) { val = mySerial.read(); //The mySerial.read()procedureiscalled,but theresult isnot printed becauseI don't want the "error message: 1" cluttering up the serial monitor if (val != 1) //If the errorcodeis not 1, then there has been an error and the RFID tag was not read correctly.In thiscasewedon't really careabout theresultant values,sothey can be suppressed {suppressAll();} }

if(mySerial.available() > 0) { val = mySerial.read(); Serial.print("1st:"); Serial.println(val, DEC); }

if(mySerial.available() > 0) { val = mySerial.read(); Serial.print("2nd:"); Serial.println(val, DEC); }

if(mySerial.available() > 0) { val = mySerial.read(); Serial.print("3rd:"); Serial.println(val, DEC); }

if(mySerial.available() > 0) { val = mySerial.read(); Serial.print("4th:"); Serial.println(val, DEC); Serial.println("-----------------"); }

delay(750); }

t

Hope the formatting worked on that one. Anyway, if you notice at the beginning of the loop is the keyword BYTE. According to the release notes BYTE no longer works, which would explain all the errors while compiling. Any suggestions for how to fix this? If I understood the release notes correctly they want me to use some different library or something like that.

Thanks,
Seb

sorry about that failed formatting. thought it would be cool to post from my new kindle fire. didn't work so well. here it is for reals:

#include <NewSoftSerial.h>
#define txPin 6
#define rxPin 8

#define RFID_LEGACY 0x0F

NewSoftSerial mySerial(rxPin, txPin);
char statusCode;
int  val = 0; 
char code[11];     //Note this is 11 for the extra null char?
int bytesread = 0;

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);

  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(txPin, OUTPUT);     //pin 6
  pinMode(rxPin, INPUT);      //pin 8

  Serial.println("RFID Read/Write Test");
}

void loop()
{
  mySerial.print("!RW");
  mySerial.print(RFID_LEGACY, BYTE);
  //mySerial.print(32, BYTE);

  if(mySerial.available() > 0) {          // if data available from reader 

    if((val = mySerial.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( mySerial.available() > 0) { 
          val = mySerial.read(); 
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 

      if(bytesread == 10) {              // if 10 digit read is complete 
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code 
      } 
      bytesread = 0;
      
      delay(250);                       // wait for a 1/2 second 
    } 
  } 
}

The below may have soe info:

thanks for the link. I think I made the right change, but i'm still missing something. changed to this:

mySerial.write("!RW");
mySerial.write(RFID_LEGACY);

here are my errors:

In file included from sketch_dec25a.cpp:1:0:
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: conflicting return type specified for ‘virtual void NewSoftSerial::write(uint8_t)’
/home/seb/arduino-1.0/hardware/arduino/cores/arduino/Print.h:48:20: error:   overriding ‘virtual size_t Print::write(uint8_t)’
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h: In function ‘void loop()’:
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: ‘virtual void NewSoftSerial::write(uint8_t)’ is private
sketch_dec25a.cpp:31:23: error: within this context
sketch_dec25a.cpp:31:23: error: invalid conversion from ‘const char*’ to ‘uint8_t’
sketch_dec25a.cpp:31:23: error:   initializing argument 1 of ‘virtual void NewSoftSerial::write(uint8_t)’
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: ‘virtual void NewSoftSerial::write(uint8_t)’ is private
sketch_dec25a.cpp:32:29: error: within this context

I believe you use print() instead of write() for strings in v1.0

I believe you use print() instead of write() for strings in v1.0

You use print() for strings in ALL versions. write() is for binary data.

Could you maybe recommend a fix? I'm not proficient enough to be able to solve it. I now have a different paragraph of errors after feeding chars into myserial.write.

  mySerial.print("!RW");

stays like it is.

  mySerial.print(RFID_LEGACY, BYTE);

becomes

  mySerial.write((byte)RFID_LEGACY);

kinda got that far myself. here are all of the errors:

In file included from sketch_dec25a.cpp:1:0:
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: conflicting return type specified for ‘virtual void NewSoftSerial::write(uint8_t)’
/home/seb/arduino-1.0/hardware/arduino/cores/arduino/Print.h:48:20: error:   overriding ‘virtual size_t Print::write(uint8_t)’
sketch_dec25a.cpp: In function ‘void loop()’:
sketch_dec25a.cpp:31:28: error: cast from ‘const char*’ to ‘byte’ loses precision //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: ‘virtual void NewSoftSerial::write(uint8_t)’ is private
sketch_dec25a.cpp:31:29: error: within this context
/home/seb/arduino-1.0/libraries/NewSoftSerial/NewSoftSerial.h:71:16: error: ‘virtual void NewSoftSerial::write(uint8_t)’ is private
sketch_dec25a.cpp:32:35: error: within this context

I marked the one that seemed to be the most important. I assume this error is happening because it can't "byte(0x0F)", it can only "byte()" one char at a time.

sebflippers:
Could you maybe recommend a fix? I'm not proficient enough to be able to solve it. I now have a different paragraph of errors after feeding chars into myserial.write.

I can't seem to be able to access arduiniana.org where the NewSoftSerial library is hosted. But if it has not changed a bit, then you can't use write in that library cause it says clearly on the error message, write is a private method. I don't know why but that is the truth. You can only do:

newsoftserial.print((uint8_t)RFID_LEGACY);

In fact, I agree with PaulS on everything except the above. newsoftserial stuff should only make the above change.

guess i'll need to use a different library. In order to do that I would like to learn more about the serial connections,though. what kind of connection is it? could somebody give me a wikipedia link?

From the Arduino v1.0 release notes:

The SoftwareSerial class has been reimplemented, using the code originally
written for the NewSoftSerial library by Mikal Hart. This allows for
multiple simultaneous instances, although only one can receive at a time.

So I believe you can just change your code: (as originally posted):

 //Code to read data from Parallax RFID reader/writer 28440 via Arduino //Program reads data from one of the 29 user-defined addresses (3-31) as define by whichSpace //Writen by vgrhcp based on codeby uberdude

#include <NewSoftSerial.h> #define RFID_READ 0x01 #define txPin 6 #define rxPin 8

#define whichSpace 4

NewSoftSerial mySerial(rxPin, txPin); int val; int runs = 0;

to

 //Code to read data from Parallax RFID reader/writer 28440 via Arduino //Program reads data from one of the 29 user-defined addresses (3-31) as define by whichSpace //Writen by vgrhcp based on codeby uberdude

#define RFID_READ 0x01 #define txPin 6 #define rxPin 8

#define whichSpace 4

SoftwareSerial mySerial(rxPin, txPin); int val; int runs = 0;

Iain

Thanks guys. I got it. Here's the final code. I'll upload this to the playground.

#include <SoftwareSerial.h>
#define txPin 6
#define rxPin 8
#define RFID_LEGACY 0x0F


SoftwareSerial mySerial(rxPin, txPin);
char statusCode;
int  val = 0; 
char code[11];     //Note this is 11 for the extra null char?
int bytesread = 0;

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);

  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(txPin, OUTPUT);     //pin 6
  pinMode(rxPin, INPUT);      //pin 8

  Serial.println("RFID Read/Write Test");
}

void loop()
{
  mySerial.print("!RW");
  mySerial.write(byte(RFID_LEGACY));
  
  //mySerial.print(32, BYTE);

  if(mySerial.available() > 0) {          // if data available from reader 

    if((val = mySerial.read()) == 10) {   // check for header 
      bytesread = 0; 
      while(bytesread<10) {              // read 10 digit code 
        if( mySerial.available() > 0) { 
          val = mySerial.read(); 
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 

      if(bytesread == 10) {              // if 10 digit read is complete 
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code 
      } 
      bytesread = 0;
      
      delay(500);                       // wait for a 1/2 second 
    } 
  } 
}