Go Down

Topic: MPL3115A2 and NEO6m using NODEMCU (Read 295 times) previous topic - next topic

ardi23

Dear all seniors,

i'm working on project to locating position using gps and height of some object.

iam using nodemcu v3, sparkfun MPL3115A2, and gps neo6m.

here is the wiring

neo6m to nodemcu
vcc -> 3v
gnd -> gnd
rx -> d7
tx -> d6

MPL3115A2 to nodemcu
vcc -> 3v
gnd -> gnd
sda -> d2
scl -> d1

when i compile this code (in the attahment)

it works for gps
but didn't works on altimeter

when i test the altimeter from the examples
it works with the same wiring

is there anyone who knows where is my mistake?

pylon

I'm missing a

Code: [Select]
  tier.setModeAltimeter();


to tell the library which mode to use.

ardi23

I'm missing a

Code: [Select]
  tier.setModeAltimeter();


to tell the library which mode to use.
Dear pylon,

thank you for the reply...

but i'm became more confused after i read the library and realized the hint that you gave me, but still encounter error.

is there any mistake in my code that haven't solved?

pylon

Post the example code that works with the same wiring!

ardi23

#4
Jul 22, 2019, 04:41 am Last Edit: Jul 22, 2019, 04:44 am by ardi23
Post the example code that works with the same wiring!
Dear Pylon,

here is the wiring (some how my images from my google drive didn't show up, i attach the image in the attachment)



here is the code
Code: [Select]
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include "SparkFunMPL3115A2.h"

/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 12, TXPin = 13;
static const uint32_t GPSBaud = 9600;

// repace your wifi username and password
const char* ssid     = "*****";
const char* password = "****";

unsigned long myChannelNumber = *******;
const char * myWriteAPIKey = "********";

// The TinyGPS++ object
TinyGPSPlus gps;
WiFiClient  client;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

MPL3115A2 tier = MPL3115A2();

void setup()
{
  Serial.begin(9600);
  ss.begin(GPSBaud);
  tier.begin();
  tier.setModeAltimeter();
  tier.setOversampleRate(7);
  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println();

  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
   Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Netmask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: ");
  Serial.println(WiFi.gatewayIP());
  ThingSpeak.begin(client);
  
}

void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring./n"));
    Serial.println(F("Couldn't find sensor"));
    while(true);
  }
}

void displayInfo()
{
 // Serial.print(F("Location: "));
  if (gps.location.isValid())
  {

    double latitude = (gps.location.lat());
    double longitude = (gps.location.lng());
    float altm = tier.readAltitude();
    float tempC = tier.readTemp();
    
    String latbuf;
    latbuf += (String(latitude, 6));
    Serial.println(latbuf);

    String lonbuf;
    lonbuf += (String(longitude, 6));
    Serial.println(lonbuf);
    
    String altbuf;
    altbuf += (String(altm, 6));
    Serial.println(altbuf);

    String tmpbuf;
    tmpbuf += (String(tempC, 6));
    Serial.println(tmpbuf);

    ThingSpeak.setField(1, latbuf);
    ThingSpeak.setField(2, lonbuf);
    ThingSpeak.setField(3, tmpbuf);
    ThingSpeak.setField(4, altbuf);
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
    delay(20000);
    
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}


here is the latest output from the code (some how my images from my google drive didn't show up, i attach the image in the attachment)

pylon

Quote
here is the wiring (some how my images from my google drive didn't show up, i attach the image in the attachment)
If you read the "hot to use this forum" you knew that links to google drive are a no-go. Attaching the image is the way to do it.

You didn't understand me:

Quote
when i test the altimeter from the examples
it works with the same wiring
I want to see the code that let the altimeter work with exactly the same hardware setup. As there are several examples and people tend to modify example to let them work with their setup, I want to see all the code mentioned in the posts. So post that example code exactly as it worked for you.

ardi23

If you read the "hot to use this forum" you knew that links to google drive are a no-go. Attaching the image is the way to do it.
i apologize didn't read all oh the tutorial in those thread.

Quote
You didn't understand me:

I want to see the code that let the altimeter work with exactly the same hardware setup. As there are several examples and people tend to modify example to let them work with their setup, I want to see all the code mentioned in the posts. So post that example code exactly as it worked for you.
i am using examples from sparkfun
Code: [Select]
/*
 MPL3115A2 Barometric Pressure Sensor Library Example Code
 By: Nathan Seidle
 SparkFun Electronics
 Date: September 24th, 2013
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 
 Uses the MPL3115A2 library to display the current altitude and temperature
 
 Hardware Connections (Breakoutboard to Arduino):
 -VCC = 3.3V
 -SDA = A4 (use inline 10k resistor if your board is 5V)
 -SCL = A5 (use inline 10k resistor if your board is 5V)
 -INT pins can be left unconnected for this demo
 
 During testing, GPS with 9 satellites reported 5393ft, sensor reported 5360ft (delta of 33ft). Very close!
 During testing, GPS with 8 satellites reported 1031ft, sensor reported 1021ft (delta of 10ft).
 
 Available functions:
 .begin() Gets sensor on the I2C bus.
 .readAltitude() Returns float with meters above sealevel. Ex: 1638.94
 .readAltitudeFt() Returns float with feet above sealevel. Ex: 5376.68
 .readPressure() Returns float with barometric pressure in Pa. Ex: 83351.25
 .readTemp() Returns float with current temperature in Celsius. Ex: 23.37
 .readTempF() Returns float with current temperature in Fahrenheit. Ex: 73.96
 .setModeBarometer() Puts the sensor into Pascal measurement mode.
 .setModeAltimeter() Puts the sensor into altimetery mode.
 .setModeStandy() Puts the sensor into Standby mode. Required when changing CTRL1 register.
 .setModeActive() Start taking measurements!
 .setOversampleRate(byte) Sets the # of samples from 1 to 128. See datasheet.
 .enableEventFlags() Sets the fundamental event flags. Required during setup.
 
 */

#include <Wire.h>
#include "SparkFunMPL3115A2.h"

//Create an instance of the object
MPL3115A2 myPressure;

void setup()
{
  Wire.begin();        // Join i2c bus
  Serial.begin(9600);  // Start serial for output

  myPressure.begin(); // Get sensor online

  //Configure the sensor
  myPressure.setModeAltimeter(); // Measure altitude above sea level in meters
  //myPressure.setModeBarometer(); // Measure pressure in Pascals from 20 to 110 kPa

  myPressure.setOversampleRate(7); // Set Oversample to the recommended 128
  myPressure.enableEventFlags(); // Enable all three pressure and temp event flags
}

void loop()
{
  //float altitude = myPressure.readAltitude();
  //Serial.print("Altitude(m):");
  //Serial.print(altitude, 2);

  float altitude = myPressure.readAltitudeFt();
  Serial.print(" Altitude(ft):");
  Serial.print(altitude, 2);

  //float pressure = myPressure.readPressure();
  //Serial.print("Pressure(Pa):");
  //Serial.print(pressure, 2);

  //float temperature = myPressure.readTemp();
  //Serial.print(" Temp(c):");
  //Serial.print(temperature, 2);

  float temperature = myPressure.readTempF();
  Serial.print(" Temp(f):");
  Serial.print(temperature, 2);

  Serial.println();
}

pylon

If you compare the two codes the Wire.begin() is missing in your code and there is also no tier.enableEventFlags() (although I don't think this is actually needed but recommended in the datasheet).

In current versions of the library the tier.begin() calls Wire.begin() so that cannot be the problem too.

To be sure, try adding the enableEventFlags() call.

So are you completely sure you're trying both sketches with exactly the same hardware setup (not one device or wire removed for one sketch but there for the other)?

ardi23

If you compare the two codes the Wire.begin() is missing in your code and there is also no tier.enableEventFlags() (although I don't think this is actually needed but recommended in the datasheet).

In current versions of the library the tier.begin() calls Wire.begin() so that cannot be the problem too.

To be sure, try adding the enableEventFlags() call.
I'll try after my thesis defence this friday.

thank you for the advice.

Quote
So are you completely sure you're trying both sketches with exactly the same hardware setup (not one device or wire removed for one sketch but there for the other)?
definitely yes

Go Up