Show Posts
Pages: [1] 2 3 ... 840
1  Products / Arduino Due / Re: attachInterrupt get interrupted pin on: Today at 11:31:40 am
C and C++ don't support closures, so there's no way to define functions
at runtime.  Its pretty clunky in fact.  And the macro system is horrible beyond
2  Using Arduino / Motors, Mechanics, and Power / Re: Suggestions to buy a battery for multicopter on: Today at 11:28:40 am
That's why you have to give us all the details you have, not just a part number!!  We can
interpret the data, but you've got to make it accessible to our impatient collective gaze smiley

Go and read the sticky thread that says "read this before posting" or some such....
3  Using Arduino / Motors, Mechanics, and Power / Re: Two 300RPM 12V DC motors connected to arduino motor shield r3 power supply on: Today at 11:26:16 am
You have told us nothing about the motors that's useful other than they are 12V.

We need to know the stall current rating, and preferably the full rated load current/power
too.  Any information please, even a photo would help to see how big they are.

If they are 12V why are you thinking of using 9V at all?

Small 9V batteries cannot power motors or servos, they just cannot produce
enough current, give up on the 9V battery notion completely!
4  Using Arduino / Motors, Mechanics, and Power / Re: I need help with my 48v Brushless Motor Controller Circuit on: Today at 11:22:04 am
Make Cboot (in nF) equal/greater to the total gate charge (in nC)
Make the 12V decoupling capacitor at least 10 times Cboot.

You want the voltage sage from the high-side drivers to be 10% or less
as they switch, so Cboot should be 10x the gate _capacitance_, however
the gate capacitance isn't linear, its better to think of total gate charge
divided by gate voltage.

Thus Cboot = 10 x Cgate = 10 x (Qgate / 10V) = Qgate

We divide by 10V rather than 12V to allow for the voltage drooping
and the voltage loss in the bootstrap diode.

Do _not_ add a 10k gate-source resistor to the MOSFETs, this just drains the
Cboot way fast.  A 15V zener between gate and source for each MOSFET is
a good precaution to protect gates from over-voltage.  Simple, cheap.
5  Using Arduino / Motors, Mechanics, and Power / Re: Low Pass Filter Usage After Motor Driver Card? on: Today at 11:15:23 am
The problem with just sensing the average voltage is that it doesn't tell you anything
useful, since (in the normal regime) its just dependent on the PWM duty cycle.

You could sense the current, but that's only a witness for the force (minus any friction),
and is again strongly related to the duty cycle, and not the load.  And its worse than
that, because the current controls the magnetomotive force (MMF), whereas the physical
force depends on that _and_ the magnetic circuit's reluctance (ie the position of
the plunger)  There is no guarantee of even a one-to-one mapping between MMF and
physical force (even before friction).

If you want to sense the position you'll have to sense the position itself, it cannot be
inferred from any electronic signal.
6  Using Arduino / Motors, Mechanics, and Power / Re: Bipolar Stepper Motor : one step CW and one step CCW ??? on: Today at 11:07:39 am
What motor?

What controller?

Links to datasheets or similar please, as you have been asked if you read the
"read before posting" sticky thread.

If you are hand-connecting a stepper to a controller you should realise that
disconnecting a motor or winding from a powered-up motor controller is
a good way of killing the controller dead.  Always power down before connecting
or disconnecting motor wires from a stepper controller.

If you want to understand how stepper motors work, there are many
resources out there for that.
7  Using Arduino / Motors, Mechanics, and Power / Re: Suggestions to buy a battery for multicopter on: Today at 11:04:04 am
Please don't make everyone google part numbers, include relevant links or the
actual specs that matter.
8  Using Arduino / Programming Questions / Re: Using If to trigger different functions on: Today at 11:02:10 am
You at this thread - its about the same kind of problem:

In particular note the need to detect when the time now is _different_
from the last time round loop() - that's when you should trigger actions,
not every single time round the loop.

The exact same issue applies to timed events using millis(), button presses,
etc etc - you detect a change to trigger a response, not respond to a steady
state condition.

If the reponse is idempotent, it doesn't matter, but when you need some
non-idempotent you have to pay attention to detecting transitions rather
than states.

Google "idempotent", its a great word.
9  Using Arduino / Programming Questions / Re: Usage relay with step motor on: Today at 10:53:54 am

For a full rotatation there are 12 lots of 30 degrees, so looping 12 times would be

If you code up the 30 degree move and triggering the camera and pausing 3 seconds
into a function with a clear name, that will make the code reabable.
void rotate_and_take_photo ()
  stepper.runToPosition () ;
  delay (100) ; // wait for motion to fully stop
  trigger_camera() ;
  delay (3000) ;  // allow time for the camera to focus and take picture

Now loop() just has to decide when to initiatiate the sequence, which would use
a for-loop to iterate 12 times calling this function.

Disclaimer - its not finished/complete code - you have to do the real work!
10  Using Arduino / Programming Questions / Re: Interface TDA7439 with atmega 328p on: Today at 10:43:58 am
You're doing some odd things, updating input / range / val variables in place -
you should lose all those assignments and write some mapping functions:

Lets look at setSnd:
void setSnd(int val, int range)
  switch (range)
    case 1:range = TDA7439_bass;break;
    case 2:range = TDA7439_middle;break;
    case 3:range = TDA7439_treble;break;
    }   // uh-oh, no default case, have you considered that possibility?
  switch (val)
    case -7:val = 0;break;   // very verbose way to do this - there's a clear pattern
    case -6:val = 1;break;   // to exploit here.
    case -5:val = 2;break;
    case -4:val = 3;break;
    case -3:val = 4;break;
    case -2:val = 5;break;
    case -1:val = 6;break;
    case 0 :val = 7;break;
    case 1 :val = 14;break;
    case 2 :val = 13;break;
    case 3 :val = 12;break;
    case 4 :val = 11;break;
    case 5 :val = 10;break;
    case 6 :val = 9;break;
    case 7 :val = 8;break;
    }   // uh-oh, no default case, have you considered that possibility?
  writeWire(range, val);
