Cosa: An Object-Oriented Platform for Arduino programming

@kowalski

Great answers as always :smiley:
Seems there is some work left with the nRF24L01+ networking then but nice to hear that it seems to be in the near future of your pipeline.
Another thing that would be awesome is to have dynamic mesh network support for nRF24L01+. That would make the RFM69W harder to motivate since I'm currently purchasing them for $7 and a nRF24 module can be had for $1.2 on ebay and with a mesh you can extend the range of nRF24 by just adding a few nodes where needed.

Regarding RF433 I have had the feeling that nRF24 is more reliable and has slightly better range (without testing myself). And since they cost the same ($1.2) on ebay I just never ordered any RF433. Also the nRF24 doesn't need two whip antennas..

I'm all for cheap hardware but when you can get a Arduino Pro Mini for $3.75 on ebay it almost seems like a bit of a waste of time to try and make all of Cosa work on a ATtiny..

Also I feel that you almost always want do to some processing of data in a local PC so ethernet/wifi nodes seem a little unnecessary (since you might aswell just plug in a nRF24 node via USB to that PC server), but maybe that's just me :slight_smile:

I hope wireless programming, reliable communication and mesh networking become a reality for nRF24 soon! Keep up the good work!

englund:
Great answers as always :smiley:

Seems there is some work left with the nRF24L01+ networking then but nice to hear that it seems to be in the near future of your pipeline.
Another thing that would be awesome is to have dynamic mesh network support for nRF24L01+.

@englund

Thanks but is was mostly CMA as the NRF24L01+ support is very basic right now. About the same level as other libraries out there. What is maybe new is the addressing in a UDP-style with 32b address and 16b port and the "socket" mapping to the chip pipes.

The dynamic mesh support is somewhat more work ;-). Would need to understand more of the use cases before considering it as I guess it should be "dynamic" with a minimum of configuration. That would mean dynamic routing tables. And package queuing which sounds like memory. With only 2 K byte on a ATmega328 this could be a problem depending on the amount of traffic you would like to route. Restricting routing to a ATmega2560 with 8K byte might be the road to go.

englund:
Regarding RF433 I have had the feeling that nRF24 is more reliable and has slightly better range (without testing myself). And since they cost the same ($1.2) on ebay I just never ordered any RF433. Also the nRF24 doesn't need two whip antennas..

I'm all for cheap hardware but when you can get a Arduino Pro Mini for $3.75 on ebay it almost seems like a bit of a waste of time to try and make all of Cosa work on a ATtiny..

Thought you have a few RF433's to test the NEXA stuff? Anyway you are completely right on the price/cost of hardware. The Arduino Pro Mini's are perfect for a wide range of small scale applications. One would need to procedure a fair number of custom boards with ATtiny before motivating that. But then it would be nice to have to software platform to be able to do that when needed.

Back to the RF433. The fun here is the "low level". It is basically a transmitter and the whole protocol is done in software. That is an interesting challenge and it gives the possibility to play around with a number of abstraction layers at the same time.

But you are totally right when it comes to cost, etc. The NRF24L01+ module is very difficult to compete with.

Cheers!

I am exploring the CosaVWIPClient & Server examples.

Currently, the example just sends some messages from the client and they are received and acknowledged by the server. What I wish to do is to be able to send the messages back to the client from the server on receiving some message from client. How to do it using trx ?

Any help on this topic please, I think may be I haven't quite understood how this system works...

Thanks,
Saumik

@saumik

A reply from sunny Sirmone on the Garda Lake.

You can achieve what you are asking for by combinding the client and server example. More efficient is to introduce separate queues for the transmitter and receiver. Right now the support is tuned towards sensor networks which is a special case.

I will see if I can put together an example more in line with what you are looking for when I am back in Sweden next week.

Cheers!

@kowalski

Thanks for the reply and the help! Must admit that you are really doing a great job with Cosa!

Actually what I am trying to do is to make a wireless quiz buzzer system. I need to identify who has hit the buzzer first. The problem with using just the simple client-server example is that when two or more buzzers (clients) send their messages together, I either get a bad checksum or bad address or sometimes the ACK from the server gets lost. There is no means to do a CSMA/CD or something similar since these are normal RF modules (433 MHz ones).

So, I am planning to move onto a polling based method where the server polls each client for a 'hit' and the clients one by one send the timestamp of the hit. Also, a periodic time sync message would be sent by the server to all clients. I am doing all this to simply avoid transmission at the same time by two or more entities.

