text:
I2C_Anything ++
a request for information has been formulated, how to say it?
in Ascii: i2C dialog: Tx -----> Rx ----> PCF8574
a drawing
https://nsm09.casimages.com/img/2023/02/28/23022802163423870818122937.jpg
3 elements on the i2C bus

an Arduino "Tx" to read values from an electric counter
an Arduino "Rx" to recycle the values and also to dialogue on a Rs485 bus
and a PCF8574 which receives the commands from the Arduino "Rx" to operate telestage relays

1st question:
I2C_writeAnything (foo1);
(foo2);
(foo3);
I2C_writeAnything (foo X?);

What is the maximum number of foo1 .. foo2 ...foo10 that I can put ?
Is this the right method?
or do we have to group them by pack?
2nd question:
when we use several libraries, in their sketch we find calls to #include <Wire.h>
that are added to the main sketch.
Can this be a cause of problems?
thanks
Arduino "Tx" for electrical measurements (simulation with a "random")

void loop()  {

unsigned long foo1 = random(2294967295);
unsigned long foo2 = random(2294967295);
unsigned long foo3 = random(2294967295);
unsigned long foo4 = random(2294967295);
unsigned long foo5 = random(2294967295);

if (timer0.available()) {
Wire.beginTransmission (SLAVE_ADDRESS);

I2C_writeAnything (foo1);
I2C_writeAnything (foo2);
I2C_writeAnything (foo3);
I2C_writeAnything (foo4);
I2C_writeAnything (foo5);

Wire.endTransmission ();

if (!Wire.endTransmission ()) { Serial.println ("endTransmission () : "); }
timer0.restart();
}
} /*Loop*/

//Arduino "Rx" for reading and using the Electrical values
#include <Wire.h>
#include <I2C_Anything.h>           //http://www.gammon.com.au/i2c
const byte MY_ADDRESS = 42;

volatile boolean haveData = false;
volatile unsigned long foo1;
volatile unsigned long foo2;
volatile unsigned long foo3;
volatile unsigned long foo4;

#include "PCF8574.h"                //https://github.com/RobTillaart/Arduino/tree/master/libraries/PCF8574
PCF8574 PCF27a (0x3D);  // adjust addresses i2c pcf8574

//...setup
//...loop

void receiveEvent (int howMany)  {

// if (howMany >=  4)
if (howMany >=  (sizeof foo1))    {
I2C_readAnything (foo1);
I2C_readAnything (foo2);
I2C_readAnything (foo3);
I2C_readAnything (foo4);

haveData = true;
}
}  // end of receiveEvent

What exactly do you mean with limit? The limit for data transferred in a single transaction is the size of the buffer in the Wire library. And the second question is not readable. Please edit your question to make it clear what you are asking

yes I have modified my text
thanks Chris

Can this be a cause of problems? ... you did not say anything about problems

Including libraries wil only generate problems if there is an incompatability with something in the rest of your code. Did you see any problems? Why do you think this might be a problem? You need to include Wire, since you are using it for the I2C communication.

Please format your code properly, especially repair the indentation.

The test assembly works, but after an hour or two the communication remains frozen.
A reset on the Arduino and it starts again.
I made a test by adding in the setup this line :
Wire.setWireTimeout(3000,true);
https://www.fpaynter.com/2020/07/i2c-hangup-bug-cured-miracle-of-miracles-film-at-11/
and my assembly works well, no more blocking.
I just have to find how to manage my data by 32bytes packets.

A return on the module of Electrical measurements.
with an i2C bus.
(it can be useful for other people)
No more errors, no more blocking, it purrs like a kitten.
For the structure I copied the work of Peter_n (thanks to you)
it helped me a lot:
https://forum.arduino.cc/t/i2c-not-sending-all-data-with-i2c_anything/293609
and for the :  Wire.setWireTimeout(3000,true);
not sure where to put it, it's put on both parts.
a copy of the sketches
Master_I2C_Anything_Linky_uneStructure_bigOctes.ino
  // base Written by Nick Gammon - May 2012 :
// struct de Peter_n : https://forum.arduino.cc/t/i2c-not-sending-all-data-with-i2c_anything/293609

//------------------ Dialogue on i2c bus between 2 ATMega328 - Arduino-Uno ------------
// --- 2x6 32-bit values  ou 1x 7
//------------------   functional test model ---------------------------
// Add in setup :  Wire.setWireTimeout(3000,true);

  #include <Wire.h>
  #include <I2C_Anything.h>   //http://www.gammon.com.au/i2c

  const byte SLAVE_ADDRESS = 42;

  #include "Timers.h"         //https://github.com/nettigo/Timers
  Timer timer0;   // delay

//------------  struct -------------------------
//------------ linky info ---- 7 types de variables --------//

  struct sensorData_STRUCT {
  byte sensorNumber;
    uint16_t A;   // uint16_t PAPP in VA
    uint32_t B;   // uint32_t BASE index in Wh
    uint32_t C;   // uint32_t HCHC index heures creuses en Wh
    uint32_t D;   // uint32_t HCHP Index heures pleines en Wh
    uint8_t E;    // uint8_t  IINST  Returns in Amp
    uint8_t F;    // uint8_t ISOUSC  Returns ISOUSC
    uint8_t G;    // uint8_t PTEC Periode tarifaire en cours (0 = HP, 1 = HC)
     uint8_t H;    // test
  } sensorData[1]; // [x] number of structures

//---------------------- SETUP --------------------
void setup() {
  Serial.begin (115200);
  Serial.println(F(" Master_I2C_Anything_Linky_structure_double.ino "));
  Serial.print(__DATE__); Serial.println(__FILE__);

  Wire.begin ();

  Wire.setWireTimeout(3000,true);

  // fill fixed data
  sensorData[0].sensorNumber = 0;
 // sensorData[1].sensorNumber = 1; //desactivé

  timer0.begin(SECS(3));  //delay transmission

  } /*Setup*/

//-------------------- LOOP -----------------------
  void loop()  {

//---------------- strucuture ------------
// collect new data
  sensorData[0].A = 10 ;
  sensorData[0].B = random(2000000000);
  sensorData[0].C = random(2000000000);
  sensorData[0].D =  random(2000000000) ;
  sensorData[0].E =  random(2000000000) ;
  sensorData[0].F =  random(2000000000) ; // valeur fixe
  sensorData[0].G = 70 ; // valeur fixe
  //     = 19 octes
//unsigned long : non-negative integer of  0 à 4 294 967 295 sur 32 bits de 4 octets

//------------------

  if (timer0.available()) {

 // 1; 2; choix du nbr de structre
  for( int sensor = 0; sensor < 1; sensor++)  {
    // transmit the data
    Wire.beginTransmission( SLAVE_ADDRESS);
    I2C_writeAnything( sensorData[sensor]);

    int error = Wire.endTransmission (); //(true) ?
     if( error != 0) {
      Serial.println(F("Error, no acknowledge from Slave"));
    }
  }

    timer0.restart();
  }

  } /*Loop*/

//---------------------- End pgm ----------------------------

Slave_I2C_Anything_PCF8574_4DO_uneStructure_bigOctes.ino
/*
 *  DESCRIPTION :
 *  un Arduino Uno en liaison avec un module i2c PCF8574 avec 4 Relais
 *  il recoi aussi d'un autre Arduino des valeurs en Kw pour le basculement des relay
 *
 *
 *  LIBRAIRIES:
 *    - Rob Tillaart pour PCF8574 https://github.com/RobTillaart/Arduino/tree/master/libraries/PCF8574
 *    - Nick Gammon  for bus i2c  http://www.gammon.com.au/i2c
 *    - Timers de Łukasz Tretyn   https://github.com/nettigo/Timers
 *
 *  ELEMENTS: sur le bus i2c
 *    - Expander PCF8574 avec module Metasys JC / 4DO - 0X3D  i2c adress
 *    - ATMega328  pour mesure Electrique
 *    - ATMega328  en Reception
 *
 *  MODIFICATION:
 *    -x- model de Peter_n : https://forum.arduino.cc/t/i2c-not-sending-all-data-with-i2c_anything/293609/11
 *    -o-
 *    -o-
 *
 *     RAS
*/

//------ Mars 2023 -------- Linky PCF8574 - 4DO / Bus i2c -----------------//

// -------------  Functional TEST BUS I2C -----------------------//
// une struct de 19 Octes, pour un maximum  de 32octes

//------ i2C Bus ------------
  #include <Wire.h>
  #include <I2C_Anything.h>
  const byte MY_ADDRESS = 42;

  // The struct must be the same in the Master and in the Slave
  //unsigned long:4 octet (32 bits) - max 4294967295
  struct sensorData_STRUCT {
  byte sensorNumber;
    uint16_t A;   // uint16_t PAPP in VA
    uint32_t B;   // uint32_t BASE index in Wh
    uint32_t C;   // uint32_t HCHC index heures creuses en Wh
    uint32_t D;   // uint32_t HCHP Index heures pleines en Wh
    uint8_t E;    // uint8_t  IINST  Returns in Amp
    uint8_t F;    // uint8_t ISOUSC  Returns ISOUSC
    uint8_t G;    // uint8_t PTEC Periode tarifaire en cours (0 = HP, 1 = HC)
     uint8_t H;    //
    };

