Compare commits
No commits in common. "Maître" and "main" have entirely different histories.
151
Rotabator.ino
151
Rotabator.ino
|
@ -1,96 +1,77 @@
|
||||||
#if defined(ESP8266)
|
/*
|
||||||
#include <ESP8266WiFi.h>
|
* Library: https://github.com/bolderflight/MPU9250
|
||||||
|
Basic_I2C.ino
|
||||||
|
Brian R Taylor
|
||||||
|
brian.taylor@bolderflight.com
|
||||||
|
|
||||||
|
Copyright (c) 2017 Bolder Flight Systems
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||||
|
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||||
|
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||||
|
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Updated by Ahmad Shamshiri on July 09, 2018 for Robojax.com
|
||||||
|
* in Ajax, Ontario, Canada
|
||||||
|
* watch instrucion video for this code:
|
||||||
|
For this sketch you need to connect:
|
||||||
|
VCC to 5V and GND to GND of Arduino
|
||||||
|
SDA to A4 and SCL to A5
|
||||||
|
|
||||||
|
S20A is 3.3V voltage regulator MIC5205-3.3BM5
|
||||||
|
*/
|
||||||
|
|
||||||
#include "MPU9250.h"
|
#include "MPU9250.h"
|
||||||
#else
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <OSCMessage.h>
|
|
||||||
|
|
||||||
char ssid[] = "cohabit"; // your network SSID (name)
|
float biai = 1.25;
|
||||||
char pass[] = "lewifidecohabit"; // your network password
|
unsigned long previousTime;
|
||||||
|
int interval = 300;
|
||||||
int update_rate = 1000000;
|
int stepPin = 14;
|
||||||
|
int dirPin = 12;
|
||||||
|
bool pinState = LOW;
|
||||||
WiFiUDP Udp;
|
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
|
||||||
// A UDP instance to let us send and receive packets over UDP
|
MPU9250 IMU(Wire,0x68);
|
||||||
const IPAddress outIp(192, 168, 0, 210); // remote IP of your computer
|
int status;
|
||||||
const unsigned int outPort = 16403; // remote port to receive OSC
|
|
||||||
const unsigned int localPort = 16384; // local port to listen for OSC packets (actually not used for sending)
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// serial to display data
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
while(!Serial) {}
|
||||||
|
|
||||||
// Connect to WiFi network
|
// start communication with IMU
|
||||||
Serial.println();
|
status = IMU.begin();
|
||||||
Serial.println();
|
if (status < 0) {
|
||||||
Serial.print("Connecting to ");
|
Serial.println("IMU initialization unsuccessful");
|
||||||
Serial.println(ssid);
|
Serial.println("Check IMU wiring or try cycling power");
|
||||||
WiFi.begin(ssid, pass);
|
Serial.print("Status: ");
|
||||||
|
Serial.println(status);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while(1) {}
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
Serial.println("");
|
|
||||||
|
|
||||||
Serial.println("WiFi connected");
|
|
||||||
Serial.println("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
Serial.println("Starting UDP");
|
|
||||||
Udp.begin(localPort);
|
|
||||||
Serial.print("Local port: ");
|
|
||||||
#ifdef ESP32
|
|
||||||
Serial.println(localPort);
|
|
||||||
#else
|
|
||||||
Serial.println(Udp.localPort());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
void ledtoggle(OSCMessage &msg) {
|
|
||||||
switch (msg.getInt(0)) {
|
|
||||||
case 0:
|
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void receiveMessage() {
|
|
||||||
OSCMessage inmsg;
|
|
||||||
int size = Udp.parsePacket();
|
|
||||||
|
|
||||||
if (size > 0) {
|
|
||||||
while (size--) {
|
|
||||||
inmsg.fill(Udp.read());
|
|
||||||
}
|
|
||||||
if (!inmsg.hasError()) {
|
|
||||||
inmsg.dispatch("/led", ledtoggle);
|
|
||||||
}
|
|
||||||
//else { auto error = inmsg.getError(); }
|
|
||||||
}
|
}
|
||||||
|
pinMode(stepPin,OUTPUT);
|
||||||
|
pinMode(dirPin,OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
receiveMessage();
|
// read the sensor
|
||||||
OSCMessage msg("/step");
|
digitalWrite(dirPin,HIGH);
|
||||||
msg.add(1);
|
IMU.readSensor();
|
||||||
Udp.beginPacket(outIp, outPort);
|
// display the data
|
||||||
msg.send(Udp);
|
|
||||||
Udp.endPacket();
|
|
||||||
msg.empty();
|
|
||||||
delayMicroseconds(update_rate);
|
|
||||||
OSCMessage msg2("/Step");
|
|
||||||
msg2.add(0);
|
|
||||||
Udp.beginPacket(outIp, outPort);
|
|
||||||
msg2.send(Udp);
|
|
||||||
Udp.endPacket();
|
|
||||||
msg2.empty();
|
|
||||||
delayMicroseconds(update_rate);
|
|
||||||
|
|
||||||
|
|
||||||
|
if((micros() - previousTime) >= interval){
|
||||||
}
|
previousTime = micros();
|
||||||
|
pinState = !pinState;
|
||||||
|
digitalWrite(stepPin,pinState);
|
||||||
|
Serial.println(IMU.getAccelX_mss() + IMU.getAccelY_mss() + IMU.getAccelZ_mss() + biai +11);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue