Cosa: An Object-Oriented Platform for Arduino programming

@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).

@pito

Thanks for your suggestions. I guess this formular could also be transformed and used to calculate for instance height using relative change in pressure. From a design perspective I want to isolate these types of calculation from the sensor drivers and provide them in a separate class/library.

This week the focus has been on improving the support for low-power mode and pushing the default idle mode as low as possible. I have added a number of example sketches to show how to go towards ultra low power (1-10 uA range) in power-down.

Below is a link to one of the sketches. It is a basic wireless temperature sensor using DS18B20s and Cosa Wireless interface and drivers (NRF24L01P, CC1101 or RF 433). The sketch will power up and issue a conversion request to two DS18B20 sensors. Sleep until the conversion to complete (750 ms). After that the temperature samples are read and sent in a message together with a sequence number and the power supply status (i.e. battery voltage). The results for an Arduino Mini Pro 16 Mhz with Power LED removed with the VWI driver and a RF 433 module are;

Power       Idle    Sampling  Transmitting        
LiPo 3.9 V  40 uA   1.3 mA    6 mA
FTDI 5,1 V  190 uA  1.5 mA    10 mA

Further reduction is possible by removing the regulator from the Arduino Mini Pro and running on the internal 8 MHz clock. On an Arduino LilyPad the power down mode is less than 1 uA.

Cheers!

Hey Kowalski,
I'm having trouble getting the CC1101 transceivers to work, and am hoping that you can offer some assistance :). Here's my setup:

I have an UNO R3 running CosaWirelessReceiver and a Mega2560 running CosaWirelessSender.

I commented out the two NRF24 lines and uncommented the CC1101 lines in both programs as follows:

#include "Cosa/Wireless/Driver/CC1101.hh"
CC1101 rf(0xC05A, 0x01);

// #include "Cosa/Wireless/Driver/NRF24L01P.hh"
// NRF24L01P rf(0xC05A, 0x01);

Here is how I have the boards/chips wired up:

CC1101   UnoPin# MegaPin#
1:GND    GND     GND
2:3.3v   3.3v    3.3v
3:CE     9       48
4:CSN    10      53
5:SCK    13      52
6:MOSI   11      51
7:MISO   12      50
8:IRQ    2/EXT0  21/EXT0

I did happen to notice one discrepancy between the NRF24 and CC1101 code in that the NRF24 uses EXT4 on the Mega while CC1101 uses EXT0.

The programs upload and start fine, I just don't see any "traffic".

I'm using the transceivers right out of the box, assuming that the Cosa driver applies necessary any configuration parameters, correct? Can you offer any advice on debugging this issue?

Thanks!

@sirhax

Actually your setup looks fine. The default settings for NRF and CC use IRQ from D2 which is EXT0 for Uno and EXT4 for Mega. I use a Nano IO Shield and a Mega Prototype Shield. Both with NRF 2X5 connector to SPI, etc.

I rigged up a Mega running CosaWirelessSender and a Nano running CosaWirelessReceiver to verify. There are a fair amount of configuration ;-). Anyway it works as it should; both ways.

After the latest improvements for low power mode I needed to adjust CC1101::await() to get the correct wait behaviour between transmitted messages. The broadcast message in CosaWirelessSender could go missing.

Try the default setting with IRQ connected to D2.

Cheers!

Thanks for the response, Kowalski!

Before adding this line (563) to CC1101.hh:
Board::ExternalInterruptPin irq = Board::EXT4)
would it have fallen through and used EXT0?

For some reason, I originally used the documentation in NRF24L01P.hh since I knew the two chips were supposed pinout-compatable, so I had the IRQ connected to pin D2 at first. After not seeing any traffic, I perused CC1101.hh and thought that the logic alleged that EXT0 was going to be used for the Mega. Still nothing.

After seeing your response, I switched the pin back to D2 and still wasn't having any luck. The two transceivers were sitting within a few inches of each other, but I didn't have antennas plugged into the sma connectors. Apparently these boards/chips have zero range without antennas, as I finally saw some messages to appear on the CosaWirelessReceiver board after putting the two sma connectors right against each other. After attaching some antennas, things started working consistently. So that was likely my problem from the start. Doh! I thought they should be able to reach a couple feet without antennas though... oh well.

After getting this to work fairly reliably, I have run into a situation where the CosaWirelessReceiver appears to stop receiving data after going out of range and then coming back. Simply pushing the reset button on the CosaWirelessReceiver board causes data to start flowing again. Have you run into this?

Thanks for verifying my configuration and taking the time to setup your own test -- I greatly appreciate it!