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
  • BigG
    0 BigG over 9 years ago

    you could avoid string to digit conversion by creating a data structure for each digit for example.

     

    You would declare as follows in Arduino:

    struct SEGDISPL {   byte dgit1 = 0;   byte dgit2 = 0;   byte dgit3 = 0; };

    SEGDISPL mySegDigits;

    // Then assign your 3 digits values of choice

    mySegDigits.dgit1 = 2;

    mySegDigits.dgit2 = 6;

    mySegDigits.dgit3 = 8;

     

    Then use the Serial write function instead of print function to send data via nRF24L01 e.g. Serial.write(&mySegDigits, sizeof(mySegDigits));

    This prevents the data from being seen as characters. See: https://www.arduino.cc/en/Serial/Write

     

    Use same data structure on receiver side when reading data from nRF24L01 etc.

    You now have your separate digits to display on segment display.

     

    SIMPLER OPTION:

    Now as your 3 digits are of the same type (my example is really suited for cases when data is of different type), a simpler method is to just create a byte array rather than use data structure.

    E.g. You declare in Arduino

    byte mySegDigits[] = {0,0,0};

    Then to assign mySegDigits[0] = 2; etc.

    Serial.write(&mySegDigits, sizeof(mySegDigits));

    etc.

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

    Good info but I think the separation will be done better at the receiving end. It will be better for me to just send a single number then decode it intp digits at the receiver. Thanks for the information.

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

    Good info but I think the separation will be done better at the receiving end. It will be better for me to just send a single number then decode it intp digits at the receiver. Thanks for the information.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
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