Show Posts
Pages: 1 ... 59 60 [61] 62 63 ... 226
901  Using Arduino / Programming Questions / Re: Command for auto-off? on: July 15, 2013, 11:38:45 am
So I guess that is a no?

Correct, there is no way for the Arduino to automatically shut itself without the aid of additional circuitry.
902  Using Arduino / Programming Questions / Re: Can't seem to get out of loop. on: July 15, 2013, 11:26:31 am
relayState is never updated within your while loop.

This does absolutely nothing:

I suspect you meant this:
relayState = digitalRead(relayPin);
903  Using Arduino / Programming Questions / Re: 4 Buttons - 4 Relays - Help needed with code on: July 15, 2013, 12:09:23 am
Any ideas on how to do this?

Start with 1. Look at the StateChangeDetection example to get the toggle working.
904  Using Arduino / Programming Questions / Re: Blink and return to loop() on: July 14, 2013, 11:05:18 am
Yes, but unfortunately it's just that my problem .... poorly written program.... But how do that ? could you help me ?

Create a flag variable:

byte flag = 0;

When serial data is received, set that flag to 0:

If (Serial.available() > 0)
  flag = 0;

If the serial data you received was a 'D', then set the flag:

else if (ch == 'D')
  flag = 1;

In your loop() function (and not nested in any other if statement), only call toRight() if the flag is set:

if (flag == 1)
905  Using Arduino / Programming Questions / Re: Blink and return to loop() on: July 14, 2013, 09:50:28 am
Thank you for the quick response.
Yes,   ch = at the beginning of loop () and  with a println (ch) ch is always equal to 'D'  as if there is more than receipt of datas...

The "beginning of loop ()" isn't run as long as you are still within your while loop, so ch never gets updated.
906  Using Arduino / Programming Questions / Re: Serial buffer being corrupted by inclusion of code on: July 13, 2013, 05:03:26 pm
I guessing you have contributed to the avr toolset to be so offended by a suggestion for an improvement.


"I blame them"

Sure sounds like a suggestion for improvement. ..
907  Using Arduino / Programming Questions / Re: Serial buffer being corrupted by inclusion of code on: July 13, 2013, 12:44:08 pm
Thanks John!  That appears to be the problem.  I'm now moving all of my UI strings over to flash using the technique documented here:  
I had no idea of the 2k ram limitation (I'm used to writing servers that can use 2gb!).  I do fault the arduino IDE / toolset for not detecting this problem, as all of the ram allocations seem to be static and fairly easily verified before loading the sketch.


Not all used RAM usage is static, and considering a single inclusion like that put you over, I'm betting that if you totaled ALL of the static declarations, it wouldn't be over 2K. I guess its' easier though, to blame others.
908  Topics / Home Automation and Networked Objects / Re: Idea: Home guardian sends e-mail when door stays open on: July 13, 2013, 11:32:28 am
This here:


Returns a 16 bit value. Say you're trying to read from TextMailSubject, that 16 bit value will contain 'G' and 'a'. You then try turn 'G' and 'a' into a pointer. That's not doing what you think its doing. What you need is to read the first character:

int i = 0;
char c = pgm_read_byte(&TextItemPointers[ItemIndex] + i);

You can put that in your buffer, and use a while loop to keep reading until you reach a null ('\0'):

while (c != '\0')


Within the while loop, you need to increment i, read the next character, and put that in your buffer. Once you're out of the while loop, you'll just need to null terminate the array:

buffer[i] = '\0';
909  Using Arduino / Programming Questions / Re: Question about variables on: July 13, 2013, 12:02:23 am
what is the difference between the two declarations?

int ledState=0;


int ledState;

do they do the same thing? 

The first declares a variable and initializes its value to 0.

The second declares a variable. Its value will be whatever was last in that memory location. It might be 0, it might not be.
910  Using Arduino / Project Guidance / Re: Connecting a passive infra-red sensor to a computer via a USB port on: July 12, 2013, 04:25:02 pm
The current it needs will just be sucked up by itself, but because the needed current is very low, wouldn't it uhm... heat up? or because the sensor already have resistors embedded on it?

Why would low current cause a device to heat up, and why would a sensor need "embedded" resistors?

I don't think you have a firm grasp on some of the basic principles of electronics. If a device needs X amount of current, that means it "pulls" the current from you power source.
911  Using Arduino / Programming Questions / Re: [Solved] if statement question on: July 12, 2013, 04:14:44 pm
912  Using Arduino / Programming Questions / Re: Arduino and HTML Buttons on: July 12, 2013, 02:44:09 pm
The compiler is going to interpret the quote before button to mean that you want the string to end there. If you want to insert quotes into a string literal, use the escape sequence:

Serial.print("I can print quotes like this: \" and like this\".");
913  Using Arduino / Programming Questions / Re: Adding hardware devices in software dynamically on: July 12, 2013, 01:53:11 pm
It sounds like you mean "dynamic" more in the sense for programmers, rather than users. In other words, once the code is compiled, the number of devices doesn't change. If that is the case, implement a begin or start type function that accepts the arguments of how many devices the programmer will be adding and use malloc() to allocate the memory. You don't have to tell the programmers to go digging through the library to change a setting and won't suffer from issues of fragmentation.
914  Using Arduino / Programming Questions / Re: Arduino programming using C++ on: July 12, 2013, 10:35:11 am
I have over over 5 years experience in Java and 2 years in C++.

Could you please help me now?

Even though I have experienced in programming , I would like to get good foundation on Arduino usage , something that guide me with examples of C++

Have you tried any of the examples yet? Most people start with them, and that is sufficient.
915  Using Arduino / Programming Questions / Re: Binary Communication - Command Request Question on: July 11, 2013, 03:59:46 pm
you get 8 bytes? or 8 bits? { in ascii is 7B, so it will print 0111 1011 no? smiley-roll-sweat

Nope, you get 8 bytes:

'0', '1', '1', '1', '1', '0', '1', 1'

Note the single quotes. The BIN argument tells it to use the ASCII encoding of the binary value of the given character. '0' and 0 binary are not the same value, nor are the same bit-width:

'0' = 48 decimal = 0x30 = 0b00110000 // The character '0'
0 = 0 decimal = 0x0 = 0b0

What i basically was trying to do was to send
0111 1011 0111 1011 1101 0010 ... ....
  7     B       7     B      D      2 .... ....

As I suspected, you don't want to send 'D', '2', you want to send 0XD2. You can do something like this:

Serial.write('{'); // sends 0x7B
Serial.write('{'); // sends 0x7B
Serial.write(0xD2); // sends 0xD2
Serial.write(0x00); // sends 0x00
Serial.write(0x02); // sends 0x02
Serial.write(0xD4); // sends 0xD4
Serial.write('}'); // sends 0x7D
Serial.write('}'); // sends 0x7D

Both print and write still send binary data. The different is how they interpret the data to send. If the data provided is numeric, print will convert it to the ASCII representation which could be up to 3 bytes worth of data. write will just send the single byte of binary data:

Serial.print(2); // sends '2' = 0b01010000
Serial.write(2); // sends 2 = 0b00000010

For the former block of code, we can save a couple of lines of code by using an array:

byte command[] = {
    {', '{', 0xD2, 0x00, 0x02, 0xD4, '}', '}'
Serial.write(command, sizeof(command));
Pages: 1 ... 59 60 [61] 62 63 ... 226