added port scan
This commit is contained in:
@@ -19,6 +19,7 @@ lib_deps =
|
||||
arduino-libraries/Arduino_JSON@^0.1.0
|
||||
adafruit/Adafruit MMC56x3@^1.0.1
|
||||
ayushsharma82/ElegantOTA@^3.1.0
|
||||
invensenseinc/ICM42670P@^1.0.0
|
||||
board_build.partitions = partitions.csv
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -37,6 +38,7 @@ lib_deps =
|
||||
arduino-libraries/Arduino_JSON@^0.2.0
|
||||
adafruit/Adafruit MMC56x3@^1.0.1
|
||||
ayushsharma82/AsyncElegantOTA@^2.2.7
|
||||
invensenseinc/ICM42670P@^1.0.0
|
||||
build_flags =
|
||||
'-D ARDUINO_USB_MODE=0'
|
||||
'-D ARDUINO_USB_CDC_ON_BOOT=1'
|
||||
|
||||
102
src/main.cpp
102
src/main.cpp
@@ -17,7 +17,8 @@
|
||||
#include <Arduino_JSON.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BusIO_Register.h>
|
||||
#include <Adafruit_MMC56x3.h>
|
||||
// #include <Adafruit_MMC56x3.h>
|
||||
#include <ICM42670P.h>
|
||||
|
||||
|
||||
#include <Preferences.h>
|
||||
@@ -26,7 +27,10 @@ Preferences settings;
|
||||
#define LED_PIN 2
|
||||
|
||||
/* Assign a unique ID to this sensor at the same time */
|
||||
Adafruit_MMC5603 mag = Adafruit_MMC5603(12345);
|
||||
// Adafruit_MMC5603 mag = Adafruit_MMC5603(12345);
|
||||
|
||||
/* ICM42670P*/
|
||||
ICM42670P imu(Wire,0);
|
||||
|
||||
//*********************************************************
|
||||
// Web server variable declarations
|
||||
@@ -71,6 +75,45 @@ void initSPIFFS();
|
||||
bool initWiFi();
|
||||
String getLEDState();
|
||||
// ----------------------------------------------
|
||||
void portScan(){
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.print(address,HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
@@ -87,16 +130,31 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("Adafruit_MMC5603 Magnetometer Calibration");
|
||||
Serial.println("");
|
||||
|
||||
portScan();
|
||||
|
||||
/* Initialise the sensor */
|
||||
if (!mag.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode
|
||||
/* There was a problem detecting the MMC5603 ... check your connections */
|
||||
Serial.println("Ooops, no MMC5603 detected ... Check your wiring!");
|
||||
while (1) delay(10);
|
||||
// Serial.println("Adafruit_MMC5603 Magnetometer Calibration");
|
||||
// Serial.println("");
|
||||
// if (!mag.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode
|
||||
// /* There was a problem detecting the MMC5603 ... check your connections */
|
||||
// Serial.println("Ooops, no MMC5603 detected ... Check your wiring!");
|
||||
// while (1) delay(10);
|
||||
// }
|
||||
|
||||
|
||||
// Initializing the ICM42670P
|
||||
int ret = imu.begin();
|
||||
if (ret != 0) {
|
||||
Serial.print("ICM42670P initialization failed: ");
|
||||
Serial.println(ret);
|
||||
while(1);
|
||||
}
|
||||
// Accel ODR = 100 Hz and Full Scale Range = 16G
|
||||
imu.startAccel(100,16);
|
||||
// Gyro ODR = 100 Hz and Full Scale Range = 2000 dps
|
||||
imu.startGyro(100,2000);
|
||||
// Wait IMU to start
|
||||
delay(100);
|
||||
|
||||
//*****************************************
|
||||
//Init OTA
|
||||
@@ -299,9 +357,31 @@ server.addHandler(new SPIFFSEditor(SPIFFS,http_username,http_password));
|
||||
server.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
inv_imu_sensor_event_t imu_event;
|
||||
|
||||
// Get last event
|
||||
imu.getDataFromRegisters(&imu_event);
|
||||
|
||||
// Format data for Serial Plotter
|
||||
Serial.print("AccelX:");
|
||||
Serial.println(imu_event.accel[0]);
|
||||
Serial.print("AccelY:");
|
||||
Serial.println(imu_event.accel[1]);
|
||||
Serial.print("AccelZ:");
|
||||
Serial.println(imu_event.accel[2]);
|
||||
Serial.print("GyroX:");
|
||||
Serial.println(imu_event.gyro[0]);
|
||||
Serial.print("GyroY:");
|
||||
Serial.println(imu_event.gyro[1]);
|
||||
Serial.print("GyroZ:");
|
||||
Serial.println(imu_event.gyro[2]);
|
||||
Serial.print("Temperature:");
|
||||
Serial.println(imu_event.temperature);
|
||||
|
||||
// Run @ ODR 100Hz
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// functions
|
||||
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
|
||||
Reference in New Issue
Block a user