(reformated a bit)

Conceptually this function takes a range code, and a val code,
and converts these to actual values for the writeWire call.

Do the conversion in a function - this is exactly what a function does best:
int device_range (int range)
  switch (range)
    case 1: return TDA7439_bass;
    case 2: return TDA7439_middle;
    case 3: return TDA7439_treble;
    default:  // so what about this case - perhaps we need to flag an error?
      return range ;

// each function does one thing, much easier to maintain
int device_val (int val)
  if (val >= -7 && val <= 0)  // exploit the obvious pattern in the mapping
    return val + 7 ;
  if (val > 0 && val <= 7)
    return 15 - val ;
  // so what about other cases?  perhaps flag an error
  return val ;

// Now setSnd is nice and simple, very clear.
void setSnd (int val, int range)
  writeWire (device_range (range), device_val (val) ;
11  Using Arduino / Programming Questions / Re: using multiple counters on 1 arduino on: Today at 10:24:00 am
Oh yes, that's a howler.  You cannot compare char* style strings using ==,
you have to call strcmp(). (+)

You don't need strings to name states - do some research on enum, or #define
or const keyword.  You typically use named small numbers to identify things
in code, not strings.

If you want to print out the values then strings are appropriate(*), but
internally to the program that ends up being a clumsy and fragile way
of coding (experience will show you this, take it on trust for now!)

(+) A char* string is represented as a pointer to char, ie the address of
some chars that form the string.  The problem is many different copies
of the string could exist, with different addresses, so comparing addresses
using '==' could give false even though the same string contents are

The String class is available for a higher-level implementation of
strings, and String objects can be compared by == because the class
overrides == for String objects.  String objects have more overheads
than char* strings, and in particular heap-allocate, using more RAM.

(*) You can index an array of string with the small integer value, for
12  Using Arduino / Programming Questions / Re: Basic Questions re using Arduino pins on: Today at 10:16:48 am
(I'm not sure if this is the correct forum for these questions, but it seemed closer than any of the other choices.)

   2.  I have read in numerous places that the analog pins can be used for digital input or output, but I haven't found anything that tells me how to do so.  Is any special code necessary to configure the pins for digital I/O or can I just do a digitalRead or digitalWrite which refers to (for example) pin A1?

On Arduinos using the ATmega328 (or 168) chip the analog inputs A0..A5 are
perfectly valid as digital pins too.  Some boards though (not the Uno) bring out
A6 and A7 as well - these two are analog inputs only, are only present on the
surface mount ATmega328 and cannot be used as digital pins - they are inputs
that only connect to the ADC multiplexer.

On the Mega all analog input pins are digital too.

On the Due the analog input pins are digital too.
13  Using Arduino / Programming Questions / Re: using multiple counters on 1 arduino on: Today at 10:06:02 am
In ReadColor() replace:
  //Learned blue, green, red percentage values of different colors
  int SavedColorRed[] = {
    28,55,42,50,19,13  };
  int SavedColorGreen[] = {
    30,25,36,22,45,26  };
  int SavedColorBlue[] = {
    45,20,20,30,36,58  };
  char* GetColor[] = {
    "white","orange","yellow","red","green","blue",""  };
  //Learned blue, green, red percentage values of different colors
  static int SavedColorRed[] = {
    28,55,42,50,19,13  };
  static int SavedColorGreen[] = {
    30,25,36,22,45,26  };
  static int SavedColorBlue[] = {
    45,20,20,30,36,58  };
  static char* GetColor[] = {
    "white","orange","yellow","red","green","blue",""  };

That way those arrays are statically allocated and setup once - not built laboriously
on the stack on every call.  The passed back string is statically allocated
anyway, as it happens, but these arrays are static in nature - you can declare
them const as well as they are constant.
14  Using Arduino / Programming Questions / Re: Basic Questions re using Arduino pins on: Today at 09:28:31 am
Until you understand all the complexities of using RX and TX pins, best avoid them.

Some of this is board-dependent:
They may have pull-ups attached.  They have a USB-serial device attached via resistors.
During boot/reset the lines are sensed by the bootloader to determine whether to download
a new sketch.
The bootloader may leave the TX pin as an OUTPUT.
Serial.begin()/end() may change the configuration of the pins - On the Due
they become detached from normal I/O functions.

Any other hardware on them will potentially interfere with ability to bootload,
bootloading and serial I/O will interfere with the other hardware...

Anyway generally this means you have to decouple any extra hardware(*)
from them at reset time, which can be tricky and just not worth it.

(*) The exception is when routing TX to an extra serial serial terminal such
as a serial enabled LCD display - normally this works but you get
garbled text when uploading a new sketch, which you can live with.
15  Using Arduino / Programming Questions / Re: DS3231 Clock & Time value on: Today at 09:20:01 am
What's wrong with:

  if (hour == 15 && minutes == 45)

(Actually the answer is that this test will repeatedly trigger in loop()
for a whole minute, so you need a flag to say I've already triggered today,
or something like:

void loop ()
  read_time () ; // or whatever you need to read the variables

  if (hour == 15 && minutes >= 45 && prev_minutes < 45)
    do_stuff () ;
  prev_minutes = minutes ;
  prev_hours = hours ;
Pages: [1] 2 3 ... 840