Show Posts
Pages: 1 2 3 [4] 5 6 ... 10
46  Using Arduino / Programming Questions / Re: Help using templates. on: November 26, 2012, 08:48:52 am
Nope. Same error: 'TYPE' does not name a type.

My sketch:
Code:
template<class TYPE> TYPE Add(TYPE n1, TYPE n2);

TYPE Add(TYPE n1, TYPE n2)
{
    TYPE result;
    result = n1 + n2;
    return result;
}

void setup()
{
    float x = 2.1;
    float y = 5.6;
    Serial.begin(115200);
    Serial.println(Add(x, y));
}

void loop()
{
}

The error is at line 3. I was mistaken in my first post. The error was in the same place as indicated this time. I'm using a Mega1280 & IDE1.0.2. Any further thoughts/ideas. As I stated above I can get this to compile using atmel studio. It's just easier to do short code tests using the arduino IDE.

Thanks again for any help,
DJ
47  Using Arduino / Programming Questions / Re: Help using templates. on: November 26, 2012, 08:26:22 am
@pYro_65

I did figure out it was the IDE when it compiled using atmel studio. I had no idea how to get it to compile in the arduino IDE. I'll give this a try and let you know if it works for me. smiley-wink

Thanks,
DJ
48  Using Arduino / Programming Questions / Help using templates. on: November 26, 2012, 06:53:02 am
I'm trying to learn templates. smiley-confuse I've been reading a tutorial (Web page: http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part-1 ). I copied an example from the tutorial but when I compile I get an error: 'TYPE' does not name a type, it highlights the error line as the first line, the line declaring the template.

Here's my sketch:
Code:
template<class TYPE>
TYPE Add(TYPE n1, TYPE n2)
{
    TYPE result;
    result = n1 + n2;
    return result;
}

void setup()
{
    float x = 2.1;
    float y = 5.6;
    Serial.begin(115200);
    Serial.println(Add(x, y));
}

void loop()
{
}

I thought the purpose of using a template (in this case) was so you didn't have to (explicitly) name a type. Can someone help me understand why I'm getting an error and the author of the tutorial (obviously) is not.

Thanks for your time,
DJ
49  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 09:39:05 pm
Thanks Nick. I guess it's time to learn all about timers.  smiley-eek-blue
I'll do some research and see if I can get all the parts to play nice with each other. If so, I'll post some code for others' in need.

Thanx,
DJ
50  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 01:50:02 pm
Now that I've thought about it, I suppose I could set up software timers using micros() or millis() and poll them.

DJ
51  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 01:46:09 pm
I've got a mega2560 and, believe it or not, I'm using almost every pin. I want to use a timer for timing events between some of the hardware I have attached. The thing is, all of the timer compare match pins are used by hardware devices. Is there any way to use a timer and not have it output on it's related compare match pins?

Thanks for your time,
DJ
52  Using Arduino / Programming Questions / A simple question about timers & pin usage. on: November 21, 2012, 12:56:06 pm
Is it possible to use a timer without affecting any pins?

Thanks for any replies,
DJ
53  Using Arduino / Installation & Troubleshooting / Re: Upload Timeout Error on Mega 2560 - Not Sure What Changed on: November 15, 2012, 12:04:22 pm
I'm having the same problem as Ragnar. Burn a new bootloader, upload one sketch. Then can't upload again (just hangs). Burn bootloader, upload one sketch... Has anyone found the problem or a fix. I'm using Mega2560 R1 and IDE1.0.2 on Windows 7 x64.

DJ
54  Community / Exhibition / Gallery / Re: How to configure the Atmel AVRISP MKii to work with Arduino IDE on: November 10, 2012, 03:10:13 pm
@retrolefty

As velocity101 said, it will not provide power. From reading the user guide
Quote
The Atmel AVRISP mkII supports target voltages from 1.8V up to 5.5V.

Note
VCC must be connected to the target board in order to get correct operation and voltages on the ISP/PDI lines. VCC does not draw any power from the target.
In fact, the AVRISP mkII will not detect the target until it (the target) is powered. Also (I can't find the quote right now), I read somewhere in the user manual that the programmer senses the target voltage and adjusts its self by level shifting to the correct voltage. I do know when you enter the programming dialog it displays the current target voltage.

Hope this info helps.

BTW I was here a few days ago and found a thread on how to get the Arduino core to work under Atmel Studio 6. I followed the instructions and it worked! For me anyway. But after messing around a bit, I'm having some minor troubles. So, I need to find that thread (that's what I was doing when I came upon this thread) and follow the steps again. It's really cool  smiley-cool having all those libraries playing nicely with a full featured IDE with debugging capabilities.  smiley-grin

So, I'm off to search...
DigitalJohnson
55  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 02, 2012, 05:51:16 pm
Changes... Done. I was going to use RX_AND_TX, but then someone might mistake the AND to mean the logical (RX & TX). So, I used RX_TX as suggested.

Thanks for the tips Mike.
DJ
56  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 01, 2012, 04:29:48 pm
Fair enough answer. Will do. smiley

