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

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,737
Location
London
zebahdy.blogspot.co.uk
So have been googling to try and work out why the sensor data is not coming through.
I found a thread that said the the I2C address might be incorrect. So I ran an I2C scanner and it returns the message (only at 9600 baud)
I2C device found at address 0x76 !
done

So I think that the sensor is there. I cannot see any code that refers to 0x76 so maybe not the problem

I have then read that not all BMP280 sensors are the same! I have a sensor that is BMP/BME280. I am unsure how one identifies the manufacturer and of course it was an eBay purchase so Chinese. I did install a BME280 library and changed the code in the sketch to refer to BME280 rather than BMP280. Is it worth installing every BMP280 library in turn and altering the sketch appropriately to find a library that works?

Finally, I found a sketch that tests BMP280 sensors. I have run this and the serial message is

Adafruit BMP280 test:
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m
Pressure: 0.00 Pa Temp: 0.00 oC Altimeter: -21206 m


Of course maybe I should admit defeat and recognise that the nanobaro project was not as straightforward as the OP suggested

TudorSailor
 
Last edited:

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,737
Location
London
zebahdy.blogspot.co.uk
I think the library by default is looking at 0x77 not 0x76.

Change line 34 to:

if (!pressure.begin(0x76) ) {

Regards

David

Ah ha! I had looked for the term (0x77) and not found it. I did not realiset the brackets were empty. Now I have changed to 0x76 the output seems to workCapture3.JPG
I closed IDE to release the port but the pressure does not show in OpenCPN. I shut down and restarted to make sure the COM5 was free for OpenCPN, but still not pressure in OpenCPN. Is there a way to force the COM5 to be free for OpenCPN to use?

Nearly there!

Thanks for the support.

TudorSailor
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,757
Location
London / Suffolk
freewheeling.world
Ah ha! I had looked for the term (0x77) and not found it. I did not realiset the brackets were empty. Now I have changed to 0x76 the output seems to workView attachment 74246
I closed IDE to release the port but the pressure does not show in OpenCPN. I shut down and restarted to make sure the COM5 was free for OpenCPN, but still not pressure in OpenCPN. Is there a way to force the COM5 to be free for OpenCPN to use?

Nearly there!

Thanks for the support.

TudorSailor

Yayyy and Woooooo it's working :encouragement:

By default it uses 0x77 when you call the begin function with no parameters, but by passing 0x76 as an argument to the begin function it overrides the default and uses that address.

I'm not sure about Open CPN unfortunately as I've only spun it up on a Raspberry Pi for testing. Hopefully GHA or someone else can help with that.
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,169
Location
Hopefully somewhere warm
Visit site
Ah ha! I had looked for the term (0x77) and not found it. I did not realiset the brackets were empty. Now I have changed to 0x76 the output seems to workView attachment 74246
I closed IDE to release the port but the pressure does not show in OpenCPN. I shut down and restarted to make sure the COM5 was free for OpenCPN, but still not pressure in OpenCPN. Is there a way to force the COM5 to be free for OpenCPN to use?

Nearly there!

Thanks for the support.

TudorSailor

In Opencpn try going into options|connections and click show NMEA debug window, you should see the sentences coming in there.

Just tried one of your sentences, dash will display the temperature but doesn't like the pressure, units are wrong "101.23367" needs to be "1.0123367".

So in ....
Code:
[/FONT][/COLOR][COLOR=#333333]// Calculate absolute pressure in mbars.[/COLOR]
[COLOR=#333333]pu = (byteHigh * 256.0) + byteMid + (byteLow/256.0);[/COLOR]

[COLOR=#333333]s = T - 25.0;[/COLOR]
[COLOR=#333333]x = (xx2 * pow(s,2)) + (xx1 * s) + xx0;[/COLOR]
[COLOR=#333333]y = (yy2 * pow(s,2)) + (yy1 * s) + yy0;[/COLOR]
[COLOR=#333333]z = (pu - x) / y;[/COLOR]
[COLOR=#333333]P = (p2 * pow(z,2)) + (p1 * z) + p0;[/COLOR]

[COLOR=#333333]return(P);[/COLOR]
[COLOR=#333333]}[/COLOR][COLOR=#000000][FONT='inherit']
... try adding "P = P/100;" (No quote marks of course) between "P=..." and "return(P); "
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,757
Location
London / Suffolk
freewheeling.world
In Opencpn try going into options|connections and click show NMEA debug window, you should see the sentences coming in there.

Just tried one of your sentences, dash will display the temperature but doesn't like the pressure, units are wrong "[FONT=&]101.23367" needs to be "1.0123367".

So in ....
Code:
[/FONT][/COLOR][COLOR=#333333]// Calculate absolute pressure in mbars.[/COLOR]
[COLOR=#333333]pu = (byteHigh * 256.0) + byteMid + (byteLow/256.0);[/COLOR]

[COLOR=#333333]s = T - 25.0;[/COLOR]
[COLOR=#333333]x = (xx2 * pow(s,2)) + (xx1 * s) + xx0;[/COLOR]
[COLOR=#333333]y = (yy2 * pow(s,2)) + (yy1 * s) + yy0;[/COLOR]
[COLOR=#333333]z = (pu - x) / y;[/COLOR]
[COLOR=#333333]P = (p2 * pow(z,2)) + (p1 * z) + p0;[/COLOR]

[COLOR=#333333]return(P);[/COLOR]
[COLOR=#333333]}[/COLOR][COLOR=#000000][FONT=&]
... try adding "P = P/100;" (No quote marks of course) between "P=..." and "return(P); "[/FONT]

Hi GHA

This is the code he's using:
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")

I also thought the pressure figure looked weird on the screenshot.
As you can see, it's already being divided by 1000, so needs to be divided by 100,000?

Tudor, change the above to
s += ",P," + String(press / 100000.0, 5) + ",B,BARO"; // OpenCPN doesn't seem to grok Pascal (unit "P"), only Bar ("B")
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,169
Location
Hopefully somewhere warm
Visit site
Hi GHA

This is the code he's using:
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")

I also thought the pressure figure looked weird on the screenshot.
As you can see, it's already being divided by 1000, so needs to be divided by 100,000?

Tudor, change the above to
s += ",P," + String(press / 100000.0, 5) + ",B,BARO"; // OpenCPN doesn't seem to grok Pascal (unit "P"), only Bar ("B")

:encouragement:

I was looking at the other code.

Also, Tudor - the logbook plugin automatically inserts temperature and pressure into a log entry if it sees this data when you make a new entry. :cool:
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,737
Location
London
zebahdy.blogspot.co.uk
OMG! I now have pressure displayed in OpenCPN.

Capture4.JPG

I must thank all of you who have helped me. I will now try and summarise the steps so that another dummy might achieve the same result without calling on you all. I think that I will make it a separate new post

Now I will go to Thingiverse to find a nice .stl of an enclosure for the Arduino nano which I can print on my 3D printer

I may also research how to display the pressure on an LCD from the Nanobaro.

I also have a new AIS receiver that is USB powered to put AIS into OpenCPN. Then I should be all set!

Thanks again. If any of you are in the Ionian next summer, I will buy you a beer!

TudorSailor
 

dolabriform

Well-known member
Joined
12 Sep 2016
Messages
1,757
Location
London / Suffolk
freewheeling.world
OMG! I now have pressure displayed in OpenCPN.

View attachment 74257

I must thank all of you who have helped me. I will now try and summarise the steps so that another dummy might achieve the same result without calling on you all. I think that I will make it a separate new post

Now I will go to Thingiverse to find a nice .stl of an enclosure for the Arduino nano which I can print on my 3D printer

I may also research how to display the pressure on an LCD from the Nanobaro.

I also have a new AIS receiver that is USB powered to put AIS into OpenCPN. Then I should be all set!

Thanks again. If any of you are in the Ionian next summer, I will buy you a beer!

TudorSailor

Fantastic :encouragement:

I've updated the code on Github with the changes.

I'll try and add some info later about adding an LCD :)
 
Last edited:

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,169
Location
Hopefully somewhere warm
Visit site
OMG! I now have pressure displayed in OpenCPN.

>
>
I may also research how to display the pressure on an LCD from the Nanobaro.


YAY!!!!

You can get an ESP8266 which will run the (almost) same code with a screen for not much more than a beer in London :cool: ...

https://www.ebay.co.uk/itm/WeMos-ES...623876&hash=item33e8e5877c:g:07gAAOSwG4xa4vh-

Then as you're now a hard core programming wizard write a little code so the esp creates a wifi network and makes a web page with your barometer history.. :)
 

Martin_J

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

You can get an ESP8266 which will run the (almost) same code with a screen for not much more than a beer in London :cool: ...

https://www.ebay.co.uk/itm/WeMos-ES...623876&hash=item33e8e5877c:g:07gAAOSwG4xa4vh-

Then as you're now a hard core programming wizard write a little code so the esp creates a wifi network and makes a web page with your barometer history.. :)


Then look into sending it out as NMEA2000 for the future...

I just wish I had more time...

I've got fuel level, cabin temperature and barometric pressure out onto NMEA2000 now but I'm still finding new instruments that have needed different PGNs for the temperature... All good fun!
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,169
Location
Hopefully somewhere warm
Visit site
Then look into sending it out as NMEA2000 for the future...

I just wish I had more time...

I've got fuel level, cabin temperature and barometric pressure out onto NMEA2000 now but I'm still finding new instruments that have needed different PGNs for the temperature... All good fun!

All good fun! :cool:

ESP32 already has a can bus built in so a few quid to get at NMEA2000 >>
https://github.com/ttlappalainen/NMEA2000_esp32

No nmea 2K here, signalk all the way onboard. And just making a start at capacitive touch sensor (also built in to esp32) . So hopefully damp fingers will turn the volume up and down on the hifi amp equipped raspberry pi. Wires getting fewer, wifi all the way. :encouragement:

Amazing just how powerful all these little microprocessors are that those nice Chinese sell for pennies!
 

Martin_J

Well-known member
Joined
19 Apr 2006
Messages
4,247
Location
Portsmouth, UK
Visit site
OMG! I now have pressure displayed in OpenCPN.

View attachment 74257

I must thank all of you who have helped me. I will now try and summarise the steps so that another dummy might achieve the same result without calling on you all. I think that I will make it a separate new post

Now I will go to Thingiverse to find a nice .stl of an enclosure for the Arduino nano which I can print on my 3D printer

I may also research how to display the pressure on an LCD from the Nanobaro.

I also have a new AIS receiver that is USB powered to put AIS into OpenCPN. Then I should be all set!

Thanks again. If any of you are in the Ionian next summer, I will buy you a beer!

TudorSailor

Well done.....
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,737
Location
London
zebahdy.blogspot.co.uk
So for someone else trying to do this here are the steps

I bought a Arduino Nano, a BMP280 sensor and a mix of “jumper wires”

The sensor I bought did not have the header soldered into the holes (these are the vertical pins). A header is easier for connecting and disconnecting the jumper wires, so a friend did a neat solder job.

Connect VIN to VIN, GND to GND, SCL to A5 and SDA to A4

On the PC download the software used to upload code onto the Arduino. The program is IDE and can be downloaded from https://www.arduino.cc/en/Main/Software

Once the Arduino is plugged into the USB you need to work out which processor is on the Chinese Nano so that you can upload code. So in IDE go to tools/board/board manager and select Arduino nano.

Then go to tools/processor and select one. Test the selection by trying to upload the code to change the blink rate of the little LED on the board. So file/examples/0.1 basics/ blink This loads the code into the sketch. In the menu toolbar the rght arrow is used to upload code. If you click it and the code uploads, then the processor is correct. If it does not, change the processor to find one that allows you to upload blink. You can prove that blink works by altering the line of code that has the time for which the LED is illuminated in milliseconds

You need to install the Wire (I2C) library, Adafruit_BMP280_Library and the Adafruit Sensor library

In the Sketch program go to sketch/include library/manage libraries and then find the three libraries. Click on install for each
Go back to library manager and select "installed" to see if all three are installed

Then copy this the code for the nanobaro from Github https://github.com/dolabriform/nanobaro_bmp280

On the IDE click on the tick to see if the code compiles properly. If it does save the file of code!

When I tried to run the code I had errors. So to test the messages would go to OpenCPN, I loaded this code into a sketch and then uploaded it to the Nano.
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);

In the IDE program there is a magnifying glass at the top right. If you click on this you can see data coming from the board. If the board is sending data it will show in the window. You may need to change the baud rate to either 4800 or 9600 (I cannot remember which).

Once the Serial monitor in IDE shows a stream of data in IDE. Close all iterations of IDE so that the serial port is free for OpenCPN.

Upload the latest version of OpenCPN. Activate the dashboard plug in and then used preferences so that it shows barometric pressure.

Now try the nanobaro code that you saved. If it does have data in the serial monitor but it does not show in OpenCpn, the I2C address may be incorrect – it was for me. So I downloaded an I2C scanner from gitbub https://gist.github.com/tfeldmann/5411375 Turns out that the nanobaro looks for something at 0x77 and my I2C device was at 0x76
So in the Nanobaro sketch I needed to go to line 34. It had a pair of empty brackets and I had to change the line to “if (!pressure.begin(0x76) ) {“ without the quotation marks This may now not be necessary as dolabriform has modified the code.

Hopefully now this is all done, pressure will come through to OpenCPN


TudorSailor
 

tudorsailor

Well-known member
Joined
12 Jun 2005
Messages
2,737
Location
London
zebahdy.blogspot.co.uk
Hi David

I downloaded the new sketch and then ran the compiler. I got the error LCD.h: No such file or directory

I cannot find LCD.h in the library and apparently it is part of the liquid crystal library. I tried installing a different Liquidcrystal I2C library but that does not help. To avoid confusion I uninstalled the new library.
Do I need to load the LCD library separately?

Capture5.JPG

Thanks

TS
 
Last edited:

gregcope

Well-known member
Joined
21 Aug 2004
Messages
1,590
Visit site
LCD.h is a header file, which defines some code. It usually always includes another .c or .cpp or other file that has the actual code.

Collectively they are essentially a library that defines a package of code.

You need to know which LCD.h the original author intended to use.

Then download that and then put it somewhere where you IDE/Complier will find it.
 

GHA

Well-known member
Joined
26 Jun 2013
Messages
12,169
Location
Hopefully somewhere warm
Visit site
Those LEDs can sometimes be a bit of a run around to get working as there are so many slightly different designs, might be best just to get an example from the library working first then paste it into the main sketch.

Think this sketch worked for the last coupe I got off ebay - just check it's an I2C screen, much easier wiring.

Code:
/* YourDuino.com Example Software Sketch
 16 character 2 line I2C Display
 Backpack Interface labelled "A0 A1 A2" at lower right.
 ..and
 Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
 MOST use address 0x27, a FEW use 0x3F
 terry@yourduino.com */


/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here:
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.


#include <LiquidCrystal_I2C.h>


/*-----( Declare Constants )-----*/
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 16 chars 2 line display
// A FEW use address 0x3F
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


/*-----( Declare Variables )-----*/
//NONE


void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);  // Used to type in characters


  lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight


// ------- Quick 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
  }
  lcd.backlight(); // finish with backlight on  


//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0  
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("Hello, world!");
  delay(1000);
  lcd.setCursor(0,2);
  lcd.print("HI!YourDuino.com");
  delay(8000);  


// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Use Serial Mon");
  lcd.setCursor(0,1);
  lcd.print("Type to display");  




}/*--(end setup )---*/




void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  {
    // when characters arrive over the serial port...
    if (Serial.available()) {
      // wait a bit for the entire message to arrive
      delay(100);
      // clear the screen
      lcd.clear();
      // read all the available characters
      while (Serial.available() > 0) {
        // display each character to the LCD
        lcd.write(Serial.read());
      }
    }
  }


}/* --(end main loop )-- */




/* ( THE END ) */
 

Members online

No members online now.
Top