Skip to content

Commit

Permalink
use software I2C, apply PR tockn#30
Browse files Browse the repository at this point in the history
Change code to use software I2C to improve stability;
PR#30: Update header to use forward declaration for SoftWire and move SoftWire.h to .cpp file
  • Loading branch information
Yury Starkov committed Aug 29, 2019
1 parent 89ffd68 commit 73c232c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/MPU6050_tockn.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "MPU6050_tockn.h"
#include "Arduino.h"
#include "SoftWire.h"

MPU6050::MPU6050(TwoWire &w){
MPU6050::MPU6050(SoftWire &w){
wire = &w;
accCoef = 0.02f;
gyroCoef = 0.98f;
}

MPU6050::MPU6050(TwoWire &w, float aC, float gC){
MPU6050::MPU6050(SoftWire &w, float aC, float gC){
wire = &w;
accCoef = aC;
gyroCoef = gC;
Expand Down
9 changes: 5 additions & 4 deletions src/MPU6050_tockn.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define MPU6050_TOCKN_H

#include "Arduino.h"
#include "Wire.h"

#define MPU6050_ADDR 0x68
#define MPU6050_SMPLRT_DIV 0x19
Expand All @@ -14,11 +13,13 @@
#define MPU6050_TEMP_H 0x41
#define MPU6050_TEMP_L 0x42

class SoftWire;

class MPU6050{
public:

MPU6050(TwoWire &w);
MPU6050(TwoWire &w, float aC, float gC);
MPU6050(SoftWire &w);
MPU6050(SoftWire &w, float aC, float gC);

void begin();

Expand Down Expand Up @@ -68,7 +69,7 @@ class MPU6050{

private:

TwoWire *wire;
SoftWire *wire;

int16_t rawAccX, rawAccY, rawAccZ, rawTemp,
rawGyroX, rawGyroY, rawGyroZ;
Expand Down

0 comments on commit 73c232c

Please sign in to comment.