/*  struct sensor2Data_STRUCT {
  byte sensor2Number;
    int G;
    int H;
    int I;
    int J;
    int K;
    int L;
    }; */

  // A special struct for the received sensor data
  volatile sensorData_STRUCT sensorDataNew;

  // A flag to indicate new data
  volatile boolean haveData = false;

  // The normal sensor data
  sensorData_STRUCT sensorData[1];  //nbr de structure [2]

//---------------- PCF8574 -------------------------------
  #include "PCF8574.h"
  PCF8574 PCF27a (0x3D);  // adjust addresses i2c pcf8574

  #define RELAY_ON  0    //
  #define RELAY_OFF 1    //

// -----------------------------------------------------------------------------
//      -----------------          SETUP          ---------------------
// -----------------------------------------------------------------------------

void setup() {

  Wire.begin (MY_ADDRESS);  // bus i2C
  Wire.onReceive (receiveEvent);

  Serial.begin (115200);
  Serial.println(F(" SlaveI2CAnythingPCF8574Structure_bigOctes "));
  Serial.print(__DATE__); Serial.println(__FILE__);

  // fill fixed data
  sensorData[0].sensorNumber = 0;

  Wire.setWireTimeout(3000,true);

  PCF27a.begin();           // i2C PCF8574

//--------- testing IsConnected i2c PCfx ------------
  Serial.print(F(" PCF8574_LIB_VERSION : \t")); Serial.println(PCF8574_LIB_VERSION);
  if (!PCF27a.begin())   {
    Serial.println(F("could not initialize..."));
    }
  if (!PCF27a.isConnected())   {
    Serial.println(F("=> not connected"));
  }
  else   {
    Serial.println(F("=> connected!!"));
    }

  } /* fin Setup */

// --------------------------------------------------------------------------
//         -----------------        LOOP      ------------------------
// --------------------------------------------------------------------------
 void loop() {

//---------------- i2C bus -------------------------------
  int sensor;  int sensor2;

    if( haveData)  {
    // New data has arrived, copy it in one of the two sensorData.
    // Disable interrups as short as possible
    // The interrupts are disabled to avoid an receiveEvent interrupt that writes new data.
    noInterrupts();
    sensor = sensorDataNew.sensorNumber;

  if( sensor == 0 || sensor == 1) {         // destination, source, size
  memcpy( &sensorData[sensor], (const void *) &sensorDataNew, sizeof( sensorData_STRUCT));

  }
  haveData = false;
  interrupts();

    printData(sensor) ; //print Data
    cmdRelay() ;        // Relay PCF8574
   }

 } /* fin Loop */

// -----------------------------------------------------------------------------
//   -------------------  Receiving messages I2C    ------------------
// -----------------------------------------------------------------------------
//howMany est le nombre d'octets reçus et par conséquent combien vous pouvez lire
//avec Wire.read(), pour un maximum de 32 octes.

 void receiveEvent( int howMany) {
  if( howMany == sizeof( sensorData_STRUCT)) {
    I2C_readAnything( sensorDataNew);
         haveData = true;
  }
  else {
    // something is wrong. Wrong number of bytes received.
    // it is possible to set a volatile variable to an error.
  }
 }

// -----------------------------------------------------------------------------
//   -------------------  Relay Control   ------------------
// -----------------------------------------------------------------------------
 void cmdRelay() {
//-------- Relay 1 ---------
  if (sensorData[0].A > 829308135 ) { PCF27a.write(0, RELAY_ON); }
  else { PCF27a.write(0, RELAY_OFF); }
     //Serial.println(PCF27a.read(0));
//-------- Relay 2 ---------
  if (sensorData[0].B > 304929158) { PCF27a.write(1, RELAY_ON); }
  else { PCF27a.write(1, RELAY_OFF); }
      //Serial.println(PCF27a.read(1));
//-------- Relay 3 ---------
  if (sensorData[0].C > 590793899 ) { PCF27a.write(2, RELAY_ON); }
  else { PCF27a.write(2, RELAY_OFF); }
     //Serial.println(PCF27a.read(2));
//-------- Relay 4 ---------
  if (sensorData[0].D > 304929158) { PCF27a.write(3, RELAY_ON); }
  else { PCF27a.write(3, RELAY_OFF); }
      //Serial.println(PCF27a.read(3));
 }

// -----------------------------------------------------------------------------
//   -------------------  Print data   ------------------
// -----------------------------------------------------------------------------
  void printData(int sensor) {

  if (sensor == 0 ) {
    Serial.print(F( "------ sensor["));
    Serial.print( sensor); Serial.println(F( "] ------"));
    Serial.print(F( "a PAPP  = ")); Serial.println( sensorData[0].A);
    Serial.print(F( "b BASE  = ")); Serial.println( sensorData[0].B);
    Serial.print(F( "c HCHC  = ")); Serial.println( sensorData[0].C);
    Serial.print(F( "d HCHP  = ")); Serial.println( sensorData[0].D);
    Serial.print(F( "e IINST = ")); Serial.println( sensorData[0].E);
    Serial.print(F( "f ISOUSC= ")); Serial.println( sensorData[0].F);
    Serial.print(F( "g PTEC  = ")); Serial.println( sensorData[0].G);
     Serial.print(F( "h test  = ")); Serial.println( sensorData[0].G);

Serial.println(sizeof( sensorData_STRUCT));
    }
    Serial.println();
  }
//------------------------------ End pgm -------------------------------------


text:
Arduino IDE 1 interfering with Arduino IDE 2?
In our electronics tinker club, we had installed Arduino IDE 1.8 including drivers + the Holtek UART bridge (vendor ID 04D9, product ID B534) for the Elegoo Smart Car Kit 3.0 Plus (product link). The board is an Arduino Uno clone.
We now installed Arduino IDE 2.0.3 in parallel and tried that one, because its features looked promising.
However, in Arduino IDE 2.0.3, we had problems uploading the compiled sketch to the Smart Car Board. When I checked, it reported a different vendor ID and product ID (sorry, I didn't record which one).
I reinstalled the Holtek UART bridge driver (direct download executable) and tried again. The vendor ID and product ID were correct this time, but uploading was still not going well in Arduino IDE 2.0.3.
Switching back to Arduino IDE 1.8 doesn't help. While the code still compiles (I expected it to), the upload problems now affect Arduino 1.8 as well, which was totally fine before we installed Arduino IDE 2.0.3.
How could I fix this issue?
I'll try to uninstall and reinstall everything, but I'm not sure it will be possible to uninstall all drivers.

You might want to add the command line and output of the call of avrdude.

@thebusybee: thanks. I don't yet know what that is, but I'll inform me about that and post it when I know it.

BTW: I upgraded 4 PCs to Arudino 2.0.4. It seems to work better on 2 PCs (upload works), but the other 2 still have the same problem.

In the IDE you can see in the output view the commands executed and their responses. You might need to set the respective option in the preferences. Copy this output as text into your question, please. -- Avrdude is the program that actually uploads the compiled sketch.

@thebusybee: thank you for this hint. It helped me a lot when diagnosing and comparing the different results. Since I had 9 robots and 8 noteboks, I had so much output and text for debugging purposes, I was reluctant to put it into the question. I have now posted an answer on this question.

I spent more time (almost 20 working hours) to isolate this problem by

testing the behavior with all of our 9 robot hardware in the club
testing the behavior with all of our 8 notebooks in the club
testing with the 6 different implementations we had, bricking and not bricking our robot hardware
testing with an additional notebook that didn't seem affected
combinations thereof

Finally I had a reproducible procedure with which I could "brick" a robot hardware and another procedure which would "unbrick" it.
That way I was able to a) minimize the code that was needed to "brick" the robot and b) compare that to the other codes that didn't have the issue. Finally I could ask this new question and get valuable feedback.
It turned out that this was not related to the new Arduino 2.0.3 or 2.0.4 IDE. It was just a timely coincidence that we wrote a new sketch we never wrote before in this way for this hardware.
That code used Serial.begin() with a "high" baud rate and obviously less delays than we ever used on this hardware before. And it turned out our hardware can't handle speeds higher than 19200 baud (!) without delay() statements. That's so slow!

source: Stack Exchange

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

sort: votes


text:
if statement with string comparison
Code Snippet:
String a;

const int red_led_pin = 13;

void setup()
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT);
}

void loop() {

    while (Serial.available())
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }

        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

Circuitry:

Issue:
The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.
What is going wrong?
Things I have tried:
I have tried as a comparison:

if (a.equals("on")){<>}
if (a == "on")){<>}
if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

[ Documentation ] String Comparison Operators
[ Documentation ] String()
[ Forum ] Compare characters (or string) in “if” function

What line ending have you set in the Serial Monitor? My guess is, that the Serial Monitor sends a line ending after the actual data, which gets included by Serial.readString(), so that the string doesn't equal "on", but for example `"on\n".

@chrisl that was it... Serial.readStringUntil('\n')

Great, I've written a full answer to this question