By the way, any suggestions on name of the third choice? Trying to keep it short and simple, like the other two. I don't know why, but I'm having a massive brain fart right now, can't come up with a simple, short name. smiley-confuse

As a side note, to those that can, this seems like an easy change to the library that gives a very useful option. Maybe on the next build...?

Thanks,
 DJ
57  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 01, 2012, 03:56:48 pm
@drjiohnsmith

Thanks, believe it or not, I was running low on available pins on my mega (big project). Need is the mother of...

@MichaelMeissner

I could do that. However, the way it is now, calling Serial.begin(baudrate) without the extra parameter behaves as it normally would. What would be the point of having a #define you don't need to use? I'm not saying it's a bad idea. Being a GOD member I'm sure you've been doing this far longer than I. I always like to learn. So, if it's not to much to ask, what is the benifit of the extra #define?
58  Development / Other Software Development / New option for HardwareSerial library. on: September 30, 2012, 10:40:35 pm
I made a small tweak to the HardwareSerial library (IDE 1.0.1) to have the ability to use only RX, only TX, or both RX and TX (normal operation). The modifications are very simple and easy to use. I've shown the modifications below. Make a copy of Arduino.h, HardwareSerial.h and HardwareSerial.cpp located in folder \arduino-1.0.1\hardware\arduino\cores\arduino\ and save them to a folder somewhere so if you screw up you can copy the old files back to the original folder.

Make the changes where indicated to the files below.

Arduino.h
Code:

// Place the three statements below somewhere around line 20
// with the other #define's that are listed there.

#define RX_TX 0
#define RX_ONLY 1
#define TX_ONLY 2


HardwareSerial.h
Code:

// Change the declaration below (at line 52)
  void begin(unsigned long);

// To this
  void begin(unsigned long, uint8_t mode = RX_TX);


HardwareSerial.cpp
Code:

// Change the definition below (at line 294)
void HardwareSerial::begin(unsigned long baud)

// To this
void HardwareSerial::begin(unsigned long baud, uint8_t mode)

// Located at the end of the same function (above)
// Replace the statements below (at lines 328, 329, 330)
  sbi(*_ucsrb, _rxen);
  sbi(*_ucsrb, _txen);
  sbi(*_ucsrb, _rxcie);

// With these
  switch (mode)
  {
  case 1:
    sbi(*_ucsrb, _rxen);
    cbi(*_ucsrb, _txen);
    sbi(*_ucsrb, _rxcie);
    break;
  case 2:
    cbi(*_ucsrb, _rxen);
    sbi(*_ucsrb, _txen);
    cbi(*_ucsrb, _rxcie);
    break;
  default:
    sbi(*_ucsrb, _rxen);
    sbi(*_ucsrb, _txen);
    sbi(*_ucsrb, _rxcie);
    break;
  }


If you want keyword highlighting for the new constants, you can add a few lines to \arduino-1.0.1\lib\keywords.txt file, though it is not neccesary.

keywords.txt
Code:

// Right after the line below (at line 1)
# LITERAL1 specifies constants

// Place these three lines (Use tabs here, NOT spaces)
RX_TX
RX_ONLY LITERAL1 Serial_begin
TX_ONLY LITERAL1 Serial_begin


To use the new changes, it's a simple addition to Serial.begin().

Example:
Code:

// Functions the same as it always has
// The receive pin (RXDn) and transmit pin (TXDn) are both controlled by HardwareSerial
Serial.begin(115200);

// Functions the same as above
Serial.begin(115200, RX_TX);

// Only the receive pin (RXDn) is controlled by HardwareSerial
// The transmit pin (TXDn) is free to use as digital I/O
Serial.begin(115200, RX_ONLY);

// Only the transmit pin (TXDn) is controlled by HardwareSerial
// The receive pin (RXDn) is free to use as digital I/O
Serial.begin(115200, TX_ONLY);


I've tested this succesfully using IDE 1.0.1 and the Mega1280/2560 on Serial ports 1, 2 and 3. I think I need to connect two arduinos to check port 0. If someone could test this out and let me know, maybe we could get this in the next build. smiley-wink

Thanks for your time,
DigitalJohnson
59  Using Arduino / Project Guidance / Re: Question about serial ports. on: September 30, 2012, 12:59:42 am
I'm using the three other serial ports to receive serial data on each of them. I'll have a look at the library and see if I can modify it for RX only as well as TX only. If I get the modification to work, maybe I'll submit for inclusion in standard libraries.

Thanks for the replies,
DJ
60  Using Arduino / Project Guidance / Question about serial ports. on: September 29, 2012, 04:10:48 pm
I am using an Arduino Mega. I was wondering if it is possible to use the RX on a serial port while not using the TX. In other words I'd like to use the TX pin for something else and I'm only using the serial port to receive and don't need to transmit. Is this possible?

Thanks for any replies,
DigitalJohnson
Pages: 1 2 3 [4] 5 6 ... 10