Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: floats to ints for temperature reading on: March 23, 2014, 09:21:45 pm
Do you really want it to self-scale without making it obvious that it has done? For example, with the approach you described, 10.2 and 102 would appear the same. If that's really what you want then I suggest you simply test whether the value is less than 100 degrees and multiply the float value by 10 or 100 to give you the integer value you want to display. You can simply cast it to an integer to get the significant digits to be displayed - add 0.5 first if you want the result to be rounded. Then you can either print the integer to get an ascii string, or use div/mod to extract the decimal digits from it.

Sometimes, I miss the simple things. This approach is 100x simpler than I anticipated.

And to answer jremington:
The code, as it currently sits, gets a reading from the sensor. But what gets printed to the display is:
F7x.4.
where 'x' is different every single time it gets written to the display, and the second decimal point may or may not show up on the write. Meanwhile, it was supposed to say something closer to:
F63.5

And it works now. It seems my analog thermometer is very wrong (it shows it's 43 F), but I think the digital one is correct. I wrote a PHP script on my local server to verify my maths. And here is my working code:
Code:
//Arduino 1.0+ Only
//Arduino 1.0+ Only

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial
//////////////////////////////////////////////////////////////////
// SDA is on analog pin 4, and SCL is on analog pin 5

#include <Wire.h>
int tmp102Address = 0x48;
const int numbers[] = {0b11111100,0b01100000,0b11011010,0b11110010,0b01100110,0b10110110,0b00111110,0b11100000,0b11111110,0b11100110}; // 0-9
const int ser = 8;
const int load = 10;
const int sck = 9;
const int a1 = 2;
const int a2 = 3;
const int a3 = 4;
const int a4 = 5;

void setup(){
  Wire.begin();
  pinMode(ser,OUTPUT);
  pinMode(sck,OUTPUT);
  pinMode(load,OUTPUT);
  pinMode(a1,OUTPUT);
  pinMode(a2,OUTPUT);
  pinMode(a3,OUTPUT);
  pinMode(a4,OUTPUT);
  digitalWrite(load,0);
  shiftOut(ser,sck,LSBFIRST,0);
  digitalWrite(a1,1);
  digitalWrite(a2,1);
  digitalWrite(a3,1);
  digitalWrite(a4,1);
  digitalWrite(load,1);
}
int a;
int b;
int c;
int s;
void loop(){
  int f;
  boolean dp = 0;

  float celsius = getTemperature();
  
  float fahrenheit = (1.8 * celsius) + 32;  
  
//  delay(200); //just here to slow down the output. You can remove this
 if(fahrenheit >= 100){
 f=(int)(fahrenheit+0.5);
 }
 
else{
  f=(int)((fahrenheit+0.05)*10.0);
  dp=1;
}

a=f/100;
b=(f/10)-(a*10)+dp;
c=f-(a*100)-((b-dp)*10);
 
 
  
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,0b10001110);
  digitalWrite(load,1);
  digitalWrite(a1,0);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  delay(5);
  
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,numbers[a]);
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,0);digitalWrite(a3,1);digitalWrite(a4,1);
  delay(5);
  
  if(dp==0){
    s = numbers[b];
  }
  else{
    s = numbers[b]+1;
  }
  
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,s);  
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,0);digitalWrite(a4,1);
  delay(5);
  
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,numbers[c]);
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,0);
  delay(5);
}

float getTemperature(){
  Wire.requestFrom(tmp102Address,2);

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  return celsius;
}
2  Using Arduino / Project Guidance / floats to ints for temperature reading on: March 22, 2014, 05:57:25 pm
I have this digital thermometer from Sparkfun: tmp102. I used the example code linked on the product page to get values from the thing. But I have an issue from there. I want to take the value given and print (strobe) them to a 4x7 segment display. My issue is getting from a float of some unknown length to four integers.

Let's say the value read is 70.68. I need to get it so that:
a=7
b=0
c=7 (because it rounded up)