@chrisl and all. this question is asked often. let's use this Q&A pair as canonical for future duplicates

I'm going to be cheeky and ask for some up votes from the community:)

Your problem is the line ending. The Serial Monitor has an option to send a line ending after the data, that you input. This line ending can be different depending on this setting, though mostly in the Arduino world a simple newline character '\n' is used.
This line ending will be in your string, when using Serial.readString(), so the string is not equal to "on", but to something like "on\n".
You can solve this issue by two ways:

Set the Serial Monitor to no line ending.
Or better: Use something like Serial.readStringUntil() and pass the line ending character to it as parameter (for example Serial.readStringUntil('\n')). This will read from the Serial interface until the specified character is reached. The specified character will be discarded and you are left with only the data, which you can then do comparisons on. This also has the advantage, that your code will react much faster, since it doesn't wait for 1s for new data (as long as you actually send the needed line ending).

if there is a \r too, trim() can help. but as always it is better not to use String

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


text:
ESP & Servo not communicating well
I have a mystery I was unable to solve and would greatly appreciate it if anyone could shed some light on this.
I have a servo DSS-M15S 270 which I managed to run perfectly fine with Arduino Uno (code below). I need only 2 cables for this - output & ground. The power cable is connected to batteries and the analog is irrelevant (although I managed to connect it as well just fine).
Same exact code on an ESP8266 NodeMCU fails to run the servo. I validated the right GPIO with a different sensor (PIR) that worked fine with the ESP, but the motor wouldn't work - it slightly jitters after a few minutes but nothing works. I already tried changing between different GPIOs and seeing different reactions but still nothing.
Eventually, I connected a new ESP32 with the same code and it almost worked! the servo works during the calibration function but ANY attempt to move it again OUTSIDE the calibration function fails. so I cancelled the calibration function and the servo works perfectly fine now with the ESP32 ! I have no idea how or what is happening.. if anyone could help me get it to work on ESP8266, that would be amazing.
Based on all those tests I reckon it's related to the different servo libraries of the chips somehow.
https://youtube.com/shorts/fZlu8wdeRGQ
In this second video I just return the cables back to the Arduino and everything works again (same code, same connection pins) -
https://youtube.com/shorts/Jvr1oZV1AKI
#include <Servo.h>

Servo myservo;

// Control and feedback pins
byte servoPin = 4;
int feedbackPin = A0;

// Calibration values
int minDegrees;
int maxDegrees;
int minFeedback;
int maxFeedback;
int tolerance = 2;  // max feedback measurement error

void calibrate(Servo servo, int analogPin, int minPos, int maxPos) {
    // Move to the minimum position and record the feedback value
    servo.write(minPos);
    minDegrees = minPos;
    delay(2000);  // make sure it has time to get there and settle
    minFeedback = analogRead(analogPin);

    // Move to the maximum position and record the feedback value
    servo.write(maxPos);
    maxDegrees = maxPos;
    delay(2000);  // make sure it has time to get there and settle
    maxFeedback = analogRead(analogPin);
}

int getPos(int analogPin) {
    return abs(map(analogRead(analogPin), minFeedback, maxFeedback, minDegrees, maxDegrees));
}

void ServoSetup() {
    Serial.println("Setting output");
    pinMode(servoPin, OUTPUT);

    Serial.println("Attaching");
    myservo.attach(servoPin);

    Serial.println("Calibrating");
    calibrate(myservo, feedbackPin, 0, 270);
}

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

void loop() {
    Serial.println(analogRead(A0));
    myservo.write(270);
    Serial.println("270");
    delay(2000);
    Serial.println(analogRead(A0));
    myservo.write(0);
    Serial.println("0");
    delay(2000);
}

The final code is basically like the above but without the calibration and different pins for the ESP32
Any ideas on what's happening here and how to make this work with ESP8266 would be great
Thanks,
Shay

Isn't the UNO running with 5V and the ESPs with only 3.3V? I suspect the servo needs 5V on the control input. It may work a bit with ESP32 but not with ESP8266 because the boards may give slightly different GPIO voltage?

I thought voltage makes a difference only for VCC and not GPIOs but it makes sense I suppose.. thanks

How can you tell the voltage consumption of a GPIO? should that be specified somewhere??

A GPIO does not have a voltage consumption. It can only source or sink current. A ESP8266 can not deliver more than 12 mA on a GPIO, while the ESP can deliver up to 40 mA per pin. That could explain that it works a bit better with ESP32. Both work on 3.3 V. But the UNO works on 5V - which is compatible with the servo's datasheet. I think your problem does NOT lie in the libraries or software. Show how did you wired everything up!


text:
How do I interface my ESP32 board with my 3.5" TFT Screen
I've bought an ESP32 board from here and a 3.5" TFT Screen from here. The ESP32 board has an UNO type layout so I thought it would work with the screen which is designed to  plug in and play with Arduino UNOs.
However upon plugging the board and shield together (they fit perfectly, each pin goes in a corresponding slot), loading one of the example scripts (provided on the 3.5" Screen .rar download on the page), set Arduino to use ESP32 Development Board on COM3 (my usual settings for the ESP32) and uploading the code I just get a white screen on the TFT.
Is there some accommodation that I have to make because my board is not an UNO but instead a ESP32, i.e. is the pin layout different so maybe I'll need to wire this manually?
I've included the pin out diagrams below:

Arduino Sketch Code:

#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>    // Core graphics library

// wiring with UNO or Mega2560:
//--------------POWER Pins--------------------------------
//   5V  connects to DC 5V
//   GND connects to Ground
//   3V3 do not need to connect(NC)
//--------------LCD Display Pins--------------------------
//   LCD_RD   connects to Analog pin A0
//   LCD_WR   connects to Analog pin A1
//   LCD_RS   connects to Analog pin A2
//   LCD_CS   connects to Analog pin A3
//   LCD_RST  connects to Analog pin A4
//   LCD_D0   connects to digital pin 8
//   LCD_D1   connects to digital pin 9
//   LCD_D2   connects to digital pin 2
//   LCD_D3   connects to digital pin 3
//   LCD_D4   connects to digital pin 4
//   LCD_D5   connects to digital pin 5
//   LCD_D6   connects to digital pin 6
//   LCD_D7   connects to digital pin 7
//--------------SD-card fuction Pins ----------------------
//This Connection Only for UNO, Do not support Mega2560
//because they use different Hardware-SPI Pins
//SD_SS    connects to digital pin 10
//SD_DI    connects to digital pin 11
//SD_DO    connects to digital pin 12
//SD_SCK   connects to digital pin 13

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define LCD_CS A3   // Chip Select goes to Analog 3
#define LCD_CD A2  // Command/Data goes to Analog 2
#define LCD_WR A1  // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

MCUFRIEND_kbv tft;

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  }

  return micros() - start;
}
void setup(void) {
   Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

  tft.reset();

  uint16_t identifier = tft.readID();
  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  }else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9595) {
    Serial.println(F("Found HX8347-I LCD driver"));
  } else if(identifier == 0x4747) {
    Serial.println(F("Found HX8347-D LCD driver"));
  } else if(identifier == 0x8347) {
    Serial.println(F("Found HX8347-A LCD driver"));
  }else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  }else if(identifier == 0x7783) {
    Serial.println(F("Found ST7781 LCD driver"));
  }else if(identifier == 0x8230) {
    Serial.println(F("Found UC8230 LCD driver"));
  }else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if(identifier==0x0101){
      identifier=0x9341;
      Serial.println(F("Found 0x9341 LCD driver"));
  }else if(identifier==0x7793){
       Serial.println(F("Found ST7793 LCD driver"));
  }else if(identifier==0xB509){
       Serial.println(F("Found R61509 LCD driver"));
  }else if(identifier==0x9486){
       Serial.println(F("Found ILI9486 LCD driver"));
  }else if(identifier==0x9488){
       Serial.println(F("Found ILI9488 LCD driver"));
  }else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier=0x9486;
  }
  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(RED, BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(YELLOW, MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));
}

void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }
}

You didn't show us the code in question. Please include your code in the question by editing it.

Ok, that's it added

please copy the content of the serial monitor and paste it into your post ... format it as code

If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.
Benchmark                Time (microseconds)
Screen fill              1386975
Text                     52997

The MCUFRIEND_kbv library has the pins hardcoded. To use the Uno pin numbering the Wemos ESP32 D1 board requires to use Dx pin names instead of x. So the library will not work with this board without changing the pins in the source code of the library.

The exact same sketch with included libraries works perfectly on my standard UNO, displays all the graphics. I need to use the ESP32 tho because it has wifi capabilities.

upvote for the use of Vogon poetry ... couldn't help myself


text:
Unable to get my created library to work - while it compiles
I am experimenting with creating my own Arduino libraries. Unfortunately, while the program compiles, the end result does not work.
For purposes of experimentation, I have broken down the library in two parts. One that will handle blinking by controlling the LED_BUILDIN pin and one that will talk to the serial input.
Thus two .h and two .cpp files. Plus there is another file for the configuration that handles preprocessor directives that the library reads.
This is the code:
FILE 1
//header_config.h
#ifndef MY_CONFIGURATION
#define MY_CONFIGURATION

