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

st599

Well-known member
Joined
9 Jan 2006
Messages
7,241
Visit site
I've just bought a cheap BME280 board and a cheap SD card board - going to see if I can make a logger which also transmits results via NMEA93 and MQTT.

May also try and add some more sensors like an MQ-135 and a light sensor.
 

pagoda

Active member
Joined
19 May 2008
Messages
2,227
Location
Scotland
Visit site
I've just bought a cheap BME280 board and a cheap SD card board - going to see if I can make a logger which also transmits results via NMEA93 and MQTT.

May also try and add some more sensors like an MQ-135 and a light sensor.

Gas sensors like that tend to be quoted at +-65% Relative Humidity. Not often found near the bilges in a boat! Plus points - it runs off 5V.
The BME280 will also give you Humidity . The problem with sensors and Arduino/Teensy/etc platforms is that the SPI and I2C sensor interfaces don't really tolerate distance. Not much of an issue with cabin locations. Other places in vessels are not remotely electronics friendly though.
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,209
Location
Hopefully somewhere warm
Visit site
I am new to Arduino but would like to give this a try

I am a keen 3D printer so will design and print a nice little box once I get the barograph working

TudorSailor

Maybe worth considering going straight for an ESP8266, programs same as an arduino but faster & wifi built in so you could send NMEA straight to Opencpn if you wanted over wifi. Or write your own website to view. Add a few more pennies sensors for battery voltage/engine temperature/current in/out of batteries(if you have a battery monitor shunt fitted already)

Whole load of fun & dead cheap :cool:
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
I've made a thing. It's a very low cost barometric sensor that outputs NMEA 0183 barometric pressure (and temperature) sentences on a USB-serial interface (should be trivial to modify with an actual serial output, if you need that). Plug it into a computer with OpenCPN and you get a barograph (barometric pressure over time). Components should cost under £10 and you only need to solder together 4 wires and do a simple firmware upload. Maybe stick it in a plastic box.

If you're interested, I've written about it here and made the source code and instructions available for free.

Is there an easy way to feed the pressure to an LCD display in addition?

TudorSailor
 
Last edited:

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
I've just bought a cheap BME280 board and a cheap SD card board -.

I have bought a BMP/BME280 sensor and a arduino nano. The sensor only has 4 pins VIN, GND, SCL and SDA
As a newbie to this, could someone tell me what to connect to what (once I have bought some jumper wires since the Arduino Nano has soldered pins.)

Thanks

TudorSailor
 

Martin_J

Well-known member
Joined
19 Apr 2006
Messages
4,258
Location
Portsmouth, UK
Visit site
With SCL (Clock) and SDA (Data) it looks like you have the I2C version as opposed to the SPI version.

Look at a page like this you will see the connectivity...

adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout

I also just found another clear diagram here that shows the bus architecture better.. All devices have their clock lines connected together and all devices have their SDA (data) lines connected together.

https://publiclab.org/notes/cfastie/04-25-2017/inexpensive-data-logging

To clarify that it needs to go to pins A4 and A5 on the Nano you could to go to the Arduino Nano page here...

https://store.arduino.cc/arduino-nano

but if you search the web for Arduino Nano Pinout then you'll find easier to read diagrams like this..

https://components101.com/sites/default/files/component_pin/Arduino-Nano-Pinout.png

As you can see, part way up the right hand side pins A4 and A5, also known as 27/28 but they also have pale blue boxes labelled SCL and SDA next to them.
 

Martin_J

Well-known member
Joined
19 Apr 2006
Messages
4,258
Location
Portsmouth, UK
Visit site

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
Many thanks Martin_J I think I need to do a course on Arduinos. I am only just getting to grips with other new skills such as CAD design and now programming! Oh well, it will occupy the winter till sailing again
Leads ordered so will see how I get on
TudorSailor
 

Martin_J

Well-known member
Joined
19 Apr 2006
Messages
4,258
Location
Portsmouth, UK
Visit site
Even before you get the sensor and jump leads connected, it's worthwhile trying out the Arduino software and proving that you can actually get code onto the Nano itself.

Have a few goes at the example 'Blink' program first, change the delays so you know it's got to the Nano and use the onboard LED (pin13) to make things easy since you'll not have to have anything more connected than the microUSB cable.
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
Even before you get the sensor and jump leads connected, it's worthwhile trying out the Arduino software and proving that you can actually get code onto the Nano itself.

Have a few goes at the example 'Blink' program first, change the delays so you know it's got to the Nano and use the onboard LED (pin13) to make things easy since you'll not have to have anything more connected than the microUSB cable.

Success - eventually. Needed to select the correct processor in order to get the modified sketch to upload, but have done this several times now!
I am waiting for jumper leads to arrive in order to connect the sensor and am prepared for the steep learning curve

I will connect VIN to VIN, GND to GND, SCL to A5 and SDA to A4

The instructions on GitHub state:
Program nanobar.ino onto your Nano. You will need the Wire (I²C) library included with the Arduino package as well as the SFE_BMP180 library from Sparkfun.

I now understand that I will copy and past nanobar.ino into the sketch program.

