Hyperterminal-Arduino

Hi, I am using Hyperterminal to send a .txt file saved from Matlab containing a matrix: here is the full .txt file

0 0 0 0 0 0;0 0 0 0 0 0;0 0 0 0 0 0;1 0 0 1 0 -1;1 -1 1 1 0 -1;2 -1 1 2 0 -2;2 -1 1 2 0 -2;3 -2 2 3 0 -3;4 -2 2 4 0 -3;4 -3 3 4 -1 -4;5 -3 3 5 -1 -5;6 -4 4 6 -1 -6;7 -5 5 7 -1 -7;9 -5 5 8 -1 -8;10 -6 6 9 -1 -9;11 -7 7 11 -1 -10;13 -8 8 12 -2 -12;14 -9 9 13 -2 -13;16 -10 10 15 -2 -14;17 -11 11 16 -2 -16;19 -12 12 18 -2 -17;21 -13 13 20 -3 -19;23 -14 14 21 -3 -21;25 -15 15 23 -3 -22;27 -17 17 25 -3 -24;30 -18 18 27 -4 -26;32 -19 19 29 -4 -28;35 -21 21 31 -4 -30;37 -22 22 33 -5 -32;40 -24 24 35 -5 -34;43 -25 25 37 -5 -36;46 -27 27 39 -6 -38;49 -28 28 42 -6 -40;52 -30 30 44 -6 -43;55 -32 32 46 -7 -45;58 -34 34 49 -7 -47;62 -35 35 51 -8 -50;66 -37 37 54 -8 -52;69 -39 39 56 -9 -55;73 -41 41 59 -9 -57;77 -43 43 61 -10 -60;81 -45 45 64 -10 -62;86 -47 47 67 -11 -65;90 -49 49 69 -11 -67;95 -52 52 72 -12 -70;99 -54 54 75 -12 -73;104 -56 56 78 -13 -76;109 -59 59 80 -13 -78;115 -61 61 83 -14 -81;120 -63 63 86 -15 -84;125 -66 66 89 -15 -86;131 -69 69 92 -16 -89;137 -71 71 95 -17 -92;143 -74 74 98 -18 -95;149 -77 77 101 -18 -97;155 -80 80 104 -19 -100;162 -83 83 106 -20 -103;168 -86 86 109 -21 -105;175 -89 89 112 -21 -108;182 -92 92 115 -22 -111;189 -95 95 118 -23 -113;197 -99 99 121 -24 -116;204 -102 102 124 -25 -118;212 -106 106 127 -26 -121;220 -109 109 130 -27 -123;229 -113 113 133 -28 -125;237 -117 117 135 -29 -127;246 -121 121 138 -30 -129;254 -125 125 141 -31 -131;263 -129 129 143 -32 -133;272 -133 133 146 -34 -135;281 -137 137 148 -35 -136;290 -141 141 150 -36 -138;299 -146 146 153 -37 -139;308 -150 150 155 -38 -140;317 -154 154 157 -39 -142;326 -159 159 159 -41 -143;336 -163 163 160 -42 -143;345 -168 168 162 -43 -144;355 -173 173 163 -44 -145;364 -177 177 165 -45 -146;374 -182 182 166 -47 -146;383 -187 187 167 -48 -147;393 -191 191 168 -49 -148;402 -196 196 169 -50 -148;412 -201 201 170 -51 -149;421 -206 206 170 -53 -149;431 -210 210 171 -54 -150;440 -215 215 171 -55 -150;449 -220 220 171 -56 -151;458 -225 225 171 -57 -152;467 -229 229 171 -58 -153;476 -234 234 171 -59 -153;484 -239 239 171 -60 -154;493 -243 243 170 -60 -155;501 -248 248 169 -61 -156;510 -252 252 168 -62 -157;518 -257 257 167 -63 -158;526 -261 261 166 -63 -160;534 -265 265 165 -64 -161;541 -270 270 164 -65 -162;549 -274 274 162 -65 -163;557 -278 278 160 -66 -164;564 -282 282 159 -66 -166;572 -286 286 157 -67 -167;579 -290 290 155 -67 -168;586 -293 293 152 -68 -169;593 -297 297 150 -68 -170;601 -301 301 147 -69 -172;608 -304 304 145 -69 -173;614 -307 307 142 -69 -174;621 -311 311 139 -70 -175;628 -314 314 136 -70 -176;635 -317 317 133 -70 -177;642 -320 320 130 -71 -178;648 -323 323 126 -71 -178;655 -326 326 123 -71 -179;662 -328 328 119 -72 -180;668 -331 331 116 -72 -180;675 -333 333 112 -72 -181;681 -336 336 108 -73 -181;688 -338 338 104 -73 -181;694 -340 340 100 -73 -181;701 -342 342 95 -74 -181;707 -344 344 91 -74 -181;714 -345 345 87 -74 -181;720 -347 347 82 -74 -181;726 -348 348 77 -75 -181;733 -350 350 73 -75 -180;739 -351 351 68 -75 -180;745 -352 352 63 -76 -179;751 -353 353 58 -76 -178;758 -354 354 53 -76 -177;764 -355 355 48 -77 -175;770 -356 356 43 -77 -174;776 -357 357 38 -78 -172;782 -358 358 33 -78 -171;788 -358 358 29 -78 -169;794 -359 359 24 -79 -166;799 -360 360 19 -79 -164;805 -360 360 15 -79 -161;810 -361 361 11 -80 -159;816 -362 362 6 -80 -156;821 -362 362 2 -80 -152;827 -363 363 -1 -81 -149;832 -364 364 -5 -81 -145;837 -365 365 -8 -81 -141;843 -366 366 -11 -81 -136;848 -367 367 -14 -82 -131;853 -368 368 -16 -82 -126;858 -370 370 -18 -82 -120;863 -372 372 -19 -81 -114;868 -374 374 -19 -81 -107;872 -377 377 -17 -80 -99;875 -380 380 -15 -78 -90;878 -384 384 -11 -75 -82;879 -387 387 -5 -71 -74;877 -389 389 1 -66 -67;872 -390 390 6 -60 -63;865 -390 390 11 -54 -62;858 -389 389 14 -48 -61;850 -388 388 16 -42 -62;842 -387 387 16 -37 -62;836 -385 385 15 -32 -63;830 -384 384 14 -29 -63;825 -383 383 13 -25 -63;821 -381 381 11 -23 -63;817 -380 380 9 -20 -63;815 -379 379 7 -18 -62;812 -378 378 4 -16 -62;811 -377 377 2 -15 -62;809 -376 376 0 -13 -61;808 -375 375 -3 -12 -61;807 -374 374 -5 -11 -60;806 -373 373 -7 -10 -60;805 -372 372 -9 -9 -59;804 -371 371 -11 -8 -59;804 -370 370 -13 -7 -58;803 -369 369 -15 -6 -58;803 -369 369 -17 -6 -57;802 -368 368 -19 -5 -57;802 -367 367 -21 -4 -57;802 -366 366 -22 -4 -56;801 -366 366 -24 -3 -56;801 -365 365 -26 -3 -56;800 -364 364 -27 -2 -56;800 -364 364 -28 -2 -55;800 -363 363 -29 -1 -55;800 -363 363 -31 -1 -55;799 -362 362 -32 0 -55;799 -362 362 -32 0 -55;799 -361 361 -33 0 -55;798 -361 361 -34 1 -55;798 -361 361 -35 1 -55;798 -360 360 -35 1 -55;797 -360 360 -35 1 -55;797 -360 360 -36 2 -55;797 -360 360 -36 2 -55;796 -360 360 -36 2 -55;835 -361 361 -34 2 -56;872 -361 361 -34 2 -56;908 -361 361 -34 2 -56;944 -361 361 -34 2 -56;979 -361 361 -35 2 -56;1013 -360 360 -35 2 -56;1047 -360 360 -36 3 -56;1080 -359 359 -36 3 -56;1113 -359 359 -37 3 -55;1146 -358 358 -37 3 -55;1179 -358 358 -38 3 -55;1211 -358 358 -38 3 -55;1244 -357 357 -38 3 -55;1276 -357 357 -39 3 -55;1308 -357 357 -39 3 -55;1340 -357 357 -39 4 -55;1373 -356 356 -39 4 -55;1405 -356 356 -40 4 -55;1437 -356 356 -40 4 -55;1469 -356 356 -40 4 -56;1501 -356 356 -40 4 -56;1533 -356 356 -40 4 -56;1565 -356 356 -40 4 -56;1597 -356 356 -41 4 -56;1629 -355 355 -41 5 -56;1661 -355 355 -41 5 -56;1693 -355 355 -41 5 -56;1725 -355 355 -41 5 -56;1757 -355 355 -41 5 -57;1790 -355 355 -41 5 -57;1822 -355 355 -41 5 -57;1854 -355 355 -42 5 -57;1886 -355 355 -42 6 -57;1918 -355 355 -42 6 -57;1950 -355 355 -42 6 -57;1982 -354 354 -42 6 -58;2014 -354 354 -42 6 -58;2046 -354 354 -42 6 -58;2078 -354 354 -43 6 -58;2110 -354 354 -43 7 -58;2142 -354 354 -43 7 -59;2174 -354 354 -43 7 -59;2206 -354 354 -43 7 -59;2238 -353 353 -43 7 -59;2270 -353 353 -44 7 -60;2302 -353 353 -44 7 -60;2334 -353 353 -44 8 -60;2366 -353 353 -44 8 -60;2398 -353 353 -44 8 -61;2435 -354 354 -42 6 -58;2471 -355 355 -41 4 -57;2506 -356 356 -40 3 -56;2541 -356 356 -40 2 -55;2574 -356 356 -40 1 -55;2608 -356 356 -39 0 -55;2641 -356 356 -39 0 -54;2674 -356 356 -39 -1 -54;2707 -356 356 -39 -1 -54;2740 -356 356 -40 -1 -55;2772 -356 356 -40 -1 -55;2805 -356 356 -40 -1 -55;2837 -356 356 -40 -1 -55;2870 -356 356 -40 -1 -55;2902 -356 356 -40 -1 -55;2934 -356 356 -40 -1 -55;2967 -356 356 -40 -1 -55;2999 -356 356 -40 -1 -55;3031 -356 356 -40 -1 -55;3063 -356 356 -40 -1 -55;3095 -356 356 -40 -1 -55;3128 -356 356 -40 -1 -55;3160 -356 356 -40 -1 -55;3192 -356 356 -40 -1 -55;3224 -356 356 -40 -1 -55;3256 -356 356 -40 0 -55;3288 -356 356 -40 0 -55;3320 -356 356 -40 0 -55;3352 -356 356 -40 0 -55;3384 -356 356 -40 0 -54;3417 -356 356 -40 0 -54;3449 -356 356 -39 0 -54;3481 -356 356 -39 0 -54;3513 -356 356 -39 0 -54;3545 -356 356 -39 0 -54;3577 -356 356 -39 1 -54;3609 -356 356 -39 1 -54;3641 -356 356 -39 1 -54;3673 -356 356 -39 1 -54;3706 -356 356 -39 1 -54;3738 -356 356 -39 1 -54;3770 -356 356 -39 1 -54;3802 -356 356 -39 1 -54;3834 -356 356 -39 1 -54;3866 -356 356 -39 1 -54;3898 -356 356 -39 2 -54;3930 -356 356 -39 2 -54;3962 -356 356 -39 2 -54;3995 -356 356 -39 2 -54;4027 -356 356 -39 2 -54]

Now i have developed a code on arduino to receive the file and transforming it into a matrix. But i am going to have problems at the beginning while printing the string received: here is the starting part of the code to check if i've received the numbers into the file:

while (Serial.available() > 0) { //read from serial

    c = Serial.read(); // read Char
    stringa = stringa + c; // add Char to string
    conta4=conta4+1; //increase counter to store the length of the string
    }
    if(s==false){
if(stringa.charAt(conta4-1)==']'){//enter if only the entire string has been completed because the file end with ']' char
  Serial.println(stringa);

the string is printed on the Hyperterminal monitor but in some numbers there is some error character like the ones in the photo above. I tried to change the baud rate (reducing it to 4800 instead of 9600) but the errors is still here. Any suggestions?

IMG_0892.JPG

Try it without the String stuff, to eliminate that as a possible cause of the issue:

if (Serial.available()) {
  Serial.write(Serial.read());
}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

The problem is not on the code, because if I copy the entire string of the .txt file on the serial monitor I receive it in the correct way, because every character is printed correctly. I don't know why those character errors occur using Hyperterminal. I repeat, the problem is not on the code but in the communication between Hyperterminal and Arduino.

Write a short Arduino program that prints the ASCII value of every byte it receives and compare what you get from the Serial Monitor with what you get from Hyperterminal

My suspicion is a different line-ending

...R

I have had another idea: instead of using Hyperterminal I found this program to be copied into the Command Prompt:

mode COM7 BAUD=4800 PARITY=n DATA=8
copy mystring.txt \\.\COM7

It seems to work but the problem occurs when I want to check if I received correctly the file trying open the serial monitor. This is the error message:
Error during the opening of COM7 (busy port). I think this is why I am using the port to send the file through the Command Prompt.
Arduino DUE has three serials, so the idea can be send file to a serial and print into the monitor the string I received. How can I do this?

Arduino DUE has three serials

Only one of them, Serial, is connected to the USB cable. If you use some application to open the COM port that the Arduino is connected to, you can't have some other application also try to open the same COM port.

If you use an FTDI cable, you can create another connection, and another COM port, between the Arduino and the PC, and have some other application connected to that COM port.

Yes I understood, how the cable must be connected to the Arduino?

Connect the FTDI cable or adapter board to the Due like so:

FTDI | Due

RX | TX
Gnd | Gnd

This connection will only work for outgoing communication from the Due. If you want to be able to communicate from the computer to the Due, you can also connect the FTDI TX to the Due's RX. However, be aware that the Due uses 3.3 V logic levels and will be damaged if it's subjected to 5 V input. If your FTDI is outputting 5 V logic levels then you would need to put a level converter on the TX pin of the FTDI.

You can actually use any USB to TTL serial adapter chip, such as the CH340. "FTDI" tends to be used as the generic term since the FTDI FT232 was the most common of these chips for many years.

There are FTDI modules that make it easy to select 3.3V for the IO vs 5V.
I use these a lot for partially that reason.

https://www.tinyosshop.com/index.php?route=product/product&filter_name=ftdi&filter_description=true&filter_sub_category=true&product_id=600

So let me check if I understood correctly:

With this cable (or that module), will I be able to have two serials? COM XX where to send the Matlab matrix and COM YY (which is the serial monitor) for debugging and verify that everything is correct, right?

That's correct.

The other thing you need to be aware of is that the Due has multiple serial ports, each of which has its own object in Arduino code:

  • SerialUSB: Native USB port
  • Serial: Programming port and RX0, TX0
  • Serial1: RX1, TX1
  • Serial2: RX2, TX2
  • Serial3: RX3, TX3

If you have the Due plugged into your computer via the Programming port and the "FTDI" connected to TX0, then the same data will be transmitted to both of the COM ports. If you want to be able to send different data to each COM port, then you should connect the "FTDI" to one of the other serial ports on the Due and write your code accordingly.

More information: