Show Posts
Pages: 1 2 [3] 4 5
31  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 21, 2013, 01:40:28 am
i have the thing in the hardware folder in my sketchbook folder.
and yea - the showing up in the ide -
i have used the ide to program the bootloader -
therefore i had to choos the the board type.
after the bootloader upload i just switched the Serialport to the USB-Serial Converter one and opend the blink sketch and hit upload-
so i dont changed the board type..

this evening i will redo the process step by step and document with photos - just to be sure i dont have missed something..
...When I get a not in sync error, it's usually because
I have the wrong board selected.
hm - is there a possibility to check if the bootloader is running fine?
(the 3flashes after reset are visible.)
i have read long ago about a debuging mode??! or something if you have !!! in your sketch the bootloader goes in ?-mode??
i dont remember what this was about..

32  Using Arduino / Project Guidance / Re: Optimal Arduino board for a multichannel system. on: May 21, 2013, 01:05:36 am
Hi,

i don't know what kind of signal you get from the EMGs - but i think they are in some way analog?
so if you have 4 analog + 1 analog for the force you need an arduino with 5 analog ins.
you can use a UNO or Leonardo - the UNO has 6 analog ins - the Leonardo has 12 analog ins
for the camcorder video signal the best way is to use a computer directly.
to log or capture video with arduino could be possible - but to store such amount of data i would prefere a computer based system.
so eventually your camcorder has firewire?! so if you have a firewire interface on your computer and driver software for the camcoder it is the easiest way.
you can program the arduino so it will just send the raw sensor readings to the computer over a Serial Interface. (it is connected with USB but shows up as Serial COM Port)
the last - and i think trickiest thing is - you need a software to log the data synchronized.
you can look if processing is capable of doing this?!

sunny greetings stefan
33  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 21, 2013, 12:37:11 am
i used the zip file from jbaum81 dated 04042013.1.zip
and for upload / burning the bootloader i used the
[MegaJr] Mega Junior,1284 V.1 Rev. A (16MHz) and
[MegaJr] Mega Junior,1284 V.1 Rev. A (20MHz)

boards.txt settings:
Code:
#############################################################

mega_jr_16.name=[MegaJr] Mega Junior,1284 V.1 Rev. A (16MHz)
mega_jr_16.upload.protocol=arduino
mega_jr_16.upload.maximum_size=130048
mega_jr_16.upload.speed=115200
mega_jr_16.bootloader.low_fuses=0xd7
mega_jr_16.bootloader.high_fuses=0xd6
mega_jr_16.bootloader.extended_fuses=0xfd
mega_jr_16.bootloader.path=megajr
mega_jr_16.bootloader.file=optiboot_atmega1284p_16.hex
mega_jr_16.bootloader.unlock_bits=0x3F
mega_jr_16.bootloader.lock_bits=0x0F
mega_jr_16.build.mcu=atmega1284p
mega_jr_16.build.f_cpu=16000000L
#mega_jr_16.build.core=arduino:arduino
mega_jr_16.build.core=standard
mega_jr_16.build.variant=MegaJr

##############################################################

mega_jr_20.name=[MegaJr] Mega Junior,1284 V.1 Rev. A (20MHz)
mega_jr_20.upload.protocol=arduino
mega_jr_20.upload.maximum_size=130048
mega_jr_20.upload.speed=115200
mega_jr_20.bootloader.low_fuses=0xd7
mega_jr_20.bootloader.high_fuses=0xd6
mega_jr_20.bootloader.extended_fuses=0xfd
mega_jr_20.bootloader.path=megajr
mega_jr_20.bootloader.file=optiboot_atmega1284p_20.hex
mega_jr_20.bootloader.unlock_bits=0x3F
mega_jr_20.bootloader.lock_bits=0x0F
mega_jr_20.build.mcu=atmega1284p
mega_jr_20.build.f_cpu=20000000L
#mega_jr_20.build.core=arduino:arduino
mega_jr_20.build.core=standard
mega_jr_20.build.variant=MegaJr
34  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 20, 2013, 04:18:17 pm
Hi jbaum81,

