Go Down

Topic: Adafruit Feather M0 Adalogger (ATSAMD21G18 @ 48MHz with 3.3V logic/power) (Read 622 times) previous topic - next topic

BryAB

I posted this problem over 2 months ago on the Adafruit forum, but no one could help me. I thought maybe someone here might have some helpful advice:

I am using 2 Feather Wings (RFM69HCW 900MHZ: https://www.adafruit.com/products/3229) each connected to a Feather M0 Adalogger (https://www.adafruit.com/products/2796). One device is the transmitter (on a Windows 7 laptop with Arduino IDE 1.6.12) and the other device is the receiver (on a Windows 8 laptop with Arduino IDE 1.8.0).

I am using an interrupt service routine (ISR) with a timer on my transmitter Feather M0 in 2 different sketches. One sketch uses only the serial monitor (i.e., all of the data is written to the serial monitor display on my Windows 7 laptop). This sketch works well, and will run for hours while the receiver Feather M0 also continues to work as expected.

The other sketch uses only the micro SD card (i.e., all of the data from the transmitter Feather M0 is written to the SD card only; there is no usage of the serial monitor). This SD sketch really only differs from the serial monitor sketch in that it uses the SD library (<SD.h>), and it writes less data to the SD card than the first sketch writes to the serial monitor display. This SD sketch (like the serial monitor sketch) compiles successfully. However, this SD sketch will only run for about 20 to 40 minutes before it stops writing data to the SD card, at which point the receiver Feather M0 also stops successfully receiving data from the transmitter Feather M0. It is as if the void loop() stops working while what is within the ISR continues to work properly. I know this because I am toggling pin 12 every 2 milliseconds within the ISR on the transmitter Feather M0, and I am displaying pin 12's square wave on my oscilloscope. The oscilloscope continues to display the toggled square wave even after the transmitter Feather M0 stops writing data to the SD card and after the receiver Feather M0 stops successfully receiving data from the transmitter.

At first, I thought that maybe the SD library (https://github.com/adafruit/SD) might be using the same timer as the ISR, but I checked SD.cpp and SD.h for any timer usage, and I found none, plus, since the SD sketch compiles successfully, I figured there is probably no timer conflict between the SD library and my ISR. I am really at a loss to understand what is happening here. Any advice would be greatly appreciated.

I was told the following by someone on the Adafruit forum:

The packet radio module's CS pin is connected to digital pin 8 on the microcontroller (not broken out to the edge of the Feather), and has a pull-down resistor so the radio is enabled by default.

If you want to use some other SPI device, you have to send pin 8 high to make the radio release the SPI pins first. When you're done talking to the other device, send pin 8 low again to re-enable the radio.

I then responded:

Just to make sure that I am implementing correctly what you are advising, can I simply write in my code:

digitalWrite(8, HIGH);

just before I write to the transmitter Feather M0's SD card and:

digitalWrite(8, LOW);

just after I write to the transmitter Feather M0's SD card, even though digital pin 8 on the microcontroller is not broken out to the edge of the transmitter Feather M0? I have never tried previously to manipulate a pin that was not connected to the edge of the board, and so I am uncertain of the procedure. I realize also that I would need to write:

pinMode(8, OUTPUT);

in my void setup(), assuming that my usage of the digitalWrite function in this case is correct.

The Adafruit forum said that that was correct. However, that advice did not work, and so I responded to the Adafruit forum thus:

I tried using the digitalWrite() function to pin 8, and unfortunately I am still getting the same results; the transmitter Feather M0 will work properly and write data to its SD card for about 40 minutes, and then it will stop transmitting data to the receiver Feather M0 and stop writing data to its SD card. Consequently at the same time, the receiver Feather M0 will also stop receiving data and stop writing data to its SD card.

I tried placing the digitalWrite() function in 2 different ways within my sketch:

Code: [Select]
  File dataFile = SD.open("log120.txt", FILE_WRITE);
      if (dataFile) {
       digitalWrite(8, HIGH); // send pin 8 high to make radio module release the SPI pin so that data is written to SD card  
       dataFile.println("REM DETECTION");
       dataFile.close();
       digitalWrite(8, LOW);   // send pin 8 low to re-enable the radio module
     }  // end of if(datafile)


and:

Code: [Select]
digitalWrite(8, HIGH); // send pin 8 high to make radio module release the SPI pin so that data is written to SD card  
       File dataFile = SD.open("log120.txt", FILE_WRITE);
      if (dataFile) {
       dataFile.println("REM DETECTION");
       dataFile.close();
     }  // end of if(datafile)
       digitalWrite(8, LOW);   // send pin 8 low to re-enable the radio module


but I unfortunately got the same result both times.

Please let me know if I am using the digitalWrite() function to pin 8 in the way that you are advising. Thanks.

Unfortunately, even after 2 months, I have never received a response from the Adafruit forum to this last request of mine. If anyone on this forum has any advice on how to solve this problem, I would greatly appreciate it. Thanks.



Koepel

You have to put more effort in your question.
The question is far too long. You mention a second Arduino board, but that is not part of the problem. When you give a link, please give a real link. You don't have to quote something from another forum, just give a link to it.

Your board is the Adafruit Feather M0 Adalogger, with the schematic.

Your add-on board is a Adafruit Radio FeatherWing, with a schematic.

The main problem with the SPI bus is a device that is not releasing the MISO line, after the Chip Select is no longer active.
I don't know if that is a problem here, I assume it is not.

The FeatherWing has in the middle of the board a "CS" pin. Did you connect something to it ? Do you assume it is magically connected to something on the Feather M0 board ? The FeatherWing has a pullup resistor connected to "CS", that means it is default disabled. Have you read the complete tutorial, to make the FeatherWing work ?

Every library enables the Chip Select for the SPI bus and releases the Chip Select after the SPI bus is no longer used. When you have to enable some Chip Select in the sketch, that is not normal. I doubt if that is needed.

Does the Adafruit board software not work with Arduino IDE 1.8.5 ? Can you please update your Arduino IDE.

Grumpy_Mike

Quote
It is as if the void loop() stops working while what is within the ISR continues to work properly.
That sort of thing can happen when you run out of memory, or when the main loop thread gets stuck waiting for something that never happens.
The first thing to look at is your use of String as opposed to string variables, the String class is not good in small memory systems and often has memory leak problems.

Use serial print statements to see where your loop function is stalling. Note this function  is called loop and not void loop.

BryAB

I apologize for my incompetence. Here is the link to the Adafruit forum where I first posted my question:

https://forums.adafruit.com/viewtopic.php?f=57&t=127764 

There is much more information there than I could post on this forum.

Quote
Have you read the complete tutorial, to make the FeatherWing work ?
I have read the tutorial for the Feather Wing RFM69HCW 900MHZ, and the Feather Wing has worked reliably well in other sketches that I used. In those sketches, I did not use the ISR, but instead I used the micros() function to perform the data calculations that I otherwise performed in the ISR. However, for some unknown reason, in those micros() sketches sometimes the sketch would lock up after a few hours, but most of the time it would run for hours without a problem. A friend (much more knowledgeable than I) recommended that I use the ISR instead of the micros().

Quote
Does the Adafruit board software not work with Arduino IDE 1.8.5 ? Can you please update your Arduino IDE.
I will definitely try to update the Arduino IDE to 1.8.5 and see if that works. Thanks for the advice.

Quote
That sort of thing can happen when you run out of memory
My transmitter sketch is using 35,964 bytes (13%) out of 262,144 bytes.

Quote
Use serial print statements to see where your loop function is stalling
The loop function does not stall when I use the serial monitor display, but only when I use the micro SD. Just to make sure that I understand what you are advising (I apologize for my ignorance), should I use dataFile.print statements to the SD, and place them throughout the loop function to see which print statement is printed to the SD card just before the loop function stalls?


Koepel

You don't have to apologize, I was only saying that no one was responding, since the whole question has to be read to understand the problem.

Your radio is on the "Wing", on the add-on board. Perhaps 'adafruit_support_mike' is confused with a Feather board that has the radio on the board itself.
As I wrote before: there is a pullup resistor, no pull down resistor, and the radio is not enabled by default and every library enables and disables the chip select. I think that 'adafruit_support_mike' is only confusing you and is wrong.

Your 13% of memory usage is what the compiler sees for normal variables. Grumpy_Mike was talking about runtime memory usage. The String object uses the heap. That could result into the "kaboom" scenario: https://learn.adafruit.com/memories-of-an-arduino/measuring-free-memory.

Grumpy_Mike adviced to use the Serial.println to print a lot to the serial monitor for debugging. Not writing more messages to the SD card, since the SD card is part of the problem.

Can you confirm that you have connected the "CS" pin of the radio Wing to a pin ? Which pin ?

An interrupt that continues to work is not hard. It does indeed mean that the loop() is halted somewhere.

The sketch is too large to pinpoint the problem.
There are while-loops that I don't trust. You can add a Serial.println() before and after every while-loop that is used in the loop().
There could be a bug in a Adafruit library.
Did Adafruit use their own SD library for the Feather series ? I'm not sure. If they do, perhaps someone else has already encountered a problem and made a "issue" on Github.

Does it halt sometimes after 1 minute ? Then it could be a hardware timing or electrical noise problem.
Does it halt at the same time or does it vary between 20 and 40 minutes ? It seems that the problem is building up. That is typically a memory problem, but it could be something else.

Grumpy_Mike

Quote
My transmitter sketch is using 35,964 bytes (13%) out of 262,144 bytes.
No that is only the program memory, you could be running out of memory for variables. While the compiler will tell you this at compile time it can not predict how much it will consume when running.
Another thing that could eat memory is recursion, that is a function calling itself, either by design or accident. If you don't clime out of it you leave stuff in the stack that keeps on growing.

BryAB

You have both provided me with some very pertinent advice. I am definitely going to try to implement your advice over the next few days as my time allows, and I will let you know what I discover. Your advice and help really mean more to me than you know. I thank both of you very much for this.

Go Up