Is there any other easy way out or a faster and more accurate method than this one ? Will the nRFL01+ modules help ? I don't want to use XBee for such a simple and low budget project. What should I do to achieve this stuff ?

Thanks,
Saumik

@saumik

That was an interesting project. It would be difficult to avoid possible collisions with RF433 and VWI if the buzzer would be allowed to send at any time. The VWI library does not support that.

A better solution would be to do as you suggest; 1) broadcast an "ARM" message to the buzzers, and then 2) poll them until timeout or one answers. You would also need a simple method of assigning addresses and attaching them. This could be done as a startup phase before the "game".

The buzzers would also need to report back the time measured until the button was pressed.

The NRF24L01+ is easier to use as it provides basic retransmission. You would need that even for the RF433 version as the poll message needs to be answered with a time measurement or not pressed (ack). My guess :wink:

Anyway, good luck with this project!

Cheers.

I have started to use the github issue handling for new items on the development list. Please comment these to help with priority. Add suggestions or improvements.

Cheers!

For those of you that are following the Cosa project it might seem like there is a lack of progress after the summer holiday. Before pushing the next update I thought I would describe one of the ongoing refactoring and updates.

INTEGRATING MULTIPLE SPI LIBRARIES

The initial Cosa SPI class extended the Arduino SPI library with SPI/USI bus controller, slave device support, interrupt handling and a rich set of functions for typical SPI device interaction. Unfortunately it did not address one of the more important SPI issues.

On this forum there are a number of requests for support with integrating several SPI devices/libraries. The problem is often that the devices have different SPI bus usage, e.g. different speed, bit order, mode, etc, resulting in conflicts and confusion. Each library will work perfectly on its own but not together. Most of these support requests end with a recommendation to use SoftSPI and avoid the problem by using more pins. There are also very few SPI device libraries that use interrupts and do not work very well in low power applications as they require polling.

What are the requirements on the SPI library? Obviously it should be able to handle multiple devices with different settings. It should also support chip select and interrupt signals. Be available for both ATmega and ATtiny, i.e., SPI and USI hardware modules and allow replacement with a bit-banging version when needed through simple configuration.

As the TWI/Wire the functions begin() and end() should be used to define an SPI interaction block. The current usage in the Arduino SPI library is more or less a setup. Most SPI device libraries assume that there is only one device on the bus.

Addressing the interrupt issue is especially interesting as the interrupt handle will want to perform SPI transfers (read/write) to at least check the interrupt status register in the serviced device. Without special care this gives concurrency problems as an interrupt could be issued during an ongoing SPI transaction. This becomes even more challenging if the interrupt is issued from another SPI device on the same bus. Simply disabling interrupts is not a very good idea as this may affect other concurrent activities such as incoming data in other hardware modules (TWI, UART, etc).

The design must support architectures with multiple SPI bus controllers.

The ongoing Cosa SPI redesign tries to address the above issues and attempts to meet the requirements.
The design so far has resulted in the evolution of the initial SPI::Driver root class to hold the context of the SPI hardware (SPI control register) and chip select pin (OutputPin) so that spi.begin()---spi.end() will perform

  • loading of the SPI hardware state,
  • toggling the chip select pin,
  • disabling interrupt handlers to allow mutual exclusive access.
  • handle the clock pin polarity for ATtiny/USI implementation to achieve all four SPI modes

The ripple effect is a major update of the Cosa's SPI device driver. Which then results in a large batch of regression testing before pushing the update.

Cheers!

To continue the presentation of the refactoring of the Cosa SPI class here are some further details. Below is a snippet from the new header file.

class SPI {
public:
  enum Clock {
    DIV4_CLOCK = 0x00,
    ...
    MASTER_CLOCK = 0x08,
    DEFAULT_CLOCK = DIV4_CLOCK
  } __attribute__((packed));

  enum Order {
    MSB_ORDER = 0, 
    LSB_ORDER = 1,
    DEFAULT_ORDER = MSB_ORDER
  } __attribute__((packed));

  class Driver {
  protected:
    ...
  public:
    Driver(Board::DigitalPin cs, 
	    Clock clock = DEFAULT_CLOCK, 
	    uint8_t mode = 0, 
	    Order order = MSB_ORDER,
	    Interrupt::Handler* irq = 0);
  };

public:
  SPI();
  bool begin(Driver* dev);
  bool end();
  uint8_t transfer(uint8_t data);
  void transfer(void* buffer, uint8_t count);
  ...
};

