Show Posts
Pages: 1 [2] 3 4 5
16  Using Arduino / Programming Questions / Pointer to Print Class (DualWriter) / TelnetServer [solved] on: November 25, 2013, 06:51:01 am
Hi Community,

i have build a test sketch for a 'menu control' for debugging things..
this sketch is reachable in two ways:
Serial
Telnet (arduino ethernet)
the Telnet thing is based on the concept of this post
for windows you can use PuTTY a telnet client.

at the moment i need a extra menu handler function for both communication ways.
but i would like to use the same menu handler function.
so i had two ideas to get this to work:
(1) give the handler function a pointer to the Object it should use for print
(2) have a 'own' myprint function that prints to both outputs.
     (just calls the orig. Serial.print() and EthernetClient.print() with the same content)

so with version (2) i would need a function that imitates the orig. print function -
but thats not so trivial - because i think there are multiple versions to get the different data-types printed -
so if i am right i would have to build that behavior too ;-) (minimal for the types i use..)

for (1) i think it should be really easy - but i don't know which pointer type to use-
one time i could use HardwareSerial the other i need EthernetClient - so how to get this together?
i know that they are both based on Stream and for printing Stream is based on Print ??

so if someone of you have an idea how to do this pleas let me know !
i have added a demosketch with the simple Serial and Telnet Menus.
(edit: updated title and updated the sketch attachment)

sunny greetings
stefan
17  Using Arduino / Audio / Re: Thoughts on a costum midi controller (what should I use) on: November 24, 2013, 01:19:29 pm
if you use a arduino that is based on Atmel ATmega32U4 this chip could be your USB Midi thing.
there are some finished libs for Mouse and Keyboard - but as far as i know no lib for Midi -
one option is to check LUFA (there are midi examples)
but i dont know if it is possible to get this in combination with the normal Arduino IDE...

if you have an UNO with the 8U2 you can use the dualMocoLUFA

i hope now you have some starting points...

sunny greetings
stefan
18  Community / Website and Forum / Reference - Ethernet library page on: November 24, 2013, 10:55:59 am
Hi Community,

i have read the Reference page about the Ethernet library
http://arduino.cc/en/Reference/Ethernet
and found that there is the Server and Client Class - but if you try to compile with the current IDE it tells you:
Quote
As of Arduino 1.0, the Server class in the Ethernet library has been renamed to EthernetServer.
so i think in the Reference there should be a remark on the Server and Client page that they are renamed?!

sunny greetings
stefan
19  Using Arduino / Programming Questions / Re: #ifdef / #switchdef / array for upload to multiple targets (same HW) on: November 14, 2013, 10:18:18 am
thanks for the suggestion with the EEPROM.
i haven't worked with this up to now ;-)
so its a good idea to look into it.

the fixed ip is by design. in the system where this boards will be used are no dhcp. all server and clients have fixed ips.
Also if you are using an ethernet or WiFi card it should have a MAC ROM already...
iam using the ArduinoEthernet boards - so its the same like an UNO + Ethernet-Shield
so the W5100 has a programmed mac?
than i think there would be a option to read that out with the Ethernet library..

sunny greetings
stefan
20  Using Arduino / Programming Questions / #ifdef / #switchdef / array for upload to multiple targets (same HW) on: November 14, 2013, 07:16:00 am
hello community,

i will have to program ~20 ArduinoEthernet boards - all with the identical sketch -
but every board has a uniq mac and a ipaddress -
so i searching for an idea to 'define' the 'Hardware/Bord-Specific' parameters for all boards -
and than choose in an easy way which one to use for the current upload target (connected board)..

i have two different ideas till now -
1 - use a array to store all possible configs
Code:
tDeviceParameters dpDeviceList[] = {
{ // -- not used.
 0, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x00 }, // mac
IPAddress(192, 168, 222, 100), // ip
},
{ // development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
},
{ // test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
},
{ // second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
},
};

tDeviceParameters dpThisDeviceX = dpDeviceList[1]; // number is identical with ID == identical with IPAddress ending.
problem: all infos are using space... but only one is used...

2 - use a list of #ifdef s
Code:
#define DEVICE_1

#ifdef DEVICE_1
tDeviceParameters dpThisDevice = {
// development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
};
#endif

#ifdef DEVICE_2
tDeviceParameters dpThisDevice = {
// second test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
};
#endif

#ifdef DEVICE_3
tDeviceParameters dpThisDevice = {
// second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
};
#endif
//...
this is not so nice from the formating  ?!  smiley-cool

have someone out there another idea / concept to do something like this?
i have added my test sketch - its the basic UDPSendReceiveString Example with small modifications.
or is the compiler so clever to know that only one of the entrys in an array is used in the software?

