Show Posts
Pages: 1 2 [3] 4 5 ... 26
31  Using Arduino / General Electronics / Re: Hall US1881 sensor issue on: June 27, 2014, 12:47:17 pm
The schematic shows analog input A0 connected to what appears to be a Hall effect device, and digital pin 13 connected to what appears to be an anemometer. 

I don't know of any reason that A0 shouldn't work as a digital input indefinitely.  To test your theory that something fails with pin A0, I'd recommend swapping those two devices - connect the Hall sensor to digital pin 13, and connect the anemometer to A0.  Naturally, you'll have to address that change in your code.  Then observe which one, if either, fails. 
32  Using Arduino / Programming Questions / Re: How does this loop end? on: June 04, 2014, 12:06:43 am
The loop terminates when the condition expression - the second thing in the for() statement - evaluates as 0, or false.  In this case, that expression is an assignment, which returns the value that's assigned to the left-hand side.  The string that pointer p points to has four elements: three printable characters, followed by a terminating null, or 0.  When the pointer is incremented to point to the fourth character, it assigns the value of 0 to character variable c.  The assignment evaluates as 0, or false, and the loop terminates.   

You can verify that the loop does indeed terminate, without building an SPI gizmo, by substituting a Serial.print() for the SPI.transfer in Nick's code, and then printing something afterward to prove that the processor hasn't hung.  To see the "stop on null" characteristic in action, you can insert a null in the string, like this:
const char * p = "Fa\0b" ;
and the code will print
33  Using Arduino / Programming Questions / Re: Software serial : buffer size limit on: June 03, 2014, 11:08:30 pm
[ I ] can't believe the solution isn't easy to find ...
Maybe the next one who tries this will find the solution here.  Do that one a favor, and read the sticky post at the top of this forum, entitled, "Read this before posting a programming question ..."  In particular, read the part that says,
When you post your code put it between [ code ] ... [ /code ] tags. You can do that by hitting the # button above the posting area.

Then edit your posts to conform to that recommendation by putting code tags around the bits of code in your several posts.  That will improve their readability and usefulness for posterity.
34  Using Arduino / Programming Questions / Re: Software serial : buffer size limit on: June 02, 2014, 06:45:34 pm
I think that you really, really want to be the one that figures this out.  I'll risk that some pedant will tell me that I'm not helpful, and say, "Here's a clue:"
... the string[ s ] are limited to 255 max size
The buffer has space for more than 255 characters, but still you see only 255 of them.  What kind of thing could cause that?  What kind of objects does a number like 255 bring to mind?
35  Using Arduino / Project Guidance / Re: Using a timer interrupt to exit out of a method on: May 28, 2014, 06:27:22 pm
Please see,148850.0.html.  Please pay special attention to:
  • Item #7, "If you are posting code or error messages, use "code" tags," and
  • Item #11, "Tips for getting the most out of your post."  In particular, please note:
Post a complete sketch (program code)! If you don't, you waste time while people ask you to do that. However, with coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code. If the problem goes away in the minimal sketch, it wasn't where you thought it was.

I think that "step() method" refers to the Stepper library provided with the IDE.  I interpret your question to be, "How do I make step() terminate early?"  One way is to call step() with the smallest reasonable argument, keep track of the number of steps and the current position with your own code, and check for a termination flag between calls to step().  Your button-press won't get an instant response, but it'll be fast, and step()'s record-keeping will match the motor's state as well as it does with multiple steps. 

Another way is to modify step() to internally check the termination flag, and return when it finds it set.  You'd want to make sure that step() terminates in an orderly fashion, with its record-keeping in sync with the motor's state.
36  Using Arduino / Programming Questions / Re: Timer1.attachInterrupt( timerIsr ) problem on: May 18, 2014, 06:28:01 pm
i changed "== "by" = "and i cleared " interrupt" and i wrote volatile unsigned long var[n] but nothing happened.
You need to do these things, too:
  • Declare n as volatile.  It's shared between the ISR and other code.
  • Delete the Serial.print() from Timer1 ISR.  That statement is what's stops execution.

How do I guarantee that "n" is increment to the 50 without put the serial inside the ISR ?
Serial.print() n from loop().

i think that your sketch still won't give you accurate results after you make those changes, but it ought to run.  The best I can tell, there will still be plenty of things wrong with it.  Your code is garbled because you didn't use code tags when you posted it.  Anyone who wants to help you will have to guess at what your code really looks like.  It's easy for you to make your intent clear; it's hard to guess what you meant.  It's been said before in this thread, but I'll be repetitive and say it again:

Use code tags when you post code.
37  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 17, 2014, 07:29:14 am
... a 1200x3 byte and a 1200x1 int, as opposed to a 1200x4 int.  That still won't fit in flash memory but it will help anyway.
It'll probably fit into flash memory, if your program isn't too big.  "Flash" refers to program memory, and there's a little less than 32K available.  Flash, or program memory, is where your data resides when you declare it using "PROGMEM".

You need 6000 bytes for your data.  If your program doesn't exceed about 25K or so, you should have room.  The IDE tells you the compiled size of the sketch; you can see it in the lower window when compilation completes.  The arrays won't fit into RAM, since there's only 2K of that.  

Edit:  spelling
38  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 16, 2014, 09:15:53 am
No your memory is lying to you.
Not yet, I think.  In a test program, this line compiles, and the array elements show up where I expect them:
int16_t a[3][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,0,1}, };
Note that last unnecessary comma before the last curly bracket.  No complaints from the IDE, even when I asked it to be verbose.  
39  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 16, 2014, 01:43:32 am
Your statement that I bolded above is not helpful., IMO.
Apparently not.  I thought it hinted at a solution to the OP's stated problem.  Since it didn't seem to work, I'll be explicit this time.

Addressing the OP's directly stated concerns,
Now I just need to figure out how to convert a CSV into an array and store it in program memory...
... it's 1200 rows long so there's no way I'm converting from CSV to the second format manually ...
In view of the resources that he seems to have in hand,
... I'm trying to get the data from Excel onto the Arduino ...

Here's how I'd put that data into a PROGMEM array:
  • Open the CSV file in a text editor, and copy it to the clipboard.
  • Open a spreadsheet, and paste.  The reason I wouldn't open the CSV in a spreadsheet directly is to keep the spreadsheet from trying to parse the data.  If you have a way of keeping it from doing that, you can open the CSV straight from the spreadsheet program.
  • Write a spreadsheet formula to append a curly open bracket, a curly closed bracket, and a comma to single line, and paste it where I need it.  In Excel or in LibreOffice that formula might be, untested:
="{ "&A1&" },"
  • Copy the results of that formula from the spreadsheet, and paste it into the IDE.
I do this fairly often, for the same reason that it seems the OP wants to: to use handily captured or calculated data as known input to a program under development.  My memory tells me that the compiler doesn't even complain if you leave the last unnecessary comma in the code.  If you're a purist, you may want to take it out.

You might want to take the intermediate step of pasting the data from the spreadsheet into a text editor, copying it again, and pasting from that into the IDE.  I've seen the IDE balk at big clipboards from Excel, but not from Notepad or Gedit, and those programs handle pastes from spreadsheets with aplomb.

Of course, all that presumes that you can readily get data out of a 2D PROGMEM array.  I've never tried it.  This post says it has a solution; maybe it works -  Alternatively, you could use a one-dimensional array, and index it with something like 4*i + j, where i is the row index, and j the column, zero-based.  If you go that route, you don't need brackets around each line, you only need to add a comma at the end of each. 

I note that the sample data shows five entries per line, rather than four, and that the sample code applies that information inconsistently.  Maybe that data is for illustration, and not the real thing.  If the CSV has line numbers, you'll want to account for it somehow, either by allowing space for it in the array, or stripping it out of the data.  The array already takes up nearly a third of the available flash memory; I'd recommend removing line numbers.  Here's a way to strip the first entry off a line of comma-separated values in Excel or Libre, untested:
OpenOffice might do it that way, too; I don't remember.

As I see it, that solves the problem, as it was directly stated:  it make the data available to the program, it doesn't require the OP to manually change oodles of lines of code, and it uses the tools he says he already has.
40  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 15, 2014, 06:29:46 pm
Now I just need to figure out how to convert a CSV into an array and store it in program memory...
To initialize an array, either in RAM or with PROGMEM, you put the values inside curly brackets, and separate them by commas.  CSV stands for, "comma separated values."  Does that suggest anything to you?
41  Using Arduino / Project Guidance / Re: Using an Uno to play back somewhat large table of analog inputs, best way? on: May 15, 2014, 11:23:56 am
1200 x 4 is 4800; ints take two bytes, for a total memory requirement of 9600 bytes.  You can't store that in RAM on an Uno.  You can store it in program memory, if you have that much to spare.  Here's a description of how to store and fetch data in flash:
42  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 15, 2014, 07:40:54 am
I tried with ArduinoFFT ...
What did you try?  What did you expect it to do, and what did it do? 

If you answer those questions, and post code and a schematic, it can only help.

43  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 13, 2014, 09:56:36 am
... what is amplitude of a signal from an average cell-phone player? ...
I don't know of any standards.  Here's a guy testing the audio output of an iPhone 5:  According to him, full output is about 1.4V peak-to-ground, with an output impedance of 4.5 ohms.  With a 2.5V offset, that'll give ADC read ranging between roughly 225 and 800, at full output.
44  Using Arduino / General Electronics / Re: Measuring AC mains on: May 11, 2014, 06:30:59 pm
Quoth the OP:
I had not thought about measuring power.
That suggests that precise power measurements may not be the intent of this project.  Without knowing the data is for, or how accurate it has to be, we're chasing our tails here.

That said, I don't think that measuring the phase angle between the voltage and current is necessary.  Real power is the sum of the products of the instantaneous voltage and current readings; reactive estimates nicely from that and the RMS values of voltage and current with the Pythagorean Theorem.  That method assumes that there aren't any appreciable real or reactive power components at any frequency other than the fundamental, but so does calculating reactive power using the phase angle as calculated from the fundamental frequency.
45  Using Arduino / Audio / Re: Creating a tuner..... Begginer! on: May 11, 2014, 05:13:33 pm
I did some things ...
I don't see a description of what you did.  A schematic would help.

Can one suggest a ready to use solution if there is one?
Here's what I use: a cheap homemade circuit to connect the audio output of the PC to the Arduino.  A schematic is attached.  The Thevenin equivalent of the voltage divider is a 10K resistor and a 2.5V DC supply.  10K is suitable for an analog input, as described in the datasheet.  Note that there's nothing in series with the analog input.  I've verified that my PC won't output a 5V peak-to-peak signal, so I don't worry about overdriving the analog input.  You may prefer to use two 10K resistors, and a 5K in series, for an equivalent impedance of 10K, with the 5K providing a measure of protection for the analog input.  This scheme isn't really suitable unless the input is stiff enough to drive the equivalent impedance of the voltage divider; otherwise, the signal level will drop.

I added a 100K resistor to ground from the signal input.  That's because I suspect that the audio output is capacitively coupled, just like my input.   Without the resistor, the DC voltage between the two capacitors is essentially undefined.  Because I'm using an electrolytic capacitor, and I presume that the audio output does, too, I add the resistor to keep the DC level between them at ground, and make sure that the capacitor polarities are proper.  I can't say that it's necessary; I just like having it in the circuit.

Advantages are that it's cheap, easy to build, and I can define the analog input quite precisely by generating my own audio content.  The primary disadvantage is that it doesn't lend itself to real-world inputs:  The input impedance is so low it would pull down most guitar inputs, and it has no protection from analog overvoltage, as you might get from an amplifier output intended for a speaker. 

Criticism is welcome.
Pages: 1 2 [3] 4 5 ... 26