Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 22, 2013, 05:03:06 am
lets say i want to upgrade the coding. so that it only display the character once it is requested. during that period, it hold the character in buffer. i seen to much way to hold the character in buffer. but, which one would simply the easy solution..
2  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 21, 2013, 12:02:30 pm
i see. in that case. how the exact method for me to to track the character been sent. When that reaches 16, any further characters sent will trigger the scroll command...

You'll need a variable that persists through loop:

Code:
static int charactersReceived = 0;

When you receive a character, you'll need to increment said variable:

Code:
if (Serial.available() > 0)
{
  charactersReceived++;
  // read and parse character
}

When that value reaches the threshold, do the shift:

Code:
if (charactersReceived() > 0)
{
  lcd.scrollDisplayLeft();
}

it works. thanks by the way arrch. the coding is like this..

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

static int charactersReceived = 0;

void setup() {
  // initialize serial:
  Serial.begin(9600); 
  lcd.begin(16, 1);
}

void loop() {
  // print the string when a newline arrives:
  while (Serial.available() > 0 ) {
    char inChar = (char)Serial.read();
    lcd.print(inChar);
   
    charactersReceived++;


      if (charactersReceived > 16)
      {
        lcd.scrollDisplayLeft();
      }   
  }
}
3  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 21, 2013, 11:43:38 am
i see. in that case. how the exact method for me to to track the character been sent. When that reaches 16, any further characters sent will trigger the scroll command...
4  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 21, 2013, 11:31:24 am
may i know this for loop can be used as the method in order to keep the track... i i think like this way. but, it just need fine tune the coding...

for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
  lcd.scrollDisplayLeft();
}

5  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 21, 2013, 11:15:50 am
yup. i already try it. but, it not working. i modified the coding like i posted above. let say i want to send ABCDEFGHIJKLMNOPQRSTUVWXYZ.
i send one by one. until letter P, which 16 character, the lcd display A until P. then, when i sent letter Q, supposed to be the lcd display BCDEFGHIJKLMNOPQ. the display scroll left one space. which the letter A no longer display at lcd display. i also try the combination of lcd.autoscroll & lcd.scrollDisplayLeft. also not working.
6  Using Arduino / Programming Questions / Re: LCD Autoscroll input get from serial monitor on: August 21, 2013, 10:33:34 am
The start of the second line is 0x40

Mark

i'm don't want to start at the next line. but, i want to remain at the first line. it just shift the character to the left & eliminate the first character as i key in the new character.
7  Using Arduino / Programming Questions / LCD Autoscroll input get from serial monitor on: August 21, 2013, 09:51:42 am
hi everyone. i have a question here. i want to display the character received from serial monitor & display it to 16x2 LCD Display. for character 1 until 16 i'm not having problem. however, i have trouble when i want to display the character after character 16. i'm intended to make the lcd scroll to the left one cursor if i key in the 17 character. the process keep repeat if i key in next character. the lcd will remain display 16 character. but, it keep updating the character if i enter new character via serial monitor. the idea supposed to be by using lcd.autoscroll. i created for loop for the counter of the lcd cursor. so, the lcd.autoscroll i put it inside the for loop counter. i already made the code. but, it is not working. i just want to ask your opinion what's wrong with my code here. thank you.

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  // initialize serial:
  Serial.begin(9600);  
  lcd.begin(16, 2);
}

void loop() {
  // print the string when a newline arrives:
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    lcd.print(inChar);
    
    
    for (int positionCounter = 0; positionCounter > 15; positionCounter++) {
    // scroll one position left:
    //lcd.scrollDisplayLeft();
    lcd.autoscroll();
    // wait a bit:
    //delay(150);
    }
}
8  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Found Bootloader active reprogramming firmware on: March 25, 2013, 01:53:17 am
before i program the xbee, i able to read the xbee. but, after it crash while program it, the xbee now cannot be read. even cannot be tested.
9  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Found Bootloader active reprogramming firmware on: March 24, 2013, 10:09:09 pm
this happen when i tried to program the xbee. i modified the modem configuration. then, while on the programming modem process, it suddenly crash. i've set the baud rate yo 9600. default baud rate. both baud rate in modem configuration & pc setting is 9600. i wonder how this happen. i manage to program 2 xbee modules. only 1 undergo this error. by the way, i try to change the baud rate to 57600, the same error happen while programming the xbee.
10  Using Arduino / Networking, Protocols, and Devices / Xbee Found Bootloader active reprogramming firmware on: March 24, 2013, 05:19:13 pm
hi. hello everyone. i'm having this kind of problem with my xbee. currently, i cannot communicate with my xbee. and, i cannot figure out the solution. together here, i attached the screenshot of the x-ctu showing the above problem. i hope anyone who manage to solve this kind of problem would give me a help. TQ.
11  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 25, 2013, 01:35:44 am
You could make that a 2D array, instead. Then, one argument would be an index that would define which row to use.