sunny greetings
stefan
21  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 11:35:19 am
thanks for the explanation :-)
22  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 11:03:34 am
thanks PaulS.
that fixed it.
i think i  understand - the difference -
Code:
FaderLin::state_Standby
so you just use the class definitions
Code:
myFaderOne.state_Standby
so you use the instance to get the member.
--> what is returned the second way?
means this i have to use the first one every time i have defined static members in my classes for a cleaner style?

i have tried to minimize code so its easier to read and understand -
if you want to look at the full code - i have added the test sketch and the raw lib files-
( the lib files go into 'arduino_sketchbook\libraries\FaderLin\' )
( the test sketch go into 'arduino_sketchbook\test_callBackFunc\' )
23  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 10:29:31 am
Hi PaulS,
Hi PeterH,
ok sorry.
i hope this time i have all relevant information posted.

in the the Library header file (FaderLin.h) i declare the constants -
Code:
/** FaderLin Library **/
//Check if this class is allready there or if it must be created...
#ifndef FaderLin_h
#define FaderLin_h


/** Includes Core Arduino functionality **/
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

/** Class Definition: **/

class FaderLin
{
public:
// public definitions:

static const byte state_NotValid = 0;
static const byte state_Standby = 1;
static const byte state_Fading = 2;
static const byte state_Finished = 42;

//call back function definition
typedef void (* tCbfuncStateChanged) (byte *bState);
typedef void (* tCbfuncValuesChanged) (word *wValues, byte bCount);


// public methods

//Constructor
//FaderLin(byte cbChannelCount_Temp);
FaderLin(byte cbChannelCount_Temp, tCbfuncValuesChanged cbfuncValuesChanged_Temp, tCbfuncStateChanged cbfuncStateChanged_Temp);


//Destructor
~FaderLin();


// initialize class
void begin();

// check if class is ready to operate.
boolean isReady();

// public methods

/** update **/
/**
  * update()
  * returns state
  * main function of library. call as often as possible ;-)
  **/
byte update();

/** getState **/
byte getState();

/** fader things **/
void startFadeTo(unsigned long ulFadeDuration_New, uint16_t *waValues_NewTarget);
//void startFadeTo(unsigned long ulFadeDuration_New, uint16_t wValues_NewTarget);
void stopFade();

uint16_t *getCurrentValues();
//uint16_t getCurrentValues();

const byte getChannelCount();

private:
// per object data

// flag to check if the begin function is already called and the class is ready to work.
boolean bReady;

//call back functions:
const tCbfuncValuesChanged cbfuncValuesChanged;
const tCbfuncStateChanged cbfuncStateChanged;

//internal variables
unsigned long ulTimeStamp_FadeStart;
unsigned long ulFadeDuration;

boolean flagFadingFinished;
boolean Active;

// channels:
const byte cbChannelCount;

//http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702
uint16_t *waValues_Source;
uint16_t *waValues_Target;
uint16_t *waValues_Current;
uint16_t *waValues_Dif;
boolean *baValues_DifIsNegativ;

// private methods
void printArray(uint16_t *array);

// word multiMap(word val, word* _in, word* _out, uint8_t size);

};

#endif //ifndef FaderLin_h

/** the end **/

in my testsketch (test_callBackFunc.ino) i have included the Library and...
Code:
/** libraries **/
#include "FaderLin.h"

//FaderLin myFaderOne(2);
FaderLin myFaderOne(2, myFaderOne_callback_OutputChanged, myFaderOne_callback_StateChanged);

//....

void myFaderOne_callback_StateChanged(byte *bState) {
Serial.println(F("myFaderOne State:"));
/* does not work. error: 'myFaderOne' cannot appear in a constant-expression */
switch (*bState) {
case myFaderOne.state_Standby : {
Serial.println(F("standby"));
} break;
case myFaderOne.state_Fading : {
Serial.println(F("fading."));
} break;
case myFaderOne.state_Finished : {
Serial.println(F("fading finished!"));
} break;
default: {
Serial.println(F("error. not a know state."));
}
} //end switch
/* */

/* this way it would work...
if ( (*bState) == myFaderOne.state_Standby ) {
Serial.println(F("standby"));
}
/* */
}

//....

void setup() {
//...
Serial.println(F("FaderLin:"));
Serial.println(F("\t myFaderOne.begin();"));
myFaderOne.begin();
Serial.println(F("\t finished."));
//...
}

void loop(){
//...
myFaderOne.update();
//...
}
... and 'made' a object out of my class.
(pleas correct the wrong technical terms - at the moment i cant remember the right ones..)
so with myFaderOne.state_Standby i have the value of the constant definition?!
but at this point i dont know how exactly this works..
i think the compiler cant make a fix (constant) thing out of my 'myFaderOne.state_Standby'-
so  i have to tell the compiler that this hole thing ('myFaderOne.state_Standby') is a constant?!
but how?

sunny greetings
stefan
24  Using Arduino / Programming Questions / switch statement and const from class (solved) on: November 12, 2013, 07:24:39 am
Hello community,

its just a simple 'is it possible':
i have:
Quote
void myFaderOne_callback_StateChanged(byte *bState) {
   Serial.println(F("myFaderOne State:"));
   /* does not work. error: 'myFaderOne' cannot appear in a constant-expression */
   switch (*bState) {
      case myFaderOne.state_Standby : {
            Serial.println(F("standby"));
         } break;
      case myFaderOne.state_Fading : {
            Serial.println(F("fading."));
         } break;
      case myFaderOne.state_Finished : {
            Serial.println(F("fading finished!"));
         } break;
      default: {
            Serial.println(F("error. not a know state."));
         }
   } //end switch
   /* */
}
the compiler don't like this because of
test_callBackFunc:426: error: 'myFaderOne' cannot appear in a constant-expression
test_callBackFunc:426: error: `.' cannot appear in a constant-expression

i have defined the states in my class as public :
static const byte state_Standby            = 1;
static const byte state_Fading            = 2;
static const byte state_Finished         = 42;
if i check with an if
Quote
   if ( (*bState) == myFaderOne.state_Standby ) {
      Serial.println(F("standby"));
   }
it just works.

i see the problem is that the compiler needs a const as switch statement.
and he dont get the linke to the consts in the class.
so is there a solution to do this with a  switch statement? / to tell the compiler that 'myFaderOne.state_Fading' is a 'const' ??
i know that i can use if..
its just out of interest..

sunny greetings stefan
25  Using Arduino / Programming Questions / Re: class - constructor initialize constant on: September 16, 2013, 04:26:44 pm
@Paul: thanks for the explanation/tip
now i have it working;-)
26  Using Arduino / Programming Questions / Re: class - constructor initialize constant on: September 16, 2013, 06:54:25 am
@Nick Gammon:
i tried your tip -
thanks! it works!!!!


@Paul: You are right!
the idea to have it const was just because of the second thing:
Code:
void FaderLin::startFadeTo(unsigned long ulFadeDuration_New, uint16_t waValues_NewTarget[cbChannelCount]) {
// set Source values
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
// set Target Values
waValues_Target[bIndex] = waValues_NewTarget[bIndex];
}
}
but i think that is no way to go -
i think i have to learn to use reference at this point...
27  Using Arduino / Programming Questions / class - constructor initialize constant [solved] on: September 16, 2013, 06:03:59 am
Hello Community,

iam experimenting with writing a library and have some questions:

how is the 'prefered' way to pass a value to the class that will not change over runtime?

normaly i would just use
Code:
const byte bMyConstantValue = 4;
i have tried and declared my Value in the .h file as following:
Code:
/** Class Definition: **/

class FaderLin {
public:
// public definitions:
static const byte state_Fading = 0;
static const byte state_Finished = 1;
// public methods
//Constructor
FaderLin(const byte cbChannelCount_Temp);
//Destructor
~FaderLin();

// initialize class
void begin();
// public methods
byte update();
private:
// per object data
// flag to check if the begin function is already called and the class is ready to work.
boolean bReady;

// channel values:
const byte cbChannelCount;

// http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702
uint16_t *waValues_Source;
uint16_t *waValues_Target;
uint16_t *waValues_Current;
uint16_t *waValues_Dif;

// private methods
};
and in the constructor of the class (.cpp file)
Code:
/** Constructor **/
FaderLin::FaderLin(const byte cbChannelCount_Temp)
{
//do some initializing
//check how to initialize const values in this place..
cbChannelCount = cbChannelCount_Temp;
}

/** Begin (activate object/instantce) **/
void FaderLin::begin()
{
if (bReady == false)
{
#ifdef debug_FaderLin
Serial.println(F("************************************************************"));
Serial.println(F("** Welcome to FaderLin World - Library will initialise... **"));
Serial.println(F("************************************************************"));
Serial.println(F("FaderLin::begin: "));
#endif

//clean up memory.
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
waValues_Source[bIndex] = 0;
waValues_Target[bIndex] = 0;
waValues_Current[bIndex] = 0;
waValues_Dif[bIndex] = 0;
}
bReady = true;
}
}
with this i get the errors:
Code:
...\FaderLin.cpp: In constructor 'FaderLin::FaderLin(byte)':
...\FaderLin.cpp:101: error: uninitialized member 'FaderLin::cbChannelCount' with 'const' type 'const byte'
...\FaderLin.cpp:105: error: assignment of read-only data-member 'FaderLin::cbChannelCount'
...
the assignment is clear - but how to do it a nother way??

as you can see i want to use the value to initialize a array.
for the array i found the solution @http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702

so in the first thing i just declared the 'cbChannelCount' as normal 'byte' type. so i just only read it in my code.
but in one following function i want to get an array with the same size as my internal arrays from the 'user-sketch'.
i also want to give the user access to the values of the waValues_Current array with a 'get' function.

my first approach was
Code:
void FaderLin::startFadeTo(unsigned long ulFadeDuration_New, uint16_t waValues_NewTarget[cbChannelCount]) {
// set Source values
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
// set Target Values
waValues_Target[bIndex] = waValues_NewTarget[bIndex];
}
}
but here the errors are:
Code:
...\/FaderLin.h: At global scope:
...\/FaderLin.h:184: error: invalid use of non-static data member 'FaderLin::cbChannelCount'
...\FaderLin.cpp:269: error: from this location
...\FaderLin.cpp:269: error: array bound is not an integer constant
...\FaderLin.cpp:269: error: prototype for 'void FaderLin::startFadeTo(long unsigned int)' does not match any in class 'FaderLin'
...\/FaderLin.h:145: error: candidate is: void FaderLin::startFadeTo(long unsigned int, uint16_t*)
can someone help me how to do this the right way?
or has someone some tutorials / infos to learn the basics in for this kind of things?

sunny greetings

stefan
28  Development / Other Hardware Development / Re: Leonardo clone circuit check on: August 23, 2013, 04:43:22 am
your right - in the examples they use the 'pull down' method so you get 'Normal Logic results':
when you push the button the pin goes high.
if you look in other projects normally you use the buttons the other way:
normally the portpin is hold hi with the internal or an external PullUp . and the Button shorts to ground -
so it pulls the portpin low. so in sw you have a inverted logic.
i don't know why - i think the second is the common way...
(+you can use the internal PullUp)

its the same way with the LED / Blink Example.
as fare as i know you normally use the Port to sink current - and if i remember right this comes from history-
older uC could only sink current..
pleas correct if iam wrong..

has someone a recommendation for an tutorial on 'bootloader / leonardo / atmel VID PID / how to compile / windows *driver* inf ' ??
i just also want to use the orig. bootloader but use the atmel vid pid s for my clone...

sunny greetings stefan
29  Using Arduino / Installation & Troubleshooting / WindowsVista - IDE 1.0.4 - Board:Leonardo(Olimex OLIMEXINO32U4) - upload problem on: July 03, 2013, 02:18:51 pm
[edit]
sorry - i clicked on the submit button twice..
thanks for merging the two.
[/edit]
30  Using Arduino / Installation & Troubleshooting / WindowsVista - IDE 1.0.4 - Board:Leonardo(Olimex OLIMEXINO32U4) - upload problem on: July 03, 2013, 02:17:56 pm
Hi Community,

i have a strange problem on
Windows Vista,
Arduino IDE 1.0.4
with an Arduino Leonardo Clone OLIMEX OLIMEXINO32U4
and Upload:

Code:
...
C:\Users\xxx\AppData\Local\Temp\build5162954245918573058.tmp\Analog2DMX_USART_12ch_v02.cpp.hex
Binary sketch size: 7,356 bytes (of a 28,672 byte maximum)
Forcing reset using 1200bps open/close on port COM6
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
PORTS {COM6, } / {COM6, } => {}
Uploading using selected port: COM6
C:\Users\xxx\Desktop\Programme und Downloads\Programme\arduino_app\arduino-1.0.4\hardware/tools/avr/bin/avrdude -CC:\Users\xxx\Desktop\Programme und Downloads\Programme\arduino_app\arduino-1.0.4\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega32u4 -cavr109 -P\\.\COM6 -b57600 -D -Uflash:w:C:\Users\xxx\AppData\Local\Temp\build5162954245918573058.tmp\Analog2DMX_USART_12ch_v02.cpp.hex:i

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Users\xxx\Desktop\Programme und Downloads\Programme\arduino_app\arduino-1.0.4\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM6
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
avrdude: ser_open(): can't set com-state for "\\.\COM6"
avrdude: Send: E [45]
avrdude: ser_send(): write error: sorry no info avail

it looks like the IDE does not wait long enough so the bootloader is found by the system.
the board goes to reset mode and sometimes it is working.
but most of the time the upload fails - thats clear - it tries to upload on com3 - but thats not the one that will get the code....

in the device manager the arduino shows up and also the driver is installed correctly.
if a sketch is uploaded it just works.
are there some more infos you need?

has it to do with some right managment on vista or with the driver?

thanks for your help

sunny greetings

stefan


[edit]
sorry - i clicked twice on the submit button....
[/edit]
Pages: 1 [2] 3 4 5