| Arduino Forum ::  Members :: masterraf
 Show Posts Pages: [1] 2
 1 Using Arduino / Programming Questions / Re: Convert Hex to exact Dec image on: March 01, 2013, 03:51:52 am QuoteNo, what you did was multiply the value by 16.I read more about bitWise operators and found this "in fact, left shifting is the equivalent of multiplying by a power of two."You were right. Moving 4 bits to the left is also equivalent to multiplying the value by 16.. Anyway, what should I do if I need to change a hex value of 12 into a dec value of 12...Or maybe a different approach..a char 1 and a char 2 into one single decimal variable of 12...The algorithm I can only think about is doing it manually likeif(heading == 0x12){decheading=12;}But I've got 0-360 HEX...and that means 360 if statements =.=
 2 Using Arduino / Programming Questions / Re: Convert Hex to exact Dec image on: March 01, 2013, 03:31:10 am Quotethe "<<" is multiplying by 16 (hexadecimal, remember), but you want decimal, so what value do you think you might want to multiply by?I'm sorry sir AWOL but what do you mean by this?....what I did there is I moved heading 4 bits to the left so that I can use OR operations to it for the next HEX value to be recieved...like if the 1st data is 1,HEX which is equal to 0001 then I move it 4 bits to he left, it will become 0001 000 then OR it with the next value for example 2,HEX which is equal to 0010. Using OR operation on 0001 0000 and 0010. It will be 0001 0010 which is equal to 12 in HEX.But what I want is instead of having 12 in HEX..I want to have a 12 in DEC but I can't think of an algorithm for doing so...
 3 Using Arduino / Programming Questions / Convert Hex to exact Dec image on: March 01, 2013, 02:04:08 am Good Day guys!I've got an electronic compass that sends char data through serial connection.For example if the degrees read is 250 it will send a char 2, then a char 5, then a char 0.I was able to use this data by converting it to HEX with this codeCode:int asc2dec (char c){  if (c >= '0' && c <= '9')    return c - '0' ;  if (c >= 'A' && c <= 'F')    return c - 'A' + 10 ;  if (c >= 'a' && c <= 'f')    return c - 'a' + 10 ;}and then combining it all together into one variable by moving 4 bits to the left and using OR logic like thisCode: for(byte r= 1; r < 4; r++){          heading <<= 4 ;          heading |= asc2dec(EC_Data[r]);so this code returns a hexadecimal value of the read degrees from the compassNow what I want is instead of having a hex value, I want to a have a decimal value...Like if the compass sends a char of 250. I also want to have a decimal value of 250?Any ideas on how to do this? THX!
 4 Using Arduino / Programming Questions / Re: Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 09:26:16 am I already made it work! Thx PaulS for teaching me the debugging part using LEDs....i forgot doing that..lolBut anyway...how does a simple Serial.println messes up the value of my flagdone? Here is the code that worked...I removed the wiegand counter option which changes the flagdone valueI hope by doing so I dont get wrong values in the long run xDCode:#define MAX_BITS 100                 // max number of bits unsigned char databits[MAX_BITS];    // stores all of the data bitsunsigned char bitCount;              // number of bits currently capturedunsigned long facilityCode=0;        // decoded facility codeunsigned long cardCode=0;            // decoded card code// interrupt that happens when INTO goes low (0 bit)void ISR_INT0(){  digitalWrite(13,HIGH);  bitCount++;   }// interrupt that happens when INT1 goes low (1 bit)void ISR_INT1(){  digitalWrite(13,LOW);  databits[bitCount] = 1;  bitCount++;}void setup(){  pinMode(13, OUTPUT);  // LED  pinMode(2, INPUT);     // DATA0 (INT0)  pinMode(3, INPUT);     // DATA1 (INT1)    Serial.begin(9600);  Serial.println("RFID Readers");    // binds the ISR functions to the falling edge of INTO and INT1  attachInterrupt(0, ISR_INT0, FALLING);    attachInterrupt(1, ISR_INT1, FALLING);  }void loop(){  Serial.println("aw");  rfid();}void rfid(){    // if we have bits and we the weigand counter went out  if (bitCount > 25) {    unsigned char i;    digitalWrite(13,LOW);      // we will decode the bits differently depending on how many bits we have    // see www.pagemac.com/azure/data_formats.php for mor info    if (bitCount == 35)    {      digitalWrite(13,LOW);      // 35 bit HID Corporate 1000 format      // facility code = bits 2 to 14      for (i=2; i<14; i++)      {         facilityCode <<=1;         facilityCode |= databits[i];      }            // card code = bits 15 to 34      for (i=14; i<34; i++)      {         cardCode <<=1;         cardCode |= databits[i];      }            printBits();    }    else if (bitCount == 26)    {      digitalWrite(13,LOW);      // standard 26 bit format      // facility code = bits 2 to 9      for (i=1; i<9; i++)      {         facilityCode <<=1;         facilityCode |= databits[i];      }            // card code = bits 10 to 23      for (i=9; i<25; i++)      {         cardCode <<=1;         cardCode |= databits[i];      }            printBits();      }    else {      digitalWrite(13,LOW);      delay(200);      digitalWrite(13,HIGH);     Serial.println("Unable to decode.");     }     // cleanup and get ready for the next card     bitCount = 0;     facilityCode = 0;     cardCode = 0;     for (i=0; i
 5 Using Arduino / Programming Questions / Re: Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 09:13:00 am I found the problem..it seems that I can't even enter if (bitCount > 0 && flagDone)because flagdone won't get 1.What seems to be causing this?
 6 Using Arduino / Programming Questions / Re: Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 09:03:34 am I also added more Serial.prints on rfid() an it prints them all outI tried adding a digitalWrite LOW inside the if( bitcount==26) and also if(bitcount==35)and the LED doesnt turn off?So i guess these mean i'm not getting all the bits I need?what can be a solution for this?**EDITI found the problem..it seems that I can't even enter if (bitCount > 0 && flagDone)because flagdone won't get 1.What seems to be causing this?
 7 Using Arduino / Programming Questions / Re: Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 08:59:22 am QuoteYou could add some LEDs, and toggle them in the ISRs, to see if ISRs are being activated. You could add more Serial.print()s in rfid(), to see where it really gets to.I tried what you said..I included a digitalwrite HIGH on isrint0 and a LOW on isrint1 and noticed that when I swipe the card 1st time the LED lit up and the 2nd time the LED blinks a little..so it seems the ISR are getting activated but still it doesn't print the card value in the serial monitor
 8 Using Arduino / Programming Questions / Re: Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 08:43:30 am QuoteYou're changing variables in an interrupt handler (like databits[], bitCount, flagDone, etc.) without declaring them as volatile. If you don't do that results may be unpredictable as the compiler is free to optimize in a way that may change the functionality.I haven't notice any unpredictable results before...but I guess no harm will be done by declaring them as volatile so I'll add them anyway...thx!QuoteThose Serial.print()s, even though they are commented out, do not belong in the interrupt service routines. Get rid of them.What have you added to loop()? What happened when you did that? What serial output do you see?I simply add a Serial.println("test"); on the loop just to test If the reading of RFID will work with other functions.( If this worked, I'm going to add additional functions such as reading compasses with software serial..and also some codes for ethernet)By adding it the output was purelytesttesttesttesteven though i swiped a card already. My expected output wastesttesttestFC=99999, CC=000000  (this will appear if i swipe a card)testtesttestsomething like this
 9 Using Arduino / Programming Questions / Wiegand RFID (attachinterrupt) + new functions on: February 20, 2013, 08:26:50 am Good Day Guys!I am trying to read a wiegand RFID with the use of this codeCode:#define MAX_BITS 100                 // max number of bits #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse.  unsigned char databits[MAX_BITS];    // stores all of the data bitsunsigned char bitCount;              // number of bits currently capturedunsigned char flagDone;              // goes low when data is currently being capturedunsigned int weigand_counter;        // countdown until we assume there are no more bitsunsigned long facilityCode=0;        // decoded facility codeunsigned long cardCode=0;            // decoded card code// interrupt that happens when INTO goes low (0 bit)void ISR_INT0(){  //Serial.print("0");  bitCount++;  flagDone = 0;  weigand_counter = WEIGAND_WAIT_TIME;    }// interrupt that happens when INT1 goes low (1 bit)void ISR_INT1(){  //Serial.print("1");  databits[bitCount] = 1;  bitCount++;  flagDone = 0;  weigand_counter = WEIGAND_WAIT_TIME;  }void setup(){  pinMode(13, OUTPUT);  // LED  pinMode(2, INPUT);     // DATA0 (INT0)  pinMode(3, INPUT);     // DATA1 (INT1)    Serial.begin(9600);  Serial.println("RFID Readers");    // binds the ISR functions to the falling edge of INTO and INT1  attachInterrupt(0, ISR_INT0, FALLING);    attachInterrupt(1, ISR_INT1, FALLING);    weigand_counter = WEIGAND_WAIT_TIME;}void loop(){  rfid();}void rfid(){  // This waits to make sure that there have been no more data pulses before processing data  if (!flagDone) {    if (--weigand_counter == 0)      flagDone = 1;   }    // if we have bits and we the weigand counter went out  if (bitCount > 0 && flagDone) {    unsigned char i;        Serial.print("Read ");    Serial.print(bitCount);    Serial.print(" bits. ");        // we will decode the bits differently depending on how many bits we have    // see www.pagemac.com/azure/data_formats.php for mor info    if (bitCount == 35)    {      // 35 bit HID Corporate 1000 format      // facility code = bits 2 to 14      for (i=2; i<14; i++)      {         facilityCode <<=1;         facilityCode |= databits[i];      }            // card code = bits 15 to 34      for (i=14; i<34; i++)      {         cardCode <<=1;         cardCode |= databits[i];      }            printBits();    }    else if (bitCount == 26)    {      // standard 26 bit format      // facility code = bits 2 to 9      for (i=1; i<9; i++)      {         facilityCode <<=1;         facilityCode |= databits[i];      }            // card code = bits 10 to 23      for (i=9; i<25; i++)      {         cardCode <<=1;         cardCode |= databits[i];      }            printBits();      }    else {      // you can add other formats if you want!     Serial.println("Unable to decode.");     }     // cleanup and get ready for the next card     bitCount = 0;     facilityCode = 0;     cardCode = 0;     for (i=0; i
 10 Using Arduino / Project Guidance / ACM08Y RFID reader HELP on: February 15, 2013, 11:52:42 pm Good day guys! First off, I'm not really sure if this is the right section to post this problem , but since it is related to my project I guess it is somehow ok Anyway, I recently bought this RFID readerhttp://www.soselectronic.com/a_info/resource/c/ACM08Y_ID_Card_reader.pdfI have experienced programming RFID reader like the RDM630 before so i thought I will have no problem in using this one..I've tried reading the data sent by the RFID using an McU but all I get is random characters of øøøøøøÿÿÿÿÿÿÿÿ and I have no idea why. I haven't experience having problems like this on the RDM630 before. Baud rate is set at 9600Anyone has any idea on how to solve this problem? Should I use a hyper terminal or the McU way of serial monitor is just fine?
 11 Using Arduino / Programming Questions / Anyone familiar with EtherCard.h or ENC28J60 Ethernet shield? on: February 04, 2013, 07:43:30 am Good day guys! I'm currently working on a web server switch for my project and here is the code. So far it is working fine, its just having some timeouts after it has been open for more than 30 mins.#include // Ethernet Part declarationstatic byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };#define BUFFER_SIZE 800BufferFiller bfill;byte Ethernet::buffer[BUFFER_SIZE];static byte myip[] = {192,168,1,15};// Ethernet Part ends hereconst int ledPin = 6;void setup () {   Serial.begin(9600);  //Ethernet Debugging ether.begin(BUFFER_SIZE, mymac, 10);ether.staticSetup(myip);//Ethernet Debugging Ends Here  pinMode(10, OUTPUT);                        digitalWrite(10, HIGH);    pinMode(ledPin, OUTPUT);  digitalWrite(ledPin, LOW);}void homepage(){      bfill.emit_p(PSTR("Ethernet Controller""

IP Based Automated
""

Room Destination
""
""""""""

Mobot is

"   ));}void http_Unauthorized(){      bfill.emit_p(PSTR("HTTP/1.0 401 Unauthorized\r\n"    "Content-Type: text/html\r\n\r\n"    "

401 Unauthorized

 12 Using Arduino / Programming Questions / Re: Load full html on SD ( Ethernet Shield) on: January 30, 2013, 12:51:14 pm Thx for the reply sir!Here is the code that I triedCode:#include #include #include // Ethernet Part declarationstatic byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };#define BUFFER_SIZE 700BufferFiller bfill;byte Ethernet::buffer[BUFFER_SIZE];static byte myip[] = {192,168,1,15};// Ethernet Part ends here// SD card declarationconst uint8_t SdChipSelect = 4;Sd2Card card;SdVolume volume;SdFile myfile;SdFile root;// SD card declaration ends hereconst int ledPin = 6;// store error strings in flash to save RAM#define error(s) error_P(PSTR(s)) void error_P(const char* str) {  PgmPrint("error: ");  SerialPrintln_P(str);  if (card.errorCode()) {    PgmPrint("SD error: ");    Serial.print(card.errorCode(), HEX);    Serial.print(',');    Serial.println(card.errorData(), HEX);  }  while(1);}void setup () {   Serial.begin(9600);     //SD card debugging  PgmPrint("Free RAM: ");  Serial.println(FreeRam());    if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");    // initialize a FAT volume  if (!volume.init(&card)) error("vol.init failed!");  PgmPrint("Volume is FAT");  Serial.println(volume.fatType(),DEC);  Serial.println();    if (!root.openRoot(&volume)) error("openRoot failed");  Serial.println();  PgmPrintln("Done");//SD card debugging ends here  //Ethernet Debugging  Serial.println("Control WebPage");   if (ether.begin(BUFFER_SIZE, mymac, 10)==0)    Serial.println( "Failed to access Ethernet controller"); else   Serial.println("Ethernet controller initialized");   if (!ether.staticSetup(myip))    Serial.println("Failed to set IP address");  Serial.println();//Ethernet Debugging Ends Here  pinMode(10, OUTPUT);                        digitalWrite(10, HIGH);    pinMode(ledPin, OUTPUT);  digitalWrite(ledPin, LOW);}const char http_Unauthorized[] PROGMEM =    "HTTP/1.0 401 Unauthorized\r\n"    "Content-Type: text/html\r\n\r\n"    "

401 Unauthorized

 13 Using Arduino / Programming Questions / Re: Basic problem on: January 30, 2013, 12:35:35 pm Quoteinstead of 1 analog input I want to detect 7. Then you have to declare 7 sensorpins variable and 7 sensorvalues to read your data likeCode:int sensorPin7 = A8;  // select the input pin A8int sensorPin6 = A7;int sensorPin5 = A6;int sensorValue1 = 0;  // variable to store the value coming from the sensorint sensorValue2 = 0;int sensorValue3= 0;void setup() {  // declare the ledPin as an OUTPUT:  pinMode(ledPin, OUTPUT);  }void loop() {  // read the value from the sensor:  sensorValue1 = analogRead(sensorPin7);   sensorValue2 = analogRead(sensorPin6);  sensorValue3 = analogRead(sensorPin5);                   }Of course this reads 3 analog pins...just declare more if you want more...is this what you mean?
 14 Using Arduino / Programming Questions / Load full html on SD ( Ethernet Shield) on: January 30, 2013, 12:24:54 pm Good day guys! For my project im using an ENC26j80 Ethernet shield with sd card.I am trying to make a web switch. for testing purposes I tried 1st with a simple led web switch.Here is my code modified from the tutorials.Code:#include #include #include // Ethernet Part declarationstatic byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };#define BUFFER_SIZE 700BufferFiller bfill;byte Ethernet::buffer[BUFFER_SIZE];static byte myip[] = {192,168,1,15};// Ethernet Part ends here// SD card declarationconst uint8_t SdChipSelect = 4;Sd2Card card;SdVolume volume;SdFile myfile;SdFile root;// SD card declaration ends hereconst int ledPin = 6;// store error strings in flash to save RAM#define error(s) error_P(PSTR(s)) void error_P(const char* str) {  PgmPrint("error: ");  SerialPrintln_P(str);  if (card.errorCode()) {    PgmPrint("SD error: ");    Serial.print(card.errorCode(), HEX);    Serial.print(',');    Serial.println(card.errorData(), HEX);  }  while(1);}void setup () {   Serial.begin(9600);     //SD card debugging  PgmPrint("Free RAM: ");  Serial.println(FreeRam());    if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");    // initialize a FAT volume  if (!volume.init(&card)) error("vol.init failed!");  PgmPrint("Volume is FAT");  Serial.println(volume.fatType(),DEC);  Serial.println();    if (!root.openRoot(&volume)) error("openRoot failed");    Serial.println();  PgmPrintln("Done");//SD card debugging ends here  //Ethernet Debugging  Serial.println("Control WebPage");   if (ether.begin(BUFFER_SIZE, mymac, 10)==0)    Serial.println( "Failed to access Ethernet controller"); else   Serial.println("Ethernet controller initialized");   if (!ether.staticSetup(myip))    Serial.println("Failed to set IP address");  Serial.println();//Ethernet Debugging Ends Here pinMode(10, OUTPUT);                        digitalWrite(10, HIGH);    pinMode(ledPin, OUTPUT);  digitalWrite(ledPin, LOW);}const char http_Unauthorized[] PROGMEM =    "HTTP/1.0 401 Unauthorized\r\n"    "Content-Type: text/html\r\n\r\n"    "

401 Unauthorized

";void homepage(){      bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"      "WebLed"      "
Web Remote
"      "

"      "