Show Posts
Pages: 1 ... 69 70 [71] 72 73 ... 152
1051  Using Arduino / Programming Questions / Re: creating function that blink led by number of my choice on: May 26, 2013, 09:55:39 am
Do you want to know how to add the parameters?

Code:
void blinkred( char c_Pin, char c_Count  )
  {
    for (int redtime=0;redtime<c_Count;redtime++)
    {
      digitalWrite( c_Pin ,HIGH );
      delay (500);
      digitalWrite( c_Pin ,LOW );
      delay (500);
    }
  }

//...
blinkred(redled,5);
1052  Products / Arduino Due / Re: Ardino due and sprintf() on Atmel Studio 6.1 doesn't work! on: May 26, 2013, 07:21:46 am
No worries, there shouldn't be problems as the version you have does not include the eeprom or progmem code. I'm working on a print library extension that allows Serial.printf(). It is only AVR compatible at the moment as I build the functionality, but eventually I can mask off the AVR only bits and I'll have support for the Due as well.

You should be fine to use the GString.h, though.
1053  Using Arduino / Programming Questions / Re: Disable hwSerial library at compile-time on: May 26, 2013, 07:12:08 am
This does work, even without any 'disable_serial0'

applying weak to the HWserial cpp I can now use the code below. Instead of the serial implementation, sending data will toggle the pin 13 led.
Code:
ISR(USART_RX_vect){
    volatile unsigned char c = UDR0;
    digitalWrite( 13, !digitalRead( 13 ) );
}

void setup(){
  pinMode( 13, OUTPUT );
  Serial.begin(115200);
}
void loop(){}
1054  Using Arduino / Project Guidance / Re: Grabbing modified video .. on: May 26, 2013, 06:26:48 am
I've seen some really basic serial cameras. You could read the first line only, straight into the arduino. Check the ArduCam project. They have a list of camera models that have worked with arduino.
1055  Using Arduino / Programming Questions / Re: crash when calling code from wire.onreceive on: May 26, 2013, 06:20:12 am
post your code, also read the 'Read this before posting' message.
1056  Community / Bar Sport / Re: Google Code is about to die. ( for a lot of us anyway ) on: May 26, 2013, 06:00:57 am
Apparently github does not support downloads either ( cancelled some time ago, as well ), SourceForge does.
1057  Using Arduino / Programming Questions / Re: Disable hwSerial library at compile-time on: May 26, 2013, 05:52:55 am
You will have to check, but I think ISR's using 'ISR()' should have the 'weak' attribute set by default.
If its not set, you could add '__attribute__((weak))' to the core versions, and implement your own versions in the sketch.

This might not work, but is how the AVR core defines its interrupts so they all point to the bad_vector ISR, unless you provide your own version.
1058  Products / Arduino Due / Re: Ardino due and sprintf() on Atmel Studio 6.1 doesn't work! on: May 26, 2013, 05:30:17 am
That is good to hear, I don't actually have a Due to do any testing, so your response was great. Cheers. smiley
1059  Community / Bar Sport / Google Code is about to die. ( for a lot of us anyway ) on: May 26, 2013, 05:23:44 am
I just posted a library to my google code account and clicked on a notification message trying to get my attention:

Starting today, existing projects that do not have any downloads and all new projects will not have the ability to create downloads. Existing projects with downloads will see no visible changes until January 14, 2014 and will no longer have the ability to create new downloads starting on January 15, 2014.  All existing downloads in these projects will continue to be accessible for the foreseeable future.

Lucky I got my uploads in... But I don't really see the need in using google code once I have to start posting elsewhere next year.
1060  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 26, 2013, 05:12:38 am
I have just uploaded a copy of the code to google, so anybody not logged in can try the library.

The file is PrintPatch_001.zip.
https://code.google.com/p/arduino-extensions/downloads/detail?name=PrintPatch_001.zip

Inside the zip are the two files attached to the post above. So the installation instructions are the same.
1061  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 25, 2013, 01:09:47 pm
Okay, here is the patch.

It adds in:
  • Print::repeat()
  • Print::concat()
  • Print::concatln()
  • Print::printf()
  • sprintf
  • ftoa
  • EString: EEPROM printable class.
  • PString: PROGMEM printable class.
  • GString: SRAM printable class.
  • NonStreamingIO: Inheritable Print extension.
Documentation will be available soon.

There are two files to download. But there are some steps required to install them properly.

Step 1.

Download files to the core folder where Print.h & Print.cpp are located.
On my machine, I have arduino in my D:\ so the path is here: 'D:\arduino-1.0.5\hardware\arduino\cores\arduino'
If you use the beta 1.5.X, you will have to find the AVR core folder, I don't have it but maybe someone can post the directoy.

