Show Posts
Pages: 1 [2] 3 4 ... 31
16  Topics / Home Automation and Networked Objects / Re: Cosa MQTT client library on: August 21, 2014, 12:09:32 pm
Old stuff. Try

17  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 16, 2014, 06:43:11 am
I see the Teensy 2 is supported.  How about the Teensy 3.1?
Hi Jim!

I am sorry to say that the Teensy 3.1 is currently not supported. It is actually a totally different architecture and has much more resources (memory, DMA, etc) which would allow a very different approach to building small to medium scale embedded systems with both RTOS and library support.

Cosa is very much tailored for the AVR and very limited memory resources. On the bright side there is only a hand full classes that are accessing hardware registers etc. The Cosa HAL smiley.

I do have a couple of the Teensy 3.1 boards but have not yet come around to start playing with them. The Teensy 3.1 Arduino core could be an excellent source for kick-starting the porting of Cosa to ARM/SAM/Teensy 3.1.

18  Using Arduino / Microcontrollers / Re: Comprehensive ATtiny libraries overview? on: August 14, 2014, 05:05:24 am
There is another approach to ATtiny libraries. In Cosa all the libraries/classes compile for the full range of MCUs (Please see documentation for the full list of MCUs and boards). SPI, TWI, OWI etc are all implemented with the same interface from ATtiny. This allows code to seamlessly be developed on ATmegaXXXX and then retargeted to ATtiny.

There are some obvious restrictions such as memory size, pins and hardware modules.

19  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 10, 2014, 06:47:35 am
Next step in integrating Cosa Shell with Ethernet protocols; A HTTP Server that runs the command line handler.

This HTTP server is simply put together by filtering the HTTP query and passing it to the same command handler as in the previous examples (telnet and serial). Below is a snippet from the request handler:

WebServer::on_request(IOStream& page, char* method, char* path, char* query)
  static const char header[] __PROGMEM = ...
  static const char footer[] __PROGMEM = ...
  int res = -1;
  page << header;
  if (query != NULL) {
    char c;
    for (char* qp = query; (c = *qp) != 0; qp++)
      if (c == '&') *qp = ' ';
    res = shell.execute(query);
  if (res != 0) page << PSTR("illegal query") << endl;
  page << footer;

The command line is the URL query where space between options and parameters are replaced with ampersand.

20  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 09, 2014, 07:20:24 am
Some performance measurements on the Cosa Telnet Shell and a short update:

1. CosaTelnetShell performance
The test bench is an Arduino Mega 2560, Ethernet Shield and a D-Link DWL-810+ Ethernet Wifi Bridge. Connecting through a Wifi Router and back to a laptop (HP Probook 4540s with Ubuntu 12.04 LTS).

a. Max burst string output
To measure the performance of pure text output from the sketch the command "help" can be used. It will print the command help text. Using the command "repeat 1000 help" will generate a longer period to measure. The measured throughput on the laptop is 60-64 K received bytes per second for this test case (using GNOME Terminal/telnet and PuTTY).

The max performance when filling buffers on the W5100 is 250 KBps (8 MHz SPI, 4 byte command to transfer 1 byte data, 1/4 MBps). This is excluding chip select and all the commands necessary to initiate and check status for the W5100 SEND command.

b. Max analog sample rate
The command "analogread a4" will sample the analog pin a4 and print the value to the io-stream (socket). Again the repeat command can be used to find the upper limit of sampling, converting and sending per second; "repeat -t 2500 analogread a4" will measure the time to execute 2500 analogread. The max rate is between 2000-3000 samples per second (sample values are converted to text, printed to the iostream/socket and sent over Ethernet/Wifi).

The variation is due to other traffic and drops on Wifi but also the sample value as the text conversion time depends on the value. Please note that the max sample rate at 112 us per sample is 8900 samples per seconds. And that the above results is for a pure sequential implementation without interleaving. It is possible to, for instance, run number conversion to text in parallel with the sampling (ADC). This could give as much as 4000-5000 samples (in textual format) per second over Ethernet/Wifi from the Arduino board.

c. New example shell commands
i. Command "pinmode" to get or set the pin mode; input, output and pullup. The command "pinmode all" will print the pin mode for all pins.

ii. The CosaShell/CosaTelenetShell are mainly to demonstrate how to use the Cosa command line support (class Shell) but may also be used as debugging tools; check hardware connections, etc. Two new commands have been added to allow scanning of 1-Wire and I2C (OWI and TWI).

iii. Setting date/time and accessing the Cosa RTC timer. The command "date" may be used to display or set the current date/time.

2. New SPI function; clock()
The new static SPI function clock() will map from frequency to the SPI clock rate setting. This allows device drivers to be written independent of the MCU system clock setting and knowledge of the SPI rate command. A SPI device driver only needs to supply the max frequency required on the bus (for the connected device).

3. Boosting W5100 performance
The W5100 device driver uses the new interleaving SPI API (spi.transfer_start/next/await) so that memory access (load/store) can be executed in parallel with SPI transfers. This gives a performance improvement of 10-20%.

4. Bug fixes
a. Analog mux setting on Mega. Failed to read bandgap correctly after using higher analog pin numbers.
b. Improved W5100::Driver::flush() robustness when client or server disconnects.


21  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 01, 2014, 05:22:04 am
Some news on the latest updates in the Cosa project:

1. New pin index to Cosa pin symbol mapping.
In many example sketches there has been a need to map between a pin index to the program level pin symbol. There are two mapping tables available. See

2. More accurate delay when using the RTC class (timer that implement micros() and millis()).
The Cosa global delay() function is a function pointer and can be redefined. The default implementation uses busy-spin. When the Watchdog is used the Watchdog::delay() is installed instead. This gives low power mode during the delay. The Watchdog accuracy is at most 16 ms tick. When the RTC is used it will install the RTC::delay() function which also gives low power mode but also better accuracy (1 ms). The order of calling Watchdog and RTC begin() defines which version is used.

3. Telnet Shell example sketch.
The CosaShell example sketch has been integrated with the Telnet Server sketch to show how to communicate with the shell over Ethernet. Below is a screenshot with left) build, upload and serial monitoring, and right) telnet connection and commands to the shell.

