Show Posts
Pages: 1 2 [3] 4 5 ... 26
31  Using Arduino / Sensors / Re: Real Time Clock DS1307 and Libraries on: March 08, 2014, 04:46:02 pm
Page 8 in the Product Description for DS1307 (http://datasheets.maximintegrated.com/en/ds/DS1307.pdf) might be of help. The problem is the library that adjusts the year. The chip handles 00-99 year value (in BCD). The library adjusts to 20XX.

Depending on what you are looking for you will have to at least have to modify the library, find another library or write your own.

Cheers!
32  Development / Other Software Development / Re: Changing the CPU clock in real time (run-time), to save some battery power on: March 08, 2014, 04:12:36 pm
This was an interesting approach. I have done some work with Cosa to get low power built-in but only used the power attributes. Below is a sketch I wrote to demonstrate different low power tweaks.
Code:
#include "Cosa/Event.hh"
#include "Cosa/Pins.hh"
#include "Cosa/Power.hh"
#include "Cosa/ExternalInterrupt.hh"
#include "Cosa/Watchdog.hh"

#define USE_DISABLE_MODULES
#define USE_DISABLE_PINS
#define USE_EVENT_AWAIT
#define USE_WATCHDOG_DELAY

OutputPin led(Board::LED);

class Button : public ExternalInterrupt {
  OutputPin* m_led;
public:
  Button(Board::ExternalInterruptPin pin, OutputPin* led) :
    ExternalInterrupt(pin, ExternalInterrupt::ON_LOW_LEVEL_MODE, true),
    m_led(led)
  {}

  virtual void on_interrupt(uint16_t arg = 0)
  {
    if (m_led != NULL) m_led->on();
#ifdef USE_EVENT_AWAIT
    Event::push(Event::NULL_TYPE, NULL);
#endif
    disable();
  }
};

Button wakeup(Board::EXT0, &led);

void setup()
{
#if defined(USE_DISABLE_MODULES)
  // 0 uA, already done by startup
  ACSR = _BV(ACD);
  ADCSRA = 0; 
  UCSR0B = 0;
#endif
#if defined(USE_DISABLE_PINS)
  // 2 uA, possible uart pin needed disconnecting
  DDRB = 0b11111111;
  PORTB = 0b00000000;
  DDRC = 0b11111111;
  PORTC = 0b00000000;
  DDRD = 0b11111011;
  PORTD = 0b00000100;
#endif
  Power::all_disable();
  wakeup.enable();
}

void loop()
{
#ifdef USE_EVENT_AWAIT
  // 180 uA - (BOD + PIN disable = 23 uA)
  Event event;
  Event::queue.await(&event, SLEEP_MODE_PWR_DOWN);
#else
  // 180 uA - (BOD + PIN disable = 23 uA)
  Power::sleep(SLEEP_MODE_PWR_DOWN);
#endif

#ifdef USE_WATCHDOG_DELAY
  // 1,5 mA, 64 ms blink
  Watchdog::begin(16, SLEEP_MODE_PWR_DOWN);
  while (wakeup.is_low()) {
    led.toggle();
    Watchdog::delay(64);
  }
  led.off();
  Watchdog::end();
#else
  // 15 mA, 16 ms blink
  while (wakeup.is_low()) {
    led.toggle();
    for (uint8_t i = 0; i < 4; i++) DELAY(16000U);
  }
  led.off();
#endif

  Power::all_disable();
  wakeup.enable(); 
}
Link to the example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaLowPower/CosaLowPower.ino

The results are for Arduino Mini Pro, approx. 3 mA idle, power LED on.
 1. Modifications; removed power LED resistor, 1 Kohm.
 2. Powered via FTDI USB/TTY adapter 5 V
     a. Connected to VCC/GND, 180 uA
     b. Connected to RAW/GND, 840 uA
     c. Connected to VCC/GND, + BOD disabled, 160 uA (See Power.hh)
     4. Connected to VCC/GND, + disable pins, 157 uA
 3. Powered with LiPo 3,7 V
     a. Connected to VCC/GND, 32 uA
     b. Connected to RAW/GND, 840 uA
 
 And for Arduino Lilypad, 8 Mhz, no modifications
  1. Powered via FTDI USB/TTY adapter 5 V, 18 uA
  2. Powered with LiPo 3,7 V, 16 uA
 
I have added frequency scaling to Cosa but there are ripple effects to consider before testing. Mainly as you write on timers and ADC. https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Power.cpp#L45

Cheers! And thanks for the inspiration.
 
33  Using Arduino / Project Guidance / Re: Change SDA and SCL pins on Mega on: March 08, 2014, 03:15:10 pm
Non-problemo, Then you can have the RTC (DS1307) and SHT21 on the same pins. No extra pins needed!

Cheers!
 
34  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: March 08, 2014, 03:09:09 pm
I have seen MQTT-SN implementations for Arduino and RF devices (JeeNode with RFM12B, CC stuff etc), and some of them are pretty small - qos -1 with only a publish function - and some are rather large - taking 20kb space...
@MarsWarrior
Are there any MQTT-SN nodes that you want to communicate with (bridge sensor data through)? If the bridge is also Arduino based it might as well handle protocol translation. This makes the Wireless interface much simpler.  

I hit some issues with the GSM shield and refocused to instead writing a driver for a Wifi module. The idea is to implement the AT based protocol as the Cosa Socket interface.

The latest development is support for the ThingSpeak TalkBack API. Both "Execute next command" and "Add command" have been implemented so it is really easy to handle both receive/dispatch TalkBack command and send commands to the server.


Cheers!
35  Development / Suggestions for the Arduino Project / Re: Improving core Arduino Code for ADC initialization on: March 08, 2014, 02:49:42 pm
Why is the original code better? It uses the correct symbols from AVR and not the bit values.

What could be better in both? Actually it is the enable of the converter. This could be done later on and only when needed. If using a strategy for low power design this is not a very good idea. The Analog Comparator should also be disabled.

I agree that the setting can be written as a single line. There is no need for four sbi(). In the large scale of things this is not very important. A few bytes extra. And a few extra cycles at start up (once).

Below is what you find in Cosa init; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/main.cpp#L46
Code:
void init()
{
  // Set analog converter prescale factor and but do not enable conversion
#if F_CPU >= 16000000L
  ADCSRA |= (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0));
#elif F_CPU >= 8000000L
  ADCSRA |= (_BV(ADPS2) | _BV(ADPS1)             );
#else
  ADCSRA |= (             _BV(ADPS1) | _BV(ADPS0));
#endif
  
  // Disable analog comparator
  ACSR = _BV(ACD);

  // The bootloader connects pins 0 and 1 to the USART; disconnect them
  // here so they can be used as normal digital IO.
#if defined(UCSRB)
  UCSRB = 0;
#elif defined(UCSR0B)
  UCSR0B = 0;
#endif

  // Allow interrupts from here on
  sei();

  // Attach the USB module and possible CDC/HID
#if defined(USBCON)
  USBDevice.attach();
#endif
}
What would be even better? I think defining the prescale value from conversion and system clock. PRESCALE = F_CPU / F_ADC. This is what inspired me from this topic.

