Show Posts
Pages: [1] 2 3 ... 351
1  Using Arduino / Project Guidance / Re: controlling flashlight on: Today at 09:54:38 pm
Arduino may not provide enough current to run the led but that's okay, the batteries do.

Question is do you want to hack a $13 flashlight or 2?

You might be able to do a clean job of it if there's room inside for wires though you will have to make a hole.

The idea is to find out how the on/off switch is connected and then put your own wires in so that if it was 1 piece of wire, the light would shine with batteries in place. But you have 2 wires. Connect those to the collector and emitter of an NPN transistor so that + is to the collector and - to the emitter. The transistor is your switch. Connect a 10k resistor to the base pin of the transistor and when you give that 5V from a pin the battery current will flow.

And make SURE that the - wire is connected to Arduino GND.

You can put the resistor and transistor right in the wires and simply plug those into the Arduino holes.

2  Using Arduino / Programming Questions / Re: Problem with DFRobot Romeo V2 on: Today at 08:37:15 pm
You should thank Steinie44 too!
I did.
3  Using Arduino / Programming Questions / Re: [SOLVED] Shuffle a char array? on: Today at 08:31:55 pm
Strings use more RAM (a byte or two IIRC) just for starts.

Add a char to a String and it copies itself with the new char added then deletes the old copy and does whatever heap management is needed to be able to use the deallocated space -- since that was fixed in the IDE a while ago now.
Add another char and the new copy won't fit where the first one did so you get a bigger hole in the heap but good news, the next one will fit in the hole but the one after that may not if you have other dynamic allocation objects doing their 'fits on a PC' behavior.

None of that is cycle-free. What's going to happen if you are trying to use tight, fast code with Strings? If you're real careful then you can get away with it and say you did. Is that worth using the things on an MCU?
Dynamic allocation is not a bright idea in a limited RAM environment. You can do it but it is going to limit the scope of what you do. C++ has lots of classes that use automatic dynamic allocation. It is best to avoid them regardless of the convenience.  

I sure don't need conveniences like that. I make what buffers I need and stick to them.
4  Using Arduino / Project Guidance / Re: program to find rpm on: Today at 08:14:03 pm
but then again, it may be so fast you need to use an interrupt...

Note that interrupts have overhead too.

Threads on close timing in the archives here use 'timing loops' and sequences of nop commands to achieve under 4 microsecond to sub-microsecond measures.

But how many rpm's would that take? Kind of scary, no?

For really, really fast I would try an external CTC (counter timer chip) to generate an interrupt every so many revs. At least I think that there are CTC's cable of operation at many times 16 MHz.
5  Community / Bar Sport / Arvind Gupta - Toys From Trash on: Today at 07:49:59 pm

IMO the man is brilliant in teaching his applications of simple science for children of all ages.
That's right, if you didn't get it the first time around then these toys can lead back to the learning.
The first of his videos I saw were in Hindi language yet I understood them. Then I found the English versions.

I think that many of these things could be Arduino-added/instrumented to put values on what is demonstrated.
They could make fine secondary school science fair type projects, maybe even be used in freshman design projects.

I subscribed so his channel shows up on my feed. If I'm 'bored' then I look for ones I haven't seen yet.
But then I do that with a lot of different channels.  smiley-mr-green
6  Using Arduino / Project Guidance / Re: How to change volume of sound on: Today at 06:50:02 pm
I'm interested in the piezo end as well.

I bought 100 10mm discs with leads for $10.30 and so far I only use then for buttons and knock sensors.

Maybe they have to have the plastic housing to make much noise?
I double-stick taped them to plastic cup base and small cookie tin lids and got sound but not much.

Some day, I'd like to make one able to pick up sound and find frequency, for example.

But I do luv piezos. They're like capacitors that you can charge by touch, discharge by release.
7  Using Arduino / Programming Questions / Re: Changing modes question with SMlib on: Today at 06:23:11 pm
Can you post the whole code?

I have no idea what the read sensors and gsm routines do and importantly how long they take to run.
If they are long in process then the button might not debounce cleanly every time.

In my own examples with multiple buttons (could as easily be sensors) and leds (could be motors) I am only processing 1 per pass through loop() and still get them all almost as fast as in a loop of their own. But for a tiny bit slower I have the other tasks able to run smoothly as well, the load is shared evenly.

8  Using Arduino / Project Guidance / Re: program to find rpm on: Today at 09:15:41 am
What is the delay for?

9  Using Arduino / Programming Questions / Re: arduino serial erratic behaviour missing characters on: Today at 07:24:34 am
More than an example.
10  Using Arduino / Programming Questions / Re: arduino serial erratic behaviour missing characters on: Today at 06:46:03 am
Does parseInt() eat the delimiter after the digits? If so then that's where your '\n' may have gone.

11  Using Arduino / Programming Questions / Re: [SOLVED] Shuffle a char array? on: Today at 03:22:18 am
Example of accessing table data in PROGMEM through indexes...
/* Yet Another Modified Blink Without Delay
 Turns on and off a light emitting diode(LED) connected to a digital 
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 This particular version blinks in a PROGMEM sinewave-table-driven pattern.
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 fixed and modified more than once 2013-2014
 by GodForSmoke
 This example code is in the public domain.

 Here's the original, but use the Example code in your IDE under File->Examples

// constants won't change. Used here to
// set pin numbers:
const byte ledPin =  13;      // the number of the LED pin

byte ledState = LOW;          // ledState used to set the LED
char degree = 0;              // can be negative, char range is -128 to 127
char goDirection = 1;         // degrees go 0 to 89 to 0 to 89 ...

// the follow variables is an unsigned long because the time, in miliseconds,
// returned by mills() is an unsigned long and you don't want to mix variable types.
unsigned long intervalMillis;
unsigned long previousMillis = 0;        // will store last time LED was updated

const word PROGMEM sineTbl[ 90 ] = {
   0,    9,   17,   26,   35,   44,   52,   61,   70,   78,
  87,   95,  104,  112,  121,  129,  138,  146,  155,  163,
 171,  179,  187,  195,  203,  211,  219,  227,  235,  242,
 250,  258,  265,  272,  280,  287,  294,  301,  308,  315,
 321,  328,  335,  341,  347,  354,  360,  366,  372,  377,
 383,  389,  394,  399,  405,  410,  415,  419,  424,  429,
 433,  437,  441,  446,  449,  453,  457,  460,  464,  467,
 470,  473,  476,  478,  481,  483,  485,  487,  489,  491,
 492,  494,  495,  496,  497,  498,  499,  499,  500,  500

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);

  Serial.begin( 57600 ); 
  intervalMillis = (unsigned long) pgm_read_word( sineTbl[ degree ] );   

  Serial.println( intervalMillis );

void loop()
  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if ( currentMillis - previousMillis >= intervalMillis )
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    ledState = !ledState; // ! is logical not, opposite

      // set the LED with the ledState of the variable:
    digitalWrite( ledPin, ledState );
    degree += goDirection;
    if (( degree < 1 ) || ( degree > 88 ))
      goDirection *= -1;
    intervalMillis = (unsigned long) pgm_read_word( sineTbl[ degree ] );   

    Serial.println( intervalMillis );


12  Using Arduino / Programming Questions / Re: [SOLVED] Shuffle a char array? on: Today at 03:10:14 am
Oh geez I hadn't noticed before -- get rid of the wasteful frikking String objects!  Use C string arrays!

You can access PROGMEM data by address + offset and size and you can access by indexes too.
The important part is that addresses in PROGMEM have to use functions that address PROGMEM.

AVR SRAM, flash and EEPROM are separate devices each with its own space.
There are other MCU's like IIRC the SAM in the Due that address all memory as a single space.

Sorry but I haven't done the indexes way enough, I have to go to my examples to say "oh yeah" on the syntax.
13  Using Arduino / Programming Questions / Re: Clock Program Stopped on: July 21, 2014, 06:26:29 pm
Time, initTime, and setTime are all of type long,
needs to be unsigned long

And the constants do too.

  hr = ((TIME / 1000UL) / 3600UL) % 24UL;
  minute = ((TIME / 1000UL) / 60UL) % 60UL;
  sec = (TIME / 1000UL) % 60UL;
14  Using Arduino / Programming Questions / Re: Problem sending 2 shorts over bluetooth from Android to Arduino. on: July 21, 2014, 05:33:43 pm
I have your answer.

2573 decimal == 0xA0D, which is newline followed by carriage return

Your code as you have it needs to read 6 bytes and use the last 2 as end of line markers -- gives you an error check.

Edit again: actually since your code reverses byte order ( array[0] is high byte, array[1] is low ) you are getting 0D 0A, not 0A 0D. Carriage Return then Newline is the more standard order.

15  Using Arduino / Programming Questions / Re: Problem with DFRobot Romeo V2 on: July 21, 2014, 04:50:46 pm
Does it all work when you have it plugged in to USB?
If so then it is more likely that there is a different problem than you think.

Maybe the motor(s) get power and the rest lacks power without the USB supplying 500mA?
Then the motor(s) would run but not the rest.
I don't need interrupts to do many things on time at once, more than you list.
But you have a lot of code that I don't know the pieces so I can't say how much work to change over.
What I saw did not look like problems, only delay() I remember is in the Leonardo setup, no big deal.

So for the easier path, if the code works when plugged in to USB, let's see if there is a simple answer.
Pages: [1] 2 3 ... 351