Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 46
16  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 16, 2013, 12:10:36 am
Oh and these ...

Code:
const uint8_t   LED_OFF             = LOW;
const uint8_t   LED_ON              = HIGH;

... should really be ...

Code:
const int   LED_OFF             = LOW;
const int   LED_ON              = HIGH;

... as functions such as ...

Code:
int digitalRead(uint8_t);

really return 'int' types.

These are intended to be self-documenting synonyms to make the code easier to read lessening the need for unnecessary comments that can get out of sync with the actual code over time.
17  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 16, 2013, 12:04:08 am
That's what I thought you might be referring to but I wasn't certain.

If you're familiar with header files then you're likely familiar with function declarations.  Looking in the header file "Arduino.h" you'll find the function declarations for some common Arduino routines.  The following is pulled from Arduino.h.

Code:
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void analogWrite(uint8_t, int);

So the answer is because that is what the API is expecting.  Yes it is common that others let the compiler do type conversion but I prefer to give the compiler the correct types as per the function declarations.  So yes it is a preference but it's also really the right thing to do.
18  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 15, 2013, 09:12:24 pm
Well isn't that something.  It seems to work 9/10 times.  Every once and awhile it will print 0000, but I put some error handling in my Visual Studio part of this project to catch that.  Going through your code, I have some questions:

What exactly is this doing?
Code:
#define A_SIZEOF(ARRAY)     (sizeof(ARRAY) / sizeof(ARRAY[0]))

The compile time operator 'sizeof' returns the number of bytes an entity occupies.  In this case the entities are the size of a complete array and the size of an element of the array.  Given the size of the array divided by the size of a single element of the array we can determine the count of elements in an array whose elements are specified at compile time.

Quote
Is there a specific reason you use uint8_t instead of int?  (I had to look it up to see what it was  smiley )
Edit: Is it because of the sizeof(long) that you should define the integers as 8 bits?

Is this question directed at any particular piece of code?  I'm not quite sure where to direct a reply unless we narrow the question down a bit.

Sorry.

Quote
How does this work?  There is nothing in the curly braces?

Code:
while ( serialRFID.available() < 1 )
{   }

Personal preference I suppose as I don't like any of the following -

Code:
while ( serialRFID.available() < 1 )
    ;

... or ...

Code:
while ( serialRFID.available() < 1 )     ;

... to me my version clearly shows that we do nothing other than loop waiting for  the condition to be satisfied.

Quote
For this code, could I use other commands, such as 'w' and then put my write functions under that case?

Code:
switch ( command )
{
    // receive command from serial to search for and read card
    case 'r':
        readTagID();
        idSend();
               
        break;
           
    default:
        break;

Yes, as long as it's a single character command, and that's why I did it that way so you could expand on it.

Quote
Thank you again for all your help.  Sorry about all the questions, but I'm trying to make sure I actually understand how it works for when I make changes.

Not a problem.  That is why I prefer to post code that can be questioned as it allows me to determine what you know or don't know.  As well as to expose you to different solutions than those shown in the tutorials.

Feel free to ask about anything and I'll do my best to answer within the context of what I think you already know limited by my free time at the moment.

19  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 14, 2013, 11:43:41 pm
I admit to being to lazy to attempt debugging your code.  Mainly because I don't have the hardware needed.

But I'm not to lazy to make an attempt of my own for you to try.  If it doesn't work sorry for wasting your time.

Code:
// <http://forum.arduino.cc/index.php?topic=166216.new#new>

#include <SoftwareSerial.h>

#define A_SIZEOF(ARRAY)     (sizeof(ARRAY) / sizeof(ARRAY[0]))

const uint8_t   pinVISUAL_CUE_LED   = 13;   // PICNDUINO Onboard LED
const uint8_t   pinLED_2            = 9;    // PICNDUINO Onboard LED

const uint8_t   pinTX               = 6;
const uint8_t   pinRX               = 7;

const uint8_t   LED_OFF             = LOW;
const uint8_t   LED_ON              = HIGH;

const uint8_t   RFID_READ           = 0x01;

SoftwareSerial serialRFID(pinRX, pinTX);

uint8_t buffID[sizeof(long)];

void idSend()
{
    for ( int i = 0; i < A_SIZEOF(buffID); i++ )
    {
        Serial.print(buffID[i], HEX);
    };

    Serial.print("\n");
}


// Reads built in tag ID

void readTagID()
{
    digitalWrite(pinVISUAL_CUE_LED, LED_ON);

        int     err;
        do
        {
            // flush software serial buffer

            while ( serialRFID.available() > 0 )
            {
                (void)serialRFID.read();
            }
           

            serialRFID.print("!RW");
            serialRFID.write(byte(RFID_READ));
            serialRFID.write(byte(32));


            // wait for data to become available

            while ( serialRFID.available() < 1 )
            {   }

            err = serialRFID.read();
        } while ( err != 1 );


        // wait for all 4 bytes of data to become available

        while ( serialRFID.available() < 4 )
        {   }

        int count = 0;
        do
        {
            buffID[count++] = serialRFID.read();
        } while ( count < sizeof(long) );

    digitalWrite(pinVISUAL_CUE_LED, LED_OFF);
}

void loop()
{
    if ( Serial.available() > 0 )
    {
        int command = Serial.read();
        switch ( command )
        {
            // receive command from serial to search for and read card
            case 'r':
                readTagID();
                idSend();
               
                break;
           
            default:
                break;
        }
    }

    delay(750);
}

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


    // ... software serial I/O pins ...

    pinMode(pinTX, OUTPUT);
    pinMode(pinRX, INPUT);
    serialRFID.begin(9600);


    // ... on-board LED pins ...

    pinMode(pinVISUAL_CUE_LED, OUTPUT);
    pinMode(pinLED_2, OUTPUT);
}

