Show Posts
Pages: 1 ... 10 11 [12] 13 14 ... 25
166  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 09, 2013, 06:39:37 pm
Not using Cosa here, but I just have to say this:
This freamework looks great! Well thought out and beautifully written & documented.

My hat is off to you!
@int2str

Thanks for your interest in this project and encouraging words! Please feel free to "take Cosa for a spin" and try some of the available example sketches. I have tried to make it really easy to get started and experience this slightly different approach to programming the Arduino/AVR based boards.

It is possible to start off in the "traditional" sequential and procedural style of Arduino/Wiring and move towards a more object-oriented and event driven style with periodic functions, state-machines and proto-threads. It is a learning curve but the interesting aspect is the possible scaling of systems and the major reduction of the complexity of writing semi-concurrent low-power applications.

Cheers!
167  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 09, 2013, 05:48:11 pm
Hi @englund.

Unfortunately that was an old installation guide (I haven't updated all posts on the forum, just too much work :-(. Cosa is now packaged as an Arduino core and much easier to install. The procedure is in the first post on this topic and in the blog. And below (why wait ;-).

1. Download the Cosa zip from github.
2. Unzip the file in your sketchbook/hardware directory. If you do not have a folder named "hardware" in your sketchbook directory please create one before unzipping. If you want rename "Cosa-master" the default git download to "Cosa". In Windows simply drag the Cosa-master directory from the zip file into the sketchbook/hardware directory.
3. Restart/start Arduino IDE and Cosa will show up as a set of examples and boards.

First test.
1. Connect an Arduino board.
2. Select the Cosa board setting and serial port in the tools menu.
3. Compile the empty sketch.
4. And see the default setup and loop in action - an event driven blink sketch. Here is the code for the empty sketch (all defaults). https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/main.cpp

I will have to get back to you with a guide on how to mix Arduino code with Cosa. This was possible "out of the box" before the packaging as a core. Now there is a bit more moving into directories and there might be some extra stuff. I will be back with the details.

BW: The compiler errors that you are getting are from the mixing of Cosa with Arduino/Wiring in the same sketch. You will need to compile Arduino or Cosa in separate files (classes). The conflicting symbols in your sketch are LED and A0. These are defined in Cosa board (as enum values) and they are define/variable in Arduino pins_arduino.h. Cosa is not really yet another Arduino library. It is more an OOP framework for small scale embedded systems. Cosa offers a clear structure, "architecture", for adding device drivers, etc. It does not use malloc/new, free/delete and is very conservative on SRAM usage. Also the whole framework, all classes, compiles from Tiny to Mighty and Mega. That includes all TWI and SPI drivers, LCD, etc.

What other libraries are you using?

Cheers!

PS: The alternative installation, if you interested in following the project more in detail and know a bit about how git works, is:
1. Create the hardware folder in your sketchbook
2. git clone from github in that directory
3. Frequently do a git pull to keep up to date with the development. Cosa is still moving with new libraries, drivers, etc. More or less weekly additions. Todays update is a Touch sensor. Don't forget to "Watch/Star" on github.
DS.
168  Using Arduino / Displays / Re: Can I change the orientation of LCD to landscape without a headache? on: August 06, 2013, 04:07:12 pm
Hi @edwinforthewin.

That LCD is a ST7735R device which actually has hardware support for handling the addressing (landscape, portrait, mirror, etc). The problem is finding good library support for that and then the real problem is writing the application to scale to the direction (if you want to be able to flip as an "iPad").

Here is a link to the direction change member function in Cosa/ST7735 driver.
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/SPI/Driver/ST7735.cpp#L182

Here is also a link to a demo sketch that flips direction (see line 291);
https://github.com/mikaelpatel/Cosa/blob/master/examples/Canvas/CosaCanvasST7735/CosaCanvasST7735.ino

Cheers!
169  Using Arduino / Sensors / Cosa/DHT11 and DHT22 device driver on: August 06, 2013, 03:23:49 pm
One of the latest improvements and additions to the Cosa Arduino framework is a major rewrite of the DHT11/DHT22 device driver. The new version is interrupt driven and fully integrated with the Cosa event framework. The traditional procedural variant looks like this (CosaDHT).
Code:
DHT11 outdoors(Board::EXT0);
#if !defined(__ARDUINO_TINY__)
DHT22 indoors(Board::EXT1);
#endif

void setup()
{
  // Start trace output stream on the serial port
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaDHT: started"));

  // Check amount of free memory and size of instance
  TRACE(free_memory());
  TRACE(sizeof(DHT));

  // Start the watchdog for low power sleep
  Watchdog::begin();
  RTC::begin();
}

void loop()
{
  // Sample every 2 seconds
  SLEEP(2);

  // Read and print humidity and temperature
#if !defined(__ARDUINO_TINY__)
  indoors.sample();
  trace << PSTR("indoors: ") << indoors << endl;
#endif
  outdoors.sample();
  trace << PSTR("outdoors: ") << outdoors << endl;
}
The output operator<< for DHT11/22 will write the sampled humidity and temperature to the output stream (LCD, Serial, etc). The active object/event driven variant uses the Cosa default loop() function (CosaDHTevent).
Code:
// Example of DHT22 sub-class and periodic member function;
// on_sample_completed() prints current value to the trace stream.
class DHTevent : public DHT22 {
public:
  DHTevent(Board::ExternalInterruptPin pin) : DHT22(pin) {}
  virtual void on_sample_completed() { trace << *this << endl; }
};

// The DHT event object
DHTevent dht(Board::EXT1);

void setup()
{
  // The trace output stream on serial output
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaDHTevent: started"));

  // Watchdog will issue timeout events
  Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);
  RTC::begin();

  // The DHT event object is started with default 2 second period
  dht.begin();
}
A program is viewed as a set of active objects communicating by events. In the example above the DHT object will sample the sensor every 2 seconds and call the on_sample_completed() virtual member function (callback), which in this example does the trace.