So now can I ask what it means when it says i need the Wire (I2C) library and the SFE_BMP180 library? I have a BMP280 so I assume that i need the BMP280 library https://github.com/adafruit/Adafruit_BMP280_Library

If there is someone that explains this, please point me in the right direction.

Thanks


TudorSailor
 
Last edited:

pagoda

Active member
Joined
19 May 2008
Messages
2,227
Location
Scotland
Visit site
Success - eventually. Needed to select the correct processor in order to get the modified sketch to upload, but have done this several times now!
I am waiting for jumper leads to arrive in order to connect the sensor and am prepared for the steep learning curve

I will connect VIN to VIN, GND to GND, SCL to A5 and SDA to A4

The instructions on GitHub state:
Program nanobar.ino onto your Nano. You will need the Wire (I²C) library included with the Arduino package as well as the SFE_BMP180 library from Sparkfun.

I now understand that I will copy and past nanobar.ino into the sketch program.

So now can I ask what it means when it says i need the Wire (I2C) library and the SFE_BMP180 library? I have a BMP280 so I assume that i need the BMP280 library https://github.com/adafruit/Adafruit_BMP280_Library

If there is someone that explains this, please point me in the right direction.

Thanks


TudorSailor

The Adafruit library works fine with the BMP 280. It's aimed at the BME 280 but you can ignore the calls for humidity values. Be aware that neither the I2C nor the SPI interfaces are good at any distance. They are really designed for multiple sensors on the board with the CPU involved. SPI in particular -with individual CS (Chip Select) lines has capacity for multiple devices. I2C is limited by what addresses the designers allow for.
That said, both are handy. If you need to run slightly longer wires (30cm +) think about twisted pairs and screening.
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
Success - eventually. Needed to select the correct processor in order to get the modified sketch to upload, but have done this several times now!
I am waiting for jumper leads to arrive in order to connect the sensor and am prepared for the steep learning curve

I will connect VIN to VIN, GND to GND, SCL to A5 and SDA to A4

The instructions on GitHub state:
Program nanobar.ino onto your Nano. You will need the Wire (I²C) library included with the Arduino package as well as the SFE_BMP180 library from Sparkfun.

I now understand that I will copy and past nanobar.ino into the sketch program.

So now can I ask what it means when it says i need the Wire (I2C) library and the SFE_BMP180 library? I have a BMP280 so I assume that i need the BMP280 library https://github.com/adafruit/Adafruit_BMP280_Library

If there is someone that explains this, please point me in the right direction.

Thanks


TudorSailor

So with the help of youtube I have installed the two libraries. For anyone else going down this route, this is what I did

I connected the nano. In the Sketch program went to sketch/include library/manage libraries and then found the two libraries. I clicked on install and they seem to go to the right place

When I went back to library manager and select "installed" they both seem to be installed

Next thing is actually connect the sensor once the jumpers (wires) arrive

Tudorsailor
 

Martin_J

Well-known member
Joined
19 Apr 2006
Messages
4,258
Location
Portsmouth, UK
Visit site
Sounds like you're doing well so far... I'm writing from my phone just just a brief reply

Looks like you have worked out the library manager. Sometimes though you will find libraries zipped up in places like Github. In that case you will have to import a different way. The second explanation at the link below describes the prices nicely.

https://www.digikey.co.uk/en/maker/blogs/2018/how-to-install-arduino-libraries

Also, remember that if you're downloading .ino files then either look for the 'raw' download link or just copy and paste the the text onto your own pc.
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,736
Location
London
zebahdy.blogspot.co.uk
I copied and pasted the code into sketch from Github
I changed the library from the BMP180 to the ADafruit BMP280 that I hope is correct for the BMP280 that I bought
There is already a line that says #include <WIre.h> so I hope that this right wire library

Of course it does not run as I have probably put the code text in the wrong place relative to the brackets
I get the error "Error compiling for board Arduino Nano"

Here is the code. Is my error obvious?

void setup() {
// put your setup code here, to run once:
#include <Adafruit_BMP280.h>
#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_BMP280 pressure;

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


void loop() {
// put your main code here, to run repeatedly:

Serial.begin(4800);

if (init_pressure() != true) {
nmea_txt("BMP280 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);
}
}
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,759
Location
London / Suffolk
freewheeling.world
Looking at the code for the adafruit library, it's not going to be a simple matter to swap to the BMP280 as the function names in the class are completely different to the 180.
For example, the 180 it triggers the startTemperature function and waits for the status to return to the get the temperature. The 280 just has a readTemparture function.
Without playing around with the hardware, I don't know if it's an easy swap on the code.
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,759
Location
London / Suffolk
freewheeling.world
OK.. I've hacked it about a bit. I don't know if this will work as I don't have the hardware to test at hand.
Give it try !

Code:
#include <Adafruit_BMP280.h>
#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

Adafruit_BMP280 pressure;


void setup() {
  // put your setup code here, to run once:

  Serial.begin(4800);

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

  
}

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


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);
}



void loop() {
  String s;
  float temp, press;
    
  temp = pressure.readTemperature();
  press = pressure.readPressure();
  
  
      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");
    
  

  delay(NMEA_DELAY * 1000);
}
 
Top