Hello. I am trying to send data from an Arduino board (Nano 33 IoT) to a PC by creating a server on the board and a client on the PC. The board uses a WiFiNINA chip to connect to WiFi.
I have noticed that the board takes some time to send readings, although it should be sending data regularly. I plotted the data points it sent me against time. The plot shows a cluster of data 1 to 2 seconds apart. There is some data sent between these clusters. The data rate in between these clusters may be too slow for my application since I need live data.
What is happening, and is there a way to fix it?
image:
code:
/*/
https://support.arduino.cc/hc/en-us/articles/360014905179-How-to-Create-a-simple-web-server-with-static-IP-and-control-builtinLED-using-WiFiNINA-library
https://www.arduino.cc/reference/en/libraries/wifinina/server.write/
https://www.arduino.cc/reference/en/libraries/wifinina/server.write/
https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/arduino-code
//*/
#include <SPI.h>
#include <WiFiNINA.h>
#define SECRET_SSID ""
#define SECRET_PASS ""
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
int Calibrated=0;
Adafruit_BNO055 bno = Adafruit_BNO055(55);
IPAddress ip(192, 168, 137, 13);
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key index number (needed only for WEP)
int led = LED_BUILTIN;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
// Initialise the BNO055 sensor
Serial.println("Initialise the BNO055 sensor");
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
bno.setExtCrystalUse(true);
Serial.println("Access Point Web Server");
pinMode(led, OUTPUT); // set the LED pin mode
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
WiFi.config(ip);
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// by default the local IP address will be 192.168.4.1
// you can override it with the following:
// WiFi.config(IPAddress(10, 0, 0, 1));
// print the network name (SSID);
Serial.print("Creating access point named: ");
Serial.println(ssid);
// start the web server on port 80
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a WiFi connection");
while(true);
}else {
server.begin();
}
// you're connected now, so print out the status
printWiFiStatus();
}
void loop() {
if (Calibrated == 0){
//*
uint8_t sys, gyro, accel, mg =0;
bno.getCalibration(&sys, &gyro, &accel, &mg);//0-> uncalibrated, 3-> best calibration
//note calibrate gyro-keep bno still
// calibrate magnetometer figure of 8 movment
// callibrate ccelerometer move hold(3seconds) move hold...
String calibrationSteing;
String parameerNameSys="sys: ";
String parameerNameGyo=" gyro: ";
String parameerNameAccl=" accl: ";
String parameerNameMag=" mg: ";
calibrationSteing= parameerNameSys+sys+parameerNameGyo+gyro+parameerNameAccl+accel+parameerNameMag+mg+"$";
const char* calibrationConstant;
calibrationConstant=calibrationSteing.c_str();
int n;
n=calibrationSteing.length();
server.write(calibrationConstant,n);
Serial.println(calibrationSteing);
if (sys == 3 && gyro == 3 && mg == 3){
Calibrated=1;
}
//*/
}else{
//* Get a new sensor event
imu::Quaternion q = bno.getQuat();
q.normalize();
imu::Vector<3> euler = q.toEuler();
euler.x() *= -180/M_PI;
euler.y() *= -180/M_PI;
euler.z() *= -180/M_PI;
if (euler.x() < 0)
euler.x() += 360;
//*/
String comboString;
String x="X: ";
String y=" Y: ";
String z=" Z: ";
comboString= x+euler.x()+y+euler.y()+z+euler.z()+"$";
const char* comboConstant;
comboConstant=comboString.c_str();
int n;
n=comboString.length();
//server.println(comboConstant);
server.write(comboConstant,n);
Serial.println(comboString);
}
//delay(30);
}
void printWiFiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