For more details see:
1. Github https://github.com/mikaelpatel/Cosa
2. Interface DHT.hh https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Driver/DHT.hh
3. Example sketch CosaDHT https://github.com/mikaelpatel/Cosa/tree/master/examples/Drivers/CosaDHT
4. Example sketch CosaDHTevent https://github.com/mikaelpatel/Cosa/tree/master/examples/Drivers/CosaDHTevent
5. Blog http://cosa-arduino.blogspot.se/
6. On-line documentation http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html

Cheers!
170  Using Arduino / Networking, Protocols, and Devices / Cosa/Manchester Phase Encoding (for RF433) on: August 06, 2013, 03:16:28 pm
One of the latest additions to Cosa is a new light-weight class for Manchester Phase Encoding (MPE) with Transmitter and Receiver for RF433 (supported by all Cosa targets; ATmega328, 168, 1284, 1280, 2560, ATtinyX4, X5). The classes are interrupt driven; timer interrupt for transmitter and external interrupt (change mode) for receiver pulse sequence detection. Below is a snippet for the demo sketches; CosaMPEsender
Code:
#include "Cosa/MPE.hh"
#include "Cosa/Watchdog.hh"

MPE::Transmitter tx(Board::D9);

void setup()
{
  Watchdog::begin();
  tx.begin();
}

void loop()
{
  static uint8_t msg[16] = { 0 };
  tx.send(&msg, sizeof(msg));
  msg[0] += 1;
  Watchdog::delay(16);
}
CosaMPEreceiver.
Code:
#include "Cosa/MPE.hh"
#include "Cosa/IOStream/Driver/UART.hh"
#include "Cosa/Trace.hh"
#include "Cosa/Watchdog.hh"
#include "Cosa/RTC.hh"

MPE::Receiver rx;

void setup()
{
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaMPEreceiver: started"));
  Watchdog::begin();
  RTC::begin();
  rx.begin();
}

void loop()
{
  static uint8_t nr = 0;
  static uint16_t count = 0;
  static uint16_t timeouts = 0;
  static uint16_t errors = 0;
  static uint16_t drops = 0;

  uint8_t buf[MPE::PAYLOAD_MAX];
  int n = rx.recv(buf, sizeof(buf), 1000);
  if (n > 0) {
    count += 1;
    if (buf[0] != nr) {
      drops += 1;
      errors += 1;
      nr = buf[0];
    }
    nr += 1;
    if (count % 100) return;
    ...
  } else if (n == 0)
    timeouts += 1;
  else
    errors += 1;
}

For more details see.
1. Github https://github.com/mikaelpatel/Cosa
2. MPE.hh https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/MPE.hh
3. Example sketch CosaMPEsender https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaMPEsender/CosaMPEsender.ino
4. Example sketch CosaMPEreceiver https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaMPEreceiver/CosaMPEreceiver.ino
5. Blog http://cosa-arduino.blogspot.se/
6. On-line documentation http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html

Cheers!

171  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: August 06, 2013, 03:09:43 pm
Some news on the latest improvements and additions to the Cosa Arduino framework.

1. Major rewrite of the DHT11/DHT22 device driver. Update to an event/interrupt driven version which is fully integrated with the Cosa event framework. The traditional procedural variant looks like this (CosaDHT).
Code:
DHT11 outdoors(Board::EXT0);
#if !defined(__ARDUINO_TINY__)
DHT22 indoors(Board::EXT1);
#endif

void setup()
{
  // Start trace output stream on the serial port
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaDHT: started"));

  // Check amount of free memory and size of instance
  TRACE(free_memory());
  TRACE(sizeof(DHT));

  // Start the watchdog for low power sleep
  Watchdog::begin();
  RTC::begin();
}

void loop()
{
  // Sample every 2 seconds
  SLEEP(2);

  // Read and print humidity and temperature
#if !defined(__ARDUINO_TINY__)
  indoors.sample();
  trace << PSTR("indoors: ") << indoors << endl;
#endif
  outdoors.sample();
  trace << PSTR("outdoors: ") << outdoors << endl;
}
The output operator<< for DHT11/22 will write the sampled humidity and temperature to the output stream (LCD, Serial, etc). The active object/event driven variant uses the Cosa default loop() function (CosaDHTevent).
Code:
// Example of DHT22 sub-class and periodic member function;
// on_sample_completed() prints current value to the trace stream.
class DHTevent : public DHT22 {
public:
  DHTevent(Board::ExternalInterruptPin pin) : DHT22(pin) {}
  virtual void on_sample_completed() { trace << *this << endl; }
};

// The DHT event object
DHTevent dht(Board::EXT1);

void setup()
{
  // The trace output stream on serial output
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaDHTevent: started"));

  // Watchdog will issue timeout events
  Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);
  RTC::begin();

  // The DHT event object is started with default 2 second period
  dht.begin();
}
A program is viewed as a set of active objects communicating by events. The above example the DHT object will sample the sensor every 2 seconds and call the on_sample_completed() virtual member function (callback), which in this example does the trace.

Cheers!
172  Using Arduino / Displays / Re: LiquidCrystal_SR3W Wiring E to the Strobe Pin on: August 01, 2013, 05:58:55 pm
You keep saying SDA, but do you mean the MOSI pin on the Arduino? Are you using SPI or just GPIO pins?
Also, that is a pretty good implementation, using SDA for RS. This keeps complexity of the circuit lower, but adds complexity to your code + requires more pins.
Actually it was your two SR solution that got me thinking about the possible pipelining as the 4-bit SR variant did not produce as good numbers as what you had shown. I had excepted better pipelining but there was a requirement of a 37 us delay also for the first nibble and not just for the last when the full byte has been transfered. After that I just did some "research", found the above solution for PIC and refactored it.

