Hi, I am a total noob with arduino. I have a TinyZero board with a microSD and GPS receiver shield, and I am trying to run a sketch to log GPS data to the card every second. However, the sketch only runs when I upload it from the Arduino editor.
I know the sketch works, because I can see the LED indicator flashing and I am able to access the GPS data after removing the SD card.
I have done quite a bit of searching and from what I understand, the setup() loop should be running each time the board is reset or powered on, yet this does not seem to be the case. I would greatly appreciate any help or advice!
#include "SoftwareSerialZero.h"
#include <SD.h>
//pins used by the GPS module
static const int GPS_ONOFFPin = A3;
static const int GPS_SYSONPin = A2;
static const int GPS_RXPin = A1;
static const int GPS_TXPin = A0;
static const int GPSBaud = 9600;
static const int chipSelect = 10;
//GPS signal is connected using a software serial port
SoftwareSerial Gps_serial(GPS_RXPin, GPS_TXPin);
void setup()
{
// Init the GPS Module to wake mode
pinMode(GPS_SYSONPin, INPUT);
pinMode(GPS_ONOFFPin, OUTPUT);
digitalWrite( GPS_ONOFFPin, LOW );
delay(5);
if( digitalRead( GPS_SYSONPin ) == LOW )
{
// Need to wake the module
digitalWrite( GPS_ONOFFPin, HIGH );
delay(5);
digitalWrite( GPS_ONOFFPin, LOW );
}
// Open the debug serial port at 9600
Serial.begin(9600);
// Open the GPS serial port
Gps_serial.begin(GPSBaud);
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
int inByte = 0;
byte pbyGpsBuffer[100];
int byBufferIndex = 0;
void loop()
{
byte byDataByte;
if (Gps_serial.available())
{
byDataByte = Gps_serial.read();
Serial.write(byDataByte);
pbyGpsBuffer[ byBufferIndex++ ] = byDataByte;
if( byBufferIndex >= 100 )
{
byBufferIndex = 0;
File dataFile = SD.open("gps.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.write(pbyGpsBuffer, 100);
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening gps.txt");
}
}
}
}
UKHeliBob:
What is your evidence that the sketch is not running ?
When I upload the sketch, I know that it runs until I power off the board--the LED flashes constantly while running, and I am able to view the GPS data saved to the card after powering it off.
Neither of these things are true when I power it off and on again. I have tried adding a simple blink statement just to see if the loop is executing at all, but that didn't seem to work either.
Robin2:
Please post an example of the output produced by your program - copy it from the Serial Monitor.
...R
The program isn't supposed to output to the Serial Monitor, it logs GPS data in NMEA format to a .txt file on the microSD card. I can provide that if necessary.
If you don't see the message "Initializing SD card..." then something is terribly wrong. You should also see either "Card failed, or not present" or "card initialized.".
I'm a little confused about the need for a "SoftwareSerialZero.h". Since the Tiny Zero shares a processor with the Arduino Zero, can't it use SoftwareSerial.h from the Arduino libraries?
johnwasser:
If you don't see the message "Initializing SD card..." then something is terribly wrong. You should also see either "Card failed, or not present" or "card initialized.".
I'm a little confused about the need for a "SoftwareSerialZero.h". Since the Tiny Zero shares a processor with the Arduino Zero, can't it use SoftwareSerial.h from the Arduino libraries?
Interesting, it definitely runs as I can view the GPS logs both in the txt file and as a track after importing into Google Earth. I don't know why it wouldn't send the message...
As for the SoftwareSerialZero library, I'm using that one because the standard library doesn't support the clock rate of the TinyZero (48MHz). When I tried to use the SoftwareSerial library, it was unable to compile.
To send text to the Arduino IDE Serial Monitor, use the SerialUSB object instead of Serial
If you were able to upload a sketch to the TinyZero and now it does not respond, you may need to force this into bootloader mode. To do this, power off the TinyZero using the slide switch. Plug the USB cable into the TinyZero and your computer. Then press and hold the button on the bottom on the TinyZero while sliding the switch to the ON position. Then try uploading your program to the TinyZero and it should work. You may need to try this several times if it does not work the first time.
The hardware between the TinyZero and TinyScreen+ share some similarities, so you may see some things labeled 'TinyScreen' which are actually for the TinyZero.
So that means you will not be able to see anything on the serial monitor with the code you have.
TomGeorge:
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What GPS?
How are you powering the GPS?
What SD Card module?
How are you powering the SD card Module?
When you say you power OFF the ON, how long between OFF then ON?
If you leave it OFF for 30seconds then ON, what happens?
Tom...
Hello, I'm just using the standard TinyZero board board coupled with their GPS receiver and microSD adapter shields. The setup is powered by a 150mAh battery. Here's a picture:
Thanks, I'll take a look at this when I have time later.
Well I would have thought it was the first thing you should do because it will tell you how far the sketch is running, and if you are having trouble with the SD card when you try and run it after a power cycle.
This is the crux of understanding your problem.
Figured it out with some help from my Dad. Just needed to add a 1sec delay at the beginning of the setup loop. Also, apparently the TinyZero does use SerialUSB and not Serial to print to the Serial Monitor. Thanks for the help guys.
Yeah my bad. I meant to say setup function, I'm aware of the difference between the terms.
Grumpy_Mike:
2) A fixed delay will not always work you need:-
Serial.begin(9600);
while (!Serial) delay(100);
This ensures that you don't go any further until the USB device enumerates. ( starts up and registers with what ever it is plugged in to )
Thanks for the advice, I'll edit it next time I work on it. Could you explain why this delay is necessary, and why it needs to be dynamic? I discovered it accidentally while trying to blink the LED as a form of debugging. Still trying to learn all this stuff.