Show Posts
Pages: 1 ... 16 17 [18] 19 20 ... 67
256  Using Arduino / General Electronics / Re: Do I need a resistor when connecting LED to digital output pin? on: April 13, 2013, 05:17:54 pm
… so use a resistor to limit the current to under 40 ma or you are likely to let the magic smoke out.

257  Using Arduino / Networking, Protocols, and Devices / Re: is there a difference in sending a serial command at setup and during loop? on: April 13, 2013, 08:57:23 am
Because the Arduino is in reset and then the bootloader for a couple seconds after the, this won't work:

serialport = serial.Serial("/dev/ttyAMA0",115200);

This works better for me:
serialport = serial.Serial("/dev/ttyAMA0",115200)

258  Community / Bar Sport / Re: Debugging - a dark art? on: April 13, 2013, 07:41:01 am
"Learned helplessness":  A state of cultivated denial caused by the assumption that the problem is someone else's to solve.

259  Community / Bar Sport / Re: Debugging - a dark art? on: April 13, 2013, 07:02:59 am
This is an important question that I think about a lot, and I'm glad you asked it.

I think the emotional aspects of debugging are often overlooked.  Discovering that the program you created is malfunctioning has an emotional dimension, right? 

Consider the five stages of a bug:

1. Shock
2. Denial
3. Anger
4. Bargaining
5. Acceptance

The helpless ones you are describing are stuck in shock/denial.  That is why it is so hard to direct their focus and attention.

The frustrated ones are stuck in the anger stage.  We've all been there.  Kind of hard to focus.

It's the ones who are past the anger and looking for answers/bargains that we can help with technical advice. 

In my view, people stuck in stages 1-3 actually need emotional / social support more than technical support, until they can get back to the state of mind required to articulate the problem and accept guidance to focus back on it so they can solve it themselves.

Would be interested in other thoughts on the matter.

260  International / Software / Re: Salvare i commandi inviati via Serialport su una SD on: April 12, 2013, 07:12:45 am
Something like this:
#define BUFSIZE 15
case 2:
byte pos= 0;
char buffer[BUFSIZE];
buffer[0] = 0;
while (pos < BUFSIZE-1) {
if (Serial.available()) {
char c =;
if ((c == '\n') || (c == '\r')) break;
buffer[pos++] = c;
buffer[pos] = 0;

Edit: Of course the VB program must be modified correspondingly to send a carriage return or line feed ascii character at the end of the command text.
261  International / Software / Re: Salvare i commandi inviati via Serialport su una SD on: April 12, 2013, 06:39:56 am
Please pardon my English.  This code has a bug of the type known as a "race condition":

  case 2:
if (Serial.available() > 0) {
byte pos= 0;
char buffer[15];
while (Serial.available() && pos < 15) {    // <-- race condition
buffer [pos++] =;

After testing for the presence of any number of characters, the code attempts to read up to 15 characters.  If they have not all arrived in the serial input buffer by the time this code is first run, the code will exit prematurely, and fail to read the data and write it to the SD card.

A common solution is to have an "end of input" character, perhaps a carriage return ('/r' or '/n') to signal that all the input characters have been received so that this loop can be rewritten so the race condition won't happen.

Good luck with your project,


262  Using Arduino / Programming Questions / Re: Quick question...can I call my setup() function? on: April 11, 2013, 10:22:37 am
I suppose it "should work" but it's kind of yucky.

Why not put the initialization you need to reuse into its own function and call it both from setup() and wherever else you need it?

263  Using Arduino / Programming Questions / Re: Reading step/direction on: April 11, 2013, 08:25:53 am
Capture the step pulses with an interrupt.  In the interrupt routine, push the direction readings into a circular buffer.  In loop(), pull readings out of the circular buffer and perform the output action.

264  Using Arduino / Programming Questions / Re: 'while' in setup(): what do I do wrong...? on: April 11, 2013, 07:01:39 am
If the button is wired right, the problem is in the code.  Could you post the whole sketch so we can be sure it isn't a small mistake in the part you haven't shown?

265  Using Arduino / Interfacing w/ Software on the Computer / Re: Cocoa: IOKit: Freeze when trying to send a message on: April 11, 2013, 06:51:28 am
Well you might want to step through that last part in the XCode debugger to see where it leaves the tracks.

This looks suspicious:

int val = 255;
    write(serialFileDescriptor, val, 1);
    NSLog (@"after2");

Shouldn't there be a & in front of val in the write command?

    write(serialFileDescriptor, &val, 1);

266  Using Arduino / Interfacing w/ Software on the Computer / Re: Easy way to Visualize and Store Serial Data on PC/Laptop? on: April 11, 2013, 06:47:41 am
Bitlash Commander might be worth a look, too:

267  Using Arduino / Programming Questions / Re: 'while' in setup(): what do I do wrong...? on: April 11, 2013, 06:45:33 am
I don't see a problem with the code, except it could be shorter:

while (!digitalRead(button)) {;}

So I wonder if your button wiring is correct.  Do you have a pull-down resistor to force the pin to 0 when the button is not pressed?

268  Using Arduino / Interfacing w/ Software on the Computer / Re: Library for sending/receiving data in UART Linux on: April 11, 2013, 06:40:59 am
Search for "serial communications in C"…  top hit looks potentially useful:

269  Using Arduino / Programming Questions / Re: rgb led fade on: April 10, 2013, 05:08:44 pm
The trickiness here is using a 16 bit counter (count) to control an eight-bit quantity.  The lowest 8 bits of count are used as the brightness, possibly inverted as I'll get to in a minute.  

The ninth bit of count is used as an up-down indicator, because it rolls over just as you'd like an up-down indicator to: it's off for the first 256 counts, then on for the next 256, and so on.  It's a little state machine, for free.

The expression that is puzzling you (count & 0x100) tests the ninth bit of count to see if it is one or zero (using a bitwise AND between count and a constant denoting the ninth bit).  If the ninth bit is one, we are in the counting down phase, and in that case the code inverts the brighness so instead of going from 0..255 it goes from 255..0, ramping down instead of up.

Read up on bitwise boolean operators for more on & (and) and ~ (bitwise complement) and their friends | (or) and ! (logical complement).

Hope that helps and happy to take followup questions.

270  Using Arduino / Programming Questions / Re: rgb led fade on: April 10, 2013, 04:33:59 pm
Yes, do stop turning off the lights.  And it's not needed to delay between each pin setting.  Something like this should generate the right pattern:

int count;

void loop() {

// increment the counter and grab 8 bits of brightness
byte brightness = ++count;

// use the next higher bit as an up or down indicator;
// invert the brightness on the down count
if (count & 0x100) brightness = ~brightness;

// update the pwm outputs
analogWrite(R, brightness);
analogWrite(B, brightness);
Pages: 1 ... 16 17 [18] 19 20 ... 67