Or if the value is 101.56:
a=1
b=0
c=2 (because it rounds up)

The purpose of the fourth digit is to determine if the third gets rounded. But the three digits get printed to the display.

I've got:
Code:
//Arduino 1.0+ Only
//Arduino 1.0+ Only

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the TMP102, simply prints temperature via serial
//////////////////////////////////////////////////////////////////
// SDA is on analog pin 4, and SCL is on analog pin 5

#include <Wire.h>
int tmp102Address = 0x48;
const int numbers[] = {0b11111100,0b01100000,0b11011010,0b11110010,0b01100110,0b10110110,0b01111010,0b11100000,0b11111110,0b11100110}; // 0-9
const int ser = 8;
const int load = 10;
const int sck = 9;
const int a1 = 2;
const int a2 = 3;
const int a3 = 4;
const int a4 = 5;

void setup(){
  Wire.begin();
  pinMode(ser,OUTPUT);
  pinMode(sck,OUTPUT);
  pinMode(load,OUTPUT);
  pinMode(a1,OUTPUT);
  pinMode(a2,OUTPUT);
  pinMode(a3,OUTPUT);
  pinMode(a4,OUTPUT);
  digitalWrite(load,0);
  shiftOut(ser,sck,LSBFIRST,0);
  digitalWrite(a1,1);
  digitalWrite(a2,1);
  digitalWrite(a3,1);
  digitalWrite(a4,1);
  digitalWrite(load,1);
}
int a;
int b;
int c;
int s;
void loop(){
  int dp;

  float celsius = getTemperature();
 
  float fahrenheit = (1.8 * celsius) + 32; 
 
//  delay(200); //just here to slow down the output. You can remove this
 
 int f=(int)(fahrenheit*10.0);
 int g=f;
  if(g/1000 != 0){
    a=g/1000;
    b=(g/100)-(a*10);
    c=(g/10)-(((a*10)+b)*10);
    if((g-((a*100)+(b*10)+c)*10) > 4){
      c++;
    dp = 0;
    }
  }
  else{
    a=g/100;
    b=(g/100)-(a*10);
    c=g-(((a*10)+b)*10);
  }
 
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,0b10001110);
  digitalWrite(load,1);
  digitalWrite(a1,0);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  delay(5);
 
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,numbers[a]);
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,0);digitalWrite(a3,1);digitalWrite(a4,1);
  delay(5);
 
  if(dp==0){
    s = numbers[b];
  }
  else{
    s = numbers[b]+1;
  }
 
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,s); 
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,0);digitalWrite(a4,1);
  delay(5);
 
  digitalWrite(load,0);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,1);
  shiftOut(ser,sck,LSBFIRST,numbers[c]);
  digitalWrite(load,1);
  digitalWrite(a1,1);digitalWrite(a2,1);digitalWrite(a3,1);digitalWrite(a4,0);
//  delay(10);
}

float getTemperature(){
  Wire.requestFrom(tmp102Address,2);

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  return celsius;
}
3  Using Arduino / Programming Questions / Re: Dynamic Array of Integers on: June 26, 2013, 11:22:30 am
Your getting a new copy of buttons (set to 0) each time loop() is called. Make buttons static or global. Look up "scope of var in c/c++".

Mark

I know. It's supposed to reset at the beginning of the loop (and I just realise I can remove that line due to how I'm setting them).