Had to breadboard the solution twice before I understood how to get the 8-bit LCD initialization working ;-)

SDA is just my pin naming convention (Serial DAta). Sorry about the bad naming. The version above, SR4W, is soft SPI, i.e. GPIO pins. Will be adding the SPI version soon. Not much to change and no big difference in speed. Just more delay ;-). For SPI SDA will translate to MOSI.

The added complexity is a single line "m_sda.write(m_rs)". And there are no extra pins required except for the back-light.

Actually (I believe) the SDA signal can be reused again for the BT after the EN pulse. This will give a possible flicker but some of that can be removed with a capacitor between the base and ground on the back-light power transistor. But then again the back-light is always on in many applications.

Off topic question, how do you make these ASCII schematics?
Hum, the ASCII schematics...., I just copied @bperrybap and changed a few lines. Might be a tool for that.

BW I implemented a LCD port adapter for the ERM1602-5 which is a 1602 with built-in SPI. It uses 3-wires (CS, MOSI, SCK) and an extra signal for back-light. No RS. Instead there is a special command for data transfer. To send a character (if previously in instruction mode) the driver must send a FUNCTION_SET command for extended mode switch, a SET_DATA_LENGTH command and then the data/character. Improving performance here is an interesting challenge ;-) even if SPI ;-)

Cheers!
173  Using Arduino / Displays / Re: LiquidCrystal_SR3W Wiring E to the Strobe Pin on: August 01, 2013, 05:24:32 pm
After working the latest week with different port adapters for the HD44780 this it the fastest SR version I have implemented (so far). Below is the wiring of the SR4W 3-wire plus back-light control/8-bit parallel LCD adapter using a single 74HC595 Shift Register.
Code:
  *                         74HC595    (VCC)
   *                       +----U----+    |
   * (LCD D1)------------1-|Q1    VCC|-16-+
   * (LCD D2)------------2-|Q2     Q0|-15-----------(LCD D0)
   * (LCD D3)------------3-|Q3    /OE|-13-----------(GND)  
   * (LCD D4)------------4-|Q4    SER|-14-----------(SDA)
   * (LCD D5)------------5-|Q5   RCLK|-12-----------(EN)
   * (LCD D6)------------6-|Q6   SCLK|-11-----------(SCL)
   * (LCD D7)------------7-|Q7    /MR|-10-----------(VCC)
   *                   +-8-|GND   Q6'|-9
   *                   |   +---------+
   *                   |      0.1uF
   *                 (GND)-----||----(VCC)
   * (LCD RS)---------------------------------------(SDA)
   * (LCD EN)---------------------------------------(EN)
   * (LCD BT)---------------------------------------(BT)
   * (LCD RW)---------------------------------------(GND)
The byte write operation for this adapter in Cosa is simply:
Code:
void
HD44780::SR4W::write8b(uint8_t data)
{
  m_sda.write(data, m_scl);
  m_sda.write(m_rs);
  m_en.toggle();
  m_en.toggle();
  DELAY(SHORT_EXEC_TIME);
}
The first write() operation will transfer (shiftout) the data to the SR using SDA and SCL. The second write() will use the SDA pin to set the current RS value (m_rs) before toggling the LCD enable signal (EN). The delay is necessary so that there is at least 37 us between two enable pulses. The loading of the next byte to the SR is done in parallel with the LCD execution of the previous (pipelining).

Inspired by AVR2LCD, a solution by Frank Henriquez. The original 74HC164 based design is by Stefan Heinzmann and Marc Simons. http://frank.bol.ucla.edu/avr2lcd.htm, http://web.archive.org/web/20100210142839/http://home.iae.nl/users/pouweha/lcd/lcd_examp.shtml#_3

