Comments (27)
i forgot to enable swire in the examples uncomment the #define swire in the demo
#ifdef SWIRE
sensor.begin(A3,A4);
#else
Wire.begin();
#endif
from gy521.
oopd forgot this part b705d0f
from gy521.
updated hopefully its working 100%
from gy521.
It looks like you did not copy the latest version, at least not for all files.
saw you used swire instead of Wire
Can you explain the differences?
OK it is a software I2C I get it.
from gy521.
Interesting code,
however a "rewrite" of the library should not be needed.
It should be possible to create an softWire object and just give it to the constructor of the GY521 class.
maybe the software Wire should derive from TwoWire to make it match?
Something like
//
// FILE: test1.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: minimal demo
// DATE: 2020-07-01
#include "GY521.h"
#include "SWire.h"
SoftWire myWire; // create software wire object
GY521 sensor(0x68, (TwoWire *) & myWire); // <<<<<<<<<< this is the critical part
uint32_t counter = 0;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
myWire.begin(4, 5);
delay(100);
while (sensor.wakeup() == false)
{
Serial.print(millis());
Serial.println("\tCould not connect to GY521");
delay(1000);
}
sensor.setAccelSensitivity(0); // 2g
sensor.setGyroSensitivity(0); // 250 degrees/s
sensor.setThrottle();
Serial.println("start...");
// set callibration values from calibration sketch.
sensor.axe = 0;
sensor.aye = 0;
sensor.aze = 0;
sensor.gxe = 0;
sensor.gye = 0;
sensor.gze = 0;
}
void loop()
{
sensor.read();
int ax = sensor.getAccelX();
int ay = sensor.getAccelY();
int az = sensor.getAccelZ();
int gx = sensor.getGyroX();
int gy = sensor.getGyroY();
int gz = sensor.getGyroZ();
int t = sensor.getTemperature();
if (counter % 10 == 0)
{
Serial.println("\n\tACCELEROMETER\t\tGYROSCOPE\t\tTEMPERATURE");
Serial.println("\tax\tay\taz\tgx\tgy\tgz\tT");
}
Serial.print(counter);
Serial.print('\t');
Serial.print(ax);
Serial.print('\t');
Serial.print(ay);
Serial.print('\t');
Serial.print(az);
Serial.print('\t');
Serial.print(gx);
Serial.print('\t');
Serial.print(gy);
Serial.print('\t');
Serial.print(gz);
Serial.print('\t');
Serial.print(t);
Serial.println();
counter++;
delay(1000);
}
from gy521.
Had a quick look at the softWire library and it has a pretty clean setup, well done.
Some things popped my mind
in the .h file you could use #pragma once
instead of the ifdef .../endif construct.
Compiler just needs to read one line instead of the whole .h file.
There are some functions like beginTransmission that appear twice, one with and one without parameter.
C++ allows default parameters for functions.
uint8_t beginTransmission(bool shouldstop = true)
Several functions are oneliners - you might add the inline keyword so the compiler can optimize call stack.
(in fact I hope most compilers will recognize these oneliners themselves)
Think I would add pin parameters to the constructor too.
Constructor should set the SDA and SCL in a defined initial condition.
(e.g. floating lines can trigger sensors or devices like the PCF8574 in an unexpected way)
The Wire lib has a function called setClock() https://www.arduino.cc/en/Reference/WireSetClock
Would be nice if the speed could be tuned, e.g. long wires typically need lower frequency
And recently I created a library for a sensor that needed only 30 kHz.
Did you do performance tests with the library?
from gy521.
a freelancer is working with it now to build a virtual reality glove for my project https://github.com/netpipe/HappyHands we should be able to see it working soon, I'm glad you kept working on it because we bumped into issues from 0.2.3 :) you are welcome to the changes for the main repo if you like.
from gy521.
you are welcome to the changes for the main repo if you like.
If time permits I might (maybe now winter is coming)
unfortunately the libraries are one big repo. I had that too in the past, and it became unmanageable in practice.-
I'm glad you kept working on it ...
Yes, I try to keep bugs out of my libs and features and performance in, with 100+ libraries under support issues still come in regularly. Sometimes bugs pop up under specific use, hard to recreate. Especially Heisenbugs, they only appear if you do not look, right after a 4 hour debugging session or so.
Coming time I will spend time to visualize CI-build results (under actions) and add support of build process for ESP32. Especially the latter I expect it will expose some weak code parts. At least this helps to keep code quality at a "certain level"
Is there functionality missing in the GY521 library for you?
Or any other lib?
from gy521.
BTW, are you familiar with https://github.com/Testato/SoftwareWire ?
from gy521.
BTW, are you familiar with https://github.com/Testato/SoftwareWire ?
i have used the library previously and it works fine !!
BTW i am the freelancer working on the VR glove (https://github.com/netpipe/HappyHands) as mentioned by @netpipe
Really interesting project and progress so far is good.
hope to finish by weekend !!
from gy521.
i have this working at 2.3 , going to update it a bit. found that newer swire was giving issues.
from gy521.
updated example
from gy521.
from gy521.
i have this working at 2.3 , going to update it a bit. found that newer swire was giving issues.
Note that the last library released is 0.3.4 and that 0.3.5 is under development
from gy521.
the newestfixed version is all the new code you had basically copy and pasted in without the updated comments. the main changes was getting rid of the micros() and changing it back to milis to make it work properly.
from gy521.
if you like i can make a fork and put it all in for you with a pull request ?
from gy521.
if you like i can make a fork and put it all in for you with a pull request ?
Yes that is preferred, than it is easier for me to analyse your changes and if and how they affect the library.
from gy521.
I need to merge #29 before you should fork as the build-CI is broken and I need to fix that first.
This PR will also update the begin() function to include a wakeup() call - see #28
from gy521.
from gy521.
GY521-SWIRE.zip here is an updated swire branch my other repo has a better copy still though.
from gy521.
Installed the GY521-SWIRE.zip as GY521 library (moved mine) , and my existing code that does not use SWire breaks.
That should not happen.
C:\Users\Rob\Desktop\GY521___\examples\GY521_performance\GY521_performance.ino: In function 'void setup()':
GY521_performance:22:3: error: 'Wire' was not declared in this scope
Wire.begin();
^~~~
C:\Users\Rob\Desktop\GY521___\examples\GY521_performance\GY521_performance.ino:22:3: note: suggested alternative: 'SWire'
Wire.begin();
^~~~
SWire
from gy521.
With swire you have to replace all instances of wire to swire
from gy521.
That is not acceptable as when I have a system with 2 busses, one SWire and one hardware Wire I cannot configure the library to handle both.
With the dependency injection, giving the right wire object as parameter this does work.
So you should make your SWire library derived from the TwoWire class and then you can just "inject" it.
from gy521.
There are at least 2 other software I2C libraries.
If those would be embedded in the same way into the library GY521 would become much harder to maintain.
Furthermore it would introduce a compile time dependency while my solution has the dependencies only runtime,
from gy521.
i forgot to enable swire in the examples uncomment the #define swire in the demo
It is not the examples I worry about, it is about the real projects people have made with the library.
from gy521.
If you derive swire from TwoWire, you can injcect the dependency runtime. Not only in this library but in many more.
you have written most functions already, so I would propose you investigate that path.
from gy521.
I close this issue as I will not integrate the current swire solution in the library.
When an Twowire derived SWire class is available, I might have time to test it.
from gy521.
Related Issues (20)
- Elaborate unit tests
- Examples use GetAngle instead of GetAccel HOT 2
- Enabling the interruptions HOT 6
- Calibration never zeros out HOT 7
- Add multiWire support
- improve performance + precision
- improve precision HOT 1
- Invalid data without Reset while initializing the begin HOT 9
- version number incorrect in .h and .cpp (minor)
- getting position from distance = acceleration * time HOT 7
- Raw data HOT 1
- getYaw, getPitch and getRoll go past 360 degrees HOT 19
- small bugfix in readCalibration HOT 3
- How can I get data from 2 sensors? HOT 4
- Shifted pitch and yaw measurement HOT 19
- why when I run the GY521_pitch_roll_yaw example code, all the numbers slowly increase 0 -> 359 -> 0? HOT 22
- use float variables in example GY521_test_1.ino HOT 1
- refactor GY521_readCalibration_2 (generate calibration code snippet) into a proper calibrate() function, as part of GY521 init HOT 9
- getRegister can return an error which is not handled properly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gy521.