How are your pull down resistors connected? Post updated code when you make changes.
I put them between the switches (which I've been calling buttons) and the Arduino (I'll create schematics later). And I'll post the new code after I re-update it.
Code:
void setup(){
  //define the inputs
  for(int z=2;z<6;z++){
    pinMode(z,INPUT);
  }
  //Define the outputs
  for(int z=8;z<12;z++){
    pinMode(z,OUTPUT);
  }
    Serial.begin(9600);
}
int buttons[16];
void loop(){

  //Read the first four inputs
  digitalWrite(8,HIGH); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,LOW);

    buttons[0] = digitalRead(2);

    buttons[4] = digitalRead(3);

    buttons[8] = digitalRead(4);

    buttons[12] = digitalRead(5);

  //Read the next four
  digitalWrite(8,LOW); digitalWrite(9,HIGH); digitalWrite(10,LOW); digitalWrite(11,LOW);

    buttons[1] = digitalRead(2);

    buttons[5] = digitalRead(3);

    buttons[9] = digitalRead(4);

    buttons[13] = digitalRead(5);
 
   //Read the next four
   digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,HIGH); digitalWrite(11,LOW);

    buttons[2] = digitalRead(2);

    buttons[6] = digitalRead(3);

    buttons[10] = digitalRead(4);

    buttons[14] = digitalRead(5);
 
   //Read the last four
   digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,HIGH);

    buttons[3] = digitalRead(2);

    buttons[7] = digitalRead(3);

    buttons[11] = digitalRead(4);

    buttons[15] = digitalRead(5);
  //Print the results
  for(int y=0;y<16;y++){
    Serial.print(buttons[y],DEC);
  }
  Serial.println();
  delay(500);
}

*EDIT*
I just figured out my problem. It's how I wired it. When there is voltage on four switches and I flip one, I put voltage on an input. That's how it should work. But when I flip a switch with no voltage on it, current travels back into the arduino; voltage drops to zero on the inputs.
4  Using Arduino / Programming Questions / Re: Dynamic Array of Integers on: June 26, 2013, 12:21:51 am
*pfft*
What I get for coding at 1AM. But now, it's not storing all the inputs. I can flip some switches and it will show. But if I flip other, it will show less. For example, right now I have two flipped. It is showing "0000000001000010", which is correct. But if I flip another, it will show "0000000001001000" when it should show "0000000001001010". And when it should show "1010000001001010", it shows "0000000001000000". I don't really have schematics right now, but I will create some soon.
5  Using Arduino / Programming Questions / Re: reading voltage frequency. Help on: June 26, 2013, 12:06:58 am
It sounds to me like you're asking for the voltage range; the peak and trough of the wave as indicated in this image rather than frequency, yes?


If so, you need the analogue pin of the Arduino (and we are about to get complicated). I'm not sure of the resolution of the Arduino, but I assume a full 5V will be indicated with 65535 (or is there an option to choose between 255 and 65535). If I am correct, then you are going to have the Arduino to check a value on the pin, echo it to terminal, and repeat (fast). You will then insert these values into something like Microsoft Excel and make a graph of them.

The highest number you get should be around 8519. The lowest should be about 3276. This is unless 5V becomes 255. Then these numbers, respectively, should be: about 33, and about 13. But if you want accuracy, you need an oscilloscope.
6  Using Arduino / Programming Questions / Dynamic Array of Integers on: June 25, 2013, 11:48:28 pm
I am currently trying to make a small project where I read 16 inputs with 8 pins; 4 inputs, 4 outputs. Here is my plan:
Set the array to all zeros (sixteen of 'em). Scan four buttons, storing their state in the array. Repeat for the next three buttons. Print their state on one line in the serial monitor (print the array). Print a new line. Wait 500ms (half a second), repeat.

My code compiles and uploads. But when I look at the serial monitor, it always prints straight zeros on each line. This leads me to believe that my array is not updating. I've checked my wiring, the code, everything.

Code:
void setup(){
  for(int z=2;z<6;z++){
    pinMode(z,INPUT);
  }
  for(int z=8;z<12;z++){
    pinMode(z,OUTPUT);
  }
    Serial.begin(9600);
}

void loop(){
  int buttons[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/*  for(int y=0;y<16;y++){
    buttons[y] = 0;
  }
 */
  digitalWrite(2,HIGH); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW);
  if(digitalRead(8)==1){
    buttons[0] = 1;
  }
  if(digitalRead(9)==1){
    buttons[4] = 1;
  }
  if(digitalRead(10)==1){
    buttons[8] = 1;
  }
  if(digitalRead(11)==1){
    buttons[12] = 1;
  }
 
  digitalWrite(2,LOW); digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite(5,LOW);
  if(digitalRead(8)==1){
    buttons[1] = 1;
  }
  if(digitalRead(9)==1){
    buttons[5] = 1;
  }
  if(digitalRead(10)==1){
    buttons[9] = 1;
  }
  if(digitalRead(11)==1){
    buttons[13] = 1;
  }
 
   digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,HIGH); digitalWrite(5,LOW);
  if(digitalRead(8)==1){
    buttons[2] = 1;
  }
  if(digitalRead(9)==1){
    buttons[6] = 1;
  }
  if(digitalRead(10)==1){
    buttons[10] = 1;
  }
  if(digitalRead(11)==1){
    buttons[14] = 1;
  }
   digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,HIGH);
  if(digitalRead(8)==1){
    buttons[3] = 1;
  }
  if(digitalRead(9)==1){
    buttons[7] = 1;
  }
  if(digitalRead(10)==1){
    buttons[11] = 1;
  }
  if(digitalRead(11)==1){
    buttons[15] = 1;
  }
  for(int y=0;y<16;y++){
    Serial.print(buttons[y],DEC);
  }
  Serial.println();
  delay(500);
}

I also tried removing the if statements so that the array elements update to the pin state directly.
Code:
  digitalWrite(2,HIGH); digitalWrite(3,LOW); digitalWrite(4,LOW); digitalWrite(5,LOW);
//  if(digitalRead(8)==HIGH){
    buttons[0] = digitalRead(8);
//  }
//  if(digitalRead(9)==HIGH){
    buttons[4] = digitalRead(9);
//  }
//  if(digitalRead(10)==HIGH){
    buttons[8] = digitalRead(10);
//  }
//  if(digitalRead(11)==HIGH){
    buttons[12] = digitalRead(11);
//  }
7  Using Arduino / Sensors / Re: Accelometer Question on: October 07, 2012, 01:05:57 pm
If I understand correctly, I have done something similar once. What you need to do is learn what values define "level." Use the "pulseIn(pin,state)" command, where "pin" is the pin your accelerometer's x or y axis is on and "state" is the logic level (this is usually high, or "1"). After getting these values from using "Serial.println(pulseIn(pin,1))", use if then statements. I will give an example:
Code:
//this is to get the values of "level"

const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer


void setup()
{
   // initialize serial communications:
  Serial.begin(9600);
  // initialize the pins connected to the accelerometer
  // as inputs:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
}

void loop()
{
  Serial.println(pulseIn(xPin,HIGH));
  Serial.println(pulseIn(yPin,HIGH));
  delay(500);
}

An example, with made-up numbers:
Code:
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
const int red_led = 4;          //connect red LED here
const int blue_led = 5;         //Blue LED here


void setup()
{
   // initialize serial communications:
  Serial.begin(9600);
  // initialize the pins connected to the accelerometer
  // as inputs:
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
}

void loop()
{
  if ((pulseIn(xPin,HIGH) > 10) and (pulseIn(xPin,HIGH) < 5000))
  { digitalWrite(red_led,HIGH); }
  else
  {digitalWrite(red_led,LOW);}
 
  if ((pulseIn(yPin,HIGH) > 1000) and (pulseIn(yPin,HIGH) < 1200))
  { digitalWrite(blue_led,HIGH); }
  else
  {digitalWrite(blue_led,LOW);}
}
8  Using Arduino / Sensors / Re: Get value from RFID tag and store it as a string on: October 07, 2012, 12:33:01 pm
Okay, I got it working for the most part. However, there is one huge problem. After the LCD displays the UID of the tag, the UID is replaced with some strange characters: each of them are decimal value 186. During that time, the code disables and re-enables the RFID reader. I did manage to use a longer time delay to get "Got some noise" to display instead of the strange characters. I have no idea what the crap is going on. I used Serial.println(tag) to show what the LCD was trying to display, and those strange dec186 characters return a blank character in the serial monitor. Here is my code:
Code:
#define RFID_ENABLE 10   //to RFID ENABLE
#define CODE_LEN 10      //Max length of RFID tag
#define VALIDATE_TAG 1  //should we validate tag?
#define VALIDATE_LENGTH  200 //maximum reads b/w tag read and validate
#define ITERATION_LENGTH 5000 //time, in ms, given to the user to move hand away
#define START_BYTE 0x0A
#define STOP_BYTE 0x0D
#define green 12
#define red 13

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
//LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(2, 3, 5, 6, 7, 8);
 
char tag[CODE_LEN]; 
 
void setup() {
  Serial.begin(2400); 
  pinMode(RFID_ENABLE,OUTPUT); 
 lcd.begin(16,2) ;
}
 
void loop() {
  enableRFID();
  delay(100);
  lcd.clear();
  lcd.print("TAG:");
  getRFIDTag();
  if(isCodeValid()) {
    disableRFID();
    sendCode();
    delay(ITERATION_LENGTH);
  } else {
    disableRFID();
    lcd.clear();
    lcd.print("Got some noise"); 
  }
  Serial.flush();
  clearCode();
}
 
/**
 * Clears out the memory space for the tag to 0s.
 */
void clearCode() {
  for(int i=0; i<CODE_LEN; i++) {
    tag[i] = 0;
  }
}
 
/**
 * Sends the tag to the LCD.
 */
void sendCode() {
    //lcd.clear();
    //lcd.setCursor(0,0);
    //lcd.print("TAG:"); 
    //Serial.println(tag);
    lcd.setCursor(0,1);
    for(int i=0; i <= 9; i++) {
      //lcd.setCursor(tag[i],1);
      Serial.println(tag[i]);
      lcd.print(tag[i]);
    }
}
 
/**************************************************************/
/********************   RFID Functions  ***********************/
/**************************************************************/
 
void enableRFID() {
   digitalWrite(RFID_ENABLE, LOW);
   digitalWrite(red, HIGH);digitalWrite(green,LOW);
}
 
void disableRFID() {
   digitalWrite(RFID_ENABLE, HIGH); 
   digitalWrite(red, LOW);digitalWrite(green,HIGH);
}
 
/**
 * Blocking function, waits for and gets the RFID tag.
 */
void getRFIDTag() {
  byte next_byte;
  while(Serial.available() <= 0) {}
  if((next_byte = Serial.read()) == START_BYTE) {     
    byte bytesread = 0;
    while(bytesread < CODE_LEN) {
      if(Serial.available() > 0) { //wait for the next byte
          if((next_byte = Serial.read()) == STOP_BYTE) break;       
          tag[bytesread++] = next_byte;                   
      }
    }               
  }   
}
 
/**
 * Waits for the next incoming tag to see if it matches
 * the current tag.
 */
boolean isCodeValid() {
  byte next_byte;
  int count = 0;
  while (Serial.available() < 2) {  //there is already a STOP_BYTE in buffer
    delay(1); //probably not a very pure millisecond
    if(count++ > VALIDATE_LENGTH) return false;
  }
  Serial.read(); //throw away extra STOP_BYTE
  if ((next_byte = Serial.read()) == START_BYTE) { 
    byte bytes_read = 0;
    while (bytes_read < CODE_LEN) {
      if (Serial.available() > 0) { //wait for the next byte     
          if ((next_byte = Serial.read()) == STOP_BYTE) break;
          if (tag[bytes_read++] != next_byte) return false;                     
      }
    }               
  }
  return true;   }
