Hi All,
I have written code, and it works. The Problem is that the data Received is in Hex, and I require it in ASCII.
My Code:
#define RXD2 16
#define TXD2 17
float cell_2;
byte ByteArray[250];
int ByteData[20];
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
//byte msg[] = {0x7E, 0x01, 0x01, 0x00, 0x03, 0x0D};
byte msg[] = {0x7E, 0x35, 0x32, 0x30, 0x31, 0x34, 0x36, 0x34, 0x32, 0x45, 0x30, 0x30, 0x32, 0x30, 0x31, 0x46, 0x44, 0x33, 0x30, 0x0D};
int i;
int len = 20;
Serial.println("SEND DATA ONE");
for (i = 0 ; i < len ; i++) {
Serial2.write(msg[i]);
Serial.print("[");
Serial.print(i);
Serial.print("]");
Serial.print("=");
Serial.print(String(msg[i]));
}
len = 0;
Serial.println();
int a = 0;
while (Serial2.available())
{
ByteArray[a] = Serial2.read();
a++;
}
int b = 0;
String registerHex;
Serial.println("DATA RECEPTION");
for (b = 0 ; b < a ; b++) {
Serial.print(" ");
Serial.print(b);
Serial.print(" ");
registerHex = String(ByteArray[b], HEX);
Serial.print("Data: ");
Serial.print(registerHex);
Serial.print("");
Serial.println();
}
Serial.println();
Serial.println("REGISTERS HEX");
ByteData[7] = (ByteArray[17]) ;
Serial.println(ByteData[7]);
cell_2 = ByteData[7];
Serial.print("Cell 2: ");
Serial.print((cell_2 / 1000), 3);
Serial.println(" V");
delay(5000);
}
What I receive is the following:
12:56:50.564 -> REGISTERS HEX
12:56:50.564 -> 48
12:56:50.564 -> Cell 2: 0.048 V
12:56:55.587 -> SEND DATA ONE
12:56:55.587 -> [0]=126[1]=53[2]=50[3]=48[4]=49[5]=52[6]=54[7]=52[8]=50[9]=69[10]=48[11]=48[12]=50[13]=48[14]=49[15]=70[16]=68[17]=51[18]=48[19]=13
12:56:55.587 -> DATA RECEPTION
12:56:55.587 -> 0 Data: 7e
12:56:55.587 -> 1 Data: 35
12:56:55.587 -> 2 Data: 32
12:56:55.587 -> 3 Data: 30
12:56:55.587 -> 4 Data: 31
12:56:55.587 -> 5 Data: 34
12:56:55.587 -> 6 Data: 36
12:56:55.587 -> 7 Data: 30
12:56:55.587 -> 8 Data: 30
12:56:55.587 -> 9 Data: 34
12:56:55.587 -> 10 Data: 30
12:56:55.587 -> 11 Data: 38
12:56:55.587 -> 12 Data: 34
12:56:55.587 -> 13 Data: 30
12:56:55.587 -> 14 Data: 31
12:56:55.587 -> 15 Data: 31
12:56:55.587 -> 16 Data: 30
12:56:55.587 -> 17 Data: 30
12:56:55.587 -> 18 Data: 44
12:56:55.587 -> 19 Data: 37
12:56:55.587 -> 20 Data: 36
12:56:55.634 -> 21 Data: 30
12:56:55.634 -> 22 Data: 44
12:56:55.634 -> 23 Data: 31
12:56:55.634 -> 24 Data: 34
12:56:55.634 -> 25 Data: 30
12:56:55.634 -> 26 Data: 44
12:56:55.634 -> 27 Data: 35
12:56:55.634 -> 28 Data: 37
12:56:55.634 -> 29 Data: 30
12:56:55.634 -> 30 Data: 44
12:56:55.634 -> 31 Data: 35
12:56:55.634 -> 32 Data: 32
12:56:55.634 -> 33 Data: 30
12:56:55.634 -> 34 Data: 44
12:56:55.634 -> 35 Data: 36
12:56:55.634 -> 36 Data: 38
12:56:55.634 -> 37 Data: 30
12:56:55.634 -> 38 Data: 44
12:56:55.634 -> 39 Data: 35
12:56:55.634 -> 40 Data: 37
12:56:55.634 -> 41 Data: 30
12:56:55.634 -> 42 Data: 44
12:56:55.634 -> 43 Data: 35
12:56:55.634 -> 44 Data: 38
12:56:55.634 -> 45 Data: 30
12:56:55.634 -> 46 Data: 44
12:56:55.634 -> 47 Data: 35
12:56:55.634 -> 48 Data: 35
12:56:55.634 -> 49 Data: 30
12:56:55.634 -> 50 Data: 44
12:56:55.634 -> 51 Data: 35
12:56:55.634 -> 52 Data: 30
12:56:55.634 -> 53 Data: 30
12:56:55.634 -> 54 Data: 44
12:56:55.634 -> 55 Data: 35
12:56:55.634 -> 56 Data: 34
12:56:55.634 -> 57 Data: 30
12:56:55.634 -> 58 Data: 44
12:56:55.634 -> 59 Data: 36
12:56:55.669 -> 60 Data: 31
12:56:55.669 -> 61 Data: 30
12:56:55.669 -> 62 Data: 44
12:56:55.669 -> 63 Data: 35
12:56:55.669 -> 64 Data: 41
12:56:55.669 -> 65 Data: 30
12:56:55.669 -> 66 Data: 44
12:56:55.669 -> 67 Data: 34
12:56:55.669 -> 68 Data: 43
12:56:55.669 -> 69 Data: 30
12:56:55.669 -> 70 Data: 44
12:56:55.669 -> 71 Data: 35
12:56:55.669 -> 72 Data: 34
12:56:55.669 -> 73 Data: 30
12:56:55.669 -> 74 Data: 44
12:56:55.669 -> 75 Data: 36
12:56:55.669 -> 76 Data: 32
12:56:55.669 -> 77 Data: 30
12:56:55.669 -> 78 Data: 44
12:56:55.669 -> 79 Data: 35
12:56:55.669 -> 80 Data: 37
12:56:55.669 -> 81 Data: 30
12:56:55.669 -> 82 Data: 36
12:56:55.669 -> 83 Data: 30
12:56:55.669 -> 84 Data: 30
12:56:55.669 -> 85 Data: 34
12:56:55.669 -> 86 Data: 33
12:56:55.669 -> 87 Data: 30
12:56:55.669 -> 88 Data: 30
12:56:55.716 -> 89 Data: 34
12:56:55.716 -> 90 Data: 34
12:56:55.716 -> 91 Data: 30
12:56:55.716 -> 92 Data: 30
12:56:55.716 -> 93 Data: 34
12:56:55.716 -> 94 Data: 34
12:56:55.716 -> 95 Data: 30
12:56:55.716 -> 96 Data: 30
12:56:55.716 -> 97 Data: 34
12:56:55.716 -> 98 Data: 34
12:56:55.716 -> 99 Data: 30
12:56:55.716 -> 100 Data: 30
12:56:55.716 -> 101 Data: 34
12:56:55.716 -> 102 Data: 37
12:56:55.716 -> 103 Data: 30
12:56:55.716 -> 104 Data: 30
12:56:55.716 -> 105 Data: 34
12:56:55.716 -> 106 Data: 32
12:56:55.716 -> 107 Data: 30
12:56:55.716 -> 108 Data: 30
12:56:55.716 -> 109 Data: 30
12:56:55.716 -> 110 Data: 30
12:56:55.716 -> 111 Data: 31
12:56:55.716 -> 112 Data: 35
12:56:55.716 -> 113 Data: 35
12:56:55.716 -> 114 Data: 35
12:56:55.716 -> 115 Data: 32
12:56:55.716 -> 116 Data: 37
12:56:55.716 -> 117 Data: 42
12:56:55.716 -> 118 Data: 43
12:56:55.716 -> 119 Data: 30
12:56:55.716 -> 120 Data: 36
12:56:55.716 -> 121 Data: 32
12:56:55.716 -> 122 Data: 37
12:56:55.716 -> 123 Data: 42
12:56:55.716 -> 124 Data: 44
12:56:55.716 -> 125 Data: 30
12:56:55.762 -> 126 Data: 30
12:56:55.762 -> 127 Data: 31
12:56:55.762 -> 128 Data: 46
12:56:55.762 -> 129 Data: 36
12:56:55.762 -> 130 Data: 33
12:56:55.762 -> 131 Data: 36
12:56:55.762 -> 132 Data: 34
12:56:55.762 -> 133 Data: 46
12:56:55.762 -> 134 Data: 46
12:56:55.762 -> 135 Data: 46
12:56:55.762 -> 136 Data: 44
12:56:55.762 -> 137 Data: 30
12:56:55.762 -> 138 Data: 30
12:56:55.762 -> 139 Data: 30
12:56:55.762 -> 140 Data: 30
12:56:55.762 -> 141 Data: 46
12:56:55.762 -> 142 Data: 46
12:56:55.762 -> 143 Data: 46
12:56:55.762 -> 144 Data: 44
12:56:55.762 -> 145 Data: 45
12:56:55.762 -> 146 Data: 31
12:56:55.762 -> 147 Data: 36
12:56:55.762 -> 148 Data: 38
12:56:55.762 -> 149 Data: d
12:56:55.762 ->
I need to combine Line 17, 18, 19, 20 and get the ASCII Value