Go Down

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


Is there a way to include only the Cosa's UART library in my std Arduino project, what files should I copy/modify and how?
What you need to do is port the following files from Cosa to Arduino. See the dependency graph.

This is not an easy task as the Arduino core does not have a lot of support. The alternative is to use the Cosa UART and IOBuffer as a base for implementing an alternative to the Arduino core HardwareSerial. In this case you need to read a lot about the AVR hardware and how the UART sub-module works.

What are you using previously in your project? And why not port that to Cosa instead?



@archipielago99, I'll second what @kowalski said:

> why not port that to Cosa instead?

You also said:

> ...the std SW library has some issues.

You don't really want to find the other issues, do you?  ;)  I am so grateful I switched every time I read about an issue instead of finding it myself!  Once your project exceeds a certain level of complexity, the compactness and quality of Cosa really becomes a necessity, IMHO.



The latest update contains:

1. Initial support for Wicked Device WildFire V3 board.
2. Support of AdaFruit ATmega32U4 board.
3. Cosa Canvas will support larger screens (i.e. uint16_t x, y coordinate system).
4. Improved Font handling and a large number of Fonts.
5. Cosa Canvas device driver for the ILI9341 TFT driver.



I am running a few Activities and a web server using Cosa. By combining the two, e.g. the CosaAtivity.ino example with the CosaPinWebServer.ino example, gives the following loop-function:

Code: [Select]
void loop()
  // The standard event dispatcher
  Event event;
  // Service incoming requests
  server.run(); // or perhaps server.run(500);?

The web server runs as expected (WebServer::run()) and you can connect to the server as intended. The events, however, are never dispatched as they should.

Running only the events (commenting the rum()-line) works fine and the events are dispatched. It's like if the code is stuck within the run-function and never returs to the loop-function. Any suggestions on how to run the server and handle the events simultaneously?


Mikael will be chiming in soon, no doubt.  'Til then, I think you need to pass a timeout to run, otherwise it blocks.  Here's something from Cosa/INET/HTTP.hh:

    /* ...  Returns
     * zero if successful otherwise a negative error code;
     * @param[in] ms timeout period (milli-seconds, default BLOCK).
     * @return zero or negative error code.
    int run(uint32_t ms = 0L);

I'm not sure you want to block at the queue::await either.  Maybe something like:

  Event event;
  while (Event::queue.dequeue( &event ))

When there are no events, it exits the loop immediately... and goes on to the server.run( 5L ) next, for example.

I'm not sure how to work in a sleep with these two things that both need to run.



Thanks! That made it all work :D

My Home Automation System now works like a charm, switching on and off my devices at given times as well as provides a remote control via the web server.


Hello kowalski,

As mentioned in another post I wanted to work with I2C MCP23017 I/O 16 ports extender.

I have adapted Adafruit Library to work with Cosa.

I haven't tested interrupt part of the library but I can read and write pin without problems.

I'll attach the code if you want to use it.

Ty and have a nice day.



Thanks for your contribution and effort with this driver. I actually order a few devices and was considering implementing a driver. This could be a nice starting point.

The idea that I had was to add an abstract expander pin class that would be implemented by I2C IO expanders and shift register drivers. This would allow an application to be written so that it could be reconfigured. There is a Cosa remote pin example sketch that uses another Arduino (for instance ATtiny). See CosaTWIremotePinMaster.ino and CosaTWIremotePinSlave.ino

What is your experience of porting from the Arduino Wiring (I2C) to Cosa TWI API? And do you have any example sketches?



Hello kowalski

It was pretty easy to adapt their library to COSA TWI api.

I had to change write and read operation but it's nearly the same and for write operation some can be resume to one call of write instead of 2 in Adafruit library.
I had to change manipulation bits call ( bit_write ) but it's also nearly the same.

As I said the job is done for all method but I haven't tested as my project consist of using it as output expander ( Home Automation ). But nearly all function use the base read and write register methods so the rest of the code should run without problem.

I have lost a lot of time because I have miss-wired my led on my breadboard ...

I have attached my test ino to this message.

When you will look at the code, be careful that input/output register is in inverted logic : 1 for input 0 for output. Another thing is that sometime when I do a soft reset ( e.g. : open com terminal ) gpio registers have sometimes strange value ( not 0 as it should be ). That's why I write 0 for gpio registers in begin().

Have a nice day

Ps : I had added the wrong file.

DemoMcp23017.ino is the test file.

sketchDomoSyncJson.ino is my sketch for automation project.



Thanks for sharing the driver demo code. This makes it easier to start with.

Also many thanks for sharing your application sketch and experience of porting to Cosa. I think your application sketch shows some of the expressive power of Cosa. That is a fairly large functional application you have put together.

Consider creating a fork of the original Adafruit library on github and pushing your changes. This give the possibility to compare and understand the changes needed to port to Cosa. Also it is easier to maintain and share with others.



Hi kowalski,

Here is the link for the fork : https://github.com/TribesTom/Adafruit-MCP23017-Arduino-Library

I hope it's what u want. I'm not used to github fork etc.

My automation script is a little messy.
I'll post when it will be finished with electronic schematic, comments, etc. But I need a lot of more work and reflexions.

Have a nice day.



Thanks for walking the extra mile. That was exactly what I was looking for. The fork with changes and the commit makes the port easier to understand. This allows others to see what is needed when porting other libraries.

The Adafruit libraries do not use as much lexical structuring and performance tuning as many of the Cosa components but this is a very good starting point for refactoring. It is always easier to start with something the works. Add tests and then refactor toward higher software quality.

I am pleased to see that you have integrated so many of components in Cosa in your home automation system.



FYI my username has changed from 'jediunix' to 'jeditekunum'.


All my github references have changed.  I'll go back and edit them.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131