For more details see

22  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 09:43:08 am
Does this mean that I can use the RFM69/nRF24 also to handle 'shell' commands? In other words I can easily create a serial to LAN/WiFi/Radio translator/gateway??
Not really there yet. You need an IOStream::Driver that will use a Wireless Driver for transportation. There is a mockup that does output only. See the example sketch With input handling (i.e. recv) and buffering in the Shell you have all the necessary components for remote commands (at least on the NRF24L01P which has built-in acknowledgement and retransmission).

I am actually working on a telnet and http service that uses the shell. Seems like an interesting challenge. See how much of that ends up in the Cosa source.

BTW: You seem to be working om my secret COSA wish list I have while developing prototype hardware. It's magic  smiley-twist
I have suspected that we have somewhat the same agenda smiley

23  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 07:35:25 am
This is brilliant smiley, thank you for all your hard work.

You are welcome!

I think that the Shell support is now more in line with what you where expecting from the start smiley. The development and refactoring has a lot to do with your input and tests - THANKS. I wanted to start-off with a simple blocking version and move slowly towards non-blocking as in the "final" version. With your input the update and evolution was somewhat faster.

I specifically added the "idle" command to the example sketch (CosaShell) to demonstrate the non-blocking IO and power down sleep that is going on in the background. There are more to be done on scripts; use EEMEM for storage, allow definition as commands, etc, but this will do fine for the release.

Thanks again for collaborating!
24  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2014, 05:30:41 am
The news on the latest updates in Cosa.

1. IOStream
The IOStream class has a new member function to allow simple command line reading; IOStream::readline(buf, size). It will read available characters and append to the given string and return the buffer pointer when the line has been completed. The function will handle backspace, carriage-return and line-feed.

2. Shell
The command line support is now completed. The Shell::run() member function will handle the read, parse and execution of command lines. The function is non-blocking and should be called in the loop(). Below is a screenshot of the example sketch CosaShell. This sketch shows how to setup the shell for serial input, run the top-loop, and how to capture idle time.

As the Shell class uses the new IOStream::readline() function all echo and backspace is handled by this function. Below is a screenshot of using PuTTY with the shell. This is the default PuTTY setting (on Ubuntu).

3. Refactoring
The macro SLEEP (Cosa/Types.h) has been removed and the function sleep() should be used instead.
b. IOBuffer::gets()
This member function has been removed and the default implementation (IOStream::Device) is used instead.
c. IOStream::print(const void *ptr, size_t size, Base base, uint8_t max)
This member function is used to dump memory block. An additional base variant is now available that will prefix each line with a source address (i.e. not the given buffers address).

4. Versioning
The Cosa project does not have explicit versioning as it is non-commercial and sharing but to make it simpler for users there are specific snapshots of source and documentation. For more details see the install description and the section "Download Versions". Please note that using the build script will require some additional configuration. Please see and previous post on this issue.

25  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 27, 2014, 02:55:21 am

Hi Adam. I use this topic of updates on the development of Cosa. There are questions from users and as other forums users mostly help each other. These questions also get mixed up in this topic.

Bugs, errors and feature requests should be posted on the Issues list on github. In general I do not add new boards, modules, devices, etc, that I cannot test or have my own project for.  Pull requests that cannot be tested are not merged (of the same reason).

Now the more interesting question; handling of NEWLINE. Linux LF, Mac CR and PC both CR+LF, and others.

I did some tests with configuration of Putty and the Terminal window setting "Implicit CR in every LF" (and local echo auto) fixes one side of the issue. The other will require adding support for translation (as in many Linux tools). The simple fix was to translate CR to LF in gets().