i have tried to use your 20Mhz Version on Breadboard.
installed with an Arduino Duemilanove (328) with Arduino ISP sketch.
the ide tolled me it was successfull.
when i try to upload a sketch (the blink example)
i get an out of sync error
Code:
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:\_Local_DATA\_tools\_Develop\_app_arduino\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM19
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.
the led on PB0 is flashing 3times on reset - so i know the reset is triggered -
but somehow the chip is not answering.
if i test it with your 16MHz version all is fine
the only thing i change on the breadboard is the crystal.

i have used the tools from Nick Gammon
(Atmega1284P minimal board and  nickgammon / arduino_sketches)
his Fuse Calculator shows:
Code:
Atmega fuse calculator.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 0x1E 0x97 0x05
Processor = ATmega1284P
Flash memory size = 131072
LFuse = 0xD7
HFuse = 0xD6
EFuse = 0xFD
Lock byte = 0xCF
Clock calibration = 0x83
OCD Enable.............................. [ ]
JTAG Enable............................. [ ]
Enable Serial (ICSP) Programming........ [X]
Watchdog Timer Always On................ [ ]
Preserve EEPROM through chip erase...... [X]
Boot into bootloader.................... [X]
Divide clock by 8....................... [ ]
Clock output............................ [ ]
Bootloader size: 1024 bytes.
Start-up time: SUT0: [ ]  SUT1: [X] (see datasheet)
Clock source: full-swing crystal.
Brownout detection at: 2.7V.

His Board Detector Shows
Code:
Atmega chip detector.
Entered programming mode OK.
Signature = 1E 97 05
Processor = ATmega1284P
Flash memory size = 131072
LFuse = D7
HFuse = D6
EFuse = FD
Lock byte = CF
Clock calibration = 83
Bootloader in use: Yes
EEPROM preserved through erase: Yes
Watchdog timer always on: No
Bootloader is 1024 bytes starting at 1FC00

Bootloader:

1FC00: 11 24 84 B7 14 BE 81 FF E7 D0 85 E0 80 93 81 00
1FC10: 82 E0 80 93 C0 00 88 E1 80 93 C1 00 86 E0 80 93
1FC20: C2 00 85 E1 80 93 C4 00 8E E0 C0 D0 20 9A 86 E0
1FC30: 2C E3 3B EF 91 E0 30 93 85 00 20 93 84 00 96 BB
1FC40: B0 9B FE CF 18 9A A8 95 81 50 A9 F7 EE 24 FF 24
1FC50: BB 24 B3 94 A1 E1 CA 2E F3 E0 DF 2E 9B D0 81 34
1FC60: 59 F4 98 D0 08 2F A8 D0 02 38 39 F1 01 38 09 F4
1FC70: 7F C0 83 E0 87 D0 83 C0 82 34 11 F4 84 E1 03 C0
1FC80: 85 34 19 F4 85 E0 A0 D0 7A C0 85 35 91 F4 82 D0
1FC90: 08 2F 10 E0 7F D0 E8 2E FF 24 FE 2C EE 24 E0 2A
1FCA0: F1 2A 8F 2D 88 1F 88 27 88 1F 8B BF EE 0C FF 1C
1FCB0: 65 C0 86 35 21 F4 84 E0 87 D0 80 E0 DB CF 84 36
1FCC0: 09 F0 41 C0 67 D0 66 D0 08 2F 64 D0 80 E0 E8 16
1FCD0: 80 EE F8 06 18 F4 F7 01 D7 BE E8 95 C0 E0 D1 E0
1FCE0: 59 D0 89 93 0C 17 E1 F7 F0 E0 EF 16 F0 EE FF 06
1FCF0: 18 F0 F7 01 D7 BE E8 95 5F D0 07 B6 00 FC FD CF
1FD00: A7 01 A0 E0 B1 E0 2C 91 30 E0 11 96 8C 91 11 97
1FD10: 90 E0 98 2F 88 27 82 2B 93 2B 12 96 FA 01 0C 01
1FD20: B7 BE E8 95 11 24 4E 5F 5F 4F F2 E0 A0 30 BF 07
1FD30: 51 F7 85 E0 F7 01 87 BF E8 95 07 B6 00 FC FD CF
1FD40: C7 BE E8 95 1C C0 84 37 61 F4 24 D0 23 D0 08 2F
1FD50: 21 D0 32 D0 F7 01 87 91 7F 01 14 D0 01 50 D1 F7
1FD60: 0E C0 85 37 39 F4 28 D0 8E E1 0C D0 87 E9 0A D0
1FD70: 85 E0 80 CF 81 35 11 F4 88 E0 18 D0 1D D0 80 E1
1FD80: 01 D0 6C CF 98 2F 80 91 C0 00 85 FF FC CF 90 93
1FD90: C6 00 08 95 80 91 C0 00 87 FF FC CF 80 91 C0 00
1FDA0: 84 FD 01 C0 A8 95 80 91 C6 00 08 95 E0 E6 F0 E0
1FDB0: 98 E1 90 83 80 83 08 95 ED DF 80 32 19 F0 88 E0
1FDC0: F5 DF FF CF 84 E1 DE CF 1F 93 18 2F E3 DF 11 50
1FDD0: E9 F7 F2 DF 1F 91 08 95 28 2E 80 E0 E7 DF EE 27
1FDE0: FF 27 09 94 FF FF FF FF FF FF FF FF FF FF FF FF
1FDF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE00: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FE90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FEA0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FEB0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FEC0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FED0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FEE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FEF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF00: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FF90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFA0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFB0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFC0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFD0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
1FFF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 05

