mikaelpatel / arduino-gpio Goto Github PK
View Code? Open in Web Editor NEWGeneral Purpose Input/Output (GPIO) library for Arduino
Home Page: https://mikaelpatel.github.io/Arduino-GPIO/
General Purpose Input/Output (GPIO) library for Arduino
Home Page: https://mikaelpatel.github.io/Arduino-GPIO/
The definition of the "toggle()" function in the file "Hardware/AVR/GPIO.h" uses the "|=" assignment .. shouldn't it use "^=" to achieve the actual "toggle" effect?
Hey! Use your library for my project, and all works fine with different stepper drivers.
Now with TB67S109AFTG nothing works.
When I add default code with DigitalWhrite all works. And with this library not. Seems like pin not make fully 0v of 5v and this drivers are sensitive for this.
For my old drivers declare pin types in init was ok:
StepMotor() {
stepPin.output();
dirPin.output();
enPin.output();
}
And for this one I must declare them in setup with pinMode:
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
Then they work, but really badly: hold torque in half power, can don't listen for dir pin etc.
Attach my code:
// StepMotor.h
#ifndef StepMotor_h
#define StepMotor_h
#include "GPIO.h"
template<BOARD::pin_t STEP_PIN, BOARD::pin_t DIR_PIN, BOARD::pin_t EN_PIN>
class StepMotor {
public:
StepMotor() {
stepPin.output();
dirPin.output();
enPin.output();
}
void runForward(int stepInterval, int dis) {
runMotor(LOW, stepInterval, dis);
}
void runBack(int stepInterval, int dis){
runMotor(HIGH, stepInterval, dis);
}
void runForeverWithAcceleration(bool dir, int startStepInterval, int endStepInterval) {
enPin = LOW;
dirPin = dir;
if (currentInterval == 0) {
currentInterval = startStepInterval;
}
if (micros() - previousMillis >= currentInterval) {
stepPin.toggle();
if (endStepInterval <= currentInterval){
currentInterval -= 20;
}
previousMillis = micros();
}
}
void resetCurrentInterval() {
currentInterval = 0;
}
void runForever(bool dir, int stepInterval) {
enPin = LOW;
dirPin = dir;
if (micros() - previousMillis >= stepInterval) {
stepPin.toggle();
previousMillis = micros();
}
}
void setCurrentDisToZero() {
currentDis = 0;
}
void setCurrentDisToMax() {
currentDis = 31000;
}
void setCurrentDis(int value) {
currentDis = value;
}
void activate(bool value = LOW) {
enPin = value;
}
void deactivate() {
enPin = HIGH;
}
int getCurrentDis(){
return currentDis;
}
bool isRunToDis(int dis){
return currentDis >= dis;
}
private:
unsigned long previousMillis = 0;
int currentDis = 0;
int currentInterval = 0;
void runMotor(bool dir, int stepInterval, int dis) {
enPin = LOW;
dirPin = dir;
if (micros() - previousMillis >= stepInterval && currentDis < dis) {
stepPin.toggle();
++currentDis;
previousMillis = micros();
}
}
protected:
GPIO<STEP_PIN> stepPin;
GPIO<DIR_PIN> dirPin;
GPIO<EN_PIN> enPin;
};
#endif
Use @tparam for template class parameters.
Hello.
I've tried to write Blink without Arduino IDE. Found problems:
Many Thanks
Since this is a class, why no unit tests? Would be nice to be able to mock this up and unit test code against it.
Noob to ATtiny micros.
I have Arduino IDE 1.8.4 installed as well as ATTinyCore and am using a ATtiny84A micro.
I downloaded this library and added it to the IDE.
I click File->Examples->Arduino-GPIO->ATtiny->Blink
When I go to compile the example, I get the following errors:
Arduino: 1.8.4 (Windows 10), Board: "ATtiny24/44/84, Disabled, ATtiny84, 8 MHz (internal), EEPROM retained, B.O.D. Disabled, Clockwise (like damellis core)"
In file included from C:\Users\Boompy\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\cores\tiny/Arduino.h:165:0,
from sketch\Blink.ino.cpp:1:
C:\Users\Boompy\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\variants\tinyX4_reverse/pins_arduino.h:44:14: error: expected identifier before numeric constant
#define SS 3
^
C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/Hardware/AVR/Board.h:393:5: note: in expansion of macro 'SS'
SS = D3, //!< SPI Slave Select
^
C:\Users\Boompy\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\variants\tinyX4_reverse/pins_arduino.h:44:14: error: expected '}' before numeric constant
#define SS 3
^
C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/Hardware/AVR/Board.h:393:5: note: in expansion of macro 'SS'
SS = D3, //!< SPI Slave Select
^
C:\Users\Boompy\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.1.5\variants\tinyX4_reverse/pins_arduino.h:44:14: error: expected unqualified-id before numeric constant
#define SS 3
^
C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/Hardware/AVR/Board.h:393:5: note: in expansion of macro 'SS'
SS = D3, //!< SPI Slave Select
^
In file included from C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/Hardware/AVR/GPIO.h:22:0,
from C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/GPIO.h:22,
from C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\examples\ATtiny\Blink\Blink.ino:1:
C:\Users\Boompy\Documents\Arduino\libraries\Arduino-GPIO-master\src/Hardware/AVR/Board.h:398:1: error: expected declaration before '}' token
};
^
exit status 1
Error compiling for board ATtiny24/44/84.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
```
Seems like your library is fighting with ATtiny core... I suspect your library uses the same #define symbols (e.g. "SS") as ATtiny core. Not sure how to proceed. Can you recommend a course of action?
Ultimately, I would like to start using the Arduino-OWI library, but since this is a prerequisite I need to get this working first I think
Replace the GPIO board pin symbols with Arduino core pin numbering (i.e. positive integers).
Hello,
first of all: Thank you for the great work.
This makes programming so much easier and more efficient.
I have a problem with the button class. I tried to turn on the board led by pressing a button and turning it off when releasing.
The led stays on all the time...
#include "GPIO.h"
#include "Button.h"
GPIOBOARD::D13 led;
ButtonBOARD::D5 button;
void setup()
{
led.output();
}
void loop()
{
if(button) {
led=1;
}
else
{
led=0;
}
}
AVR ATmega2560 based boards are currently not support. Access to ports with higher io port address need synchronized access. They do not compile to single instructions and thus not atomic. GPIO member function need to be atomic even for these.
To me it seems like an obvious error that the return value of millis() is stored in a 16 bit variable when the return value actually is 32 bits. This will lead to wrong behavior when it overflows.
Add board definition for the ATtiny core (ATtinyX4 and ATtinyX5).
I use Eclipse Sloeber IDE and opening up file 'Hardware/AVR/GPIO.h' I noticed some unresolved symbols and functions at lines 36, 39, 170, 175 and 211.
To fix, I placed '#include "Arduino.h" so it will resolve symbols.
Am I correct in thinking that this include should be included ?
Many thanks for your work on great code.
Paul - VK7KPA
Make it easier for implementations to follow interface changes. Also collect interface documentation in one place.
E.g. GPIO.h should contain the interface and included the correct target implementation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.