The more elegant solution is to add a translation setting to IOStream::Device and default to a common standard. The NEWLINE handling needs to be abstracted to all type of devices (e.g. terminal, network, files, etc).

I do not use Putty and I work mostly on Linux/Ubuntu. To get the fastest possible development turn-around I have actually added a build script (modified Arduino-Makefile) and miniterm for serial monitor (also modified). This allows build of only what has changed, upload and starting the serial monitor as a single command. The Arduino IDE build is 3-5 times slower in build. A lot of unnecessary operations are performed as it does not use make.

26  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 26, 2014, 06:32:03 am
A new screenshot of the Cosa Shell example sketch. There are a number of new commands; dump memory, play tone, repeat command lines, etc.

The options parser makes it really easy to write action functions with multiple options and variable number of arguments. Below is a snippet from CosaShell Commands. It implemented the memory dump command which has radix options, memory address and block size:
static const char DUMP_NAME[] __PROGMEM =
static const char DUMP_HELP[] __PROGMEM =
  "[-b|-d] POS [SIZE] -- dump memory";
static int dump_action(int argc, char* argv[])
  IOStream::Base base = IOStream::hex;
  uint32_t addr = 0L;
  size_t size = 256;
  char* option;
  char* value;
  char* sp;
  int ix;
  while ((ix = shell.get(option, value)) == 0) {
    if (strcmp_P(option, PSTR("b")) == 0)
      base = IOStream::bin;
    else if (strcmp_P(option, PSTR("d")) == 0)
      base = IOStream::dec;
      return (-1);
  if (ix < argc) {
    addr = strtoul(argv[ix++], &sp, 16);
    if (*sp != 0) return (-1);
  if (ix < argc) {
    size = strtoul(argv[ix++], &sp, 10);
    if (*sp != 0) return (-1);
  if (ix != argc) return (-1);
  cout.print(addr, (void*) addr, size, base);
  return (0);
The first section uses Shell::get(option, value) to parse the given options. The next section handles possible parameter; memory address to dump from (default 0), and size of memory block (default 256). For more details please see

The Cosa Flash File System (CFFS) shell has also been updated with some new commands:

For more details please see

27  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 25, 2014, 06:07:44 pm

Update available that fixes that for Arduino 1.0.X.

BW: It is better to use the github issues list for this type of problems.

28  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 06:45:39 pm

That is actually exactly the behavior it "should" have right now when the line is too long. The input buffer is limited to 64 characters (in the current version). It is a configuration variable. The error handling could be improved. Please see the configuration constants:

I will see what I can do about that in Shell::run() as the too long command lines will result in multiple gets() calls. These will have to be ignored and reported as an error.

Latest update; The script handling will allow parameter binding (standard shell script syntax, $1 for parameter/option one, etc). Please see the updated CosaShell.ino/Commands.cpp. The script blink will require a delay time parameter (in ms).

29  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 12:38:42 pm
I can see new shell function "execute_P", I believe it is taking the input from the prog mem instead of the buffer? I didn't find it in the online documentation.

That one is easy; my dropbox has not yet synced the latest update. But it should be ready now.

Could you please tell me one more small thing that I didn't find the answer for yet - how to understand the uart blocking and non blocking "uart.set_blocking(SLEEP_MODE_IDLE)" what does it actually do?
The issue is what should uart.gets() do when there is no more characters in the input buffer. The non-blocking behavior is to return directly with what was available. That would require building up the command line until the new-line character is seen.

The set_blocking() tells the device to wait for more characters and return when it receives the new-line. The function gets() will call yield() while waiting for more character. And the actual sleep mode is defined by the implementation of yield(). There are two major implementations of yield(). One that uses power down and the second that does context switches.

Links down the rabbit hole.

30  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 24, 2014, 11:40:09 am

Had some time over today so I did an update :-); small steps forward. Refactored the script execution and improved the handling of string literal parameters (e.g. echo "a string parameter"). There is also a bunch of new commands in the example sketch CosaShell. The scripting looks like this:
#define LF "\n"

static const char BLINK_NAME[] __PROGMEM =
static const char BLINK_HELP[] __PROGMEM =
  "-- turn led on and off";
static const char BLINK_SCRIPT[] __PROGMEM =
  "echo -n \"led on\"" LF
  "led on" LF
  "delay 500" LF
  "echo -n \"\"" LF
  "led off" LF
  "delay 500" LF
  "echo -n \"..on\"" LF
  "led on" LF
  "delay 500" LF
  "echo \"\"" LF
  "led off" LF;
#define blink_action (Shell::action_fn) BLINK_SCRIPT
And the entry in the command table:
static const Shell::command_t command_vec[] __PROGMEM = {
  { BLINK_NAME, blink_action, BLINK_HELP },
A nice next step would be to tie the Shell together with the HTTP::Server and view the URL as a command; "http://..../command?arg1=xxx&arg2=yyy" which then translate to the Shell "command arg1=xxx arg2=yyy".

Pages: 1 [2] 3 4 ... 31