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 Parsing integer strings?
  • 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 Suggested Answer
  • Replies 19 replies
  • Answers 2 answers
  • Subscribers 393 subscribers
  • Views 2373 views
  • Users 0 members are here
  • serial_communications
  • potentiometers
  • parsing
  • boolean
  • arduino
Related

Parsing integer strings?

scorpion
scorpion over 9 years ago

I need help with parsing a string of integers sent from another Arduino. The values will be like this 1, 0, 1234, 1234,

1 is a Boolean

0 is a Boolean

1234 are pot values

I would like for it to go to variables

Vpot is first pot value

Hpot is second pot value

C is first Boolean

Z is second Boolean

 

Thanks,

Ben Bonen

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 9 years ago +1
    sscanf is your friend, probably supported by Arduino (I don't use Arduino). Reddit on the topic however is here. https://www.reddit.com/r/arduino/comments/pznnj/using_sscanf_with_arduino/
  • gadget.iom
    gadget.iom over 9 years ago +1
    The Serial.readStringUntil command may help you if you are receiving the data through the serial port. Something like this might work: void loop(){ String C = Serial.readStringUntil(',').toInt(); Serial…
  • clem57
    clem57 over 9 years ago +1
    One way is using indexOf( ) like in http://stackoverflow.com/questions/11068450/arduino-c-language-parsing-string-with-delimiter-input-through-serial-interf… Then easy to convert to known values. Suggest…
  • scorpion
    0 scorpion over 9 years ago in reply to gadget.iom

    @Paul Ellison

    That is true, but that number (1234) was just and example and I am not sure what the actual analog range of a pot is.

    So, what if I mapped the input value to a range of 0 to 999 and used that?

    Would that work?

     

    Ben

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

    This topic is fully covered in a seriese I posted a while back

     

    Fast Track to Arduino Programming

     

    Lesson 2 and 3 are the ones most relevent to your issue

     

    they use a C command strtok that allows parsing of strings using a provided token or tokens and is very powerful and perfect for this kind of scenario

     

    Enjoy

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to scorpion

    See below for my other response using strtok

     

    strtok will not care how big the number is, it looks for the delimeters and effectivly splits up the string based on them

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to scorpion

    The code I've provided below might just work regardless of with the pot value runs into 0, 1, 2, 3 or 4 digits. Would you mind giving it a try.

    Would be interested to know if it works image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 9 years ago in reply to gadget.iom

    Paul, did you forget to include the code? I can't see it.

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to neilk

    Hi neilk

    It was posted earlier. Can be found by scrolling down to here:

    Re: Parsing integer strings?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • neilk
    0 neilk over 9 years ago in reply to gadget.iom

    Hi gadget.iom

     

    Thanks Paul, got it now.

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to neilk

    You're welcome. Glad it helps somebody. image

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

    UPDATE:

    Thank you for all of your help! image

    I forgot to mention that I was using this with a wireless transmitter to control an ESC, so I will just transmit the ESC control code through it.

     

    Ben

    • 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