Show Posts
Pages: 1 2 3 [4] 5 6 ... 837
46  Using Arduino / Programming Questions / Re: #define, int or const int on: July 19, 2014, 10:43:28 am
could see NO reason to use const instead of define, based on my experience and reading of the documentation.

Using a const value is better than using a macro substitution because it gives you explicit visibility and control over the type of the value. It is a better way of doing the same thing.

However, based on the level of understanding and competence in C++ you have shown so far in this thread, I'm not surprised that you have reached a different conclusion. You seem to have fundamentally misunderstood how the C++ preprocessor works, which is surprising given the experience you claim to have.

47  Using Arduino / Programming Questions / Re: Serial Monitor -> GUI on: July 19, 2014, 10:22:02 am
And it's a better IDE than the Arduino one too smiley-razz

^^^ That.
48  Using Arduino / Programming Questions / Re: Adding character to string on: July 19, 2014, 10:21:12 am
If you know that the client is only going to send one command each time it connects then you can keep reading and buffering the incoming characters until the client disconnects or you receive the terminating character 'a'.

// incomplete, untested

const byte BUFFER_LENGTH = 32; // make this long enough to hold your longest command
char buffer[BUFFER_LENGTH+1]; // +1 allows space for the null terminator
byte bufferCount;

void loop()
    // Create a client connection
    EthernetClient client = server.available();
    if (client)
        Serial.println("Client connected");
        while (client.connected())
            if (client.available())
                char c =;
                if(c == 'a')
                    bufferCount = 0;
                    buffer[bufferCount] = 0;
                    // if you want the server to disconnect the client after receiving the first command, call client.stop(); here
                    if(bufferCount < BUFFER_LENGTH)
                        buffer[bufferCount++] = c;
                        buffer[bufferCount] = 0; // append null terminator
                        // buffer full - discard received character

void handleMessage(char *msg)
    your code here
49  Using Arduino / Programming Questions / Re: Sending single int with NRF24LO1 on: July 19, 2014, 08:15:17 am
I think I understand now.

All you need to do is record the highest number that you have received. If you receive duplicate or lower numbers, ignore them.
50  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 19, 2014, 08:12:43 am
The delay function "stops" interrupts.

I don't think that's the case.
51  Using Arduino / Project Guidance / Re: Use photoresistor to stop actuator. on: July 19, 2014, 07:59:33 am
I have been able to get it to be basically 0 or 180

You don't say what sort of actuator you have, but if you know how to move it to a given position then all you need to add is a pair of LDRs as Robin2 describes. The algorithm to control the actuator is then extremely simple.
52  Using Arduino / Project Guidance / Re: Using Arduino to access a hard drive wirelessly, how to...? on: July 19, 2014, 07:55:21 am
Is it important that you access the hard drive directly? As soon as you introduce a PC between the Arduino and the hard drive, the problem becomes much simpler to solve. If you can find/write an Arduino NFS or SMB client, it would also be easy to add a network interface and access network attached storage, windows file shares, NFS shared drives etc.
53  Using Arduino / Project Guidance / Re: Read PWM signal (12v wave) get it's frequency, output PWM converted frequency x2 on: July 19, 2014, 07:51:02 am
The rpm gauge works with arduino 5V pwm signal frequency between 10-220 HZ (tested)

It seems unlikely that you tested what you describe above, since it's neither easy nor necessary to generate a variable frequency PWM signal in this case.

All you need is to
(1) measure the incoming pulse length in microseconds.
(2) halve that value.
(3) use the technique demonstrated in blink without delay to output a square wave of that pulse length

The whole sketch would probably be about a dozen lines of code.
54  Using Arduino / Project Guidance / Re: Keypad Entry with Multiple PIN Numbers on: July 19, 2014, 07:46:08 am
It's possible, but requires a fundamental change to the way you validate PINs. Currently you validate each input against the PIN and allow the user to enter an endless sequence of numbers until you get four consecutive numbers that match the expected value. That's very unsecure, and in any case won't work when you need to support multiple PINs.

Instead I suggest you separate out entering the PIN from validating it. Require the user to enter a PIN of the expected length before you validate it. I suggest you apply a timeout between key presses so that if an incomplete PIN is entered the system will clear itself back down after a little while. Store the entered PIN as a null-terminated char array.

Store the valid PINs in an array of strings (null terminated char arrays).

When the whole PIN has been entered you can validate it by looping through each of the valid PINs and using strcmp() to test whether the entered PIN matches that entry.

It would be sensible to introduce a minimum inter-key delay, and lock the keypad out for a while after each failed attempt, to increase the time needed for a 'brute force' attack.

You should consider how you are going to configure and maintain the set of PINs. In my opinion it would be more sensible to do the PIN validation and logging on an attached PC and just use the Arduino as an interface to the keypad and display etc; with this approach, the valid PINs would be defined on the PC (where they are easy to display and change) and the Arduino part can be relatively dumb.
55  Using Arduino / Programming Questions / Re: Sending single int with NRF24LO1 on: July 18, 2014, 07:53:57 pm
I also would like to stop receiving a specific number once its been received. Otherwise I have scene numbers coming in like crazy

Do you mean you want to stop *sending* it? The receiver will receive whatever is sent.

If you can explain exactly what behaviour you want, I'm sure it will be possible to achieve it.
56  Products / Arduino Yún / Re: HTTP Routing on Arduino Yun on: July 18, 2014, 11:36:58 am
When I try to cat, less or vi the *.lua files on my Yun they all come up as binary. Same happens if I 'scp' to my local machine and open them in vim or sublime text. Anybody seen this/have any idea why it's happening?

What file type does 'file' indicate for it?
57  Using Arduino / Project Guidance / Re: Trying to combine a RomeoV2 motordriver and a Servo in codes on: July 18, 2014, 11:25:39 am
I try to include a servo that should sweep from 30 to 150, but somehow it interfere with the receiver and the platform runs uncontrolled.

If you disconnect the servo but leave everything else the same, does that affect the behaviour?

I suggest you describe/draw your hardware setup including details of the power supplies, and what the sketch is intended to do.
58  Using Arduino / Project Guidance / Re: Arduino Linear image sensor not reading pixels on: July 18, 2014, 11:20:14 am
There's too much code there to be worth reviewing in detail, but I'm surprised to see that you're hitting the I/O registers directly, and using floating point values for time, and have invented your own version of delayMicroseconds(). I suggest you try to write a test sketch that does the absolute minimum needed to get data out of the chip and don't worry about buffering images etc until you know you can talk to it OK.

It would help if you described / illustrated the overall circuit including the Arduino and the sensor, and gave a summary of what your code was intended to do for example how you're configuring the chip and how you're communicating with it in terms of clock and data signals.

The data sheet says this:
Clock frequency: 100kHz (Min), 1MHz (Max)

What frequency are you trying to use, and how are you controlling the clock frequency?
59  Using Arduino / Programming Questions / Re: Help understanding a script. on: July 18, 2014, 09:36:57 am
My question is how can use that filtered result to control a motor's speed and direction? like if (xangle > 0) {digitalWrite (IN1, LOW); digitalWrite (IN2, HIGH); analogWrite (ENA, i);} etc...

You need to understand what relationship you need between the input signal from the sensor, and the output signal you need to supply to the motor driver. The relationship would be determined by what your solution is intended to achieve - which you haven't told us.
60  Using Arduino / Project Guidance / Re: Arduino and a 17 servo motor robot, possible? on: July 18, 2014, 09:31:58 am
If you have a lot of servos to control, you might find it best to offload the servo signal generation to something like this, and let the controller focus on managing the servo positions.
Pages: 1 2 3 [4] 5 6 ... 837