The most important addition to the previous SPI interface is that the SPI::Device class, which is the device driver support class, holds information about the device SPI hardware setting, chip select and possible interrupt handler (pin).

SPI::begin() and SPI::end() become essential functions that mark the beginning and end of an SPI transaction. They will handle 1) asserting the chip select pin, 2) disabling/enabling all interrupt sources on the SPI bus (if any) and most important 3) setting the SPI hardware state for each transaction. This allows several devices with different SPI settings to be integrated without conflicts.

Below is a snippet from the current implementation. NB: The macro synchronized marks a block of code as mutual exclusive (i.e. interrupt handing is turned off). The macro is part of the syntax abstraction in Cosa (See Cosa/Types.h).

bool
SPI::begin(Driver* dev)
{
  synchronized {
    ...
    m_dev = dev;

    // Initiate the SPI hardware with the device driver settings (context)
    SPCR = dev->m_spcr;
    SPSR = dev->m_spsr;

    // Select the device
    dev->m_cs.toggle();

    // Disable interrupts from SPI devices
    for (dev = spi.m_list; dev != 0; dev = dev->m_next)
      if (dev->m_irq) dev->m_irq->disable();
  }
  return (true);
}

bool
SPI::end()
{ 
  synchronized {
    ...

    // Deselect the device
    m_dev->m_cs.toggle();

    // Enable interrupts from SPI devices
    for (Driver* dev = spi.m_list; dev != 0; dev = dev->m_next)
      if (dev->m_irq != 0) dev->m_irq->enable();
    
    // Release the SPI driver support
    m_dev = 0;
  }
  return (true);
}

Below is a snippet from the ST7735 TFT device driver to gives an idea of typical usage of the SPI device driver support. NB: The asserted(pin) is a macro that will toggle the pin before and after the block. The chip select is handled by SPI::begin/end. Please also note that the internal/protected write methods are used within a transaction as set_port() and draw_pixel(). These two Canvas methods are given in full detail to give an idea how this works.

class ST7735 : public Canvas, SPI::Driver {
protected:
  OutputPin m_dc;
  enum Command {
    NOP = 0x0,			// No Operation
    RDDID = 0x04,		// Read Display ID
    RDDST = 0x09,		// Read Display Status
    RDDPM = 0x0A,		// Read Display Power Mode
    ...
  } __attribute__((packed));

  ...

  void write(Command cmd)
  {
    asserted(m_dc) {
      spi.transfer(cmd);
    }
  }

  void write(Command cmd, uint8_t data)
  {
    asserted(m_dc) {
      spi.transfer(cmd);
    }
    spi.transfer(data);
  }

  void write(Command cmd, uint16_t data)
  {
    asserted(m_dc) {
      spi.transfer(cmd);
    }
    spi.transfer(data >> 8);
    spi.transfer(data);
  }

  void write(Command cmd, uint16_t x, uint16_t y)
  {
    asserted(m_dc) {
      spi.transfer(cmd);
    }
    spi.transfer(x >> 8);
    spi.transfer(x);
    spi.transfer(y >> 8);
    spi.transfer(y);
  }

public:
  ST7735(Board::DigitalPin cs = Board::D10, 
	 Board::DigitalPin dc = Board::D9);

  void set_port(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
  {
    spi.begin(this);
    write(CASET, x0, x1); 
    write(RASET, y0, y1);
    write(RAMWR);
    spi.end();
  }

  virtual void draw_pixel(uint8_t x, uint8_t y)
  {
    set_port(x, y, x + 1, y + 1);
    color16_t color = get_pen_color();
    spi.begin(this);
    spi.transfer(color.rgb >> 8);
    spi.transfer(color.rgb);
    spi.end();
  }

  ...
};

Cheers!

Hi! Here is some news on the latest update and development of Cosa:

  1. The SPI and TWI device driver support has been improved so that many of the problems described on this forum may be avoided when using multiple device driver libraries and interrupts. The Arduino SPI library does not allow several devices with different settings and is not interrupt safe. The Cosa SPI support will handle chip select (with pulse for HD44780 SR with SPI), interrupts from SPI sources, SPI hardware module context switch, etc.

  2. The Cosa SPI and TWI device drivers have been updated to take advantage of the above improvements. This increases both robustness and code quality. Also with the new abstractions reduce the code volume/footprint. Please see changes to ST7735.