MD5 sum of bootloader = 02 98 C3 84 86 12 DA 29 D3 94 65 05 C4 41 A0 C3

First 256 bytes of program memory:

0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
10: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
20: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
30: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
40: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
50: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
60: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
70: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
80: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
90: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
A0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
B0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
C0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
D0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
E0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
F0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

the fuse settings look fine if i sea it right.
is there a way to check if the bootloader is flashed right and working?!
or there are other checks that i can do ?
can some one else read something out of the test tool outputs??

thanks for your help!

sunny greetings stefan
35  Using Arduino / Installation & Troubleshooting / Arduin IDE 1.0.5 - Menu - Tools - Board - long list on: May 19, 2013, 05:37:27 pm
Hi community,

i have found a small 'bug':
if you have a hardware folder in your sketchbook folder and in there some extra boards  -
than the list under Tools - Board gets to long to show on the screen...
ok - for this it need really much boards.. but i get this problem as i added the jbaum81-megajunior1284 optiboot clone.
the list is not scrollable - so you cant reach the entries that are going out of your screen..
i think it would be nice - if there is a custom 'hardware' folder that this board would show up in an submenue - one sub menu for each folder in 'hardware' ..
so you can test and play with different user defined boards...

sunny greetings stefan
36  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 19, 2013, 03:58:55 pm
thanks oric_dan!
your right-
i have get it the wrong way-
so i will update my original post!
the fuse settings mean: Brown Out Detection  enabled for the Power Condition.

Thanks!!
37  Using Arduino / Project Guidance / Re: Control Robotic Arm via Android or iPhone on: May 19, 2013, 03:47:17 pm
i think android is easier - but if your goal is to use it in an marketing thing you have to go with ios devices..
other idea is - you search for possible finished systems to use-
so you dont have to learn all the stuff to setup a complete one application and communication system..
i think i have read about some ideas and concepts some where ..
38  Using Arduino / Project Guidance / Re: Radioshack LED strip (Power Issues??) on: May 19, 2013, 03:41:33 pm
if your arduino is ok - than this should work..
39  Using Arduino / Motors, Mechanics, and Power / Re: Battery for childrens ball on: May 19, 2013, 03:32:47 pm
Hey dt08bdk,

i would use some normal AAA types - its easy to replace - and 'the user' could decide if he uses rechargeable types..
but i think you will read something similar on all battery types...
its an interesting thing to think about the usage of the materials..
sunny greetings stefan
40  Using Arduino / Motors, Mechanics, and Power / Re: Food Grade or acceptable electronics on: May 19, 2013, 03:27:06 pm
I have searched for a long time about food grade pumps.
the only thing i have found are peristaltic pumps.
just like the one that cr0sh linked!!
with this technic only the tube is in contact with the food.
for the tube you can try to get a sample - i have order one in the past and it was no problem to get one meter.
peristaltic pumps have some disadvantages:
  • for the most pumps its difficult to get them and they are expansive
  • they are slow
