Show Posts
Pages: [1] 2 3 ... 18
1  Using Arduino / Programming Questions / Re: compile error when calling delay from within a library? on: March 09, 2014, 11:49:14 am
With the cases of interest being serial, I don't think I can write a better string handler than the one built-in!
2  Using Arduino / Programming Questions / Re: Is there a class/library that encompasses both hardware and software serial port on: March 09, 2014, 08:47:24 am
And, I can confirm that it compiles and works! Thanks everyone!
3  Using Arduino / Programming Questions / Re: compile error when calling delay from within a library? on: March 09, 2014, 08:45:21 am
It's a serial device, and I've wanted to be able to communicate with it via both hardware and software serial ports. I confess that those methods are in there to avoid compile errors, and not because I fully understand what's going on under the covers. Are you saying that when I call something like the "print" method, it will end up calling the single byte "write" method if there isn't an implementation of the write(byte*, int) method? And that all I need to do is add another of those "hey just call the method of the passed in class" entries for it to work more efficiently? (Not that efficiency is paramount here, but I'm happy to gain some by including one more line!), e.g.

Code:
    size_t write ( uint8_t* val, int num ) { return _dev->write ( val, num ); }
4  Using Arduino / Programming Questions / Re: compile error when calling delay from within a library? on: March 08, 2014, 09:25:15 pm
Thank you so much, folks; all compiles now! (and realized I forgot a Foo:: in front of the HoldOnAMinute function...)

Now I just have to make the *real* one do useful things :-)
5  Using Arduino / Programming Questions / compile error when calling delay from within a library? on: March 08, 2014, 08:08:33 pm
I must be doing something wrong, or misunderstanding something. I have a library which has a function that calls delay, and this gives a compiler error:

Code:
Arduino: 1.5.6-r2 (Windows 7), Board: "Digistump DigiX (standard)"

C:\Users\tastewar\Documents\Arduino\libraries\TESTLIB\TESTLIB.cpp: In function 'void HoldOnAMInute(long unsigned int)':
C:\Users\tastewar\Documents\Arduino\libraries\TESTLIB\TESTLIB.cpp:27: error: 'delay' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

This is in a stripped down project/library just for reproducing this. Here's the sketch
Code:
#include <Stream.h>
#include <TESTLIB.h>

Foo myFoo(Serial2);

void setup() {
  // put your setup code here, to run once:
  Serial2.begin ( 9600 );
}

void loop() {
  // put your main code here, to run repeatedly:
  myFoo.bar ( "hello world" );
  myFoo.HoldOnAMInute ( 1234 );
}

And the TESTLIB.h file:
Code:
class Foo : Stream
{
  private:
    Stream *_dev; // Somewhere to store the object's pointer

  public:
    Foo ( Stream& dev );
    ~Foo ( );
    size_t write ( uint8_t val );  // Call a function on the stored object pointer
    int available ( ) { return _dev->available ( ); }
    int read ( ) { return _dev->read ( ); }
    int peek ( ) { return _dev->peek ( ); }
    void flush ( ) { return _dev->flush ( ); }
    size_t bar ( char *string );
    void HoldOnAMInute ( unsigned long ms );
};

and the TESTLIB.cpp file:

Code:
#include <Stream.h>
#include "TESTLIB.h"

Foo::Foo ( Stream& dev )
{
_dev = &dev;
}

Foo::~Foo ( )
{
}

size_t Foo::write ( uint8_t val )
{
return _dev->write(val);
}

size_t Foo::bar ( char *string )
{
size_t a;
a=print ( "prefix" );
return a+print ( string );
}

void HoldOnAMInute ( unsigned long ms )
{
delay ( ms );
}

Is there some very generic header file I have to include in my library, or before including the library's .h file?
6  Using Arduino / Programming Questions / Re: Is there a class/library that encompasses both hardware and software serial port on: March 08, 2014, 08:02:14 pm
This is coming along nicely. Almost compiles, but getting an error that seems unrelated to this, which I will post separately.
7  Using Arduino / Programming Questions / Re: Is there a class/library that encompasses both hardware and software serial port on: March 04, 2014, 07:06:16 am
Excellent! Thanks, majenko -- I will give that approach a try!
8  Using Arduino / Programming Questions / Re: Is there a class/library that encompasses both hardware and software serial port on: March 03, 2014, 10:49:04 pm
Hmm... I don't seem to be explaining this well.

I have a serial device. It's simple enough to interface to the device either through a SoftwareSerial port, or a hardware one. But the device uses obscure commands, and I would like to hide the complexity from the user inside of a library. I would like the user to tell the library, probably in the constructor, how/where the device is connected. So the user should somehow pass to me some form of reference to a serial port. One user of the library might have an Arduino that has multiple hardware serial ports, and they might have the device connected to Serial2, so they should be allowed to pass that in to the constructor, e.g.
Code:
MyObject ( Serial2 );
But another user might only have the one hardware serial port, and might be using it for debugging, or talking to software on the computer, etc. So they might want to use a software serial port, e.g.:

Code:
SoftwareSerial ss1 ( 2, 3 );

MyObject ( ss1 );
How should I implement such a function, and what data type should it accept as its argument? I imagine I could implement 2 separate overloaded functions, one of which accepts a hardware serial name, and the other of which accepts a SoftwareSerial type. But then in the library code, everytime I want to access the serial port, I have to have an if:

Code:
if ( UsingSoftwareSerial ) DoTheSoftwareSerialThing ( );
else DoTheHardwareSerialThing ( );


I'm hoping to find a better way which appropriately hides the differences between hard and soft serial from me! :-)
9  Using Arduino / Programming Questions / Re: subroutine with struct pointer on: March 03, 2014, 10:20:51 pm
The normal way to refer to a field in a structure, when given a pointer, is with the -> operator rather than the . operator. So most if not all of your *packet.xxxxx can be replaced with packet->xxxxx and the instances where you are using &packet.xxxxx are almost certainly wrong. At a glance, I'm pretty sure you'll be significantly closer if you consistently use packet->xxxxx to refer to the fields of the structure you've been given a pointer to.
10  Using Arduino / Programming Questions / Re: Is there a class/library that encompasses both hardware and software serial port on: March 03, 2014, 10:15:00 pm
Thanks, majenko. Are you (or anyone) aware of any examples of libraries written that use Stream in this way? Mine can't, for instance, support all the child classes your search came up with, really just the hardware and software serial ones. If I derive mine from Stream, doesn't that leave me implementing all the things that the hardware and software serial classes provide, like setting baud rate, etc.? I want the user of my library to be able to pass in either a softwareserial interface (on pins 2 and 3 for example) or a hardware serial port (e.g. Serial2). If anyone is aware of such an example, I'd be greatly obliged!
11  Using Arduino / Programming Questions / Is there a class/library that encompasses both hardware and software serial port on: March 03, 2014, 05:01:59 pm
A long time ago (Arduino 022), I developed a class library for a hardware device that uses a normal serial interface. At that time, there was something like a softserial (official) and a newsoftserial (better) library available, and of course a built-in hardware serial port on the early Arduinos. Back then, it wasn't possible to easily write one library that could allow for either type of interface to the device. In the intervening years, and with what used to be newsoftserial becoming softwareserial, has the situation improved? Is there some way to develop a class which derives from whichever type of serial interface the user has available, so that they can simply pass in a reference of some sort to the serial interface they wish to use to communicate with my supported device?
12  Using Arduino / General Electronics / Re: What type of Relay to use? on: September 22, 2012, 06:45:07 am
Probably depends somewhat on what you mean by "power supply." My laptop runs on a 120V A/C power supply, but the "power supply" is a transformer that sits outside the laptop. So, up to the power supply (my definition, in this case) the voltage is indeed 120V, but beyond the PS (i.e., the wiring inside the device) it is 19V (and various lower voltages, too).

If you're device is an appliance that plugs into mains power, and you don't know for certain otherwise, the safe assumption is that it's 240V. But if you're uncertain, it's perhaps ill-advised to be modifying the device...
13  Using Arduino / General Electronics / Re: Interfacing Arduino to single coil latching relay on: September 21, 2012, 09:15:30 pm
Wow! I step away for a few hours, thinking we're done here, and there's a whole lotta discussion when I get back! Interesting!

Anyway, I can't tell you much more than I have, other than to say that my intent is to use this to make my porch light flicker on Halloween. I was looking for something like the PowerSwitch Tail but for a bulb socket. Never really expected to find something purpose-built, but this is pretty close. It's made to be connected to a PIR motion sensor as an add-on to allow it to control a second bulb, like if you were retrofitting a motion detector to a pair of floodlights.

Here's the device:
http://www.amazon.com/gp/product/B0009J1I2G/ref=s9_simh_gw_p60_d19_i1

And here's the sensor it's designed to be connected to:
http://www.amazon.com/Thomas-Betts-HS3100D-Sensing-Adapter/dp/B0009J1I26/ref=pd_cp_hi_0

So it turns out that it provides a pretty uC friendly interface. Now to find some zener diodes...
14  Using Arduino / General Electronics / Re: Interfacing Arduino to single coil latching relay on: September 21, 2012, 02:18:14 pm
Thanks, folks!
15  Using Arduino / General Electronics / Re: Interfacing Arduino to single coil latching relay on: September 21, 2012, 12:44:04 pm
D'oh! Sorry, Zener diodes. What type are you proposing?
Pages: [1] 2 3 ... 18