  3. The Cosa LCD/HD44780 device driver for 4-bit parallel port has been updated to allow easier configuration.

Cheers!

Hi! Here is some news on the latest update and development of Cosa:

  1. TWI device driver for BMP085 digital pressure sensor.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/TWI/Driver/BMP085.hh

  2. SPI device driver with interrupt handler for CC1101 (433 MHz) Low-Power Sub-1 GHz RF Transceiver. Tested on Arduino Nano IO Shield with CC1101 module with pinout as the RF24L01+ module. Simple interrupt handler for incoming messages. Can be configured with TI SmartRF Studio. Default configuration as panstamp (but 433 MHz).
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Wireless/Driver/CC1101.hh
    SMARTRFTM-STUDIO Calculation tool | TI.com

  3. Added support for even higher speed update of output pins. Unprotected (non synchronized) update member functions. Typically used when several updates are performed within a synchronized block.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Pins.hh#L353

  4. Adding datatype cast operator (e.g. operator uint8_t()) to bit-field definitions to reduce code complexity and improve readability.
    Updating HD44780 port access functions. · mikaelpatel/Cosa@93990e4 · GitHub

  5. New directory structure for drivers for Wireless devices.

Cheers!

Hi! This week the Cosa project takes another jump forward. Below are some of the highlights.

  1. The Cosa NRF24L01P and VWI (Virtual Wire Interface) device drivers have been adapted to the Cosa Wireless abstract class/interface. This allows VWI, CC1101 and NRF24L01P device drivers to be interchanged by simply altering a single line of code. See Wireless example sketches.
    Cosa/Wireless.hh at master · mikaelpatel/Cosa · GitHub
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Wireless/Driver/NRF24L01P.hh
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Wireless/Driver/VWI.hh
    Previous enhanced mode VWI Transceiver has be replaced by the new Wireless interface based version of VWI. The update of VWI adds node addressing but removes the retransmission functionality.

  2. A Registry class has been added to allow mapping from path string (number sequence) to objects in memory. This will together with the Wireless interface allow simple implementation of panstamp/SWAP like protocols with great flexibility.
    http://code.google.com/p/panstamp/wiki/SWAP
    The Registry allows the following basic register/node types; ITEM with name string and type, ITEM_LIST for directory nodes in the register tree, ACTION object reference and BLOB for binary objects. The interface is very thin with only two primary functions (as the Registry is defined statically in program memory); lookup() to allow mapping from index sequence to Register and apply() to allow execution of an ACTION object. There is a macro set to support creating the data structure in program memory. No data memory is used for the Registry. It follows the same design pattern as the Cosa LCD Menu system.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Registry.hh
    https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaRegistry/CosaRegistry.ino

  3. The Cosa Pin classes benchmark now includes additional tests with the new unprotected OutputPin write/set/clear member functions. These allow an additional X2-X4 performance increase compared to the Arduino/Wiring digitalWrite function. The benchmark also show the mapping between Arduino/Wiring pin functions and Cosa.
    Cosa/CosaBenchmarkPins.ino at master · mikaelpatel/Cosa · GitHub

  4. The LCD driver for 4b parallel port and soft SPI have been updated with the new unprotected/fast pin member functions and are now 10-20% faster. An outer synchronized block is used to protect updates to the ports/pins. The LCD adapter member function HD44780::SR3W::write4b(uint8_t data) is a good example of how a synchronized block may be used to protect a sequence of updates.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/LCD/Driver/HD44780_IO_SR3W.cpp#L35

  5. A simple touch capacitive sensor has been added. See example sketches for further details.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Touch.hh

See the Issues log on github for more details on what is going on.

Cheers!

Hi! The focus these last weeks in the Cosa project has been low power mode and additional example sketches for the Wireless interface and device drivers (CC1101, NRF24L01+ and RF433 modules).

  1. Low Power Mode
    Out of the box Cosa will turn off analog converter and comparator until needed or explicitly powered up. There are two new member function for AnalogPin; powerup() and powerdown(). The Analog Comparator is powered up resp down on enable() and disable() of the interrupt handler.

  2. Wireless Interface
    There are a number of new sketches to show how to use the Wireless interface and device drivers. These also show how to swap device with only minor changes to the sketch. There is a general sender and receiver sketch, a simple message stream debugger, an example sketch that samples a DHT11 and broadcasts the temperature and humidity reading, and also a sketch to demonstrate low power mode.

