text:
''Wire1' was not declared in this scope' in I2C_MPU6886 library
I recently purchased a 6-axis IMU MCP6886 module by M5Stack. Product link: https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/IMU_Unit. The example code provided by the manufacturer is as follows:
#include "I2C_MPU6886.h"

I2C_MPU6886 imu(I2C_MPU6886_DEFAULT_ADDRESS, Wire1);

void setup() {
  Serial.begin(115200);
  delay(1000);

  Wire1.begin(21, 22);

  imu.begin();
  Serial.print("whoAmI() = 0x%02x\n", imu.whoAmI());
}

void loop() {
  float ax;
  float ay;
  float az;
  float gx;
  float gy;
  float gz;
  float t;

  imu.getAccel(&ax, &ay, &az);
  imu.getGyro(&gx, &gy, &gz);
  imu.getTemp(&t);

  Serial.print("%f,%f,%f,%f,%f,%f,%f\n", ax, ay, az, gx, gy, gz, t);

  delay(100);
}

When I run this code on Arduino IDE 1.8.19, I get the following error: 'Wire1' was not declared in this scope. I believe this issue is with the I2C_MPU6886 library itself, but I am not able to troubleshoot it. I am using an Arduino Uno R3 board and running the IDE on Windows 11.

What CPU are you using?

I am using an Arduino Uno R3 board -- so... not an M5Stack...? So why are you using M5Stack code...?

"M5Stack" is an ecosystem of ESP32 based boards and peripherals.
All code for M5Stack peripherals is written for the M5Stack system. Not for the Uno.
You have to find code for the Uno, not for the M5Stack. M5Stack code will not work on the Uno since it is a completely different system.


text:
Create a library when using PlatformIO
(1) I'm trying to work with libraries in PlatformIO format", for , of a library, located in Arduino's libraries, where code is llocated under \src directry.
(2) Any other library, not it "PlatformIO format" as I call it, has to contain inside libraries/EXMPLE lib a EXMPLE.h, and EXMPLE.cpp file.
(3) Now, when I try to create a "PlatromIO format" library (since I want to move to PlatfromIO)
compilation fails, saying .h file was not found (an error you would get since .h .cpp was not located in their parent directory), as noted in 2 . see library ABCD in  (which contains only library structures).
Appreciate any help
Guy

You're describing "1.5.x" format libraries, not "PlatformIO". This arrangement for a library was created for Arduino IDE version 1.5.0.
The critical part of this library format is the library.properties file which describes the library, and also identifies it as being a library (and which you seem to be lacking). The format of the file is described here.

Well I suspected so, but it have to an url to GitHub ?

@guyd No, but if there is a web page associated with the library it should be included. It doesn't have to be github, that's just an example. I think url= is optional anyway.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Problem with "converting a string constant to 'char*'" in the WiFi library
error:
C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino: In function 'void setup()':

C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino:41:24:
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

   WiFi.begin(SSID, PASS);   //Begin WiFi
              ^     ^

code:
#include <DHT.h>
#include <WiFi.h>
#define DHTTYPE DHT11
#define DHTPIN 5

DHT dht(DHTPIN, DHTTYPE);

String msg = "GET /update?key=TWE505JXFTXDPNB3";
float temp;
char SSID;
char Pass;

int hum;

String tempC;

int error;
void updateTemp();
#define SSID "wifi name"

#define PASS "wifi pass"

#define IP "184.106.153.149"

void setup()
{
  dht.begin();
  Serial.begin(9600);
  delay(10);

  // Connect to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);     //Begin WiFi

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}

void loop() {
start:
  error = 0;

  temp = dht.readTemperature();
  hum = dht.readHumidity();

  char buffer[10];
  tempC = dtostrf(temp, 4, 1, buffer);
  updateTemp();

  if (error == 1) {
    goto start;
  }
  delay(5000);
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  Serial.println(cmd);
  delay(2000);

  if (Serial.find("Error")) {
    return;
  }
  cmd = msg ;
  cmd += "&field1=";
  cmd += tempC;
  cmd += "&field2=";
  cmd += String(hum);
  cmd += "\r\n";
  Serial.print("AT+CIPSEND=");
  Serial.println(cmd.length());

  if (Serial.find(">")) {
    Serial.print(cmd);
  }
  else {
    Serial.println("AT+CIPCLOSE");
    //Resend...
    error = 1;
  }

  Serial.println("AT+CWMODE=1");
  delay(2000);
}

boolean connectWiFi()
{
  String cmd = "AT+CWJAP=\"";
  cmd += SSID;
  cmd += "\",\"";
  cmd += PASS;
  cmd += "\"";
  Serial.println(cmd);
  delay(5000);

  if (Serial.find("OK")) {
    return true;
  }
  return false;
}

We need the full error message, including the information where the compiler found the problem in your code. Please add that to your question

C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino: In function 'void setup()':
C:\Users\mrtas\Desktop\sketch_may23a\sketch_may23a.ino:38:24: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
WiFi.begin(SSID, PASS);     //Begin WiFi
^
                      ^

Please add the error message to the question (click on “edit”) rather than as a comment. 2. This looks suspiciously like an issue of the WiFi library that was fixed five years ago. What version of the library are you using?

that's a warning, not an error ... does the compilation actually abort?

WiFi.h and AT commands mix? what are you doing?

i am working on a iot project and i found the code online .I am trying to fix it piece by  piece but i am not an expert in coding ,this is my first project i am still a student so if you can help  i would really  appriciate it

What is your hardware setup? Do you have a link to the place where you found the code?

This is a software issue. Hardware is irrelevant.

It's basically a bug in the library which is expecting "char *" when you are supplying "const char *.
You could work around it by changing:
#define SSID "wifi name"
#define PASS "wifi pass"

to:
char SSID [] =  "wifi name";
char PASS [] =  "wifi pass";

That makes them non-const so the error message should go away.
Not tested. But that is the general idea.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Error while uploading the sketch to Arduino UNO using CLI
I have connected my Arduino UNO through USB to Raspberry pi 3B. I am using CLI for editing, compiling and uploading sketches >  arduino-cli upload --fqbn arduino:avr:uno cli-test. However, after attempting to upload the sketch, it throws the error, Error during Upload: Failed uploading: no upload port provided I even checked if the Arduino is detected on the respective port using arduino-cli board list and it shows
/dev/ttyACM0 serial   Serial Port (USB) Arduino Uno arduino:avr:uno arduino:avr
/dev/ttyAMA0 serial   Serial Port       Unknown

The support forum of Arduino says to 'select' the port. Nevertheless the support forum resolves the error for GUI application and not for CLI. I searched for how to select the port in CLI, but in vain. Any help is appreciated.

https://arduino.github.io/arduino-cli/0.23/getting-started/#compile-and-upload-the-sketch

You specify the port with the --port flag to the upload command:
$ arduino-cli upload --fqbn arduino:avr:uno --port /dev/ttyACM0 cli-test

You can find all these things out for yourself by using --help at any time. For example:
$ arduino-cli upload --help
Upload Arduino sketches. This does NOT compile the sketch prior to upload.

Usage:
  arduino-cli upload [flags]

Examples:
  arduino-cli upload /home/user/Arduino/MySketch

Flags:
      --board-options strings        List of board options separated by commas. Or can be used multiple times for multiple options.
      --discovery-timeout duration   Max time to wait for port discovery, e.g.: 30s, 1m (default 1s)
  -b, --fqbn string                  Fully Qualified Board Name, e.g.: arduino:avr:uno
  -h, --help                         help for upload
      --input-dir string             Directory containing binaries to upload.
  -i, --input-file string            Binary file to upload.
  -p, --port string                  Upload port address, e.g.: COM3 or /dev/ttyACM2
  -P, --programmer string            Programmer to use, e.g: atmel_ice
  -l, --protocol string              Upload port protocol, e.g: serial
  -t, --verify                       Verify uploaded binary after the upload.

Global Flags:
      --additional-urls strings   Comma-separated list of additional URLs for the Boards Manager.
      --config-file string        The custom config file (if not specified the default will be used).
      --format string             The output format for the logs, can be: text, json, jsonmini, yaml (default "text")
      --log-file string           Path to the file where logs will be written.
      --log-format string         The output format for the logs, can be: text, json
      --log-level string          Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic
      --no-color                  Disable colored output.
  -v, --verbose                   Print the logs on the standard output.


text:
A bug with multiple IR detectors
I have a device power by arduino nano atmega328.
The idea of this HW is to detects dropped seed (corn, oil bean etc.) and to count it.
I wrote initial code, but id does not work in an expected way. it increments one count "channel" (I have 8 pairs of IR diodes 3mm) automatically, and passing it does not detect.
Here is the code maybe, someone has some similar experience and maybe help me to refactor the code.
#include<wire.h>
#include<Adafruit_SSD1306.h>

int irPin1 = 1;
int irPin2 = 2;
int irPin3 = 3;
int irPin4 = 4;
int irPin5 = 5;
int irPin6 = 6;
int irPin7 = 7;
int irPin8 = 8;

int count1,count2,count3,count4,count5,count6,count7,count8, count = 0;
boolean state = true;

void setup(){
  Serial.begin(9600);
}

void loop(){
if(!digitalRead(irPin1) && state)
 {
   count1++;
   state = false;
   Serial.print("count1: ");
   Serial.println(count1);
   delay(200);
 }

if(digitalRead(irPin1))
  {
    state=true;
    delay(100);
  }

if(!digitalRead(irPin2) && state)
 {
   count2++;
   state = false;
   Serial.print("count2: ");
   Serial.println(count2);
   delay(200);
 }

if(digitalRead(irPin2))
  {
    state=true;
    delay(100);
  }

  if(!digitalRead(irPin3) && state)
 {
   count3++;
   state = false;
   Serial.print("count3: ");
   Serial.println(count3);
   delay(200);
 }

if(digitalRead(irPin3))
  {
    state=true;
    delay(100);
  }

    if(!digitalRead(irPin4) && state)
 {
   count4++;
   state = false;
   Serial.print("count4: ");
   Serial.println(count4);
   delay(200);
 }

if(digitalRead(irPin4))
  {
    state=true;
    delay(100);
  }

 if(!digitalRead(irPin5) && state)
 {
   count5++;
   state = false;
   Serial.print("count5: ");
   Serial.println(count5);
   delay(200);
 }

if(digitalRead(irPin5))
  {
    state=true;
    delay(100);
  }
 if(!digitalRead(irPin6) && state)
 {
   count6++;
   state = false;
   Serial.print("count6: ");
   Serial.println(count6);
   delay(200);
 }

if(digitalRead(irPin6))
  {
    state=true;
    delay(100);
  }
 if(!digitalRead(irPin7) && state)
 {
   count7++;
   state = false;
   Serial.print("count7: ");
   Serial.println(count7);
   delay(200);
 }

if(digitalRead(irPin7))
  {
    state=true;
    delay(100);
  }

 if(!digitalRead(irPin8) && state)
 {
   count8++;
   state = false;
   Serial.print("count8: ");
   Serial.println(count8);
   delay(200);
 }

if(digitalRead(irPin8))
  {
    state=true;
    delay(100);
  }
count= count1+count2+count3+count4+count5+count6+count7+count8;
}

