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 8424981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:09:07+00:00 2026-06-10T04:09:07+00:00

I’m having this weird output when I read hex characters in PHP , wherein

  • 0

I’m having this weird output when I read hex characters in PHP, wherein PHP fetches its data from Arduino serial..

Here’s the output..

ÿ ÿ^A ÿ^A

I wrote a user space application which I use to send data to the Arduino.

Here’s the sample code of my userspace application:

unsigned char data[2][7] = {{0x01,0x01,0xFF,0x3F,0x00,0x3F,0x08},
                            {0xFF,0x01,0x02,0xFF,0x00,0x2F,0x10}};

fd=open("/dev/ttyS0",O_RDWR | O_NOCTTY);
if(fd<0)
    exit(1);

if (strcmp(argv[1], "go up")==0) {
    write(fd,data[0],8); // What I used to send data to my Arduino..
}

Here’s the sample PHP code of what I’m using to fetch the data from the Arduino:

$sCon = $sConnect->SerialConnect("/dev/ttyS0", 9600);
shell_execute("test 'go up'"); //Test is the name of my user space application
usleep(100000)
$data .= fread($sCon, 25);     // Get the data from the Arduino..
$sConnect->SerialClose($sCon);

Now when I run it, the data displayed on the page is messed up: ÿ ÿ^A ÿ^A. I need to retrieve this data: 0x01,0x01,0xFF,0x3F,0x00,0x3F,0x08, which will be displayed on my website..

When I change this

write(fd,data[0],8);  // Prints `ÿ ÿ^A ÿ^A`

to this

write(fd,"010101FF3F003F08",15);  // Prints 010101FF3F003F08 in PHP

then I can retrieve the data without any problem…

Why is it displaying like ÿ ÿ^A ÿ^A?

  • 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-06-10T04:09:08+00:00Added an answer on June 10, 2026 at 4:09 am

    When you do write(fd, data[0], 8), your are sending a stream of binary data, that is characters which are coded 0x01, 0x01, etc., not an ASCII representation of your data.

    Depending on what is your goals, you should send them as an ASCII string. To process them in PHP, this is the easiest way (but it will lose half of your bandwidth with 4 useful bits per 8 bits transmitted).

    for(int p=0; p<8; p++) { 
        fprintf(fd, "%02x", data[0][p]); 
    }
    

    instead

    write(fd, data[0], 8);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I would like to count the length of a string with PHP. The string
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.