  3. Low Power Wireless on ATtiny85
    To verify the low power handling for ATtiny an additional example Wireless sketch has been added. This sketch will power down and wait for a button to be pressed. During the wait only a minimum of the internal hardware modules are used. When the button is pressed the internal hardware is enabled and a message with a timestamp and three analog readings is send. After the transmission is completed the device goes back into power down mode. This allows the power down current to be a low as 5 uA for an ATtiny85-20PU with the Watchdog enabled.
    Cosa/CosaWirelessButton.ino at master · mikaelpatel/Cosa · GitHub

  4. Registry
    The Registry handler has been improved and will now allow mapping from the directory to data stored in SRAM, PROGMEM and EEMEM. There is also a full example sketch to show how application data can be stored in the directory.
    https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaRegistry/CosaRegistry.ino

The Registry and the Wireless interface will become the basis for a small scale variant of SMNP and have many features in common with panstamp/SWAP.

Cheers!

Please find Cosa on Ohloh! https://www.ohloh.net/p/cosa
You can register your usage of Cosa and get a lot of information about the project.

Cheers!

Hey kowalski. Great to see you are still plugging away at this project!!

I just purchased the same CC1101 modules as you (http://www.ebay.com/itm/2pcs-CC1101-433MHz-Wireless-Transceiver-Module-NRF905SI4432-with-SMA-Interface-/221274129252) and am wondering if they are usable with the AtTiny85 chips? Seeing "#if !defined(ARDUINO_TINYX5)" at the top of the CC1101.hh/cpp files leads me to believe they might not be?

If they are compatible, what pins get connected between the CC1101 modules at the Tiny85?

Thanks in advance for any assistance!!

Hi sirhax!

Yes the project is still going strong and there is a lot more that I would like to add and achieve. The CC1101 module you have found is exactly what I am using in my prototyping. It works fine as a replacement for the NRF24L01+ module on for instance the Arduino Nano IO Shield.

Right now I have removed the usage of ATtiny85 as the pin D2 is both the USI/SPI clock (SCK) and external interrupt (EXT0). This is possible to solve by using a Pin Change Interrupt (PCI-pin) or simply removing the interrupt handler for ATtiny85. Need to push this onto the backlog (issue list) and figure out a priority for this update. Actually the same goes for NRF24L01+.

You might want to have a look at the ongoing work on the protocol; Cosa Rete. This will become Cosa's version of the panstamp SWAP protocol and work on all Cosa Wireless drivers (RF433, CC1101 and NRF24L01+), and support low power nodes out of the box. Cosa Rete is a scaled down version of SNMP with a dash of DDS (OMG Data Distribution Service). Cosa Wireless interface is one of the building blocks. The other building block is Cosa Registry which acts as a MIB with mapping to application data. The vision is a framework for very easy implementation of low power wireless sensor/actuator nodes.

Cheers!

Ref:

  1. https://github.com/mikaelpatel/Cosa/blob/master/RETE.txt
  2. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Rete.hh
  3. Cosa/Wireless.hh at master · mikaelpatel/Cosa · GitHub
  4. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Registry.hh
  5. https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaRegistry/CosaRegistry.ino
  6. Simple Network Management Protocol - Wikipedia
  7. Management information base - Wikipedia
  8. Data Distribution Service - Wikipedia

Thanks for the reply, kowalski!

That makes sense. For now I just ordered a handful of "ATTINY84A-PU-ND"s from digikey.

That's certainly some very cool and interesting work! I'm anxious to see it in its final form :).

Along the lines of "internet-of-things", have you seen this project?
http://www.kickstarter.com/projects/flutterwireless/flutter-20-wireless-arduino-with-half-mile-1km-ran

sirhax:
Along the lines of "internet-of-things", have you seen this project?
http://www.kickstarter.com/projects/flutterwireless/flutter-20-wireless-arduino-with-half-mile-1km-ran

Thanks for the feedback and the kickstarter link. That was an interesting project. I have seen a number of Arduino-clones with varying functions on kickstarter. Would be nice to see a project or two with software as the main focus instead of just hardware. Will soon need to produce a board and/or shields to fund further development of Cosa :wink:

Cheers!

Some news on the latest developments in Cosa. The theme has been supporting multi-DOF boards and improving TWI sensor drivers.

