digitalWriteFast library

hey,

I wanted to use the command digitalReadFast in order to get better results from my rotation encoder, but after I downloaded the zip file of the library from here:Google Code Archive - Long-term storage for Google Code Project Hosting. the dwf file, I tryed to add it to arduino then wrote the comman attach and the read comman but from some reaon it is not compiling.

please help me.

thanks.

Can you paste your code.
And use Link tag to attach the link
https://code.google.com/p/digitalwritefast/downloads/list

hey , ok here is code and I will use link next time,thanks

 #include <digitalWriteFast>
 int val; 
 int encoder0PinA = 3;
 int encoder0PinB = 2;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;

 void setup() { 
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   Serial.begin (9600);
 } 

 void loop() { 
   delay(1);
   n = digitalReadFast(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalReadFast(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
        if (encoder0Pos >=360)  {encoder0Pos=encoder0Pos-360;}
                if (encoder0Pos <=0)  {encoder0Pos=encoder0Pos+360;}

     Serial.print (encoder0Pos);
     Serial.println ("  degrees");
   } 
   encoder0PinALast = n;
 }

Which board your using For coding??

arduino uno

from some reaon it is not compiling.

Please post the text of the error message.

Unless your encoder is high resolution/speed you don't really need to use fast read. Your problem is probably due to you calling the routine to quickly. Try increasing the delay from 1 to about 10 or 20.
If it is a high resolution/speed encoder then you would be better off using interrupts.

Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

sketch_may28d.ino: In function 'void loop()':
sketch_may28d:19: error: 'digitalReadFast' was not declared in this scope

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

I don't know much about interupts to be honest, can you explain me abit or giveme good starting link?

thanks

sketch_may28d:19: error: 'digitalReadFast' was not declared in this scope

It looks like the library is not installed properly or that the IDE was was not stopped and restarted after the library was installed.

Which library do you want to use ? digitalReadFast or digitalWriteFast ?

Is the library installed and if so, where (exactly) ?

What rotary encoder are you interfacing to and how is it wired up. Usually pins A & B need pullup resistors and pin C is to ground.

This compiled for me but is obviously untested.

 #include <digitalWriteFast.h>
 int val; 
 int encoder0PinA = 3;
 int encoder0PinB = 2;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;

 void setup() { 
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   Serial.begin (9600);
 } 

 void loop() { 
   delay(1);
   n = digitalReadFast2(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalReadFast2(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
        if (encoder0Pos >=360)  {encoder0Pos=encoder0Pos-360;}
                if (encoder0Pos <=0)  {encoder0Pos=encoder0Pos+360;}

     Serial.print (encoder0Pos);
     Serial.println ("  degrees");
   } 
   encoder0PinALast = n;
 }

I read that digitalreadfast is function in digitalwritefast library so I tryed using it i downloaded the zip and used sketch>import library.

pin a and b I conected to digital 2,3.

projectsira:
pin a and b I conected to digital 2,3.

With pull-up resistors?

no

Got the library from here: https://code.google.com/p/digitalwritefast/downloads/list

Renamed the demo code digitalWriteFastTestUno from pde to ino

Tried to compile. No changes anywhere. So many errors it overflowed the window. Here's some of them. They repeat over and over. Would really like to have digitalWriteFast working.

^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:153:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1256:1: note: in expansion of macro 'pinModeFast2'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:153:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1262:1: note: in expansion of macro 'pinModeFast2'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:153:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1264:1: note: in expansion of macro 'pinModeFast2'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:153:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1269:1: note: in expansion of macro 'pinModeFast2'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:153:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1271:1: note: in expansion of macro 'pinModeFast2'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:113:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1277:1: note: in expansion of macro 'digitalWriteFast'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:113:35: note: in expansion of macro 'digitalPinToTimer'
bitClear(digitalPinToTimer(P), digitalPinToTimerBit(P));
^
digitalWriteFastTestUno.ino:1279:1: note: in expansion of macro 'digitalWriteFast'
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:171:80: error: invalid type argument of unary '
' (have 'uint8_t {aka unsigned char}')
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
^
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:105:32: note: in definition of macro 'bitClear'
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
^
C:\Program Files (x86)\Arduino\libraries\digitalWriteFast/digitalWriteFast.h:134:34: note: in expansion of macro 'digitalPinToTimer'
bitClear(*digitalPinToTimer(P), digitalPinToTimerBit(P)) ,
^

Hi,

I've got the library from here:

It clearly says it's compatible with Arduino Due.
Does anyone have any ideea why it throws "#error Non-AVR device, unsupported." at compile?

Thanks!

davidk_ro:
It clearly says it's compatible with Arduino Due.

It does.

But when you look at the code in the .h file it does not seem to be compatible with the Due.

I have been using the version at GitHub - watterott/Arduino-Libs: Arduino Libs & Examples: ADS1147, ADS7846, DAC8760, DS1307, RV8523, MCP2515, WS2812, S65-Display, MI0283QT-2/-9/-11, HX8347D, ILI9341, SSD1331 and it does not look like it would produce that error. However it looks as if it just uses the regular digitalWrite() for a non-AVR board.

I don't have a Due.

...R

Not to presume too much, but doesn't this make speed futile?

   delay(1);

aarg:
Not to presume too much, but doesn't this make speed futile?

   delay(1);

Where is that?

...R

void loop() {
   delay(1);
...