Go Down

Topic: Cosa: An Object-Oriented Platform for Arduino programming (Read 108046 times) previous topic - next topic


I am trying the example CosaEEPROM on an atmega32u4.  The make target 'eeprom' only resets.  The make target 'raw_eeprom' says

  On leonardo, raw_xxx operation is not supported.  Stop.

Arduino.mk raw_eeprom says ERROR_ON_CATERINA.

What's the story here?  Is it not possible to initialize EEPROM on Caterina?


What's the story here?  Is it not possible to initialize EEPROM on Caterina?


Did you try modifying Arduino.mk and disabling the caterina check? This seems to have to do with a problem in older versions of avrdude. Anyway allowing eeprom hex upload works but avrdude will ask if the fuses should be updated. The modification is available on github.


Ref. http://lists.nongnu.org/archive/html/avrdude-dev/2012-07/msg00027.html


Announcing the availability of more add-ons for Cosa.

CosaTimezone provides full Timezone capability.
CosaINA219 provides driver for INA219 high-side current sensor.


I wonder if the following is possible in Cosa assuming some Arduino with LAN connection:
  • Server for TCP/IP on port xxxx for direct communication with some PC
  • Small simpel webserver on port 80, serving static HTML
  • MQTT Client

This means I can't use blocking calls, but should poll the TCP ports and send MQTT data if available in the main loop or something?



I don't see any direct problems with this usage of the Ethernet services. Obviously it would be more elegant to use interrupts from the Ethernet controller but polling is fine.

I have done some combination of services such as Telnet and Web-server. No problems with that.



Some information on the latest updates in the Che Cosa project. Summary of commits since mid-September.

  • Support for Arduino 1.0.6
  • Refactoring of SPI class to allow multi-tasking (i.e. device driver semaphore)
  • Update SPI device drivers
  • New LCD member function; line_clear()
  • Bugfix: NRF24L01P missing auto-ack on pipe
  • Allow Alarm period to be larger than 18 h (i.e. time period changed from uint16_t to uint32_t)
  • Add support for Arduino Micro
  • Bugfix: Time-zone should be signed
  • Bugfix: PWMPin handling for ATmega1284P
  • Allow yield during Analog conversion
  • Improved CDC auto-reset handling
  • Allow EEPROM upload to ATmega32U4 based boards
  • New Alarm member function; expired_in() to query time left before alarm
  • Add support for Arduino Pro Mini @ 8 MHz  
  • Improved checking of build size; program memory, SRAM and EEPROM
  • Add support for LowPowerLab Moteino Mega
  • Bugfix: Risk for Watchdog left hanging removed
  • Initial testing of Arduino 1.6.0rc1
  • Added support for SainSmart LCD2004 I2C LCD adapter
  • Initial support for libraries and components. Command line support only
  • Many improvements to the command line build script and makefiles

Special thanks to @jediunix, @SlashDevin and @thomasahlendorf for many contributions and bug fixes.



The latest update include support for event driven programming of IOStream device receive and send. This may be used to allow the UART device driver to push an event when a full line has been received or when the input buffer is full.

The new template class is called IOEvent<T> and takes an implementation of the IOStream::Device class as parameter. Below is a snippet from the example sketch CosaIOEvent.ino.

Code: [Select]

typedef IOBuffer<UART::BUFFER_MAX> Buffer;

class Handler : public Event::Handler {
  virtual void on_event(uint8_t type, uint16_t value)
    Buffer* buf = (Buffer*) value;
    while (buf->available()) trace << (char) buf->getchar();

Handler handler;
IOEvent<Buffer> ibuf(&handler);
Buffer obuf;
UART uart(0, &ibuf, &obuf);

void setup()
  trace.begin(&uart, PSTR("CosaIOEvent: started"));

void loop()

The example sketch will read an input line and push an event. The event is then dispatched by Event::service() to the handler. The handler on_event() member function prints the event type and the received line.

The basic event dispatcher allows easily integration with timed actions (Alarms, Activity), button handler, and other event driven classes in Cosa.  


Ref. IOEvent.hh


Now and then I get the question about mapping Cosa Pin classes and member functions to Arduino/Wiring functions. There is actually an implementation of this in the sketch CosaBenchmarkPins.ino.
Code: [Select]
inline void pinMode(Board::DigitalPin pin, uint8_t mode)
  IOPin::set_mode(pin, (IOPin::Mode) mode);

inline int digitalRead(Board::DigitalPin pin)
  return (InputPin::read(pin));

inline void digitalWrite(Board::DigitalPin pin, uint8_t value)
  OutputPin::write(pin, value);

inline void digitalToggle(Board::DigitalPin pin)

inline int analogRead(Board::AnalogPin pin)
  return (AnalogPin::sample(pin));

The benchmark shows the performance when using Cosa's strongly data typed board/pin definitions. Below are the results for the adaptation functions (for Arduino 1.5.8, Arduino Nano, ATmega328P, 16MHz). The result is X2-X10 faster than the standard Arduino core.
Code: [Select]
175:void loop():info:Measure the time to perform an input pin read
194:void loop():measure:digitalRead(D7):63 ns

199:void loop():info:Measure the time to perform an output pin toggle
268:void loop():measure:digitalWrite(D8, 1/0):252 ns
274:void loop():measure:digitalToggle(D8):126 ns

280:void loop():info:Measure the time to perform input pin read/output pin write
320:void loop():measure:digitalWrite(D8, !digitalRead(D7)):566 ns
325:void loop():measure:digitalRead(D7)/digitalWrite(D8,0/1):346 ns

333:void loop():info:Measure the time to perform 8-bit serial data transfer
441:void loop():measure:digitalWrite(D9/D10):9 us
450:void loop():measure:digitalWrite(D9)/digitalToggle(D10):8 us

459:void loop():info:Measure the time to read analog pin
483:void loop():measure:analogRead(A0):112 us

For more details see the Cosa Benchmarks and Board definitions.


Go Up