Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 30
91  Development / Other Software Development / Re: Cosa: An Object-Oriented Platform for Arduino programming on: March 16, 2014, 06:14:18 pm
Some news on the latest development in Cosa.

1. ThingSpeak Channel and TalkBack example sketch
https://github.com/mikaelpatel/Cosa/tree/master/examples/IoT/ThingSpeak/CosaThingSpeakClient
An example sketch that allows the TalkBack commands LED_ON/OFF, SENSOR_ON/OFF, PING/PONG together with post of sensor data to a channel. The command SENSOR_ON will enable post of sensor data (DHT11) to a channel. The command LED_ON/OFF controls a led. Last the command PING demonstrates issuing commands back to the server (PONG).

2. Alarm class
Scheduling functions with seconds level resolution. The callback member function may be called once or periodic. Typical usage is "call function at given time", "call function every hour", etc.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Time/CosaAlarm/CosaAlarm.ino
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Alarm.hh

3. Activity class
High level scheduling of functions with start time, duration and period on seconds and minutes level of resolution. The callback member function is periodically called throughout the activity duration. May be used to schedule activities such as "during 10:00 to 14:00 sample sensor every 5 seconds" or "every hour sample sensors every 10 seconds for two minutes", etc.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Time/CosaActivity/CosaActivity.ino
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Activity.hh

4. Nucleo (multi-tasking) updates
a. Improved delay handing
The thread level delay function is now based on a delay queue.
b. Performance optimization
The context switch is 11 us, semaphore wait-signal pair is 41 us.
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmarkNucleo/CosaBenchmarkNucleo.ino
c. Message Passing (Actors)
https://github.com/mikaelpatel/Cosa/blob/master/examples/Nucleo/CosaNucleoActor/CosaNucleoActor.ino
d. Blink example with threads
Three threads running on an ATtiny85 with 32 bytes stack and 33 byte context per thread. Demonstrates low power when using Cosa Nucleo. https://github.com/mikaelpatel/Cosa/blob/master/examples/Blink/CosaBlinkThread/CosaBlinkThread.ino

5. Sizeof Benchmark update
List of classes in Cosa and size of instances. Note: static data not included.
https://github.com/mikaelpatel/Cosa/tree/master/examples/Benchmarks/CosaBenchmarkSizeOf

6. Cosa example sketches
The example sketch folders have been restructured. There are over 130 test, benchmarking and example sketches in total.
https://github.com/mikaelpatel/Cosa/tree/master/examples
And most of them may be compiled for Tiny, Standard, USB, Mega, Mighty Arduino based boards.

Cheers!
92  International / Fran├žais / Re: programmation avec arduino atmega 1280 on: March 16, 2014, 11:08:08 am
http://translate.google.com/#auto/en/bonjour%0Aj%27ai%20une%20probleme%20qui%20concerne%20la%20programmation%20de%20carte%20arduino%20atmega%201280%0Atout%20d%27abord%20j%27%C3%A9crit%20un%20programme%20de%20commande%20de%20moteur%20pap%20%C3%A0%202%20sens%20et%20%C3%A0%20l%27aide%20de%20potentiometre%0Aet%20je%20fais%20une%20simulation%20%20%C3%A0%20l%27aide%20de%20ISIS%20le%20programmae%20%C3%A7a%20va%20se%20marche%20bien%20avec%20une%20carte%20arduino%20uno%0Amais%20si%20je%20charge%20ce%20programme%20avec%20atmega%20%2C%20rien%20ne%20fonctionne%20%2Cj%27essais%20plusieurs%20fois%20de%20corriger%20ce%20pb%20mais%20rien%20change%0Ameme%20si%20je%20change%20les%20pins%20d%27entree%20et%20de%20sortie%0Avoila%20mon%20programme%20et%20une%20photo%20de%20isis%20avec%20carte%20arduino%20uno%20et%20atmega

Cheers!
93  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 15, 2014, 12:05:49 pm
Code:
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68

volatile int count;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();
  attachInterrupt(0, compteur , RISING);
}

void compteur()
{
  count = count + 1;
}

void loop()
{
  int c = count;
  while (c == count);
  Serial.println(count);
}
Cheers!
94  Using Arduino / Project Guidance / Re: Counting length of pulses on: March 13, 2014, 02:12:23 am
Im doing a school project and you guys on here are my only hope  smiley-confuse

I will have an input from another microcontroller and i need to count the length of pulses,
there will be 3 different pulses one after another.

So, basically there will be one pulse for lets say 21 seconds, i need to store this,
then 5 seconds or so after that pulse has finished another will start on the same pin for lets say 15 seconds, i need to store this separately,
finally 5 seconds after the previous pulse there will be one last pulse for 3 seconds and i need to store this separately from the other 2 pulses,
Tom
What have you learnt in school? What type of problem is this? Do you know what a finite state machine is? And how it can be programmed? Is the signal stable? What is the distance, length of the cable? Is there noise? How do you indent to connect the two microcontrollers? Does the solution have to be low power? Will the microcontrollers run on battery? Are there programming languages for this type of problem?

Cheers!
95  Development / Other Software Development / Re: Writing menu library, need help with #include's on: March 10, 2014, 06:07:30 pm
@pekasus
What is the compiler trying to tell you? It points to the line; https://github.com/pekasus/M16/blob/master/M16.cpp#L31

If you define lcd as a local variable in the constructor M16 it is not available after that. It is created on the stack and then removed after the constructor (M16).

"I guess I have to declare lcd somewhere else?" yepp.

Cheers!
96  Using Arduino / Networking, Protocols, and Devices / Re: SNMP Manager example code on: March 09, 2014, 05:59:30 am
Yes it is possible to write that. It is not implemented in that library, https://github.com/utz-michael/libraries/blob/master/snmp/Agentuino.h#L333

But why not write it as an uint8_t vector instead.

Cheers.
97  Using Arduino / Networking, Protocols, and Devices / Re: SNMP Manager example code on: March 09, 2014, 04:11:43 am
What library are you using? Your code above is wrong as the OID is a string and you are accessing characters and not numbers. Cheers!
98  Using Arduino / Networking, Protocols, and Devices / Re: SNMP Manager example code on: March 08, 2014, 07:26:11 pm
The OID encoding of 247 is; 128+1,247-128=129,119. Which is what you got.

The full OID 1.3.6.1.4.1.247.87.0 should be encoded as 1,3,6,1,4,1,129,119,87,0. This should be prefixed with the length of the OID which is 10.

BTW: 1.3.6.1.4.1.247 is an enterprise OID for AEG Electrocom.

Cheers!
99  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!
100  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.
 
101  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!
 
102  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!
103  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.
104  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!
105  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!
Pages: 1 ... 5 6 [7] 8 9 ... 30