9  Using Arduino / Sensors / Re: Get value from RFID tag and store it as a string on: October 05, 2012, 06:10:10 pm
Well it didn't work. But it almost did. If someone wants to help, here's the code:
Code:
#define RFID_ENABLE 10   //to RFID ENABLE
#define CODE_LEN 10      //Max length of RFID tag
#define VALIDATE_TAG 1  //should we validate tag?
#define VALIDATE_LENGTH  200 //maximum reads b/w tag read and validate
#define ITERATION_LENGTH 2000 //time, in ms, given to the user to move hand away
#define START_BYTE 0x0A
#define STOP_BYTE 0x0D

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
//LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(2, 3, 5, 6, 7, 8);
 
char tag[CODE_LEN]; 
 
void setup() {
  Serial.begin(2400); 
  pinMode(RFID_ENABLE,OUTPUT); 
 lcd.begin(16,2) ;
}
 
void loop() {
  enableRFID();
  lcd.clear();
  getRFIDTag();
  if(isCodeValid()) {
    disableRFID();
    sendCode();
    delay(ITERATION_LENGTH);
  } else {
    disableRFID();
    lcd.clear();
    lcd.print("Got some noise"); 
  }
  Serial.flush();
  clearCode();
}
 
/**
 * Clears out the memory space for the tag to 0s.
 */
void clearCode() {
  for(int i=0; i<CODE_LEN; i++) {
    tag[i] = 0;
  }
}
 
/**
 * Sends the tag to the LCD.
 */
void sendCode() {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("TAG:"); 
    //Serial.println(tag);
    lcd.setCursor(0,1);
    for(int i=0; i<=CODE_LEN; i++) {
      lcd.setCursor(tag[i],1);
      lcd.print(tag[i]);
    }
}
 
/**************************************************************/
/********************   RFID Functions  ***********************/
/**************************************************************/
 
void enableRFID() {
   digitalWrite(RFID_ENABLE, LOW);   
}
 
void disableRFID() {
   digitalWrite(RFID_ENABLE, HIGH); 
}
 
/**
 * Blocking function, waits for and gets the RFID tag.
 */
void getRFIDTag() {
  byte next_byte;
  while(Serial.available() <= 0) {}
  if((next_byte = Serial.read()) == START_BYTE) {     
    byte bytesread = 0;
    while(bytesread < CODE_LEN) {
      if(Serial.available() > 0) { //wait for the next byte
          if((next_byte = Serial.read()) == STOP_BYTE) break;       
          tag[bytesread++] = next_byte;                   
      }
    }               
  }   
}
 
/**
 * Waits for the next incoming tag to see if it matches
 * the current tag.
 */
boolean isCodeValid() {
  byte next_byte;
  int count = 0;
  while (Serial.available() < 2) {  //there is already a STOP_BYTE in buffer
    delay(1); //probably not a very pure millisecond
    if(count++ > VALIDATE_LENGTH) return false;
  }
  Serial.read(); //throw away extra STOP_BYTE
  if ((next_byte = Serial.read()) == START_BYTE) { 
    byte bytes_read = 0;
    while (bytes_read < CODE_LEN) {
      if (Serial.available() > 0) { //wait for the next byte     
          if ((next_byte = Serial.read()) == STOP_BYTE) break;
          if (tag[bytes_read++] != next_byte) return false;                     
      }
    }               
  }
  return true;   }
10  Using Arduino / Sensors / Re: plz suggest me accelerometer on: October 05, 2012, 11:10:39 am
You can look on sparkfun:
https://www.sparkfun.com/categories/80
11  Using Arduino / Sensors / Re: Get value from RFID tag and store it as a string on: October 05, 2012, 11:09:16 am

I believe (after edits) that that may have gotten it. I'll have to check later, for I am currently working on another project at the moment.
12  Using Arduino / Sensors / Get value from RFID tag and store it as a string on: October 03, 2012, 10:29:41 pm
I have looked for a couple hours now and the closest code I found didn't work. I have an RFID card reader from Parallax. I would like to get a tags value with it and print it to an LCD screen. However, I cannot find a way to get the tags value. I plan on using the RX pin of the arduino.  All I need is a simple program that gets the tag ID and convert it to a string. From there, I know how to send it to the LCD.
Pages: [1]