#include <Arduino.h>

#define SERIAL_DEBUG
#define LED_BLINK

#include <led_functions.h>
#include <serial_functions.h>

void my_setup()
{
  my_setup_led();
}

void my_loop()
{
    led_blinker();
    serial_transmit("Hello");
}

#endif

FILE 2
//led_functions.h
#ifndef MY_LED_LIBRARY
#define MY_LED_LIBRARY

  #include <Arduino.h>
  #include "header_config.h"
  #include "serial_functions.h"

  extern void led_blinker();
  extern void my_setup_led();

#endif

FILE 3
//led_functions.cpp
void led_blinker()
{
  #ifdef LED_BLINK
  digitalWrite(LED_BUILTIN, HIGH);
  serial_transmit("LED ON");
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  serial_transmit("LED OFF");
  delay(1000);
  #endif
}

void my_setup_led()
{
#ifdef LED_BLINK
pinMode(LED_BUILTIN, OUTPUT);
#endif
}

FILE 4
//serial_functions.h
#ifndef MY_SERIAL_LIBRARY
#define MY_SERIAL_LIBRARY

  #include <Arduino.h>
  #include "header_config.h"

  #ifdef SERIAL_DEBUG
  #include <SoftwareSerial.h>
  #define rxPin 2
  #define txPin 3
  SoftwareSerial mySerial(rxPin, txPin);
  #endif

  extern void serial_transmit(char*);

#endif

FILE 5
//serial_functions.cpp
void serial_transmit(char *str)
{
  #ifdef SERIAL_DEBUG
  //mySerial.begin(9600);
  //mySerial.println(str);
  //mySerial.end();
  Serial.begin(9600);
  Serial.println(str);
  Serial.end();
  #endif
}

Please note that while the serial code creates a SoftwareSerial object (in serial_functions.h), I do not use that (in serial_functions.cpp) and instead I make use of hardware Serial. The reason is debugging, so that I can see communication on the PC. I left the SoftwareSerial object inside, because that is what I ultimately want.
Finally, outside the library, in it's separate folder, is the .ino file that makes use of this library.
#include <header_config.h>
#include <led_functions.h>
#include <serial_functions.h>

void setup()
{
  my_setup();
}

void loop()
{
  my_loop();
}

As I said, the program compiles fine, but it does not work in the real world. Neither the blinking, nor the serial communication.

Your cpp files don't include the header_config.h file, so they don't have SERIAL_DEBUG and LED_BLINK defined.
The content of included file replaces the include directive so if you now include header_config.h into both cpp, there will be 3 functions named my_setup() and 3 functions named my_loop() and the linker will complain. So you can't put functions definitions into an include file. And for the same reason you can't have variable definitions in .h file so the SoftwareSerial instance will cause problems too if used.

"Your cpp files don't include the header_config.h file, so they don't have SERIAL_DEBUG and LED_BLINK defined." Why is this necessary, since both header files are included in header_config.h? And the final .ino file calls header_config.h. Also, since the header files use the extern keyword for the function definitions, then shouldn't that work?

@user1584421 the cpp files don't include any .h sothey don't include the header_config.h  over the  other .h files

And what do you suggest i do about the SoftwareSerial object? Should it go to the cpp file instead?

@user1584421 you use it only in serial_functions.cpp so yes

I managed to get it working! Thank you! However, it is still unclear to me why I have to include, <header_config.h> in the .cpp files. Like you said, the content of the files replace the include directive. So if in header_config.h I include the .cpp files and then in the .cpp files, in include back the header_config.h file, isn't it like the header_config.h file includes itself back?

@user1584421 the header files are not compiled. The #include line is replaced by the preprocessor with the content of the included file so  the content of the includes file becomes part of the preprocessed cpp file and then it is compiled


text:
6 ST7735 screens not working at same time with Pico
Hello i have a question for you. I have 6 St7735s screen 0.96 ınch. I connect them to my Raspberry pi pico. I want to show them some text but they are showing at the same time. First screen start working and shows "Screen 1 Test" and then its close. After that second screen start working and show "Screen 2 Test" and its close again and it goes to last screen and it show "Screen 6 test" and not closing. But the rest of it stay close. I use same connection for GND - VCC - SCL - SDA - RES - DC pins. Only Cs pin is diffrent. Any advice for me?
The code that i used :
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>

#define TFT_CS1 2
#define TFT_CS2 3
#define TFT_CS3 4
#define TFT_CS4 5
#define TFT_CS5 14
#define TFT_CS6 15
#define TFT_DC 9
#define TFT_RST 7

Adafruit_ST7735 tfts[] = {
  Adafruit_ST7735(TFT_CS1, TFT_DC, TFT_RST),
  Adafruit_ST7735(TFT_CS2, TFT_DC, TFT_RST),
  Adafruit_ST7735(TFT_CS3, TFT_DC, TFT_RST),
  Adafruit_ST7735(TFT_CS4, TFT_DC, TFT_RST),
  Adafruit_ST7735(TFT_CS5, TFT_DC, TFT_RST),
  Adafruit_ST7735(TFT_CS6, TFT_DC, TFT_RST)
};

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

  for(int i = 0; i < 6; i++){
    tfts[i].initR(INITR_MINI160x80);
    tfts[i].setRotation(3);
    tfts[i].fillScreen(ST7735_BLACK);
    tfts[i].setTextColor(ST7735_WHITE);
    tfts[i].setTextSize(2);
  }
}

void loop() {
  for(int i = 0; i < 6; i++){
    tfts[i].setCursor(0, 0);
    tfts[i].println("Screen " + String(i+1) + " test");
    delay(1000);
  }
}

what happens if you iterate through the screens in a descending order?

I didnt understand but if i lower delay time it still working same

go through the screens in the 6, 5, 4 order

You might want to have separate reset pin for each, it probably resets all displays and initialize one of them.

Or you can try if it's possible to configure only first object with TFT_RST and the rest with -1 instead. But it might be checked somewhere.


