loosing nano 33 iot configuration when disconnecting usb cable or reseting

4 Ansichten (letzte 30 Tage)
Hi, I am trying to use the Arduino Nano 33 IoT with the 'MATLAB® Support Package for Arduino® Hardware'.
I am calling the arduinosetup() function to configure the Nano to connect to MATLAB with Wi-Fi. Then I use the lines:
a = arduino('192.168.137.10','Nano33IoT',9500);
imu = bno055(a,'I2CAddress','0x28','SamplesPerRead',1,'ReadMode','latest');
Why I suspect I am losing the configuration on the board is because...
- When I close the instance of MATLAB, then reopen a new one and create new Arduino and BNO055 objects, I can receive data from the Nano.
- If, however, I disconnect the board's USB cable from the PC and try a different power supply (or even reconect it to the same USB port) or press the reset button, I cannot create an Arduino object anymore. I have to call the arduinosetup() function and redo the configurations again.
We need to use the BNO055 sensor wirelessly, hence we are using the Nano IoT.

Antworten (2)

Adeline
Adeline am 12 Okt. 2023
Hi,
I understand you are trying to connect an Arduino Nano 33 IoT board with MATLAB over WiFi.
If you manually disconnect the board before clearing the arduino object from the MATLAB workspace, the Arduino serial port may not be recognized when you reconnect. In the first scenario where the instance of MATLAB is closed, the object information in the workspace would be erased. Hence, the Arduino Nano was able to receive data in the new instance. Try clearing the Arduino object before disconnecting the USB to fix the connection issue.
Note: To retrieve the necessary credentials from your previous configuration check the “Retrieve last configuration from Arduino board” option in the Hardware Setup UI.
I hope this helps!

Salah Ad-Din Ahmed
Salah Ad-Din Ahmed am 13 Okt. 2023
I solved the problem by using arduino IDE instead of MATLAB to program the arduino.
For anyone in need, here is the code I used to send data collected from the BNO055 senser and sent to MATLAB over tcp link (static IP addres, enter wifi name and password in arduino_secrets.h):
///////////////////ARDUINO side//////////////////////////////////////////////////////////////////////////////////////////
/*
https://www.arduino.cc/reference/en/libraries/wifinina/server.write/
https://forums.adafruit.com/viewtopic.php?f=19&t=142352&p=703676#p703676
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>
#include "arduino_secrets.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
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() {
/* 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.write(comboConstant,n);
Serial.println(comboString);
delay(1000);
//Serial.println(comboConstant);
//Serial.println(n);
//*/
}
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);
}
////// arduino_secrets.h ///////////////////////////
#define SECRET_SSID ""
#define SECRET_PASS ""
///// MATLAB side \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
% tc=tcpclient('192.168.137.13',80);
% while 1
% read(tc)
% pause(1);
% end
tc=tcpclient('192.168.137.13',80);
remainind_data=[];
while 1
r=[remainind_data char(read(tc))];
while 1
[x, y, z, remainind_data]=process_fields(r);
fprintf('x=%f, y=%f, z=%f\n',x,y,z)
remaining_data_legth=length(remainind_data);
if remaining_data_legth >0
if remainind_data(remaining_data_legth) ~= '$'
break;
else
r=remainind_data;
end
else
break;
end
end
pause(1);
end
function [x, y, z, remainind_data]=process_fields(r)
data_strings=[];
indx=0;
L=length(r);
x=0;
y=0;
z=0;
stopBitNotRecieved=1;
while ~(indx >= L)
indx=indx+1;
data_string(indx)=r(indx);
if r(indx) == '$'
stopBitNotRecieved=0;
break;
end
end
if stopBitNotRecieved == 0
if indx < L
remainind_data=r((indx+1):L);
else
remainind_data=[];
end
i=1;
while i < indx
if strcmp(data_string(i:i+1),'X:')
i=i+3;
j=1;
while data_string(i)~=' ' && data_string(i)~='$'
xstring(j)=data_string(i);
i=i+1;
j=j+1;
end
x=str2double(xstring);
end
if strcmp(data_string(i:i+1),'Y:')
i=i+3;
j=1;
while data_string(i)~=' ' && data_string(i)~='$'
ystring(j)=data_string(i);
i=i+1;
j=j+1;
end
y=str2double(ystring);
end
if strcmp(data_string(i:i+1),'Z:')
i=i+3;
j=1;
while data_string(i)~=' ' && data_string(i)~='$'
zstring(j)=data_string(i);
i=i+1;
j=j+1;
end
z=str2double(zstring);
end
i=i+1;
end
else
remainind_data=r;
end
% examples
% [x, y, z, remainind_data]=process_fields('X: 2.333 Y: -12.2 Z: 34.29$')
% [x, y, z, remainind_data]=process_fields('X: 2.333 Y: -12.2 Z: 34.29$ X: 1.22 Y: ')
% [x, y, z, remainind_data]=process_fields(' -12.2 Z: 34.29$X: 1.22 Y: ')
% [x, y, z, remainind_data]=process_fields(' -12.2 Z: 34.29$ X: -8.444 Y: 9.065 Z: 39.65$')
% [x, y, z, remainind_data]=process_fields('X: 2.333 Y: -12.2 Z: 34.29$ X: -8.444 Y: 9.065 Z: 39.65$')
% [x, y, z, remainind_data]=process_fields(' -12.2 Z: 34.29')
end

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by