BLYNK
BLYNK.IO       📲 GETTING STARTED       đź“— DOCS       👉 SKETCH BUILDER

No connection to Wifi if my code contains some particular pgm_read_word_near commands

Hello,

My code contains PROGMEM arrays that tell my servo motors which position to take every 0.05 seconds (with a loop). I have a particular file which allows to store these arrays. These arrays are called "arrayH2 ", "arrayV2 " etc. My servos are called “monServoH”, “monServoV”, etc.
One array = one servo.

Below is the content of my file :

// Reine de la Nuit


void Presentation() {
    Serial.println("Je suis la reine de la nuit");
    detachAll();

    arrayHi = pgm_read_word_near(arrayH2 + 1);
    arrayVi = pgm_read_word_near(arrayV2 + 1);
    arrayRi = pgm_read_word_near(arrayR2 + 1);
    arrayXi = pgm_read_word_near(arrayX2 + 1);
    arrayYi = pgm_read_word_near(arrayY2 + 1);
    **arrayLidsi = pgm_read_word_near(arrayLids2 + i);**
    attachAll();
    sweepH(arrayHi,50);
    sweepV(arrayVi,50);
    sweepR(50,20);
    sweepX(arrayXi,10);
    sweepY(arrayYi,10);
    sweepLids(minLids,2);
    monServoLids.write(minLids);
    sweepJaw(minJaw,10);
    detachAll();
    

    myMP3.stop();
    delay(100);

    if (x == 1) {
        myMP3.volume(30);
        myMP3.play(4);
    }
    
    int b = analogRead(pinBusy);
    int z = 1;
    while (z == 1) {
        delay(1000);
        b = analogRead(pinBusy);
        Serial.print("b=");
        Serial.println(b);
        if (b > 500) { delay(1); }
        if (b < 500) { z = 2; }
    }

    int i = 14;
    
    
    if (b < 500) {
        attachAll();

        unsigned long currentMillis = millis();
        unsigned long  previousMillis = millis();
        Serial.println("Debut");
        while (i < L2) {
        
            currentMillis = millis();
       
        
            arrayHi = pgm_read_word_near(arrayH2 + i);
            arrayVi = pgm_read_word_near(arrayV2 + i);
            arrayRi = pgm_read_word_near(arrayR2 + i);
            arrayXi = pgm_read_word_near(arrayX2 + i);
            arrayYi = pgm_read_word_near(arrayY2 + i);
            **arrayLidsi = pgm_read_word_near(arrayLids2 + i);**
            arrayJawi = pgm_read_word_near(arrayJaw2 + i);


            monServoH.write(arrayHi);
            monServoV.write(arrayVi);
            monServoR.write(arrayRi);
            monServoX.write(arrayXi);
            monServoY.write(arrayYi);
            monServoLids.write(arrayLidsi);
            monServoJaw.write(arrayJawi);

            b = analogRead(pinBusy);

            if (currentMillis - previousMillis >= TIME2) {
                i = i + 1;
                previousMillis = currentMillis;
            }

            if (i >= L2-1 ) {
                detachAll();
                detach = true;
            }
        }

        detachAll();
        detach = true;
        
    }

    if (i >= L2) { // obligée de faire ça pour stopper la musique
        myMP3.pause();
        myMP3.volume(0);



    }

 

 
}

Do you see the bold lines (edit: the lines with “**” )?
This particular command:

arrayLidsi = pgm_read_word_near(arrayLids2 + i);

If I comment them, my ESP8266 will be able to connect to Wifi.
If I don’t comment them, my ESP8266 won’t be able to connect.

I really don’t understand why.
I have tried several times, and I always have the same conclusion…

This loop works very well when I don’t use Blynk. And it works perfectly for the other arrays…

Thank you in advance for your help!

Post your whole sketch please.

Hello,

My whole script contains 16 files (I found it was easier)

Below is the main file.
I added the other files here: https://github.com/nebetbastet/Robobo_wifi

My problem is in this script: https://github.com/nebetbastet/Robobo_wifi/blob/main/mode_reine.h
The arrays are here: https://github.com/nebetbastet/Robobo_wifi/blob/main/servo_array_reine.h
(I converted the arrayLids2 PROGMEM array into a classical array).

// Paramètres
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "Robobo"
#define BLYNK_AUTH_TOKEN "xxx"
char ssid[] = "xxx";
char pass[] = "xxx";
char auth[] = "xxx";

#include ESP8266_Lib.h
#include BlynkSimpleShieldEsp8266.h
#define EspSerial Serial3
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;



