Go Down

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


And I could help you a bit - without obligations from your side - by solving your first problem in getting some modules if you want...

That would help ;-). The RFM69 was not (yet?) a very popular wireless module on ebay. Actually more or less a single US based seller.

Yep, there seems to be just one US based seller of these modules who doesn't even sell the 868MHz EU versions...

If you PM me some address, and wait some days (probably a few more due to new year), you should be able to welcome a few modules in their new home in 2014  ;)


I just wanted to pass along a huge THANK YOU for all of your amazing work on Cosa.  I have been using your framework exclusively for all my projects and have really enjoyed watching the mind-boggling progress over the past year.  I also wanted to thank you specifically for taking time to trouble-shoot and answer some of my elementary questions as I greatly appreciate it!  How can I buy you a beer?



Many, many THANKS back to you and all for testing and support this project. Without your effort testing different parts of Cosa it would not have evolved as much as it has. Your questions help improve documentation, abstractions and give a better understand for typical usage patterns - not to mention all the encouragements!

Great year with a lot of fun. Hope to be able to find as much time next year and continue the work on the blog, more demo code and documentation.

Cheers! And a Happy New Year.


Jan 05, 2014, 08:14 pm Last Edit: Jan 06, 2014, 02:02 am by kowalski Reason: 1
Cosa is approaching a first major release. It contains over 150 classes and over 30 SPI/TWI device drivers (35+ KLOC in total). Below is a complete list of classes (without internal implementation classes). These range from object-oriented Digital and Analog Pin abstractions to Wireless devices and application frameworks.  
Code: [Select]

