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.

-br
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 serial.open, this won't work:

Code:
serialport = serial.Serial("/dev/ttyAMA0",115200);
serialport.write("^Power&\n");

This works better for me:
Code:
serialport = serial.Serial("/dev/ttyAMA0",115200)
time.sleep(2)
serialport.write("^Power&\n")

-br
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.


-br
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.


-br
260  International / Software / Re: Salvare i commandi inviati via Serialport su una SD on: April 12, 2013, 07:12:45 am
Something like this:
Code:
#define BUFSIZE 15
case 2:
{
byte pos= 0;
char buffer[BUFSIZE];
buffer[0] = 0;
while (pos < BUFSIZE-1) {
if (Serial.available()) {
char c = Serial.read();
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":

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

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,

-br

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?

-br
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.

-br
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?

-br
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:

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

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

Code:
    write(serialFileDescriptor, &val, 1);

-br
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:

https://github.com/billroy/bitlash-commander

-br
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:

Code:
while (!digitalRead(button)) {;}
servo_1.write(180);

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?

-br
 
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:

http://www.easysw.com/~mike/serial/serial.html

-br
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.

-br
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:

Code:
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);
delay(del);
}
Pages: 1 ... 16 17 [18] 19 20 ... 67