Or. use a switch statement to select which array to send. But, don't write 5 functions.

2D array? i think my experience in programming is just shallow. by the way, for the switch case. i understand that one. i'm gonna try it. but, perhaps i could learn how to do 2D array.
12  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 24, 2013, 08:25:39 pm
Why do you have 5 nearly identical functions? One would suffice. Pass it arguments.

Perhaps you've observed that functions like digitalRead() don't have numeric suffixes.

in each deletefinger() function, it has it own command code need be transmitted via serial.write. perhaps if has other way, i could learn a new thing too.
13  Using Arduino / Programming Questions / Re: TX command code & RX respond code of module via serial com on: January 23, 2013, 12:10:10 pm
below code is already functioning. but, may i ask. is there any other way that i can make the code become less line. i think there is another way. but, i don't have any idea how to do it. i think the value of adc_key_in can be made into for loop so that if counter 0, it will call function deleteFinger0();
but i don't have any clue on how to do it. i would be glad if someone could give me a hint on how to do it. thank you.

Code:
//==========================================================================
// Author     : CYTRON TECHNOLOGIES SDN BHD
// Project             : Arduino Duemilanove
// Project description : Project_1: "Hello World" and utilize switch
//==========================================================================

#include <LiquidCrystal.h>

/*
  The circuit:
 * LCD RS pin to digital pin 8
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7
 * LCD R/W pin to ground
*/

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int analogPin = A0;
int adc_key_old;
int adc_key_in;
int NUM_KEYS = 5;
int key=-1;
int adc_key_val[5] ={30, 150, 360, 535, 760 };       
               
byte deleteFingerPrint0[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x00, 0xFA}; // 8 bytes
byte deleteFingerPrint1[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x01, 0xFB}; // 8 bytes
byte deleteFingerPrint2[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x02, 0xFC}; // 8 bytes
byte deleteFingerPrint3[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x03, 0xFD}; // 8 bytes
byte deleteFingerPrint4[] = {0x4D, 0x58, 0x10, 0x03, 0x42, 0x00, 0x04, 0xFE}; // 8 bytes

byte respondCorrect[] = {0x4D, 0x58, 0x30, 0x01, 0x01, 0xD7}; // 6 bytes

byte operationSuccessDelete[] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x31, 0x4A}; // 7 bytes
byte parameterErrorDelete [] = {0x4D, 0x58, 0x30, 0x02, 0x42, 0x35, 0x4E}; // 7 bytes
byte respond[6],operation[7],a,f,g;
                   
                   
/*******************************************************************************
* PRIVATE FUNCTION: setup()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Define of I/O pin as Input or Output
*
*******************************************************************************/
// The setup() method runs once, when the sketch starts
void setup ()
{
  // initialize serial:
  Serial.begin(57600);
 
  lcd.begin(16, 2);                         // set the lcd dimension
  lcd.print("  CYTRON TECH.");              // display the text
  lcd.setCursor(0,1);                       // set lcd.setCursor (column,row)
  lcd.print(" Eg. LCD Shield");   
  delay(1500);                              // delay for 3000ms
  lcd.clear();
  adc_key_old = analogRead(analogPin);      // store the unpress key value
}