if you dont need the pump but can work with gravity you can just think about an ~180° bending of the tubing. 
i think this should be possible with an simple servo..

there are people out there that try to build diy peristaltic pumps but its difficult - the motor and mechanics must withstand heavy forces ( for squeezing the tubing)
you can check out the Bartendro people - they have a peristaltic pump modified so it has the controller things 'on board'
i think they use a Welco WP 11 (up to 700ml/min) pump as base and modifies them to there needs...

i am interested in this too - so just report back if you have some other ideas or sources of peristaltic pumps :-)
sunny greetings stefan
41  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 19, 2013, 02:57:25 pm
Hey all,

you are right - CKOUT is PB1 == pin number 2 on the dip == pin number 41 on the TQFP;
he maps PB1 to Arduino D1 (check in the pins_arduino.h file)

if i interpret the fuse settings right -
the fuse for CKOUT is set - so it would output the cpu_clock on this pin.
and that means you cant use this pin as Digital IO -
so i just want to know why jbaum has choose to do this.
it could be that i have misunderstood the datasheet..
pleas check my explanation / table in my earlier post
if i have all thinks understood right - it shows - what the settings i have found in the make file - would mean...
iam in the process of learning about bootloaders - so i want just to understand what is going on...
sunny greetings stefan
42  Using Arduino / Microcontrollers / Re: Mega Junior,1284 on: May 19, 2013, 08:05:23 am
jbaum is using the fix that was discovered on a couple of incredibly long threads about 1284
RX0 problems from back in february 2013. With the fuse bit settings used in the maniac 1284
bootloader files [low power oscillator], chip operation is disrupted because of crosstalk between
RX0 and the crystal pins. Maniacbug still hasn't fixed his files.

Hi oric_dan,
yea i have read a lot of this - it makes sens to use the full swing if you dont care about power..
my main question is :
Why is the CKOUT activated?

sunny greetings stefan
43  Using Arduino / Microcontrollers / Re: Mega Junior,1284 Bootloader on: May 11, 2013, 02:49:47 pm
Hi jbaum81,

i have setuped a 1284P on a BreadBoard for testing.
at the moment i have loaded it with the mighty 1284P optiboot 16MHz
but just out of interest i would love to try the 20MHz version.

i have looked at your version and found that you have lowFuse set to 0xD7
if i have interpreted the atmel datasheet the right way this means:
(table based on datasheet page 298; 27.2 Fuse bits and page 31..; 9. System clock and clock options)
Code:
CKDIF8  CKOUT  SUTn  CKSELn   hex    comment
               1 0   3 2 1 0      
1       1      1 1   0 1 1 1   0xF7  Full swing Crystal Oscillator, slowly rising power;  mighty modified;
1       1      0 1   0 1 1 1   0xD7  Full swing Crystal Oscillator, slowly rising power, BOD enabled; <--your version?!
1       1      1 1   1 1 1 1   0xFF  Low Power Crystal Oscillator,  slowly rising power; mighty optiboot;

[edit] corrected - read this message from oric_dan for orig.  [/edit]

[original]CKOUT is explained at page 39; 9.10 Clock Output Buffer: if set it will output the CPU-frequenz on the CLKO pin. (overriding normal port io functionality)
so do you using this for something?
or is there some other thinks i don't know about this? (i am new to bootloaders and system clock..)[/original]


and has someone a nice 'tutorial' how to compile the bootloaders self?
or is it to complicated and you have to know to much background infos?
thanks for your time.

sunny greetings stefan
44  International / Deutsch / Re: IR Sensor, Zuordnung bei mehr als 8 Signalen macht Probleme on: May 10, 2013, 04:24:55 pm
Hi Lambda,

