help please on HEX...

Hello ! , i have a HEX data like this :

F0440000702060030000000000000008000000000000000203000E090000000100000C000900000000000000000000070007070F0F0C0B00000C0300000C0300000C0300000C0300000C0300000C03000007000F070F0F040C0000040400000404000004040000040400000404000004040000070000040008000400000004000000040000000400000004000000040000000400050B080C0A06030B08050304000E01040B090D03040A05090D0C0A0702090200010A0D0A0E080A00000E070B090C090A080B0C0001080E07030705050206030701000A0805060C040406060107050E04050907000D0E050A000603070B0D0906090803020609030B06040E0A0E00040D040A00F7

then i want to make a file with that information were :

at adress 0x0 is writen F0
at adress 0x1 is writen 44
at adress 0x2 is withen 00
at adress 0x3 is withen 00
at adress 0x4 is wrinten 70
.
.
.
.
at adress 0x106 is writen 00
at adress 0x107 is writen F7

This site does what i want :

just paste the hex data there and outputs the file i want..

http://support.codeandcopper.com/txt-to-syx/

how can i do this with arduino?

Thanks

What do you mean with "Arduino" in the sentence "how can i do this with arduino"? The fash memory of the Arduino maybe?

Where do you get the hex from?

ptmir:
This site does what i want :

just paste the hex data there and outputs the file i want..

http://support.codeandcopper.com/txt-to-syx/

how can i do this with arduino?

Put an "Ethernet shield" on your Arduino, load the Ethernet library example sketch "WebServer", and then you program a modified Arduino Webserver sketch that does the same job as the PHP script on the linked page.

What are you really trying to do? IE where does the hex data come from? Perhaps
it can be captured as binary in the first place?

the HEX data is made inside the arduino , then is writen to a file in SD card called data.txt

but what i want is not that data in the data.txt but rtather the output that the site a mention does .

also i can not use internet its a stand alone box . i must code what that site does...

any help ?

i think is something like a HEXtoASCII ? may be not.. sorry

on a computer i could for example make a 264 bytes file then open in HEX editor and write the
HEX values in that list on addresses , how can a program on the IDE that ....

this image shows what i mean ( the hex is not the same as i posted ...)

so how can i program that in the arduino IDE ?

for (int n=0; n< strlen(stuff); n+=2)
  {
  byte thisbit= (stuff [n] <= '9' )? stuff[n] - '0':stuff[n] -'A' + 10;
       thisbit *=16;
  thisbit += (stuff[n+1] <= '9' )? stuff[n+1] - '0':stuff[n+1] -'A' + 10;

  file.write(thisbit);    
  }

Thanks Kent ! , but please can you comment the code so i can understand it ?
i will try it write now if i can.... get inside the logic :slight_smile:

ptmir:
Thanks Kent ! , but please can you comment the code so i can understand it ?
i will try it write now if i can.... get inside the logic :slight_smile:

//USED TO send a char array (in stuff) as bytes
 n is used to index through the array, 2 characters at a time until it gets to the end of the string */

for (int n=0; n< strlen(stuff); n+=2)
  {
  /*Read first character of current byte
  if it's numeric we get it's actual value by deducting '0' from it's character code
  if it's alpha we get it's actual value by deducting 'A' and adding 10 to it's character code  */
  
  byte thisbit= (stuff [n] <= '9' )? stuff[n] - '0':stuff[n] -'A' + 10;
  

  //Multiply by 16 (because this was just the first character of the two
     thisbit *=16;
  

  //Now add on the value of the second character, using the same logic as the first to determine it's value
   thisbit += (stuff[n+1] <= '9' )? stuff[n+1] - '0':stuff[n+1] -'A' + 10;


  //write the byte to the file
  file.write(thisbit);    
  }

btw it's kenF :stuck_out_tongue_winking_eye:

ptmir:
the HEX data is made inside the arduino , then is writen to a file in SD card called data.txt

but what i want is not that data in the data.txt but rtather the output that the site a mention does .

also i can not use internet its a stand alone box . i must code what that site does...

any help ?

Ist this what you want:

You have written the data to a file on SD card, called "data.txt".

And now you want to read the data in from "data.txt" and then write the modiefied data back to SD card with another filename, let's name it "data.dat"?

byte data[264] = {
0xF0, 0x44, 0x00, 0x00, 0x70, 0x20, 0x60, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x00, 0x0E, 0x09, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0x00, 0x07, 0x07, 0x0F, 0x0F, 0x0C, 0x0B, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00,
0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00,
0x00, 0x07, 0x00, 0x0F, 0x07, 0x0F, 0x0F, 0x04, 0x0C, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04,
0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04,
0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x07, 0x0F, 0x0F, 0x0C, 0x0B, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C,
0x03, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x00, 0x0C,
0x03, 0x00, 0x00, 0x07, 0x00, 0x0F, 0x07, 0x0F, 0x0F, 0x04, 0x0C, 0x00, 0x00, 0x04, 0x04, 0x00,
0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x04, 0x04, 0x00,
0x00, 0x04, 0x04, 0x00, 0x00, 0x07, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xF7
} ;

// SAVE RANDOM SOUND TO FILE ???
//==================================
else if (buttonSaveRandS == LOW) { // INPUT_PULLUP ...

buttonSaveRandS=1;

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("data.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {

//===================== testing code hex to ascii

for (int n=0; n< 264; n+=2)
{
byte thisbit= (data [n] <= '9' )? data[n] - '0':data[n] -'A' + 10;
thisbit *=16;
thisbit += (data[n+1] <= '9' )? data[n+1] - '0':data[n+1] -'A' + 10;

dataFile.write(thisbit);
}

//======= final hex to ascii= test

dataFile.close();
delay(1000);
}

}

well , the output is no right but is already doing some thing.. :slight_smile:

So your data is ALREADY in bytes! So we've been wasting our time here.

Replace THIS

for (int n=0; n< 264; n+=2)
  {
  byte thisbit= (data [n] <= '9' )? data[n] - '0':data[n] -'A' + 10;
       thisbit *=16;
  thisbit += (data[n+1] <= '9' )? data[n+1] - '0':data[n+1] -'A' + 10;

  dataFile.write(thisbit);   
  }

With this

int datalen = sizeof(data);
for (int n=0; n< datalen ; n++)
  dataFile.write(data[n]);

ok trying that KentF , thanks for you patience !

If you have your bytes already as formatted text "byte array in C", then you writen the bytes like

for (int n=0; n< 264; n++)
{
  dataFile.write(data [n]);    
}

Great !! Thank You Both KentF and jurs [[ ]]

here the picture result

ptmir:
Great !! Thank You Both KentF and jurs [[ ]]

But I didn't do anything :open_mouth:

KenTF:
But I didn't do anything :open_mouth:

I think he was talking to me :slight_smile:

:grinning: YES YOU [[ ]]

KenF lol , sorry i'm dyslexic