Hello people of the internet,
I was making a project where an Arduino should receive a string via serial, entered on the serial monitor for instance, and then compares it to an instruction and reacts.
(The board is currently an Uno rev3. )
I have both operated with strings and string operations and sent serial data (though no strings) with arduinos, but not the two together.
Here is my setup:
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Serial.begin(19200);
Serial.setTimeout(200);
Serial.println(bootConfirm);
Serial.print(bootNotice);
for (int k = 0; k < strlen_P(bootNotice); k++) {
char miniBuffer = pgm_read_byte_near(bootNotice + k);
Serial.print(miniBuffer);
}
Serial.println(readyConfirm);
Serial.flush();
}
and this is the loop
void loop() {
if (Serial.available() > 0) {
instruction = Serial.readStringUntil('\n');
Serial.println(instruction);
if (instruction == "LED") {
//int a = digitalRead(2);
//digitalWrite(2, !a);
Serial.println("correct");
}
else {
; //do nothing
}
}
}
Another odd thing that happens: there is a large character array that I print at the beginning:
char bootConfirm[] = " Switchboard booted successfully \n";
char readyConfirm[] = "\n System is ready to receive instructions \n";
const PROGMEM char bootNotice[] = {
"The system is initialising \n"
"Instructionset: \n"
"Type \"move up () degrees\" ; \"move down () degrees\" to tilt \n"
" where () is to be replaced with the desired number of degrees to move \n"
"Type \"turn left () degrees\" ; \"turn right () degrees\" to pan \n"
" where () is to be replaced with the desired number of degrees to move \n"
"Type \"return to zero\" to return to the origin \n"
"Type \"stop motors\" or press stop button to stop any movement \n"
};
That prints out on the serial monitor just fine, if I leave the pin toggling in the loop function commented out (as it is now), but if try to toggle the pin, the first line of bootNotice[] glitches out some odd square characters.
Anyone got an idea why?
This is what it looks like:
⸮⸮⸮⸮⸮The system is initialising
Instructionset:
Type "move up () degrees" ; "move down () degrees" to tilt
where () is to be replaced with the desired number of degrees to move
Type "turn left () degrees" ; "turn right () degrees" to pan
where () is to be replaced with the desired number of degrees to move
Type "return to zero" to return to the origin
Type "stop motors" or press stop button to stop any movement
I am really not the greatest of programmers, but I cannot see any reason for this to not work, except if I pulled a massive bonehead move that I don't see; so I try to refer to the swarm of people smarter than me, because I'm running out of ideas right here.
Thanks for reading this lot and for any help you might offer.