Compare commits

..

2 commits

Author SHA1 Message Date
boutrie.eytan f99cb0c0bb Code Esclave 2023-06-26 15:10:20 +02:00
boutrie.eytan 3b23142fc1 innit 2023-06-26 15:04:13 +02:00

View file

@ -1,77 +1,66 @@
/* #include <WiFi.h>
* Library: https://github.com/bolderflight/MPU9250 #include <WiFiUdp.h>
Basic_I2C.ino #include <OSCMessage.h>
Brian R Taylor #include <OSCBundle.h>
brian.taylor@bolderflight.com #include <OSCData.h>
char ssid[] = "cohabit"; // your network SSID (name)
char pass[] = "lewifidecohabit"; // your network password
Copyright (c) 2017 Bolder Flight Systems // A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
Permission is hereby granted, free of charge, to any person obtaining a copy of this software const unsigned int localPort = 16403; // local port to listen for UDP packets (here's where we send the packets)
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"
float biai = 1.25;
unsigned long previousTime;
int interval = 300;
int stepPin = 14; int stepPin = 14;
int dirPin = 12; int dirPin = 12;
bool pinState = LOW;
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;
void setup() { void setup()
// serial to display data {
Serial.begin(115200); Serial.begin(115200);
while(!Serial) {} // initialize LED digital pin as an output.
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
// start communication with IMU while (WiFi.status() != WL_CONNECTED) {
status = IMU.begin(); delay(500);
if (status < 0) { Serial.print(".");
Serial.println("IMU initialization unsuccessful"); }
Serial.println("Check IMU wiring or try cycling power"); Serial.println("");
Serial.print("Status: ");
Serial.println(status); Serial.println("WiFi connected");
while(1) {} Serial.println("IP address: ");
} Serial.println(WiFi.localIP());
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT); Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(localPort);
digitalWrite(dirPin, HIGH);
} }
void loop() { void step(OSCMessage &msg) {
// read the sensor switch (msg.getInt(0)) {
digitalWrite(dirPin,HIGH); case 0:
IMU.readSensor(); digitalWrite(stepPin, LOW);
// display the data break;
case 1:
if((micros() - previousTime) >= interval){ digitalWrite(stepPin, HIGH);
previousTime = micros(); break;
pinState = !pinState; }
digitalWrite(stepPin,pinState); }
Serial.println(IMU.getAccelX_mss() + IMU.getAccelY_mss() + IMU.getAccelZ_mss() + biai +11);
} void loop()
{
OSCMessage msg;
int size = Udp.parsePacket();
if (size > 0) {
while (size--) {
msg.fill(Udp.read());
}
//step(msg);
step(msg);
}
} }