I work in platformIO.

One of the the things that stands out immediately is that you're using the serial TX pin for an IR sensor but also using Serial to send. The way you've asked the question, this isn't exactly an answer though.

When the delays are active nothing else is. Try using the millies instead.

@Gil can you elaborate more or give me an example? what are the milies are?

@timemage do you have another solution? which I should use instead TX and serial?Im also into that shorten the code to create some kind event to subscribe on it, and then to check which ir is triggered..

See the blinkWithoutDelay example for using millis() instead of delay(). This is also referred to as non-blocking code.

Digital pin 1 is used for serial TX. Avoid using it for any other purpose if you need it for serial. Allocate a different free pin for sensor 1.

you are trying to run before you can walk ... get this to work with only one sensor ... then try two sensors ... it is a waste of everyone's time, including yours, by asking about eight sensors if you can't get one to work

@jsotola One is working. but strange, only digitalRead(6), others shows that there is some obstacle beetween although is not any.

one working is good ... since the others are failing, work on each one separately

use the working sensor for testing each of the other pins

Use arrays instead of a copy/paste coding style.
Use millis() instead of delay() statements to eliminate blocking code.
Explicitly configure input pins.
compiles, but untested:
uint8_t irPin[ 8 ] = { 2, 3, 4, 5, 6, 7, 8, 9 } ; // set the sensor pins here . Avoid 0 and 1.
uint16_t seedCount[ 8 ] = { 0 } ;
uint32_t lastSeedAtMs[ 8 ] = { 0 } ;
const uint32_t lockOutTimeMs = 200UL ; // milliseconds - prevent 1 seed generating multiple counts

void setup() {
  Serial.begin(9600);
    for ( uint8_t channel = 0; channel < 8 ; channel++ ) {
      pinMode( irPin[ channel ] , INPUT_PULLUP ) ;  // configure all input pins
    }
}

void loop() {
  for ( uint8_t channel = 0; channel < 8 ; channel++ ) {
    if ( digitalRead( irPin[ channel ] ) == LOW ) {  // sensor active low
      if ( millis() - lastSeedAtMs[ channel ] > lockOutTimeMs )  {  // if X ms passed since last detection on this channel
        seedCount[ channel ] ++ ;
        lastSeedAtMs[channel ] = millis() ;
        Serial.print("count");
        Serial.print(channel);
        Serial.print(": ");
        Serial.println( seedCount[ channel ] );
      }
    }
  }
}


text:
Input Oscillating Wildly
I'm trying to read an input from a switch but instead of getting 0 and 1 for closed/open, I'm getting 0 and a rapid series of 1s and 0s. Originally I tried (and failed) to simply read a rotary encoder but when I swap it for a standard rocker switch or even connect wires directly then it's the same.
This is my first time trying to get an input into an Arduino so I'm probably missing something quite straightforward.
I've got ground going to one pin of the switch and pin 2 to the other.
Here's the code I'm using to see if the switch is on or off.
void setup() {
  pinMode (2, INPUT);
  Serial.begin(9600);
}

void loop() {
 Serial.println(digitalRead(2));
}

In addition to @Bra1n's answer, this sort of problem can also usually be solved by grounding the switch via a resistor.

Pins configured as INPUT are in a high impedance state and very sensitive to electrical noise from the environment, especially with wires connected to them See Arduino Tutorial
Try using INPUT_PULLUP in your pinMode statement.
Additionally you might want to investigate switch debouncing methods for when your switch is operated.

Yes PULLUP has solved it, thanks!!


text:
esp32, platformio A fatal error occurred: Packet content transfer stopped (received 8 bytes) *** [upload] Error 2
When i try to upload code to the esp32 the following error shows up in the command line:
A fatal error occurred: Packet content transfer stopped (received 8 bytes).
I use platformio in VScode the platform.ini file looks like this:
    [env:esp-wrover-kit]
    platform = espressif32
    board = esp-wrover-kit
    framework = arduino
    upload_port = COM4
    monitor_speed = 115200

Here's the code i'm trying to upload:
#include <Arduino.h>

void setup() {
    Serial.begin(115200);
    Serial.println("init");
}

void loop() {
}

It's an esp32-wrover-dev from freenove. When i unplug it and plug it back in it starts to write random stuff to the serial monitor, when i attempt an upload it stops but it also gives me the error above.

For anyone wondering, i found out it means that there's some kind of disconnect between the computer from which your uploading and the file system. Essentially, the esp32 is broken.

Reducing upload speed to 11520 worked for me.

I was able to resolve this issue by detaching jumpers that i had connected to the GPIO 12/13 pins during upload.
After uploading they can be attached again.
See this github issue: https://github.com/espressif/arduino-esp32/issues/2415

I was using GPIO 12 and detaching it worked for me.

I had this error when trying to upload a sketch from Arduino IDE to a TTGO T-Display, found that I could resolve this by changing the upload speed from the default of 921600 to 115200.
After doing that it uploaded just fine with no issues.

Hi all I found I got this error because my FTDI adapter was in 3.3V mode, not 5V as soon as I set it to 5V the issue was resolved and it programmed fine. One more thing to check before you scrap your ESP32.
Mick

so an est32 should be powered with 3.3 V. 5 V will damage it.

Hi I was using the CAM module which has pins marked as 5V so maybe dont do that if powering the IC direct. Apparently it has less issues at 5V. Thanks.


text:
ESP32 AsyncWebServer with softAP does not serve pages
I'm trying to create a AsyncWebServer after enabling the SoftAP:
#include <Arduino.h>
#include <SPIFFS.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

WebApp webapp;

void setup()
{
  Serial.begin(115200);
  SPIFFS.begin();

  File f = SPIFFS.open("/index.html");
  String s = f.readString();
  Serial.println(s);
  f.close();

  WiFi.softAP("ssid", NULL);
  WiFi.softAPsetHostname("ssid");
  Serial.println(WiFi.softAPIP());

  webapp.Begin();
}

void loop()
{
}

class WebApp
{
public:
    WebApp();
    void Begin();

private:
    AsyncWebServer _server;
};

#include "webapp.h"

WebApp::WebApp() : _server(80)
{
}

void WebApp::Begin()
{
  _server.on("/", HTTP_GET, [this](AsyncWebServerRequest *request)
  {
    Serial.println("GET request");
    _server.serveStatic("/", SPIFFS, "/").setDefaultFile("/index.html");
  });

  _server.onNotFound([](AsyncWebServerRequest *request){
    request->send(404);
  });

  _server.begin();
  Serial.println("[WEB] HTTP server started");
}

The SoftAP brings up the network and I can connect to it (softAPgetStationNum() tells me that 1 client is connected). It answers to pings.
The index.html is stored into the flash (the contents is printed out correctly).
But when I try to open the root page (192.168.4.1) it prints out "GET request" but the browser request timeouts and nothing is received.
Am I missing anything in the code?

The usage of serveStatic() is wrong. It's not intended to be used inside a callback. Just place the call in the setup of the webserver, i.e.:
void WebApp::Begin()
{
  _server.serveStatic("/", SPIFFS, "/").setDefaultFile("/index.html");

  _server.onNotFound([](AsyncWebServerRequest *request)
  {
    request->send(404);
  });

  _server.begin();
  Serial.println("[WEB] HTTP server started");
}

I don't have enough rep to make a comment on your post, but is it possible that when you give the parameter for the function setDefaultFile() that the forward slash on /index.html is causing the path of the file to be //index.html instead of /index.html.
Because serveStatic is probably appending the filename of setDefaultFile() to the root directory of / (the third parameter of serveStatic()), you're probably getting an extra character you don't want in your filepath.
TL;DR you don't need the / in index.html for setDefaultFile().
See https://github.com/me-no-dev/ESPAsyncWebServer#serving-files-in-directory for the example.

I'll try this as soon as possible. But in that case should not just fall into a 404?

Tried. It changes nothing. I can reach the page using the complete address (i.e. 192.168.4.1/index.html) but often the wdt triggers and the ESP32 reboots. The pages are very light, less than 6 kBytes

Reloading the page usually leads to 404

I confirm the issue is still there.


text:
How to make the compiler ensure that local variables memory allocation won't cause any RAM overflow during execution?
Upon compiling a sketch using the Arduino IDE, a message like the following gets displayed in the console:
Global variables use 1540 bytes (75%) of dynamic memory, leaving 508 bytes for local variables. Maximum is 2048 bytes.

In addition, it seems that if the global variables use exceeds around 75% of total dynamic memory, the following message gets displayed in addition:
Low memory available, stability problems may occur.

So, it seems that by using the IDE in a regular way, the compiler does not ensure that local variables memory allocation won't cause any RAM overflow during program execution. Instead, it just displays a warning message when little RAM is left for local variables.
This can lead to program malfunctions at execution time, if local variables happen to take up more space than the remaining RAM.
How can one have the compiler detect whether local variables memory allocation will cause RAM overflow during execution or not, and warn the user at compile time only in those specific cases?

the compiler knows nothing about the program's logic

How do you expect the compiler to guess what might happen in your program that relies on external stimulii to control its operation?

@Majenko I don't in general; yet there are many cases in which it should be obvious for the compiler that local variables are necessarily going to cause RAM overflow at execution time. I expect the compiler to be at least able to produce a compilation error in those obvious cases (cases that do not depend on any external stimulus).

and why do you ask it here on Arduino SE?

@Juraj Where else do you suggest?