Cheers!
174  Using Arduino / Displays / Re: LCD keypad shields on: August 01, 2013, 04:56:54 pm
@Gustermaximus

Thanks for providing the code. Much easier and you don't have to read my "hand waving". Your program is  "small" and the libraries do help with some of the complexity.

First thing to check is the DHT library and that the delay is not active there. There is a version that does a delay of up to 2 seconds between samples.

Second thing to do is write a small test sketch that only uses the keypad and serial output and verify that it isn't a hardware problem.

I'll took a second look at the keypad library code and, hum, you might want to twiddle with the DFR_Key DEFAULT_THRESHOLD (static int DEFAULT_THRESHOLD = 5) it might be a little low. I don't like the logic in the get_key() function. It is possible to have a key reading that is not read.

Cheers!
175  Using Arduino / Displays / Re: Cosa/Boosting LCD 1602 performance (7X SR4W, 6.5X 4-bit parallel, 1.7-2.3X I2C) on: August 01, 2013, 03:42:11 pm
Here are the footprints (program memory sizes) for the different Cosa LCD port adapters and drivers for a "Hello World" style of test program (Arduino Mega, Uno and ATtiny84 build):
Code:
/ Binary sketch size:  MEGA/STD*/TINY bytes
// =========================================
// Baseline: 780/ 656/ 558 bytes
// HD44780::Port4b: 3618/3448/3310 bytes
// HD44780::SR3W: 4534/4364/4220 bytes
// HD44780::SR3WSPI: 3858/3744/3504 bytes
// HD44780::SR4W: 4054/3872/3712 bytes
// HD44780::MJKDZ: 5106/5012/5568 bytes
// HD44780::DFRobot: 5076/4982/5538 bytes
// PCD8544: 4458/4322/4004 bytes
// ST7565:   4830/4710/4394 bytes
// VLCD: 4008/3948/4370 bytes
The sketch is (https://github.com/mikaelpatel/Cosa/blob/master/examples/LCD/CosaLCDsize/CosaLCDsize.ino)
Code:
#include "Cosa/Watchdog.hh"
#include "Cosa/LCD/Driver/HD44780.hh"
HD44780::Port4b port;
// HD44780::SR3W port;
// HD44780::SR3WSPI port;
// HD44780::SR4W port;
// HD44780::MJKDZ port;
// HD44780::DFRobot port;
HD44780 lcd(&port);

// #include "Cosa/LCD/Driver/PCD8544.hh"
// PCD8544 lcd;

// #include "Cosa/LCD/Driver/ST7565.hh"
// ST7565 lcd;

// #include "Cosa/VLCD.hh"
// VLCD lcd;

void setup()
{
  Watchdog::begin();
  lcd.begin();
  lcd.puts_P(PSTR("Hello World!"));
}

void loop()
{
}
The HD44780::MJKDZ and HD44780::DFRobot port use the I2C IO Expander and include the TWI driver. For ATtiny this will include an USI/software implementation which increases the footprint. The SR3W implementation uses full loop unrolling which increases performance at the price of footprint.

Please note that the PCD8544 and ST7565 LCD device drivers also include a system font in program memory.

Cheers!
176  Using Arduino / Displays / Re: LCD keypad shields on: August 01, 2013, 03:22:31 pm
I would say that this is a perfect example of what is wrong with the Arduino/Wiring programming paradigm and the challenges that it gives. Any "larger" embedded system will contain several tasks/threads; in your case at least 1) monitor the keypad, 2) sample the sensors, 3) do some logging and/or calculations, 4) handle the display, and 5) service communication with host/network.

Doing this as a pure sequential program is difficult and it is easy to miss external events, mix-up states, etc. This can occur when sampling the sensors, etc. Or even when updating the LCD. Remember that clearing a 1602 LCD takes over 2 ms.

Now this is not helping you ;-) or even giving any advice.

What could you do? Here I have to do some guessing as you have not provided any code.

