Nanobaro - NMEA/USB barometric sensor, easy DIY electronics project

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
Many thanks for taking the time. I realise that I am trying to shortcut the learning process
Is there a trick to copy and paste the code. When I copy the code in the post, it pastes without line breaks. I can add them but I am sure there is a trick that I am missing

TD
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,803
Location
Kent
freewheeling.world
Many thanks for taking the time. I realise that I am trying to shortcut the learning process
Is there a trick to copy and paste the code. When I copy the code in the post, it pastes without line breaks. I can add them but I am sure there is a trick that I am missing

TD

Weird, I hadn't noticed that before:
I've put it on github:
https://github.com/dolabriform/nanobaro_bmp280
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,416
Location
Hopefully somewhere warm
Visit site
Hi means copying it out of thread into an editor on the computer. I get the same problem which is why I stuck it in github.

Ah, indeed. No problems on a win10 machine copying from inside
Code:
 tags and pasting into the arduino IDE. 

And if anyone hasn't found it, ctrl "t" in the IDE autoformats the code.
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
So now have both components and have header soldered onto the little sensor
I downloaded the code into IDE. I have installed the adafruit BMP 280 from the library
The compiler gives me an error that I not understand of course
Rather than overload the window I have copied the long error message into the attached document

Is it blindingly obvious where I am going wrong?

Thanks

TudorSailor
 

Attachments

  • Arduino error.pdf
    9.5 KB · Views: 0

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,803
Location
Kent
freewheeling.world
So now have both components and have header soldered onto the little sensor
I downloaded the code into IDE. I have installed the adafruit BMP 280 from the library
The compiler gives me an error that I not understand of course
Rather than overload the window I have copied the long error message into the attached document

Is it blindingly obvious where I am going wrong?

Thanks

TudorSailor

Here's the problem:

Adafruit_BMP280.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

You need to install the Adafruit Sensor library :)

Regards

David
 

gregcope

Well-known member
Joined
21 Aug 2004
Messages
1,615
Visit site
Have you downloaded the Adafruit Sensor lib?

One of the last error lines is;

Adafruit_BMP280.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
Have you downloaded the Adafruit Sensor lib?

One of the last error lines is;

Adafruit_BMP280.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

Having looked at the test for the BMP, I saw that I needed the Sensor Library. I downloaded that and then read your replies. I have run the code again and there is no error! I have now uploaded the code with no errors, so now off the OpenCPN.....

Thanks

TudorSailor
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,416
Location
Hopefully somewhere warm
Visit site
Having looked at the test for the BMP, I saw that I needed the Sensor Library. I downloaded that and then read your replies. I have run the code again and there is no error! I have now uploaded the code with no errors, so now off the OpenCPN.....

If you click the little magnifying glass top right of the arduino IDE you should see the lovely NMEA messages in a serial monitor :cool:
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
I knew this was too good to be true. There does not seem to be data getting from the Arduino to the PC. In order to check I used IDE/tools/serial monitor and it says "error opening serial port (port busy). I have been to device manager and set the baud rate to 4800, I have left the rest of the settings alone data bits 8, parity none, stop bits 1, flow control none

Thanks

TS
 

pagoda

Active member
Joined
19 May 2008
Messages
2,227
Location
Scotland
Visit site
If you click the little magnifying glass top right of the arduino IDE you should see the lovely NMEA messages in a serial monitor :cool:

Even better if you use "Actisense NMEA Reader" and feed it your NMEA serial output from your Arduino/ BMP 280 you can decode the NMEA words. Or just look at the raw serial output as suggested.
 

pagoda

Active member
Joined
19 May 2008
Messages
2,227
Location
Scotland
Visit site
I knew this was too good to be true. There does not seem to be data getting from the Arduino to the PC. In order to check I used IDE/tools/serial monitor and it says "error opening serial port (port busy). I have been to device manager and set the baud rate to 4800, I have left the rest of the settings alone data bits 8, parity none, stop bits 1, flow control none

Thanks

TS

Only NMEA 0183 expects to run at 4800Baud. If you want to test transmission, pretty much any baud rate will work as long as the PC end is using the same speed.
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,416
Location
Hopefully somewhere warm
Visit site
I knew this was too good to be true. There does not seem to be data getting from the Arduino to the PC. In order to check I used IDE/tools/serial monitor and it says "error opening serial port (port busy). I have been to device manager and set the baud rate to 4800, I have left the rest of the settings alone data bits 8, parity none, stop bits 1, flow control none

Thanks

TS

Is it the code from Yngmar you're using? If so, if it loaded onto the arduino OK then the computer must be talking to it. Just make sure only one program is talking to the nano over serial at the same time.
You shouldn't need to do anything to the virtual port in the device manager, just set the baud rate on whatever is doing the looking like Opencpn or the arduino IDE.




Code:
[COLOR=#000000]#include <SFE_BMP180.h>[/COLOR]#include <Wire.h>

#define NMEA_TALKER_ID "WI" // Weather Instruments
#define NMEA_DELAY 10 // Send data every 10 seconds

// meters above mean sea level
#define ALTITUDE 1
// How many samples to take per iteration
#define PRESS_OVERSAMPLING 3


SFE_BMP180 pressure;

int init_pressure() {
  if (pressure.begin()) return true;
}

void setup() {
  Serial.begin(4800);

  if (init_pressure() != true) {
    nmea_txt("BMP180 init fail");
    exit(1);
  }
  nmea_txt("Nanobaro ready.");
}

int get_temperature(double &temp) {
  int status;

  status = pressure.startTemperature();
  if (status) {
    // Wait for the measurement to complete:
    delay(status); // Typically 5ms
    status = pressure.getTemperature(temp);
    if (status) return true;
  }
  return false;
}

int get_pressure(double &press, double &temp) {
  int status;

  status = pressure.startPressure(PRESS_OVERSAMPLING);
  if (status) {
    // Wait for the measurement to complete:
    delay(status); // Typically 26 at oversampling 3 in startPressure
    status = pressure.getPressure(press, temp);
    if (status) return true;
  }
  return false;
}

const byte buff_len = 90;
char CRCbuffer[buff_len];

byte nmea_crc(String msg) {
  // NMEA CRC: XOR each byte with previous for all chars between '$' and '*'
  char c;
  int i;
  byte crc = 0;
  for (i = 0; i < buff_len; i++){
    crc ^= msg.charAt(i);  // XOR
  }
  return crc;
}

void nmea_send(String sentence, String params) {
  String msg = String(NMEA_TALKER_ID) + sentence + params;

  msg.toCharArray(CRCbuffer, sizeof(CRCbuffer)); // put complete string into CRCbuffer
  int crc = nmea_crc(CRCbuffer);

  if (crc < 16) msg += "0"; // pad with leading 0
  String hexcrc = String(crc, HEX);
  hexcrc.toUpperCase();
  Serial.println("$" + msg + "*" + hexcrc);
}

void nmea_txt(String text) {
  nmea_send("TXT", ",01,01,01," + text);
}

String s;
double temp, press, seapress;

void loop() {
  if (!get_temperature(temp)) {
    nmea_txt("Temperature read failure");
    temp = -1000.0;
  }

  if (temp > -1000.0) {
    if (get_pressure(press, temp)) {
      seapress = pressure.sealevel(press, ALTITUDE);
      s = "";
      s = ",C," + String(temp)  + ",C,TEMP";
      s += ",P," + String(press / 1000.0, 5) + ",B,BARO"; // OpenCPN doesn't seem to grok Pascal (unit "P"), only Bar ("B")
      nmea_send("XDR", s);
      // These NMEA 0183 sentences are deprecated:
      //nmea_send("MTA", "," + String(temp) + ",C");
      //nmea_send("MMB", ",0.0,I,1.5,B");
    } else {
      nmea_txt("Pressure read failure");
      seapress = 0.0;
    }
  }

  delay(NMEA_DELAY*1000); [COLOR=#000000]}[/COLOR]
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,416
Location
Hopefully somewhere warm
Visit site
If you want some easir code just to see some messages on opencpn try this (works, just tried it), sends an NMEA once a second >

Code:
void setup() {  // put your setup code here, to run once:
 Serial.begin(4800);
}


void loop() {
  // put your main code here, to run repeatedly:
Serial.println("$OSXDR,P,1.0143,B,AIRP,C,18.9,C,AIRT*43");
delay(1000);
}
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,803
Location
Kent
freewheeling.world
If you want some easir code just to see some messages on opencpn try this (works, just tried it), sends an NMEA once a second >

Code:
void setup() {  // put your setup code here, to run once:
 Serial.begin(4800);
}


void loop() {
  // put your main code here, to run repeatedly:
Serial.println("$OSXDR,P,1.0143,B,AIRP,C,18.9,C,AIRT*43");
delay(1000);
}

I suspect tudor is using the hack I put on Github (which as I said I haven't tested ) for the BMP280. see post #62.
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
I suspect tudor is using the hack I put on Github (which as I said I haven't tested ) for the BMP280. see post #62.

Thanks everyone! Yes I am using the code put on Github
I unplugged and turned off the laptop and rebooted. Now the arduino does not throw the COM5 connection error
The serial monitor in IDE immediately gives a few characters but not the continuous flow that I expected.
Capture1.JPG

I loaded Mintaker commander to see if the pressure is displayed and it gives the message of no device found.

Any thoughts?

TudorSailor
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,752
Location
London
zebahdy.blogspot.co.uk
One thing at a time! :)
Upload the code from message 75 and see if you can get data streaming with some simple code first .

Success, of sorts. I still cannot copy and paste code from the forum post directly. However as it was only two lines, easy to format. I will spell out what I did for anyone else following this thread

Serial monitor in IDE shows a stream of data in IDE. I then remembered to exit all iterations of IDE so that the serial port was free for OpenCPN

I uploaded the latest version of OpenCPN. I activated the dashboard plug in and then used preferences so that it showed barometric pressure. Now it does!

I have not moved to work out how to get a graph of the pressure which is my ultimate aim. I have tried to show the test pressure in MintakerCommander software but it does not see the COM5 input. So still on the learning curve

So I have proved that the arduino can send the right messages to the PC. Could the pressure module be faulty??

Thanks

TudorSailor
 
Last edited:

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,416
Location
Hopefully somewhere warm
Visit site
Success, of sorts. I still cannot copy and paste code from the forum post directly. However as it was only two lines, easy to format. I will spell out what I did for anyone else following this thread

Cut n paste orks OK here, paste in the code into aruido IDE then press CTRL - t which asks the IDE to autoformat the code.


I have not moved to work out how to get a graph of the pressure which is my ultimate aim.

In dashboard preferences in Opencpn, add barometer history.
 
Top