/*******************************************************************************
* PRIVATE FUNCTION: loop()
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Non-Stop looping
*
*******************************************************************************/
void loop()
{
  lcd.setCursor(0,0);             
  lcd.print("Fingerprint Reader");
  lcd.setCursor(0,1);
  lcd.print("Select Address");

  adc_key_in = analogRead(analogPin);     // read ADC value
  adc_key_in = get_key(adc_key_in);
 
  if (adc_key_in==0)
  {
    deleteFinger0();
    correctRespond();
    operationSuccesful();
  }
 
  else if (adc_key_in==1)
  {
    deleteFinger1();
    correctRespond();
    operationSuccesful();
  }
 
  else if (adc_key_in==2)
  {
    deleteFinger2();
    correctRespond();
    operationSuccesful();
  }

  else if (adc_key_in==3)
  { 
    deleteFinger3();
    correctRespond();
    operationSuccesful();
  }

  else if (adc_key_in==4)
  {
    deleteFinger4();
    correctRespond();
    operationSuccesful();
  }
}
 

/*******************************************************************************
* PRIVATE FUNCTION: get_key
*
* PARAMETERS:
* ~ integer
*
* RETURN:
* ~ unsigned int input
*
* DESCRIPTIONS:
* convert the ADC value to number between 0 to 4
*
*******************************************************************************/
int get_key(unsigned int input)
{
int k;
   
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
{
           
    return k;
        }
}
   
    if (k >= NUM_KEYS)
        k = -1;     // No valid key pressed
   
    return k;
}

void deleteFinger0(){
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print("Del Fingerprint1");

  // write the 8bytes array of the command code
  Serial.write(deleteFingerPrint0, sizeof(deleteFingerPrint0));
  delay(1500);
}

void deleteFinger1(){
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print("Del Fingerprint2");

  // write the 8bytes array of the command code
  Serial.write(deleteFingerPrint1, sizeof(deleteFingerPrint1));
  delay(1500);
}

void deleteFinger2(){
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print("Del Fingerprint3");

  // write the 8bytes array of the command code
  Serial.write(deleteFingerPrint2, sizeof(deleteFingerPrint2));
  delay(1500);
}

void deleteFinger3(){
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print("Del Fingerprint4");

  // write the 8bytes array of the command code
  Serial.write(deleteFingerPrint3, sizeof(deleteFingerPrint3));
  delay(1500);
}

void deleteFinger4(){
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print("Del Fingerprint5");

  // write the 8bytes array of the command code
  Serial.write(deleteFingerPrint4, sizeof(deleteFingerPrint4));
  delay(1500);
}

void correctRespond() {
  // Now, reply contains all 6 bytes
  for(byte x=0; x<6; x++)
  {
    while(Serial.available() == 0) {}; // Wait for a byte
    respond[x] = Serial.read();
   
    a = memcmp(respondCorrect, respond, sizeof(respondCorrect));

    if (a==0) {
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // Print a message to the LCD.
      lcd.print("Correct Respond");
      }
 
    else {
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // Print a message to the LCD.
      lcd.print("Wrong Respond");
      }
  }
  delay(1500);
}

void operationSuccesful () {
  // Now, reply contains all 7 bytes
  for(byte x=0; x<7; x++)
  {
    while(Serial.available() == 0) {}; // Wait for a byte
    operation[x] = Serial.read();
   
    f = memcmp(operationSuccessDelete, operation, sizeof(operationSuccessDelete));
    g = memcmp(parameterErrorDelete, operation, sizeof(parameterErrorDelete));
   
    if (f==0) {
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // Print a message to the LCD.
      lcd.print("Operation Success");
      }
     
    else if (g==0) {
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // Print a message to the LCD.
      lcd.print("Parameter Error");
      }
   
    else  {
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // Print a message to the LCD.
      lcd.print("Please Restart");
      }
  }
  delay(1500);
}
14  Using Arduino / Programming Questions / Re: need help to modify this push button code on: January 21, 2013, 10:10:15 pm
In your code you have: (currentState == 1);

That won't do as you are intending. Assuming you want currentState to change to 1 you need to change it to: currentState = 1;

haha. thank you for that. now it is working. thanks buddy.
15  Using Arduino / Programming Questions / Re: need help to modify this push button code on: January 21, 2013, 09:29:29 pm
(currentState == 1); does nothing.  Actually not quite true, but not what you want
currentState = 1; sets the currentState variable to 1

== compares 2 things
= sets the variable on the left to the value on the right.

actually not quite true? i think my coding is like this. my initial state is zero by the way. currentState = 0; sets the currentState variable to 1
Pages: [1] 2 3 ... 7