text:
Dump data check failed on a TinyPICO using ESP32
I use the TinyPICO microcontroller with ESP32 and I program it using the Arduino IDE. I recently got a new error on my Serial Monitor:
E (113) esp_core_dump_�^X.K�ɕ�dump data check failed:
Calculated checksum='453aefca'
Image checksum='ffffffff'`

This error also occurs with the examples provided by the Arduino IDE for the TinyPICO like 'TinyPICO_Funky_LED.ino', so the error must be on the TinyPICO or must have something to do with the serial connection.
Also it is worth mentioning that this error didn't occur yesterday with the exact same computer and microcontroller. All the programs work fine but this error always comes in my Serial monitor. My guess is that I somehow accidentally wrote something on the TinyPICO which would create this error but I am not sure.
Do you have any idea on what could be the cause of this error and how I could fix it (or ignore it) ?


text:
How to prevent an Arduino connected to the Internet from being hacked?
I have an Arduino (with environmental sensors doing measurements) connected to the Internet via ethernet. Can it be hacked? Can someone access it via Internet and upload his own C/C++ code? If, yes how can I prevent this?
Update (03/03/2023): One final thought: Supposing that I have secured USB plug and nobody can access it. However, I am using the Serial interface of the Arduino MEGA 2560. So, Serial_1 is continuously reading. Can someone with physical access to the Arduino inject malicious code via the Serial_1 so that can alter the code inside my Arduino and have access to information?

does it have Ethernet bootloader or ArduinoOTA library?

I am using the Arduino MEGA 2560 R3 + original Arduino Ethernet Shield 2....if that helps...

Depending on the architecture of your solution, the risk could be exposing your home network to the internet. If your Arduino system is designed to accept incoming traffic from the internet, say it runs a web server, and you configure port forwarding on your router to support this, then you expose your network to such a risk.

This depends on what you consider "hacked".
Do you care about someone reading the data, or changing it on its way to the target? Or do you provide endpoints to trigger something in your project from the internet, that only you should be able to do? Then you need to think about authentication and encryption. Though I guess that this data will be published either way, so that is not a big problem. But you should write down every endpoint, that you expose to the internet, and every request you are making. Then decide what level of security you need them to have individually. Exposed endpoints can easily be found and you have to decide yourself, if it is OK for others to use them.
If you mean getting into the device and executing malicious code from there: IOT devices are often vulnerable because of two reasons. They often have an OS (like a small linux OS), that is badly secured (often using standard password). And they often get updates via the internet. If someone can hijack the update process, malicious code might be delivered. An Arduino doesn't have an OS, so that isn't a problem. And hijacking the update process won't be possible, if you don't provide the possibility to update through the network. This makes updating your code a bit more complicated (since you need to connect the Arduino via USB or similar to program it), but more secure. That way no one (not even you) can inject malicious code into your project without physical access to the Arduino. To take up Jurajs comment: Updating through network is normally done by the Ethernet bootloader or the ArduinoOTA library (Over The Air updates). If you are not using those or similar projects, then you will be safe in that regard.

With strangers having physical access to the device it is a different story. To reprogram the Arduino one would need access to Serial (RX0 and TX0) and a possibility to reset the Arduino (either Reset pin or a way for power cycling it), or access to the ISP pins and the reset pin.
If you can secure the Arduino itself from physical access and only expose the Serial1 interface and ground/5V, then you will be safe, since the bootloader is only listening on Serial (RX0 and TX0). But keep in mind, that someone might still break into your project with brute force - depending on how you secured it physically. At that point nothing can stop them from overwriting your code. Only you can assess how big the chance for that is and how bad it would be.
Another point: If someone manages to break into your project, he can read out the program and push it through a deassembler. That doesn't give them the C++ code - they are not seeing C++ code, only assembler, and no meaningful variable names - but if they are determined enough they can read out credentials, that you might have hard coded or saved in EEPROM. Though especially for environmental sensors I would say the chance is very low, that someone would go to such lengths. If you think the danger to be big enough for some inconvenience, you can have a look at code protection (protecting the program memory from being read), though that still doesn't completely block reprogramming.
All in all: Preventing physical access is a big step in security. You yourself need to assess how much security you really need for your project.

I have updated my question...please read it again!! Everyone many thanks for your help...

@just_learning I added some paragraphs about that in my answer


text:
Calibration of pH sensor
I am working with pH sensor (https://wiki.seeedstudio.com/Grove-PH-Sensor-kit/ ) and arduino. The board provided with sensor is not having any potentiometer to set the voltage value when dipped in known buffer solution. I have read that when BNC connector is short then voltage value should be 2.5 V. But when I do the same voltage comes out to be 1.9 V. Also sensor gives wrong readings when put in known buffer solutions of 4.0pH, 7.0pH and 9.2 pH. I am not getting how to calibrate the sensor without having potentiometer on board.
I have already done as per mentioned on website (in link given above).

"I have read that when BNC connector is short then voltage value should be 2.5 V", that may apply to this poorly-designed PH sensor board but certainly does not apply to Grove PH Sensor board as the board is using a single 3.3v power supply with an external reference voltage of 1.8v. You may want to read my review about the Grove PH board to understand how it work and how to use it.

You probably need to do that in software. That is supported by step 7 in the chapter Software on your linked site.
In step 4 we see the proposed demo code, which contains the calculation of pH based on the read voltage:
pHValue = -19.18518519 * voltage + Offset;

The first number is probably k, so the calculation is
pHValue = k * voltage + Offset;

For the calibration you need to find the values for k and Offset. This is done with 2 buffer solutions with known pH. Step 7 shows the formulas for calculating these values based on the known pH values (removed the dollar signs):
k= (PH2-PH1)/(V2-V1)
Offset=[(PH2+PH1)-k*(V1+V2)]/2

And they even provide a link to an Excel sheet, which helps you with the calculation: https://files.seeedstudio.com/wiki/Grove-PH_Sensor_kit/Calibration_for_k&offset.xlsx
Here is an image of that sheet:

In column B behind PH1 and PH2 you can input the known pH values for your buffer solutions. In column E behind V1 and V2 you can input the resulting sensor voltages (! voltages, not wrongly calculated pH values) for each solution. Then you will get your values of k and Offset in the cells B4 and B5.
Input those values into the calculation for phValue in the code and you should get correct values.

I have done as per mentioned. But when I put sensor in 9.2 buffer it gives ph= 2.62 and voltage =2.02. Similarly in buffer 4.0 it gives some other pH value. It leads to wrong calculation of k and offset value.

@JashanjotKaur Please add your calculation and the resulting values to your question.


text:
I goofed: I used a digital output rather than an analog output
OK, I have a little hardware issue I need to fix in software for the time being.  I say, "For the time being," because I already have the PC Boards printed, and I need to make do for this run of boards.  (So sue me for not bread boarding first.)  I THOUGHT the little buzzers I purchased sounded off on a DC input, but I was wrong.  I used the nearest pin to the buzzer to activate it, which is D14.  The next run of boards I will use A6 instead, but  until then I will need to output a square wave of about 2731 Hz on D14 of an ATTiny88.  The straightforward approach would seem to be something like:
bool buzzer(bool x) {
  if (x) {
    return true;
  }
  return false;
}
bool PinVal = false;
void loop() {
  <some code here>
  buzzerVal = buzzer(true | false);
  <some code here>
  if (buzzerVal && micros()%376 > 365) {
    PinVal = !PinVal;
    digitalWrite`(14,PinVal);
    }
  while (micros()%376 > 365);
}

Is there a smarter, more efficient way?  If so, I might consider not even changing the board layout.  Pin 14 has an alternate function of register PB7.  It occurs to me it might be more efficient to write directly to PB7, rather than using the digitalWrite function, which presumably has more overhead.  Yes? No?  Any other ideas?

Try the tone() library or built-in function to generate the signal.

"The next run of boards I will use A6 instead", there is a fundamental misunderstnad of what A6 means, the pin is capable to be configure as an ADC input of ADC channel 6, but when you using it as an GPIO output, it just another GPIO pin like D14 pin.

Also, depending on the microcontroller,  A6 may not even be usable as an output pin of any sort. For example, the SMD packages of the ATmega328P break out analog pins A6 and A7 but these are pure input pins. The remaining analog pins A0 to A5 do not have this restriction and can also be used as digital pins.

This is contrary to my understanding.  My understanding was on the ATTiny88, pins A0 through A7 can all be used as PWM outputs using the analogWrite function.  Please confirm or deny.  Note pin A5 is also available on the board, so although it is less convenient, it could also be used in the next design.

Mind @6v6gt's hint, A6 and A7 are on some MCU pure inputs!! You did not specify your controller.

ATTiny88, as I mentioned above.