BitSet.hh:class BitSet
Button.hh:class Button
Canvas.hh:class Canvas
Canvas.hh:  class Context
Canvas.hh:  class Element
Ciao.hh:class Ciao
Ciao.hh:  class Descriptor
EEPROM.hh:  class Device
Event.hh:class Event
Event.hh:  class Handler
ExternalInterrupt.hh:class ExternalInterrupt
Fai.hh:class Fai
Fai.hh:  class Descriptor
FixedPoint.hh:class FixedPoint
FSM.hh:class FSM
Interrupt.hh:class Interrupt
Interrupt.hh:  class Handler
IOBuffer.hh:class IOBuffer
IOStream.hh:class IOStream
IOStream.hh:  class Device
IOStream.hh:  class Filter
IR.hh:class IR
IR.hh:  class Receiver
Keypad.hh:class Keypad
Keypad.hh:class LCDKeypad
LCD.hh:class LCD
LCD.hh:  class Device
LED.hh:class LED
Linkage.hh:class Linkage
Linkage.hh:class Link
Linkage.hh:class Head
Listener.hh:class Listener
Menu.hh:class Menu
Menu.hh:  class Action
Menu.hh:  class Walker
Menu.hh:  class KeypadController
Menu.hh:  class RotaryController
OWI.hh:class OWI
OWI.hh:  class Driver
OWI.hh:  class Search
Periodic.hh:class Periodic
PinChangeInterrupt.hh:class PinChangeInterrupt
Pins.hh:class Pin
Pins.hh:class InputPin
Pins.hh:class OutputPin
Pins.hh:class PWMPin
Pins.hh:class IOPin
Pins.hh:class AnalogPin
Pins.hh:class AnalogPins
Pins.hh:class AnalogComparator
Power.hh:class Power
ProtocolBuffer.hh:class ProtocolBuffer
Queue.hh:class Queue
Registry.hh:class Registry
Registry.hh:  class Iterator
Registry.hh:  class Action
Rete.hh:class Rete
Rete.hh:  class Device
Rete.hh:  class Manager
Rotary.hh:class Rotary
Rotary.hh:  class Encoder
Rotary.hh:    class SignalPin
Rotary.hh:  class Dial
Rotary.hh:  class AcceleratedDial
RTC.hh:class RTC
Servo.hh:class Servo
SPI.hh:class SPI
SPI.hh:  class Driver
SPI.hh:  class Slave
Thread.hh:class Thread
Touch.hh:class Touch
Trace.hh:class Trace
TWI.hh:class TWI
TWI.hh:  class Driver
TWI.hh:  class Slave
Watchdog.hh:class Watchdog
Wireless.hh:class Wireless
Wireless.hh:  class Driver
AVR/Programmer.hh:class Programmer
AVR/STK500.hh:class STK500
Canvas/Font.hh:class Font
Canvas/GLCDFont.hh:class GLCDFont
Canvas/OffScreen.hh:class OffScreen
Canvas/UTFTFont.hh:class UTFTFont
Cipher/Base64.hh:class Base64
Cipher/RC4.hh:class RC4
Cipher/Vigenere.hh:class Vigenere
Driver/DHT.hh:class DHT
Driver/DHT.hh:class DHT11
Driver/DHT.hh:class DHT22
Driver/DS1302.hh:class DS1302
Driver/HCSR04.hh:class HCSR04
Driver/NEXA.hh:class NEXA
Driver/NEXA.hh:  class Receiver
Driver/NEXA.hh:  class Transmitter
FS/FAT16.hh:class FAT16
FS/FAT16.hh:  class File
Soft/SPI.hh:  class SPI
Soft/SPI.hh:    class Driver
Soft/UART.hh:  class UART
USI/TWI.hh:class TWI
USI/TWI.hh:  class Driver
USI/TWI.hh:  class Slave
Canvas/Driver/ST7735.hh:class ST7735
Canvas/Element/Textbox.hh:class Textbox
Canvas/Font/FixedNums8x16.hh:class FixedNums8x16
Canvas/Font/Segment32x50.hh:class Segment32x50
Canvas/Font/System5x7.hh:class System5x7
IOStream/Driver/CDC.hh:class CDC
IOStream/Driver/RS485.hh:class RS485
IOStream/Driver/UART.hh:class UART
IOStream/Driver/WIO.hh:class WIO
LCD/Driver/HD44780.hh:class HD44780
LCD/Driver/HD44780.hh:  class IO
LCD/Driver/HD44780.hh:  class Port4b
LCD/Driver/HD44780.hh:  class SR3W
LCD/Driver/HD44780.hh:  class SR3WSPI
LCD/Driver/HD44780.hh:  class SR4W
LCD/Driver/HD44780.hh:  class MJKDZ
LCD/Driver/HD44780.hh:  class GYIICLCD
LCD/Driver/HD44780.hh:  class DFRobot
LCD/Driver/HD44780.hh:  class ERM1602_5
LCD/Driver/PCD8544.hh:class PCD8544
LCD/Driver/ST7565.hh:class ST7565
LCD/Driver/VLCD.hh:class VLCD
LCD/Driver/VLCD.hh:  class Slave
OWI/Driver/DS18B20.hh:class DS18B20
OWI/Driver/DS18B20.hh:  class Search
SPI/Driver/SD.hh:class SD
TWI/Driver/ADXL345.hh:class ADXL345
TWI/Driver/AT24CXX.hh:class AT24CXX
TWI/Driver/AT24CXX.hh:class AT24C32
TWI/Driver/AT24CXX.hh:class AT24C64
TWI/Driver/AT24CXX.hh:class AT24C128
TWI/Driver/AT24CXX.hh:class AT24C256
TWI/Driver/AT24CXX.hh:class AT24C512
TWI/Driver/BMP085.hh:class BMP085
TWI/Driver/DS1307.hh:class DS1307
TWI/Driver/DS3231.hh:class DS3231
TWI/Driver/HMC5883L.hh:class HMC5883L
TWI/Driver/L3G4200D.hh:class L3G4200D
TWI/Driver/MPU6050.hh:class MPU6050
TWI/Driver/PCF8574.hh:class PCF8574
TWI/Driver/PCF8574.hh:class PCF8574A
TWI/Driver/PCF8591.hh:class PCF8591
Wireless/Driver/CC1101.hh:class CC1101
Wireless/Driver/NRF24L01P.hh:class NRF24L01P
Wireless/Driver/VWI.hh:class VWI
Wireless/Driver/VWI.hh:  class Codec
Wireless/Driver/VWI.hh:  class Receiver
Wireless/Driver/VWI.hh:  class Transmitter

Cosa is implemented as an Arduino 1.0.5 "core" and replaces the standard Arduino/Wiring core. All ATmega328P (Uno, Nano,...), ATmega2560 (Mega), ATmega1284 (Mighty) and ATmega32u4 (Leonardo, Micro,...) Arduino based boards are supported together with support for ATtinyX4, ATtinyX5, ATtinyX61 within this single core. The devices drivers and processor module abstractions are available across all processors (where the HW supports them). Cosa is one of the  most complete platforms for Arduino board programming.