maybe GCC developers mailing list

The underlying GCC might have an option to check during runtime whether the stack runs into used RAM, depending on its version. But I have no idea how to add such a potential option in the Arduino IDE. Please note that it slows down your sketch, because this check is most probably done each time the used stack space increases, that is at function/method calls or local variable allocations.

the compiler can detect early problems. running out of var space is a late problem. ex. at coding time, you can reserve 20 bytes for a user's name but then Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr. comes along and your well-laid plans don't pan out.

Look at it like this. If you have 2kB of RAM and 2 functions, a() and b(), each of which dynamically allocate 1.5kB, you may be OK. It depends.
It is definitely bad luck if b() calls a(), a() calls a() etc. If a() and b() are never active simultaneously it may work. If b() calls a() depending on user input at runtime, the compiler can't see that.

You are describing "memory profiling" and is not typically a feature of C or C++.  It is more common in higher level languages, such as Java, but C is a considered a much lower level language.
Typically such profiling is done at runtime using external tools such as valgrind and massif.
It's not really possible for the compiler to work out what your program will be doing when it is using external data and inputs to control how it works. Any such tests at compile time would be pretty much meaningless since any that pass in testing may still cause problems at runtime depending on what else may be happening at the same time, or even what may have happened in the past (see heap fragmentation).


text:
RFM9x LoRa Radio code will compile with Uno but not Nano Every
I have code involving the use of an Adafruit Ultimate GPS Breakout v3 and an Adafruit RFM95W LoRa Radio that will compile with an Uno Rev3 but not with a Nano Every. The code I'm using comes almost directly from the examples provided by Arduino. I tried just the GPS code using the GPS_SoftwareSerial_Parsing test from Arduino and that worked, but I when I try using the Feather9x_TX code from Arduino it does not and I am not sure why. I am new to using Arduinos and have little experience with coding. I have attempted to search my error messages but have not been able to really find any answers so any help would be useful.
Here's the code
#include <SPI.h>
#include <RH_RF95.h>

#define RFM95_CS 9
#define RFM95_RST 8
#define RFM95_INT 2

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup()
{
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }

  delay(100);

  Serial.println("Feather LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

int16_t packetnum = 0;  // packet counter, we increment per xmission

void loop()
{
  delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
  Serial.println("Transmitting..."); // Send a message to rf95_server

  char radiopacket[20] = "Hello World #      ";
  itoa(packetnum++, radiopacket+13, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
  radiopacket[19] = 0;

  Serial.println("Sending...");
  delay(10);
  rf95.send((uint8_t *)radiopacket, 20);

  Serial.println("Waiting for packet to complete...");
  delay(10);
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  Serial.println("Waiting for reply...");
  if (rf95.waitAvailableTimeout(1000))
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))
   {
      Serial.print("Got reply: ");
      Serial.println((char*)buf);
      Serial.print("RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);
    }
    else
    {
      Serial.println("Receive failed");
    }
  }
  else
  {
    Serial.println("No reply, is there a listener around?");
  }

}

And here are the errors
Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano Every, None (ATMEGA4809)"

C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp: In member function 'virtual void RHHardwareSPI::attachInterrupt()':
C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp:49:25: error: 'virtual void SPIClassMegaAVR::attachInterrupt()' is private within this context

     SPI.attachInterrupt();
                         ^

In file included from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RadioHead.h:731:0,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RHGenericSPI.h:10,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RHHardwareSPI.h:10,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp:7:

C:\Users\jfeze\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\SPI\src/SPI.h:186:15: note: declared private here

   inline void attachInterrupt() { SPI0.INTCTRL |= (SPI_IE_bm); }
               ^~~~~~~~~~~~~~~

C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp: In member function 'virtual void RHHardwareSPI::detachInterrupt()':
C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp:56:25: error: 'virtual void SPIClassMegaAVR::detachInterrupt()' is private within this context

     SPI.detachInterrupt();
                         ^

In file included from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RadioHead.h:731:0,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RHGenericSPI.h:10,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead/RHHardwareSPI.h:10,
                 from C:\Users\jfeze\Documents\Arduino\libraries\RadioHead\RHHardwareSPI.cpp:7:

C:\Users\jfeze\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\libraries\SPI\src/SPI.h:187:15: note: declared private here

   inline void detachInterrupt() { SPI0.INTCTRL &= ~(SPI_IE_bm); }
               ^~~~~~~~~~~~~~~

Multiple libraries were found for "RH_RF95.h"
 Used: C:\Users\jfeze\Documents\Arduino\libraries\RadioHead
 Not used: C:\Users\jfeze\Documents\Arduino\libraries\RadioHead-master
exit status 1

Error compiling for board Arduino Nano Every.

what is your specific question?

So far as I can tell, the library simply incompatible with your board. The functions they're trying to use are essentially commented as "don't use these" in the core(s). In the megaavr core that the Nano Every uses they were made private:.  For what it's worth, the functions they're used from appear to be in turn used nowhere in the project. So, I commented out the calls. However the library fails to compile owing to other differences in architecture. Basically you need a port for the megaavr core. I do not have a suggestion one for. You may not actually need RadioHead at all though.


text:
Serial ports grayed out when Arduino plugged in (MS Surface Pro X, Windows 10 Pro 21H2). How do I get Arduino IDE to recognize them?
I am helping a Windows user program an Arduino application. The computer is a Surface Pro X running Windows 10 Pro 21H2. It only has USB-C ports (which cannot be used to power or program Arduinos) so he's using this USB-C hub and a USB-type A to USB-C cable to program it. The Arduino is a Sparkfun Artemis Redboard (Cortex M4).
When he connects the Arduino to the Surface Pro, the Arduino powers up as normal, but no serial ports are visible in the Arduino IDE, and the serial port line remains grayed out.
By contrast, the same USB-C hub, cable, and Arduino can be programmed by a Mac. I run Linux and don't know anything about USB port access on either Mac or Windows, but I got the impression that manually installing drivers should not be necessary on either.
Any advice on how to get the Arduino IDE to recognize this as a serial port when plugged in to a Surface Pro?

A Mac is based on Unix/Linux.  I believe you can open a console on a Mac and type the Linux command lsusb to list the attached USB devices just like you do on a Linux box.  On the Win10 box ... I would consult the Sparkfun web site and discover if there is any special drivers that need to be installed to prompt Win10 to create a serial port.  Also, you may try to connect A USB device that you know will generate a serial port to test if the HUB you are using on the Sur/Pro/10 is actually working as expected.

Do you get the typical USB chime when you insert the device? Because if you don't, if it doesn't list at all in Device Manager, even temporarily, even as an unrecognized USB device, then the drivers are not a problem to worry about (yet anyway).  USB devices have to work well for the operating system in order to get USB device descriptor for it to even know what driver it should be trying to load.

Consider running through this Sparkfun Hookup Guide for the SparkFun RedBoard Artemis.  There is a section dealing with this problem:

My Nano is not showing up as a COM port?!
Most Artemis carrier boards use the CH340C IC which is not affected by
this issue. This issue is only for the Nano that uses the much smaller
CH340E.


