element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum wirless display using Arduino and NRF24L01
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 32 replies
  • Answers 2 answers
  • Subscribers 394 subscribers
  • Views 3136 views
  • Users 0 members are here
  • help
  • nrf24l01+
  • led
  • arduino
Related

wirless display using Arduino and NRF24L01

billpenner
billpenner over 11 years ago

I am bogged down in this project

I'm using Arduino UNO.
I Have the keyboard data decoded and printing to the serial port (computer) fine.
I  want to send this data to a 16X2  LCD as soon as it is entered on the keypad.
  The LCD is working fine with serial input from computer to the Arduino but I cannot get the data to display on the
  LCD as soon as  a key is depressed. I have to send “enter”, then all three numbers are displayed.
I must have all three numbers sent to the transmitter as a group but the LCD should display them instantly as they are entered.
When the three numbers have been entered , the "*" key will send the string of numbers to a  NRF24L01.
Another  NRF24L01 and Arduino UNO will decode the data and display the numbers on a large 3 digit, 7 segment display.
The 7 segment display/decoder is working fine.
I can't seem to get the keyboard data into a form suitable for sending to either the 16X2  LCD or the  NRF24L01.
I can't even seem to get it into a string. I guess this is the form I need?
I think the  NRF24L01 will need a string of 3 digit numbers as a string? Right?
This is the code I have so far. Any help in getting me headed in the right direction would be greatly appreciated.
I gone over and over all the examples and tutorials on strings I can find but I can't seem to absorb it enough to make it work.
// key board to remote display.
#include <Keypad.h>
#include <LiquidCrystal.h>
int i;
String  A;                // Setup string to contain the data to transmit.
String  B;
String  C;
String  D;
                                          // set up the keypad decode
const byte ROWS = 4;       // Four rows
const byte COLS = 3;         // Three columns
                                          // Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = { 5, 4, 3, 2 }; // keypad rows to Arduino pins
byte colPins[COLS] = { 6, 7, 8 }; //keypad columns to Arduino pins
                                                    // Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define NRF2401                      // output pin to xmitter
void setup()
{
  Serial.begin(9600);
  }
void loop()
{
char key = kpd.getKey();
  delay(10);
  if(key)  // Check for a valid key.
     {
     switch (key)                            // check for transmit or clear keys
    {
      case '*':                                     //send data to transmitter
        Serial.print(key);                      // send data to xmitter
        Serial.println("  pressed");       //testing
      break;
    
                // digitalWrite(transmit); // for testing
                 // break;                          // for testing
      case '#':                                     // clear and reset data
       A,B,C="";                                   // clear strings
        Serial.print(key);    
        Serial.println(" Cleared");         // testing
       // Serial.println(C4);  // for testing
       break;                    
   
      default:    //accum max 3 char
        for(int i=0 ; i<4 ; i++){
         if (i==1)
           A = A + char(key);
           Serial.print (A);            // for testing
           Serial.print (key);        // for testing
         if(i==2)
           B = A +(key);               // for testing
           Serial.print(B);            // for testing
         if(i==3)  
           C = B +(key);
          Serial.println(C);          // for testing
           Serial.print(i);             // for testing
           Serial.print (A);           // for testing
        break;
         // Serial.println(C);         // for testing
       }
     }
     /*    Serial.print (A);
           Serial.print(char(B));                        // For testing
           Serial.print(char(C));
           Serial.print (char(A+B+C+D));
     */
          if(i==4)                                                    //Too many digits! Only three allowed
           Serial.print("   ERROR");
         // Serial.println(i) ;
    }
  }  
  • Sign in to reply
  • Cancel

