Losing arduino nano 33 iot when disconnecting from pc

6 次查看(过去 30 天)
I amtrying to work with the arduino nano 33 iot (wifi capable) we are using the arduino library on MATLAB to connect configure it, using the function arduinosetup().
The arduino should connct to pc via mobile hotspot (produced by pc). Afther configuration we use the line:
a = arduino('IP adress','Nano33IoT',(port));
This creates a connection to the WiFi supported Arduino board. if I close MATLAB and re-open it I can still use this function to connect to the bourd. But if I disconnect the arduino I cant use arduino() anymor, I end up having to call arduinosetup() again and configuring it again.This is problamating since we need to use the bourd remotly (I am thinking of connecting it to a power bank via USB).
Thanks

回答(1 个)

Ganapathi Subramanian R
Hi Salah,
It is my understanding that you are working with ‘Arduino Nano 33 IOT’ board and wants to know how to reconnect it when disconnected from PC. Please select the ‘Retrieve last configuration’ from ‘Arduino board’ option to retrieve the necessary credentials from previous configuration to reconnect.
Kindly refer to the ‘Arduino Wi-Fi Connection Failure’ topic in the below documentation to resolve failure in Wi-Fi connection with Arduino.
Please refer to the below documentation for alternative ways to connect with Arduino.
  2 个评论
salah ad-din youbi
salah ad-din youbi 2023-10-3
编辑:salah ad-din youbi 2023-10-3
I am afraid not. You see we need to operate the nano remotly. If the remote connection stops working evry time we disconnected from pc, the bourd is usless. To do what you are saying resquires us to reconnect the bourd with pc. Then the wifi will stop working again once we disconnect it. And befor you ask:
-Yes I've tried and you need to specify the serial port to do what you are saying.
-Yes the bourd had sufficient power, it was connected to a 2A charging brick.
-No the brick did not damage the arduino I used it befor.
Salah Ad-Din Ahmed
Salah Ad-Din Ahmed 2023-10-13
High I had started this post with my student account, now that is closed so I have to answer with my work account. 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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by