Go Down

Topic: GPS Logger, reading and Writing to and from SD (Read 4564 times) previous topic - next topic

-dev

#30
May 09, 2017, 02:59 pm Last Edit: May 23, 2017, 09:11 pm by -dev Reason: numbering
Here's a few suggestions:

1) Check the return value from bmp.begin():

Code: [Select]
void setup()
{
  Serial.begin(115200);
  gpsPort.begin( 9600 );

  if (!bmp.begin()) {
    Serial.println( F("BMP280 error!") );
    for (;;); // hang here
  }

2)  Do you have an LED on pin 10?  I just re-read some of your earlier posts, and I didn't notice that you have an LED on one of the SD pins.  Put the LED (+ resistor!?!) on a different pin.  Add a const int for the LED pin at the top, and use that name instead of the pin number in setup and loop.

3)  Confirm that you used something to level-shift pin 3 (gpsPort TX) down to the GPS RX pin.  A resistor?  A resistor divider?

4)  Your GPS module uses a ublox M8 GPS chip,  not a MTK GPS chip.  Delete the PMTK configuration commands and send these, instead:

Code: [Select]
 // Configure the GPS device
  GPS.send_P( &gpsPort, F("PUBX,40,RMC,0,0,0,0,0,0") ); // disable RMC
  GPS.send_P( &gpsPort, F("PUBX,40,GLL,0,1,0,0,0,0") ); // enable GLL
  GPS.send_P( &gpsPort, F("PUBX,40,GSV,0,0,0,0,0,0") ); // disable GSV
  GPS.send_P( &gpsPort, F("PUBX,40,GSA,0,0,0,0,0,0") ); // disable GSA
  GPS.send_P( &gpsPort, F("PUBX,40,GGA,0,0,0,0,0,0") ); // disable GGA
  GPS.send_P( &gpsPort, F("PUBX,40,VTG,0,0,0,0,0,0") ); // disable VTG
  GPS.send_P( &gpsPort, F("PUBX,40,ZDA,0,0,0,0,0,0") ); // disable ZDA

This should make the GPS module send the fewest number of characters each second.  That will decrease the number of interrupts the Arduino has to handle and increase the GPS quiet time (more time to take BMP reading and do the SD write).

The GLL sentence will only fill the date/time and lat/lon fields of the fix, though.  If you want to receive and use other pieces, you may have to enable other sentences.

5)  Run the NeoGPS example NMEAorder.ino to verify you have the correct LAST_SENTENCE_IN_INTERVAL selected in NMEAGPS_cfg.h.  This will make sure you're taking the altitude reading while the GPS device is quiet.  After sending the above configuration commands, it should say that GLL is the LAST.

6)  Change the buffer size in copyFile to 128:

    uint8_t buffer[ 128 ];

7)  If it still doesn't work after trying those things, I'd try commenting out all the SD includes and code.  If GPS+BMP works, you'll know it has something to do with adding the SD library.  Or try commenting out the GPS includes and code, and just write the altitude.  Simulate the GPS code with millis():

Code: [Select]
uint32_t simulGPS;

void loop()
{
  //if (gps.available()) {
  if (millis() - simulGPS >= 1000) {
    simulGPS = millis();

    altimeter = bmp.readAltitude (1050.35); // * .1; why ?
    Serial.println(altimeter);

    gpsDataFile.println(altimeter);
    gpsDataFile.flush();
  }

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
    ...

If neither of those works, that leaves NeoSWSerial as a culprit.  Don't call gpsPort.begin() and see if it works.  Then comment out the NeoSWSerial includes and gpsPort declaration.  If the altitude starts working, try AltSoftSerial, with the GPS on pins 8 (to GPS TX) and 9 (to GPS RX through resistor or resistor divider).
Really, I used to be /dev.  :(

Tonyi

Thanks a lot for all these potential solutions!  It will probably take me a long while to try all of them, unless I get lucky, and find the right fix, as I go down from the top of the list.

-dev

Sorry, forget #2 for now.  Pin 10 is not used for the SD card by default.  If you want the SdFat library to use the standard Arduino SPI library to talk to the card, you must set SD_SPI_CONFIGURATION to 1 in SdFatConfig.h.  That uses pin 10 for the SS ("slave select", aka "chip select" or CS).

By default, SD_SPI_CONFIGURATION is 0, and it uses its own code to talk to the card.  You can use other pins for the SS (you used pin 4).
Really, I used to be /dev.  :(

Tonyi

I had already changed the push button from pin 10 to pin 9 after reading your last post; it did not change anything.   I do remember, reading somewhere, to refrain from using pin 10, and reserve it for the SD card slot device, even though nothing is plugged into it.. (pin 10) that is.

Tonyi

#34
May 14, 2017, 05:51 am Last Edit: May 14, 2017, 05:58 am by Tonyi
I finally got some time to work on this again and sure enough your #1 suggestion was correct. The BMP280 is not starting up!   After implementing you snippet, from #1, I got the error: BMP280 error!   In the serial monitor. 
Something is interfering with either or both of the pins, A4 , A5 which are the default pins for the I2C  connection and I have no clue how to re assign I2C pins.

-dev

Well, there ya' go!

Look at Adafruit_BMP280.cpp, line 61.  That's the only place ::begin returns false.  So print out the chip ID to see what is coming back.  Change these lines:

  if (read8(BMP280_REGISTER_CHIPID) != chipid)
    return false;

...to something like this:

Code: [Select]
  uint8_t returnedChipID = read8(BMP280_REGISTER_CHIPID);
  Serial.print( F("CHIPID = 0x") );
  Serial.println( returnedChipID, HEX );

  if (returnedChipID != chipid)
    return false;

Then you can see what it returns and why it doesn't match.

Quote
I have no clue how to re-assign I2C pins
You can't.  I2C is hardwired to those pins.  I2C requires pull-up resistors, do you have those connected?

I don't see a schematic in any of the previous posts (asked for in reply #20).  Please describe all connections; a schematic would be best.  Please don't use Fritzing.  :P  Some free schematic editors: Schemit, CircuitLab (used by electronics.stackexchange) and CircuitBee.  Capture a screenshot of the schematic (or export a JPG/PNG), paste it into an image editing program (Paint, GIMP, IrfanView), save it as a JPG/PNG, attach it to your post or link from your blog).

You could just use an image editing program to sketch it out.  Or, go old school and draw it on a napkin and take a pic.  :)

You haven't answered my question about the GPS level-shifting either, so this would tell me for sure what is connected (see Reply #2 and #9).
Really, I used to be /dev.  :(

Tonyi

After altering the cpp  file I get this in the serial monitor:
Quote
CHIPID = 0xFF
BMP280 error!
.  
Quote
Some free schematic editors: Schemit, CircuitLab (used by electronics.stackexchange) and CircuitBee
Which one of those programs is most like Fritzing, being that Fritzing is the only one I have ever used.  
Quote
You can't.  I2C is hardwired to those pins.  I2C requires pull-up resistors, do you have those connected?
I've heard some say bit banging, but personally have no clue how to do that.  No, I had not implemented the resistors but will; after mothers day, and a happy MD to ya.

-dev

Quote
I had not implemented the resistors but will
That's probably it.  0xFF means the BMP280 did not respond to the READ_CHIPID command.

Quote
Which one of those programs is most like Fritzing
Thankfully, none.  ;)  Fritzing is a diagram of the physical parts, the way they look.  The wiring is poorly "routed" and usually hard to follow.

A schematic is a logical diagram that shows what is connected.  You'll see boxes and lines, with text labels that show the name of the pin, just like my "Level-shifting" post.

Scheme-it is ok, but most of it's overkill.  Select the "Custom Symbols" on the left.  In "Symbol Primitives", choose "Box" and drop a few on the grid.  Select one of the boxes, and you can change the labels in the right pane.

Then grab a few "Pin Right" or "Pin Left" and drop them on the boxes.  Click on the pins to change their name.  To connect the pins with a wire, press the Left mouse button on one pin and move to another pin, and release it.

I like CircuitLab, but it costs money now.  :(  You can create an account at stackexchange, and start to ask a question on the electronics site.  There's an icon in the post editor that allows you to enter a schematic, using a subset of the CircuitLab capabilities.  Take a screenshot when you're done and DON'T POST THE QUESTION.

CircuitBee is pretty easy, too.  Create an account and give it a whirl.

Or just sketch something out, take a pic and post it...  label the boxes and lines so we know what is connected to what.
Really, I used to be /dev.  :(

Tonyi

I haven't got the schematic figured out yet; not much time lately, but in fritzing, a few years ago, I did try, and the schematic was a mess, like unraveling a twisted spiders web, so I agree with you.  I did manage to have time to try many resistors to pull both the SDA SCL high, with the same results as before.  
Quote
CHIPID = 0xFF
BMP280 error!
I tried using a 22k ohm, 100k ohm, 220k ohm, 10,000 ohm and a 100 ohm pair of resistors; one on each pin.   I didn't have a 3.4k ohm resistor, as seen posted as a common one to use, to try out but in my research, into this BMP280 have found that the unit has built in 10k resistors on the sensor unit.  I did try the stand alone sketch, that has been working all along with the, changes in the Adafruit_BMP280.cpp
Quote
if (read8(BMP280_REGISTER_CHIPID) != chipid)
    return false;
and the changes you suggested to the sketch:
Quote
if (!bmp.begin()) {
    Serial.println( F("BMP280 error!") );
    for (;;); // hang here
with the 22k ohm resistor connected and it ran fine.   It runs fine without the resistor added to it, with the stand alone sketch....Just figured I would give an update.

-dev

Quote
How do I put a resistor in there?
It's not under the "Custom Symbols", it's under "Schematic Symbols -> Passives -> Resistors -> General".
Really, I used to be /dev.  :(

Tonyi

Quote
I don't see a schematic in any of the previous posts (asked for in reply #20).  Please describe all connections; a schematic would be best.  Please don't use Fritzing.
Please bear with me, all I've ever used previously is Fritzing.   I used the tools the most accurately I could, and thanks -dev for pointing me to the websites.  I'm guessing it is preferable to use the schematic without the  grid...

-dev

Ok, that confirms that you are not level-shifting the GPS pins (#3 in reply 30).  Without them, the GPS device can draw extra current, the Nano might damage the GPS RX pin, or GPS TX data may not be received reliably.

Does your SD card have level-shifting transistors on the board?  Perhaps a 3.3/5V switch?  If it only has resistors, it may not be reliable.  If it has nothing (direct connections to the socket), the Nano may damage your SD card.

You'll have to describe what happens for each step in reply #30, and attach the code you tried.  I think you've tried #1, and posted the schematic.

Skip #2.

Next is to get step #3 straightened out and investigate the SD card voltage levels.  Then the hardware will be "safely" connected together.

Step #4 requires sending to the GPS RX pin, safely, so let's be sure everything is kosher.

Cheers,
/dev
Really, I used to be /dev.  :(

Tonyi

Quote
Ok, that confirms that you are not level-shifting the GPS pins (#3 in reply 30)
I would level-shift, but sorry to say, I don't how its done, or if I have the components to do so.  I will try feeding the BMP280 voltage from a separate source.
Quote
Does your SD card have level-shifting transistors on the board?  Perhaps a 3.3/5V switch?
Yes, the SD card has both a 3.3/5V  input, but no physical switch or jumper.   I'm using the 5v input now but will try using the 3.3v and see what happens....

-dev

Quote
I'm using the 5v input now but will try using the 3.3v and see what happens....
Umm... maybe you shouldn't do that.  Please provide a link to where you bought it.

Quote
would level-shift, but sorry to say, I don't how its done, or if I have the components to do so.
See reply #2.

Quote
I will try feeding the BMP280 voltage from a separate source.
That has nothing to do with level-shifting.  That's something you would do if the Nano+GPS is using most of your power supply capacity.
Really, I used to be /dev.  :(

Tonyi

I got one of these inexpensive SD card readers: here
Quote
That has nothing to do with level-shifting.  That's something you would do if the Nano+GPS is using most of your power supply capacity.
I thought that the GPS might be hogging the voltage causing the BMP280, not function, so I supplied it with a separate power source and had the grounds hooked to each other...  Same results (not functioning).
Quote
level-shift,...... See reply #2
I think you meant #3, but still not sure how to go about it.  Is it similar kind of hookup as a voltage divider using two resistors.  Like method 1 on this HERE website?

Go Up