Difference in compiled file Cloud vs. IDE

I have a code which I compiled in Cloud and in IDE(v2.2.1).

Using a ESP32 chip - NodeMCU-32S
My code is contains the Adafruit_PCF8574 library. And if I upload from Cloud via agent, the library doesn't find my i2c chip for inputs/outputs. If I upload the same code from IDE the code works perfectly.

I verified the compiler result on both version and gives me difference.

What could be the problem?
Another question, is there a way to upload the *.bin file from cloud?

My Code:

#include "arduino_secrets.h"
#include <Adafruit_PCF8574.h>
#include <Adafruit_PCF8575.h>
#include "thingProperties.h"

// Inputs and outputs form i2c
Adafruit_PCF8574 pcfOut, pcfIn;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  if (!pcfOut.begin(0x24, &Wire)) {
    Serial.println("Couldn't find PCF8574 for Outputs");
    while (1);
  }
 
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here

}

Cloud compiler result:

Sketch uses 1130737 bytes (86%) of program storage space. Maximum is 1310720 bytes.

Global variables use 51776 bytes (15%) of dynamic memory, leaving 275904 bytes for local variables. Maximum is 327680 bytes.

IDE compiler result:

Sketch uses 1163449 bytes (88%) of program storage space. Maximum is 1310720 bytes.
Global variables use 58000 bytes (17%) of dynamic memory, leaving 269680 bytes for local variables. Maximum is 327680 bytes.

Different tools (compilers etc). Suppose you take a trip from one end of the continent to the other visiting several people and several others do the same. What are the odds all will have exactly the same mileage?

Hi @tamibandy. I think comparing the verbose compilation output from both environments will give us a clear idea of what the differences are.

Arduino Cloud

  1. Select "Preferences" from the menu on the left side of the "Arduino Web Editor" window.
    The preferences panel will open to the right of the menu.
  2. Check the box next to "☐ Always show output panel**" in the preferences panel.
  3. Check the box next to "☐ Console: Show verbose output**" in the preferences panel.
  4. Open your sketch in Arduino Web Editor.
  5. Click the button ("Verify") in the sketch panel.
  6. Wait for the compilation to finish.
  7. Click the icon in the top right corner of the black output panel at the bottom of the "Arduino Web Editor" window that looks like two pieces of paper.
  8. Open a forum reply here by clicking the "Reply" button.
  9. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  10. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  11. Move the cursor outside of the code block markup.

Arduino IDE

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the "OK" button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to finish.
  6. Right click on the black "Output" panel at the bottom of the Arduino IDE window.
  7. From the context menu, click Copy All.
  8. Open a forum reply here by clicking the "Reply" button.
  9. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  10. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  11. Move the cursor outside of the code block markup before you add any additional text to your reply.
  12. Click the "Reply" button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (image) on the post composer toolbar:
    Upload icon on toolbar
    A dialog will open.
  6. In the dialog, select the .txt file you saved.
  7. Click the "Open" button.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

No. Arduino Cloud doesn't actually directly upload sketches to your board. It downloads the compiled binary file to your computer and then its helper tool "Arduino Create Agent" runs the standard uploader tool (esptool in the case of the ESP32 board) on your computer to upload the binary file to the board. So if you want to upload a binary file to your board, you can just do what Arduino Cloud would do directly.

It is useful to let Arduino Cloud generate the base upload command for you:

  1. Upload a sketch to the board using Arduino Cloud.
  2. Wait for the upload to finish.
  3. Examine the contents of the black output panel at the bottom of the Arduino Web Editor page. You will need to scroll up to see it all. There you will find the command that was used to upload the binary file.
    For example:
    Flashing with command:C:/Users/per/.arduino-create/esp32/esptool_py/4.2.1/esptool.exe --chip esp32 --port COM51 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 C:/Users/per/AppData/Local/Temp/extrafiles1859975601/sketch_dec24a.bootloader.bin 0x8000 C:/Users/per/AppData/Local/Temp/extrafiles1859975601/sketch_dec24a.partitions.bin 0xe000 C:/Users/per/AppData/Local/Temp/extrafiles1859975601/tools/partitions/boot_app0.bin 0x10000 C:/Users/per/AppData/Local/Temp/arduino-create-agent1186875505/sketch_dec24a.bin
    

You can copy that command, modify it to use the path of the binary file you wish to upload, then run it from the terminal on your computer.

Hi @ptillisch,

I attached the two *.txt file with the outputs.

In the second question I referred for OTA, using the *.bin file. I could generate from the IDE and upload via OTA. Right now I purchased the Maker plan for arduino cloud, just for the OTA function.
Cloud Compiler.txt (7.6 MB)
IDE Compiler.txt (6.8 MB)

Edit:
I made another compilation with IDE and get this information:

FQBN: esp32:esp32:nodemcu-32s
Using board 'nodemcu-32s' from platform in folder: C:\Users\Bandi\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11
Using core 'esp32' from platform in folder: C:\Users\Bandi\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11

and in Cloud compiler:

Using board 'nodemcu-32s' from platform in folder: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5

Using core 'esp32' from platform in folder: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5

There is a difference between the version numbers
Attached the new ouptup *.txt files. I simplified the code to remain just the Adafruit_PCF8574 part in it.
Cloud Compiler_v2.txt (424.9 KB)
IDE Compiler_v2.txt (506.8 KB)

New code:

#include <Adafruit_PCF8574.h>

// Inputs and outputs form i2c
Adafruit_PCF8574 pcfOut, pcfIn;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  if (!pcfOut.begin(0x24, &Wire)) {
    Serial.println("Couldn't find PCF8574 for Outputs");
    while (1);
  }
}

void loop() {
  // Your code here

}

Nice job of analyzing the output! I was also interested in checking for any additional differences in which library dependencies of the sketch were used, which are shown in the output:

Using library Adafruit PCF8574 at version 1.1.1 in folder: C:\Users\Bandi\Documents\Arduino\libraries\Adafruit_PCF8574 
Using library Adafruit BusIO at version 1.14.5 in folder: C:\Users\Bandi\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Wire at version 2.0.0 in folder: C:\Users\Bandi\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\Wire 
Using library SPI at version 2.0.0 in folder: C:\Users\Bandi\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\SPI 

But I see that the same versions of the libraries are used on Arduino Cloud and Arduino IDE both.


So I do think the difference in the versions of the "esp32" boards platform is the cause of the different behavior of the sketch programs.

If you want to verify this, you could use the Arduino IDE Boards Manager to install version 2.0.5 of the "esp32" boards platform. The expectation is that, after doing that and using Arduino IDE to upload the sketch to your board again, the behavior would be the same as the behavior of the sketch program will be the same as when you uploaded the sketch using Arduino Cloud.

Unfortunately I don't have an idea of what specific difference between the two platform versions would cause this. I did browse through the large changelog between the version 2.0.11 of the platform you are using with Arduino IDE and the version 2.0.5 used by Arduino Cloud and didn't spot anything related to I2C or the Wire library.

There isn't any way to change the version of the platforms used by Arduino Cloud, so you are stuck with the 2.0.5 version there until the Arduino Cloud maintainers get around to upgrading it.

Hi @ptillisch,

I know what is the problem. I'm using a Kincony board and the NodeMCU-32S pins for SDA & SCL is different than the original one. This is the major problem. The version difference maybe not a problem on this example.

Is there a possibility to update with my custom settings in Arduino Cloud?
Or if this isn't possible, then exists a way to just upload the compiled *.bin file by OTA?

Update:
I found the Arduino Cloud CLI solution for uploading the localy compiled *.bin file via OTA.
I will close this post

Thanks for posting an update with your findings.

There is no way to modify the configuration of the "esp32" boards platform in Arduino Cloud. However, you should be able to configure the pins in your sketch by calling Wire.setPins(4, 5) in your sketch before passing the Wire object to pcfOut.begin:

https://docs.espressif.com/projects/arduino-esp32/en/latest/api/i2c.html#setpins

  Wire.setPins(4, 5);
  if (!pcfOut.begin(0x24, &Wire)) {
2 Likes

Hi @ptillisch,

Oh you are the best. Thanks for all of your help. It was clear and detailed. And this will be the best solution with setpins. I can use the cloud for downloading with this trick.

1 Like

You are welcome. I'm glad if I was able to be of assistance.

Regards, Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.