Step 2.

Open Print.h.
Scroll to the very bottom.
Before the closing brace of the Print class, add the line: #include "Print_Ext.h"

Here is the last 10 lines of Print.h with the mod:
Quote
    size_t println(long, int = DEC);
    size_t println(unsigned long, int = DEC);
    size_t println(double, int = 2);
    size_t println(const Printable&);
    size_t println(void);
   
   #include "Print_Ext.h"
};

#endif

Save changes and close.

Step 3.

Open Print.cpp
Underneath the line '#include "Print.h"' add the line: #include "Print_Ext.source"

Here is the first 10 lines ( after comments ) of code in Print.h with the mod:
Quote
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "Arduino.h"

#include "Print.h"
#include "Print_Ext.source"

// Public Methods //////////////////////////////////////////////////////////////

Save changes and close.

Step 4. ( optional, otherwise PROGMEM code is doubled up. )

In Print.cpp find the function:
Code:
size_t Print::print(const __FlashStringHelper *ifsh)
{
  const char PROGMEM *p = (const char PROGMEM *)ifsh;
  size_t n = 0;
  while (1) {
    unsigned char c = pgm_read_byte(p++);
    if (c == 0) break;
    n += write(c);
  }
  return n;
}

Comment it out and replace it with this:
Code:
size_t Print::print(const __FlashStringHelper *ifsh)
{
  return print( PString( ifsh ) );
}

Hopefully thats it.
1062  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 25, 2013, 12:41:49 pm
I forgot this version, which also compiles to 2492 bytes.

Code:
  EString e( 0, 16 );
  PString p = c0;   
  Serial.begin(115200);
  Serial.repeat( '=', 30 );
  Serial.concat( "\nEEPROM: " ).concat( e ).concat( "\nPROGMEM: " ).concatln( p );
  Serial.repeat( '=', 30 );
1063  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 25, 2013, 12:16:46 pm
The s/printf function is large due to it including support for float & decimal conversions, PROGMEM, EEPROM.
You will see its benefit in apps where you already use these features, so no more code is added, just the sprintf function code.

These small examples are not a good test, I'll post a sketch testing all the string functionality where you can see the size drop just from my underlying framework, then converting the blocks into printf calls makes for even smaller code.

The three classes GString, EString, and PString are designed for use with print and println calls.

As a control:
Code:
 Serial.begin(115200);
  Serial.println( "Hi" );

1,926 bytes.

Testing printf:
Code:
 Serial.begin(115200);
  Serial.printf( "%30n\nEEPROM: %16r\nPROGMEM: %p\n%30n", '=', 0, c0, '=' );

5,318 bytes.

The 'small' app equivalent of the printf line above:
Code:
 EString e( 0, 16 );
  PString p = c0;  
  Serial.begin(115200);
  Serial.repeat( '=', 30 );
  Serial.print( "\nEEPROM: " );
  Serial.print( e );
  Serial.print( "\nPROGMEM: " );
  Serial.println( p );  
  Serial.repeat( '=', 30 );

2,492 bytes.

Each feature not found in the Arduino standard 'sprintf' can be disabled by defining certain macros.
As you can see, the last version is only half a kb more than the control. Its the float and decimal conversions that are hurting the code.

I have a few other things I'm testing, but they aren't included in my patch, yet.
1064  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 25, 2013, 11:15:54 am
I have finished adding the last few bits to sprintf/printf. Here is an example of the latest features.

This expects the EEPROM value written in my previous post to still be valid.
Code:
char c0[] PROGMEM = "Test string two.";

void setup(){
  Serial.begin(115200);
  Serial.printf( "%30n\nEEPROM: %16r\nPROGMEM: %p\n%30n", '=', 0, c0, '=' );
}
void loop(){}

Output.
Quote
==============================
EEPROM: Test string one.
PROGMEM: Test string two.
==============================

I'll have the code ready shortly.
1065  Development / Other Software Development / Re: String/sprintf alternative specifically for Arduino. on: May 25, 2013, 09:34:57 am
Woo Hoo. My test worked perfectly.

It writes a PROGMEM string into EEPROM then prints the EEPROM text over serial.
This code is also safe, the EString won't overwrite unchanged data, so it only writes the string once.

Code.
Code:
char c0[] PROGMEM = "Test string one.";

void setup(){
 
  PString p = c0;
  EString e( 0 );
 
  Serial.begin(115200);
  e.print( p );
  Serial.println( "-----------------------" );
  Serial.println( e );
  Serial.println( "-----------------------" );
}
void loop(){}

Output.
Quote
-----------------------
Test string one.
-----------------------
Pages: 1 ... 69 70 [71] 72 73 ... 152