-
Notifications
You must be signed in to change notification settings - Fork 0
/
WSN_R.ino
63 lines (51 loc) · 1.48 KB
/
WSN_R.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Speed Transmitter Right
#include "HX711.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <HX711.h>
#include <Wire.h>
#include <MPU6050.h>
#define calibration_factor 38800 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 3
MPU6050 mpu;
RF24 radio(8, 7);
//----------------------------------
const uint64_t pipe2 = 0xF0F0F0F066;
struct sensor
{
int force;
int angle;
byte sensorNum;
};
sensor pole;
HX711 scale;
void setup() {
Serial.begin(250000);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(1600); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
radio.begin();
radio.openWritingPipe(pipe2);
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
pole.sensorNum = 2;
delay(1000);
}
void loop() {
Vector normAccel = mpu.readNormalizeAccel();
pole.force = scale.get_units();
pole.angle = -(atan2(normAccel.XAxis, sqrt(normAccel.YAxis*normAccel.YAxis + normAccel.ZAxis*normAccel.ZAxis))*180.0)/M_PI;;
Serial.print(pole.force);
Serial.print(", ");
Serial.println(pole.angle);
radio.write(&pole, sizeof(pole));
//delay(10);
}