text:
Accessing HTTPS server of ESP8266 through fetch
I have been messing around with this application for a while but seem to keep hitting roadblocks. I am trying to have a public HTTPS page make a fetch to a private ESP8266.
As you can guess I ran into several infamous CORS issues and had to become with these posts: https://developer.chrome.com/blog/private-network-access-update/
https://web.dev/cors-rfc1918-feedback/
https://wicg.github.io/private-network-access/
After reading this I became persuaded that I needed to have an HTTPS server on my ESP8266 because this is the only way that the CORS policy would allow me to make a request from a public page to a private one. My issue now is that Chrome will allow these requests with a self-signed certificate on the ESP8266, but Firefox (which didn't throw any errors about this until very recently) blocked my request because the certificate was self-signed.
Is there any easy way to have a trusted certificate (i.e. something not self-signed) on my ESP8266 so that both Chrome and Firefox will allow this request?
If not, what is the most appropriate way to allow HTTPS connections to come to my ESP8266 without having to have a user trust the self-signed certificate in their browser?

https://unix.stackexchange.com/questions/644176/how-to-permanently-add-self-signed-certificate-in-firefox

you can use a web server (or a package like node-red) as a proxy. the esp talks to the server, your browser listens to the server. you can also use websockets, which don't have as much scheme and domain restriction.


text:
PlatformIO - Creating a library including a 3rd party library
I'm using PlatformIO, and I'm trying to create a library who uses another library in it.
(1) For that I created an empty library called ABCD.h stored in a newrep github repository.
(2) 3rd party library chosen is Panda_segmentBed_I2C.h with no particular reason.
(3) That library was inserted as needed to lib_deps and initiate build update the newly create library that it pulled 3rd party library as needed, as shown in pic1
(4) ABCD.h includes #include <Panda_segmentBed_I2C.h>
(5) Now to simulate a use of ABCD.h library inside a code, I've created a new project called TEST_NEWREP. Only 1 line was added to project:  #include <ABCD.h>
(6) After running build I get an error that 3rd party library, inside ABCD.h is not found.
(7) see TEST_NEWREP tree:

**Edit 1 - update .gitignore **
Somehow, when Project is created, a default .gitignore includes an ignore of .pio library. Perhaps in some cases it should be ignored, but when that Project is a library, it does not upload .pio\libdeps. Now after the exclude is removed, all dependencies are pulled as needed when build the project, BUT STILL ERROR REMAINS THAT Panda_segmentBed_I2C.h is not found.

You main.cpp should be in the same source directory with ABCD.h and ABCD.cpp (as a local library), and you declare it as #include "ABCD.h" in your main.cpp.

@hcheung but main.cpp is not part of library files.

You don't need to mess with the .gitignore, when compiling the code, the platformIO will download the library based on your libdeps configuration in your platformio.ini file.

If ABCD.h is a separate library, then you only need to set up the libdeps in your platformio.ini to use it. From the first picture you shown, the ABCD.h is not an independent library, but a local file to the project newrep.


text:
ESP8266 - Can't upload or use Serial Monitor - Ubuntu 22.04 LTS
When trying to use the ESP8266 Node MCU or Multiple Feather Huzzah's I get the following error. I can program Arduino Uno & Mega without issue.
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

I have tried all the many fixes on the web, the real issue is that all of these devices work fine with a windows machine. Also I use VMM and QEMU, I built a Windows 10 VM and Ubuntu 20.04 - When I share ttyS0 with either of these VM's I can program the 8266 just fine, but I can not directly from my host running 22.04. I can work with the VM's but I would rather not.
Any help would be appreciated.
Thank you

I'm curious to know whether or not you can connect to an already programmed board and get serial data in and out of it.

all of these devices work fine with a windows ... then your problem is with linux serial port ... nothing to do with Arduino ... you are asking at the wrong place

is it this problem? https://arduino.stackexchange.com/questions/86211/fail-upload-sketches-to-esp8266-only-on-ubunto-20-04-3/86214#86214

@timemage - I had the same issue will 4 esp8266's all had code running on them. The issue ended up being a conflict or something with the CP210x driver. I found this solution in a separate post - it fixed my issue and I was able to replicate and validate this worked on a second 22.04 machine.

I found this solution in a separate post - it fixed my issue and I was able to replicate and validate this worked on a second 22.04 machine.
systemctl stop brltty-udev.service
sudo systemctl mask brltty-udev.service
systemctl stop brltty.service
systemctl disable brltty.service


text:
How to convert a reading to percentage in Arduino
I am using this example on how to use a photoresistor to detect the value of light that the sensor is getting but I want to convert the reading of the resistor to a percentage but I can't use the map() function from the Arduino docs but I can implement something similar to it
so I created this simple function
float photo_resistor(int pinNum)
{
    float reading = analogRead(pinNum);
    if (reading == 54)
    {
     return 0.0;
    }
    return (reading - 54)/(100/920);

}

as in the docs I want to use an output range from 0 to 100 and the minimum reading i got is 54 and the maximum is 974
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// this becomes (x - 54)*(100 - 0 ) / ( 974 - 54) + 0;
// (x-54)/(100/920);

but this does not output a value from on the scale from 0-100

your question is about arithmetic, not about Arduino

think of a basket that can hold 20 apples maximum ... there are 6 apples in the basket ... how full is the basket, expressed in percent?

You wrote:

return (reading - 54)/(100/920);

In C++, 100/920 is zero. This is because, when both operands are
integers, the division operator performs an integer division. You can
overcome this problem by making sure that at least one of the operands
is a floating point number. For instance, 100.0/920 is roughly 0.1087.
However, your division is backwards. You probably mean
return (reading - 54) * (100.0/920);

I'd use return max(0.0, min(100.0, (reading-54.0)*(100.0/920))); -- this makes sure that no values outside the range 0.0 .. 100.0 are ever returned, even when another photoresistor with slightly different tolerances is being used.


text:
TVout characters don't line up
I am messing around with the Arduino TVout library and I have created some multi-character tiles (I don't know what else to call them). Just to start out, I created a simple X that spans across 4 characters but when I print them to the screen they align correctly.
How they should align:

How they really align:

Here is the code I have so far:
Main file:
#include "expressions.h"
#include <TVout.h>

TVout win;
unsigned char x = 0, y = 0;

void setup() {
  win.begin(NTSC);
  win.select_font(expr8x8);
}

void loop() {
  win.clear_screen();
  x = 2, y = 5;
  print_char(0, x, y);

  win.delay(1);
}

void print_char(char c, int startx, int starty) {
  int tmpx = startx, tmpy = starty;
  for (char i = c; i < c + 4; i++) {
    win.print_char(tmpx * 8, tmpy * 8, i);
    if (++tmpx == c + 2) {
      tmpy++;
      tmpx = startx;
    }
  }
}

expressions.h
#define EXPRESSIONS8x8_H

#include <avr/pgmspace.h>
extern const unsigned char expr8x8[];

expressions.cpp
#include "expressions.h"

PROGMEM const unsigned char expr8x8[] = {
  8, 8, 0, // width, height, start

  // broken
  0x00, 0x00, 0x30, 0x38, 0x1c, 0x1e, 0x07, 0x03,
  0x00, 0x00, 0x0c, 0x1c, 0x38, 0x70, 0xe0, 0xc0,
  0x03, 0x07, 0x0e, 0x1c, 0x38, 0x38, 0x00, 0x00,
  0xc0, 0xc0, 0x70, 0x38, 0x1c, 0x0c, 0x00, 0x00,

  // happy
  0x00, 0x00, 0x00, 0x00, 0x07, 0x1f, 0x38, 0x70,
  0x00, 0x00, 0x00, 0x00, 0xe0, 0xf8, 0x1c, 0x0e,
  0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00
};

Is there something I am doing wrong? How do I fix this bug/issue?

Less lines of code would be to just have 4 prints, one for each character.

I believe your problem is in this line:
if (++tmpx == c + 2) {

Here you are mixing two different things:

c is a character code, i.e. the index of a glyph within the
expr8x8 font
tmpx is the index of a character cell (a 8×8 block of pixels) within
a line of the screen

Comparing those makes little sense. And in fact, the comparison will
always be false, as c is zero, and tmpx starts at 2 and increases
from there.
I guess what you meant was:
if (++tmpx == startx + 2) {


text:
Why are raw data bytes not converting to ASCII, but only in one part of my program?
I am writing a program to read from the Atlas Scientific EZO-HUM, -O2, and -CO2 sensors simultaneously via the I2C protocol with an Arduino Uno. The sensors all work, but for some reason, just the O2 sensor data does not convert to ASCII text. Below is my program:
#include <Ezo_i2c.h>
#include <Ezo_i2c_util.h>
#include <iot_cmd.h>
#include <sequencer1.h>
#include <sequencer2.h>
#include <sequencer3.h>
#include <sequencer4.h>
#include <Wire.h>                //enable I2C.

#define HUM_address 111          //default I2C ID number for EZO Humidity sensor.
#define O2_address 108           //default I2C ID number for EZO O2 sensor.
#define CO2_address 105          //default I2C ID number for EZO CO2 sensor.

//EZO-HUM vars
//   | |
//   V V
char computerdata[32];           //we make a 32 byte character array to hold incoming data from a pc/mac/other.
byte received_from_computer = 0; //we need to know how many characters have been received.
byte serial_event = false;       //a flag to signal when data has been received from the pc/mac/other.
byte code = 0;                   //used to hold the I2C response code.
char Humidity_data[22];          //we make a 22-byte character array to hold incoming data from the Humidity sensor.
byte in_char = 0;                //used as a 1 byte buffer to store inbound bytes from the Humidity  sensor.
byte i = 0;                      //counter used for Humidity_data array.
int time_ = 1000;                 //used to set the delay needed to process the command sent to the EZO Humidity sensor.

//EZO-CO2 vars
//   | |
//   V V
//char CO2_computerdata[20];           //we make a 20 byte character array to hold incoming data from a pc/mac/other.
byte CO2_received_from_computer = 0; //we need to know how many characters have been received.
byte CO2_serial_event = false;       //a flag to signal when data has been received from the pc/mac/other.
byte CO2_code = 0;                   //used to hold the I2C response code.
char CO2_data[20];               //we make a 20-byte character array to hold incoming data from the Co2 sensor.
byte CO2_in_char = 0;                //used as a 1 byte buffer to store inbound bytes from the Co2 sensor.
byte CO2_i = 0;                      //counter used for Co2_data array.
//int CO2_time_ = 1000;                 //used to set the delay needed to process the command sent to the EZO Co2 sensor.
int Co2_int;                     //int var used to hold the value of the Co2.

//EZO-O2 vars
//   | |
//   V V
//char O2_computerdata[20];           //we make a 20 byte character array to hold incoming data from a pc/mac/other.
byte O2_received_from_computer = 0; //we need to know how many characters have been received.
byte O2_serial_event = false;       //a flag to signal when data has been received from the pc/mac/other.
byte O2_code = 0;                   //used to hold the I2C response code.
char O2_data[20];                //we make a 20-byte character array to hold incoming data from the o2 sensor.
byte O2_in_char = 0;                //used as a 1 byte buffer to store inbound bytes from the o2 sensor.
byte O2_i = 0;                      //counter used for o2_data array.
//int O2_time_ = 600;                 //used to set the delay needed to process the command sent to the EZO o2 sensor.

char *HUM;                       //char pointer used in string parsing.
char *TMP;                       //char pointer used in string parsing.
char *NUL;                       //char pointer used in string parsing (the sensor outputs some text that we don't need).
char *DEW;                       //char pointer used in string parsing.
char *O2_reading;
char *O2_reading_2;

float HUM_float;                 //float var used to hold the float value of the humidity.
float TMP_float;                 //float var used to hold the float value of the temperatur.
float DEW_float;                 //float var used to hold the float value of the dew point.
float O2_float;
float CO2Con_float;

void setup()                    //hardware initialization.
{
  Serial.begin(9600);           //enable serial port.
  Wire.begin();                 //enable I2C port.
  while(!Serial);            //wait for serial monitor to be open
}

void serialEvent() {                                                              //this interrupt will trigger when the data coming from the serial monitor(pc/mac/other) is received.
  received_from_computer = Serial.readBytesUntil(13, computerdata, 22);           //we read the data sent from the serial monitor(pc/mac/other) until we see a <CR>. We also count how many characters have been received.
  computerdata[received_from_computer] = 0;                                       //stop the buffer from transmitting leftovers or garbage.
  serial_event = true;                                                            //set the serial event flag.
}

void loop() {                                                                     //the main loop.
  if (serial_event == true) {                                                     //if a command was sent to the EZO device.
    for (i = 0; i <= received_from_computer; i++) {                               //set all char to lower case, this is just so this exact sample code can recognize the "sleep" command.
      computerdata[i] = tolower(computerdata[i]);                                 //"Sleep" ≠ "sleep"
    }
    i=0;                                                                          //reset i, we will need it later

 //---------------------------------------------------------EZO-HUM Sensor-----------------------------------------------------------------------------//
    Wire.beginTransmission(HUM_address);                                              //call the circuit by its ID number.
    Wire.write(computerdata);                                                     //transmit the command that was sent through the serial port.
    Wire.endTransmission();                                                       //end the I2C data transmission.

// Need to talk to each sensor separately. Because they're all Atlas Scientific EZO sensors, they all respond to the same commands

    if (strcmp(computerdata, "sleep") != 0) {                                     //if the command that has been sent is NOT the sleep command, wait the correct amount of time and request data.
                                                                                //if it is the sleep command, we do nothing. Issuing a sleep command and then requesting data will wake the Humidity  sensor.

      delay(time_);                                                               //wait the correct amount of time for the circuit to complete its instruction.

      Wire.requestFrom(HUM_address, 22, 1);                                           //call the circuit and request 22 bytes.
      code = Wire.read();                                                         //the first byte is the response code, we read this separately.

      switch (code) {                       //switch case based on what the response code is.
        case 1:                             //decimal 1.
          Serial.println("HUM Success");        //means the command was successful.
          break;                            //exits the switch case.

        case 2:                             //decimal 2.
          Serial.println("HUM Failed");         //means the command has failed.
          break;                            //exits the switch case.

        case 254:                           //decimal 254.
          Serial.println("HUM Pending");        //means the command has not yet been finished calculating.
          break;                            //exits the switch case.

        case 255:                           //decimal 255.
          Serial.println("HUM No Data");        //means there is no further data to send.
          break;                            //exits the switch case.
    }

    while (Wire.available()) {              //are there bytes to receive.
      in_char = Wire.read();                //receive a byte.
      Humidity_data[i] = in_char;           //load this byte into our array.
      //Serial.println((int)in_char);
      i += 1;                               //incur the counter for the array element.
      if (in_char == 0) {                   //if we see that we have been sent a null command.
        i = 0;                              //reset the counter i to 0.
        break;                              //exit the while loop.
      }
    }
    if (computerdata[0] == 'r') string_pars();    //uncomment this function if you would like to break up the comma separated string into its individual parts.
  }

 //---------------------------------------------------------EZO-O2 Sensor-----------------------------------------------------------------------------//

    Wire.beginTransmission(O2_address);                                           //call the circuit by its ID number.
    Wire.write(computerdata);                                                     //transmit the command that was sent through the serial port.
    Wire.endTransmission();                                                       //end the I2C data transmission.

    if (strcmp(computerdata, "sleep") != 0) {                                     //if the command that has been sent is NOT the sleep command, wait the correct amount of time and request data.
                                                                                //if it is the sleep command, we do nothing. Issuing a sleep command and then requesting data will wake the Humidity  sensor.

      delay(time_);                                                               //wait the correct amount of time for the circuit to complete its instruction.

      Wire.requestFrom(O2_address, 22, 1);                                           //call the circuit and request 22 bytes.
      O2_code = Wire.read();                                                         //the first byte is the response code, we read this separately.

      switch (O2_code) {                       //switch case based on what the response code is.
        case 1:                             //decimal 1.
          Serial.println("O2 Sensor Success");        //means the command was successful.
          break;                            //exits the switch case.

        case 2:                             //decimal 2.
          Serial.println("O2 Sensor Failed");         //means the command has failed.
          break;                            //exits the switch case.

        case 254:                           //decimal 254.
          Serial.println("O2 Sensor Pending");        //means the command has not yet been finished calculating.
          break;                            //exits the switch case.

        case 255:                           //decimal 255.
          Serial.println("O2 Sensor No Data");        //means there is no further data to send.
          break;                            //exits the switch case.
    }

    while (Wire.available()) {              //are there bytes to receive.
      O2_in_char = Wire.read();                //receive a byte.
      O2_data[i] = O2_in_char;           //load this byte into our array.
      Serial.println((int)O2_in_char);
      Serial.println(O2_data);
      i += 1;                               //incur the counter for the array element.
      if (O2_in_char == 0) {                   //if we see that we have been sent a null command.
        i = 0;                              //reset the counter i to 0.
        break;                              //exit the while loop.
      }
    }
//    Serial.print("O2 Concentration:");                      //This code doesn't output any information, although the program receives bytes which display in the while loop.
//    Serial.println(O2_data);
//    Serial.println();

    if (computerdata[0] == 'r') O2_string_pars();             //This code also doesn't output any information.
  }

 //---------------------------------------------------------EZO-CO2 Sensor-----------------------------------------------------------------------------//

    Wire.beginTransmission(CO2_address);                                          //call the circuit by its ID number.
    Wire.write(computerdata);                                                     //transmit the command that was sent through the serial port.
    Wire.endTransmission();                                                       //end the I2C data transmission.

    if (strcmp(computerdata, "sleep") != 0) {                                     //if the command that has been sent is NOT the sleep command, wait the correct amount of time and request data.
                                                                                //if it is the sleep command, we do nothing. Issuing a sleep command and then requesting data will wake the Humidity  sensor.

      delay(time_);                                                               //wait the correct amount of time for the circuit to complete its instruction.

      Wire.requestFrom(CO2_address, 22, 1);                                           //call the circuit and request 22 bytes.
      CO2_code = Wire.read();                                                         //the first byte is the response code, we read this separately.

      switch (CO2_code) {                       //switch case based on what the response code is.
        case 1:                             //decimal 1.
          Serial.println("CO2 Sensor Success");        //means the command was successful.
          break;                            //exits the switch case.

        case 2:                             //decimal 2.
          Serial.println("CO2 Sensor Failed");         //means the command has failed.
          break;                            //exits the switch case.

        case 254:                           //decimal 254.
          Serial.println("CO2 Sensor Pending");        //means the command has not yet been finished calculating.
          break;                            //exits the switch case.

        case 255:                           //decimal 255.
          Serial.println("CO2 Sensor No Data");        //means there is no further data to send.
          break;                            //exits the switch case.
    }

    while (Wire.available()) {              //are there bytes to receive.
      CO2_in_char = Wire.read();                //receive a byte.
      CO2_data[i] = CO2_in_char;           //load this byte into our array.
      //Serial.println((int)CO2_in_char);
      i += 1;                               //incur the counter for the array element.
      if (CO2_in_char == 0) {                   //if we see that we have been sent a null command.
        i = 0;                              //reset the counter i to 0.
        break;                              //exit the while loop.
      }
    }
    Serial.print("CO2 Concentration:");
    Serial.println(CO2_data);
  }

  serial_event = false;                     //reset the serial event flag

//  if (computerdata[0] == 'r') string_pars();    //uncomment this function if you would like to break up the comma separated string into its individual parts.
}
   }

void string_pars() {                        //this function will break up the CSV string into its 3 individual parts. HUM|TMP|DEW.
                                            //this is done using the C command “strtok”.

  HUM = strtok(Humidity_data, ",");         //let's pars the string at each comma.
  TMP = strtok(NULL, ",");                  //let's pars the string at each comma.
  NUL = strtok(NULL, ",");                  //let's pars the string at each comma (the sensor outputs the word "DEW" in the string, we dont need it.
  DEW = strtok(NULL, ",");                  //let's pars the string at each comma.

  Serial.println();                          //this just makes the output easier to read by adding an extra blank line.

  Serial.print("HUM:");                      //we now print each value we parsed separately.
  Serial.println(HUM);                       //this is the humidity value.

  Serial.print("Air TMP:");                  //we now print each value we parsed separately.
  Serial.println(TMP);                       //this is the air temperatur value.

  Serial.print("DEW:");                      //we now print each value we parsed separately.
  Serial.println(DEW);                       //this is the dew point.
  Serial.println();

  //uncomment this section if you want to take the values and convert them into floating point number.
  /*
    HUM_float=atof(HUM);
    TMP_float=atof(TMP);
    DEW_float=atof(DEW);
  */
}

void O2_string_pars() {                        //this function will break up the CSV string
                                            //this is done using the C command “strtok”.

  O2_reading = strtok(O2_data, ",");         //let's pars the string at each comma.
//  O2_reading_2 = strtok(NULL, ",");

  Serial.println();                          //this just makes the output easier to read by adding an extra blank line.

  Serial.print("O2 Concentration: ");
  Serial.println(O2_reading);
//  Serial.println("O2 extra info: ");
//  Serial.print(O2_reading_2);

}

The following is the output from the program:

HUM Success
HUM:45.39
Air TMP:23.61
DEW:11.16
O2 Sensor Success
50
48
46
56
53
0
O2 Concentration:
CO2 Sensor Success
CO2 Concentration:599

Because in your code you are specifically printing the integers?

If you read the program, I am printing the array containing the bytes in the line below the command to print the individual bytes as they are entered into O2_data. These prints output blank lines. I tried replicating the EZO-HUM's string_pars() function for the EZO-O2's outputs, which also outputs blanks. I don't have this issue with either of the other two sensors.

What is i at the start of your receiving loop?

If you mean at the start of the "EZO-O2 Sensor" section, it has been reset to 0 after receiving a NULL command from the EZO-HUM sensor at the end of that sensor's respective section. At least, that's how I'm reading it.

Are you sure of that? Print what i is to make certain.

I printed i in all three segments - HUM, O2, and CO2. The counter did not reset after the HUM segment, but it did after the O2 segment. This was related to the way the EZO-HUM's example code was written. It asked for a 22-byte character from the sensor, resetting the array counter when receiving a "0" byte. Long story short, 22 bytes would cut off the NULL command sent by the sensor, and changing 'Wire.requestFrom(HUM_address, 22, 1);' to 'Wire.requestFrom(HUM_address, 23, 1);' fixed it. Thank you @Majenko !

note: use the name computer_data to have a consistent naming convention throughout your program

You are relying on a NULL byte being received to reset your i pointer variable. If that NULL never arrives for whatever reason you won't be writing your new data to the start of your next array.
You should always reset the counter before receiving new data regardless of what you have just received.


text:
ESP32 access point with an ENC28J60 ethernet module
Does anyone know if the following is possible? Any advice would be much appreciated.
I am programming an Ethernet connected Arduino to be a webserver. What would be ideal is a small portable "router" so I can take the whole test setup and my laptop without depending on my home/company network.
My idea:

Set up an ESP32 as an access point
Connect an ENC28J60 module to it

I hope:

My laptop can connect to the ESP over WiFi (status: done)
My board can connect over UTP
They both get IP addresses
I can test the Arduino webserver from my laptop

What I found is that I could use the Ethercard for ESP32 or the [EthernetENC][2] libraries.
I've been trying with EthernetENC, but no luck. Is this even possible?

This is my minimal code for the ESP32 so far:
#include <WiFi.h>
#include <SPI.h>
#include <EthernetENC.h>

const char* ssid = "ESP32router01";
const char* pass = "01234567";          // At least 8 characters

void setup() {
  WiFi.softAP(ssid, pass);
  Ethernet.init(5);
}

void loop() {
}

remove the Arduino and the ENC28J60 from the project

https://forum.arduino.cc/t/adapter-for-ethernet-shield-to-communicate-on-wifi/529679/3

esp8266 Arduino supports routing between network interfaces and supports enc28j60 as network interface in WiFi library. STA and SofftAP are the network interfaces you know. I don't know if it supports routing for the 'new' network interlaces

@Juraj : Thanks, the TL-WR702N would be the easy/convenient way, I'll consider that. But I also have an ESP8266  at hand so I can explore your suggestion.

I'm still planning on doing this project and have found: https://github.com/martin-ger/esp_wifi_repeater#enc28j60-ethernet-support - This library supports an ENC28J60 ethener adapter so that's what I'll be trying, I don't know when but I'll try to post my findings.

Did you figure it out? I have a similar problem.


text:
How often should we poll the 74HC165 if we wish to detect 'button' presses?
I am going to either chain 4 shift registers, or connect 4 shift registers to an ESP32 that is connected to a computer with bluetooth.
I understand at 3.3 volts, the 74HC165 can run at a clock speed of up to 18mhz. (5mhz at 2v, 25mhz at 4v).
What is normal for monitoring events on the shift registers? Is it normal to endlessly poll the shift registers? Or is a short delay between each read possible and/or desirable?
I cant imagine a reason for wanting to check for "events" (button presses, etc...) 1 million times per second. We could I guess, I just don't know if we should.
(I am new to the ESP32, so I am not sure how maintaining a bluetooth connection impacts things)

your question can easily be answered by you running some test code and pressing buttons ... it's not a question about Arduino, so it is off topic here ... questions about optimum sampling intervals belong at https://electronics.stackexchange.com/questions

I was going to ask why this downvoted (I dont really understand why) but then I looked at the "Top questions" tab and see most questions are downvoted ♂

it was probably downvoted because the Arduino is irrelevant to your question ... you could be using a PIC chip or a PC or a Raspberry Pi or any of the many development boards and your question would not change

@jsotola Im not sure if thats true though? I didn't think I was asking an electronics question, because I am not sure how bluetooth and other activities on the ESP32 impact or don't impact reading from the chip. (For example, I don't know if reading from the buttons is interrupted by bluetooth events? Maybe it does? Maybe it doesnt? I just don't know what I dont know about programming these things yet.)

For this you can employ the nyquist-shannon theory for signal sampling.
In short it states that "to sample a signal frequency of X you need at least 2x X samples per second".
So if you know how long a button will be pressed for (or released for, whichever is faster, i.e., the "highest frequency component of interest") then you know you need to sample with an interval of at most half that time.
So for a button that you may press for 100ms you know you need to sample at most every 50ms, preferably faster.

Thank you! that gives me a logical way to think through the numbers. The only thing that is not clear, then, from an electronics perspective (battery consumption, EMF, etc... ) do people tend to sample as infrequently as possible, or will the ESP32/74HC165 use basically the same power either way?
(Apologies if these are basic questions, I am primarily a coder, enjoying exploring building basic electronic devices)

@Jay most people don't over think it unless they're doing something battery operated with sleep modes. As long as you do it fast enough just do whatever makes sense for your program. It makes no difference from a power consumption perspective unless you're sleeping.

Yes, it's pretty normal to endlessly poll the buttons. Even the original NES controller did it exactly that way, its protocol works exactly like you'd talk to a shift register. Majenko alredy gave an answer on a good polling frequency, here's the additional hardware you'd need to work with interrupts instead of polling:
You'd need to add a bunch of OR gates (or AND gates if your buttons pull down instead of up) in "parallel" to your shift registers, so that you've got one signal with the semantics "(at least) one of the buttons have been pressed".
This signal then can be connected to the SH/LD input of your shift registers, triggering the shift registers to load (i.e. sample and hold) the inputs. In addition, it needs to be connected to one GPIO of your Arduino/ESP, to which you connect an interrupt handler on the software side. That interrupt handler then polls the shift register once (or sets a flag that causes your main loop to poll it). You may need an additional gate and GPIO to allow the polling routine to keep SH/LD HIGH while polling, depending on your use case and how bouncy your buttons are.
You could even use that signal to wake the ESP from deep sleep, poll the buttons once, do whatever needs to be done as a reaction to that button, then go back to deep sleep.
In conclusion: Endless polling is mostly the way to go, because of the hardware overhead to implement an interrupt solution.


text:
Assign a list of char *
Explain in a simple example. How to pass a char* to a function?
#define name1 "ABCD"
#define name2 "EFGH"
#define name3 "HIJK"

char *list[3] = {};

void printList(char *l, int x) {
  for (int i = 0; i < x; i++) {
    Serial.println(l[i]);
  }

}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("start");
  list[0] = name1;
  list[1] = name2;
  list[2] = name3;

  printList(list, 3);

}

void loop() {
  // put your main code here, to run repeatedly:

}

I get an error:
/home/guy/Documents/Dropbox/Arduino/sketch_jun12a/sketch_jun12a.ino: In function 'void setup()':
sketch_jun12a:24:13: error: cannot convert 'char**' to 'char*'
   24 |   printList(list, 3);
      |             ^~~~
      |             |
      |             char**
/home/guy/Documents/Dropbox/Arduino/sketch_jun12a/sketch_jun12a.ino:7:22: note:   initializing argument 1 of 'void printList(char*, int)'
    7 | void printList(char *l, int x) {
      |                ~~~~~~^
exit status 1
cannot convert 'char**' to 'char*'

You're trying to pass an array of char * to a function that is expecting a single char *.

@Majenko AFAIK anyway you pass only  pointer for the first cell of the array,  or am I wrong ?

Just change this:
void printList(char *l, int x) {

to this:
void printList(char **l, int x) {

OK, this deserves some explanation...
In C and C++, when you use (not when you define) an array
identifier, it decays to a pointer to its first element. In
this case,
char *list[3] = {};

is an array of pointers to char. When you use it here:
printList(list, 3);

it decays to a pointer to pointer to char. Thus the double * needed
in the parameter declaration.
Side note: to get really correct C++, you should replace every
instance of char by const char. This is because the characters in
question belong to string literals, and you are not allowed to modify a
string literal at run time.


text:
Enable full float-capable snprintf() library with PlatformIO
I want to use snprintf() to format floats to a string.
I know the "normal" version of Arduino's avrlibc had all the float-formatting code removed to make it smaller.
I also know that at some point in the fairly recent past, it became possible to force gcc to use an alternate (forked?) larger Arduino avrlibc that had all the float-formatting functionality that was originally removed put back in.
However... I'm still trying to find an actual explanation of how to do that for an Arduino project using PlatformIO.
I found a clue someplace where someone said, "change linker rules in platform.txt file to enable floating point xxprintf()" (which hopefully enables floating point support in other float-to-string functions as well).
Problem #1: platform.txt appears to be global rather than local to this one project. There's no file named "platform.txt" anywhere in the project's directory.
Problem #2: I do have several dozen files on my computer named platform.txt... I don't know which one is the one that actually matters to PlatformIO, and I don't know enough about PlatformIO's internals to know how to figure out which platform.txt is the one that matters.
Problem #3: Even if I manage to figure out which platform.txt is the one I need to modify, I still don't know what exact modifications actually need to be made.

Update: I stumbled over a thread in Arduino's Issue discussion ("Sprintf for floats on Arduino Mega 293") that said to append the text quoted further down to boards.txt. The relevant line appears to be mega.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
So... I'm guessing that what I need to put somewhere in platform.txt (once I figure out which platform.txt is the one that matters) is -Wl,-u,vfprintf -lprintf_flt
##############################################################

menu.printf=AVR printf Version
menu.scanf=AVR scanf Version

yun.menu.printf.default=Default printf
yun.menu.printf.default.avr_printf_flags=
yun.menu.printf.full=Full printf
yun.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
yun.menu.printf.minimal=Minimal printf
yun.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

yun.menu.scanf.default=Default scanf
yun.menu.scanf.default.avr_scanf_flags=
yun.menu.scanf.full=Full scanf
yun.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
yun.menu.scanf.minimal=Minimal scanf
yun.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

yun.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

uno.menu.printf.default=Default printf
uno.menu.printf.default.avr_printf_flags=
uno.menu.printf.full=Full printf
uno.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
uno.menu.printf.minimal=Minimal printf
uno.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

uno.menu.scanf.default=Default scanf
uno.menu.scanf.default.avr_scanf_flags=
uno.menu.scanf.full=Full scanf
uno.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
uno.menu.scanf.minimal=Minimal scanf
uno.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

uno.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

diecimila.menu.printf.default=Default printf
diecimila.menu.printf.default.avr_printf_flags=
diecimila.menu.printf.full=Full printf
diecimila.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
diecimila.menu.printf.minimal=Minimal printf
diecimila.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

diecimila.menu.scanf.default=Default scanf
diecimila.menu.scanf.default.avr_scanf_flags=
diecimila.menu.scanf.full=Full scanf
diecimila.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
diecimila.menu.scanf.minimal=Minimal scanf
diecimila.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

diecimila.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

nano.menu.printf.default=Default printf
nano.menu.printf.default.avr_printf_flags=
nano.menu.printf.full=Full printf
nano.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
nano.menu.printf.minimal=Minimal printf
nano.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

nano.menu.scanf.default=Default scanf
nano.menu.scanf.default.avr_scanf_flags=
nano.menu.scanf.full=Full scanf
nano.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
nano.menu.scanf.minimal=Minimal scanf
nano.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

nano.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

mega.menu.printf.default=Default printf
mega.menu.printf.default.avr_printf_flags=
mega.menu.printf.full=Full printf
mega.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
mega.menu.printf.minimal=Minimal printf
mega.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

mega.menu.scanf.default=Default scanf
mega.menu.scanf.default.avr_scanf_flags=
mega.menu.scanf.full=Full scanf
mega.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
mega.menu.scanf.minimal=Minimal scanf
mega.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

mega.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

megaADK.menu.printf.default=Default printf
megaADK.menu.printf.default.avr_printf_flags=
megaADK.menu.printf.full=Full printf
megaADK.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
megaADK.menu.printf.minimal=Minimal printf
megaADK.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

megaADK.menu.scanf.default=Default scanf
megaADK.menu.scanf.default.avr_scanf_flags=
megaADK.menu.scanf.full=Full scanf
megaADK.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
megaADK.menu.scanf.minimal=Minimal scanf
megaADK.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

megaADK.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

leonardo.menu.printf.default=Default printf
leonardo.menu.printf.default.avr_printf_flags=
leonardo.menu.printf.full=Full printf
leonardo.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
leonardo.menu.printf.minimal=Minimal printf
leonardo.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

leonardo.menu.scanf.default=Default scanf
leonardo.menu.scanf.default.avr_scanf_flags=
leonardo.menu.scanf.full=Full scanf
leonardo.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
leonardo.menu.scanf.minimal=Minimal scanf
leonardo.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

leonardo.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

micro.menu.printf.default=Default printf
micro.menu.printf.default.avr_printf_flags=
micro.menu.printf.full=Full printf
micro.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
micro.menu.printf.minimal=Minimal printf
micro.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

micro.menu.scanf.default=Default scanf
micro.menu.scanf.default.avr_scanf_flags=
micro.menu.scanf.full=Full scanf
micro.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
micro.menu.scanf.minimal=Minimal scanf
micro.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

micro.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

esplora.menu.printf.default=Default printf
esplora.menu.printf.default.avr_printf_flags=
esplora.menu.printf.full=Full printf
esplora.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
esplora.menu.printf.minimal=Minimal printf
esplora.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

esplora.menu.scanf.default=Default scanf
esplora.menu.scanf.default.avr_scanf_flags=
esplora.menu.scanf.full=Full scanf
esplora.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
esplora.menu.scanf.minimal=Minimal scanf
esplora.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

esplora.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

mini.menu.printf.default=Default printf
mini.menu.printf.default.avr_printf_flags=
mini.menu.printf.full=Full printf
mini.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
mini.menu.printf.minimal=Minimal printf
mini.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

mini.menu.scanf.default=Default scanf
mini.menu.scanf.default.avr_scanf_flags=
mini.menu.scanf.full=Full scanf
mini.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
mini.menu.scanf.minimal=Minimal scanf
mini.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

mini.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

ethernet.menu.printf.default=Default printf
ethernet.menu.printf.default.avr_printf_flags=
ethernet.menu.printf.full=Full printf
ethernet.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
ethernet.menu.printf.minimal=Minimal printf
ethernet.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

ethernet.menu.scanf.default=Default scanf
ethernet.menu.scanf.default.avr_scanf_flags=
ethernet.menu.scanf.full=Full scanf
ethernet.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
ethernet.menu.scanf.minimal=Minimal scanf
ethernet.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

ethernet.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

fio.menu.printf.default=Default printf
fio.menu.printf.default.avr_printf_flags=
fio.menu.printf.full=Full printf
fio.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
fio.menu.printf.minimal=Minimal printf
fio.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

fio.menu.scanf.default=Default scanf
fio.menu.scanf.default.avr_scanf_flags=
fio.menu.scanf.full=Full scanf
fio.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
fio.menu.scanf.minimal=Minimal scanf
fio.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

fio.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

bt.menu.printf.default=Default printf
bt.menu.printf.default.avr_printf_flags=
bt.menu.printf.full=Full printf
bt.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
bt.menu.printf.minimal=Minimal printf
bt.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

bt.menu.scanf.default=Default scanf
bt.menu.scanf.default.avr_scanf_flags=
bt.menu.scanf.full=Full scanf
bt.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
bt.menu.scanf.minimal=Minimal scanf
bt.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

bt.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

LilyPadUSB.menu.printf.default=Default printf
LilyPadUSB.menu.printf.default.avr_printf_flags=
LilyPadUSB.menu.printf.full=Full printf
LilyPadUSB.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
LilyPadUSB.menu.printf.minimal=Minimal printf
LilyPadUSB.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

LilyPadUSB.menu.scanf.default=Default scanf
LilyPadUSB.menu.scanf.default.avr_scanf_flags=
LilyPadUSB.menu.scanf.full=Full scanf
LilyPadUSB.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
LilyPadUSB.menu.scanf.minimal=Minimal scanf
LilyPadUSB.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

LilyPadUSB.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

lilypad.menu.printf.default=Default printf
lilypad.menu.printf.default.avr_printf_flags=
lilypad.menu.printf.full=Full printf
lilypad.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
lilypad.menu.printf.minimal=Minimal printf
lilypad.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

lilypad.menu.scanf.default=Default scanf
lilypad.menu.scanf.default.avr_scanf_flags=
lilypad.menu.scanf.full=Full scanf
lilypad.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
lilypad.menu.scanf.minimal=Minimal scanf
lilypad.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

lilypad.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

pro.menu.printf.default=Default printf
pro.menu.printf.default.avr_printf_flags=
pro.menu.printf.full=Full printf
pro.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
pro.menu.printf.minimal=Minimal printf
pro.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

pro.menu.scanf.default=Default scanf
pro.menu.scanf.default.avr_scanf_flags=
pro.menu.scanf.full=Full scanf
pro.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
pro.menu.scanf.minimal=Minimal scanf
pro.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

pro.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

atmegang.menu.printf.default=Default printf
atmegang.menu.printf.default.avr_printf_flags=
atmegang.menu.printf.full=Full printf
atmegang.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
atmegang.menu.printf.minimal=Minimal printf
atmegang.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

atmegang.menu.scanf.default=Default scanf
atmegang.menu.scanf.default.avr_scanf_flags=
atmegang.menu.scanf.full=Full scanf
atmegang.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
atmegang.menu.scanf.minimal=Minimal scanf
atmegang.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

atmegang.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

robotControl.menu.printf.default=Default printf
robotControl.menu.printf.default.avr_printf_flags=
robotControl.menu.printf.full=Full printf
robotControl.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
robotControl.menu.printf.minimal=Minimal printf
robotControl.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

robotControl.menu.scanf.default=Default scanf
robotControl.menu.scanf.default.avr_scanf_flags=
robotControl.menu.scanf.full=Full scanf
robotControl.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
robotControl.menu.scanf.minimal=Minimal scanf
robotControl.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

robotControl.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

robotMotor.menu.printf.default=Default printf
robotMotor.menu.printf.default.avr_printf_flags=
robotMotor.menu.printf.full=Full printf
robotMotor.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
robotMotor.menu.printf.minimal=Minimal printf
robotMotor.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

robotMotor.menu.scanf.default=Default scanf
robotMotor.menu.scanf.default.avr_scanf_flags=
robotMotor.menu.scanf.full=Full scanf
robotMotor.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
robotMotor.menu.scanf.minimal=Minimal scanf
robotMotor.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

robotMotor.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

gemma.menu.printf.default=Default printf
gemma.menu.printf.default.avr_printf_flags=
gemma.menu.printf.full=Full printf
gemma.menu.printf.full.avr_printf_flags=-Wl,-u,vfprintf -lprintf_flt
gemma.menu.printf.minimal=Minimal printf
gemma.menu.printf.minimal.avr_printf_flags=-Wl,-u,vfprintf -lprintf_min

gemma.menu.scanf.default=Default scanf
gemma.menu.scanf.default.avr_scanf_flags=
gemma.menu.scanf.full=Full scanf
gemma.menu.scanf.full.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_flt
gemma.menu.scanf.minimal=Minimal scanf
gemma.menu.scanf.minimal.avr_scanf_flags=-Wl,-u,vfscanf -lscanf_min

gemma.compiler.c.elf.extra_flags={avr_printf_flags} {avr_scanf_flags}

##############################################################

Update 2:
I found what appears to be the solution & posted it as my own answer, but I'm going to hold off for a day or two to test it thoroughly and make sure it actually works.

For the record, both the “normal” and the “alternate” avr-libc are parts of the regular avr-libc. From the documentation of <stdio.h>: “In order to allow programmers a code size vs. functionality tradeoff, the function vfprintf() which is the heart of the printf family can be selected in different flavours using linker options.”

I finally found the answer at https://github.com/sstaub/LCDi2c
When using PlatformIO, add the following line to platformio.ini to enable full support for floats to printf():
build_flags = -Wl,-u,vfprintf -lprintf_flt -lm
Caution:
This solution increases the amount of required flash by at least 2k. If you're using a Mega2560, you probably have flash to burn and really don't care. If you're using an Uno, Leonardo, Nano, or some other smaller AVR-based variant... it might matter, and you might have to care.
Tip: if the Nano/Leonardo/Uno doesn't have enough flash or SRAM, but you don't have space for a full-blown Mega2560, consider the "Arduino Nano Every". It uses the ATMega4809, with 48k flash and 6k SRAM.


text:
Fluctuation in 4 half bridge load cell via combinator
I'm currently using a Sparkfun 4 Half-Bridge load sensor (50 Kg) with combinator and amplifier both are from the Sparkfun. Link:https://www.sparkfun.com/products/10245 (For Load Sensors)https://www.sparkfun.com/products/13878 (Combinator)
https://www.sparkfun.com/products/13879 (HX711)
Our application requires long-term use i.e 8 to 10 hours of load application and monitoring the weight change during this time. Is this possible to achieve the above requirement using these chips/amplifiers? As we have experienced a drift in the readings if a weight is placed for more than approx. 3 minutes.
We are using 4 half-bridge sensors, a combinator, and an amplifier.The issues I am tackling right now are,

Zero balance: Load sensor value exponentially increases or decreases after calibration(this is a cyclic thing and keeps happening). The error ranges usually from -20g to +40g.
Drift in reading: When the load is placed and kept for more than 3 minutes a drift is observed which increases with time and rises up to 50 to 60g.
Can you please assist in this matter?
have used different libraries. Results are the same.

how much weight is placed on the sensors?

@jsotola 9.2kg.

Can you post the minimal code that demonstrates each of your issues? Also a photograph showing the setup?

What is your anticipated error range based on the sensor data sheet and amplification? e.g., creep, zero drift, noise

Consider a change in temperature either the cause or partially the cause for weight drift.  This supplier web page talks about load cell temperature compensation.  There they consider a 2000lb load cell.  Their chart infers a 20 degree Fahrenheit change can cause an temperature uncompensated load cell to change about 1.5lb.

I took precautions and tried to maintain the same temperature throughout the test. So I don't think temperature is an issue in my case. Could it be the HX711? @st2000

If this answer does not solve your problem consider un-accepting it so that others may offer alternative solutions.  If you like this answer you can always up-vote it. There are many possible sources for fast and slow unexpected changes. Temperature is just one. Bad or under-rated power supplies is another. Bad voltage references. Air currents (many balances are built inside an enclosure). Vibrations (some balances are built with heavy bases). Also, you did not say over what period of time you saw variation. Or the total weight of the mass you tested with. This may help to answer you question.

Thanks for replying @st2000. Performed a couple of tests. The duration of the tests was between 40 to 60 minutes.
1)Zero balance test.
2)Full Scale
for zero balance the fluctuation was from -2 to 9 within 5 minutes and the maximum and minimum peak experienced in an hour were -4 to +12.
And the full-scale error was almost 50g over 1 hour.

Until you solve this problem, I do recommend un-accepting the my answer (and, if you like, vote it up) to encourage others to offer alternative solutions.  2. It is encouraged for you to edit your question to make it clearer as to what you are asking.  I would add the test weight of 9.2kg and the above times. 3. Where the changes random (i.e. 0g, -4g, 8g. 2g ...) or were they slow showing a trend (i.e. 0g, 2g, 6g, 8g ...)?


text:
Cannot make https request on esp32
I have esp32 cam. I want to send https request to azure function. I have exposed https port via ngrok.
HTTPClient http;

if (http.begin("https://4b21-31-183-241-151.eu.ngrok.io/", rootCACertificate)) { //Specify the URL and certificate
  int httpCode = http.GET();                                                  //Make the request

  if (httpCode > 0) { //Check for the returning code

      String payload = http.getString();
      Serial.println(httpCode);
      Serial.println(payload);
    }

  else {
    Serial.println("Error on HTTP request");
  }

  http.end(); //Free the resources
} else {
  Serial.println("Cannot begin");
}

I have generated cert as openssl s_client -showcerts -connect 4b21-31-183-241-151.eu.ngrok.io
http.begin returns 1, but http.GET() returns -1.
I want to do it with minimal effort. I saw that HttpClient allows https, so I don't need explicitly init WiFiClientSecure.
What I'm doing wrong?


text:
NodeMCU ESP8266 - Which pins can I use?
I'm trying to connect 3 LEDs to a LoLin NodeMCU ESP8266. It seems that several or "all" of the digital pins have some special use that prevents me from using them.

If I connect the LEDs (and set pinmode to output) to D0, D1 and D2, then the blue bootloading LED will glow constantly, and the code does not seem to run at all (nothing in serial output).
D3 seems to constantly have high power, regardless what I code it to.
If I connect the LEDs (and set pinmode to output) to D1, D2 and D4, then the blue bootloading LED will glow constantly, and the serial output is garbled, but I guess the code is running.
If I connect the LEDs (and set pinmode to output) to D5, D6 and D7, then the blue bootloading LED will glow constantly, and the serial output is garbled, but I guess the code is running.

Yes, I have checked the baud rate, that's not the problem.
What's up with this?

This link at projecthub says:

In order to use digital pins, you should select GPIO numbers. For example, the D7 pin is defined as GPIO13. So you should set up the pin number 13 whenever you want to use D7 in your program. Also, you can use pin D2(GPIO4) as SDA and pin D1(GPIO5) as SCL


text:
Controlling Bluetooth voice-controlled car with ultrasonic sensor
I am trying to use an ultrasonic sensor to stop a tiny voice-controlled car but I can't get it to work. once the motor starts moving it doesn't stop I'm trying to make the car stop moving even though it is already in motion. I need help writing a proper if statement or while loop to make the motor stop when there is an obstacle in its path.
#include <SoftwareSerial.h>

SoftwareSerial BT(0, 1); //TX, RX respetively
String readvoice;
int IN1= 3;
int IN2= 4;
int IN3= 5;
int IN4= 6;
int trigpin= 12;
int echopin= 11;
int pingTraveltime;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(trigpin, OUTPUT);
pinMode(trigpin, OUTPUT);

}
//-----------------------------------------------------------------------//
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
readvoice += c; //build the string- "forward", "reverse", "left" and "right"
digitalWrite(trigpin,LOW);
delayMicroseconds(10);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
pingTraveltime=pulseIn(echopin,HIGH);
Serial.println(pingTraveltime);
}
if (readvoice.length() > 0) {
Serial.println(readvoice);

if(readvoice == "*forward#")
{
while(pingTraveltime>500){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
}

else if(readvoice == "*back#" )
{
digitalWrite(IN1, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN4,HIGH);
}

else if (readvoice == "*left#")
{
digitalWrite (IN1,HIGH);
digitalWrite (IN2,LOW);
digitalWrite (IN3,LOW);
digitalWrite (IN4,LOW);

}

else if ( readvoice == "*right#")
{
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);

}

else if (readvoice == "*stop#")
{
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);
}

readvoice="";}} //Reset the variable

