Hi
I have some moderately annoying issues I was hoping you guys might be able to help me with. my Arduino NANO 33 IOT doesn't seem to work properly.
the first issue is that nothing the Arduino prints to the serial port shows up until I send some text over back to it using the serial monitor. my code works I'm fairly certain. it starts just fine. accepts input as it should. and prints all the text its supposed to After I send the first text to it over the serial monitor. but any print commands run before the first
secondly. reset doesn't work properly? if i press the button on the device itself, it just stops. and if i reset it in software. i get a similar result. the device just freezes. the only way to reset the device now is to reupload the code from the IDE. kind of a problem since I plan on copying the code to several other Arduinos and use them as trackers. is this normal? do i need to do something to cause reset to work?
note, the Arduino was bought from RS components.
to help explain the first point. here is the code I'm currently trying to run. note that both these problems seem to happen with everything I write. although I have not tested external code.
the code uses a state variable to control where it is and what its doing. as you can see. it starts in state 1000. its boot phase. here its supposed to try and connect to a network (not implemented yet). and print some text to serial monitor just to show the user its up and running. then it sets itself to state 1001. its idle phase where its waiting for commands from the user. as mentioned. it accepts commands perfectly well. and prints the appropriate responses after that. but the text "Arduino tracker system v0.1" never shows up unless i manually set the state to 1000 using a command. in which case it shows up just fine (presumably because I've now sent text over the serial monitor to the Arduino and its now speaking fine).
the state 1000 boot phase btw was an attempt to deal with the fact that i was getting nothing out of the serial.print commands put into void setup(). which also don't produce anything.
is this normal? am i just being stupid or is there something wrong with my Arduino? its always been like this btw.
#include <SPI.h>
#include <WiFiNINA.h>
int SBS = 16; // Serial buffer size, controlls how much of the serial buffer is read, max is 64
int CC = 7; // command count. how many commands there are in total
// note, for the command index below the first dimention needs to match the nummer of
// commands, while the second needs to match the serial buffer size
char commandIndex[7] [16] = { "T", "restart", "devicecfg", "ipconfig", "debug", "ping" "edit"};
// note, state is the most important value in the program. it controlls program flow
// and ensures the correct code gets execuded in the correct order. the start state is 1000
// with each subsequent subroutine getting its own state. command decoding for example is 1010.
// these values MUST NOT be modified without knowing what youre doing.
int state = 1000;
int lastState = 0;
char commandRegister[16];// <- this too needs to match the size of the input buffer
int commandIndexLookup = 0; // <- the command currently being checked.
char userInput[16]; //<- also needs to be the same as the serial buffer size.
void(* resetFunc) (void) = 0; // declare reset fuction at address 0
// system variables
//==============================================================
// command variables
int regnr;
char location[32];
byte MAC[6];
char ssid[];
int status = WL_IDLE_STATUS;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
while (state == 1000) {
delay(1000);
Serial.println("Arduino tracker system v0.1");
WiFi.macAddress(mac);
state = 1001;
}
while (state == 1001) {
if (Serial.available() != 0) {
for (int i = 0; i < SBS ; i++) {
byte o = Serial.read();
if (o == 10) {
i = (SBS + 1);
state = 1010;
}
userInput[i] = o;
}
state = 1010;
Serial.println(userInput);
}
}
while (state == 1010) {
for (int i = 0; i < SBS; i++) {
commandRegister[i] = commandIndex[commandIndexLookup][i];
}
if (strcmp(commandRegister, userInput) == 0) {
state = (999 - commandIndexLookup);
commandIndexLookup = 0;
}
else if (commandIndexLookup > CC) {
Serial.println ("unknown command");
state = 1001;
}
else
{
commandIndexLookup ++;
}
}
while (state == 999) {
Serial.println("Terminating!");
lastState = state;
state = 1001;
}
while (state == 998) {
Serial.print("Restarting");
delay(250);
Serial.print(".");
delay(250);
Serial.print(".");
delay(250);
Serial.print(".");
resetFunc(); //call reset
}
while (state == 997) {
Serial.println("device configuration");
Serial.println("(1) Device registration number");
Serial.print(":");
if (regnr == 0;) {
Serial.println("not configured");
}
else {
Serial.println(regnr);
}
lastState = state;
state = 1001
}
}
thanks in advance