init repo
This commit is contained in:
commit
1d7cc722ae
6 changed files with 315 additions and 0 deletions
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# esp32 teddy
|
39
include/README
Normal file
39
include/README
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Normal file
46
lib/README
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
24
platformio.ini
Normal file
24
platformio.ini
Normal file
|
@ -0,0 +1,24 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32dev]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
board_build.f_cpu = 240000000L
|
||||
board_build.f_flash = 80000000L
|
||||
board_build.flash_mode = qio
|
||||
board_build.partitions = huge_app.csv
|
||||
lib_deps =
|
||||
cnmat/OSC
|
||||
hideakitai/MPU9250
|
||||
paulstoffregen/OneWire
|
||||
milesburton/DallasTemperature
|
194
src/main.cpp
Normal file
194
src/main.cpp
Normal file
|
@ -0,0 +1,194 @@
|
|||
#include "Arduino.h"
|
||||
#include "MPU9250.h"
|
||||
#include "WiFi.h"
|
||||
#include "WiFiUdp.h"
|
||||
#include "OSCBundle.h"
|
||||
|
||||
// SCL Pin is 22
|
||||
// SDA PIN is 21
|
||||
|
||||
#define BL_ON 0
|
||||
|
||||
#if BL_ON
|
||||
#include "BLEDevice.h"
|
||||
#include "BLEScan.h"
|
||||
|
||||
// bluetooth name
|
||||
#define blName "Teddy"
|
||||
#endif
|
||||
|
||||
// WiFi stuff
|
||||
#define ssid ""
|
||||
#define pwd ""
|
||||
|
||||
// OSC
|
||||
#define host "192.168.21.232"
|
||||
#define port 3030
|
||||
|
||||
#define oneWireBus 18
|
||||
|
||||
WiFiUDP Udp;
|
||||
MPU9250 mpu;
|
||||
|
||||
|
||||
|
||||
|
||||
float ypr[3];
|
||||
float acc[3];
|
||||
int pr;
|
||||
const float threshold = 0.7;
|
||||
const int thresholdP = 50;
|
||||
|
||||
void set_calibration() {
|
||||
mpu.setAccBias(232.00, 89.60, -581.30);
|
||||
mpu.setGyroBias(14.80, 95.80, 23.00);
|
||||
mpu.setMagBias(284.65, -333.85, 91.40);
|
||||
mpu.setMagScale(0.59, 1.39, 1.68);
|
||||
}
|
||||
|
||||
void get_calibration() {
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Accel Gyro calibration will start in 5sec.");
|
||||
Serial.println("Please leave the device still on the flat plane.");
|
||||
mpu.verbose(true);
|
||||
delay(5000);
|
||||
mpu.calibrateAccelGyro();
|
||||
Serial.println();
|
||||
|
||||
Serial.println("Mag calibration will start in 5sec.");
|
||||
Serial.println("Please Wave device in a figure eight until done.");
|
||||
delay(5000);
|
||||
mpu.calibrateMag();
|
||||
Serial.println();
|
||||
|
||||
Serial.println("< calibration parameters >");
|
||||
Serial.println("accel bias [g]: ");
|
||||
Serial.print(mpu.getAccBiasX());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getAccBiasY());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getAccBiasZ());
|
||||
Serial.println();
|
||||
Serial.println("gyro bias [deg/s]: ");
|
||||
Serial.print(mpu.getGyroBiasX());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getGyroBiasY());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getGyroBiasZ());
|
||||
Serial.println();
|
||||
Serial.println("mag bias [mG]: ");
|
||||
Serial.print(mpu.getMagBiasX());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getMagBiasY());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getMagBiasZ());
|
||||
Serial.println();
|
||||
Serial.println("mag scale []: ");
|
||||
Serial.print(mpu.getMagScaleX());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getMagScaleY());
|
||||
Serial.print(", ");
|
||||
Serial.print(mpu.getMagScaleZ());
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
mpu.verbose(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(500);
|
||||
Wire.begin();
|
||||
delay(500);
|
||||
|
||||
if (!mpu.setup(0x68)) { // change to your own address
|
||||
while (1) {
|
||||
Serial.println("MPU failed");
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
|
||||
set_calibration();
|
||||
//get_calibration();
|
||||
ypr[0] = mpu.getYaw();
|
||||
ypr[1] = mpu.getPitch();
|
||||
ypr[2] = mpu.getRoll();
|
||||
|
||||
acc[0] = mpu.getAccX();
|
||||
acc[1] = mpu.getAccY();
|
||||
acc[2] = mpu.getAccZ();
|
||||
|
||||
pr = 0;
|
||||
|
||||
// connecting to a WiFi network
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.begin(ssid, pwd);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.print("WiFi connected, IP = ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
#if BL_ON
|
||||
BLEDevice::init(blName);
|
||||
#endif
|
||||
|
||||
Udp.begin(9000);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
float yprNew[3];
|
||||
float accNew[3];
|
||||
bool send = false;
|
||||
|
||||
if (mpu.update()) {
|
||||
yprNew[0] = mpu.getYaw();
|
||||
yprNew[1] = mpu.getPitch();
|
||||
yprNew[2] = mpu.getRoll();
|
||||
accNew[0] = mpu.getAccX();
|
||||
accNew[1] = mpu.getAccY();
|
||||
accNew[2] = mpu.getAccZ();
|
||||
}
|
||||
for(int i = 0; i < 3; i++){
|
||||
if (abs(ypr[i] - yprNew[i]) > threshold){ send = true;}
|
||||
if (abs(acc[i] - accNew[i]) > threshold){ send = true;}
|
||||
}
|
||||
if(send == true){
|
||||
OSCBundle bundle;
|
||||
bundle.add("/teddy/acc").add(acc[0]).add(acc[1]).add(acc[2]);
|
||||
bundle.add("/teddy/abs/acc").add(abs(acc[0])).add(abs(acc[1])).add(abs(acc[2]));
|
||||
//bundle.add("/teddy/ypr").add(ypr[0]).add(ypr[1]).add(ypr[2]);
|
||||
bundle.add("/teddy/abs/ypr").add(abs(ypr[0])).add(abs(ypr[1])).add(abs(ypr[2]));
|
||||
|
||||
Udp.beginPacket(host, port);
|
||||
bundle.send(Udp);
|
||||
Udp.endPacket();
|
||||
bundle.empty();
|
||||
}
|
||||
for(int i = 0; i < 3; i++){
|
||||
ypr[i] = yprNew[i];
|
||||
acc[i] = accNew[i];
|
||||
}
|
||||
|
||||
int prNew = analogRead(39);
|
||||
if (abs(pr-prNew) > thresholdP){
|
||||
OSCMessage msg("/teddy/druck");
|
||||
msg.add(prNew);
|
||||
Udp.beginPacket(host, port);
|
||||
msg.send(Udp);
|
||||
Udp.endPacket();
|
||||
pr = prNew;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
||||
}
|
||||
|
11
test/README
Normal file
11
test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
Loading…
Reference in a new issue