Hey, I'm running into a few issues with the below sketch. It should be taking a string of letters, converting each letter to its ASCII equivalent, and then printing that result. One of the issues I'm running into is, that the first and last lines of the serial print contain unrecognizable characters. What could be causing this/ Dose it mean my Arduino is damaged?
// results
the random part I am referring to is the squares and random letters at the top and bottom of the ss.
when I use my letters variable in place of 3 in the for loop, I get more lines printed but it ends the same way.
Serial.begin(115200);
char myword[] = "EFG";
size_t size = myword;
int letters = size / myword[0];
//int asciiNumb = (int) x;
int asciiWord[letters];
//Serial.print(word);
//Serial.print(size);
Serial.print("array is this long \n");
Serial.print(letters);
Serial.print("there are letters in this word /n");
for(int index = 0;index <=3;index ++){
asciiWord[index] = ((int) myword[index]);
Serial.println(asciiWord[index]);
}type or paste code here
As this question is nothing to do with the boot loader I have moved it here.
You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.
No the Arduino is not damages, this is the result of you failing to configure your system correctly, or to write your code correctly.
In your code you set the baud rate with:-
Now you need to set the serial monitor window to the same value, otherwise nothing you print will look correct. It is worth adding a small delay say half a second after the serial begin to allow the drivers to start working before you use them.
You also need to understand the difference between binary, hex and ASCII,
They are all stored in binary bytes, but there are standards on how they are interpreted by humans and computers.
void setup()
{
delay(3000);
Serial.begin(115200);
char myword[] = "EFG";
int size = sizeof(myword);
int letters = size / sizeof(char);
int asciiWord[letters];
Serial.print("Array is this long \n");
Serial.println(letters);
Serial.print("These are letters in this word \n");
for (int index = 0; index < 3; index ++)
{
asciiWord[index] = ((int) myword[index]);
Serial.println(asciiWord[index]);
}
}
Thank you! I'm new to Arduino's, are there any youtubers, you would recommend to watch to get a good understanding of the ide and what is possible with an Arduino?
binary is base 2, hex is base 16 ascii is base 10. ascii is used to relate letters to numbers. I want to use the ascii # to calculate the binary version of each letter using mod 2.
It took me wayyy to long to see that i wasn't using println on the variables print line, i was so confused lmao.
Question for you tho, when i replace 3 with the letter's variable. I see an extra 0 being printed. Two zeros if i change the < to a <=.
Can you explain why? I'm assuming it's because each string in C has an ending char of "0" as a delimiter. Which i confirmed by printing the size of "myword". Still that doesn't explain why there would be two when <= is used.
Is there a better permanent solution other then using letters - 1 in the for loop?
No, there is a lot of rubbish out there, and most people who answer questions here do not bother with watching videos. However, feel free to search for videos and if there is something you don't understand then post the link to the video, along with the time through the video that the bit you understand occurs.
Mostly videos have a low information density, that is they drag things out.
Yes.
Everything is stored in a computer is in base 2. The only use of other bases is to display, or input, numbers for the connivance of the user or programmer. It is what these binary numbers represent, or mean, is up to you and how you want to interpret them.
In the case of ASCII, search for an ASCII table to see the relationship between a number, in any base, and the appropriate symbol shape. Also the word "mod 2" is not what you mean here it is short for modulo 2. It actually means to take a number, divide it by another number, in this case 2, and just have the remainder of the division left. So if you use mod 2 on a number, you will get either zero or one, nothing else.
Yes, I know that mod 2 is modulo 2. In discrete mathematics, I learned you can use mod x to turn a number into base x by keeping track of the remainder.
I understand that, I was only using 3 and "EFG" as an example to get the code running. I will have an input that is entered at runtime, so I need the for loop to be dynamic. Hence my previous question.
Two zeros if i change the < to a <=. Why is there a second zero at the end of the for loop?
EX:
for (int index = 0; index < letters; index ++)
{
asciiWord[index] = ((int) myword[index]);
Serial.println(asciiWord[index]);
}
will print
69
70
71
0 // this being the ascii representation of the termination bit i think
in my mind, this doesn't make sense because letters = 4 so when index = 3, it should execute, increment index, and then exit since 4 is not < 4
but when my for loop becomes
for (int index = 0; **index <= letters**; index ++)
{
asciiWord[index] = ((int) myword[index]);
Serial.println(asciiWord[index]);
}
will print
69
70
71
0 // ascii delim
0 // why and how is this 0 getting printed?
The only thing i can think of is that letters = 5. but that isn't possible because it is based on myword and we have already established that myword 4 chars long three elements and one delimiter.
that being myword[0] = E , myword[1] = F , myword[2] = G , then the delimiteing char "/0"
where is the fifth char?? is it treating the delimiting char as two separate chars?