Show Posts
Pages: 1 ... 22 23 [24] 25 26 ... 36
346  Using Arduino / Sensors / Using analogReference() on: August 18, 2012, 08:26:08 am
I have a couple questions about using analogReference on an Pro Mini 3.3volts.

If I set the reference to 1.1volts with analogReference(INTERNAL), I assume it's till okay to have the actual voltage on the pins go up to 3.3 volts.  Is that correct?

Can I change the analogReference before I read an input, then change it back to read a different input. Any issues with doing this.  For example:
Code:
analogReference(INTERNAL);
analogRead(0);
analogReference(DEFAULT);
analogRead(1);
347  Using Arduino / Networking, Protocols, and Devices / I2C - can I ask for specific data on: August 16, 2012, 03:42:01 pm
I want to have two Arduino's communicate over I2C, so I've been looking at the example files.  It doesn't look to hard, but I'm wondering if the master can request the slave for specific data.  Right now it looks like I just make a request of a specific slave and tell it how many bytes I want.  Can I make a more specific request, for example, send me the temperature from sensor 1.

Also, do I need to worry about error checking of the data I get back, or does I2C take care of that for me?
348  Using Arduino / Programming Questions / Re: Help understanding additional tabs in IDE on: August 13, 2012, 06:41:50 pm
somesmallnumber is not defined anywhere. The extern reference to it in newtab.h tells the compiler that some other file has the definition for it, but in your case none do. You need to define it somewhere, presumably in the main tab.

Oh, I thought
Code:
extern byte somesmallnumber;
was defining it. 

So if in my main tab if I add this:
Code:
byte somesmallnumber;
Then I could use it in my main tab and also in newtab.cpp
349  Using Arduino / Programming Questions / Re: Help understanding additional tabs in IDE on: August 13, 2012, 04:50:33 pm
I created a sketch with the main tab, and a newtab.h and newtab.cpp tabs.  When I compile I get this error:
...newtab.cpp:5: undefined reference to `somesmallnumber'

Here's the main tab:
Code:
#include "newtab.h"
extern byte tabtest();
void setup()

 byte h =  tabtest();
}
void loop()
{
}

Here's newtab.h
Code:
#include <arduino.h>
extern byte somesmallnumber;

Here's newtab.cpp
Code:
#include "newtab.h"
extern byte tabtest()
{
  somesmallnumber  = 5;
  return somesmallnumber;
}


350  Using Arduino / Programming Questions / Re: Help understanding additional tabs in IDE on: August 13, 2012, 03:50:13 pm
You need to create both newtab.h and newtab.cpp.  Note, things in your sketch will only know about things in the .h file if you include it, and similarly in newtab.cpp..

Okay, that's a bit familiar from looking at library files.  What if my 2nd tab is not a .h, but just a plain simple name with no extension?  Does the IDE behave differently?

The reason I'm asking is I want to modify my w5100.h file and use a "#if defined" statement to initialize a different Slave Select pin for my Ethernet shield.  But w5100.h doesn't see my defined name because of the order things are compiled.  Someone told me I need to move my #define and the #include <ethernet.h> into a separate tab.  This would force things to compile in such a way so my #define is compiled before w5100.h.  When I started moving things to the new tab I was getting errors I didn't understand.  So now I'm trying to figure this multiple tab thing out.
351  Using Arduino / Programming Questions / Re: Help understanding additional tabs in IDE on: August 13, 2012, 03:35:45 pm
I just tried that and I still get the same error.
I only use the IDE to compile and upload to the board, but I had to put the .h and .cpp files in the include directory in my sketchpad directory on my Linux system.  You may have to put the files in the correct directory on Windows to get them read in, or get answers from somebody who actually uses the IDE to create new tabs.

I was replying to a different post, I should have quoted it.  I tried adding "extern" before "byte" but that didn't work.
352  Using Arduino / Programming Questions / Help understanding additional tabs in IDE on: August 13, 2012, 03:17:14 pm
I'm confused how adding a tab affects my sketch.  The following sketch compiles just fine:
Code:
byte somesmallnumber;
void setup()
{
}
void loop()
{
}

But if I add a tab called newtab.h and move "byte somesmallnumber" into it.  I get the error "byte does not name a type"

Here's the main sketch
Code:
#include "newtab.h"
void setup()

}
void loop()
{
}
Here's newtab.h
Code:
byte somesmallnumber;

Can someone explain what's happening?
353  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 13, 2012, 11:09:50 am
That's so because the IDE is restructuring your sketch before sending the generated source file to the compiler. It works if you use it in another tab (a separate source file, these are sent to the compiler as-is).

That explains why it's not working.  I just tried your suggestion and it didn't work.  I created another tab called EthernetTest.h and put my #define in there.  But w5100.h still doesn't recognize it.
354  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 13, 2012, 09:40:35 am
I tried my setup again, and now it's working.  I tried it with SS on pin 9 and pin 8 and it worked on both.  Also, at the beginning of setup() I set pin 10 as an OUTPUT and to HIGH.  Which I had done before.

Now I have another problem I'm trying to solve.  To get this SS pin change working, I made a change to 5100.h, but I'd like to use an #if defined to control when I change the SS pin to something else. but I can't get 5100.h to see my defined name.  At the top of my sketch I defined _CC1101_H.  But 5100.h doesn't see "#if defined (_CC1101_H)" as true. Here's what I have in 5100.h; I'm trying to get the first section to execute.

Code:
#if defined (_CC1101_H)
// Set digital pin 8 (Port B, Pin 0) as Slave Select for Ethernet shield
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega32U4__)   
  inline static void initSS()    { DDRB  |=  _BV(6); };
  inline static void setSS()     { PORTB &= ~_BV(6); };
  inline static void resetSS()   { PORTB |=  _BV(6); };
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#else       
  inline static void initSS()    { DDRB  |=  _BV(2); }; 
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
355  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 13, 2012, 07:28:22 am
Another alternative could be using a shield based on the ENC28J60 chip. You will have to use EtherCard instead of the official Ethernet library, which has quite a different interface, but it will allow you to pass the SS pin to the begin() method.

I want to stick with the Arduino shields since I have several of them.  Plus a different chip would be different libraries and a lot more to learn.  I experienced some of this when I purchased some nanodes - these are Arduino based boards with Ethernet built in.  It used the ethercard.h library and ended up being very time consuming for me to get working.  Also, some other libraries I want to use, like twitter.h assume I'm using Arduino's ethernet.h library. 
356  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 12, 2012, 09:44:02 pm
Did you set the default SS pin (digital pin 10) to OUTPUT and HIGH? Even tho you are using digital pin 8 for the w5100 SS, you must set the default SS to OUTPUT, or the SPI will not be in master mode. Normally, Ethernet.begin() does that, but it will now set digital pin 8 instead.

Yes, I tried that, it didn't help.
357  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 12, 2012, 07:12:17 pm
Maybe you might try connecting the SS signal to pin 5 of the SPI header.

Looking at the Ethernet shield schematic pin 5 on the SPI header is reset.  There is no SS pin on the header, it's connected to Digital pin 10 (ie pin 3 on J1 header).
358  Using Arduino / Networking, Protocols, and Devices / Re: Switch Slave Select pin with Ethernet shield on: August 12, 2012, 07:02:08 pm
Did you connect all the other data pins?  Power?  Ground?  Check the Ethernet Shield schematics to see which Arduino pins it connects to.

I didn't connect the other data pins, I did have power and ground connected.  As I said, this setup worked when pin 10 on the Arduino was connected to pin 10 on the Ethernet shield.  So I see no reason to hook up other pins. All I did was change 5100.h and recompiled and uploaded to the Arduino.  Physically, I moved the wire from pin 10 to pin 8 on the Arduino.
359  Using Arduino / Networking, Protocols, and Devices / Switch Slave Select pin with Ethernet shield on: August 12, 2012, 01:12:06 pm
I am trying to see if I can use a slave select pin other then pin 10 to control an Ethernet Shield (R3).  My end goal is to take an Ethernet shield and connect it to a panStamp (this is like an Arduino Pro Mini 3.3v Atmega328 with RF chip).  The panStamp uses SPI to communicate with the RF chip and it's hard wired to use pin 10 for SS. 

As a test just to see if I could get an Ethernet shield to work using a different SS pin, I took a Duemilanove and connected it to a Arduino Ethernet shield R3.  I didn't plug the shield into the headers, I just used wires to connect the two.  I had pin 10 on each connected, then pins 11-13 on the Duemilanove wired to the SPI connector on the shield. Plus 5v and Gnd.  This setup worked fine and I could use the Ethernet shield to upload to cosm.com.

I did some research on changing the SPI pin and found this forum post which was pretty informative.  Basically he says to change modify 5100.h file.  So I changed
Code:
inline static void initSS()    { DDRB  |=  _BV(2); }; 
inline static void setSS()     { PORTB &= ~_BV(2); };
inline static void resetSS()   { PORTB |=  _BV(2); };
to
Code:
inline static void initSS()    { DDRB  |=  _BV(0); }; 
inline static void setSS()     { PORTB &= ~_BV(0); };
inline static void resetSS()   { PORTB |=  _BV(0); };

This should change to SPI from pin 10 to pin 8.

For my test I connected pin 8 on the Duemilanove to pin 10 on the Ethernet shield.  But I couldn't get the Ethernet shield to work with this setup.  I also tried to set pin 8 low in my sketch with digitalWrite() before I made an Ethernet call, but that didn't help.  Is it even possible to use a pin other then 10?  If so, are their certain pins that will work and others that won't?  I'd appreciate any suggestions in getting this to work.

 
360  Using Arduino / Networking, Protocols, and Devices / Re: Low Cost RF Transmitter and Receiver setup on: August 12, 2012, 12:46:48 pm
I just got some panStamps which are pretty neat.  They have  a RF chip and Arduino Pro Mini together on one small PCB. 
http://www.panstamp.com/home
Pages: 1 ... 22 23 [24] 25 26 ... 36