you don't need PWM (sound frequencies are not that high) and you don't need analog output (it would not vibrate the buzzer and there isn't a DAC on the ATTiny). you can use any pin. if the buzzer is 'active', then set the pin HIGH. if the buzzer is passive, use the tone() function or a timer with interrupt.

The IDE cannot find the tone() library.  I can't seem to find anything with the library manager that provides "pitches.h" or a tone() function.  Given the rest of the code (not shown here), I am not sure a timer interrupt is a good idea.  I definitely would rather have the tone vary a bit than risk collisions with the other interrupts in the code.

the tone() functions should be in the core, but maybe the core you use doesn't have it. in AVR core it is implemented with a timer interrupt. pitches.h is part of the tone example in IDE Examples menu

Why not buy the correct buzzers, that appears to me to be the easiest solution.


text:
Sudden Error: File does not exist
I am suddenly getting an error every time I try to compile code in the IDE, even though every one of the sketches previously compiled just fine:
Arduino: 1.8.13 (Windows 7), Board: "MH-ET LIVE Tiny88(16.0MHz)"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\lrhorer\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\lrhorer\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\lrhorer\Documents\Arduino\libraries -fqbn=mhetlive:avr:MHETtiny88 -ide-version=10813 -build-path C:\Users\lrhorer\AppData\Local\Temp\arduino_build_609285 -warnings=all -build-cache C:\Users\lrhorer\AppData\Local\Temp\arduino_cache_521731 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.micronucleus.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\tools\micronucleus\2.0a4 -prefs=runtime.tools.micronucleus-2.0a4.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\tools\micronucleus\2.0a4 -prefs=runtime.tools.avr-gcc.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.8.1-arduino5 -prefs=runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.8.1-arduino5 -verbose C:\Users\lrhorer\Documents\Arduino\sketch_feb27a\sketch_feb27a.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\lrhorer\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\lrhorer\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\lrhorer\Documents\Arduino\libraries -fqbn=mhetlive:avr:MHETtiny88 -ide-version=10813 -build-path C:\Users\lrhorer\AppData\Local\Temp\arduino_build_609285 -warnings=all -build-cache C:\Users\lrhorer\AppData\Local\Temp\arduino_cache_521731 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.micronucleus.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\tools\micronucleus\2.0a4 -prefs=runtime.tools.micronucleus-2.0a4.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\tools\micronucleus\2.0a4 -prefs=runtime.tools.avr-gcc.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.8.1-arduino5 -prefs=runtime.tools.avr-gcc-4.8.1-arduino5.path=C:\Users\lrhorer\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.8.1-arduino5 -verbose C:\Users\lrhorer\Documents\Arduino\sketch_feb27a\sketch_feb27a.ino

Using board 'MHETtiny88' from platform in folder: C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\hardware\avr\1.0.0

Using core 'tiny88' from platform in folder: C:\Users\lrhorer\AppData\Local\Arduino15\packages\mhetlive\hardware\avr\1.0.0

Detecting libraries used...

"C:\\Users\\lrhorer\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\4.8.1-arduino5/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -w -x c++ -E -CC -mmcu=attiny88 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_DIGISPARKPRO -DARDUINO_ARCH_AVR "-IC:\\Users\\lrhorer\\AppData\\Local\\Arduino15\\packages\\mhetlive\\hardware\\avr\\1.0.0\\cores\\tiny88" "-IC:\\Users\\lrhorer\\AppData\\Local\\Arduino15\\packages\\mhetlive\\hardware\\avr\\1.0.0\\variants\\tiny88" "C:\\Users\\lrhorer\\AppData\\Local\\Temp\\arduino_build_609285\\sketch\\sketch_feb27a.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

exec: "C:\\Users\\lrhorer\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\4.8.1-arduino5/bin/avr-g++": file does not exist

Error compiling for board MH-ET LIVE Tiny88(16.0MHz).

The file indeed does not exist in that location.  What now?
Update:
Under the ATTinyCore compiler the missing file name is the same, but the directory is different:
exec: "C:\\Users\\lrhorer\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++": file does not exist

The latest version of the DigiStump compiler does not even have the MH-ET Live Tiny88 board compiler included.
I can get the code to compile under Linux, but I am having trouble uploading the binary to the board.  How can I take the binary code and upload it to the ATTiny88 board under either Linux or Windows 7?
Update:
I found three files quarantined by my anti-virus.  I restored the files, and now avr-g++.exe seems to be back where it belongs, and the compiler no longer claims the file is missing.  Now, however, it s complaining about not finding the stdlib.h library called from the Arduino.h library.
Update:
After I removed three files apparently related to the IDE from quarantine by my virus scanner, I deleted everything, and re-installed the IDE.  Now it compiles without error, but I cannot upload to the board in either Windows or Linux.  Of course I tried more than once to reinstall the Windows USB drivers, and they install without error, but the virtual device does not show up like it is supposed to, and the upload processor times out.

"This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences." Please post the detailed error messages.

install/reinstall the Arduino AVR core in Boards Manager

I added verbose output during compilation and edited the query to include the output..  I tried to re-install the AVR code.  There is nothing identified as the  "core".  I tried installing Arduino 1.8.5 and then reinstalling 1.8.6, and I tried removing and reinstalling the  MH-ET Live boards.  Neither worked.  There is a file C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++.exe and a file C:\Users\lrhorer\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\bin\avr-g++.exe.  Should I try re-installing the Digistump drivers from the command line?

the MH-ET boards package depends on Arduino AVR boards package. so again, reinstall the Arduino AVR boards package in Boards Manager. reinstalling the IDE doesn't reinstall Boards Packages

Didn't help.  See the update in the main text.

didn't help? you solved your original problem

Not by re-loading the Arduino AVR board.  That had no effect.  Now it compiles, but will no longer upload, which it also did just fine before this problem occurred.

Deleting / uninstalling the entire IDE and completely reinstalling allowed the code to compile, so I am closing this question.  It will not upload, so I will open another question.


text:
Fast digital IO
I have a device programmable via an 8 bit digital parallel bus. I would like an Arduino to translate from a parallel 4 bit output of an existing device to 8 bit by intentionally reducing the resuloution. Unfortunately, I can't just use the most significant bits as I want to change the step size. The idea is to use an Arduino that ready the 4 digital input bits and then computs the necessary 8 bit output which it output to the 8 bit bus. However, this need to be as fast as 1 us. Is this possible with an Arduino? If so which board would you recommend? I guess I can't use the digitalWrite command as this will be too slow though. Any suggestions?

You can do this with an Uno, provided it has nothing else to do. I would
program it low-level, skipping the Arduino core since, as you said,
digitalWrite() would be too slow for this application.
Here is my proposed approach: read the 4-bit input from one port, use a
look-up table to translate it to an 8-bit output, and write that output
to another port. I would use PORTD (pins 0–7) for the output, as it is
the only full 8-bit port on the Uno, then the first bits of PORTB (pins
8–11) for the input:
/* Translation look-up table (dummy example). */
const uint8_t lut[16] = {
    0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
    0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
};

int main() {
    DDRB = 0x00;  // set port B as input
    DDRD = 0xff;  // set port D as output
    for (;;) {
        uint8_t input = PINB & 0x0f;  // grab the lowest 4 bits
        PORTD = lut[input];  // set the output
    }
}

I compiled and disassembled this code to count the CPU cycles: the main
loop takes 10 cycles per iteration. Given that the Uno is clocked
at 16 MHz, this is one update of the output every 0.625 µs.
Edit: This is a straightforward approach. At the cost of some extra
complexity, it could be optimized down to 7 cycles per iteration
(0.438 µs), or even 6 cycles (0.375 µs) in assembly.

nice answer ... upvote for the effort

Thank you very much for the detailed answer and testing. One further question out of curiosity: Does this mean that if I go for an Arduino Zero, it will be (48 MHz / 16 MHz) 3x faster and for a Due (84 MHz / 16 MHz) 5x faster?

@P.Egli: Re: “if I go for an Arduino Zero [...]”: No. These Arduinos use an ARM architecture, which is completely different from the AVR architecture of the Uno. The code above may not be trivially ported to them. AVR is simple enough that you can count the CPU cycles simply by looking at an assembly listing. I doubt the ARM cores of the Zero and the Due are at this level of simplicity.


text:
USB serial communication arduino nano and jetson nano
I want to communicate between Jetson nano and arduino nano through serial.
I wrote a simple script to test functionality but I receive strange data
here is the arduino code
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

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

  Serial.println("work fine");
  delay(10000);
}

and this is the python code run on jetson nano
import serial
import time

arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)

while True:
  try:
     data = arduino.readline()
     if data:
        print(data)
        print('Hi Arduino')
  except:
     arduino.close

the output is
b'\x17\x0f\t\x0b\x01\x06\t\x0e\x15\r\n'
Hi Arduino

if tried different baud rates but nothing change.
when is use serial monitor on windows it works fine.

start by sending only one character every second

Wondering if this might be a UTF conversion problem.

refer to ASCII tables ... data bits are being dropped ... working in hex makes it clear ... the arduino sends 77, 6F, 72, 6B, 20, 66, 69, 6E, 65, 0D, 0A and the Jetson receives 17, 0F, 09, 0B, 01, 06, 09, 0E, 15, 0D, 0A ... possibly a speed mismatch, or the data buffer is being swamped by incoming data

regarding the speed, is there parameter other than baud rate that can cause mismatch?
I sent character "I" each 10 sec, but received b'\t\r\n'

Asynchronous serial transmission has 3 additional parameters: number of data bits, usage of parity, number of stop bits. A common set is 8-N-1, meaning 8 data bits, no parity, 1 stop bit. You need to check these. A mismatch on the number of stop bits is harmless, as long as the sender uses more than the receiver.

I also belive its to do with the following line,
 data = arduino.readline()

Try the following,
while True:

try:
     arduino.flushInput() // Clear buffer

     data = arduino.readline()

     // decode the bytes into str format, 'utf-8' arg should work
     data.decode('utf-8')

     // strip the \r\t in the str output
     data.strip()
     if data:
        print(data)
        print('Hi Arduino')
  except:
     arduino.close

See if this resolves your problem.
Note: I used an ESP32 and python script with the above-mentioned changes and it worked for me.
Also, as mentioned in the comment section some of the information might be missing in the output 'b'\x17\x0f\t\x0b\x01\x06\t\x0e\x15\r\n' this is not something reproducible for me. Just for reference my byte string output without the modifications was b'work fine\r\n' not 'b'\x17\x0f\t\x0b\x01\x06\t\x0e\x15\r\n'

double-check Arduino write speed,
double-check python serial connection baud rate,
include the py script correction

see if this helps resolve your problem.

This stackoverflow question/answer implies that .readline() needs to be converted to a string.
import serial
ser = serial.Serial("COM11", 9600)
while True:
     cc=str(ser.readline())
     print(cc[2:][:-5])

I agree w/one of the comments to that answer that it might be better written as:
import serial
ser = serial.Serial("COM11", 9600)
while True:
     cc=str(ser.readline())
     cc=cc.decode("utf-8")
     print(cc)

readline() returns numbers ... it's returning non-printable characters

... returns "Bytes" then?

there is no difference between text and bytes  ... it's all bytes ... the difference is how you present those bytes to the user ... the python code is printing text because it escapes non-printable characters ... the escape character is the \


text:
WiFiClient.cpp:517 flush(): fail on fd 48, errno: 11, "No more processes" what it mean?
Hello i wrote this sketch that upload a temperature reading of a DHT22 sensor to a phpMyAdmin server in localHost, the sketch work fine, the data been upload every 5 min to the server than ESP go t sleep, but every time the code has been executed i have the printout in the console of this error which i don't understand what mean.
[  1937][E][WiFiClient.cpp:517] flush(): fail on fd 48, errno: 11, "No more processes"

here below my sketch:
the sketch include the timer every 5 min to wakeup esp read the temperature and post to the server.
#include <Arduino.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>

// FOR T sensor
#define TsensorPin 4
#define DHTTYPE DHT22
DHT dht(TsensorPin, DHTTYPE);
String sensorName = "DHT22";
String sensorLocation = "Casa1";
float h;
float t;
float f;
float hif;
float hic;

// for wifi connection
const char* ssid     = "Captain Spiko";
const char* password = "123456789d";

// server data
const char* serverName = "http://192.168.50.158/esp_web/post_esp.php";
String apiKeyValue = "123456789";

// for awake and sleep
#define uS_TO_S_FACTOR 1000000
#define TIME_TO_SLEEP  300
RTC_DATA_ATTR int bootCount = 0;

void print_wakeup_reason(){
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  switch(wakeup_reason)
  {
    case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
  }
}