Cheers!

BTW: I would like to encourage you to make a pull request to the Arduino repository.
36  Using Arduino / Project Guidance / Re: I2c sniffer on: March 08, 2014, 02:17:41 pm
This is not possible with ATmegaXXX processors and the internal TWI/I2C hardware but actually possible with ATtinyXXX or others that have internal USI. The problem has to do with the address matching. In TWI/I2C the slave address match is build-in. On USI this is done in software and you can implement a monitor.

Obviously you could implement this with soft TWI on any Arduino. http://www.atmel.com/Images/doc8478.pdf

Cheers!
37  Using Arduino / Project Guidance / Re: Change SDA and SCL pins on Mega on: March 08, 2014, 02:11:38 pm
DHT11 is not an i2c device, so you could not use that with the rtc. The sht15 is i2c, that should work with your rtc.
Sorry to say this but both these devices, DHT11 and SHT1x, are NOT I2C. They have other protocols.
Cheers!
38  Using Arduino / Microcontrollers / Re: PCB Assembly house programming an ATtiny? on: March 08, 2014, 01:58:18 pm
That was an interesting question on this forum. Obviously it doesnt have anything to do with Arduino. Instead it is a question about how to OEM program AVR.

First of all there is no need to program a bootloader and upload. Typically an ATtiny is programmed with the ISP interface. If the PCB does not have a ISP connection and uses SMD components the programming will have to be done before the assembly.