Top Replies

  • bobcroft
    bobcroft over 10 years ago in reply to Former Member +1
    Hi Averil, Peter has posted some information for you that will help you. However, if you need anything else please send me your email address and I'll forward what I have. I used an Arduino and a LCD display…
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    I see no code what so ever here to write to the LCD, sure you have the library included but thats it

     

    you need to create an instance of the LCD library and send the data to it as you read from the keypad

     

    this might help get you started http://tronixstuff.com/2013/12/16/arduino-tutorials-chapter-42-numeric-keypads/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • billpenner
    0 billpenner over 11 years ago in reply to Robert Peter Oakes

    I have just spent the last while on the link you sent. What an excellent site. Thank you.

    I will rewrite the sketch and get back to you with the question of sending the 3 digits to the radio.

    You are a great resource.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to billpenner

    Good luck, I look forward to hearing how you did

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to billpenner

    No problems, I am quite familiar with using the NRF radios and so could help if needed

     

     

     

    You just have to ask

     

     

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billpenner
    0 billpenner over 11 years ago in reply to Robert Peter Oakes

    I think this will be fine. I will have to rewrite some of it since I am using the parallel LCD. Also I will have to go to the Mega since I will not have enough digital pins. (No problem)

    Thanks again.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • billpenner
    0 billpenner over 11 years ago in reply to Robert Peter Oakes

    I think this will be fine. I will have to rewrite some of it since I am using the parallel LCD. Also I will have to go to the Mega since I will not have enough digital pins. (No problem)

    Thanks again.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to billpenner

    If you use a SPI to parallel or I2C to parallel chip you could stick with the 328. But the mega is more than able too and provides plenty of additional IO for future expansion

     

    Let us know how you get on

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billpenner
    0 billpenner over 11 years ago in reply to Robert Peter Oakes

    Peter:

    I have rebuilt the sketch using your reference (tronixstuff.com). great tutorials there. thanks.

    I am using the mega currently.

     

    This is the error I get when compiling

    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:15:  undefined reference to `loop'C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:15: undefined reference to `loop'

     

    I went to the above error reference copied (below).

     

        USBDevice.attach();

     

    #endif

     

      

     

        setup();

     

      

     

        for (;;) {

     

            loop();

     

            if (serialEventRun) serialEventRun();

     

        }

     

          

     

        return 0;

     

    }

     

    I can not decipher what could be wrong. this seems to be referring to USB device...
    I'm afraid I am in over my head.
    Could you please help me fix it or send me for more education?

     

     

    This the current code

     

    //keypad/LCD combo
    // http://tronixstuff.com/tutorials > chapter 42

    #include <Keypad.h>
    #include<LiquidCrystal.h>
    char C1,C2,C3,C4 ;
    LiquidCrystal lcd(27, 26, 25, 24, 23, 22);

          // Create the Keypad
    const byte ROWS = 4; // Four rows
    const byte COLS = 3; // Three columns
            // Define the Keymap
    char keys[ROWS][COLS] =
    {
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'#','0','*'}
    };

    byte rowPins[ROWS] = {5,4,3,2}; // keypad rows to Arduino pins
    byte colPins[COLS] = {8,7,6}; //keypad columns to Arduino pins

    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

    char PIN[6]={
      '1','2','A','D','5','6'}; // our secret  number
    char attempt[6]={
      '0','0','0','0','0','0'}; // used for comparison
    int z=0;

    void setup()
    {
    Serial.begin(9600);
      lcd.begin(16, 2);
      lcd.print("PIN Lock ");
      delay(1000);
      lcd.clear();
      lcd.print("  Enter PIN...");
    }

    void correctPIN() // do this if correct PIN entered
    {
      lcd.print("* Correct PIN *");
      delay(1000);
      lcd.clear();
      lcd.print("  Enter PIN...");
    }
    void incorrectPIN() // do this if incorrect PIN entered
    {
      lcd.print(" * Try again *");
      delay(1000);
      lcd.clear();
      lcd.print("  Enter PIN...");
    }

    void checkPIN()
    {
      int correct=0;
      int i;
      for ( i = 0;   i < 6 ;  i++ )
      {

        if (attempt[i]==PIN[i])
        {
          correct++;
        }
      }
      if (correct==6)
      {
        correctPIN();
      }
      else
      {
        incorrectPIN();
      }

      for (int zz=0; zz<6; zz++)
      {
        attempt[zz]='0';
      }
    }

    void readKeypad()
    {
      char key = keypad.getKey();
      if (key != NO_KEY)
      {
        attempt[z]=key;
        z++;
        switch(key)
        {
        case '*':
          z=0;
          break;
        case '#':
          z=0;
          delay(100); // for extra debounce
          lcd.clear();
          checkPIN();
          break;
        }
      }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to billpenner

    Very straight forward problem:

     

    every sketch MUST have two functions specifically "Setup()" which you have, this is used to initialize stuff your using and also "loop()" where you kick off your code. The error your getting is because you dont have the lop() function.

     

    this is the one from the chapter42 of the tronix web site

     

    void loop()

    {

      char key = keypad.getKey();

      if (key != NO_KEY)

      {

        lcd.print(key);

        count++;

        if (count==17)

        {

          lcd.clear();

          count=0;

        }

      }

    }


    you need a loop() function also to read the keypad, collect your keys and display them onto the lcd, also to call your functions like CheckKey() etc.


    That is why you have the error shown

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to Robert Peter Oakes

    Oh, they MUST have those two, but you can add your own funcions as well

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billpenner
    0 billpenner over 11 years ago in reply to Robert Peter Oakes

    I am so embarrassed. I obviously deleted while I was cleaning it up. What a foolish mistake. I vow to pay better attention in the future. Thanks for being so nice.

    Bill

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to billpenner

    No worries, happens to us all from time to time

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billpenner
    0 billpenner over 10 years ago in reply to Robert Peter Oakes

    my  code was basically  from  http://tronixstuff.com/tutorials > chapter 42.  I have changed and added sections so that I can

    1. Get a PIN for authority.

    2. Get the message from the keypad.

    3. Send the message wirelessly to another  NRF24 / Arduino for display on a large 7 segment display.

    4. Reset and wait for the next PIN etc.

     

    I have all the sections working individually but cannot seem to go to the  right section based on the results of the previous section.

    In basic I would jump to a subroutine and go back to the main code for the next operation. In this sketch (LCDKeypad) I keep ending up in the wrong place in the code.

    This is probably just my lack of understanding of C++.I have looked over many samples but cannot find code close enough to help me.could you please look over the sketch

    and provide guidance. your previous help is very much appreciated.

     

    //keypad/LCD combo
    // http://tronixstuff.com/tutorials > chapter 42
    #include <Wire.h>
    #include <Keypad.h>
    #include<LiquidCrystal.h>
    //Char Kid();   // need string here  
    LiquidCrystal lcd(27, 26, 25, 24, 23, 22);
    // Create the Keypad
    const byte ROWS = 4; // Four rows
    const byte COLS = 3; // Three columns
    // Define the Keymap
    char keys[ROWS][COLS] =
    {
      {'1', '2', '3'},
      {'4', '5', '6'},
      {'7', '8', '9'},
      {'*', '0', '#'}
    };
    //define Arduino pins & rows
    byte rowPins[ROWS] = {2, 3, 4, 5};
    byte colPins[COLS] = {6, 7, 8};
    //KeyMap
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    //////// AUTHORIZATION CODE ///////
    //     Change Here if  new one is desired  //
    char PIN[4] = {'4', '3', '1','6'}; // our secret (!) number
    char attempt[4] = {'0', '0', '0','0'}; // used for comparison
    int z = 0;
    //*************  SETUP  *******************************
    void setup()
    {
       Serial.begin(9600);
      lcd.begin(16, 2);
      delay(100);
      lcd.clear();
      lcd.print("  Enter PIN...");
      lcd.setCursor(6, 1);
      lcd.cursor();
      lcd.blink();
    }
    //***********  PIN OK  *********************
    void correctPIN() // do this if correct PIN entered
    {
      int(j);
      for ( j = 0;   j < 4 ;  j++ )
      lcd.clear();
      lcd.print(" Enter Kid #");
      Serial.print("I got here");  /////////test///////
      /*
      char key = keypad.getKey();
      //delay(100);
      if (key != NO_KEY)
      {
        lcd.print(key);
        attempt[j] = key;
        j++;
        
        Serial.print("I got here");  /////////test///////
        char(Kid) = key; 
        lcd.print(Kid);
      }
        switch (key)
      {
          case '*':
            z = 0;
            break;
          case '#':
            z = 0;
            
      //lcd.clear();
      //lcd.print("  Enter PIN...");
      lcd.setCursor(6, 1);
       }
      */ 
    }
    //************ incorrect pin entered *******************
    void incorrectPIN() // do this if incorrect PIN entered
    {
      lcd.clear();
      delay(100);
      lcd.print(" * Try Again *");
      delay(2000);
      lcd.clear();
      lcd.print("  Enter PIN...");
      lcd.setCursor(6, 1);
    }
    //************** CHECK PIN ********************************
    void checkPIN()
    {
      int correct = 0;
      int i;
      for ( i = 0;   i < 4 ;  i++ )
      {
        Serial.print(correct);
        
        if (attempt[i] == PIN[i])
        {
        
          correct++;
       
       // Serial.print(PIN);
       //Serial.print(i);
       // Serial.print(i);
        if (correct == 3);
        
         correctPIN();
        }
        else
         incorrectPIN();
      }
     for (int zz = 0; zz < 3; zz++)
      {
        attempt[zz] = '0';
      }
    }
    
    //************** READ KEPAD ********************************
    void readpad()
    {
      char key = keypad.getKey();
      delay(100);
      if (key != NO_KEY)
      {
        lcd.print(key);
        attempt[z] = key;
        z++;
      }
        switch (key)
        {
          case '*':
            z = 0;
            break;
          case '#':
            z = 0;
    
     //  delay(100); // for extra debounce
     //  lcd.clear();
    
       checkPIN();
        break;
       }
     }
    //*************** LOOP **********
    void loop()
    {
      readpad();

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube