Show Posts
Pages: 1 ... 11 12 [13] 14 15 ... 18
181  Using Arduino / Programming Questions / [SOLVED] a way to define conditions? on: March 29, 2012, 09:11:09 am
Similar to #define for constant values (or similar to standard variable declarations), is there a way to define/declare CONDITIONS upfront?

To further explain why this is necessary... In my code, I do an IF statement to test a condition. However, I believe I might change this condition later as my code evolves. Plus this condition might be tested at various points across the code. So it would be nice to declare upfront at the beginning of my code what this condition is (and possibly other conditions).

So, I'm looking for something resembling Code-A, instead of Code-B.

Code-A:
Code:
#define ConditionA [a > 20 && a < 30]
...
if (ConditionA) {
// action...
}

instead of Code-B:
Code:
if (a > 20 && a < 30) {
// action...
}
182  Using Arduino / Microcontrollers / Re: Scratch Built 3.3v 8MHz Arduino Clone not working at 3.3v on: March 24, 2012, 09:22:46 am
Hmm, still can't see any problem.

But note that, based on the Atmega328 datasheet, the AVCC pin of the atmega chip MUST be externally connected to the supply voltage as well, even if you're not using the ADC.

Use this as a reference for the connections:
http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Also, if you're able to, see if you can post a photo of your layout

Finally, when you say "pin 13", you are aware that Arduino-number-13 is not the same as Atmega-chip-number-13, yes? (I believe Arduino-13 = Pin #19 of Atmega328)
183  Using Arduino / Microcontrollers / Re: Scratch Built 3.3v 8MHz Arduino Clone not working at 3.3v on: March 24, 2012, 08:43:28 am
Bootloading it should be the only requirement prior to uploading sketches.
More details would be useful to isolate the problem.
Also, how are you powering it (for the 3.3 volt test case)?
184  Using Arduino / Microcontrollers / Re: [SOLVED-Sortof] ATMEGA2560v-Au Bootloader on: March 24, 2012, 08:33:25 am
apparently the timeout issue has occurred to other people before (not to me):

this discussion (http://arduino.cc/forum/index.php?topic=83079.0) suggests trying the upload with arduino-022/arduino-023 versus arduino-1.0

try with different version and let me know what happens.

also, google "avrdude: stk500v2_ReceiveMessage(): timeout" [with the double-quotes]...

185  Using Arduino / Microcontrollers / Re: reaDIYboot: a Wi-Fi bootloader which downloads hex files from the Internet on: March 22, 2012, 09:24:12 pm
Wow, great idea, especially with the recent popularity of the awesome RN-XV, which is the Xbee-sized variant of the Wifly module: http://www.sparkfun.com/products/10822.

And well-written instructions on the project Github page. I'm definitely trying this out this weekend.

Also really digging the related reaDIYmate idea that you guys are developing (http://www.kickstarter.com/projects/readiymate/readiymate-build-an-internet-connected-thing-in-10).
186  Using Arduino / Microcontrollers / Re: [SOLVED] Bootloading Mega1280 to run @ 8 Mhz, 3.3 V on: March 22, 2012, 09:20:11 pm
Lefty, Problem solved! I was using Arduino-022 earlier but now downloaded Arduino 1.0 which, I think by using the latest version of AVR, allows uploading sketches using non-standard baud rates, including 28800.

Got that fact from this post: http://arduino.cc/forum/index.php/topic,74042.msg557491.html#msg557491
187  Using Arduino / Microcontrollers / Re: ATMEGA2560v-Au Bootloader on: March 22, 2012, 10:00:51 am
I cannot give an exact technical answer of how to CREATE the necessary modified bootloader.
However, having done this exact thing successfully in the past, I recommend you try one of the following two approaches:

(1) Get the already compiled file for Sparkfun's 3.3 V / 8 Mhz version of Mega2560 (hex file, credit Brett Hagman):
http://code.google.com/p/wiring/downloads/detail?name=WiringBoot_sparkfun-megapro-8MHz.hex
Then burn using avrdude commandline specifying "m2560" for the microcontroller (even though technically, the uC is Atmega2560-V version)

(2) Or instead, if using Arduino IDE, first edit the "boards.txt" file in the appropriate arduino folder (for example) "arduino-0022/hardware/arduino/", by changing the following two parameters in the file:
Code:
mega2560.upload.speed=57600

mega2560.build.f_cpu=8000000L
Then reload Arduino IDE, select Tools >> Board >> Arduino Mega 2560, then Tools >> Burn bootloader, and so on.

Note:
In both of the above cases, AFTER the bootloader is burned, I think you will get a msg toward the end as follows:
"avrdude: verification error, first mismatch at byte 0x3e000... 0x0d != 0xff"
This error can be ignored; Test it out by uploading a sketch, and it will work fine.
188  Using Arduino / Microcontrollers / Re: Bootloading Mega1280 to run @ 8 Mhz, 3.3 V on: March 22, 2012, 12:39:01 am
Almost there! Specifically, bootloader upload worked great...
HOWEVER, now when I try to upload (via standard FTDI-FT232 chip),
the Arduino IDE states:
Code:
avrdude: serial_baud_lookup(): unknown baud rate: 28800

How can this 28800 baud rate (different from the standard 19200 or 57600) be made possible in the sketch upload?


In the meantime, I'm trying to look through the Arduino folder for any possible config files that can be edited to allow this baud rate.
189  Using Arduino / Microcontrollers / [SOLVED] Bootloading Mega1280 to run @ 8 Mhz, 3.3 V on: March 21, 2012, 06:43:10 pm
I'm doing an experiment with running an independent Atmega1280 chip in a breadboard-Arduino style (sort of). Works great with the default Arduino Mega1280 bootloader, with the chip running @ 5 Volts, 16 Mhz.

However, my idea is to run the chip at 3.3 Volts, and thus with an external crystal of 8 Mhz, going by the allowed frequency suggested by datasheet.

What would I need to change in the boards.txt file and/or other files, in order to burn the Arduino bootloader onto the Atmega1280, and facilitate the 3.3-V/8Mhz instead of the original 5-V/16Mhz?
(Note: I'm using my Uno as the programmer device.)

Currently, the boards.txt file says the following (default):
Code:
mega.name=Arduino Mega (ATmega1280)

mega.upload.protocol=stk500
mega.upload.maximum_size=126976
mega.upload.speed=57600

mega.bootloader.low_fuses=0xFF
mega.bootloader.high_fuses=0xDA
mega.bootloader.extended_fuses=0xF5
mega.bootloader.path=atmega
mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex
mega.bootloader.unlock_bits=0x3F
mega.bootloader.lock_bits=0x0F

mega.build.mcu=atmega1280
mega.build.f_cpu=16000000L
mega.build.core=arduino
190  Using Arduino / Audio / Re: Speech command recognition system on: December 06, 2011, 09:41:53 pm
Quote
Do you know if this approach will even work?
Thank you, Yeah i think it might work just for a few commands..but might not be that accurate though..i just wanna try it, and i need help please..

I too am a big fan of doing as much as possible from scratch but if you are interested in a more reliable/quick solution, you might want to try using a pre-built speech recognition module:
http://www.sparkfun.com/products/10963
or
http://www.instructables.com/id/Carlitos-Projects-Wireless-Speech-Controlled-Ard/

On the other hand, if you want to code things from the ground up, here's a useful primer from Carnegie Mellon:
http://www.speech.cs.cmu.edu/comp.speech/Section6/Q6.3.html

And a google search for "arduino eeprom" should give you tons of tutorials on how to write/read eeprom.
191  Using Arduino / Sensors / Re: Mitutoyo Digimatic SPC on: December 06, 2011, 09:35:09 pm
@Steve Spence: Congrats for persisting through all the difficulties and getting it finished. I'm interested in testing your code myself when I get a chance in the next couple of weeks.
Since you already have your working code ready in the post above, perhaps you should put it together along with an image of your basic circuit hookup and put it in the Exhibition/Gallery section, or on the Playground.
192  Using Arduino / Sensors / Re: Mitutoyo Digimatic SPC on: December 04, 2011, 05:21:04 am
@Steve Spence:
For your reference, Page 2 of this document covers in visual detail the BCD format (in fact the whole document deals pretty much exactly with your project):
http://www.tinaja.com/glib/muse145.pdf
193  Using Arduino / Sensors / Re: Mitutoyo Digimatic SPC on: November 24, 2011, 08:43:42 pm
Glad to see someone else working on this interface (digimatic protocol which appears to be used in Mitutoyo calipers and a few other measurement devices). I wrote the original code that you seem to have started with. Wow at that time, struggled with finding related information on the internet and concluded that I was the only one in the world who needed to log mechanical/dimensional data smiley-wink

Below's the latest version; try it out... had sleepless nights with interpreting the BCD myself (note the strtoint function which was a temporary fix for the fact that the read binary-format values were in reverse), but following code should most likely work

Code:
#include<stdlib.h>

int dat = 2; // pin 2
int clk = 3; // pin 3
int iclk = 1;
int req = 5; // pin 5 - note to self: also try pin 4 instead (closer on Atmega328 chip for breadboard version)

int i = 0;
int j = 0;
int k = 0;
const int kmax = 5;
int mydata[52];
String mydata2[13];
int convint[13];
String mydata3 = "";


void setup()
{
  Serial.begin(19200);
  pinMode(req, OUTPUT);
  pinMode(clk, INPUT);
  pinMode(dat, INPUT);
}

void loop()
{
    digitalWrite(req, HIGH);
    delay(25);
    digitalWrite(req, LOW);
    attachInterrupt(iclk, myisr, RISING);
    if (i > 51)
    {
      Serial.println();
      for (j = 0; j < 13; j++)
      {
        Serial.print("--");
        mydata2[j] = "";
        for (k = 0; k < 4; k++)
        {
          mydata2[j] = mydata2[j] + mydata[(j*4)+k];
        }
        Serial.print(mydata2[j]);
      }
    finalconv();
    i = 0;
    }
}

void myisr()
{
  if(i < 52)
  {
  j = i % 52;
  mydata[j] = digitalRead(dat);
  i++;
  }
}

int strtoint(String strtoconv)
{
  if (strtoconv == "0000") return 0;
  if (strtoconv == "1000") return 1;
  if (strtoconv == "0100") return 2;
  if (strtoconv == "1100") return 3;
  if (strtoconv == "0010") return 4;
  if (strtoconv == "1010") return 5;
  if (strtoconv == "0110") return 6;
  if (strtoconv == "1110") return 7;
  if (strtoconv == "0001") return 8;
  if (strtoconv == "1001") return 9;
  if (strtoconv == "1111") return 0;
}

void finalconv()
{
  mydata3 = "";
  long int myval;
  int mysign;
  String myunits = "";
  float myfin;
  for (j = 0; j < 13; j++)
  {
    convint[j] = strtoint(mydata2[j]);
    switch(j) {
      case 0:
        break;
      case 1:
        break;
      case 2:
        break;
      case 3:
        break;
      case 4:
        if (convint[4] == 0) mysign = 1;
        else if (convint[4] == 8) mysign = -1;
        break;
      case 5:
        myval = convint[5]*100000;
        break;
      case 6:
        myval += convint[6]*10000;
        break;
      case 7:
        myval += convint[7]*1000;
        break;
      case 8:
        myval += convint[8]*100;
        break;
      case 9:
        myval += convint[9]*10;
        break;
      case 10:
        myval += convint[10]*1;
        break;
      case 11:
        switch (convint[11])
        {
          case 0: myfin = myval / 1.00000; break;
          case 1: myfin = myval / 10.00000; break;
          case 2: myfin = myval / 100.00000; break;
          case 3: myfin = myval / 1000.00000; break;
          case 4: myfin = myval / 10000.00000; break;
          case 5: myfin = myval / 100000.00000; break;
        }
        break;
      case 12:
        switch (convint[12])
        {
          case 0: myunits = "mm"; break;
          case 1: myunits = "in"; break;
          case 2: myunits = "mm +nogo"; break;
          case 3: myunits = "mm go"; break;
          case 4: myunits = "mm -nogo"; break;
          case 5: myunits = "in +nogo"; break;
          case 6: myunits = "in go"; break;
          case 7: myunits = "in -nogo"; break;
          default: myunits = "";
        }
        break;
    }
  }
  myfin = myfin * mysign;
  Serial.println();
  Serial.print(myfin,5);
  Serial.println(myunits);
}
194  Using Arduino / Programming Questions / Re: Efficiency of multiple If conditions on: November 05, 2011, 12:53:46 am
You can do what Nick Gammon frequently does - look at the lower level code and see what actually gets created by the compiler.
Robert, how does one look at the lower level code (I presume you mean the code behind the scenes of the Arduino C code)?
195  Using Arduino / Programming Questions / Re: Efficiency of multiple If conditions on: November 05, 2011, 12:50:59 am
Quote
Or would Code2 also skip the whole line as soon as the 1st condition fails?
This is what C does. Efficient, but can be a little surprising.
Quote
Efficient, but can be a little surprising.
Especially if the if test involves a function call, and you expect that function call to be made.

Interesting. So in general, for such functions, it's probably better to store the function-return-value to a variable first (although that comes at the cost of one extra variable) and only then do any test that involves multiple conditions.
Pages: 1 ... 11 12 [13] 14 15 ... 18