Go Down

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


Yes an analyser is probably the most useful tool a firmware person can own IMO. Even when you decide everything is working there's no substitute for seeing the actual waveform as that can often highlight a fault.

I'd be lost without mine.

BTW, did you get one of the new Saleaes or is that a Logic8/16?

Rob Gray aka the GRAYnomad www.robgray.com



Last time I used a logic analyzer was back in the late 80'ies/beginning of 90'ies.

The quantum leap for me this time around was the ability to capture several seconds of data (at medium high speed) and then being able to zoom. The high level patterns became easier to see. A bit like FFT but on trace/probe data. This gave a lead on possible high and low level optimizations. I have not had tooling before that allow this size of capture and not zooming between 10 s to 10 ns level so fast and seamlessly.    

BTW, did you get one of the new Saleaes or is that a Logic8/16?

I was avoiding marketing as there must be a lot of these tools out there but lets say it pure logic levels (no analog), 8 channels @ 24 MHz. Nothing fancy.

It would be great to put together some kind of "firmware programmers handbook" (or even teaching material) where the focus would be on using logic analyzers for verification and optimization. There seems to be a lot of knowledge out there and this could be combined with software architecture, design patterns and optimization techniques. Device driver programming for embedded systems is a growing area with M2M and IoT coming along.

Next stop will be a closer look at the Cosa Wireless device drivers and improving them.



Last time I used a logic analyzer was back in the late 80'ies/beginning of 90'ies.

Me to, and then they were a big purchase even for a company. We live in fun times.


Rob Gray aka the GRAYnomad www.robgray.com


Sep 16, 2014, 02:30 pm Last Edit: Sep 16, 2014, 02:34 pm by kowalski Reason: 1
The latest Cosa update contains a refactoring of the MQTT support class. The example sketch CosaMQTTtemperature demonstrates how to push temperature readings from DS18B20 to an MQTT server. The sketch can be configured for a number of MQTT servers. The default server is q.m2m.io.

Below is a screen shot from MQTTInspector on Apple iPad. A MQTT topic is used for the client name and an additional three topics for the digital thermometers (indoors, outdoors and basement).  

A standard web-browser can also be used to view data published on MQTT servers. Below is a screen shot from 2lemetry MQTT Client, www.mqtt.io.

Last, the example sketch also demonstrates some of the new features in C++11.
Code: [Select]

// One-wire pin and connected DS18B20 device
OWI owi(Board::D7);
DS18B20 outdoors(&owi);
DS18B20 indoors(&owi);
DS18B20 basement(&owi);
DS18B20* thermometer[] = {
void setup()
 uint8_t i = 0;
 for (auto sensor : thermometer) {

C++11 allow more advanced for-loop constructions with auto type definition. http://en.wikipedia.org/wiki/C%2B%2B11#Range-based_for_loop



Interesting about the new for-loop syntax. I was an early adopter of C++ all those years ago but have hardly touched it since. I should get back into it.

Rob Gray aka the GRAYnomad www.robgray.com


Sep 26, 2014, 06:11 pm Last Edit: Sep 29, 2014, 02:38 pm by kowalski Reason: 1
The latest update focuses on reducing build time. Cosa currently supports 24 board variants. There are over 160 example sketches. Recompiling and testing all these variants takes some time.

In total the Cosa core contains 292 source code files and these are in total over 63 KLOC (lines of code). The Arduino (AVR) core contains 42 files and approx. 8 KLOC. The Cosa core is somewhat like having all the Arduino official libraries available at all time and seamless from ATtiny to ATmega.

The new build support reduces the sketch build time to approx. 1.5 second. This is achieved by caching the Cosa core library and object files. The initial build of the library for a board will take 5-7 seconds (depends on Arduino/AVR gcc tool chain). The core library is then kept between sketch builds. Only the sketch needs compiling and linking. Even the sketch object and hex files are kept between builds. Any change to the core or sketch will trigger rebuild of the necessary files.

Total rebuild of the Cosa core library for all 24 boards will now only take approx. 2 minutes for 1.0.X and 2.45 minutes for 1.5.7. Rebuilding all 164 example sketches for a specific board takes 4.15 minutes. The build times are for HP ProBook 4540s, Intel® Core™ i5-3230M CPU @ 2.60GHz × 4, 64G SSD, Ubuntu 14.4 LTS. The Cosa build uses the available processor cores (parallel make). More details in the build log, https://github.com/mikaelpatel/Cosa/blob/master/build/arduino-1.5.7.log and https://github.com/mikaelpatel/Cosa/blob/master/build/arduino-1.0.6.log.

The Cosa build support is implemented as a set of scripts and makefiles. The Arduino-Makefile project is used as a basis for the implementation together with miniterm.py (serial monitor).

Geany (http://www.geany.org/) together with the Cosa command line build script this is a great alternative IDE for Arduino users on Linux.


1. Cosa.mk, makefile rules, https://github.com/mikaelpatel/Cosa/blob/master/build/Cosa.mk
2. cosa, makefile-less build script, https://github.com/mikaelpatel/Cosa/blob/master/build/cosa
3. tutto, total rebuild script, https://github.com/mikaelpatel/Cosa/blob/master/build/tutto
4. Install and setup, http://forum.arduino.cc/index.php?topic=150299.msg1789114#msg1789114


I have found a minor annoyance in W5100.cpp (line 618):

// Check for default gateware. Assume router is first address on network
  uint8_t ROUTER[4];
  if (gateway == NULL) {
    memcpy(ROUTER, ip, sizeof(ROUTER) - 1);
    ROUTER[3] = 1;
    memcpy(m_dns, ROUTER, sizeof(ROUTER));
    gateway = ROUTER;

This is a rather nasty assumption because it means unless you use DHCP, your board will not find the right default gateway. It also assumes that the DNS server is the same. I'm working on a patch, but my time is very limited. It probably needs an additional "begin" that allows DNS and the gateway to be specified.



Hi! Sorry for the delay.

I think you are referring to W5100::bind() which is used to connect a socket to a specific setting (and part for the setup W5100::begin() and begin_P()). https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket/Driver/W5100.hh#L639

In W5100::begin_P(hostname, timeout) the IP address is given by the DHCP server which also provides the DNS server address.

For W5100::bind(ip, subnet, gateway) where gateway is NULL the assumption is that the gateway is the first address on the subnet and also provides DNS.

I will add a set_dns_addr() and consider adding an extra argument to bind().

Cheers and thanks for the catch!


Oct 16, 2014, 11:03 pm Last Edit: Oct 17, 2014, 12:06 am by benjaminf Reason: 1
Just discovered this library, looks like a great work!  8)
Let's dive into it now.

edit: awesome !



I'm using Cosa to my home project. It's great.

I have a little question about dht22 class.

I see that in example data pin are connected to external interrupt.

May I use other pin ? My project will involve +-10 dht sensors so not enough external interrupt pin.

I suppose I'll lose the event part of the class but I will be able to make a simple sample ?

How much time take a sample ? I'm a little confused there. Like 2 second or 200ms ?

Thanks for your help.

Sorry for my bad English I speak French.

Go Up