Please see documentation on github and blog for more details.
1. https://github.com/mikaelpatel/Cosa
2. http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html
3. http://cosa-arduino.blogspot.se/



Jan 06, 2014, 01:15 am Last Edit: Jan 06, 2014, 01:20 am by Graynomad Reason: 1
Just to show that I'm paying attention,

ATmega1248 (Mighty)

Is that ATmega1284?

EDIT: And ATmega368P

Rob Gray aka the GRAYnomad www.robgray.com


Just to show that I'm paying attention,

Thanks Rob. Corrected that. Just too many numbers ;-) Cheers!


Cosa may now be used with both major versions of the Arduino IDE (1.05 and 1.5.5). The configuration files have been updated so that both environments are supported. The installation procedure for 1.5.5 will require an additional directory level to be created. Please see the installation instructions on github and/or the blog.

Thanks to @Jantje for convincing me that this update was a "piece-of-cake". 




Jan 17, 2014, 09:41 pm Last Edit: Jan 19, 2014, 04:26 pm by kowalski Reason: 1
Here is a short update on the latest development in the Cosa project.

1. RFM69W/HW device driver.
The device driver implements the Cosa Wireless interface.

2. Socket Interface
Updated version of the Cosa Socket Interface with IOStream::Device as base class. Allows stream output to sockets. Default implementation of IOStream::read/write are Socket::recv/send.

3. W5100 Ethernet Controller device driver
Implementation of the Socket interface for the W5100. Allows streamed construction of messages in the device internal TX buffer before transmission (flush). Please see CosaWebServer.ino for an example of usage. Note that even though the stream output is several lines only a single message is transmitted.

4. W5100 example sketches
CosaWebClient https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaWebClient/CosaWebClient.ino
CosaWebServer https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaWebServer/CosaWebServer.ino

5. Allow compiling outside the Arduino IDE
Update to the Cosa Types definitions so that the source code tree may be compiled with more traditional tools. Contribution by ericyanush https://github.com/mikaelpatel/Cosa/pull/93

6. Refactoring of the Pin Change Interrupt class
Contribution by SlashDevin https://github.com/mikaelpatel/Cosa/pull/95

7. SPI interrupt handler
Fixed bug in enable/disable of SPI device interrupt handler chain.



Jan 19, 2014, 09:03 am Last Edit: Jan 19, 2014, 09:11 am by solderspot Reason: 1
Cosa seems very substantial. However, looking at the API docs and some examples it's very hard to get a good understanding of the overall system. Is it preemptive scheduling or co-routine? (I'm assuming it's more co-routine than anything else.) There is not explicit explanation of how it works. Saying something is an "Event driven" system is quite a broad definition.

Maybe someone who is converse in Cosa can show how they would implement the following code in the Cosa paradigm: https://github.com/solderspot/WallieBot/blob/master/WallBot_v2/WallBot_v2.ino

I am currently looking at moving over to an RTOS system but maybe Coas is all I need? I certainly like the ideas of contributing to an actively ongoing project rather than starting something new.

One of the next steps in my robotics project is to add support for quadrature encoders, and, using PID control, to ensure more accurate navigation. This either requires writing interrupt routines or a high priority service thread to measure the encoder inputs. Not sure how I would do this in Cosa. Are there existing drivers for this?

Either way I will download and try out Cosa. Hopefully it's as useful as it looks. I'm certainly impressed with the work done so far. Very well done! I'd appreciate any feedback from experienced Cosa developers.

All the best,