ich hab mir gerade mal deinen Sketch angeschaut -
und hab dann mal in die ir lib geschaut die hier auch schon gepostet wurde (hab die schon ausproiert  - funktioniert echt gut...)
und dann hab ich überlegt ob du vielleicht sogar ohne viel aufwand dein system 'nonblocking' umbauen kannst:
du könntest nen timer interrupt als Zeit Basis benutzen. (so macht die lib das auch)
wäre nen guter einstieg in timmer  (hab ich neulcih auch gemacht^^)
der rest kann denke ich zum testen fast so bleiben...
als einstieg in die interrupt geschichte empfehle ich http://www.gammon.com.au/forum/?id=11488&reply=2#reply2

viel erfolg und spaß!

sonnige grüße stefan
45  Using Arduino / Programming Questions / headerfile: order of definitions - using typdefs/structs in each other [solved] on: April 24, 2013, 04:01:57 pm
Thanks pYro_65,

it is working great :-)
[solved]

my next step is to convert this into a library - maybe this is a bit overkill for this easy thing - but hey - its easy to use and makes a project more structured. (so my opinion)

so in this case - if i have the same schema for the callback function the class would need to give a referenc to herself.
how is this possible ? or is there a other method or construct to make something similar?

i have the library attached as zip but for a fast look i include the header and cpp here:
(in the zip is also an example - my test sketch for developing the lib)

slight_RotaryEncoder.h
Code:
/**
  * slight_RotaryEncoder.h
  * for Infos  see slight_RotaryEncoder.cpp file
  **/

 
#ifndef slight_RotaryEncoder_h
#define slight_RotaryEncoder_h

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


/**
  *
  * Definitions
  *
  **/

/*
struct aspecialthing
{
int one;
int two;
int three;
};

typedef struct aspecialthing AspecialThing;
*/

// definitions
// typdef for step callback
//typedef void (* tCBF_OnStep) (slight_RotaryEncoder*encObj);
typedef void (* tCBF_OnStep) (byte bState); 

const byte state_UNDEFINED = 0;
const byte state_CW = 1;
const byte state_CCW = 2;
const byte state_HalfStep = 3;

class slight_RotaryEncoder
{
public:
// public methods
//Constructor
slight_RotaryEncoder(byte bPin_A_NewValue, byte bPin_B_NewValue, byte bPulsPerStep_NewValue, tCBF_OnStep cbfOnStep_NewValue);
// bool inverse_logic = false --- the = false means a standard value / makes it optional?

//Destructor
~slight_RotaryEncoder();

//word xYfuncName(word XXX);

// run every loop to update stee of system.
void update();

// get state
byte getState();



private:
// per object data

byte pin_A;
byte pin_B;

byte bPulsPerStep;

tCBF_OnStep cbfOnStep;


//internal data
byte bNr;

boolean bA;
boolean bB;
boolean bA_last;
boolean bB_last;
boolean bLastFullStep;

byte bPulsCount;
byte bState;

unsigned long ulTimeStamp;



//word _blubber;
//AspecialThing _theValues;

// private methods
void test();

void stateChange();
void printState();
};

#endif


slight_RotaryEncoder.cpp
Code:
/**
  * slight_RotaryEncoder.cpp
  * library for easy encoder using
  *
  * copyright (c) 2013 by stefan krueger
  *
  * based on infos and ideas from:
  *  ~ http://www.mikrocontroller.net/articles/Drehgeber
  *  ~ http://www.mikrocontroller.net/topic/drehgeber-auslesen
  *  ~ http://www.mikrocontroller.net/topic/38863
  *  ~ http://hacks.ayars.org/2009/12/using-quadrature-encoder-rotary-switch.html
  *  ~ http://playground.arduino.cc/Main/RotaryEncoders#Waveform
  *
  * whit help from:
  *   pYro_65 ( http://arduino.cc/forum/index.php/topic,162249.0.html )
  *
  * changelog / history:
  *   24.04.2013 08:46 created; based on SwitchPCB_Test_RotaryEncoder_v02
  *
  * to do:
  *   
  **/


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


/**
  * Include yourselfs header file
  **/
#include <slight_RotaryEncoder.h>


/**
  * Constructor
  **/