void readTemperature(){

  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true); // in F

  // Compute heat index in Fahrenheit (the default)
  hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

void activateSleep(){
  Serial.println("Going to sleep now");
  delay(1000);
  Serial.flush();
  esp_deep_sleep_start();
}

bool setupWifi(){
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  if (WiFi.status() == WL_CONNECTED){
    return true;
  } else {
    return false;
  }

}

void postData(){
  if(WiFi.status()== WL_CONNECTED){
    WiFiClient client;
    HTTPClient http;
    http.begin(client, serverName);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
                          + "&location=" + sensorLocation + "&value1=" + String(h)
                          + "&value2=" + String(t) + "&value3=" + String(f) + "";
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);
    int httpResponseCode = http.POST(httpRequestData);
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  }else {
    Serial.println("WiFi Disconnected");
  }
}

/// @brief  Set up
void setup() {

  Serial.begin(115200);
  delay(1000);
  ++bootCount; // tiene il conto dei restart
  Serial.println("Boot number: " + String(bootCount));
  print_wakeup_reason();
  if (setupWifi() == true){
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);// set up next wake up after 30 sec
    Serial.println(F("DHTxx test!"));
    dht.begin();
  };

}

/// @brief loop func
void loop() {
  readTemperature();
  postData();
  activateSleep();
}

at which device and in which program are you seeing the error?

I’m using VS code with platformio, I see this error on the esp32 serial print out, the one that post the data to the server .

FD probably means File Descriptor and 48 is the number. If it's Linux-like, basically everything is treated as a file: files, sockets, processes, ...

If setupWifi() == false, then dht.begin(); is never called but it still enters loop() and tries to read temperatures. Not sure if that's good or eventually runs into undefined behavior.

Also, I don't get why esp_sleep_enable_timer_wakeup() is only activated if it was possible to connect to the Wifi. If it was not possible to connect to the Wifi, you still goto into deep sleep. But you don't want to wake up after 30 seconds then?

if (WiFi.status() == WL_CONNECTED){ return true; } else {return false; } is cargo cult programming. It can be simplified to return WiFi.status() == WL_CONNECTED. Similar for if (setupWifi() == true), which is equal to if (setupWifi())

I think you ran into the issue described on Github issues for WifiClient.
A user has loooked into this and found that the error message does not match the problem:

errno 11 (EAGAIN) happens when you go to read (via BSD recv function) bytes from a stream with MSG_DONTWAIT flag and there are no bytes to be read. The ESP error string "No more processes" is misleading. It's really "No data available, try again later." or maybe "No data to process".

It seems that there's no fix for the package yet as of today, but another user has posted a derived class that fixes the problem:

File wifiFix.h:
#pragma once

class WiFiClientFixed : public WiFiClient {
public:
  void flush() override;
};

File wifiFix.cpp:
#include <WiFi.h>
#include <lwip/sockets.h>
#include "wifiFix.h"

#define WIFI_CLIENT_FLUSH_BUFFER_SIZE    (1024)

void WiFiClientFixed::flush() {
  int res;
  size_t a = available(), toRead = 0;
  if (!a) {
      return;//nothing to flush
  }
  auto *buf = (uint8_t *) malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE);
  if (!buf) {
      return;//memory error
  }
  while (a) {
      // override broken WiFiClient flush method, ref https://github.com/espressif/arduino-esp32/issues/6129#issuecomment-1237417915
      res = read(buf, min(a, (size_t)WIFI_CLIENT_FLUSH_BUFFER_SIZE));
      if (res < 0) {
          log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
          stop();
          break;
      }
      a -= res;
  }
  free(buf);
}

File main.cpp:
#include "wifiFix.h"
WiFiClient* wifi = new WiFiClientFixed();

Finally, instead of http.begin(url);, use http.begin(*wifi, url);

In Platformio.ini I changed config to "platform = espressif32@3.5.0" from "platform = espressif32". It solved this issue for me

How does this resolve the problem, i dont get the direct coloration?

This bug is solved in Espressif Arduino Core 2.0.14 which is out since last month. If you're using PlatformIO add this to your platformio.ini file:
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.05/platform-espressif32.zip

This is not from the official PlatformIO branch but from Tasmota, a trusted source in the PlatformIO community. See the github site: https://github.com/tasmota/platform-espressif32


text:
Atmega328P constantly restarting when defining a function
I wanted to make a simple led on/off program using USART interface. When the code doesn't have any functions other than main it runs fine, however Arduino keeps resetting when one is included. At this point I have no clue what could I be doing wrong. Here's the code:
#include <avr/io.h>
#include <util/delay.h>

#define BAUD 19200
#define BAUDRATE ((F_CPU / 16 / BAUD) - 1)

// void init()
// {
//     // Keeps resetting when uncommented, runs fine when commented
// }

int main() {
    // Initialize USART
    UBRR0H = (BAUDRATE >> 8);
    UBRR0L = BAUDRATE;
    UCSR0B = (1 << RXEN0);
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
    // Set bit 3 to output and pull it high
    DDRD |= 0b00001000;
    PORTD = 0b00001000;

    char char_arr[128];

    while(1)
    {
        int i;
        // Read USART
        for(i = 0; i < 128; i++){
            loop_until_bit_is_set(UCSR0A, RXC0);
            char c = UDR0;
            if(c == '\r')
                break;
            char_arr[i] = c;
        }
        // Handle received characters
        for(int j = 0; j < i; j++){
            switch(char_arr[j]){
                case '1':
                    PORTD = 0b00001000;
                    break;
                case '0':
                    PORTD = 0b00000000;
                    break;
            }
            _delay_ms(100);
        }
    }
}

Does this happen if the function has a name other than init()?

@EdgarBonet yes, function name doesn't matter

the compiler should remove that function during optimization, because the function is not used .... maybe the problem is in the compiler command line


text:
Automatic pet feeder with a simple menu type keypad
this is the sample code where the user enters A to set the number of times the pet needs to be fed. When I click A on the keypad it asks for the user to set the number. However, the keypad still somehow saves the input of A that is initially pressed. I want the system to ask for another input. How would I clear the memory of the keypad?
Here is the code attached
    /* Hello Wokwi! */
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const int ROW_NUM    = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3', 'A'},
  {'4','5','6', 'B'},
  {'7','8','9', 'C'},
  {'*','0','#', 'D'}
};
int col = 0, row =0;
byte pin_rows[ROW_NUM] = {10,9,8,7};      // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {6,5,4,3}; // connect to the column pinouts of the keypad
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

void setup () {

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(col,row); // move cursor to   (cursorColumn, 0)
  lcd.print("HI OWNER");
  delay(3000);
}
int h1,h2,hf1,min1,min2,minf1;
int numfed,setnofeed=0;

void loop() {

  char key = keypad.getKey();
  if(!key){
    displaytime();
  }

  switch(key){
    case 'A':
      lcd.setCursor(col,row);
    lcd.print("SET NO. OF");
    lcd.setCursor(col,1);
    lcd.print("FEEDING TIMES");
    delay(3000);

    lcd.clear();
    lcd.setCursor(col,row);
    lcd.print("MAX 5 MIN 2");
    col=0;
    lcd.setCursor(col,1);
    if (col==0&&setnofeed==0){
      numfed=key-48;
      lcd.print(numfed);
      delay(1000);
      col=1;
    }
    else if(col==1){
    lcd.setCursor(col,1);
    lcd.clear();
    lcd.print("NO. OF FEEDING");
    lcd.setCursor(col,1);
    lcd.print("SET");
    delay(2000);
    setnofeed=1;
    }

    break;

  }

}
void displaytime(){

      lcd.setCursor(0,0); // move cursor to   (cursorColumn, 0)
    lcd.print("Time now:");
}

where is the keypad memory?

don't be in a rush to do everything when A is pressed ... display the menu only, nothing else

What should I do instead? Are there any proposed solutions?

start by describing the program behavior, on paper,  in great detail ... a very detailed description translates into code almost directly ... anyway, you already have code that runs when A is pressed ... reduce it to display the menu only ... add code that runs when a numeric key is pressed ... add a variable to the program that keeps track of which menu is displayed


text:
Error with Mega2560 via SPI
I tried the following code to communicate via SPI with MPU9250 and Mega2560 But I got the following error:
Error initializing communication with IMU
Why I got this error?
/*
* Brian R Taylor
* brian.taylor@bolderflight.com
*
* Copyright (c) 2021 Bolder Flight Systems Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "mpu9250.h"

/* Mpu9250 object, SPI bus, CS on pin 10 */
bfs::Mpu9250 imu(&SPI, 10);

void setup() {
  /* Serial to display data */
  Serial.begin(115200);
  while(!Serial) {}
  /* Start the SPI bus */
  SPI.begin();
  /* Initialize and configure IMU */
  if (!imu.Begin()) {
    Serial.println("Error initializing communication with IMU");
    while(1) {}
  }
  /* Set the sample rate divider */
  if (!imu.ConfigSrd(19)) {
    Serial.println("Error configured SRD");
    while(1) {}
  }
}

