Show Posts
Pages: [1] 2 3 ... 31
1  Using Arduino / Programming Questions / Re: Error: com port X already in use on: Today at 02:35:01 pm
I copied the complete error message, which is:

Binary sketch size: 11,416 bytes (of a 30,720 byte maximum)
processing.app.SerialException: Serial port 'COM2' already in use. Try quiting any programs that may be using it.
   at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
   at processing.app.Sketch.upload(Sketch.java:1671)
   at processing.app.Sketch.exportApplet(Sketch.java:1627)
   at processing.app.Sketch.exportApplet(Sketch.java:1599)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
   at java.lang.Thread.run(Thread.java:619)
2  Using Arduino / Programming Questions / Error: com port X already in use on: Today at 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?
3  Using Arduino / Programming Questions / Re: simple maths on: Today at 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:

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

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

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

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

Code:
int bad;
w = (long) bad;

because it documents your intentions.
4  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.
5  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:

Code:
  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.
6  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:

Code:
// ...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.
7  Using Arduino / Programming Questions / Re: Problem with RTC and time library on: April 11, 2014, 11:47:08 am
Quote
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:

Code:
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
  Wire.endTransmission();

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.
8  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.
9  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?
10  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:

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

I would have expected something more entertaining,  like:

Quote
You can read the 6th position of a 4 element array, it's just that it probably won't be anything useful.
11  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.
12  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?
13  Using Arduino / Programming Questions / Re: Problem with RTC and time library on: April 09, 2014, 12:00:21 pm
It makes it easier for us if you post your code. With the cursor in the Arduino IDE, do Ctrl-T to format it in a standard way, then use the sharp sign ('#') and copy your code between the two code tags.
14  Using Arduino / Programming Questions / Re: Help with extracting coordinates for usage in GPS program on: April 08, 2014, 09:04:39 pm
Try looking at: strchr(), strnchr(), and strtok(). Read the descriptions, think about what you're trying to do and write it down, then go back and read the descriptions again. I think you'll know exactly what to do.
15  Using Arduino / Programming Questions / Re: Time on a display on: April 08, 2014, 01:31:42 pm
Don't the values returned have to be converted from BCD back to decimal??
Pages: [1] 2 3 ... 31