The first advice I would give you is sample the keypad with a periodic event (timer).  You could also use a pin change interrupt handler but the keypad is actually implemented with a resistor net and sampled with an analog pin which makes this "difficult".

BW: Sampling the analog pin takes over 100 us. So it all adds up.

Cheers!

PS: You could look at this and dig into Cosa for some inspiration. Cosa is a totally different programming paradigm. http://forum.arduino.cc/index.php?topic=178395.0 
177  Development / Other Software Development / Re: C++ Problem with Wire.OnReceive() on: August 01, 2013, 10:01:54 am
Hi!

The compiler is telling you exactly what the problem is. The error message is perfect ;-) If you check the specification of onReceive() you will see that it takes a callback function as parameter. Not an object and not a member function.

Code:
    void onReceive( void (*)(int) );

Define _on_wire_message_recevied() as static and it will compile BUT remember that there is no context ("this" is not valid in a static member function). A static member function cannot reference member variables.

There is an example sketch in arduino/libraries/Wire/examples. See slave_receiver.ino.

Cheers!
178  Using Arduino / Displays / Re: Cosa/Boosting LCD 1602 performance (7X SR4W, 6.5X 4-bit parallel, 1.7-2.3X I2C) on: July 31, 2013, 06:31:53 pm
Below is the wiring of the SR4W 3-wire plus back-light control/8-bit parallel LCD adapter using a single 74HC595 Shift Register.
Code:
  *                         74HC595    (VCC)
   *                       +----U----+    |
   * (LCD D1)------------1-|Q1    VCC|-16-+
   * (LCD D2)------------2-|Q2     Q0|-15-----------(LCD D0)
   * (LCD D3)------------3-|Q3    /OE|-13-----------(GND)  
   * (LCD D4)------------4-|Q4    SER|-14-----------(SDA)
   * (LCD D5)------------5-|Q5   RCLK|-12-----------(EN)
   * (LCD D6)------------6-|Q6   SCLK|-11-----------(SCL)
   * (LCD D7)------------7-|Q7    /MR|-10-----------(VCC)
   *                   +-8-|GND   Q6'|-9
   *                   |   +---------+
   *                   |      0.1uF
   *                 (GND)-----||----(VCC)
   * (LCD RS)---------------------------------------(SDA)
   * (LCD EN)---------------------------------------(EN)
   * (LCD BT)---------------------------------------(BT)
   * (LCD RW)---------------------------------------(GND)
The byte write operation for this adapter in Cosa is simply:
Code:
void
HD44780::SR4W::write8b(uint8_t data)
{
  m_sda.write(data, m_scl);
  m_sda.write(m_rs);
  m_en.toggle();
  m_en.toggle();
  DELAY(SHORT_EXEC_TIME);
}
The first write() operation will transfer (shiftout) the data to the SR using SDA and SCL. The second write() will use the SDA pin to set the current RS value (m_rs) before toggling the LCD enable signal. The delay is necessary so that two enable pulses are at least 37 us a part. The loading of the next byte to the SR is done in parallel with the execution delay of the previous (pipelining).

Cheers!
179  Using Arduino / Displays / Re: How to connect 4 pin LCD? on: July 31, 2013, 02:41:02 pm
Try the I2C Address: 0x3F

Cheers!

Ref. http://forum.arduino.cc/index.php?topic=128635.0
180  Development / Other Software Development / Re: New fork of the IDE on: July 31, 2013, 12:50:10 pm
@pito @majenko

That is my bad. The CosaBenchmarkPins.ino should have been updated when the Cosa core was introduced. It isn't possible to compile the benchmark with comparison with the arduino core as those files are not available (as the compiler correctly reports).

I think it is time to remove the comparison with Arduino/Wiring. We know the numbers and the issues :-)

There will be an update shortly. Sorry about that.

Cheers!

Pages: 1 ... 10 11 [12] 13 14 ... 25