I can't connect my rp2040 via Wifi if it is not connected to my PC. I connect it through an external 5v source, I reset the board but I can see the wifi connection of my rp2040... I would appreciate the help.
Does the program running in your rp2040 actually try to use wifi?
I download the program and while it is connected to the PC, I can see the wifi connection of the rp2040 and it runs fine without problems, but when I close the program (Arduino IDE) and I am still connected to the PC (technically I am using the USB port as a source), I reset the board from the button and wait as a minute and the Arduino's WIFI connection does not appear. I also don't see the connection if I place the RP2040 with the phone charger.
Perhaps the problem is in the program running in the rp2040. Do you suppose that is possible?
Don't you think that posting the program that is giving you trouble would be helpful?
Maybe it's waiting for a USB/serial link that it will not find when it's not connected to USB
I don't understand when you mean a link. What should I do to repair it?
I'm doing. Let me explain myself better. I download the program on rp2040 and connected to my PC I can see that the wifi connection of the rp4020 appears. Then I close my program or connect it to an external power source, I can't see the wifi connection. I also reset from the button and there are no changes. But if I open the program again and connect the rp2040 to the PC, I can see the connection and communicate without problems.
I hope I have explained it a little better.
I hadn't thought about it. I'm going to run another program and see what happens.
Post your source code.
#include <Arduino_LSM6DSOX.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include "index.h"
// size of buffer to store HTTP requests
int REQUEST_BUFFER = 50;
int char_cnt = 0;
char HTTP_requst[50] = {0}; // HTTP request string
char ssid[] = "test"; // your network SSID (name)
char pass[] = "12345678"; // 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 status = WL_IDLE_STATUS;
WiFiServer server(80);
float Ax, Ay, Az, pre_Ax, pre_Ay, pre_Az, sensorData;
float farray[20][3];
int x, y, z, pre_x, pre_y, pre_z, multi, aft_dec;
const String table_name[]={"X","Y","Z"};
void setup() {
Serial.begin(115200);
while(!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.println("Access Point Web Server");
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
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);
// Create open network. Change this line if you want to create an WEP network:
status = WiFi.beginAP(ssid, pass);
if (status != WL_AP_LISTENING) {
Serial.println("Creating access point failed");
// don't continue
while (true);
}
// wait 10 seconds for connection:
delay(10000);
// start the web server on port 80
server.begin();
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
Serial.println();
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println("Hz");
Serial.println();
// you're connected now, so print out the status
printWiFiStatus();
}
void loop() {
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(Ax, Ay, Az);
multi = 1000;
aft_dec=4;
x=Axmulti;
y=Aymulti;
z=Az*multi;
if (x != pre_x and y != pre_y and z != pre_z){
for (int thisPin = 20; thisPin > 0; thisPin--){
farray[thisPin][0] = farray[thisPin-1][0];
farray[thisPin][1] = farray[thisPin-1][1];
farray[thisPin][2] = farray[thisPin-1][2];
}
farray[0][0]=Ax;
farray[0][1]=Ay;
farray[0][2]=Az;
pre_x = x;
pre_y = y;
pre_z = z;
}
}
// compare the previous status to the current status
if (status != WiFi.status()) {
// it has changed update the variable
status = WiFi.status();
if (status == WL_AP_CONNECTED) {
// a device has connected to the AP
Serial.println("Device connected to AP");
}
else {
// a device has disconnected from the AP, and we are back in listening mode
Serial.println("Device disconnected from AP");
}
}
sensorData=farray[0][0];
WiFiClient CanvasDisplay = server.available(); // Get CanvasDisplay client
if (CanvasDisplay) { // got CanvasDisplay?
boolean currentLineIsBlank = true;
while (CanvasDisplay.connected()) {
if (CanvasDisplay.available()) { // check if CanvasDisplay available to read
char HTTP_requst_char = CanvasDisplay.read(); // read 1 byte (character) from CanvasDisplay request
if (char_cnt < (REQUEST_BUFFER - 1)) { //last element is 0 => null terminate string
HTTP_requst[char_cnt] = HTTP_requst_char; // store each HTTP request character in HTTP_requst array
char_cnt++;
}
if (HTTP_requst_char == '\n' && currentLineIsBlank) { //give response only after last line
// send a standard http response header
CanvasDisplay.println("HTTP/1.1 200 OK");
if (SearchForRequest(HTTP_requst, "ajax_inputs")) {
CanvasDisplay.println("Content-Type: text/xml"); // data as XML
CanvasDisplay.println("Connection: keep-alive");
CanvasDisplay.println();
XML_response(CanvasDisplay); //send data to Canvas Display
}
else{
CanvasDisplay.println("Content-Type: text/html");
CanvasDisplay.println("Connection: keep-alive");
CanvasDisplay.println();
if (SearchForRequest(HTTP_requst, "GET /digital.htm")) CanvasDisplay.println(digital),CanvasDisplay.println(digital1);
else if (SearchForRequest(HTTP_requst, "GET /analog.htm")) CanvasDisplay.println(analog), CanvasDisplay.println(analog1);
else if (SearchForRequest(HTTP_requst, "GET /bargraph.htm")) CanvasDisplay.println(bargraph);
else CanvasDisplay.println(gauge);
}
Serial.print(HTTP_requst);//Debug on serial port
// reset buffer
char_cnt = 0;
for (int i = 0; i < REQUEST_BUFFER; i++) HTTP_requst[i] = 0;
break;
}
if (HTTP_requst_char == '\n') currentLineIsBlank = true; //new line detected
else if (HTTP_requst_char != '\r') currentLineIsBlank = false; //get next character
} // end if (CanvasDisplay.available())
} // end while (CanvasDisplay.connected())
delay(2); // short delay before closing the connection
CanvasDisplay.stop(); // close the connection
} // end if (CanvasDisplay)
}
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);
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}
// searches for a needle in the haystack
char SearchForRequest(char *haystack, char *needle)
{
char needle_index = 0;
char haystack_index = 0;
char haystack_length;
haystack_length = strlen(haystack);
if (strlen(needle) > haystack_length) return 0;
while (haystack_index < haystack_length) {
if (haystack[haystack_index] == needle[needle_index]) {
needle_index++;
if (needle_index == strlen(needle)) return 1; // found needle
}
else needle_index = 0;
haystack_index++;
}
return 0;
}
// prepare send the XML file with arduino input values
void XML_response(WiFiClient cd)
{
int analog_0 = 0;
int analog_1 = 0;
int analog_2 = 0;
int analog_3 = 0;
int analog_4 = 0;
int analog_5 = 0;
int digital_5 = 0;
int digital_6 = 0;
int digital_7 = 0;
int digital_8 = 0;
analog_0 = x;
analog_1 = y;
analog_2 = z;
analog_3 = z;
analog_4 = z;
analog_5 = z;
digital_5 = 1;
digital_6 = 0;
digital_7 = 0;
digital_8 = 0;
cd.print("<?xml version = \"1.0\" ?>");
cd.print("<inputs>");
cd.print("<analog>");
cd.print(analog_0);
cd.print("</analog>");
cd.print("<analog>");
cd.print(analog_1);
cd.print("</analog>");
cd.print("<analog>");
cd.print(analog_2);
cd.print("</analog>");
cd.print("<analog>");
cd.print(analog_3);
cd.print("</analog>");
cd.print("<analog>");
cd.print(analog_4);
cd.print("</analog>");
cd.print("<analog>");
cd.print(analog_5);
cd.print("</analog>");
Serial.println(x);
cd.print("<digital>");
cd.print(digital_5);
cd.print("</digital>");
cd.print("<digital>");
cd.print(digital_6);
cd.print("</digital>");
cd.print("<digital>");
cd.print(digital_7);
cd.print("</digital>");
cd.print("<digital>");
cd.print(digital_8);
cd.print("</digital>");
cd.print("</inputs>");
}
while(!Serial);
Waits for a serial connection, which it gets if connected to the PC but never does when not connected to the PC.
I just ran another program and it works exactly the same.
I don't see the Wifi connection from rp2040 when I have an external power supply.
As I suspected.
Get rid of that (comment it out) -- OK?
Hi fugitive_pancake and EmilyJane, very grateful for your analysis, that line of code is the problem, I commented on it and that's it.
Now I will continue studying.
Do you have any reference that you can recommend to me to add images to the rp2040?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.