Uno R4: WiFi Total Mysteries

Hardware:

  • Uno R4 WiFi;
  • Linux Mint 21.3 (Virginia; completely up-to-date);
  • up-to-date Cloud Agent;
  • Arduino IDE 2.3.9

Problem(s):

I have looked for a 'structured' tutorial (etc) to introduce a relative newbie to the many extra layers of interaction that adding a WiFi link seems to add. But I have not found anything suitable. Any suggestions?

Lacking a structured approach, I have resorted to a hacking approach (or as a Swiss friend calls it, "learning by breaking"). Here are a few of my steps and stumbling blocks ⸺

  • I managed to get the Cloud Agent installed and I am using the no-$ version for now (knowing that in this version, I cannot use the over-the-air [OTA] method of uploading sketches etc).
  • I was able to 'Associate' my brand-new R4 WiFi 'Device' using the Cloud Agent
  • I was able to create 'a Thing', and assign my R4 'Device' with that 'Thing'.
  • I was able to associate a number of Variables to said Thing.
  • I was also able to create a crude Dashboard, referencing the Variables associated with the Thing
  • In the process of Associating a Device, the Cloud Agent seems to have created a bare-bones, device-specific Sketch (and named it "untitled may28a.ino");
  • ...After the Association of variables to the Thing, the Cloud Agent (automatically) modified the sketch so as to include 'triggers' which would cause changes to the Variables to be uploaded to the Cloud (and so made available to my remote Dashboard).

Up to this point, the hacking approach does reveal how the various elements of the WiFi / Cloud Agent system interact, and that feels "promising". However.... Here is where matters take a 'dark' turn:

If I upload any simple Arduino Example sketch to the R4 WiFi board (using a USB connection as I cannot use OTA method with the zero-cost Cloud service), that action immediate destroys any WiFi connectivity. Specifically, the board goes "dark", the on-board dancing LED display no longer functions, and I cannot find any method for re-establishing the online connection with the Device using the Cloud Agent. I even tried quitting the Agent, re-booting my desktop computer, and resetting the R4. Nothing.

In a desperate attempt to recover, I tried to "Update the Firmware" of the R4, via the Arduino IDE v2.3.9. That did not re-establish the WiFi connection, and I could NOT use the Cloud Agent to detect the R4 board.

I then deleted the Device (within the Cloud Agent), and tried to re-Add the Device, but that also did NOT work (Adding the device seems to have stalled-out completely, and it could not link to the R4 WiFi board).

After concluding that I had somehow "smoked" my R4 ⸺ and had nothing to lose by further experimentation ⸺ I followed the method outlined at Arduino Support: Re-Install ESP32 Firmware . After a bit of further fussing around with the Cloud Agent, that seems to have got me back to a functioning R4 board: I was able to get the Cloud Agent to recognize and Add the Device and to re-associate the Device with my Thing, and I now have an active cloud connection to my R4.

Interesting observation: having re-installed the ESP32 Firmware, and even after the Cloud Agent "updated" the R4 firmware during the process of Adding a Device....the dancing LED cloud image is definitely different after the re-installation of firmware. Specifically, the original dancing-LED 'cloud' stayed in one place on the LED matrix with the exception of a wiggling internal loop (or internal 'tail', supposedly to emulate how the data "cloud" was active in the way that an atmospheric cloud changes shape); but NOW, the LED 'cloud' outline does not change shape but rather shifts from left-to-right, and then back again. I include this observation because, for a person with intimate knowledge of the R4, it might indicate which version of the Firmware(s) are currently running on my R4.

2nd Interesting Observation: I keep getting pop-ups ⸺ WITHIN the Cloud Agent itself (!!!) ⸺ telling me that I must install the Cloud Agent. What kind of weird gaslighting is that? What does it possibly mean?

So after a full day of frustration, I have what is (essentially, seemingly...) an out-of-the-box R4 with basic connectivity via the Cloud.

Clearly, I do not understand how to craft a Sketch that will upload (via USB connection) to the R4 and not destroy the WiFi connectivity.

I believe that the untitled may28a.ino , automatically created by the Cloud Agent when I first established my connection with this particular R4 board, holds the key.....particularly, the fact that this automatically generated Sketch includes the helper file #include "thingProperties.h"

Pointers? Suggestions? Major themes that I am missing here?

I have only used the cloud a little bit so am far from an expert, but this kind of programming is tricky. The cloud itself wants to do much of the work and if you mess with that it will fail. The part that caught my attention is

I have never done that, you build the sketch by working in the cloud to select variables and associate them with dashboards etc. Had you posted the code we could probably see the code for the wifi connection has been deleted as you overwote the sketch.

Programming in the cloud is VERY different and as a 65+ yrs experienced person, I don't much like it as I want to drive myself so to speak.

I just quickly initiated a sketch (they get created automaticaly when you do something in the cloud, I don;t remember what I did. Here is the code, I think you will see the wifi part, compare this sketch to yours to see what is different.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Thing_Test_1"
  https://create.arduino.cc/cloud/things/793bca33-6a82-4b95-a66b-cadcfcd87fc8 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool var_1;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

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); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

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

/*
  Since Var1 is READ_WRITE variable, onVar1Change() is
  executed every time a new value is received from IoT Cloud.
*/
void onVar1Change()  {
  // Add your code here to act upon Var1 change
}

Using WiFi with your board and programming the board "through the cloud" are two almost entirely separate things. (In common: you connect to WiFi.) What do you want to do? Maybe give some examples.

Ha! You and I are essentially the same age (and similar attitudes re: 'drive it myself') and additionally what I can only guess to be "a Canadian of Ukrainian descent".

Here is the Cloud-generated code thrown at me by The Agent (with modifications it added, after I assigned some Variables to The Thing):

/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"

URL create_arduino_cc/cloud/things/"my-R4-device-address-goes-here"

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are made to the Thing

float CO2_ppm;
float Mass;
float RHumidity;
float TempC;

Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

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);

// Defined in thingProperties.h
initProperties();

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

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

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

}

/*
Since Mass is READ_WRITE variable, onMassChange() is
executed every time a new value is received from IoT Cloud.
*/
void onMassChange()  {
// Add your code here to act upon Mass change
}

/*
Since TempC is READ_WRITE variable, onTempCChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTempCChange()  {
// Add your code here to act upon TempC change
}

/*
Since RHumidity is READ_WRITE variable, onRHumidityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onRHumidityChange()  {
// Add your code here to act upon RHumidity change
}

/*
Since CO2PerCent is READ_WRITE variable, onCO2PerCentChange() is
executed every time a new value is received from IoT Cloud.
*/
void onCO2PerCentChange()  {
// Add your code here to act upon CO2PerCent change
}

/*
Since CO2Ppm is READ_WRITE variable, onCO2PpmChange() is
executed every time a new value is received from IoT Cloud.
*/
void onCO2PpmChange()  {
// Add your code here to act upon CO2Ppm change
}

When I used a USB cable to upload a Sketch to the R4 WiFi board, it was the Arduino HX711 Library example sketch, "HX711_full_example.ino" ⸺ completely raw and unmodified, meaning that I did not even add the helper file #include "thingProperties.h"

Ultimately, I aim to create a remotely located environmental sensor, which

  1. would have its own on-board SD card logging system; and,
  2. have real-time (or nearly so!) updates via WiFi to a remote dashboard.

In the future, so as to operate at a more distant location, I would be re-creating the project with a LoRa system. But, one step at a time...

For the present time I do not think that I need to be concerned about using OTA for updates of the device sketch; it can be thought of as a "strictly" one-way communication system from the remote sensor + datalogger, back to a remote dashboard.

Thanks for your interest and help.

Hmmm. I have a possible insight, let me know if I am on the right track:

If I want to be able to use an "Example" sketch in my WiFi setup, I am beginning to think that I need to cut-and-paste the appropriate parts of the original "Example" code into the "untitled_date_.ino" sketch that was generated by the Arduino Cloud Agent ..... so as to preserve the references to "thing.Properties.h". (and whatever other internal connections / hooks that the Agent has created to the Device, which I may not even be able to see).

If that is the case then it is very weird (see my original "2nd interesting observation") and confusing that I am getting that cryptic message about 'uploading a sketch via USB' which would require that the 'Cloud Agent is installed and running on this computer'. See screenshot, below:

If it is even possible to upload via USB ⸺from within the Cloud Agent ⸺ I cannot figure out how to do that (the "LEARN MORE" link doesn't help me). And how is it that the Agent would be sending this message, if it is already open and running (which is the case!)

To be clear, the "LEARN MORE" link tells one how to install the Cloud Agent. But (again!) it is the Cloud Agent that is sending me this link, so very confusing and circular! Rather like being in a hall of mirrors....

But I am noticing that the Serial Monitor button (upper right corner of the screen) is greyed-out in the Cloud Agent and when I hover over it with the Cursor, it says:

Serial port unavailable

No device connected via USB.

except, uh, the device is currently powered by a USB cable and clearly running and connected to the Cloud (etc etc).

Ok, if a sketch is uploaded over USB from the IDE, then it will overwrite the current content of the memory on the Renesas MCU on the board. Were you using the examples from within the IDE? (File -> Examples -> Examples for the UNO R4 WiFi sub-section). Or something found online?

As noted in the previous posts, any sketch that communicates with the cloud requires as follows:

At the beginning of the sketch:

#include "thingProperties.h"

In void setup you should have:

ArduinoCloud.begin(ArduinoIoTPreferredConnection);

In void loop you should have:

ArduinoCloud.update();

As you have already concluded, without those at minimum, no communication with the cloud would be possible. I believe that cloud provisioning also stores a security key along with your WiFi credentials on the ESP but my knowledge here is limited. Following the Re-install ESP32 firmware guide will have restored the ESP to its original factory state. Having re-provisioned it in the cloud means it has the credentials stored on it again.

Just a speculation, but if you uploaded a sketch that did not use the WiFiS3 library or was not designed for this board, then this may have configured the ESP in a way that conflicted with the cloud provisioning. It may also e worth noting that if you look at the description of the HX711 library you will see that the UNO R4 is not listed as a compatible board:

https://docs.arduino.cc/libraries/hx711-arduino-library/

It may or may not work depending on whether it uses code that is common C++ that works on all boards or whether low level MCU register manipulation is involved.

In a typical cloud sketch there are also statements relating to the "things" that you create within the cloud that might also have needed to be manually added in. In your example you have this function among other similar others:

void onRHumidityChange()  {
// Add your code here to act upon RHumidity change
}

This function relates to an event generated when a humidity value change is detected in your cloud 'thing'. At present it has no code, but if it did, the code within would run whenever your the humidity control configured in the cloud application was changed. So it might read a LED, read a sensor or show something on a display, whatever was needed to happen on the board in response to the control.

I am however a bit surprised that you can't update/push the sketch from the cloud editor. With that, along with tutorials, perhaps someone from the Arduino Team can help?

BTW, please don't post screenshots of code. They are usually difficult to read. Instead copy/paste the code and use the CODE tags (<CODE/>) at the top of the post editor window, to highlight it. Thanks.

I am 84. No I am not of Ukrainian lineage at all, I claim English, Scot and something like 6 or so generations of Canadian. My many great grandmother was the oldest citizen in the United Kingdom at 106. She walked from Montreal to approximately where I grew up in Hamilton, Ontario.
The reason for the Ukrainian colours is to support my sister in law who is not ony Ukrainian but is very active in that community travelling a lot throughout Canada to events and meetings. She is some sort of executive in some sort of Ukrainian organization.

Well! Very interesting and very encouraging to see you so active at 84!! Regardless of genetics and genealogy your support for your sister-in-law is surely appreciated (Slava Ukraini!)

You can and should rename that in the cloud editor. I am including attachments that show how to rename the THING and the sketch.

You keep mentioning the cloud agent. I installed it once years ago and never looked at it again. It isn't something we need to interact with. I drive a Max so mine is (see attach)

Now that you have the sketch, just add dials etc to your dashboard and hook the updates to them via the onChange event in the code you posted.

Thanks for your reply....it seems like I am beginning to get a handle on this! I will need to read over the details again.

Regarding the "BTW, please do not....", the reason for the screenshot was not to display the code (which also appears in the screenshot), but rather to show the Pop-Up window at the bottom (the black bar) while simultaneously proving that the Pop-Up window is occurring WITHIN the Cloud Agent itself (which is of course the main part of the background) !!!

As is visible in the rest of my Post, I make use of the "CODE" formatting where appropriate. In this case of the screenshot, the intention was not the legible display the .ino and *.h code (which does appear, appropriately formatted, elsewhere).

Is this the same cable that you used for the upload you mentioned earlier?

Which OS are you running on? I take it you have a Serial.begin(baudrate) somewhere in void setup()?

Noted. My mistake.

Hello again:

Thanks. I have actually renamed the sketches, Things and Devices at least once already.

But I was confused about the "USB" connection and the fact (or, what seems to be a fact) that I cannot toggle between WiFi connectivity and USB connection.

I have, just now, discovered that I needed to "Allow" the Agent to "access other services" etc when FireFox warned me about the Agent wanting that access (the other option was "Block", which is my default action).

Once I gave the Agent access, it suddenly gave me a new slider button at the top of the IDE, to choose between USB (left) and CLOUD (Right)

Not a problem! Thanks!

Also, I seem to have discovered the source of the curious "hall of mirrors" effect:

  1. I had blocked the Agent from accessing some resources (prompted by a FireFox security alert---see my reply to SonOfCy); and,
  2. the "error" messages that the Agent can display are not very specific / diagnostic and, in this case, the Agent should not be telling me that I should install the Agent ! (How weird is that? Did anybody think about the implications of that message, before they wrote it and made it available for display?!)

I don't see that toggle anywhere. What page is that on?

That is a convenient toggle, now Serial.print statements used for debuging can be seen. When I created a cloud project before I had to use MQTT I think as there was no way to use Serial since the board was not connected to anything but WiFi.
The particular MQTT library I used could send output to any commbination of Serial and MQTT. I would still use that for obvious reasons.

Can you do a ful screen grab to show me where that is, I can't find it.

Here is a screenshot: