Show Posts
Pages: 1 ... 6 7 [8] 9 10 ... 30
106  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!
107  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.
108  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!
109  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!
110  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!
111  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
112  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!
113  Development / Other Software Development / Re: "optimizing compiler" on: March 06, 2014, 06:02:23 pm
Great! Good luck with your project. Cheers!
114  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!
115  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!
116  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.
117  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!
118  Using Arduino / Project Guidance / Re: generating interrupt for running a specific code on: March 05, 2014, 04:32:34 pm
Actually ATmega has the perfect mechanism for this. Below is a section from the manual:

25. AC – Analog Comparator
The Analog Comparator compares the input values on the positive pin AIN0 and negative pin
AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin
AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger
the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate
interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on com-
parator output rise, fall or toggle.

You can find out more on page 271 in the ATmega2560 manual.

Cheers!

Does Arduino/Wiring support this? No but Cosa does. Check github or my posting on the forum.

119  Development / Other Software Development / Re: "optimizing compiler" on: March 05, 2014, 12:18:44 pm
The next thing to do is to sort the symbol files;

sort xxx.sym > xxx.sorted.sym

And then check where the commented function size is larger than uncommented. Then you check the listing to see the assembly code. And my guess is that you will find the answer --- compiler function inlining.

I did all this and found that the menu functions became much larger in the commented version. This implies the compiler took the decision to inline some functions.

00002bb6 000007e6 T MenuGeneral()         commented
vs
00002266 000001e4 T MenuGeneral()          uncommented

Hum, you need to know something about the file format. It is simply address, size, attribute and symbol. Nothing strange. Try using google and reading manuals ;-)

And, yes, you can force the compiler to not inline (for instance AddWord) to reduce footprint but that is a different line of QA.

Cheers!
120  Development / Other Software Development / Re: "optimizing compiler" on: March 05, 2014, 03:28:08 am
Replacing "avr-size" with "as" is not correct. Try removing that all together. Skip the size information for now and generate the symbol and listing file first. Then you have something to work on.

To implement the "avr-size" information I think it's easiest just to look at what the IDE for 1.5.X does as it produces that information at the end of the build.

Cheers!
Pages: 1 ... 6 7 [8] 9 10 ... 30