I searched all over the web couldn't find solution what I am trying to solve
I am receiving HEX data from elm327 to arduino
the hex data coming in from elm327 to arduino 34 38 36 42 31 30 in ASCII would be 48 6B 10
and this what I see on in any Serial monitor from pc ....
but when elm send to arduino
I store it as
data[0] = Serial.read();
data[1] = Serial.read();
data[3] = Serial.read();
data[4] = Serial.read();
on and on
I tried write and add in the ,HEX or BYTE no different , I tried bit shifting it did work on digit less then 9
data[11] =Serial.read();
data[12] =Serial.read();
data[41] = (unsigned int )data[11]<<4;
data[42] = (unsigned int )data[12]<<4;
data[42] = (unsigned int )data[12]>>4;
data[43]=(data[41])+(data[42];
Serial.print(data[43],BYTE);
so far in here print out to another IC or arduino correct and match what
I receive..... the result 07 instead if I didn't do above would be 30 37
but now below any over 9 wouldn't work for ASCII A is HEX 46 and arduino store it as 34 36 and it print correct to
arduino monitor F if as a BYTE ,below a sample
Serial.print (data[0]); value holding 33 instead of 34 ! its adding 30 before the digit
Serial.print (data[1]); 34
Serial.print (data[2]); 33
Serial.print (data[3]); 38
on and on
printed result to another IC or arduino 33 34 33 38 33 36 34 32
the real receiving value what i need to reprint are 34 38 36 42 and no problem to the serial monitor print correctly
please help me in here ive been struggling 19 days with this and as you see Im new to this ,I don't know if I am posting this correctly under the proper subject,or if i did explain it correctly , sorry I couldn't copy and paste since I am using separate pC
but you get the idea on this , and I am sure some one already explain this or came up with it .thank you
Yes I'm using Val = Serial.read();
If (Val = the charecter I want witch is 4 hex
Would be 0x34 ){
Data[0] = Serial.read();
And on ...
I'm not having issues getting the wrong data
But the issue is arduino some how putting and storing
30 before the digit how do I take this off ?
If you had posted your whole program instead of just bits and pieces I would not need to ask, but what data type is your data array and how is it declared ?
husu:
Yes I'm using Val = Serial.read();
If (Val = the charecter I want witch is 4 hex
Would be 0x34 ){
Data[0] = Serial.read();
And on ...
I'm not having issues getting the wrong data
But the issue is arduino some how putting and storing
30 before the digit how do I take this off ?
maybe you should post your code ( there are several ways to send files from 1 PC to another one )
, because, as you describe it, I understand that you do :
Val = Serial.read(); // 1rst call
if(Val=='4')
{
data[0] = Serial.read(); //2nd call
....
}
so, data[0] is not '4'
BTW, I don't quite understand what you mean by "But the issue is arduino some how putting and storing
30 before the digit how do I take this off ?"
I did it this way
To get it to send 10 and 07 correctly without the 3 before it
With out it the result would be
31 30 for 10
30 37 for 07
I can't believe why arduino like this !
Got to be a solution got this
If you want to try it from your end
With two arduino
Send from one
Serial.read (0x46 ,Hex) ;
You will see from the other arduino
When data[0] = serial.read();
And print it back to the first arduino
It will come back as 34 and carry on to
the other data[1] =serial.read () 36
I'm not sure if explanation is clear but if you try it
You would know exactly what I'm talking about.
here is the code and I tried to clean it up as much as I can but still a little messy , but please ignore the unrelated code to the subject unless interfering with it ,
here is a brief explanation again 01 01 \r
I send Serial1.print("0101\r"); in HEX would be 3031 3031 0D
receiving in ASCII
486B1041018307FF00
PRINTING TO THE MONITOR THE SAME IN ASCII
UNLESS if I send it to the monitor in HEX would be
48 6B 10 41 01 07 FF 00
3438 3642 3130 3431 3031 3037 4646 3030 data[0]; to data[20]; lets focus on this one only
not to worry about the other
not problem what so ever to read it to the serial monitor from arduino
but when send to another IC not arduino
it sees it like 3130 I want to send to my IC 10 not 3130 !
what I did I use
data[38]= (unsigned int)data[3]<< 4;
data[39]= (unsigned int)data[4]<< 4;
data[39]= (unsigned int)data[39]>> 4;
data[40]= (data[39])+ (data[38]);
Serial.print (data[40],BYTE);// resulty 10 to my IC other wise will be the print from my IC 31 and it goes to the other byte 30 and its invalid byte
////////////######################################
data[41]= (unsigned int)data[11]<< 4;
data[42]= (unsigned int)data[12]<< 4;
data[42]= (unsigned int)data[42]>> 4;
data[43]=(data[41]) + (data[42]);
Serial.print (data[43],BYTE); // resulty 07 to my IC other wise will be the print from my IC 30 and it goes to the other byte 37 and its invalid byte
but the formula will not work on number over 9HEX
for the letter A ASCII will be 42 for F will be 46hex
another word I change the serial.print to write and I tried Serial.print (data[!!],BYTE);and intead of byte to hex and no different , but yes makes different on serial monitor ! some how the serial monitor has some what background convertor ,
if i send Serial.print(0x47, HEX);//my IC will get it a as an F ,SO HOW DO I pick it up and print like this F
to my IC
my other IC print as follow
buffer(8)= read2; this language its old PLM51
read1 is the byte I am storing from arduino Serial send data[11]; and data [12];( its getting [11] not [12],[12] is caring on to read
here you can see the problem 'read2 is a byte 8bits' 'data[11]and [12] two bytes total 16bites '
read2 suppose to be FFh; but reading 34h; ,above I combined them and I came up with the correct way
witch is 10h; instead of 31h; by doing the above but again not working ,can't figuer this thing out!
NOTE Serial.print(0x57, BYTE);//W letter to put my IC in boot load mode thats all then
will start reading and storing the incoming byte....
Finally I got it
thanks to Rick @ adafruit_support_rick
he answer it with a simple answer
adafruit_support_rick wrote:To convert ascii hex digits to binary:
If the hex is less than 0x41 ('A'), subtract 0x30 ('0'). Otherwise, subtract 0x37
more then 20 days on this thing and finally im done with this and ready for another problem :0
who ever need this will really know how impotent is this ....
i had to tweek it a little to combine two byte together
data[44]=(unsigned int)data[1]-0x30,HEX;// this one is 36 for 6
data[46]=(unsigned int)data[1]-0x37,HEX; // this one 42 for B
data[47]=(data[44]<<4)|(data[46]);// here putting 6B together
finally Serial.print(data[47],BYTE); //here my other IC will receive the correct value 6B instead 36 only
thank you again Rick....
data[44]=(unsigned int)data[1]-0x30,HEX;// this one is 36 for 6
data[46]=(unsigned int)data[1]-0x37,HEX; // this one 42 for B
data[47]=(data[44]<<4)|(data[46]);// here putting 6B together
finally Serial.print(data[47],BYTE);
no now it byte data[80];
after I got the formula I have change few things , if there is another way to combine two byte in in onwhat would be an easy way to e beside what I am using please let me know , I am talking about since we I know -0x30 to make it one digit, if under 0x39 then -0x37 if over 0x39
the result would be lets assume the receiving byte is 37 hex -0x30= 07 and if 31 -0x30= 01
if above 39 would be if 41 as {A} ascii -0x37 = 0A then by doing to the first dat bit shifting and combine the second byte with is
would be 10 if it was 3110 hex 31-0x30= 01 30-0x30 since both under 39 = 00 now data[ blaa] ( 01<<4) | (00)
Serial.print (data [blaa ] ,BYTE; the result print 10 and keep on mind on monitor would be unreadable characters , but I am not doing it to the monitors ,I am sending it to another IC receive byte in a diiferent format then arduino if i guess it right
now in order to filter the incoming byte either > >39 or lower the 39 what would to send the proper deduction ???
I am trying a short cut how this would be ? in plm51 you can set the procedure and call it later to execute without righting bunch of codes ,
here how how its done the long way in arduino
if (data[1]) <= 0x39){// then do -0x30
else (- 0x37);}
I dont if this will work but if does work its much for 80 data or more !!?
so is there a way to pick the byte data[80] and if any of the each byte if <= 39 do -0x30 else -0x37 ?
please let me know if any other way .
thank you