Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Programming Questions / Re: mathematic libraries
|
on: January 22, 2013, 04:13:33 pm
|
|
Discussions like this have been going on since at least 2010. Replies from the Arduino experts have been, to say the least, unsatisfactory, and the subject is well worth a rant. Arduino is for scientists as well.
In my own case I need to calculate small differences between high audio frequencies, which are in turn calculated from values proportional to pitch (MIDI note numbers, cents). Similar situations arise in elementary statistics and, as several contributors have mentioned, several other areas where the Arduino is a perfectly appropriate platform. The key points are that evaluating the numerical stability of (for example) exponentiations is likely to be too difficult for most Arduinio users (including amateur and some professional scientists), as is interpolating between items in lookup tables. That's why spreadsheets such as Excel and Open Office Calc were suitably modified more than a decade ago so that ordinary users don't have to worry about numerical stability; 7-digit precision isn't even enough to calculate the mass of a fairly small molecule.
Since the early days of computing, and particularly during the period when home computers were 8-bit, it has been perfectly normal to write and use libraries of high-precision algorithms. Major scientific applications are still being written in old languages such as Fortran 77. C++ is supposed to be a major modern language, so there ought to exist a maths library that works with arbitrary levels of precision.
Arduinos such as the Mega have more than enough memory; several contributors have pointed out that computing time is not an issue here, and it's a pity that expert replies to this forum seem to be dominated by people who don't seem to understand that some of us need to combine real-time functionality with accurate calculations which are not time-critical.
So, I repeat the question that has been asked many times here: does there exist a multiple-precision C or C++ math library that could be used with Arduino?
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: serialEvent with yes/no dialogue?
|
on: November 27, 2012, 03:58:46 am
|
|
@PaulS : then what I'm asking for would be an additional library.
For those of us new to this sort of thing, the logic behind serialEvent is hard to follow. As it's built in to Arduino, the user doesn't see whether or not 'void serialEvent()' is an interrupt handler that's called any time data arrives. Is the the following part of the comment before void serialEvent() in the example a little bit misleading?
'This routine is run between each time loop() runs,...
If it is an interrupt handler, should the reader just be advised to get back into loop() as frequently as necessary? In my case they are typed in the terminal and can wait a few seconds for action.
|
|
|
|
|
5
|
Using Arduino / Programming Questions / serialEvent with yes/no dialogue?
|
on: November 26, 2012, 04:40:18 pm
|
|
Hello,
serialEvent works perfectly as advertised. For the moment I use it with the Arduino terminal as I havn't started to link that to Processing.
Many times, you'd like your sketch to return an acopalyptic message requiring confirmation of a command. For example, if you type:
apocalypse <send>
Arduino could reply:
Delete Earth, Solar system, Galaxy, Universe; or Wait another day (E/S/G/U/W)?
It should be easy enough to program (presumably using static variables) but, since this is a commonly-required action, does anyone have a library that does the job in the professional manner?
|
|
|
|
|
6
|
Using Arduino / Audio / Re: Multiple MIDI I/Os
|
on: November 23, 2012, 05:19:04 pm
|
|
Yes, I was going to ask a similar question.
I run a MIDI-shield through Serial1 of a mega, keeping Serial0 for normal use (snip the TX/RX pins and use jumpers to TX1/RX1). I'd like to have two MIDI-ins and was thinking of modifying a copy of the MIDI library so as to run more than one instance with piggy-backed shields or breakout boards.
It isn't so easy for someone of my level to know what to change in the library code, but if anyone could indicate what needs to be done (if it can be done) I could do the work. Obviously, a single multichannel version would be great.
Just one very little thing if Franky47 is still working on it: most MIDI devices send Note Off as a Note On with zero velocity (it's in the standard). At present you have to catch that in your Note On handler; easy, but it would be nice to have it built in to the library. It's always OK to send a proper MIDI off.
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Re: Comparing Strings with serialEvent
|
on: October 30, 2012, 10:37:28 am
|
Many thanks PaulS. I suppose you could change the order of commands in void serialEvent() so the newline doesn't get appended to inputString, but presume the author had reasons for not doing that. A bit of browsing turns up method trim() which does the job nicely. Here's my corrected and tested version, with "chris" declared as though it were a constant: /* Serial Event example, with addition by crlMIDI When new serial data arrives, this sketch adds it to a String. When a newline is received, the loop prints the string and clears it. A good test for this is to try it with a GPS receiver that sends out NMEA 0183 sentences. Created 9 May 2011 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/SerialEvent */
String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete // the string we are going to compare inputString with String myString1 = "chris";
void setup() { // initialize serial: Serial.begin(9600); // reserve 200 bytes for the inputString: inputString.reserve(200); }
void loop() { // print the string when a newline arrives: if (stringComplete) { checkMystring(); Serial.println(inputString); // clear the string: inputString = ""; stringComplete = false; } } void checkMystring() { // trim is a method of the String class that removes whitespace // including Newline and Carrriage return inputString.trim(); // either of the following 2 commands is OK: if (inputString == myString1) // if (inputString.equalsIgnoreCase(myString1)) {Serial.println("Matches"); } else {Serial.println("Match not found"); } }
/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } }
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Comparing Strings with serialEvent
|
on: October 29, 2012, 04:59:47 pm
|
Hello, I must be doing something stupid with my Mega2560 (Arduino 1.0.1) when trying to test a String that's input using the serialEvent example with my own strings. In the example below, checkMystring() always returns 'String not found'. I've tried all sorts of variations. Perhaps I can't get my head round the object/variable/constant uncertainty that seems to surround the Arduino String object, at least in the minds of newbies. /* Serial Event example When new serial data arrives, this sketch adds it to a String. When a newline is received, the loop prints the string and clears it. A good test for this is to try it with a GPS receiver that sends out NMEA 0183 sentences. Created 9 May 2011 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/SerialEvent */
String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete // Can't get these commented-out ones to work: //String myString = String("chris"); //String myString = "chris"; String myString1;
void setup() { // initialize serial: Serial.begin(9600); // reserve 200 bytes for the inputString: inputString.reserve(200); myString1 = String("chris"); }
void loop() { // print the string when a newline arrives: if (stringComplete) { checkMystring(); Serial.println(inputString); // clear the string: inputString = ""; stringComplete = false; } } void checkMystring() { // if (inputString == myString1) .. doesn't work either if (inputString.equalsIgnoreCase(myString1)) {Serial.println("Matches"); } else {Serial.println("Match not found"); } }
/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } }
|
|
|
|
|
10
|
Using Arduino / Audio / Re: Help for MIDI Library v3.2
|
on: September 28, 2012, 01:46:42 pm
|
Hello, I came across this thread while looking for something else. It prompted me to post - very much prematurely - a sketch that does Roland sysex: http://www.music.chrblee.net/tuningaid/index.html. Since I did that I discovered how to attach files to a post on this forum. The code is definitely not for the eyes of Inspector TidyCode, but it works. Well, it started working this afternoon. One thing I forgot to mention is that if you send a sysex Data Request to a Roland JV, the response lacks the final F7. This might be troublesome if you locate the data you want by its distance from the end of the array. Perhaps I should configure the brilliant MIDI.h, as proposed, to insert the F0 and F7 automatically. Another thing, if you send a Data Set sysex, make sure you put in a delay (Roland says 20ms, a source on the web says 40). The JV responds with some junk, perhaps to make sure you remember this. Finally, the best way to use a MIDI shield with a Mega is to snip off the two serial (0) pins, and connect the shield to serial1. You need serial0 to see what your code is getting up to...
|
|
|
|
|
11
|
Using Arduino / Programming Questions / Re: Equality operators don't work in "for" loops
|
on: July 16, 2012, 09:04:52 am
|
|
Point taken, except that I use Arduino & don't consider myself a complete idiot.
When using structures that have been in common use in other languages for several decades it should normally be sufficient to look up just the syntax. The documentation and the Arduino Cookbook (700 pages) are very well written; all I was saying is that it would help if the little warnings about the differences between Arduino and pure C++ could be extended to include other languages a user is likely to have encountered.
If you've had the misfortune to write XL VBA macros during the day for your employer, a little reminder that C++ "for" loops don't have the equivalent to "to" in them would make life easier when you switch to Arduino and a different reference book back at home.
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: Equality operators don't work in "for" loops
|
on: July 16, 2012, 08:21:09 am
|
|
Thanks,
It does need documenting more explicitly for Arduino users, then, because this seems to be one of those C++ wierd things that we aren't all familiar with.
Normally, you'd expect the middle bit of "for" loops to mean "until". Various dialects of Pascal and BASIC have separate "for - until" and "while" constructs.
Regards
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Equality operators don't work in "for" loops
|
on: July 16, 2012, 07:42:12 am
|
Hello, This code loops as you'd expect: for (int i=5; i < 13; i++) { Serial.println("i"); Serial.println(i); //etc.
However, this code doesn't loop, and as there is no error message I spent a bit of time on it: for (int i=5; i == 12; i++) { Serial.println("i"); Serial.println(i); //etc.
The "for" loop doesn't seem to accept an equals sign anywhere in the relational operator (">=" doesn't work either). Has this been documented (it's hard to search for "for" in the forum...)? Arduino 1.0.1 with mega 2560
|
|
|
|
|
14
|
Using Arduino / Audio / Two instances of MIDI library
|
on: April 29, 2012, 03:50:09 pm
|
Hello, I'm using MIDI.h with a Sparkfun midishield plugged into an Arduino mega. Since the mega has more than one set of serial ports, I've connected the midishield to serial1 using 2 bits of wire, so I don't have to remember to move the switch that's provided each time I upload one of my buggy programs. MIDI.h is a bit more complicated than the written-out code that comes with the midishield, but it minimises the dreaded MIDI latency problem by using interrups. It was easy enough to edit MIDI.h to change the serial setting as instructed, and everything works fine  . However, I wanted to change the library name to something like MIDI1.h so as not to forget that I have messed around with my copy. That caused my sketch to crash. No great problem even for my tiny brain, except that soon I'd like to piggyback a second midishield, using serial2, and so run two instances of MIDI.h which would definitely need separate library names. In addition to my own Arduino project, I'd then be able to make a 2-in 2-out USB/MIDI interface/filter for the price of the extra midishield (or MIDI breakout). Before I start taking the trouble of working it out, please could anyone indicate which lines I should change in MIDI.h to match the new library names?
|
|
|
|
|