void loop() {
  /* Check if data read */
  if (imu.Read()) {
    Serial.print(imu.new_imu_data());
    Serial.print("\t");
    Serial.print(imu.new_mag_data());
    Serial.print("\t");
    Serial.print(imu.accel_x_mps2());
    Serial.print("\t");
    Serial.print(imu.accel_y_mps2());
    Serial.print("\t");
    Serial.print(imu.accel_z_mps2());
    Serial.print("\t");
    Serial.print(imu.gyro_x_radps());
    Serial.print("\t");
    Serial.print(imu.gyro_y_radps());
    Serial.print("\t");
    Serial.print(imu.gyro_z_radps());
    Serial.print("\t");
    Serial.print(imu.mag_x_ut());
    Serial.print("\t");
    Serial.print(imu.mag_y_ut());
    Serial.print("\t");
    Serial.print(imu.mag_z_ut());
    Serial.print("\t");
    Serial.print(imu.die_temp_c());
    Serial.print("\n");
  }
}

Source code:
https://github.com/bolderflight/invensense-imu/blob/main/examples/arduino/mpu9250/spi/spi.ino
Connection:
MPU9250                 Mega 2560
    GND <.............> GND
    3V3 <.............> 3.3V
    SCL <.............> pin 52
    SDA <.............> pin 51
SDC/SA0 <.............> pin 50
    CSB <.............> pin 53

This is the sensor ( IMU 10DOF SENSOR MODULE MPU9250 BMP280 ( GY-91 ))
But I only interested on the MODULE MPU9250 readings via SPI

Is your Mega 5 VDC? Do the I/Os on the MPU9250 operate at 3.3 volts or are they 5 volt tolerant?

did you use the correct pins?

you got that error because the following program line runs when IMU does not return a successful start status ... Serial.println("Error initializing communication with IMU");

so, your question should really be asking why does imu.Begin() fail?


text:
localtime - executing one after the other- different time_t, but getting same results
When I try to comapre 2 time_t values I get unexplained behavour
time_t t = 12345;
time_t T = 67890;
struct tm *tm = localtime(&t);
struct tm *Tm = localtime(&T);

    char timeStamp[40];
    sprintf(timeStamp, "(1) %04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
    Serial.println(timeStamp);
    sprintf(timeStamp, "(2) %04d-%02d-%02d %02d:%02d:%02d", Tm->tm_year + 1900, Tm->tm_mon + 1, Tm->tm_mday, Tm->tm_hour, Tm->tm_min, Tm->tm_sec);
    Serial.println(timeStamp);

I get the exact same date.
When commenting out one of each set, I get the correct answer for each one.
Workaround I did was, but i'm sure there is an elegant way to overcome:
        time_t t = 12345;
        time_t T = 12345;
        struct tm *tm = localtime(&t);
        uint8_t now_month = tm->tm_mon;
        uint8_t now_day = tm->tm_mday;

        struct tm *Tm = localtime(&T);
        uint8_t save_month = Tm->tm_mon;
        uint8_t save_day = Tm->tm_mday;

        if (now_month == save_month && now_day == save_day)
        {
        }

From the manual page of localtime() (emphasis mine):

The asctime(), ctime(), gmtime(), and localtime() functions
shall return values in one of two static objects: a broken-down time
structure and an array of type char. Execution of any of the
functions may overwrite the information returned in either of these
objects by any of the other functions.

As a solution, I suggest you take a copy of the struct tm used by
localtime() to store its result, rather than keeping a pointer to it:
struct tm tm = *localtime(&t);
struct tm Tm = *localtime(&T);

Well somehow I missed that line when seeking the answer. I can't see how they managed to pull such bad design (or it  has a reason for that).... I have a shocked look as in your user's pic :) TNX!

@guyd it is the C language old time API


text:
subroutine with if else does not work
Everything in this code seems to work as expected except the subroutine speedcw at the bottom. It should change the time_delay variable.
#define ENA 2 //pin 2 on chip
#define in_A 0 //pin 0 on chip IN2
#define in_B 1 //pin 1 on chip IN1
#define in_C 3 //pin 3 on chip AUX
#define in_D 4 //pin 4 on chip AUX

byte PWM_PIN = 5;  //pin 5 on chip

int pwm_value = 1500;

int time_delay = 7;

void setup() {
    pinMode(ENA, OUTPUT);
    pinMode(in_A, OUTPUT);
    pinMode(in_B, OUTPUT);
    pinMode(in_C, OUTPUT);
    pinMode(in_D, OUTPUT);
    pinMode(PWM_PIN, INPUT);
}

void step1(){
    //A+,B+
    digitalWrite(in_A, 1);
    digitalWrite(in_B, 1);
    delay(time_delay);
}

void step2(){
    //A+,B-
    digitalWrite(in_A, 1);
    digitalWrite(in_B, 0);
    delay(time_delay);
}

void step3(){
    //A-,B-
    digitalWrite(in_A, 0);
    digitalWrite(in_B, 0);
    delay(time_delay);
}

void step4(){
    //A-,B+
    digitalWrite(in_A, 0);
    digitalWrite(in_B, 1);
    delay(time_delay);
}

void clockwise(long st){
    long i = 0;
    while( i < st ){
        //step1
        step1();
        //step2
        step2();
        //step3
        step3();
        //step4
        step4();
        i++;
    }
}

void counter_clockwise(long st){
    long i = 0;
    while( i < st ){
        //step1
        step4();
        //step4
        step3();
        //step3
        step2();
        //step2
        step1();
        i++;
    }
}

void loop() {
    pwm_value = pulseIn(PWM_PIN, HIGH);
    time_delay = 7;

    while (pwm_value <= 1450) {//red LED
        pwm_value = pulseIn(PWM_PIN, HIGH);
        digitalWrite(ENA, 1);
        //    digitalWrite(in_C, 1); //red LED
        //    digitalWrite(in_D, 0); //green LED
        // time_delay = 1;
        speedcw();
        clockwise(2);
    }

    while (pwm_value >= 1550) {//green LED
        pwm_value = pulseIn(PWM_PIN, HIGH);
        digitalWrite(ENA, 1);
        //    digitalWrite(in_C, 0); //red LED
        //    digitalWrite(in_D, 1); //green LED
        time_delay = 1;
        // speedccw();
        counter_clockwise(2);
    }

    while ((pwm_value >= 1451)&&(pwm_value <= 1549)) {
        pwm_value = pulseIn(PWM_PIN, HIGH);
        digitalWrite(ENA, 0);
        digitalWrite(in_C, 0);
        digitalWrite(in_D, 0);
    }
}

void speedcw(){
    if (pwm_value <= 900){
        time_delay = 1;
    }
    else if (pwm_value <= 1000){
        time_delay = 2;
    }
    else if (pwm_value <= 1100){
        time_delay = 3;
    }
    else if (pwm_value <= 1200){
        time_delay = 4;
    }
    else if (pwm_value <= 1300){
        time_delay = 5;
    }
    else if (pwm_value <= 1400){
        time_delay = 6;
    }
}

void speedccw(){
}

Are you sure that 'pwm_value <= 1450' is ever true? If not, then the code would just skip that while loop and not even call speedcw().

thank you, you were correct i made and error with the pwm i was feeding my code, 1300 was the lowest received.  im new to the arduino.


text:
Empty message parse using ArduinoJSON from aedes MQTT server
I'm using aedes as my custom MQTT broker and PubSubClient at the ESP32 side, together with the ArduinoJSON package.
My server test code:
import Aedes from "aedes";
import net from "net";

let port = process.env.MQTT_PORT || 1883; // MQTT Port

const id = "MY_SERVER";

const aedes = new Aedes({
    id: id,
});

aedes.on("client", async (client) => {
    console.log("Client conntected...");
});

aedes.on("subscribe", async (subscriptions, client) => {

    let topic = "cmd/" + client.id;

    let msg = {
        topic: topic,
        type: "test",
        param: "p1"
    };

    console.log("Sending command...")
    console.log(msg);

    this.aedes.publish(msg);

});

let server = net.createServer(aedes.handle, options);

server.listen(port, () => {
    console.log(`Find the server at: mqtt://localhost:${port}/`);
});

When running I'm getting:
Client connected...
Sending command...
{ topic: 'cmd/4CA9A712B42A', type: 'test', param: 'p1' }

At the client (ESP32) side I have my PubSubClient callback as follows:
void callback(char *topic, byte *payload, unsigned int length)
{
    Serial.println("Message received.....");

    StaticJsonDocument<256> doc;
    deserializeJson(doc, payload, length);

    char *command = doc["type"];
    char *param = doc["param"];

    Serial.println(command);
    Serial.println(param);
}

The callback is being called property after subscription - but I'm not being able to parse the payload:
Message received.....
<empty line>
<empty line>

How can I fix the server or client to allow then to send/parse correctly the payload.

Could you Serial.write(payload, length); in the callback and show us what it prints?

Did it - payload has length zero, so nothing is coming from the server...

Do you have another way of testing the server? Maybe sniff the connection?

No way to sniff.... need to try different approach

Found the problem.... Needs to have a payload property when sending message:  let msg = {topic: topic, payload: JSON.stringify({type: "test", param: "p1"})} did the trick.