EDIT: Made slight change waiting for input from 'serialRFID' of at least 1 character.
20  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 14, 2013, 07:03:31 pm
No, you got it the first time.

Thanks.
21  Using Arduino / Programming Questions / Re: One output, reacting to many inputs. on: May 14, 2013, 11:20:22 am
Code:
const int floodSensor1 = 2; // the number of the Flood Sensor pin
const int floodSensor2 = 3; // the number of the Flood Sensor pin
const int floodSensor3 = 4; // the number of the Flood Sensor pin
#if 0
const int floodSensor4 = 5; // the number of the Flood Sensor pin
const int floodSensor5 = 6; // the number of the Flood Sensor pin
#endif
const int ledPin = 9;       // the number of the LED pin (pin 9 is the on board led)


void setup()
{
    // initialize the LED pin as an output:
    pinMode(ledPin,       OUTPUT);

    // initialize the flood Sensor pin as an input:
    pinMode(floodSensor1, INPUT);
    pinMode(floodSensor2, INPUT);
    pinMode(floodSensor3, INPUT);
}

void loop()
{
    // variable for reading the floodSensors status
    int floodSensorState;

    // read the state of the flood Sensor value:
    floodSensorState  = digitalRead(floodSensor1);
    floodSensorState |= digitalRead(floodSensor2);
    floodSensorState |= digitalRead(floodSensor3);

    // check if the flood Sensor is wet.
    // if it is, the floodSensorState is HIGH:
    digitalWrite(ledPin, floodSensorState);
}
22  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 14, 2013, 09:50:09 am
Any documentation on what the RFID tag returns to the buffer?
23  Using Arduino / Programming Questions / Re: Parallax RFID Read/Write Project Serial.print issues on: May 13, 2013, 11:46:38 pm
Code:
if ( command == 'r' ) //receive command from serial to search for and read card
24  Using Arduino / Programming Questions / Re: Help with making a sketch on: May 12, 2013, 11:35:54 am
Your best bet at this time is likely a - flowchart!
25  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 10, 2013, 10:29:27 pm
In the macro itself the '13' is an integer literal but what happens with the integer literal depends upon the context in which it is expanded.

The main thing here is that the question had NOTHING to do with 'define'.
26  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 10, 2013, 10:03:20 pm
Well, it's not 'define'd, again referencing "Arduino.h"

Code:
typedef uint8_t byte;
27  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 10, 2013, 09:30:22 pm
@lloyddean,
Why are you using uint8_ts instead of byte?

Did my reply above answer your question adequately?
28  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 09, 2013, 05:26:43 pm
Yes, it's amazing how many 'sick' students are out there!!!
29  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 09, 2013, 05:20:38 pm
Alls I can say is you're in trouble and wish you good luck!
30  Using Arduino / Programming Questions / Re: [help,urgently] arduio programing problem on: May 09, 2013, 05:16:00 pm
Because that is the declaration of 'pinMode',  'digitalRead',  'digitalWrite',  'analogRead',  'analogWrite' and several others ...


EDIT -

As declared in Arduino.h ...

Code:
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);

... although I'm not a fan of leaving out the parameter name and would prefer ...

Code:
void pinMode(uint8_t pin, uint8_t mode);
void digitalWrite(uint8_t pin, uint8_t state);
int digitalRead(uint8_t pin);
int analogRead(uint8_t pin);
void analogReference(uint8_t mode);
void analogWrite(uint8_t pin, int value);

... to help document the functions parameters.
Pages: 1 [2] 3 4 ... 46