Show Posts
Pages: 1 ... 15 16 [17] 18 19 ... 30
241  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!
242  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!
243  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!
244  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 
245  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!
246  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!
247  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
248  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!

249  Using Arduino / Displays / Re: Cosa/Boosting LCD 1602 performance (6.5X 4-bit parallel, 1.7-2.3X I2C) on: July 31, 2013, 10:30:47 am
Some news on the Cosa HD44780 LCD device driver. Two new port adapters have been added.

a. Support for the ERM1602-5 serial interface (SPI).

b. Support for SR4W, 4-wire/8-bit parallel shift register (74HC595) based port. The fastest port adapter yet with an average byte transfer time of 44 us (using Cosa Pin functions and not SPI (yet)). This is over 7X faster that the original LiquidCrystal library with a 74HC595 for $0.20. Below is the wiring. The tricks are i) reusing SDA for the RS signal when pulsing EN, ii) using EN for both the SR latch and LCD enable signal.  

Cheers!
250  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 31, 2013, 10:17:23 am
Some news on the latest improvements and updates to Cosa.

1. Two more HD44780 LCD port adapters have been added.
a. Support for the ERM1602-5 serial interface (3-wire+backlight control).
b. Support for SR4W, 3-wire+backlight control/8-bit parallel shift register (74HC595) based port. The fastest port adapter yet with an average byte transfer time of 44 us (using Cosa Pin functions and not SPI (yet)). This is over 7X faster that the original LiquidCrystal library with a 74HC595 for $0.20. Below is the wiring. The tricks are i) reusing SCL for the RS signal when pulsing EN, ii) using EN for both the SR latch and LCD enable signal.  
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 LCD port adapter 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);
}

2. Cryptographer support. See example/test sketches.
a. Vigenere autokey cipher (1 us per byte). The inner core of the algorithm is the following inline function:
Code:
 char encrypt(char c)
  {
    char res = c + m_key[m_nr++];
    if (m_max != N) m_key[m_max++] = c;
    if (m_nr == N) m_nr = 0;
    return (res);
  }
The line with "if (m_max != N)..." gives the autokey behavior, i.e., the password/phrase and the beginning of the message form the key. Vigenere autokey method requires key size plus 3 bytes.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Cipher/CosaVigenere/CosaVigenere.ino
b. RC4 (2,2 us per byte). The inner core of this method is:
Code:
 char encrypt(char c)
  {
    m_y = m_y + m_state[++m_x];
    uint8_t tmp = m_state[m_x];
    m_state[m_x] = m_state[m_y];
    m_state[m_y] = tmp;
    uint8_t ix = m_state[m_x] + m_state[m_y];
    return (c ^ m_state[ix]);
  }
https://github.com/mikaelpatel/Cosa/blob/master/examples/Cipher/CosaRC4/CosaRC4.ino
RC4 requires more memory; 256 byte state table plus 2 bytes (index m_x/y).

3. I2C/TWI bus scanner. A Cosa version is available. See examples/TWI/CosaTWIscanner. And this is what is looks like.
Code:
#include "Cosa/TWI.hh"
#include "Cosa/IOStream.hh"
#include "Cosa/IOStream/Driver/UART.hh"

IOStream cout(&uart);

void setup()
{
  uart.begin(9600);
  for (uint8_t addr = 3; addr < 128; addr++) {
    twi.begin();
    uint8_t data;
    int count = twi.read(addr, &data, sizeof(data));
    twi.end();
    if (count == sizeof(data)) {
      cout << PSTR("device = ") << hex << addr
   << PSTR(":group = ") << (addr >> 3) << '.' << (addr & 0x07)
   << endl;
    }
  }
}

void loop() {}
Typical output:
Code:
device = 0x1e:group = 3.6
device = 0x27:group = 4.7
device = 0x48:group = 9.0
device = 0x50:group = 10.0
device = 0x53:group = 10.3
device = 0x68:group = 13.0
Links:
1. Documentation http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html
2. Download/Install https://github.com/mikaelpatel/Cosa#install
3. Blog http://cosa-arduino.blogspot.se/

Cheers!
251  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 31, 2013, 10:10:10 am
Great job! Looking good! Feel like I should be providing you with some feedback but I see that @pito is doing an excellent job. Right now I am focused on yet-another LCD port driver ;-) and adding a few ultra fast ciphers.

