Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:59:43+00:00 2026-05-30T18:59:43+00:00

I’m successfully sent single int values from Processing to Arduino, but now I need

  • 0

I’m successfully sent single int values from Processing to Arduino, but now I need to sent a pair of ints (both having values between 0 and 90) together and I’m not sure how to do that.

Reading the docs, I see I can send byte/byte[]/int/char/String types.
One idea is to send string containing the two ints concatenated by a comma character,
but am not 100% sure how to convert the data to a String and split it in Arduino.

serial.write(intValue1+","+intValue2);

Another thing I was thinking was packing two ints into a byte[] somehow, but I haven’t worked with bytes much, so any tips on getting started would be helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:59:45+00:00Added an answer on May 30, 2026 at 6:59 pm

    If you’re sending pairs of ints, or any number of bytes, it seems you may want to consider a simple serial protocol. There are a few questions here specifically about serial command protocols for embedded systems, for example:

    1. How do you design a serial command protocol for an embedded system?
    2. Simple serial point-to-point communication protocol

    One suggestion is starting off your message with a header byte, usually something outside of your data range if possible (>90 in your case?). The following code has not been tested; it’s just an idea, but it should run.

    int lookingForHeader = 1;
    int lookingForByteOne = 0;
    int lookingForByteTwo = 0;
    
    while (myPort.available() > 0) {
        while (lookingForHeader == 1) {
            int header = myPort.read();
            if (header == HEADER_BYTE) {
                lookingForHeader = 0;
                lookingForByteOne = 1;
            }
            // Consider incrementing a counter here and timing out if it gets too large.
        }
    
        if (lookingForByteOne == 1) {
            int byteOne = myPort.read();
            // Check if byteOne is between 0 and 90.
            lookingForByteOne = 0;
            lookingForByteTwo = 1;
        }
    
        if (lookingForByteTwo == 1) {
            int byteTwo = myPort.read();
            // Check if byteTwo is between 0 and 90.
            lookingforByteTwo = 0;
            lookingForHeader = 1;
    
            // Perhaps do a serial.write() here to acknowledge that 
            // a header and two bytes have been received.
    
            // Finally, do stuff with byteOne and byteTwo.
        }
    }
    

    Another option would be to acknowledge the receipt of each byte (i.e. receive header, respond with a special “ack header” byte, receive next byte, respond with “ack byte one”, etc.). This is slower but it may fine for you.

    Finally, a couple key points from the questions I linked to above:

    Consider sending a checksum (i.e. sum of bytes) at the end of the message. The Arduino would add up the header, byte 1 and byte 2. If it doesn’t match the check sum, then it could respond with a failure, or send again message.

    Rex’s answer to question [2] sums up what a message protocol might look like:

    // total packet length minus flags len+4
    U8 sflag;         //0x7e start of packet end of packet flag from HDLC
    U8 cmd;           //tells the other side what to do.
    U8 len;           // payload length
    U8 payload[len];  // could be zero len
    U16 crc;
    U8 eflag;         //end of frame flag
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.