  1. New TWI driver for L3G4200D Digital Gryposcope.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/TWI/Driver/L3G4200D.hh

  2. New TWI driver for MPU6050 Motion Processing Unit; Digital thermometer, accelerometer and gyroscope.
    https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/TWI/Driver/MPU6050.hh

  3. Major refactoring and improvement of the TWI drivers for BMP085 and ADXL345.

  4. Improved TWI scanner. Will print name and short description of connected devices. Verifies identity register (WHO_AM_I) if available. See CosaTWIscanner. https://github.com/mikaelpatel/Cosa/blob/master/examples/TWI/CosaTWIscanner/CosaTWIscanner.ino

device = 0x1e:group = 3.6:HMC5883L, 3-Axis Digital Compass
device = 0x53:group = 10.3:ADXL345, Digital Accelermeter
device = 0x69:group = 13.1:L3G4200D, 3-Axis Digital Gyroscope
device = 0x77:group = 14.7:BMP085, Digital Pressure Sensor

Above is the scanner information generated for the GY-80.

  1. Extended example sketch for GY-80 10DOF module.
Cosa10DOF: started
free_memory() = 1499
sizeof(TWI::Driver) = 3
sizeof(ADXL345) = 3
sizeof(BMP085) = 37
sizeof(HMC5883L) = 13
sizeof(L3G4200D) = 3
acceleratometer.begin() = 1
bmp.begin(BMP085::ULTRA_LOW_POWER) = 1
gyroscope.begin() = 1
compass.begin() = 1
ADXL345(x = 260, y = 2, z = 2)
BMP085(temperature = 222, pressure = 98462)
HMC5883L(x = -579, y = 36, z = -143)
L3G4200D(x = -43, y = 216, z = 3)

ADXL345(x = 258, y = 0, z = 0)
BMP085(temperature = 222, pressure = 98459)
HMC5883L(x = -579, y = 18, z = -143)
L3G4200D(x = -53, y = 204, z = 15)

ADXL345(x = 260, y = 0, z = 0)
BMP085(temperature = 221, pressure = 98451)
HMC5883L(x = -579, y = -4, z = -143)
L3G4200D(x = -9, y = 197, z = -4)
  1. Wireless IOStream class. Use any Wireless driver as an IOStream. The below example sketch will send digital and analog pin readings over the connected wireless driver and display on an LCD (monitor).
    Cosa/CosaWirelessIOStream.ino at master · mikaelpatel/Cosa · GitHub
    Cosa/CosaWirelessMonitor.ino at master · mikaelpatel/Cosa · GitHub
    Cheers!

A note to the BMP085 driver: you may add the barometric pressure reading, as the pressure you measure now is the "absolute pressure". Thus, if you want to see the barometric pressure your local weather station reports (ie. a local airport) you have to calculate "Barometric pressure adjusted to Sea Level" (as this is how they report it).
You have to provide your Altitude (in meters over the sea level) as well.
For example:

  /**
   * Return latest calculated Absolute pressure from temperature and pressure
   * raw sensor data.
   * @return calculated pressure in steps of 1 Pa (0,01 hPa).
   */
  int32_t get_ABS_pressure()
  {
    return (m_pressure);
  }
    
   /**
   * Return latest calculated Barometric pressure from Absolute pressure
   * and your altitude over Sea Level.
   * You have to provide your Altitude [meters] over the sea level.
   * @return calculated pressure in steps of 1 Pa (0,01 hPa).
   */
  int32_t get_BSL_pressure(int32_t myAltitude, int32_t ABSpressure) {
  float p;
  p = ABSpressure / pow((1.0 - ( myAltitude / 44330.0 )), 5.255);
  return (int32_t) p;
  }
  // Calculate and print values
  trace << PSTR("BMP085(mode = ") << mode
	<< PSTR(", temperature = ") << bmp.get_temperature()
	<< PSTR(", ABS pressure = ") << bmp.get_ABS_pressure()
	<< PSTR(", BSL pressure = ") << bmp.get_BSL_pressure(235, bmp.get_ABS_pressure())
	<< PSTR(", delay = ") << (stop - start)
	<< PSTR(")") << endl;
BMP085(mode = 1, temperature = 238, ABS pressure = 97811, BSL pressure = 100581, delay = 32)

PS: to avoid a "chicken-egg" situation, you may get your Altitude by changing the altitude in above function until the BSL reading is equal to the number your local weather station reports (most current report, as the pressure changes with time and location).