#include "CapacitiveSensor.h"
#include "Servo.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "SR04.h"
#include "header.h"
#include "config_servos.h"
#include "config.h"
#include "smallGestures.h"
#include "servo_array_doris.h"
#include "mode_perhaps.h"
#include "servo_array_reine.h"
#include "mode_reine.h"
#include "servo_array_etoile.h"
#include "mode_etoile.h"
#include "servo_array_lacrimosa.h"
#include "mode_lacrimosa.h"
#include "servo_array_oui.h"
#include "mode_oui_non.h"
#include "mode_normal.h"


  
void setup()
{
  Setup();
 // Dodo();
  Initialize2(false); // position "neutre", yeux ouverts

  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);

  detachAll();

  //timer.setInterval(1000L, myTimerEvent);


}

// Loop
void loop() {
    Blynk.run();
    timer.run();
}


// Lacrimosa
BLYNK_WRITE(V0)
{
    if (param.asInt() == 1)
    {
      attachAll();
      ModeLacrimosa();
      detachAll();
    }

}

// Perhaps Perhaps
BLYNK_WRITE(V1)
{
    if (param.asInt() == 1)
    {
        attachAll();
        ModePerhaps();
        attachAll();
        Dodo();
        detachAll();
    }

}


// Paupières
BLYNK_WRITE(V2)
{
    monServoLids.attach(pinLids);
    int pinValue = param.asInt();
    int pos = map(pinValue, 0, 100, minLids, maxLids);
    sweepLids(pos, 10);
    monServoLids.detach();
}

// Slider vertical neck
BLYNK_WRITE(V3)
{
    monServoV.attach(pinV);
    int pinValue = param.asInt();
    int pos = map(pinValue, 0, 100, minV, maxV);
    sweepV(pos, 15);
    monServoV.detach();
}

// Slider rolling neck
BLYNK_WRITE(V4)
{
    monServoR.attach(pinR);
    int pinValue = param.asInt();
    int pos = map(pinValue, 0, 100, minR, maxR);
    sweepR(pos, 30);
    monServoR.detach();
}


// Slider horizontal neck
BLYNK_WRITE(V5)
{
    monServoH.attach(pinH);
    int pinValue = param.asInt();
    int pos = map(pinValue, 0, 100, minH, maxH);
    sweepH(pos, 15);
    monServoH.detach();
}

// Slider Eyes X
BLYNK_WRITE(V6)
{
    int posLids = monServoLids.read();
    int valueLids = map(posLids, minLids, maxLids, 0, 100);
    if (valueLids <= 35) { // On bouge l'oeil seulement si l'oeil n'est pas trop fermé
        monServoX.attach(pinX);
        int pinValue = param.asInt();
        int pos = map(pinValue, 0, 100, minX, maxX);
        sweepX(pos, 15);
    }
    monServoX.detach();
}

// Slider Eyes Y
BLYNK_WRITE(V7)
{
    int posLids = monServoLids.read();
    int valueLids = map(posLids, minLids, maxLids, 0, 100);
    if (valueLids <= 35) { // On bouge l'oeil seulement si l'oeil n'est pas trop fermé
        monServoY.attach(pinY);
        int pinValue = param.asInt();
        int pos = map(pinValue, 0, 100, minY, maxY);
        sweepY(pos, 15);
    }
    monServoX.detach();
}


// Slider Jaw
BLYNK_WRITE(V8)
{
    monServoJaw.attach(pinJaw);
    int pinValue = param.asInt();
    int pos = map(pinValue, 0, 100, minJaw, maxJaw);
    sweepJaw(pos, 15);
    monServoJaw.detach();
}

// Poème Etoile
BLYNK_WRITE(V9)
{
    if (param.asInt() == 1)
    {
        attachAll();
        PoemeEtoile();
        detachAll();
    }

}
//
//BLYNK_READ(V10) // Distance
//{
//    a = sr04.Distance();
//    Blynk.virtualWrite(V10, a); //sending to Blynk
//}

//void myTimerEvent()
//{
//    // You can send any value at any time.
//    // Please don't send more that 10 values per second.
//    Blynk.virtualWrite(V10, a);
//}

// Petit geste aléatoire
BLYNK_WRITE(V11)
{
    if (param.asInt() == 1)
    {
        attachAll();
        Initialize2(false);
        int i;
        RandomGesture2();
        detachAll();
        Initialize2(false);
    }

}

// Position neutre
BLYNK_WRITE(V12)
{
    if (param.asInt() == 1)
    {
        attachAll();
        Initialize2(false);
        detachAll();
    }

}

//// Presentation
BLYNK_WRITE(V13)
{
    if (param.asInt() == 1)
    {
        attachAll();
        Presentation();
        detachAll();
    }

}


//// Presentation
BLYNK_WRITE(V14)
{
    if (param.asInt() == 1)
    {
        attachAll();
        Initialize2(false);
        Oui();
        detachAll();
    }

}