Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 452
61  Using Arduino / Programming Questions / Re: boolean doesn't response on: June 29, 2014, 05:01:31 am
   if (GoToServo); //if the rule is true - go to this part of the code
In this case, the problem may be the ";"  That ENDS the "if" statement.
(disregard if that's a transcription error rather than how the code actually reads.)
62  Using Arduino / Programming Questions / Re: Data types and arithmetics on: June 29, 2014, 04:58:43 am
I don't really understand why though (why didn't I have to type cast MC_ also?), since X2 being a 32bit integer should be able to store it?
C has simple but counter-intuitive rules for doing math.  Given an expression like
long X2 = MC * (1 << 11) / (X1 + MD);
, it calculates results of sub-expressions "in order."  So in 1<<11, both numbers are "int" (short) (all constants are
"int" unless you indicate otherwise), leading to a short result.  Then we multiply by MC, which is another short, and expect another short result (which is now getting questionable.)  X1 is a long, so X1+MD gets calculated using longs (MD is first "promoted" to a long), and produces a long result.  The final division has the short result divided by a long, so again the short is convert to a long, the calculations are long, and you get a long result.  ONLY THEN does it notice that the X2 is also a long, so it can directly assign the result of the calculations.  The fact that the final destination is a long has NO EFFECT on calculating the value of the expression on the right hand side.

You can google "C promotion rules" and find out more.  Note that this is a lot less obvious in many C compilers (desktop computers, for instance), because the default type for constants (int) is 32bits on those machines, and you don't do math that overflows 32bits nearly as often as you do math that overflows 16bits.
63  Using Arduino / Programming Questions / Re: Data types and arithmetics on: June 28, 2014, 08:51:40 pm
long UT = 27898;
unsigned short AC5 = 32757;
unsigned short AC6 = 23153;
short MC = -8711;
short MD = 2868;
You'll save yourself a lot of uncertainty by using the same data type (long) for all your constants.  The calculations all have at least one long, so all of the ints will need promoted to longs anyway.
Both 2^11 and 2^15 are wrong.
X1 = ((UT - AC6) * AC5) / (1<<16);  // Right shift "undefined" for signed numbers :-(
  X2 = ((long)MC<<12) /  (X1 + MD);
I assume that these calculations are from datasheets, so the bits discarded in making X1 are known irrelevant.
64  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 28, 2014, 08:04:52 pm
One of the things that I like about the normal Official Arduino boards is that they are "correctly" priced.  If I design a "product" around an Uno core with MSRP of $30, then I know that I can put the relevant components on a board of my own design, and that section of the product can sell for about $30 (or less, because I can leave things out.)  With these subsidized Evaluation Boards from Chip vendors, it's a lot harder to get that 'feel' for end product cost.  I mean, as a hobbyist or end-user, a $15 board with an ST M4 chip is great.  But the chip itself is $10+ in small quantities, and it probably needs a 4-layer board and professional assembly.  So there's no way that $15 represents a realistic cost for me to use the same chip in a design, short of something "really big" that will sell in 10k+ quantities.

OTOH, there's an argument that says that in my target quantity (say, 100-1000), I should stop worrying about using chip-level devices in general: just buy the launchpad or Nucleo boards and restrict my part of the design to a "shield"...
(On the gripping hand, it's not clear that the semiconductor vendor boards are allowed (license-wise) to be used in products.)
65  Development / Other Software Development / Re: Will Arduino team ever do better than this?! on: June 28, 2014, 04:56:23 am
What should a C function (extern "C" {}) return for "true" ?  Is there a standard way to define true in a head such that it gets #defined for C code, but not for C++ code?
66  Using Arduino / Microcontrollers / Re: Is this "too good to be true"? on: June 28, 2014, 04:52:55 am
postage on eBay is bulk, it is always per item.
Not always.  I've bought components from some dealers (not from china, AFAIK) who combine postage in quite reasonable ways.
67  General Category / General Discussion / Re: Input => Process => Output on: June 28, 2014, 03:06:24 am
Event-process-action ?
68  Development / Other Software Development / Re: Will Arduino team ever do better than this?! on: June 28, 2014, 12:19:46 am
In this case, there is a "#define true 0x1" in Arduino.h, so C++ never gets to see it's version of "true", right?
69  Using Arduino / General Electronics / Re: 2 modules in SPI on: June 27, 2014, 05:23:45 pm
You could look at the official Arduino Ethernet board, which has the WizNet ethernet chip and an SD card, both of which are also SPI-based.  Or the Adafruit Waveshield which has an SD card and a D-A converter (both SPI.)
70  Using Arduino / General Electronics / Re: 2 modules in ISP on: June 27, 2014, 03:58:16 am
"SPI" - yes; you use different chip-select pins for each SPI peripheral.  MOSI, MISO, and SCK in common, one chip-select per module.
71  Development / Other Software Development / Re: Will Arduino team ever do better than this?! on: June 27, 2014, 12:42:55 am
So code like:
EthernetClient::operator bool() {
  return _sock != MAX_SOCK_NUM;
invokes the function (and returns the bool value) whenever an EthernetClient object is referenced with no other qualifiers?

Note that "true" is not defined as a bool either, so I would have expected (as a C programmer) "client == true" to devolved to a comparison between a pointer and an int.
72  Using Arduino / Microcontrollers / Re: Updating the mighty-1284p core on: June 26, 2014, 07:25:09 pm
That seems to have worked.  Icky, though.  Can't ask normal Arduino users to go through that.

73  Using Arduino / Programming Questions / Re: How to program Arduino without C? on: June 26, 2014, 04:40:14 am
Writing assembler for AVR and using it on an Arduino is easy enough.
1) Choose an assembler.  The main contenders are Atmel's assembler, which you can get for Windows and Linux, and the avr-gcc assembler, which you can get for just about anything.  There are minor players (avra, tavrasm) available as OSSW that are simpler than installing gcc.   Note that Atmel assembler and Gnu Assembler have somewhat different syntax :-(
2) Choose an editor.  You can use a simple text editor (note: NOT a word processor!), or you can use an IDE designed for code development ("Atmel Studio" is the big player for AVR.  But also Eclipse, Netbeans, XCode, and others.  I *don't* think that the Arduino IDE will handle assembler files.
3) Choose a build procedure.  An IDE will probably have a simple "build" button, after you've done "setup" process.  You can also use Makefiles, batch files (or shell scripts), or make users type bare commands in a command window.  You'll want to eventually produced a .hex file.
4) Choose an upload tool.  This may also be built into the IDE.  If you have Arduino hardware, you CAN upload any .hex file using the Arduino bootloader and "avrdude."  Or you can use a "device programmer" of some kind.

Enter the assembler program using your text editor, assemble/link/postprocess using your assembler and build procedure, upload using your tool, and see if it works.  Piece of cake.

(Atmel Studio and "real" tools will also include debugging capabilities.   Which is really handy when it's going to be a significant amount of work before you can get an equivalent of "print" working.)
74  Development / Other Software Development / Re: Will Arduino team ever do better than this?! on: June 26, 2014, 04:06:32 am
If you open the ethernet library, there is exactly one line of comment in EthernetServer.cpp
Yes, that's pretty bad.  Especially since accept() really needs some documentation; pretty confusing stuff.

On top of that, there's this snip from the documentation page for the Ethernet library:
void loop() {
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client == true) {
That's just EVIL, isn't it?  "client" would traditionally be null (which happens to be the same as false) or an object address; it would never be "true."  (I see that EthernetClient.cpp overrides "operator bool" to allow this.   I guess that works (?  How does it tell that this a boolean and not a numeric comarison?), but I don't like it!
75  Using Arduino / Microcontrollers / Re: working of bootloader on: June 26, 2014, 02:43:16 am
I'm not sure what level of detail you want.  The "ways" you list are all "device programmers" capable of loading programs onto an AVR chip via "hardware."  The "bootloader" is just a program that you can load that is then capable of loading additional programs onto the same chip via Software, set up so that it runs first.  When you do a "burn bootloader", the IDE just starts up the avrdude program with the designated programmer type and the correct bootloader program .hex file.  The next time the chip resets, the bootloader program runs first, and checks to see whether anything is trying to "upload" a sketch.
Pages: 1 ... 3 4 [5] 6 7 ... 452