The HEX file is just fine (if they can handle that ;-). That is a question to the PCB Assemby house.

Depending on where you plan to by the ATtinys you can actually get them pre-programmed. In some cases this is worth the extra cost. Your favorite web-search tools is as usual a good friend; http://electronics.stackexchange.com/questions/38990/preprogrammed-atmel-microcontrollers

Cheers!
39  Using Arduino / Microcontrollers / Re: LCD 20x4 on ATTiny85 I2C problems on: March 07, 2014, 10:02:23 am
do you have a simple sample sketch?
When working with the 85 do you call pin 5 or Pin 0?
First of all I need to explain that Cosa is an object-oriented platform for Arduino with over 100+ classes. It is an Arduino core but supports all AVR processor based boards plus ATtiny and Mighty. It is also stand-alone and does not depend on any Arduino code more than the IDE build process.

The simplest example sketch is the LCD hello world that I use for footprint benchmarking.
https://github.com/mikaelpatel/Cosa/blob/master/examples/LCD/CosaLCDsize/CosaLCDsize.ino

The pin-out is described in the Board description file for ATtiny.
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Board/TinyX5.hh#L41
Pins in Cosa are symbols, e.g. Board::D0 instead of integers as in Arduino/Wiring.

You can basically develop on Mega, Uno, etc, and simply select ATtiny85 and compile-and-burn with more libraries than in any other Arduino package. SPI, TWI, 1-Wire etc are all support. LCD support is an abstract class that is implemented for HD44780, PCD8544, ST7565. The HD44780 driver also has an adapter layer for 4-bit parallel, Shift Register 3-wire (Pin or SPI), Shift Register 4-wire and a whole range of different I2C adapters. You can see how the configuration works in the CosaLCDsize sketch above.

Cheers!

Mikael
40  Using Arduino / Microcontrollers / Re: LCD 20x4 on ATTiny85 I2C problems on: March 07, 2014, 08:24:24 am
Did you use external pullup resistors? The internal are too weak on the ATtiny. Some I2C LCD adapter modules do not have them at all and require external.

Please see https://github.com/mikaelpatel/Cosa/issues/86


More info on http://cosa-arduino.blogspot.se/2013/07/object-oriented-lcd-management.html

Cheers!
41  Development / Other Software Development / Re: "optimizing compiler" on: March 06, 2014, 06:02:23 pm
Great! Good luck with your project. Cheers!
42  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: March 06, 2014, 04:09:26 pm
The next increment of the ThingSpeak API support in Cosa is now available. This update contains an implementation of the ThingSpeak TalkBack API and allows execution of commands sent to the server command queue. See https://thingspeak.com/docs/talkback for more details.

The Cosa support allows easy extension of a command handler by basically sub-classing the ThingSpeak::TalkBack::Command class and implementing the virtual member function execute(). The application does not need to match command strings and dispatch command handlers. All that is provided by the Cosa ThingSpeak TalkBack classes.

Below is a snippet from the example sketch. This section shows how to define a command handler. In this case a generic command handler that traces the command string.
Code:
class Command : public ThingSpeak::TalkBack::Command {
public:
  Command(ThingSpeak::TalkBack* talkback, const char* string) :
    ThingSpeak::TalkBack::Command(talkback, string)
  {}
  virtual void execute();
};

void
Command::execute()
{
  trace << Watchdog::millis() << ':' << get_string() << endl;
}

const char LED_ON[] PROGMEM = "LED_ON";
const char LED_OFF[] PROGMEM = "LED_OFF";
const char REBOOT[] PROGMEM = "REBOOT";

// Talkback command
Command led_on(&talkback, LED_ON);
Command led_off(&talkback, LED_OFF);
Command reboot(&talkback, REBOOT);
The setup and loop functions are very simple. Basically intiating the ethernet driver, creating a ThingSpeak client and executing queued commands on the server.
Code:
ThingSpeak::Client client;
ThingSpeak::TalkBack talkback(&client, KEY, ID);
...
void setup()
{
  uart.begin(9600);
  trace.begin(&uart, PSTR("CosaThingSpeakTalkBack: started"));
  Watchdog::begin();
  TRACE(ethernet.begin_P(HOSTNAME));
  TRACE(client.begin(ethernet.socket(Socket::TCP)));
}

void loop()
{
  // Take a nap if there was nothing to execute
  if (talkback.execute_next_command() != 0) SLEEP(30);
}
Example sketch: https://github.com/mikaelpatel/Cosa/blob/master/examples/IoT/ThingSpeak/CosaThingSpeakTalkBack/CosaThingSpeakTalkBack.ino
The TalkBack command queue can be connected to a ThingSpeak channel which is used as a log of the executed commands.
https://thingspeak.com/channels/10781

Cheers!
43  Development / Other Software Development / Re: "optimizing compiler" on: March 05, 2014, 07:17:17 pm
So where did you put the function attribute and did you update the platform.txt file?

I checked your code and you are not using header files right. Please check how to partition code into header and source files. Below is the correct pattern for the "noinline" attribute.

Code:
int func(int arg) __attribute__((noinline))
{
}

As all code is included into the build through the "header" files this actually signals to the compiler that the functions are inline. This is how C++ works. Member functions in header files are automatically inline (when possible). The compiler uses a few heuristics to determine if there is actually en benifit from inline and how much the function is allowed to grow.

If your really want to do something about your source code start by cleaning up the "header" file mess. This will also clean up the footprint problem.

Cheers!
44  Using Arduino / Project Guidance / Re: generating interrupt for running a specific code on: March 05, 2014, 06:54:26 pm
@Robin2

Unfortunately this question is poorly specified. We (at least I) simply do not know the full spec/use case/etc. Using digitalRead() does not say that it is 5V. It could be as low as 0.6VCC (3V typical). Below is the original question.

Quote
i want to generate an interrupt on detecting 5 volts and run any specific code

The function digitalRead does not generate an interrupt. All this depend on how we interpret the question; logical high signal, analog voltage theshold, button, etc. And an interrupt is intended.

But I fully agree Analog Comparator is the more complex and thus less likely (Occam). The interpretation of the question is then "how do it detect a logical high signal and execute a specific part of code". And the answer is:

Code:
if (digitalRead(PIN)) {
   // the specific code block to execute when the PIN is logical high/on/active/etc
}

Cheers!

[Update] After reading other forum posts by kazmi I am convinced that @Robin2 your interpretation is spot on. The usecase seems to be a trigger to capture an image and send to a mobile phone. But this is with some hand-waving.
45  Development / Other Software Development / Re: "optimizing compiler" on: March 05, 2014, 04:36:38 pm
I think we have answered your original question. To make it easier for others to find information please post a new question instead of continueing on this post. Please make an attempt to search for the information and share instead of just asking questions. For instance google on gcc function attributes, read the manual, and ask for an interpretation and/or examples.

Cheers!
Pages: 1 2 [3] 4 5 ... 26