Hello everyone,
I´m new to Arduino and this is my first question. I´m having some issues using the seeeduino xiao with this Lib FlashStorage - Arduino Libraries to save serial data to the flash storage.
void loop() {
mytime = millis();
if (Serial1.available() > 0) {
SincomingByte[counter] = Serial1.read();
SerialUSB.print(SincomingByte[counter]);
loop_finished = false;
counter++;
start_time = mytime + 10000;
stop_time = start_time + 5000;
}
else if(mytime >= start_time && mytime <= stop_time){
if(!loop_finished){
my_struct logger_loop = my_flash_store.read();
for(int c = 0; c < counter; c++){
if(Serial1.available() > 0){
break;
}
logger_loop.incomingByte[c] = SincomingByte[c]; //This doesn´t work if I call my_flash_store.write(logger_loop); but works fine if I just print it and not save it
logger_loop.incomingByte[c] = {'A'}; //Saving simple Char works
}
logger_loop.valid = true;
logger_loop.not_connected = true;
logger_loop.counter = counter;
my_flash_store.write(logger_loop);
loop_finished = true;
}
}
}
Guessing as to the issue... No wait it is better if the issue(s) were shared that way1000's of people don't have to play 100000000's questions to guess the issue(s).
Sorry!
The sketch loads fine but after 5 sec the Usb port is not recognized anymore
Write 46024 bytes to flash (720 pages)
[==============================] 100% (720/720 pages)
done in 0.390 seconds
Verify 46024 bytes of flash with checksum.
Verify successful
done in 0.050 seconds
CPU reset.
processing.app.SerialException: Cant Find Serial Port "COM4".
at processing.app.Serial.(Serial.java:152)
at processing.app.Serial.(Serial.java:82)
at processing.app.SerialMonitor$2.(SerialMonitor.java:132)
at processing.app.SerialMonitor.open(SerialMonitor.java:132)
at processing.app.AbstractMonitor.resume(AbstractMonitor.java:132)
at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2126)
at processing.app.Editor.access$1300(Editor.java:116)
at processing.app.Editor$UploadHandler.run(Editor.java:2095)
at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM4; Method name - openPort(); Exception type - Port not found.
at jssc.SerialPort.openPort(SerialPort.java:167)
at processing.app.Serial.(Serial.java:141)
... 8 more
If not mistaken, your board has native USB so serial ports change for the upload and (are supposed to) change back. Sometimes you might get another port.
- Check with windows device manager what is happening.
- The switching back might be too slow and serial monitor can't find the original port.
Note: don't post snippets, post complete code. In this case not relevant as the error has nothing to do with your code.
I could not find the problem, but I did a workaround: a global struct with the FlashStrorage Lib so that it changes to the struct members do not get overwriten when the loop function gets called each time. Then I removed the static variable and wrote directly to the struct char member "logger_loop.incomingByte"
typedef struct {
boolean valid = false;
char incomingByte [ARRAY_SIZE] PROGMEM;
boolean not_connected = false;
boolean counterVoll = false;
unsigned long counter = 0;
} Flash;
FlashStorage(my_flash_store, Flash);
Flash logger_loop = my_flash_store.read();
void loop() {
mytime = millis();
if (Serial1.available() > 0) {
logger_loop.incomingByte[counter] = Serial1.read();
loop_finished = false;
counter++;
start_time = mytime + 10000;
stop_time = start_time + 5000;
}
else if(mytime >= start_time && mytime <= stop_time){
if(!loop_finished){
logger_loop.valid = true;
logger_loop.not_connected = true;
logger_loop.counter = counter;
my_flash_store.write(logger_loop);
loop_finished = true;
}
}
}