slight_RotaryEncoder::slight_RotaryEncoder(byte bPin_A_NewValue, byte bPin_B_NewValue, byte bPulsPerStep_NewValue, tCBF_OnStep cbfOnStep_NewValue) {

// initialise variables
pin_A = bPin_A_NewValue;
pin_B = bPin_B_NewValue;
bPulsPerStep = bPulsPerStep_NewValue;
cbfOnStep = cbfOnStep_NewValue;

//debug nr.
bNr = 33;

bA = 0;
bB = 0;
bA_last = 0;
bB_last = 0;
bLastFullStep = 0;
bPulsCount = 0;
bState = state_UNDEFINED;
ulTimeStamp = 0;

// initialise pins
pinMode(pin_A, INPUT_PULLUP);
pinMode(pin_B, INPUT_PULLUP);

}

/**
  * Destructor
  **/
slight_RotaryEncoder::~slight_RotaryEncoder() {
  //
}



/**
  * Public methods
  **/

/*
word slight_RotaryEncoder::xYfuncName(word XXX)
{
  //some code
  result XXX;
}*/


/**
  * Returns State (direction)
  **/
byte slight_RotaryEncoder::getState() {
return bState;
}


/**
  * update
  **/
void slight_RotaryEncoder::update() {

/**
rast punkt immer bei 0,0 oder 1,1
CCW
---- A, B
111: 0, 1
111: 0, 0 !
111: 1, 0
111: 1, 1 !
---- A, B
111: 0, 1
111: 0, 0 !
111: 1, 0
111: 1, 1 !

CW
---- A, B
111: 1, 0
111: 0, 0 !
111: 0, 1
111: 1, 1 !
---- A, B
111: 1, 0
111: 0, 0 !
111: 0, 1
111: 1, 1 !

Error
---- A, B
111: 1, 0
111: 0, 0
111:1
111+1
111: 0, 1
111: 1, 1
111:1
111+1
111: 1, 0
111: 1, 1
111:2 <--Wrong reading!!!
111-1
111: 1, 0
111: 0, 0
111:1
111+1

this reading is wrong.
it is not alowed to have 1,1; 1,0; 1,1

**/

boolean bTemp_A = digitalRead(pin_A);
boolean bTemp_B = digitalRead(pin_B);
if ( (bTemp_A != bA) || (bTemp_B != bB)) {
//status changed.
bA = bTemp_A;
bB = bTemp_B;

/** **
Serial.print(bNr);
Serial.print("?: ");
Serial.print(bA);
Serial.print(", ");
Serial.println(bB);
/** **/

// half step; save state of encoder pins for direction check
if (bA != bB) {
bA_last = bA;
bB_last = bB;
bState = state_HalfStep;
stateChange();
} else {
// full step; one step is finished. --> This is Only true if the last full step was not the same level (high or low)
if ( (bA == bB) && (bA != bLastFullStep) ) {
//remember LastFullStep (error correction)
bLastFullStep = bA;
// Encoder turns CW
if (bA == bB_last)  {
//Do Something
bState = state_CW;
stateChange();
} else {
// Encoder turns CCW
if (bB == bA_last)  {
bState = state_CCW;
stateChange();
}
}
}
}
}



}



/**
  * Private methods
  **/
/*
void slight_RotaryEncoder::test()
{
_blubber = _blubber + 1;
}*/

void slight_RotaryEncoder::stateChange() {

if ( (bState == state_CW) || (bState == state_CCW) ) {
if (bPulsCount >= bPulsPerStep) {
// One Step for the User
bPulsCount = 0;

/** DEBUG OUT **/
Serial.print(bNr);
Serial.print(": ");
printState();
Serial.println();
/** **/

/**  RUN CALLBACK Function: **/
cbfOnStep(bState);
} else {
bPulsCount = bPulsCount + 1;
}
}





}

void slight_RotaryEncoder::printState() {
switch (bState)
{
case state_UNDEFINED: {
Serial.print("state_UNDEFINED");
break;
}
case state_CW: {
Serial.print("state_CW   +1");
break;
}
case state_CCW: {
Serial.print("state_CCW  -1");
break;
}
case state_HalfStep: {
Serial.print("state_HalfStep");
break;
}
default: {
Serial.println("??");
}
}
}

/** THE END **/

Thanks for your help!
sunny greetings stefan
Pages: 1 2 [3] 4 5