Have you tried compiling an empty sketch in UECIDE with the Cosa core?

Below is the Cosa default main(), setup() and loop(). Actually I fixed the local static instance and pure virtual problem in AVR. There where a few functions missing.

Code:
#include <avr/io.h>
#include <avr/interrupt.h>

#include "Cosa/Event.hh"
#include "Cosa/Watchdog.hh"
#include "Cosa/LED.hh"

/**
 * The init function; minimum setup of hardware after the bootloader.
 * This function may be overridden.
 */
void init() __attribute__((weak));
void init()
{
   ...
}

/**
 * The default setup function; initiate the watchdog. This function may be
 * overridden.
 */
void setup() __attribute__((weak));
void setup()
{
  // Start the watchdog ticks and push time events
  Watchdog::begin(16, SLEEP_MODE_IDLE, Watchdog::push_timeout_events);

  // Start the built-in LED in alert mode
  static LED builtin;
  builtin.alert_mode();
}

/**
 * The default loop function; event dispatcher. This function may be
 * overridden.
 */
void loop() __attribute__((weak));
void loop()
{
  Event event;
  Event::queue.await(&event);
  event.dispatch();
}

/**
 * The main function. This function may be overridden.
 */
int main(void) __attribute__((weak));
int main(void)
{
  init();
  setup();
  while (1) loop();
  return (0);
}

Yepp, the default, empty sketch will give you the classical blink program but in an event driven style.

Cheers! And keep up the great work.

BW: The Cosa Arduino.h file is great fun. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Arduino.h
252  Development / Other Software Development / Re: EEPROMex library - An extension of the standard Arduino EEPROM library on: July 30, 2013, 02:27:47 pm
Quote
if you change the order in which you 'declare' the variables you mess it up
What I expected, thanks for the explanation
@robtillaart

Sorry for the very late reply. Missed your questions.

The bottom-line here is that when using the EEMEM attribute the variables become symbolic. Otherwise you are handling the eeprom address space yourself. Possible but tedious.

I wouldn't go as far as calling it a mess up when the compiler/linker remaps the variables when they are changed, removed, etc. The program should use the symbols and not care about the actual address.

Having that said there are some performance optimizations possible with eeprom as most devices have a page mode which is fast update of a "row" in the memory. Padding variables in page boundaries can give higher performance.  

Last, consider if the SRAM would be handled as the Arduino EEPROM library. Programmers would have to keep a map of the memory usage.

Cheers!
253  Using Arduino / Displays / Re: display serial input on LCD Keypad Shield on: July 30, 2013, 04:38:22 am
I guess you mean D0 (RX) and D1 (TX) for the hardware serial port otherwise you need to bind the software serial port to the port you want to use. And then there is the Arduino SerialEvent() handling.

Cheers!

BW: This was an interesting problem so I did a quick hack in Cosa to show how the UART and LCD can be bound together; i.e. no code required. This is possible as the UART takes two IOStream::Device as in/out channels. The default is an IOBuffer but it is possible to connect any other implementation of IOStream::Device such as the LCD.

The example sketch shows two major examples; 1) the traditional approach where the loop goes low power and waits for incoming characters on the UART and feeds them to the LCD, 2) declarative approach where the LCD is bound to the UART and that's all.

See the example sketch https://github.com/mikaelpatel/Cosa/blob/f1155072cfc2a40e6d707c41a998ace35cea205c/examples/LCD/CosaLCDterm/CosaLCDterm.ino
254  Using Arduino / Programming Questions / Re: Finding a number in a large array on: July 30, 2013, 03:54:19 am
And this is such a common problem that there is already a function in stdlib.h even for AVR.

See http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga885c1ccefb716ff16ab73a57003140be
http://www.cplusplus.com/reference/cstdlib/bsearch/

And then just google bsearch for more example code.

BW: What is the original problem? My guess is that this is part of a larger problem and you have already done a design choice. As mentioned above a hashtab might be a better solution but it depends...

Cheers!
255  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: July 29, 2013, 04:43:33 pm
@arturmon

Arduino IDE 1.5.2 is not supported right now. Sorry about that.

Try 1.0.5 instead.

The Socket implementation for Ethernet is not yet available. There is not very much interest right now.
The NRF24L01+ Socket implementation works but it is restricted functionality.

Please check the list of supported hardware.

Cheers!
Pages: 1 ... 15 16 [17] 18 19 ... 30