Show Posts
Pages: 1 2 [3] 4 5 ... 33
31  Using Arduino / Programming Questions / Re: dtostrf return NANO on: April 17, 2014, 12:14:34 pm
Good catch, Paul...
32  Using Arduino / Programming Questions / Re: dtostrf return NANO on: April 17, 2014, 10:30:25 am
Can you post an example that duplicates the error?
33  Using Arduino / Programming Questions / Re: Error: com port X already in use on: April 16, 2014, 10:10:31 pm
Thanks Peter: I had it happen again several hours ago and I did load the Task Manager and, sure enough, there was a process tying up COM port 2. I right-clicked on the application and it identified the process as belonging to Chrome, which is the browser I use. Chrome has multiple processes running, but most of the time, none is identified as using COM port 2. I clicked on the End Process option, Chrome shut down, and the IDE was happy again. I can't identify what the process controls, nor do I remember doing anything but the usual within Chrome. Oh well, at least I know how to make it go away.

Thanks again...
34  Using Arduino / Programming Questions / Re: Error: com port X already in use on: April 16, 2014, 02:35:01 pm
I copied the complete error message, which is:

Binary sketch size: 11,416 bytes (of a 30,720 byte maximum) Serial port 'COM2' already in use. Try quiting any programs that may be using it.
35  Using Arduino / Programming Questions / Error: com port X already in use on: April 16, 2014, 02:17:31 pm
I've had this happen with IDE 1.05: I've been working on a program for many hours, perhaps performed 30 compiles using Com port 2, and everything is fine. Then I recompile again, which it does fine, but on the upload I get a message that says the port is already in use. Sometimes, if I save the current sketch, and try to recompile, it compiles and uploads without problem. Other times, that does not work and I have to exit the IDE altogether and reload the IDE, reload the sketch, and recompile/upload and things work fine again. Given enough recompiles, however, it will do the same thing again.

I'm using Windows 7 with 16Gb of memory. Has anyone else had this problem, and if so, did you find a work around?
36  Using Arduino / Programming Questions / Re: simple maths on: April 16, 2014, 08:48:55 am
Jack's solution used what is called a cast, which involves placing the data type within parentheses before it is used:

long w = (long)analogRead(A0)

What this does is take the 1 byte returned from the analog read of pin A0, and convert it to the 4 bytes the long data type requires. When to use a cast? If w is a long data type, doing this:

int bad;
bad = w;

won't work well because you are trying to pour 4 bytes of information held in w into a 2-byte bucket named bad, which can result in lost information if it isn't corrected. The fix is to use a cast:

int bad;
bad = (int) w;

The cast says: Take the 4 bytes from w and reshape it into 2 bytes and assign it into bad. Note, a silent cast:

int bad;
w = bad;

is not a problem because you are taking the contents of a 2-byte bucket and assigning it into a 4-byte bucket. However, good coding practice says to use as cast in this case, too, even though it isn't required:

int bad;
w = (long) bad;

because it documents your intentions.
37  Using Arduino / Programming Questions / Re: Correlation matrix to calculate similarity? on: April 15, 2014, 02:54:12 pm
If you look up Sums of Squares or Sum of Differences, you'll likely find references to Analysis of Variance (ANOVA) as well as the Correlation Coefficient (and R^2 analysis). Depending on the data, will an int be large enough to hold the result? Also, take the definition of uint8_t diff out of the loop. Finally, with the cursor in the source code window of the Arduino IDE, press Ctrl-T to reformat your code in a little easier-to-read format.
38  Using Arduino / Programming Questions / Re: Parsing a part of a string of unknown length on: April 15, 2014, 02:47:16 pm
Wouldn't it be easier to use:

  int bytesRead;
  if (Serial.available()) {  // when the serial port is available
      bytesRead = Serial.ReadBytesUntil('\n', command, MAXLEN);
     // more code...

This reads the entire line of code up to the newline character into the string buffer command and returns the number of characters that were read.
39  Using Arduino / Programming Questions / Re: Parsing a part of a string of unknown length on: April 15, 2014, 10:35:52 am
If com contains the line to be parsed and you know the leadin is always 20 characters in length, how about:

// ...your code, then add:
int len = strlen(com);              // How long is the string?
strncpy(title, &com[19], len - 20); // Skip over 20 characters and copy the rest.

This still leaves the newline character at the end, but you can chop that off if you need to.
40  Using Arduino / Programming Questions / Re: Problem with RTC and time library on: April 11, 2014, 11:47:08 am
The DS1307 doesn't have a register for the weekday...

Sure it does.  Register 0x03 is the DAY register and is taken from bits 0-2 and has a value from 1 through 7 (it is not zero-based). An example of writing to the RTC is:

Wire.beginTransmission(I2C_RTC); // Select RTC
  Wire.send(0);        // Start address
  Wire.send(DecToBcd(second));     // Second
  Wire.send(DecToBcd(minute));    // Minute
  Wire.send(DecToBcd(hour));    // Hour
  Wire.send(DecToBcd(weekday));    // Weekday
  Wire.send(DecToBcd(day));    // Day
  Wire.send(DecToBcd(month));     // Month (with century bit = 0)
  Wire.send(DecToBcd(year));    // Year

Note the Wire.send(0) statement near the start of the code. This call is done to reset the internal register pointer for the timekeeper register. The pointer autoincrements when a register is read/written.  Passing in a zero value resets the pointer to the start of the timekeeper register. Failure to do that will cause the pointer to read/write to wherever the register pointer currently points. The pointer does "wrap around" after the last timekeeper register is read.
41  Using Arduino / Programming Questions / Re: function pointer & memory selection on: April 11, 2014, 06:52:44 am
Perhaps you could pass in a pointer to a union and, upon return from the function, extract the value you need that the function placed in the union.
42  Using Arduino / Programming Questions / Re: How do i find an average value from an array? on: April 11, 2014, 06:46:01 am
If you know you need the average, why wouldn't you maintain a running average as the values are read in from the sensors? You could still save them in the array, but why read them a second time?
43  Using Arduino / Programming Questions / Re: How to use switch case for light dependent resistor sensor's value on: April 10, 2014, 09:29:24 pm
@PaulS: You're going soft on us:

You can't read from the pin in the 6th position of a 4 element array.

I would have expected something more entertaining,  like:

You can read the 6th position of a 4 element array, it's just that it probably won't be anything useful.
44  Using Arduino / Programming Questions / Re: Problem with array scope and array content on: April 10, 2014, 09:20:57 pm
strcat() works with strings and char arrays are not necessarily strings. Some compilers do the equivalent of a memset() with zero that would make the array appear to work on the first pass. However, strcat() assumes there is a null-terminated sequence of data to which it adds the new data. Since the first time strcat() is called, all zeros looks like all nulls and things work out great. On the second iteration of the loop, that may not be the case. I'm not sure because I don't know how the compiler allocates memory for local arrays on each pass through a loop. I'm just saying it might be a problem. Brad's suggestion of using strcpy() on the first call is a good one.
45  Using Arduino / Programming Questions / Re: Reversing a Sketch with a button on: April 10, 2014, 11:56:36 am
How does buttonState get changed? Try looking at what comes back from the switch. Also, why an analogRead() when you're just looking for a switch closure?
Pages: 1 2 [3] 4 5 ... 33