Show Posts
Pages: 1 2 3 [4] 5 6 ... 22
46  Development / Other Hardware Development / Re: Shield with optocouplers on: September 22, 2011, 11:37:03 am
Hi Willem, I don't know of a specific shield which has a bunch of OK's on it, but here's a non-shield design that may help you in designing one - in this case it daisy-chains all OK's (to split an already opto-coupled input), but it's a decent starting point for a schematic and layout:

47  Using Arduino / Programming Questions / Re: Making a library: I must be missing some steps... on: September 10, 2011, 01:40:11 am
... and don't ignore this error:

testclass:-1: error: new types may not be defined in a return type
testclass.cpp:3: note: (perhaps a semicolon is missing after the definition of 'testclass')

You're missing a semi-colon:

#ifndef testclass_h
#define testclass_h

#include <WProgram.h>

class testclass{
      int addnum(int a, int b);
}; // semi-colon required

48  Using Arduino / Programming Questions / Re: Setting the cursor position for a Serial LCD on: September 05, 2011, 10:22:44 am

This didn't work:
#define LCD_WIDTH 20
SparkSoftLCD lcd = SparkSoftLCD(LCD_TX_PIN, LCD_WIDTH);

This worked:
SparkSoftLCD lcd = SparkSoftLCD(LCD_TX);

I did notice something weird though.  I am able to create and use custom characters with the SerLCD, however, if leave the Arduino Uno unplugged for awhile and then plug it back in, my sketch doesn't run correctly.  Right now I am only using custom characters.

That's odd that the constructor didn't work for you - I suppose it gave a compile error, about not having a matching prototype...  It may be resolved by saying:

SparkSoftLCD lcd = SparkSoftLCD(LCD_TX, (uint8_t) LCD_WIDTH);

Either way, it's not actuallly necessary since there is effectively no difference in how it drives the LCD with or without the width argument - that's likely an artifact from early on when it appeared the positioning arithmetic was different based on different widths.  It's not actually, and you can see in the cursorTo method it behaves the same given any width (I should remove the spurious inclusion of 'lenAdd').

Sorry to hear about the damage Irene did, haven't had to deal with a hurricane around here since Ike, and that was a pretty big clean-up.  Wouldn't wish that on anyone!

49  Using Arduino / Motors, Mechanics, and Power / Re: max ampere for VIN pin on: September 05, 2011, 10:12:58 am

Yea, but I've had a 5 amp transistor blow up to protect a 2 amp fuse.  smiley-grin

Yeah, pretty much every 4N007 has a 30A "spike" current, and "spikes" can be loosely defined, in my example, I'm doing lots of PWM, so those "spikes" are very short, but very often =)

50  Using Arduino / Motors, Mechanics, and Power / Re: max ampere for VIN pin on: August 29, 2011, 07:39:16 pm
My duemilanove in front of me has a 4007 diode.  Meaning, 1A max continuous.

51  Using Arduino / Programming Questions / Re: Setting the cursor position for a Serial LCD on: August 29, 2011, 07:32:20 am
Looks like your library supports 16x2 and 20x2, but doesn't not support 20x4 LCDs.

It is supposed to support 20x4, what's not working for you?

52  Using Arduino / Motors, Mechanics, and Power / Re: max ampere for VIN pin on: August 26, 2011, 05:11:41 pm

Well the issue (and limit) is the maximum continuous forward current rating of the series polarity protection diode wired between the external power connector and the Vin pin. This diode will pass all current supplied to the board and any current consumed off board via the Vin pin. Does anyone one know the actual diode part number used and it's max forward current rating? I have no doubt one can draw more then it's safe rating but it's not an accepted good engineering practice to do so. I always assumed it was a bog standard 1 amp diode?

You know, now I feel like an Idiot with a capital I.

No matter how many times I've looked at that schematic, I've blocked D1 out of my mind until this moment.

Now I'm nervous, hah. (Well, not really... But now I just have to know!)  I'm going to take a look when I get home and see if I can discern anything...

53  Using Arduino / Programming Questions / Re: Setting the cursor position for a Serial LCD on: August 26, 2011, 05:03:50 pm
Wow, thanks guys.  That's why I love this community, everyone helps each other out.  I've spent a few days searching the internet for something similar to LiquidCrystal library and looks like the SparkSoftLCD library is pretty close.  I think I'll probably use the SparkSoftLCD library because I wouldn't have to make too many changes to my sketch.  Thanks for the other suggestion; it had me pulling my hair out last night.  it kind of makes sense now.

No problem at all =)  Glad to be of service!

