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 Using PORT() for data
  • 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 9 replies
  • Answers 4 answers
  • Subscribers 391 subscribers
  • Views 664 views
  • Users 0 members are here
  • strings
  • 7-segment-display
  • port manuplation
Related

Using PORT() for data

billpenner
billpenner over 9 years ago

This is probably a very easy question for someone out there but It has me stumped. I have a three digit number like 123 or 286 etc. I am sending it from a Mega to NRF24l01+. This is working fine.

I am receiving the number fine with another NRF24l01+ and a Nano. now the problem. I have a 3 digit, 7 segment display. It is also working fine when using this code for a test..

 

[code]

/*Select a seven segment digit () in sequence.

* load a value into display for testing

*/

int i ;

byte j = B0000 ;              //the digit value (0 to 9)

 

void setup()

{

   DDRC = DDRC | B00111111;    // set PORT C (digital 5~0) to outputs

  pinMode(6, OUTPUT);               // digit select pins (Latch signal)

  pinMode(7, OUTPUT);

  pinMode(8, OUTPUT);

Serial.begin(9600);

}

 

void loop() {

for (i = 6; i <9 ; i++)       //digit select latch

  {

  digitalWrite(i, HIGH);      // open latch

    delay(100);

    for (j = 0; j <10 ;  j++) // test values for the display

     {

       PORTC = j;             // write HEX value to digit

      // Serial.print( PORTD ) ;    // just for testing

      // Serial.print( PORTC ) ;     // just for testing

       delay(100); //

     }

     delay(500);  // wait a bit to read digit

     digitalWrite(i, LOW);      // close latch

     delay(1000);

       Serial.println( byte(i)) ; //only for testing

   }

   if(i == 9, i=6);  //reset digit counter and do it again

}

[/code]

when I run the above code each digit counts up the latches then the next digit counts up. At he end.all is reset and repeats.

My problem is I can't isolate each of the received digits to individually load them into the display. Is there a way to separate the received number into digits so I can load the port? I hope this makes sense.

I can supply the schematic, video, etc.  if it would help.

 

Bill

  • Sign in to reply
  • Cancel
Parents
  • clem57
    0 clem57 over 9 years ago

    I think you need this Adafruit customer service forums • View topic - How to convert a string to a number . It can take 1 cgar at a time and convert to a number.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • billpenner
    0 billpenner over 9 years ago in reply to clem57

    Thanks for the quick reply. atoi Hmm I am not sure I understand all that but I will Study it.

    I also tried this. It works but 4k is a lot of code for my little Nano.

     

    [code]

    //converting a number to digits

    //BillP

    byte hundreds ;

    byte tens ;

    byte units ;

    void setup()

    {

      // Open serial communications and wait for port to open:

     

      Serial.begin(9600);

      while (!Serial)

      {

       String recData = "000";

      }

    }

     

    void loop()

    {

     

     

      String recData = "456" ; //Incomming data from NRF24

      Serial.println(recData);   

     

     

    char hundreds = recData.charAt(0);

    char tens = recData.charAt(1);

    char units = recData.charAt(2);

     

     

    Serial.println(int(hundreds)); // this turns out to be ASCII

    Serial.println(int(tens));

    Serial.println(int(units));

     

     

      String message = "Most significant digit of the Data is: ";

      Serial.println(message + hundreds);

      Serial.print("tens digit is  ");

      Serial.println(tens);

      Serial.print("units digit is  ");

      Serial.println(units);

     

    // Pause

      while (true);

     

     

    }

    [/code]

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to billpenner

    4K may because of the many function calls you have. Try to simplify the calls to only one serial.print/println without the strings. atoi is ascii to integer function, It takes one or more character strings null terminated and converts to a working integer to do math with like add etc, Your trick here is to play and determine what the shortest code you can generate, Functions tend to be generic so if you do by hand thibgs get better. But that is more work for youimage

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • clem57
    0 clem57 over 9 years ago in reply to billpenner

    4K may because of the many function calls you have. Try to simplify the calls to only one serial.print/println without the strings. atoi is ascii to integer function, It takes one or more character strings null terminated and converts to a working integer to do math with like add etc, Your trick here is to play and determine what the shortest code you can generate, Functions tend to be generic so if you do by hand thibgs get better. But that is more work for youimage

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • billpenner
    0 billpenner over 9 years ago in reply to clem57

    Yes thanks, The function calls were only for the testing. finally it boils down to around 3K. I think I can live with that.

    Thanks for your help.

    • 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