Show Posts
Pages: 1 2 3 [4] 5 6 ... 18
46  Using Arduino / Programming Questions / Re: getenv/setenv - Arduino equivalent on: June 21, 2012, 10:34:39 am
If you want to send data from or to the Arduino over ethernet, you can use a web server or client. Check out this tutorial: http://arduino.cc/en/Tutorial/WebServer
47  Using Arduino / General Electronics / Re: IR frequency on: June 20, 2012, 04:21:59 pm
You will need the Arduino to detect hits in the targets and to keep the score, but you probably don't want/need to use the Arduino in the guns. As DuaneB suggested, use 555 timer to generate 38kHz frequency. If you need to distinguish several guns from each other, use second 555 the generate payload signal which is different for each gun (say 1000Hz for one gun and 800Hz for an other).
48  Using Arduino / General Electronics / Re: IR frequency on: June 20, 2012, 03:51:08 pm
Quote
I was wondering if a photo-transistor would be better for my application.

It won't be. You really need a "real" IR detector which detects 38kHz modulated IR signal. If you just try to detect an IR beam with a photo-transistor it would be very difficult to distinguish the ambient IR (for example, sunlight) from the actual beam you want to detect.
49  Using Arduino / Programming Questions / Re: Program compiles, but breaks setup() on: June 20, 2012, 02:35:10 pm
Have you set the same serial speed in the serial monitor and in the sketch?

If that doesn't solve the problem, try to reduce the sketch by removing everything that is not related to the problem. For example, remove everything but

Code:
Serial.begin(9600);
Serial.print("Server address:");

from setup() and check if it still behaves erratically.
50  Using Arduino / Programming Questions / Re: Having trouble concatenating a char* on: June 19, 2012, 02:26:45 pm
Code:
string[19] = '\0';

You don't need to do that. strcat adds the trailing zero automatically.

Quote
Ahh got it. I can basically just set the FIRST value to '\0'

You can do that, or you can use strcpy instead of strcat to copy the first value into string as I suggested:

Code:
strcpy(string, Chord[navigator]);  

If you do that, there is no need  to separately "clear" the string by setting the first char to '\0'.

51  Using Arduino / Programming Questions / Re: What happens if sketch tries to write to serial when no port is available? on: June 19, 2012, 11:17:15 am
Code:
But what happens if the serial port is not connected and the sketch still tries to write to serial port?

Nothing happens. Unless the other end should write something back or some kind of handshake protocol is involved, your sketch can't tell if the port is connected or not.
52  Using Arduino / Programming Questions / Re: array, pointer & adressOf on: June 19, 2012, 03:23:42 am
Nick just pointed out that you didn't present a real question that can be answered. But my answer to you question is "Yes, you have to implement something with pointers & adressOf."

You really cannot write anything but the most trivial C++ programs unless you have a good grasp of pointers.
53  Using Arduino / Programming Questions / Re: How do I insert a string in a file on a SD card? on: June 18, 2012, 03:12:23 pm
You don't actually have to save the write position as I earlier suggested. If the last part of the file is always the same, you can seek back a fixed length from the end of the file.
54  Using Arduino / Programming Questions / Re: How do I insert a string in a file on a SD card? on: June 18, 2012, 10:00:22 am
You don't need to rewrite the whole file, but you need to rewrite everything from the point where you append the coordinates. When you add new coordinates, save the position after the last coordinates (where you want to write the next set of coordinates). On the next time you need to write the coordinates, you open the file for writing, seek to the position you saved and write the coordinates and the part of the file that comes after the coordinates (e.g, </coordinates> ... </kml>")
55  Using Arduino / Programming Questions / Re: Having trouble concatenating a char* on: June 18, 2012, 09:15:48 am
Did you try the piece of code I suggested? The way you manipulate the string in the code you posted is wrong. It may seem to work at some extent, but will surely mess up the memory.

This is still wrong

Code:
char* string;
string = Chord[navigator];
strcat(string, " : ");
strcat(string, Camelot[navigator]);
 u8g.firstPage();
 do {
draw(string);
 } while( u8g.nextPage() );

You are still not allocating memory for string. When you do the assignment:
Code:
string = Chord[navigator];
you start using the memory allocated for Chord[navigator].  Lets assume that the initial value of Chord[navigator] is "foo" and Camelot[navigator] is "bar".
After your code executes the strcat statements, both string and Chord[navigator] point to char array "foo : bar". (And probably writes beyond the memory you allocated for Chord[navigator]).
When your code runs the strcat for second time (e.g. in the loop fuction) you are concatenating "foo : bar", ": " and "bar". And after third iteration string will be "foo: bar : bar : bar" and so on. Seems to be pretty much what you said you saw on the lcd

With each iteration the string keeps growing untill it runs beyond the Arduino's address space. At that point, if not earlier, you sketch will crash.
56  Using Arduino / Programming Questions / Re: Having trouble concatenating a char* on: June 17, 2012, 04:54:06 pm
Quote
However if I try to allocate memory to it like char* string[20] or char string[20], I get the error:
incompatible types in assignment of 'char*' to 'char [20]

On what line do you get the error "incompatible types in assignment of 'char*' to 'char [20]"? I don't know what the signature of draw function in your code is, but I'm pretty sure the piece of code I posted works as I explained.

Did you declare "string" both as "char *string;" and "char string[20];"? You should only keep the latter. And 20 here is only an example. Make sure that the string is long enough to hold the whole text you want to display.


57  Using Arduino / Programming Questions / Re: Having trouble concatenating a char* on: June 17, 2012, 02:38:51 pm
Have you used Serial.print to check that string is what you think it is? Do you set the cursor between writes (lcd.home() or something)? It may be that concatenation happens because you don't return the cursor and/or clear the lcd between writes.

Anyway, the way use the "string" variable seems suspicious:
Code:
string = "";                            
string = Chord[navigator];  
strcat(string, " : ");
strcat(string, Camelot[navigator]);
If string is of type "char *", you need to allocate memory for it.

This is unnecessary
Code:
string = "";
because the after the next line string holds the value of Chord[navigator].
Code:
string = Chord[navigator];  
If Chord[navigator] holds a pointer to a string, has it enough memory allocated for " : " and the value of Camelot[navigator]?
Code:
strcat(string, " : ");
strcat(string, Camelot[navigator]);

The code may seem to work even if you haven't allocated enough memory for string. if it overflows (strcat writes beyond the allocated memory), depending on what variables etc. the memory holds it may or may not crash. But you really should make sure you have allocated enough memory, e.g.,

Code:
char string[20]; // allocate enough memory for Chord[navigator], " : " and Camelot[navigator]
strcpy(string, Chord[navigator]);  
strcat(string, " : ");
strcat(string, Camelot[navigator]);


58  Using Arduino / Programming Questions / Re: Communicating with IC's without a library on: June 17, 2012, 01:56:29 pm
Code:
But how do you know what kind of data to send to it?

HIGH, LOW, 10110010, 3E, 0x000004.

If you send data to an external IC,  you send HIGHs and LOWs to it, that is, you set the pins to 0V and 5V (different ICs may require different voltage levels) in certain order for certain periods of time. Things like 10110010, 3E, 0x000004 are higher level abstractions of the data and the datasheet explains how the data maps to HIGHs and LOWs.
59  Using Arduino / Programming Questions / Re: Enumerator values to char* on: June 17, 2012, 11:25:37 am
Enums don't work as you seem to think. Enums are more like named integer values. You should use an array of strings instead.
60  Using Arduino / Programming Questions / Re: Convert int to char and append to buffer on: June 16, 2012, 09:51:43 am
Quote
I really don't get C programming with pointers.

I really think you should take the time and learn to understand the pointers. They are absolutely crucial in the C/C++ programming. And it's not that hard to learn really. 
Pages: 1 2 3 [4] 5 6 ... 18