If you have any issues with the library, let me know.  (Disclosure: I'm the author =)

54  Using Arduino / Motors, Mechanics, and Power / Re: max ampere for VIN pin on: August 26, 2011, 01:49:20 pm
It's worth noting that I have about a thousand devices in the field drawing from 1.25A to 2A @12V through the Arduino Vin pin (to a shield), and none of them have burned out any traces or melted any pins in the Arduino =)

The biggest concern I had originally, was the trace size from the dc plug to the Vin pin, which seems fairly small, and AFAIK the Arduino boards use 1oz pours.  (My shield uses 20 mil traces for the biggest consuming paths, and 2oz pours.)  However, this has not proven out to be an issue.  However, I still have some serious concerns in the long run, considering a lot of the female headers I see out there are rated @ 2A through each contact.  I don't know the specific P/N of the headers used in the Arduino, but I'd bet money on them being around the same.


55  Using Arduino / Programming Questions / Re: Setting the cursor position for a Serial LCD on: August 26, 2011, 10:56:14 am
Have you looked at ? The SparkSoftLCD library, has the function cursorTo(row, col) - it would be extremely simple to reverse these arguments in the library, to match the order of arguments in liquidcrystal library (col, row).

Of course, if you just want to figure out how to set the row and column, this may be more instructive than your example (from the above library) :

   switch(line) {
       case 1:
   case 2:
pos += 64;
   case 3:
pos += 20;
   case 4:
pos += 84;
   pos += 128;   
   sendControl( pos );

56  Using Arduino / Programming Questions / Re: How to free the RAM memory specifically used by local variables ? on: August 24, 2011, 04:23:12 pm
Solution: I converted all functions that return array of chars into void functions.
Almost certainly what you were doing was returning a pointer to a local variable that went out of scope. While that memory will not be immediately overwritten, pointing to data on the heap is dangerous because you never know when the memory will be clobbered.

Does the compiler not at least throw a warning when you do that?  I haven't tried such in arduino, but I know Qt will not compile when you attempt to return a pointer to a local variable from within a method or function.

57  Using Arduino / Programming Questions / Re: How to free the RAM memory specifically used by local variables ? on: August 24, 2011, 10:13:58 am
I can see (via LCD) the "trash" on this data structure just after writing the correct data using different functions. This is the scenario that the program is "locked" and if continues after the loop, the behavior of the device is unpredictable. Therefore, the leakage seems to be caused by the mentioned functions and their usage of the RAM memory.

I'd better dollars to donuts you don't have a memory "leak" (which is memory allocated but never freed when no longer needed, yet continuing to allocate new memory causing usage of RAM to grow), but instead, you have a memory over- or under-flow. This happens, most notably, when using arrays and forgetting to check the bounds of the array when using incrementing indeces, and so forth.  This is more than likely why you're seeing "garbage data" in your printed data - if it's at the beginning of your data, you likely overflowed the variable before it.*

But, without seeing code - that would be nearly impossible to ascertain at a distance.

If you're not using new or malloc, then you're likely not having anything like a memory leak. (As already stated.)

* - it's actually more complex than this, but I'm not sure I'm qualified to explain heap, stack, and how variables are declared - I've just had to fix a lot of similar issues myself =)

58  Using Arduino / Programming Questions / Re: Serial transmission with dynamic buffer on: August 22, 2011, 03:33:12 pm
To add to what PaulS said, if you're going to use a persistent buffer, it should be large enough to hold your largest command data set.  Because of this, you will need to make sure that you always memset() it back to all zeros -before- writing anything into it, otherwise you will have bytes left over in it when reading a shorter command.


memset(cmdtrans, 0, CMDBUFSIZE * sizeof(uint8_t)); // CMDBUFSIZE defines maximum buffer len


59  Using Arduino / Programming Questions / Re: millis help needed on: August 18, 2011, 12:37:12 pm
1: Do not mix logic.  Mixing "which LED do I turn on," and "should I turn any LED off" is a big part of your problem.  They are distinct issues, and should be treated distinctly - not only will this generate less code, it will also make it much easier to debug.

2: Avoid redundant code.

Imagine the following:


int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
long int time4 = 4500;
long previousMillis = 0;


boolean is_lit = false;
byte cur_led  = led1;

void loop() {

  if( ! is_lit && digitalRead(buttonState1) == HIGH ) {

      // no led is currently list

    cur_led = random(1,4) + 1; // LEDs start at pin 2 and move sequentially to pin 5

    digitalWrite(cur_led, HIGH);
    previousMillis = millis();
    is_lit = true;


  else {

    // an LED is lit currently.

     if( millis() - previousMillis() >= time4 ) {
          // enough time has passed to turn off the LEd
        digitalWrite(cur_led, LOW);
        is_lit = false;


Note here the logic is such:

If no LED is lit and button is pressed -> determine which LED to light up + light the LED + indicate time LED was started + indicate that LED is lit up
If an LED is lit -> determine if enough time has passed to turn off the LED, if it has - turn it off an indicate that the LED is no longer on

Note that your previous code wouldn't turn off the LED if the button wasn't pressed.

60  Using Arduino / Programming Questions / Re: 8 lose bits to 1 binairy number to convert. on: August 18, 2011, 12:05:42 pm
If you wanted to be slick, you could do it quite easily (and a lot faster, with a lot less code) using the port input pins register.

Assuming you used pins 0-7 (yes, using the RX/TX may not be safe =), you could quickly do:

result = PIND;

Yup, that's it =)

PIND = one bit per state, where the first bit (Bx) is pin 7 and the last bit (B0000000x) is pin 0.  Thus, Binary one = B00000001, and only having pin 0 high would cause PIND's value to be B00000001.  If you spread the pins across two registers, you'd need to do some bit-shifting and some and operations to get the right values in place, but that's pretty easy to do.

The drawbacks?  You have to use PIND which may change on different processors.  The benefits?  If you're doing time-sensitive stuff, this will run eons faster than 8 digitalRead()s, and will compile to a lot less code.

Pages: 1 2 3 [4] 5 6 ... 22