[P.S.: There is an explanation of the wallbot code here: http://solderspot.wordpress.com/2014/01/12/wall-bot-version-2 . It is a very simple "check distance and control motors" sketch. My only complaint is that the servo control is very jerky due to scattered delay() calls in the code.]


Jan 19, 2014, 01:14 pm Last Edit: Jan 19, 2014, 01:16 pm by MarsWarrior Reason: 1
Cosa uses proto threads and is not an RTOS!

To understand the possibilities of concurrency using PT I would say check this example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkThread/CosaBenchmarkThread.ino#L50

You will see how three concurrent threads are using different delays, but do not block each other!

In the past I have used parts of Cosa in ChibiOS / NilRTOS, but then you have to know what you are doing to avoid conflicts between real RTOS threads and Cosa PT, ie I only used ChibiOS threads and Cosa objects running in a certain thread!


Jan 19, 2014, 04:55 pm Last Edit: Jan 27, 2014, 12:24 am by kowalski Reason: 1
The second increment of the Socket/W5100 WIZnet Ethernet Controller device driver is now available. This update contains several optimizations.

1. IOStream::Device base class
The Socket interface has been updated to allow IOStream operations direct to a Socket device driver. The default implementation maps read/write to send/recv.

2. Message streaming
The new Socket interface allows messages to be constructed directly in the W5100 transmit buffer memory. The message is either sent when the maximum message size is exceeded or on a flush/send operation. The W5100 contains 16 Kbyte memory that may be used for TX/RX buffer for the four internal sockets. On small scale embedded devices such as the Arduino AVR it is a great advantage to be able to construct messages directly to these internal buffers instead of using valuable SRAM or sending very small IP messages. It is  important to reduce the number of messages (send operations) to achieve high performance and reliability.

Below is a snippet from CosaWebServer.ino to give an idea of the style of programming that is allowed.
Code: [Select]

 // Bind the socket to an iostream
 IOStream page(sock);
 uint8_t mac[6];
 uint8_t ip[4];
 uint16_t port;

 // Get connection information
 sock->get_dest(mac, ip, port);
 // Reply page; header and footer are static, contents dynamic
 static const char header[] PROGMEM =
   "HTTP/1.1 200 OK" CRLF
   "Content-Type: text/html" CRLF
   "Connection: close" CRLF
   "Refresh: 5" CRLF CRLF
   "<HTML>" CRLF
   "<HEAD><TITLE>CosaWebServer</TITLE></HEAD>" CRLF
   "<BODY>" CRLF;
 static const char footer[] PROGMEM =
   "</BODY>" CRLF
 static const char BR[] PROGMEM =
   "<BR/>" CRLF;

 // Construct the page; header-contents-footer
 page << header;
 for (uint8_t i = 0; i < 14; i++)
   page << PSTR("D") << i << PSTR(": ") << InputPin::read(i) << BR;
 for (uint8_t i = 0; i < 4; i++)
   page << PSTR("A") << i << PSTR(": ") << AnalogPin::sample(i) << BR;
 page << PSTR("Vcc (mV): ") << AnalogPin::bandgap() << BR;
 page << PSTR("Memory (byte): ") << free_memory();
 page << PSTR("(") << setup_free_memory << PSTR(")") << BR;
 page << PSTR("Uptime (s): ") << Watchdog::millis() / 1000 << BR;
 page << PSTR("Requests: ") << nr++ << BR;
 page << PSTR("MAC: ") << mac[0];
 for (uint8_t i = 1; i < 6; i++) page << PSTR(".") << mac[i];
 page << BR;
 page << PSTR("IP: ") << ip[0];
 for (uint8_t i = 1; i < 4; i++) page << PSTR(".") << ip[i];
 page << BR;
 page << PSTR("PORT: ") << port << BR;
 page << footer;
 page << flush;

The generated output can be debugged by using telnet to the webserver port. See command example and output below:
Code: [Select]

$ telnet 80
Connected to
Escape character is '^]'.
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Refresh: 5

D0: 1<BR/>
D1: 1<BR/>
D2: 1<BR/>
D3: 0<BR/>
D4: 0<BR/>
D5: 0<BR/>
D6: 0<BR/>
D7: 0<BR/>
D8: 0<BR/>
D9: 0<BR/>
D10: 1<BR/>
D11: 1<BR/>
D12: 1<BR/>
D13: 0<BR/>
A0: 249<BR/>
A1: 202<BR/>
A2: 175<BR/>
A3: 126<BR/>
Vcc (mV): 3362<BR/>
Memory (byte): 1259(1281)<BR/>
Uptime (h:m:s): 0:3:58<BR/>
Requests: 49<BR/>
PORT: 34400<BR/>
</HTML>Connection closed by foreign host.



Jan 24, 2014, 12:25 pm Last Edit: Jan 24, 2014, 02:44 pm by kowalski Reason: 1
The third increment of the Socket/W5100 WIZnet Ethernet Controller device driver is now available. This update contains the following improvements:

1. INET class
A new static class has been introduced to collect the common Ethernet address specification and access functions; parsing, format transformation and print-out.
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET.hh

2. Socket/W5100 device driver
a. New socket interface access function for client address access; MAC, IP and port.
b. Code footprint reduction (W5100, approx. 200 byte).
c. Correct handling of dynamic port numbering for TCP/UDP.
d. Improved connection-less message handling (UDP).
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket.hh, https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket/Driver/W5100.hh

3. Domain Name System (DNS) client
New class for handling of DNS requests; gethostbyname() function.
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/DNS.hh
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaDNS/CosaDNS.ino

4. WebServer sketch
Next step in the example web server sketch. SRAM requirement (stack/local variables) reduced to under 50 bytes while generating web-page.
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaWebServer/CosaWebServer.ino

Additional improvements:

1. ATtiny pin map documentation
The ATtiny board documentation has be updated with the pin map (textual graphical). Suggestion by hasse_bjork.
ATtinyX4: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Board/TinyX4.hh#L29
ATtinyX5: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Board/TinyX5.hh#L29
ATtinyX61: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Board/TinyX61.hh#L29

2. Cosa Types; Support for network byte order
Improved support for mapping between host and network byte order; ntoh/hton functions.



Jan 26, 2014, 12:57 pm Last Edit: Jan 27, 2014, 12:21 am by kowalski Reason: 1
The latest update of the INET/Socket/W5100 WIZnet Ethernet Controller device driver contains the following improvements:

1. DHCP client.
A Dynamic Host Configuration Protocol (DHCP) client.
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/DHCP.hh
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaDHCP/CosaDHCP.ino

2. Socket interface update.
Some additional member functions to better support send/write of data stored in program memory (e.g. fixed message header) have been introduced.

3. W5100 device driver update.
New member function to allow binding of network address and subnet mask later with for instance DHCP. Better support for message parsing. Please see implementation of DHCP for an example (DHCP::recv, https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/DHCP.cpp#L113). Futher reduction of code footprint.

4. Telnet server port trace output.
A new example sketch is added to demonstrate simple binding of trace output to a telnet session. Carriage-return will toggle the trace mode and the command "exit" will close the session. The trace output contains; timestamp, digital pins, analog pins, power supply voltage and free memory. Example run below:
Code: [Select]

$ telnet
Connected to
Escape character is '^]'.

trace off

trace on
Connection closed by foreign host.

Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaTelnetServer/CosaTelnetServer.ino



Some more updates to the Cosa Socket/Ethernet Controller (WIZnet W5100) support:

1. Integration of DHCP with the W5100 device driver.
A new W5100 device driver member function is introduced to allow DHCP based network address assignment and other network information (subnet mask, gateway and DNS network  address).
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket/Driver/W5100.hh#L605
Example: https://github.com/mikaelpatel/Cosa/blob/master/examples/Ethernet/CosaNTP/CosaNTP.ino#L52

2. Network Time Protocol (NTP) client.
Client access to network time server. Integrated with the Cosa time_t data type to allow synchronization/setting of RTC such as DS1307 and DS3231.
Interface: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/INET/NTP.hh
Example: As above.

3. Cosa Time support class update
New data type clock_t introduced. This data type is seconds from NTP Epoch. New time_t constructor to allow conversion from clock_t to time_t and easy update of RTC/print out.
Interface https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Time.hh
Example: As above.



First of all....THANKS a lot for your effort in this library! Beeing new to Arduino/Microproc programming,  cosa makes - in combination with the STL port - my life much easier!

I'm allmost finished with my DRO project for my mill and lathe - and considering to port it to cosa.

1. I see, you have a rotary implementiation which is useful for hand rotated encoders. I believe, from looking at your code, that the rotary class probably doesnt perform enough for high speed rotary/quadratur  encoders -and lost steps are not detected/reported (which is a must for DROs).  Is there already another class built into cosa ? If not, i happily provide my implementation for that.

2.   I'm using the u8gLib  for my displays (SSD1306, ST7920, 2004) - but non of them seem to be supported in cosa.  Ok, not a big deal -  just a bit of coding effort. But, did you ever tought about using u8g for cosa as well ?

thats it for the moment - need to play with cosa :) And thanks again for that work (even tough you are going to make a lot of my code obsolete ;)

Go Up