first thing to do, format the code properly ... please use correct indent levels for each block ... you can press ctrl-T in the Arduino IDE for auto format


text:
Read State from Variable
I am attempting to use radio modules to receive a value from a sensor, either 1 or 0, and complete an action. The only problem is that I would like the action to only complete once per state change, instead of every time (if it activates when the variable is 0, only activate again when the variable changes to 1.) Despite the != sign, the code inside the if statement will not activate even if the variables are reading 0 and 1.
// Keyboard - Version: Latest
#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_sv_SE.h>
#include <SPI.h>
#include "RF24.h"

RF24 myRadio (7, 8);
int mag = 2;
int prevState = 1; // 0=open, 1=closed

byte addresses[][6] = {"0"};

void setup()
{
  Serial.begin(9600);
  Keyboard.begin();
  delay(1000);

  myRadio.begin();
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ;
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}

struct package
{
  int val;
};

typedef struct package Package;
Package data;

void loop()
{
  if ( myRadio.available())
  {
    while (myRadio.available())
    {
      myRadio.read( &data, sizeof(data) );
    }
    // Serial.print("state: ");
    Serial.println(data.val);
    int state = digitalRead(data.val);
    // Serial.print("prevState: ");
    // Serial.println(prevState);
    // Serial.print("\n");

    if (state != prevState) {
      Keyboard.press(' ');
      delay(50);
      Keyboard.press(KEY_LEFT_GUI);
      delay(50);
      Keyboard.press('D');
      delay(50);
      Keyboard.releaseAll();
      Serial.println("Executed successfully.");

      prevState = state;
    }
  }
  delay(1000);
}

Try int prevState = -1; //-1= not initialized, 0=open, 1=closed

The payload of the radio packet appears to be the number of the digital pin on which the sensor is attached: int state = digitalRead(data.val); Is that what you intend?

please copy and paste the content of the serial console to your question above ... please no screenshots

Just out of curiosity, why are you including key definitions for the Danish, German, Spanish, French, Italian and Swedish keyboard layouts?

Consider using an enum for prevState instead of values 0, -1, 1; it makes the program easier to read/maintain.


text:
How to do 'for' loop over inline anonymous array
I have a bunch of pins given names in the header:
#define DIP5 53
#define DIP4 52
#define DIP3 51
#define DIP2 50
#define DIP1 49
#define DIP0 48

If it's not obvious, I have a bunch of DIP switches connected to digital pins 48..53 on an Arduino Mega2560
In setup(), I need to set them all to INPUT_PULLUP. I know it would probably be less total effort to just do a series of pinMode commands, like:
pinMode(DIP5, INPUT_PULLUP);
pinMode(DIP4, INPUT_PULLUP);
// ... and so on

... but I'm trying to enrich my C++ skills & be fancy, so I'm trying to figure out how to declare an anonymous array and foreach through it... something like:
for (int pin : {DIP5, DIP4, DIP3, DIP2, DIP1, DIP0}) {
    pinMode(pin, INPUT_PULLUP);
}

... which, presumably, the compiler will optimize away into 6 inline pinMode commands anyway, but let me feel good about having pretty source code ;-)
except... when I try it, I get the following error:
error: deducing from brace-enclosed initializer list requires #include <initializer_list>
... but when I add #include <initializer_list>, I get a different error:
fatal error: initializer_list: No such file or directory
Any ideas what's wrong?
also... can I safely assume that the compiler will just unroll the whole thing behind the scenes, or is there a real risk it will actually declare a real array in SRAM just to iterate through one time?

define an array dip[0], dip[1] ....

As for the "risk" of an array being created in SRAM, that would anyway be destroyed when the function in which it is defined, typically setup(), exits. If you explicitly define an array, you can still scan it with a C++11 range based for loop, which may improve the program's aesthetics.

I'm trying to enrich my C++ skills & be fancy

The Arduino Mega is probably not the right platform to learn fancy C++.
The development environment doesn't support all the modern C++ stuff. In
particular...

fatal error: initializer_list: No such file or directory

...it rests on avr-libc, which is a C library with only limited support
for C++.

can I safely assume that the compiler will just unroll the whole
thing behind the scenes

No, you can't. The Arduino IDE, by default, calls avr-gcc with the -Os
flag, which means “optimize for code size”. Loop unrolling is the kind
of space vs. speed trade-off the compiler is unlikely to do with this
optimization setting. You can disassemble the .elf file if you want to
know for sure.

is there a real risk it will actually declare a real array in SRAM
just to iterate through one time?

I suggest you follow jsotola's advice and declare the array yourself.
You can declare the array PROGMEM if you want to avoid wasting RAM.
But given that it need not take more than 6 bytes (as uint8_t[]),
I would personally not even bother.

Edgar Bonet answers why for (int pin : {DIP5, DIP4, DIP3, DIP2, DIP1, DIP0}) { isn't working. What you would get (where supported) with this syntax is an initializer_list which itself is not an array type, although it is backed by an array.
If you really did want to do something like that with an AVR-based Arduino you could do:
for (int pin : (const int []){DIP5, DIP4, DIP3, DIP2, DIP1, DIP0}) {
    pinMode(pin, INPUT_PULLUP);
}

This is technically not standard C++. It is the use of something called a compound-literal, which is being used to make an array typed value. This is a feature of C language feature (from C99 onward), not C++. However, the compiler and its configuration for Arduino allows its use as a language extension.
Should you do this? Perhaps not, for the reasons that Edgar, 6v6gt, and jsotola point out.  However, this much can be done if you really wanted. With respect to what it's doing efficiency-wise, you should test it.