text:
Can I use an arduino as an interface to pass files between a device and a PC?
Or maybe you guys can point me towards another direction...
You may ask, why not connect the device directly to the PC?
Well, the device is designed to recognize only USB sticks, and dump the data into them, so I cannot just plug my PC into it and retrieve the data (as far as I know...), because the PC acts as a USB host (I think).
So I thought about using an arduino and make it act as a USB stick, and then pass the data from the arduino to the PC.
Is this possible? Or maybe what I need is a raspberry pi?
Every suggestion is welcomed. Thank you in advance!

use an SD-USB adapter and an arduino sd card reader module, and of course an sd card.

Please post answers in the answers section. I don't know if your "answer"
is correct but I can't vote it down as it isn't an answer.

To do what you suggest you'd really need a microcontroller with two native USB interfaces. I only know of one family like that off hand (the PIC32MK series), and that doesn't have an Arduino core available for it yet (as I haven't had time to add support to chipKIT).

You have a device that saves information to a USB stick, is that right? Like a scanner or some sort of temperature logger?
To emulate a USB stick would be quite a task, because what you would have to do is pretend that you have a file system, as your device will be opening files, writing to them, and closing them.
It sounds like a lot of work - it might be easier to get another device that actually logs to something like a serial port.
Having said that, it seems on the face of it to be a reasonable request. Just as an example, I have a scanner that writes to a USB stick. It would be handy to have it send files directly to my PC without having to move the USB stick around all the time.
See Make a computer act as a virtual USB device for other equipments as an example of a similar question, with answers suggesting that it might be possible, for example USB-USB cables.
Even if you got it to work, it might be tedious to use. For instance, if your gadget appends to some file on what it thinks is a USB stick you would have to emulate that file system, and then check on your PC if the file has got larger, and thus have new data on it.
Plus possibly the expense (and time) involved in getting this working might be more than just getting another gadget that actually logs via some sort of port, like serial or RS485.


text:
Infrared Reciver doesn't work properly after the first signal
i'm trying to play a passive buzzer with an IR reciver
My Code

#include <IRremote.h>
IRrecv irrecv(10);
decode_results results;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(11, OUTPUT);//buzzer
  irrecv.enableIRIn();//Ir reciver at pin 10
}

int cmdex = 0;

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

  if(irrecv.decode(&results)){
    cmdex = 1;
    Serial.println(results.value);
    unsigned long data = results.value;
    switch(data){
      case 0xFF30CF:
        noTone(11);
        tone(11, 1056);
        break;
      case 0xFF18E7:
        noTone(11);
        tone(11, 571);
        break;
      case 0xFF6897:
        noTone(11);
        break;
    }
    irrecv.resume();
  }
}

Issue
My problem is that if i use any button instead of 1 (FF30CF) 0 (FF6897) or 2 (FF18E7) the serilal port give me the right data, then when i pusch 1 the buzzer starts to play but when i push another button, the data keep changing at every push.
Serial Output
FF10EF (here I push 4)
FF38C7 (here I push 5)
FF5AA5 (here I push 6)
FF30CF (here I finally push 1 and the buzzer starts to play)
(then I push 3 times 0, but the output is different from the expected FF6897 and the buzzer doesn't stop)
D965AA42
EB670632
AB03A967
Note

I'm using the IRremote.h library

does IRremote use Timer2 used by tone()?

as per @Juraj comment ... please refer to https://stackoverflow.com/questions/62832918/function-tone-and-irremote

Ok thanks, how ca I solve the timer issue?

source: Stack Exchange

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

sort: votes


text:
esp8266 wifi/ read serial data with python
I'm trying to read some serial (ADC) data from my esp8266 nodeMCU v3 over wifi using python.
I connected the esp on my local wifi and set it with fixed local IP using arduino IDE, but I couldn't find a way to extract the data using Python.
In a normal case, I just type in my python code the COM Port number and the Baudrate and just read. But with Wifi I counld not find a simple solution.
any Ideas ?
Thanks

There is no simple Serial via Wifi. You can look into websockets. I think that would be the way to transmit the data over the wifi network

You can run an httpserver on the esp and request desired data via wifi. Here's a tutorial https://randomnerdtutorials.com/esp8266-web-server-with-arduino-ide/

A basic TCP connection via WiFiClient would be easier than web sockets or an HTTP server, and would provide a reliable byte stream.

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


text:
Delay() and millis() functions don't work in cpp external files
I'm currently facing an issue using delay() and millis() functions in an external cpp file.
The issue is that when I used delay() in my main program (meaning .ino file) it works well but when I call the same function in an external cpp file, I'm stuck in the delay function. Concerning the setup, the .hpp linked to the used cpp is well included in the .ino file and the librairy Arduino.h is included in my cpp. I also tried to replace delay by a loop using millis but the value returned by millis is always 0.
I'm using an Arduino mega2560 and a water level sensor in the follwing example. The Arduino IDE version is 1.8.16.
Here is an extract from my ino file:
#include <Arduino.h>
#include "DS3231.h"
#include "MyGardenClock.hpp"
#include "sensors.hpp"
#include <LiquidCrystal.h>
#include "Keypad.h"
#include <Wire.h>

///Time object creation
DS3231 clock; //Clock object -> contains basic Real Time Clock functions
RTCDateTime dt; //Struct from DS3231 lib - contains date and time
mG_RTC myClock; //Object that contains specific clock functions to my project like printing date and time on the lcd...

///LCD object creation
//--Pin allocation
const int rs = 2, en = 1, d4 = 4, d5 = 7, d6 = 8, d7 = 10;
//--LCD dynamic object creation
LiquidCrystal* pLCD = new LiquidCrystal(rs, en, d4, d5, d6, d7);

///Keypad parametrization and object creation
//Define col nb and row nb
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {52, 50, 48, 46}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {44, 42, 40, 38}; //connect to the column pinouts of the keypad
//Keypad dynamic object creation
Keypad* pKpd = new Keypad(makeKeymap(hexaKeys),rowPins,colPins,ROWS,COLS);

///Sensors object creation
//WaterLvl Sensors
//--Pin allocation
const int WtrLvlAnalogPin = 8; //pin used to read value from water lvl sensor
const int WtrLvlPowerPin = 35; //pin used to power the sensor before reading a value
//--WaterLvl dynamic object creation
Water_Lvl_Sensor* pWtrLvlSens = new Water_Lvl_Sensor(WtrLvlAnalogPin,WtrLvlPowerPin); //contains the delay and millis functions that don't work

/////////// TEST FUNCTIONS ///////////
void testLCD_Kpd(Keypad*,LiquidCrystal*); //test lcd and keypad
void testWtrLvlSens(Water_Lvl_Sensor*,LiquidCrystal*); //test water lvl sensor

void setup()
{
    Serial.begin(9600);
    pLCD->begin(16,2);
    testLCD_Kpd(pKpd,pLCD);
    testWtrLvlSens(pWtrLvlSens,pLCD);

}

void loop()
{

}
////////////////////// TEST FUNCTIONS ///////////////////////////
void testLCD_Kpd(Keypad* pKpd, LiquidCrystal* pLCD)
{
   char test;
   test ='i';

   pLCD->print("Hello");
   do
   {
    test = pKpd->waitForKey();
   }while(test=='i');
   pLCD->clear();
   delay(3000); //This one work well
   pLCD->print("test = ");
   pLCD->print(test);

}

void testWtrLvlSens(Water_Lvl_Sensor* pWLS,LiquidCrystal* plcd)
{
  int wtrLvl;
  wtrLvl = pWLS->getCurrentWaterLvlValue();
  plcd->setCursor(0,1);
  plcd->print("wtrLvl = ");
  plcd->print(wtrLvl);

}

Here is an extract from my cpp file:
#include <Arduino.h>
#include "sensors.hpp"

/********************************************
*   CLASS WATER LvL SENSOR DESCRIPTION      *
********************************************/
///Constructor
//-- Assign pin number (analog & digital)
//-- Define pinMode for VCC + set to low
//-- read and store actual waterLevelValue as initial val
Water_Lvl_Sensor::Water_Lvl_Sensor(int anPinNb, int DigPinNb)
{
  //Variable used for millis
  unsigned long prevTime;
  unsigned long currentTime;
  const unsigned long delayTime = 100;

  Serial.begin(9600); //to debug

  //Assign analog and digital pin numbers
  analogPinNumber = anPinNb;
  VCC_digitalPinNumber = DigPinNb;
  pinMode(VCC_digitalPinNumber, OUTPUT); //Digital pin to power the sensor
  digitalWrite(VCC_digitalPinNumber,HIGH);//Turn sensor ON before reading initial value

  //delay(100); //not working ???
  prevTime = millis(); //get and store actual time
  do
  {
    currentTime = millis(); //get actual time
    Serial.println(currentTime); //print actual time (debug only)
  }while(currentTime<(prevTime+delayTime)); //while time spent < 100

  currentValue = analogRead(analogPinNumber); //read analog value

  digitalWrite(VCC_digitalPinNumber,LOW); //turn sensor OFF
  historyValue = currentValue; //init history val
  minValue = 0; //default value - sensor dry
  maxValue = 520; //default value - sensor under water
}

Does anyone has a solution?
I hope I've given enough details. If not, please feel free to ask.
Thanks!

The Arduino framework does some initializing for you before going into setup() and loop(), for example configuring Timer0 correctly for millis(), delay() and siblings. This is done in the main() function, which then after the first initializing calls setup() and loop().
But the creation of globally defined objects (and thus the execution of their constructors) is done even before the main() function. At that time neither millis(), nor delay() will work, since the hardware Timer0 is needed to be configured correctly for them to work. The hardware timer generates interrupts with a specific frequency and in the corresponding ISR (Interrupt Service Routine) the variable for millis() is incremented. If the Timer0 isn't configured, it's interrupt cannot trigger and thus millis() will stay zero. So you cannot do all that in the constructor of the object, or you always need to create the object in setup() or loop().
For this very reason most hardware related Arduino libraries use a .begin() method to initialize the hardware related stuff. That function can be called on the global object in the setup() function, when everything else is already configured correctly.
What to do now? Create a .begin() method for your class. Move all the code from the constructor (except for the pin number assignment) into this .begin() function. And then call that function in setup().

Thanks a lot for your quick answer. It really makes sense, indeed.  I'll make the change and tell you if it works, but I'm confident.

Hi chrisl, just to let you know your solution works well. Thanks a lot.


text:
Millis() based timer program for 24x7 usage in Arduino
I have made an irrigation system using Arduino. Timer program is based on comparing the previous Millis() and current Millis(). I want to know the chance for error when the currentMillis() overflows and start from zero after 50 days, while the previous Millis() stored in the variable remains as a larger value.

What do you mean with "chance of error"? If you do it like in the BlinkWithoutDelay example the overflow is no problem as long as the time difference between the previous millis() value and the current one stays below the ~50 days, since millis() just cannot count longer.

See How can I handle the millis() rollover?.

arduino timekeeping is not accurate if you do not use an RTC module .... it is ok for timing intervals, such as watering every 12 hours ... but it is unable to water at a specific time

this may be useful ... https://github.com/OpenSprinkler


text:
Getting location working on SIM800L with TinyGSM?
Hey Arduino enthusiasts :)
I have purchased a LilyGo T-Call board. Which has a Esp32 processor and a SIM800L GSM module. For my project i want to send location data over the 2G cellular network. I am using the TinyGSM library for communicating with the GSM module, and it is working great so far. Communications with the modem, and sending SMS and cellular data is working correctly.
The challenge i am facing is retrieving the location data using the GSM network. In theory this should work fine. My module supports it as well as TinyGSM. But i just cannot seem to get a fix on the location. Running the example script allFunctions link with only gprs and GSM location test running I get the attached at logs. I have naturally read the TinyGSM readme and followed their troubleshooting section.
In my research i found some relevant resources. This github issue states the same problem, and with the exact same board. His problem however was about not getting SSL working which i do not need for my project. And from his AT logs you also see him getting a location after a little while. This SIM800L datasheet documents the CLBS AT command. What i understood from it is that I am getting the <locationcode> = 3 response which should be a NET error. But that does not really tell me much. There is also this TinyGSM gitter chat for the library.
I feel really lost here, so any help would be gladly appreciated :)

cannot seem to get a fix ... what does "seem to" mean? ... please describe the problem in detail, including a description of the data you expect and the data you actually get

You describe someone else's problem more than the problem you are facing, you provide nothing than "cannot seem to get a fix". TinyGSM behind the scene set the timeout for 2 minutes for querying GSM Location, and done twice (one for getting a String, another for getting a struct) in AlluFunction example, if all done right and you still don't get the location, you might want to check with your carrier whether the network support the feature or not. Not all the features that the module supported get supported by the carrier network, some need extra subscription fee.

BTW, GSM Location is Cell-based LBS, it does get a "fix" like GPS. It uses the cell-tower fingerprints that your module could "see" to querying a database to get back a lat,lng with accuracy of +/-500m.

thank you guys for comments. do you suggest i create a new more detailed post or should i edit this post?


text:
Should I use C or C++ for a pure code implementation of Arduino?
I have an arduino board (SAMD21 microcontroller) which supports either Arduino or CircuitPython programming. I'd like to program in pure C/C++ instead of Arduino, which seems to be possible without too much trouble. But I'm not sure whether to use C or C++. I thought Arduino was based in C++ but I went to look at some of the library files and they were written in C. Since I'm pretty sure they're not interchangeable, can someone help me learn which language I should use to program my board?

Whichever you are most comfortable in. C is a subset of C++ (or the other way around - C++ is a superset of C).

You can effectively use either c or c++ in Arduino. There's a few caveats to be aware of, but they both work. You can even inline assembly if you want.

I thought Arduino was based in C++

There is no language "Arduino" - the Arduino IDE runs a the GNU C++ compiler so "its language" is the language supported by the compiler. It is primarily C++ with a little bit of preprocessing done to your code to help learners get past some of the places they can trip over easily (adding #include statements when it thinks you need them, for instance).
Here is an answer I wrote to a similar question a few years ago. I think it's relevant to your question.


text:
Sunfounder IR remote controller issue
I've been making a hoverboard using arduino, tinkercad and c++ (pic included). When I wired it up irl, I wired it exactly as I did in the picture (arduino UNO)
However, when I tested it out, it didn't work. The IR sensor got signal from my Sunfounder IR remote, but the fans didn't turn like I expected it to. The entire thing works fine with tinkercad.
I'm really sure it's not my wiring, since I took extra extra care to wire it properly.
This leads me to believe that it's a problem with my remote code
The IR remote control used was a random one in tinkercad. I'm using sunfounder ir remote irl.
Starting line 37, I've put code that uses the remote in the tinkercad to control the motors.
Is it possible that I need to recode specifically with the cases of the sunfounder IR remote? If so, where can I find a list of what buttons are what cases/code. so that I can rewire the entire thing?
I hope you all can help me. Thank you! :)

Did you check what codes the real remote sends fpr each button? They are most likely not the same as in tinkercad. Have you tried printing the received values to Serial so that you can see them in the Serial Monitor?

why would you need a list of codes?

You're saying that your remote is SunFounder's so I assume this is the one?

If it is then this should be the equivalent codes:

Try if it works for you.


text:
Rfid Mfrc522 not working using long cable
I am doing a project using Arduino and a Rfid Mfrc522 module that consists of reading a card to unlock/lock a door. The Arduino is 3 meters far away from the Rfid Mfrc522 module and I used 7 cables to connect it, according to the schematic of the Mfrc522 Arduino library. When I previously tested the system everything was working fine but after I connect the Arduino to the module with the 3 meters cable I get this output and I can not read any card.
Firmware Version: = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...

When I try to run the firmware check example for the library I get the following output
*****************************
MFRC522 Digital self test
*****************************
Firmware Version: = (unknown)
-----------------------------
Only known versions supported
-----------------------------
Performing test...
-----------------------------
Result: DEFECT or UNKNOWN

Is it possible that 3 meters away from Arduino the module is unable to communicate with it? If so what can be a possible solution to extend the "communication range" between both of them?
Thanks for the help,
Enzo

You are using 7 individual wires? That sounds bad, because that's 7 antennas. While I can't say that it will work, I'd at least try a shielded cable (you can try a standard CAT-5 cable)

Try slowing down your SPI communication. Also quadruple-check your wiring.

@PMF Thanks for the answer I will try to do that. So the issue is that each cable interferes with each other or the noise outside in air interfere with the 7 cables? Because my cat 5 cable I have at home is shielded between the 8 wires and the surroundings, not between each other. Thanks

@Majenko Thanks that could also help, do you know how I can do this in the Arduino code editor?

Depends on what library you are using. Read this: https://www.arduino.cc/en/Reference/SPISetClockDivider

@Enzo Both could be an issue. That's why good CAT-5 cables use twisted pairs, which filters interferences between two wires. I can't say which ones to put together for an SPI connection, though.

Don't use the SPISetClockDivider() as it is a deprecated method since 2014. Using the SPISettings() object to setup SPI configuration. If you are using this library it allows you to define a variable to set the clock speed and pass it in to the SPISettings object. By default, the SPI clock is set at 4MHz, I would suggest you try change it to 1MHz.


text:
Issues with the TX pins for recieving data from the HM19 and HC05
I bought a hm19 (link 2), 2 hc05s, an Arduino micro, and an Arduino due. I'm trying to turn an led on and off using my phone over Bluetooth. I verified that all modules work by themselves. So here's my issue.
First is that the Hc05 (link 1 below) modules simply do not respond to any AT command at all but work for serial communication. I have tried shorting a pin to send it into AT mode but that just made it impossible for me to communicate with it since I cannot get any input on my desktop using an USB cable from the Bluetooth module which brings me to the second issue.
Second is that I can send inputs from the serial monitor from my desktop to my phone but i cannot send data from my phone to my desktop. I have tracked this issue down to being in between the Bluetooth module and the Arduino. I have strong reasons to believe that DSD tech (hm19) have mislabled their bluetooth module because plugging rx into rx, tx to tx, gnd to gnd, and vcc to 5v works while flipping the rx and tx pins gives me a weird format.
Is there anyway I can fix the second issue preferably so i can diagnose the first one myself?
Link 1: https://www.amazon.com/gp/product/B07C1PXM44/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1
Link 2: https://www.amazon.com/gp/product/B07MBLVHH8/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1
Connecting RX to TX and TX to RX

Connecting RX to RX and TX to TX

All inputs were "1" and were sent from my desktop to my phone
here's the code run using an Arduino DUE with the TX0 and RX0 pins
char inputByte;
void setup() {
 Serial.begin(9600);
 pinMode(13,OUTPUT);

}

void loop() {
while(Serial.available()>0){
  inputByte= Serial.read();
  Serial.println(inputByte);
  if (inputByte=='Z'){
  digitalWrite(13,HIGH);
  }
  else if (inputByte=='z'){
  digitalWrite(13,LOW);
  }
  }
}

Have you read this HC-05 "how-to" or an equivalent? When I last used an HC-05, this is what I needed to get it going.


text:
Can no longer select a port in Arduino IDE on Linux?
I am trying to upload to my Elegoo Mega 2560. I previously had it set up properly with the board installed and selected and the port automatically detected.
Now when I go to Tools and hover my mouse over Port nothing happens. I don't get an additional menu showing the port that is detected.
At the bottom of the IDE it says:
Arduino Mega or Mega 2560, ATmega2560 (Mega2560) on /dev/ttyACM0

But when I attempt to upload i get this error:
avrdude: ser_open(): can't open device "/dev/ttyACM0": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
avrdude: ser_send(): write error: Bad file descriptor
avrdude: stk500_send(): failed to send command to serial port
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: Bad file descriptor
avrdude: stk500_send(): failed to send command to serial port

When I run the following command:
ls /dev | grep ttyACM0

I get no output and error code 1, which indicates that this port doesn't exist. The board is plugged in and some leds are lit up so it is receiving power. I tried reinstalling the drivers via board manager and deleting the files in the arduino15 directory and reinstalling the drivers. I've tried uninstalling and installing arduino ide all together but I still get the same error.
Why does it think it is at /dev/ttyACM0 but then at the same time it can't access it on this port?
This isn't working on my arch linux machine. Plugging the same board into a windows 10 machine and uploading the same code works just fine.
After reinstalling Arduino IDE on Arch Linux it no longer shows the board at ttyACM0 instead just showing a '-'

The output from dmesg might be helpful.

the IDE remembers the last selected port even if the port is no longer available. don't get distracted by that and do the common port-not-available trouble shooting. try different USB cable, USB connector, computer...


text:
NodeMCU dev board shows 13 for ADC when grounded - why?
I have a NodeMCU 1.0 ESP-12E development board.  Trying to hook up a LM35 to measure temperature.  For that I need to use the analog pin A0. However it seems my sensor is out by about 4C.  I traced this to an offset error - when the board is connected via USB to the PC, and I connect analog pin A0 to analog ground with a jumper on the board, I read 13 from analogRead(A0).  I should be getting 0.  I confirmed with a voltmeter that A0 is at ground potential.  I have nothing else connected to the board.  When I feed in 3.3V to A0, I get 1024.  When I hook up the LM35 which outputs 210mV, I get a reading of 81 which is 13 off (based on the standard analogValue / 1024 * 3300 calculation).
What am I doing wrong?

just subtract 13 from the adc read, problem solved.

Won’t work as I said, it is 13 when wifi is off, 2-3 if wifi is on. That will not be reliable.

The input A0 is not actually an ADC input. Instead it's the input to a voltage divider which then goes to the ADC input. The ESP8266's ADC is only capable of reading up to about 1.1V, so the makers of the NodeMCU helpfully created a small voltage divider (two resistors) to drop the input voltage to the range the ADC can cope with.
Except it's not perfect.
The resistors used aren't 100% precise, so the actual values you get from the ADC vary slightly from board to board. To get more precise readings you will have to first calibrate your ADC by providing known stable voltages to the ADC and logging the read values. Or you can measure the resistors used on your board and use those in the calculation to determine actually what value is being seen by the ADC.
Or you can use an external ADC that doesn't require the voltage divider circuit to function, which would be my preferred method, since the internal ADC is not great.

Thanks for the response.  I am aware of the voltage divider, however their tolerances would not be enough to cause a reading of 13 when shorted to ground - surely?  13 is the equivalent of 41mV.  Also, I just observed something else - when I start WiFi on the device, the shorted-to-ground reading drops to 3.  This is very strange...

The ADC is tightly coupled to the WiFi functionality. It's a really really crap arrangement. You really would be better using an external ADC.

Just ordered an ADS1115 - will give that a go - thanks again.


text:
Controlling a 5V fan and ultrasonic fogger with an arduino - do I need an external power supply?
I know the whole controlling a fan with an arduino thing is getting old, but somehow I still don't get it to work. Tried to answer it based on other questions but I am too much of a newbie to extrapolate the info there to my specific problem.
For my project of building an arduino-controlled mushroom grow box, I need to control a PC fan and ultrasonic fogger. I chose these two products:
DC 3-12V Ultrasonic Fogger,
DC 5V Fan
I hoped that by using 5V devices, I could connect them to the 5V pin of the arduino to power them. However, with the whole setup (see circuit and photo), they don't run. I'm using a BC337 transistor. I tried them both separately, but nothing.

I know that there is a resistor missing in the photo, I forgot to put it back in when I took it.

The fan works if I just insert it between 5V and GND but the fogger doesn't do anything.
The code works (and is fairly hard to mess up) but I'm including it anyway.
const int fan = 3;

void setup() {
  pinMode(fan, OUTPUT);
}

void loop() {
  digitalWrite(fan, HIGH);
}

Do I need a higher voltage power supply or is something wrong with my transistor choice? Which parts would be a better fit? Or am I entirely on the wrong track?
In the end the full thing should also contain an LCD display and a SCD41 sensor, both connected via I2C.

Thanks in advance!

the fan red wire is not connected to any part of the circuit

About the ultrasonic fogger:
The product description is misleading. This is a pure transducer. That means it does not generate its own ultrasonic frequency and is thus not DC. You need to provide an AC voltage at the frequency of 113kHz (though one reviewer states to have received products with a resonance frequency of 108kHz. Maybe just try out what you have). You can use utilize Timer1 to generate a fitting square wave at one of its output compare pins.
Note: Since you are more at the lower end of the foggers voltage rating you might see a bad performance when you get it to work. For it to work with its full power you should probably drive it with 12V, utilizing its full range.
About the fan:
As jsotola already stated in the comments, the red wire of the fan is not connected to the circuit. If you look at your breadboard you will see that the blue and red lines are interrupted in the middle of the breadboard. This means, that the rails are disconnected here (divided into the left and the right part of the breadboard). Move the red fan cable to the left of the red LED jumper wire. Then you should be connected.

Oh boy, now I feel dumb. Seems like I never used so much space on the breadboard before to notice this. I'll try your suggestions and hope that the fogger has enough power at 5V - or else get higher voltage power source for it! Thank you so much for the quick help

In regards with your schematics

Are you sure you want your stuff working only when both D3 and D5 are up? Because it seems to me you connected them in series, so if one transistor is down, nothing's gonna work.

check the power rating of the ultrasonic transducer, if you get your power source from the computer USB port, you will get at best about 2.2W from the 5V pin. It may turn out that it may be insufficient to produce any notable effect from the transducer with that, especially if you have the fan powered too.

Most modern PC USB ports (except maybe a laptop running very conservative power settings) will merrily provide at least 5V1A despite lack of negotiation. Even if it runs through the regulator (though I think USB power in usually doesn't), that gives us 800mA - 50mA for the arduino = 750mA * 5V = 3.75W. The transducer is rated 1.5W and the fan is likely 1.0-1.5W, so there's plenty of headroom.

You're right, I meant to put them in parallel and completely messed up the second circuit drawing in my panicky state yesterday! Thanks for pointing this out.


text:
Blinking a led using assembly language at different frequencies using two push buttons
I want to blink a led using assembly language and arduino
I want the circuit to have a normal state of 5 hz blinking frequency
Then use two push buttons to increase or decrease the blinking frequency
The up button will increment the blinking frequency by 5 hz step until the led seems to be continuously on
While the down button will decrement the blinking frequency by 5 hz step until the normal state again
Is this achievable ?
And if any one can point me where to start as this the first time i am using assembly language but i am familiar with arduino

Have you seen these Q+As? https://arduino.stackexchange.com/search?q=assembly

Totally achievable. Have you looked into some assembler tutorials for AVR microcontrollers/Arduinos? A short search seems to give promising results. What have you tried so far? Have you tried building the code step by step, starting with turning on an LED, then blinking it, then reading a button?

It is achievable, yes. After all, the C++ compiler turns code into assembly code. But why do you want to do this? Is it a homework exercise?

1-No i haven't looked at the q&a but i will thank you
2- no i haven't tried anything yet since i am total newbie in assembly language and i was looking for guidance
3- yes and no , this is an optional assignment in my course that has no credit but our instructor gave it for our benefit

Here is one example of how to blink an LED in assembly coding on an Arduino UNO. You can attempt to solve your challenge. If you are stuck, please post the code and the connections and I am sure, you will get help again.
The code is here
#define __SFR_OFFSET 0

#include "avr/io.h"

.global main

main:
  sbi   DDRB, 5     ; Set PB5 as output

blink:
  sbi   PINB, 5     ; Toggle PINB
  ldi   r25, hi8(1000)
  ldi   r24, lo8(1000)
  call  delay_ms
  jmp   blink

delay_ms:
  ; Delay about (r25:r24)*ms. Clobbers r30, and r31.
  ; One millisecond is about 16000 cycles at 16MHz.
  ; The inner loop takes 4 cycles, so we repeat it 3000 times
  ldi   r31, hi8(4000)
  ldi   r30, lo8(4000)
1:
  sbiw    r30, 1
  brne    1b
  sbiw    r24, 1
  brne    delay_ms
  ret

Link to the project: https://wokwi.com/arduino/projects/290348681199092237

thank you sir, your help is greatly appreciated


text:
RF Keyfob single button code
I'm making a project where a 2 channel RF keyfob (433Mhz) controls an led using arduino nano. As for the hardware everything works and I have tested it with the example decoder code and it works fine. Library I'm using is the RCSwitch.h for receiving.
I have modified the library example code a bit to suit my project. What I'm basically trying to achieve is make an led turn on when I press button A on the keyfob and after a while if I press button A again then the led must turn off. However with my current code, what happens is pressing button A makes the led turn on and pressing button A again does nothing, but if I press button B then the led turns off. So where did I go wrong?
Here is my code
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
int LED = LED_BUILTIN;
boolean statusled = LOW;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available())
  {
    Serial.print(mySwitch.getReceivedValue());
    unsigned long int num = mySwitch.getReceivedValue();
    Serial.print(num);

    if (num == 16130609){
    mySwitch.disableReceive();

      if (statusled == LOW)
      statusled = HIGH;
    }
    else
    {
      statusled = LOW;
    }

    digitalWrite(LED, statusled);
    unsigned long time_now = millis();
    int ck = 500;
    while(millis() <time_now + ck)
    {;}

    mySwitch.resetAvailable();
    mySwitch.enableReceive(0);
  }
}

16130609 is the value I get from decoding button A
16130610 is the value from button B

Look again at your logic here:
if (num == 16130609){
    mySwitch.disableReceive();

    if (statusled == LOW) statusled = HIGH;
}
else
{
    statusled = LOW;
}

When you press A you will get num with the value 16130609. In the if you turn the LED on, if it is off currently. But you never turn it off there. You will always get in this if statement when pressing A. You don't turn the LED off there, so it doesn't turn off when you press A. When you press B you get another value for num. Thus the else clause will get executed, turning the LED off.
So the code is doing exactly, what you told it to do.
Solution: Since you want to toggle the LED on press of A, you should just toggle the value of statusled in there, instead of explicitly setting it. That would look like this:
if (num == 16130609){
    mySwitch.disableReceive();

    statusled = !statusled;
}

I removed the else clause, since you don't want button B to do anything.

Ohhh..now I see what went wrong with my if,else command. Thanks, your code worked. I didn't know (!) command existed to toggle. I thought it was just a comparator.

@Kokachi the ! is not a comparator ... it is a logical NOT

As jsotola wrote its the logical NOT operator. It will negate the value of the operant, so making true to false and vice versa.

I understand it now. Previously when I went through the documentation I saw ! in comparison operator. I think it was !=


text:
Serial.parseInt works for first menu but now in a sub menu
I am trying to use the Serial object to print some lines giving the users some options to select by entering an int. It works at this main menu. But when the user selects 1 I use Serial again to print some lines and collect another int. But in this submenu it prints the line, waits a second and then continues back out to the main menu. Below is my entire sketch:
int menu = 0;

void setup() {
  // put your setup code here, to run once:
  //Starting the serial comm
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (menu == 0) {
    //Prints the menu to the serial port
    Serial.println("Select an option:");
    Serial.println("-----------------");
    Serial.println("1) Do Submenu");

    menu = getSerialInt();
  }

    //Used to calibrate the pen height
  if (menu == 1) {
    int calibrating = 1;
    while (calibrating == 1) {          //While loop that will continue until "0" is sent in the serial port
      Serial.println("Enter a pen value: ");
      int penMove = getSerialInt();

      Serial.println("You entered: ");
      Serial.println(penMove);
      if (penMove == 0) {
        calibrating = 0;
      }
    }
    menu = 0;   //Sets the menu variable back to 0
  }
}

int getSerialInt() {
  int retInt;
  Serial.flush();

  while (!Serial.available()) {}  //Waits for an input on the serial device
  retInt = Serial.parseInt();       //Takes the Serial input and looks for an integer
  Serial.flush();

  return retInt;
}

Thanks in advanced for any help trying to debug this.

Based off this thread: https://forum.arduino.cc/t/parseint-clears-serial-available-but-leaves-terminator-in-serial-buffer/515199/8
And some other threads talking about carriage returns, I rewrote getSerialInt to call parseInt() twice to trow away the carriage return:
int getSerialInt() {
  int retInt;
  Serial.flush();

  while (!Serial.available()) {}  //Waits for an input on the serial device
  retInt = Serial.parseInt();       //Takes the Serial input and looks for an integer
  Serial.parseInt(); // throw away carage return
  Serial.flush();

  return retInt;
}

There is probably a better way to do this...


text:
Pressed Buttons are permanently low and one of them is not working
I am a beginner to Arduino, and I'm having a problem in a project that I am currently working on.
I was just beginning to write the code, after preparing the components and the wiring, and suddenly two of my buttons never stopped outputting, despite my instructions to only output when the buttons are low, and the other one doesn't do anything at all.
I am using three buttons, one of them is a interruptor switch.
Here is my code:
#include <Adafruit_NeoPixel.h>

#define PIN 3    // input pin Neopixel is attached to
#define NUMPIXELS 28 // number of neopixels in strip

#define TRAVAO 8
#define PISCA 13
#define QUATRO_PISCAS 11

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int redColor = 0;
int greenColor = 0;
int blueColor = 0;

void setup() {
  pixels.begin();

  pinMode(TRAVAO, INPUT_PULLUP);
  pinMode(PISCA, INPUT_PULLUP);
  pinMode(QUATRO_PISCAS, INPUT_PULLUP);

  Serial.begin(9600);
}

void loop() {
  if(digitalRead(TRAVAO) == LOW) {
    Serial.print("bbb");
  }

  if(digitalRead(PISCA) ==  LOW) {
    Serial.print("ccc");
  }

  if(digitalRead(QUATRO_PISCAS) ==  LOW) {
    Serial.print("ddd");
  }

  delay(1);
}

Here is my arduino:

I count 42 "pixels" and the code says #define NUMPIXELS 28 So, I'm wondering how accurate the diagram is to the project. Are there actually 42? Is it really an UNO? etc.

What happens if you use only the four-LED strip?

@timemage only 28 are currently wired and being used. The six interior pixels of each circle are not being used.

@timemage nothing changes.

buttons never stopped outputting, despite my instructions to only output when the buttons are low ... maybe the buttons are always low

@jsotola could you please clarify?

maybe the input pins on the arduino are pulled low when the buttons are not pressed ... did you disconnect the wires to the arduino pins to confirm that the program stops printing to serial?

Make sure your buttons are oriented correctly, not turned 90°.

An in focus well lit picture of your actual wiring may help.

i think the slider PISCA not need INPUT_PULLUP
pinMode(PISCA, INPUT_PULLUP);
just pinMode(PISCA, INPUT_PULLUP);

Here's your problem:
#define TRAVAO 8

As you can see from your wiring diagram, nothing is connected to pin 8.


text:
Transfer a single pulse from Tektronix function generator to Arduino UNO
I have set up a single pulse (width of ~400 ms) using the burst feature on the Tektronix AFG3102 function generator and I want to transfer this signal to the digital pin of Arduino UNO. Essentially I want to continuously (in a loop) perform reading on pin 7 using the built-in digitalread() function. So I'm expecting to see 0 when I did not trigger the signal and 1 when I trigger the signal for a duration of 400 ms and then back to 0. However, this is not the case here as I'm just reading 0s even though I trigger my signal. Interestingly when I change the width of the pulse to 1ms I can see the signal coming through, but It does seem to work with 400 ms.
I have placed my code here for your review. I would highly appreciate some help on this.
void setup() {
    Serial.begin(9600); // start serial for output
    pinMode(7,INPUT);
}
void loop() {
      Serial.println(digitalRead(7));
      Serial.print('\n');
}

Thank you,
Nikan

To what voltage did you set the function generator? Also currently you are very fast filling up the Serial buffer. Have you tried a delay at the end of loop(), like 50ms, and/or increasing the baudrate to something like 115200?

Does your AFG share its ground with the Arduino? What does the pulse look like on the scope? Side note: there is no point in Serial.print('\n');, as Serial.println() already adds "\r\n". @chrisl: Filling the serial buffer should be no issue: it justs adds a small latency (< 7 ms) to the transmitted data.

@chrisl: the voltage from the function generator is at 3 Vpp, Also What Im not understanding is that when I send continuous square waves, PIN 7 starts to pick up at the voltage above 2 Vpp. Of course I need to keep this below 5.

@chrisl: Also to answer your questions regarding the ground. In fact they are connected.


text:
Bootloader Burning Issue
I have a custom CCA that utilizes an ATMEGA328 but with an external clock of 1MHz that I originally burned the ADABOOT bootloader on using an Arduino Nano.  Everything worked as expected, only issue is I noticed the boot up time is a little long and after some research it seems that putting the Opti bootloader on may help with this.
Thus, I am trying to burn the opti bootloader onto my CCA, this time using an Elegoo Uno R3.  I successfully was able to upload the ArduinoISP sketch onto the Uno but when I go to burn the bootloader I get the following error:
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM7
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x03

avrdude done.  Thank you.

Error while burning bootloader.

I'm wondering if there is some sort of communication error since my custom CCA has the other bootloader on with different boards.txt settings than the default
f_cpu = 8000000L
upload speed = 7200
low fuse = 0XCB
high fuse = 0xDA
extended fuse = 0xFD
When I perform the loopback test I don't get an echo on the serial monitor.  I see both the "Rx" and "Tx" lights blink on the Uno, not sure if something is up there... Do you need to have a certain sketch uploaded for that to work?
Thanks,
Pete

did you select the programmer in Tools menu to "Arduino as ISP"?


text:
Speedometer for car
I want to build a speedometer for a car using Arduino UNO.
For the display, I'm using an LCD screen that will be located behind the steering wheel.
For context, I'm building the speedometer for a Tesla, which does not have a speedometer behind the steering wheel.
Because this speedometer is for a car, and for driving purposes, I need the speedometer to be very accurate.
I am planning to calculate the current speed of the car using a GPS module, but not sure which GPS module would have the best accuracy but is not too expensive?
I am also open to other methods that may be available to measure current speed.

An interesting project. I will not vote, but since there is no mention of an Arduino, likely people will vote to close this question as off topic. As for GPS, most inexpensive modules will only be accurate to about +/- 10 meters and only work (well) w/a clear view of the sky. Some will calculate bearing and speed for you (i.e. likely all you have to do is pluck this data out of the stream of data coming out of the GPS). Before investing time building this, consider using an old Android phone & an application which reports the data of interest to you.

For me, it would make more sense to read the speed from CAN

I built a GPS speedometer for an old Corvette using the TinyGPSPlus library with a GY-NEO6MV2 NEO-6M with an Arduino Uno.
http://www.carols62.com/speedo
Speed readings were very accurate.

hey thanks, this seems like exactly what I need!


text:
Arduino Uno R3 not recognized by Arduino IDE on Ubuntu 21.04
Now I've been pulling my hair for two days over this one. I've tried everything. I've turned every stone, looked at every search result, and every Arduino Forums thread.
The problem is that Arduino IDE does not recognize the Arduino when connected to the PC, thus I can't upload compiled sketches. As usual, the serial port dropdown menu is greyed-out.
Things I have tried so far:

Tried a different USB cable. Same results.
Tried it on a Mac. It works flawlessly with different sketches.
Looked at dmesg logs for Arduino when connecting. It connects to the PC successfully.
Created a custom udev rule for it to be symlinked from /dev/bus/usb/001/00X to /dev/ttyACMX.
Modified the custom udev rule for it to be symlinked from /dev/bus/usb/001/00X to /dev/ttyUSBX (since for some reason IDE was looking for ttyUSB0 first).
Tried Arduino IDE from snap, apt, and from arduino.cc. All of them work the same.
Tried different versions of AVR board packages from the Boards Manager, none of them work at all.
Tried a NodeMCU (ESP8266), it works flawlessly.
Tried Arduino Due, it works flawlessly.
Added myself to dialout, uucp, and tty groups. Nothing changed.
Changed permissions to a+rwx for all possible Arduino device file nodes.
Changed group ownership to dialout, uucp, and tty for all possible Arduino device file nodes.
Tried running Arduino IDEs as root. Nothing changed.
Installed different firmware and libraries for linux (ex. libserialport0)
Patched the apt version of Aruino IDE with patchelf.
Updated.
Rebooted.

"But hey man, why don't you just use the Mac to compile and upload the sketch, or any other MCU for that matter?" - Because I need to get output from my main PC and delegate it via serial to the Arduino. And Arduino Due is too clunky. And NodeMCU has disputable support for FastLED.
If any of you crazy mfs has an idea on how to solve this, I owe you a beer.

it may be a baud rate mismatch ... load a sketch that sends a known character at a known baud rate every 1/2 second, or so ... use a serial console, other than arduino IDE, to monitor the serial port

When the Arduino is connected, are there any ttyACMX or ttyUSBX device files in /dev? If yes, please connect to them with a serial program (like cu -l /dev/ttyUSB0 -s 115200 on the commandline) and try to sends something. Is the RX LED lighting up a bit (will only be very shortly, but visible)?

@jsotola The sketch can't send anything since I can't upload anything to the Arduino sadly :(

@chrisl There can be ttyACX/ttyUSBX since I created an udev rule to symlink the device once it connects. It is normally "mounted" at /dev/bus/usb/001/00X for some reason.
I'll try the cu trick. Thank you very much!

@Tozzart you said that it works on a Mac ... use the Mac to load a test sketch

Until you sort out your basic problem of getting connected to it, I would remove whatever udev rules you've added, because these are only going to complicate troubleshooting.

After upgrading to Ubuntu 22.04 from 20.10, I could no longer upload anything to Arduino UNO boards. Issue was, the correct port was not listed in the Arduino IDE. All I had available as a port was ttyS0. It won't work with USB boards. I am using Arduino IDE 1.8.19, but I believe this is irrelevant to the issue.
After checking the logs :
sudo dmesg

I got this output:
usb 4-2: Product: USB2.0-Serial
ch341 4-2:1.0: ch341-uart converter detected
usb 4-2: ch341-uart converter now attached to ttyUSB0
input: BRLTTY 6.4 Linux Screen Driver Keyboard as /devices/virtual/input/input27
usb 4-2: usbfs: interface 0 claimed by ch341 while 'brltty' sets config #1
ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
ch341 4-2:1.0: device disconnected

So, my Arduino UNO boards all seem to be recognized as some braille tty device (!). Then braille support tries to establish dialog with the UNO board. This of course fails, resulting in a disconnection of the UNO board, causing removal of device /dev/ttyUSB0. This is the reason why it does not show up in the IDE.
The quick fix is to simply remove braille tty display devices support if you don't need it.
sudo apt remove -y brltty

This worked for me. Hopefully it works for you too.
The issue might be related to some udev rule installed with the package brltty. If I am not mistaken, udev rules are processed in alphabetical order. So it could be that some braille udev rule matches in first, causing the above mentioned scenario.

Thanks for specific details of dmesg.  That helped out, because I had gone all through this and uninstalled brltty many months ago after upgrading to 22.04.  However, today I tried connecting a Arduino Nano and I couldn't get it to be recognized.  I discovered that brltty had been installed again. I ran the apt remove and arduino nano came up on ttyUSB0 just as it should.   Because you showed dmesg I was able to compare to mine and see that it was the problem.

I have experienced that with several new installs of the Linux OS.  Try this:
Linux does not see board Run:
Type 'groups', is 'dialout' there ?
sudo usermod -a -G tty yourUserName
sudo usermod -a -G dialout yourUserName
Log off and log on again for the changes to take effect.
https://playground.arduino.cc/Linux/All/#Permission
sudo ln -s /usr/bin/python3 /usr/bin/python


text:
Where am I going wrong in modifying Timer0 and the ISR interrupts in this example?
(Arduino) Hello I don't know where I am going wrong here, please advise.
In the end I want to step a bipolar motor, HIGH/LOW, using Timer0 with OCR0A and OCR0B interrupts to adjust the motors step interval and duty cycle. Eventually I would like to do the same thing with a second motor and Timer2.
The idea is that the interrupt at OCR0A triggers step LOW and the interrupt at OCR0B triggers step HIGH. This breaks down into the TCNT count from 0 to OCR0B is the LOW phase and TCNT count from OCR0B to OCR0A is the HIGH phase. Both phases together make up the motor step interval which would be between TCNT0=0 and OCR0A ISR Clear. The duty cycle is determined by value between OCR0B and OCR0A, the duration of the HIGH phase.
My first test was to use Serial.println() to return "LOW" or "HIGH" from the corresponding ISRs to the computer to see if the step sequence is in the correct AB-AB pattern. It is not. The step sequence starts out correctly but after 7(seven) OCR0B ISR interrupts in sequence the OCR0B ISR ceases to repeat while the ISR for OCR0A prints repeatedly. The following is the code:
 ISR(TIMER0_COMPA_vect) { Serial.println("HIGH");} //end ISR COMPA//

 ISR(TIMER0_COMPB_vect) { Serial.println("LOW"); } //end ISR COMPB//

 int long  SPEED_A  = 200; // OCR0B->OCR0A is HIGH PHASE // trigger LOW  // clear to 0 //

 int long  SPEED_B  = 150; // 0->OCR0B is LOW PHASE      // trigger HIGH

   void setup()
   {
      noInterrupts();             // disable interrupts

      OCR0A   = SPEED_A;          // interrupt A compare to TCNT0 value each tick // 0-255

      OCR0B   = SPEED_B;          // interrupt B compare to TCNT0 value each tick // 0-255

      TCCR0A  |= ( 1 << COM0A1);  // clear counter on match // OCR0A

      TIMSK0  |= ( 1 << OCIE0A);  // enable timer compare interrupt A

      TIMSK0  |= ( 1 << OCIE0B);  // enable timer compare interrupt B

      interrupts();               // enable interrupts

      Serial.begin(9600);         // serial

   }  //END setup///

 void loop() { } //END loop//

The Serial return is as follows:
LOW
HIGH
LOW
HIGH
LOW
HIGH
LOW
HIGH
LOW
HIGH
LOW
HIGH
LOW
HIGH
HIGH
HIGH
HIGH
...
Why does the ISR for OCR0B stop executing?

flash an LED instead of printing ... if you still want to print, do not do any printing inside an ISR function ... set a flag inside one ISR ... clear the flag inside the other ISR ... print the state of the flag inside the loop() function

Thank you for the comment, I noticed I was misunderstanding the math of what 1 period equated to microsecond wise and the LED 100% helped me see the issue. I need to include global variable to count the ticks or 'OCR0A revolutions' to time the intervals correctly.

Don't do serial prints inside an ISR. Ever. They require interrupts to work, and inside the ISR interrupts are off. For a while the attempts to print will fill up a buffer which is emptied by another ISR, however when that buffer fills the Serial.print will block. And if it blocks inside an ISR waiting for an interrupt it will block forever. Thus it stops printing.
As Jstola suggested in a comment under the question, turn an LED on and off, or something like that.
I can't explain your 7 prints perfectly, but printing HIGH and LOW repeatedly, with their corresponding carriage-return/linefeeds, would, after 7 turns (7 x 11 = 77), pretty-much fill up the serial buffer which is 64 bytes.
So, you are sending around 77 bytes, some would have "escaped" before the buffer filled up, and when you filled it with 64 bytes, it stops.
Your results would change slightly if you made the baud rate higher, say 115200 baud, which I always use, but still, you should not print inside an ISR.


text:
Using IN1/ IN2 pins for PWM instead of ENA in L298N
So basically i tried providing PWM directly to the IN1/IN2 Of L298n motor driver instead of using ENA pin i got more or less the same result
Im using ESP32 with 30000Hz freq for my PWM
My question is if both ways it can be used why aren't people using this method? Or am i missing something?
I would love to know the reason if someone has any idea about it.

"why aren't people using this method?" It's not true, it's a widley used method.

When using only IN1/2 to control speed and direction, you must apply PWM to IN1 for one direction and to IN2 for the other direction, while the other pin will be connected to ground. This method is easy to implement with a MCU but uses two PWM channels.I think the EN pin is used for applications without MCUs or where there is only one PWM channel. In these situations, pins IN1/2 are used for STOP/CW/CCW selection and EN for speed from a single PWM source.


text:
Serial read and send to UDP?
I was trying to send whatever is received from serial by udp, but it doesn't work properly.
the receiver side showing number 50 51 53 ..... the result like below screenshot:

can anyone help me please to fix ?
sender sketch:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "MikroTik";
const char* password = "12345678";
unsigned int localPort = 2390;

WiFiUDP Udp;
void setup() {
  delay(1000);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Udp.begin(localPort);
}

void loop() {
  Udp.beginPacket("10.5.50.23", localPort);
  int val = Serial.read();
  Udp.print(val);
  Udp.endPacket();
  delay(10);
}

receiver sketch:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "MikroTik";
const char* password = "12345678";
unsigned int localPort = 2390;
char packetBuffer[255];
WiFiUDP Udp;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(".");
  }
  Udp.begin(localPort);
}

void loop() {
  delay(10);
  if (Udp.parsePacket()) {
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) {
      packetBuffer[len] = 0;
      Serial.println(packetBuffer);
    }
  }
}

thanks for reply. sorry I'm new to coding arduino can you help me and edit my code to working properly ?

What help do you need exactly? I explained that you should replace Udp.print() by Udp.write(). Further edits depends on what you want the code to do. You did describe that.

ok I changed to Udp.write(val) but on the receiver side only show first number of serial read side.
for example Instead of showing the number 300, it displays the number 3

Thats the part about reading up to a delimiter character. For example you could use Serial.readStringUntil('\n') for this. It is a blocking function, but that should be ok for your case. Sorry, but I won't write the code for you. There are lots of example codes and tutorials on the web about that. You can also look at the SerialEvent example, that comes with the Arduino IDE

Besides the issues with the code, I hope you understand that UDP is not a "reliable" protocol. It doesn't guarantee that you'll receive everything that's sent, and it won't tell you if something gets dropped.

The problem is with the different interpretations of the binary data and lies in these two lines:
int val = Serial.read();
Udp.print(val);

What you write into the Serial Monitor is ASCII encoded text. Each byte of data corresponds to one character. If you write an a this is taken as the ASCII representation. In hexadecimal this character is 0x61 and in decimal 97. Thats the actual value that gets transmitted to the ESP over Serial. Then you read that into an integer. SO val would have the value 97. Then you use Udp.print(val). All print() functions are there for producing a human readable representation of the data, meaning ASCII encoded (Thats a standard Arduino convention). So basically you said here: "Here you have a number (integer). Print it into the UDP packet in human readable (ASCII) form." So the UDP packet now contains the ASCII string "97". You probably typed the digit 5 and then 4 a few times. Their decimal values are 53 and 52.
There probably also is a function called Udp.write(). The write() functions by convention don't change the data. They just write it without interpretation. So by using Udp.write() the actual binary value of the received data would be send and the letter a would appear as letter a in the Serial output of the receiver.
This works good as long as you only want to send single bytes in your packets. Also note, that Serial.read() will return -1 if there is no data to read in the buffer. So to handle that you need to step up the sender code:

Only read from Serial, if there is actually data in the buffer. You can use an if statement for this like:
  if(Serial.available()){ // read in this if statement

Read all data from Serial up to a specific delimiter character, which marks the end of a complete message. Typically the newline character \n is used for that. You can configure the Serial Monitor to use newline as line ending (it then gets appended to the typed text when you press Enter). There are a lot of example codes for this on the web.


text:
Flight controller board Reprogram
Recently in my scrap yard visits, more and more I find cheap quad-copters and remote controllers of all kind. I have built up quite a collection of boards and spare parts to create my own army of drones.
Now, my question is, how can I access the microprocessor on the board to upload code, say MultiWii, Ardupilot or similar.
I know every board is different, but very often I see STM32 processors on these boards, with I2c connections available.
Should there be also TX and Rx pins for USB communication in order to flash the controller? Or can it be done with I2c and an arduino as a master?

Have you googled on how to program a standalone STM32? Tx and Rx are commonly for UART interfaces and has nothing to do with USB. For programming over serial you need a bootloader on the chip

Well, of course one does his fair bit of research before asking a question...

Have you seen this guide. It explains how to flash an STM32 via the SWD/JTAG interface. You need an SWD/JTAG debugger to do this. Does that help?

No, that is one of the many things I have probably missed, it explains exactly what to do. Thank you.


text:
How to combine servo shield with peristaltic pump?
I am creating a project where I need 16+ (possibly up to 20) servos to open/close liquid flow through tubing, which in turn will be controlled by a peristaltic liquid pump (https://www.adafruit.com/product/1150). Since the adafruit servo shield (https://www.adafruit.com/product/1411) gives you access to 16 servos per shield, it seems like the obvious option. However, this shield wont be able to drive a peristaltic pump. I've been told I can put a adafruit servo shield on top of a adafruit motor shield (https://www.adafruit.com/product/1438), but is this really the most effective way to build this project? I want to have a system that is as compact and cheap as possible, using already-available electronics (although I suppose one option is to build a shield myself, but having not done that before it would take me a very long time).
I am quite new to arduino and its accessories, so I apologise if this is a very simple question.
Best,
N

You don't need a shield to run servos. Maybe you should be looking at a more powerful board that can directly connect to many servos without the need for any additional hardware. There's more than just Arduino boards in the whole ecosystem.

the pump is just a DC motor, as far as the microcontroller is concerned ... there are many tutorials on the web about controlling a motor with a microcontroller

Minimal components for driving a motor like a pump is: MOSFET used as switch (capable of handling the needed current and having a threshold voltage well beloe logic level of the Arduino), a diode used as flyback diode and a resistor to limit the gate current (just to be safe). That enables you to drive the motor in one direction, controlling its speed.

nn123,
Never apologize for asking the simple questions! The only reason I've learned in my life is for asking these kinds of questions. We all have to start somewhere, and should never be embarrassed for what we don't know. The key is being willing to learn and ask for help.
Here's a simple solution to your problem.
The shield is a great idea for you to use. It's very simple to wire (it plugs in :), you have power management system on the shield, and you can control the entire thing with I2C. So I'd definitely stick with that.
In order to drive a DC motor (pump), all you need is a sort of low power MOSFET to power this. You can look up thousands of tutorials on how to power a motor with an Arduino. Here is one for reference.
If you don't want to buy individual components and perfboard to construct your own circuit, you can buy a motor driver from Adafruit just like this one. Remember Adafruit always gives you incredibly good instructions for all their products if you're ever stuck.

This board is perfect for powering low-power motors. Your pump only pulls a maximum of 300mA at 12V, and that shield can do up to 3.6A peak (probably more like 2A continuous). The shield is also a H-bridge, which means you can power the motor forwards & backwards (not sure if this is useful to you).
To hook up the motor driver all you would need is 2 digital pin PWM pins (like 5&6) to control it forward/backwards.
Comment if you have any questions and good luck with the project!

Thank you so much, for your kind words and help! I will read up on what you suggested and I'll comment if I have further questions as I move forward with the project!


text:
Changing I2C Address on Garmin LidarLite, resets on reboot
I am trying to change the I2C address of multiple Garmin LidarLite-V3. I am able to change them one at a time using the LidarLite C++ library using the setI2Caddr function, and can see the updated I2C address using i2cdetect. The problem is that when the LidarLite loses power and turns back on, the address is reset to the default 0x62. This means when I have multiple LidarLite connected in parallel, they all default to the same I2C address and I am unable to individually change the addresses using the setI2Caddr function. How can I change the I2C address so that it persists through a power cycle, or alternatively change the addresses when multiple LidarLite are connected in parallel?

The manual of the Garmin Lidar Lite tells you about this. From page 5 under "Configurable I2C Address":

This can be used to run multiple devices on a single bus, by enabling one,
changing its address, then enabling the next device and repeating the
process.
The I2C address will be restored to default after a power cycle

So you cannot change the fact, that the I2C addresses will be reset to the default value on power cycle. But on startup you can give each sensor its own address. For that you need to wire the Power Enable pins to digital pins on the Arduino. When the digital pin is HIGH, the sensor is deactivated. So you start with all the Power Enable pins on HIGH. Then you set the first Power Enable pin to LOW, set the sensors I2C address via the corresponding I2C command and then proceed to the next sensor. When finished every sensor has its corresponding address and you don't get any collisions on the bus, since you always have only one sensor with the default address enabled at any time.


text:
ATmega 328 Bootloaded, but Cannot Upload
I have been working on a project that I program using the ATMEGA 328p inserted into an Arduino Uno, and then remove it to put it on my breadboard. I now have realized how inadvisable this is, since I had a pin breakoff. I have spare ATMEGA 328 chips and a borrowed functional Arduino Uno. Starting with the instructions here from the official Arduino site, and then progressing to the instruction set here for using the different device signiture, I eventually gave up on using the IDE and ran avrdude from the command line. Here is my command:
C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\bin>avrdude -v -v -c arduino -p m328p -P com9 -b19200 -F

And the following results:
avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch`

         System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"

         Using Port                    : com9
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9514
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as 7
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

From these results, I want to conclude that the bootloader is now installed onto my ATMEGA 328. However, when I try to upload to it using the Arduino Uno "shell" with its 328p removed,I get the following error:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x80

(and the next 10 tries)
Is there something I am missing? I am connecting the reset pin to pin 1 of my ATMEGA 328, and the RX/TX to pins 2 and 3, respectively.
Any help on this one would be greatly appreciated.

Why do you think that you have burned the bootloader? Neither the avrdude commandline, nor its output mention the bootloader hex file or writing to the Atmega. I'm not that firm with the avrdude options, but it seems, that you just read the fuses. You have written nothing (it would have told you if it had written something).

Most people will never have a legitimate reason to use avrdude's -F options. That message you get from avrdude about -F is a not a prescription. I see you mentioning 328P and 328, but it's not clear to me that you understand that these are different devices, which is why they have different signatures.  So what you actually have? Is there a P in your actual chip's part number or not?

chrisl is right, you are not uploading anything. The line to upload in one of my makefiles for an ATmega328 looks like this... avrdude -p m328 -c avrispv2 -P COM4 -U flash:w:hexfile.hex -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m -v -B 10 -i 10... if you want to upload, you need to specify both the write target and a hex file (-U flash:w:hexfile.hex)

...you probably have to change the command a little bit if you want to upload a bootloader, I don't quite remember atm... but you definitely need to use the -U option for upload


text:
Arduino Code is slow when running two task

I want pin 11 to give a square wave of once 3 sec

and want pin 12 to act as a switch to glow pin 13 Built in led..

connected pin 12 to GND with 10k resistor

If i fed the switch code alone it is fast(the led turn on instantly), but when i fed this code (the on in picture) it has a 1 sec lag to turn on the led. why?
And also if i connect pin 11 to 12 i assume the builtin led should turn on and off according to the wave form coming out of  but the led is always low.

use this library https://www.arduino.cc/reference/en/libraries/arduino-timer/

Or this https://playground.arduino.cc/Main/FlexiTimer2/  https://learn.adafruit.com/multi-tasking-the-arduino-part-2/timers

Just to try to confirm what exactly you're asking about: you've explicitly told it to do something, delay for 3 seconds, do something else, delay for another 3 seconds ... and now you're asking why there's a delay ... ?

No code as image please. Copy and paste the code as text into the question. Then you can format is as code so that it will be displayed correctly

Look at the BlinkWithoutDelay example that comes with the Arduino IDE, and at the millis() function. You can find many tutorials about that online. Basically you should not delay for long periods of time, since the arduino cannot do anything in that time. Use a non-blocking code style

@brhans bro i mean only the switch portion not the wave form..  if i turn on the switch there a 1 sec lag

@chrisl what language is ard ?? C or c++

Arduino code is C++

Your Arduino isn't going to even read the switch until the delay(s) are finished. So you're looking at a delay of up to 6 seconds in every loop where it's not reading the switch.

@brhans so first the blink code execute then only the switch code comes???

Please make sure that you understand the code you have written. From your comments it does not seem so. As chrisl says, look at the blink example without delay, and understand it. We can only give you hints, the learning is your task.

@yuvanm: Re “first the blink code execute then only the switch code comes?”: Indeed: the Arduino executes one statement at a time, in the order they are written. Whatever comes after delay(3000); is only executed once the Arduino is done with the delay.

@EdgarBonet thank you got it

OK everyone. You see the "answer" box below the question? That's where answers go. It is kind-of sad that this box is empty (at the time I write this) and a whole lot of useful answers are given as comments on the question. This is not a forum. Please do not answer in comments.

@yuvanm If you think you understand what the issue is, you can even answer your own question, thus helping future people who are wondering the same thing. Then people can vote on your answer, showing how good it is.

Basically, the code comprises Two Parts

Square Wave with 3-sec delay on and 3-sec delay off
if the pin 12, is high pin 13 will be high and if 12 is low 13 is also low(a simple on/off switch)

The second block of code executes only after the first Block of code is done executing.
That's why when I connected the pin 11 to 12 the led wasn't shining because when the WAVE code(that first block of code which gives a square wave) was running, the second block of code was quiet hence the 12th pin was still not become a switch yet.
And the delay I told was due to this, actually, the delay is 6 sec.
Because after the switch code completes its run, it will take a whole six seconds for the Arduino to come back to switch code in the loop because the wave signal of 3 sec on and 3 sec off should run.
if you want to run two tasks at the same time you need to learn the topics of millis() and protothreading.

You can ask me why I was this dumb to ask a question like this, because the only programming language I have ever snorted is python and in there I learned python is an interpreter and it executes line by line, Since Arduino ide code is built around c++ which is the compiler.
I thought the code won't run line by line instead the code will be compiled but now only I understood that even though the file is compiled there is no chance every code can be run at the same time as the actual meaning of the compiler.

I would suggest you do some research on the delay function so you understand why it is called a blocking function. The compiled code goes line by line as well. If you want to do two things at once you need two threads.  You can get the appearance of doing two things at once with multitasking. I have a feeling your code works as written, it only checks the switch every 6 seconds.

Yeah brother, i got it


text:
Problem on Sending float number and multiple float numbers
Im having trouble in sending float number and multiple float numbers.
Im currently working on project matlab and arduino mkr1000. The situation is that i want to send float number and multiple float numbers through communication(which in client.available() code) and view it in Serial Monitor. I have been searching throughout the internet but unfortunately could not receive it. The more i read the more confused i became. Im new to this environment. I do need consider bitshifting right?. Is there any similar examples and guidances from others would be really highly appreciated. Thank you.
Arduino Ide
    /* Latest Progress of the Project*/
#include <SPI.h>
#include <WiFi101.h>

// sensitive data placed in arduino_secrets.h
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID; // name wifi
char pass[] = SECRET_PASS; // password
int status = WL_IDLE_STATUS; // status of wifi

// variables used
float value;

IPAddress ipserver(192, 168, 1, 109); // home wifi ip address

// initialize the client library
WiFiClient client;

void setup()
{
  // initialize serial and wait for port to open:
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID:");
  Serial.println(ssid);

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED)
  {
    // will keep trying until connected
    Serial.print("Attempting to connect to network: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds(enough time) for connection:
    delay(10000);
  }

  // if you're connected now, so print the data status:
  Serial.println("You're connected to the network");
  Serial.println("------------------------------------");
  Serial.println("Hi FYP63333 Group");
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  Serial.println("------------------------------------");
  Serial.println("\nStarting connection to server...");
}

void loop()
{
  // Client connect or not connect in serial monitor:
  if (!client.connect(ipserver, 1234))
  {
    // if you didnt't get a connection to the server:
    Serial.println("Can't connect to server, try again.");
    delay(5000);
    return;
  }
  else
  {
    // if you get connection to the server:
    Serial.println("Connected to server!!!");
    Serial.println("MATLAB READY");
    //client.println("Hello from MKR1000");
  }

  // If there are incoming bytes available from the server, read and print them
  // Read all the lines of the reply from server and print them inside Serial Monitor:
  Serial.println();
  Serial.println("Incoming and receiving data from remote server:");
  while (client.connected() || client.available() || Serial.available())
  {
    while (Serial.available())
    {
      char data;
      data = Serial.read();
      if (client.connected())
      {
        client.print(data);
      }
    }
    while (client.available())
    {

      //------------------main-code(works)--------------for string//
      char ch = static_cast<char>(client.read());
      Serial.println(ch);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected())
  {
    Serial.println();
    Serial.println("Disconnecting from the server.");
    client.stop();
  }
}

Matlab code
clear;
clc;
%% Connecting matlab and Arduino IDE(TCP/IP Server)
t = tcpserver("192.168.1.109",1234);
t.ByteOrder = "big-endian";

I would highly recommend sending all data as text. Then you don't have to worry about bit-shifting, byte order and such. See String::toFloat().

trouble in sending float number and multiple float numbers ... it appears that you may not be thinking clearly about the problem you are facing ... the success in sending multiple numbers is dependent on the success in sending a single number ... it may be time to go for a break and clear your head

i can read the single number send from MATLAB to Arduino IDE by just using serial.println(ch,DEC) but when it comes to float numbers im having trouble about it.

Sending numerical values between systems is fraught with difficulty. Not only do you have to ensure that both ends agree on the size of the data (16 bit vs 32 bit ints, float vs double, etc) but that the byte ordering is handled correctly. On top of that is knowing where a number is in the stream of data. With nothing to delimit each value (and when you have 8 bits of communication width and 8 bits of data there's no room for "out of band" control signals) yo have no way of knowing which byte in the data stream corresponds to which byte in a value's raw data.
It's far better to encode the data into some other format that leaves you room to add delimiting control signals and has a predefined machine-agnostic data format.
The simplest encoding: ASCII. Simply "print" the numbers as text with the precision you desire (number of decimal places) as one number per line. Then on the Arduino you can read text data a line at a time then use the internal float conversion routines to turn that data into an actual floating point value again.
Some references:

Reading Serial on the Arduino - a blog post by me, also applicable to TCP/IP communication
String::toFloat() - Converting a String object to a floating point value
strtof() - Convert a C string to a floating point value

thank you and i will try

Check out the I2C_Anything library.  It is used to transfer any data type bit-by-bit using the I2C serial protocol, but the algorithms could be just as easily used over ANY serial connection.  You do have to make sure that the size of a particular datatype is the same on both ends, but that's about it.
Here's my subroutine running on a Teensy 3.5 that acquires VL53L0X LIDAR data from another Arduino processor (actually a Teensy 3.2).

    bool GetRequestedVL53l0xValues(VL53L0X_REQUEST which)
{
  //Purpose: Obtain VL53L0X ToF sensor data from Teensy sensor handler
  //Inputs:
  //    which = VL53L0X_REQUEST value denoting which combination of value to retrieve
  //        VL53L0X_CENTERS_ONLY -> Just the left/right center sensor values
  //        VL53L0X_RIGHT -> All three right sensor values, in front/center/rear order
  //        VL53L0X_LEFT -> All three left sensor values, in front/center/rear order
  //        VL53L0X_ALL -> All seven sensor values, in left/right front/center/rear/rear order
  //        VL53L0X_REAR_ONLY -> added 10/24/20 Just the rear sensor reading

  //Outputs:
  //    Requested sensor values, obtained via I2C from the VL53L0X sensor handler
  //    Returns TRUE if data retrieval successful, otherwise FALSE
  //Plan:
  //    Step1: Send request to VL53L0X handler
  //    Step2: get the requested data
  //Notes:
  // Copied from FourWD_WallE2_V4.ino's IsIRBeamAvail() and adapted
    // 08/05/20 added a VL53L0X_ALL request type
    // 01/24/21 added error detection/reporting
    // 01/16/22 rev to use I2C_Anything1 functions for Wire1

  //Step1: Send request to VL53L0X handler
  //DEBUG!!
    //myTeePrint.printf("Sending %d to slave\n", which);
  //DEBUG!!

  //myTeePrint.printf("In GetRequestedVL53l0xValues(%d)\n", (int)which);

  //03/01/22 rev to cvt all readings to cm
  uint16_t Lidar_RightFrontMM = 0;
  uint16_t Lidar_RightCenterMM = 0;
  uint16_t Lidar_RightRearMM = 0;
  uint16_t Lidar_RearMM = 0;

  uint16_t Lidar_LeftFrontMM = 0;
  uint16_t Lidar_LeftCenterMM = 0;
  uint16_t Lidar_LeftRearMM = 0;

  Wire1.beginTransmission(VL53L0X_I2C_SLAVE_ADDRESS);
  I2C_writeAnything((uint8_t)which, &Wire1);
  Wire1.endTransmission();

  //Step2: get the requested data
  int readResult = 0;
  int data_size = 0;
  switch (which)
  {
  case VL53L0X_READYCHECK: //11/10/20 added to prevent bad reads during Teensy setup()
    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, (uint16_t)(sizeof(bVL53L0X_TeensyReady)));
    readResult = I2C_readAnything(bVL53L0X_TeensyReady, &Wire1);
    break;

  case VL53L0X_CENTERS_ONLY:
    //just two data values needed here
    data_size = 2 * sizeof(uint16_t);
    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, (uint16_t)(2 * sizeof(Lidar_RightCenterMM)));
    readResult = I2C_readAnything(Lidar_RightCenterMM, &Wire1);
    glRightCenterCm = Lidar_RightCenterMM / 10; //integer truncation OK

    if (readResult > 0)
    {
      I2C_readAnything(Lidar_LeftCenterMM, &Wire1);
      glLeftCenterCm = Lidar_LeftCenterMM / 10; //integer truncation OK
    }

    //DEBUG!!
        //myTeePrint.printf("VL53L0X_CENTERS_ONLY case: Got LC/RC = %d, %d\n", Lidar_LeftCenterMM, Lidar_RightCenterMM);
    //DEBUG!!

    break;
  case VL53L0X_RIGHT:
    //four data values needed here
    data_size = 3 * sizeof(uint16_t) + sizeof(float);

    //DEBUG!!
        //myTeePrint.printf("data_size = %d\n", data_size);
    //DEBUG!!

    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, data_size);
    readResult = I2C_readAnything(Lidar_RightFrontMM, &Wire1);
    glRightFrontCm = Lidar_RightFrontMM / 10; //integer truncation OK

    if (readResult > 0)
    {
      readResult = I2C_readAnything(Lidar_RightCenterMM, &Wire1);
      glRightCenterCm = Lidar_RightCenterMM / 10; //integer truncation OK
    }
    if (readResult > 0)
    {
      readResult = I2C_readAnything(Lidar_RightRearMM, &Wire1);
      glRightRearCm = Lidar_RightRearMM / 10; //integer truncation OK
    }
    if (readResult > 0)
    {
      readResult = I2C_readAnything(glRightSteeringVal, &Wire1);
    }

    //DEBUG!!
        //myTeePrint.printf("VL53L0X_RIGHT case: Got L/C/R/S = %d, %d, %d, %3.2f\n",
        //  glRightFrontCm, Lidar_RightCenterMM, Lidar_RightRearMM, ToFSteeringVal);
    //DEBUG!!

    break;
  case VL53L0X_LEFT:
    //four data values needed here
    //data_size = 3 * sizeof(int) + sizeof(float);
    data_size = 3 * sizeof(uint16_t) + sizeof(float);

    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, data_size);
    readResult = I2C_readAnything(Lidar_LeftFrontMM, &Wire1);
    glLeftFrontCm = Lidar_LeftFrontMM / 10; //integer truncation OK

    if (readResult > 0)
    {
      readResult = I2C_readAnything(Lidar_LeftCenterMM, &Wire1);
      glLeftCenterCm = Lidar_LeftCenterMM / 10; //integer truncation OK
    }
    if (readResult > 0)
    {
      readResult = I2C_readAnything(Lidar_LeftRearMM, &Wire1);
      glLeftRearCm = Lidar_LeftRearMM / 10; //integer truncation OK
    }
    if (readResult > 0)
    {
      readResult = I2C_readAnything(glLeftSteeringVal, &Wire1);
    }

    //DEBUG!!
        //myTeePrint.printf("VL53L0X_RIGHT case: Got L/C/R/S = %d, %d, %d, %3.2f\n",
        //  Lidar_LeftFrontMM, Lidar_LeftCenterMM, Lidar_LeftRearMM, ToFSteeringVal);
    //DEBUG!!

    break;
  case VL53L0X_ALL: //added 08/05/20, chg to VL53L0X_ALL 10/31/20
    //nine data values needed here - 7 ints and 2 floats
    data_size = 7 * sizeof(uint16_t) + 2 * sizeof(float); //10/31/20 added rear distance

    //myTeePrint.printf("In VL53L0X_ALL case with data_size = %d\n", data_size);

    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, data_size);

    //Lidar_LeftFrontMM
    readResult = I2C_readAnything(Lidar_LeftFrontMM, &Wire1);
    glLeftFrontCm = Lidar_LeftFrontMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_LeftFrontMM))
    {
      myTeePrint.printf("Error reading Lidar_LeftFrontMM\n");
    }

    //Lidar_LeftCenterMM
    readResult = I2C_readAnything(Lidar_LeftCenterMM, &Wire1);
    glLeftCenterCm = Lidar_LeftCenterMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_LeftCenterMM))
    {
      myTeePrint.printf("Error reading Lidar_LeftCenterMM\n");
    }

    //Lidar_LeftRearMM
    readResult = I2C_readAnything(Lidar_LeftRearMM, &Wire1);
    glLeftRearCm = Lidar_LeftRearMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_LeftRearMM))
    {
      myTeePrint.printf("Error reading Lidar_LeftRearMM\n");
    }

    //glLeftSteeringVal
    readResult = I2C_readAnything(glLeftSteeringVal, &Wire1);
    if (readResult != sizeof(glLeftSteeringVal))
    {
      myTeePrint.printf("Error reading glLeftSteeringVal\n");
    }

    //Lidar_RightFrontMM
    readResult = I2C_readAnything(Lidar_RightFrontMM, &Wire1);
    glRightFrontCm = Lidar_RightFrontMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_RightFrontMM))
    {
      myTeePrint.printf("Error reading Lidar_RightFrontMM\n");
    }

    //Lidar_RightCenterMM
    readResult = I2C_readAnything(Lidar_RightCenterMM, &Wire1);
    glRightCenterCm = Lidar_RightCenterMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_RightCenterMM))
    {
      myTeePrint.printf("Error reading Lidar_RightCenterMM\n");
    }

    //Lidar_RightRearMM
    readResult = I2C_readAnything(Lidar_RightRearMM, &Wire1);
    glRightRearCm = Lidar_RightRearMM / 10; //integer truncation OK

    if (readResult != sizeof(Lidar_RightRearMM))
    {
      myTeePrint.printf("Error reading Lidar_RightRearMM\n");
    }

    //Lidar_RearMM
    readResult = I2C_readAnything(Lidar_RearMM, &Wire1);
    glRearCm = Lidar_RearMM / 10; //integer truncation OK
    if (readResult != sizeof(Lidar_RearMM))
    {
      myTeePrint.printf("Error reading Lidar_RearMM\n");
    }

    //glRightSteeringVal
    readResult = I2C_readAnything(glRightSteeringVal, &Wire1);
    if (readResult != sizeof(glRightSteeringVal))
    {
      myTeePrint.printf("Error reading glLeftSteeringVal\n");
    }

    //myTeePrint.printf("%lu: VL53l0x - %d, %d, %d, %d, %d, %d, %d\n",
    //  millis(),
    //  Lidar_LeftFrontMM, Lidar_LeftCenterMM, Lidar_LeftRearMM,
    //  glRightFrontCm, Lidar_RightCenterMM, Lidar_RightRearMM,
    //  Lidar_RearMM);
    break; //10/31/20 bugfix

  case VL53L0X_REAR_ONLY:
    //just ONE data value needed here
    data_size = sizeof(uint16_t);
    Wire1.requestFrom(VL53L0X_I2C_SLAVE_ADDRESS, (uint16_t)(sizeof(Lidar_RearMM)));
    readResult = I2C_readAnything(Lidar_RearMM, &Wire1);
    glRearCm = Lidar_RearMM / 10; //integer truncation OK

    //DEBUG!!
        //myTeePrint.printf("VL53L0X_REAR_ONLY case: Got Rear = %d\n", Lidar_RearMM);
    //DEBUG!!

    break;

  default:
    break;
  }
  //myTeePrint.printf("GetRequestedVL53l0xValues(): LR/LC/LF/RR/RC/RF/R = %d\t%d\t%d\t%d\t%d\t%d\t%d\n",
  //  Lidar_LeftRearMM, Lidar_LeftCenterMM, Lidar_LeftFrontMM,
  //  Lidar_RightRearMM, Lidar_RightCenterMM, glRightFrontCm, Lidar_RearMM);

  return readResult > 0; //this is true only if all reads succeed
}

and here's the corresponding code on the other end of the I2C link:
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  //Purpose: Send requested sensor data to the Mega controller via main I2C bus
  //Inputs:
  //  request_type = uint8_t value denoting type of data requested (from receiveEvent())
  //      0 = left & right center distances only
  //      1 = right side front, center and rear distances, plus steering value
  //      2 = left side front, center and rear distances, plus steering value
  //      3 = both side front, center and rear distances, plus both steering values
//Outputs:
  //  Requested data sent to master
  //Notes:
  //  08/05/20 added VL53L0X_ALL request type to get both sides at once
  //  10/24/20 added VL53L0X_REAR_ONLY request type
  //  11/09/20 added write to pin for O'scope monitoring

  int data_size = 0;

//DEBUG!!
    //Serial.printf("RequestEvent() with request_type = %d: VL53L0X Front/Center/Rear distances = %d, %d, %d\n",
    //    request_type, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm);
//DEBUG!!

  //digitalWrite(LED_BUILTIN, HIGH);//added 01/22/22
  digitalWrite(REQUEST_EVENT_DURATION_OUTPUT_PIN, HIGH);

  digitalToggle(LED_BUILTIN);//2/21/22 added for visual indication of I2C activity
  switch (request_type)
  {
  case  VL53L0X_READYCHECK: //added 11/10/20 to prevent bad reads during Teensy setup()
    //Serial.printf("in VL53L0X_READYCHECK case at %lu with bTeensyReady = %d\n", millis(), bTeensyReady);
    I2C_writeAnything(bTeensyReady);
    break;

  case VL53L0X_CENTERS_ONLY:

    //DEBUG!!
      //data_size = 2*sizeof(uint16_t);
      //Serial.printf("Sending %d bytes LC_Dist_mm = %d, RC_Dist_mm = %d to master\n", data_size, LC_Dist_mm, RC_Dist_mm);
    //DEBUG!!

    I2C_writeAnything(RC_Dist_mm);
    I2C_writeAnything(LC_Dist_mm);
    break;

  case VL53L0X_RIGHT:

    //DEBUG!!
            //data_size = 3 * sizeof(uint16_t) + sizeof(float);
            //Serial.printf("Sending %d bytes RF/RC/RR/RS vals = %d, %d, %d, %3.2f to master\n",
            //    data_size, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, RightSteeringVal);
    //DEBUG!!

    I2C_writeAnything(RF_Dist_mm);
    I2C_writeAnything(RC_Dist_mm);
    I2C_writeAnything(RR_Dist_mm);
    I2C_writeAnything(RightSteeringVal);
    break;

  case VL53L0X_LEFT:

    //DEBUG!!
            //data_size = 3 * sizeof(uint16_t) + sizeof(float);
            //Serial.printf("Sending %d bytes LF/LC/LR/LS vals = %d, %d, %d, %3.2f to master\n",
            //    data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal);
    //DEBUG!!

    I2C_writeAnything(LF_Dist_mm);
    I2C_writeAnything(LC_Dist_mm);
    I2C_writeAnything(LR_Dist_mm);
    I2C_writeAnything(LeftSteeringVal);
    break;

  case VL53L0X_ALL:
    //Serial.printf("In VL53L0X_ALL case\n");
    //added 08/05/20 to get data from both sides at once
    //10/31/20 chg to VL53L0X_ALL & report all 7 sensor values

//DEBUG!!
    //data_size = 3 * sizeof(uint16_t) + sizeof(float);
    //data_size = 7 * sizeof(uint16_t) + 2 * sizeof(float);
    //Serial.printf("Sending %d bytes to master\n", data_size);
    //Serial.printf("%d bytes: %d\t%d\t%d\t%3.2f\t%d\t%d\t%d\t%d\t%3.2f\n",
    //    data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal,
    //  RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, Rear_Dist_mm, RightSteeringVal);
//DEBUG!!

    //DEBUG!!
      //data_size = 3 * sizeof(uint16_t) + sizeof(float);
      //Serial.printf("Sending %d bytes LF/LC/LR/LS vals = %d, %d, %d, %3.2f to master\n",
      //    data_size, LF_Dist_mm, LC_Dist_mm, LR_Dist_mm, LeftSteeringVal);
    //DEBUG!!

    //left side
    I2C_writeAnything(LF_Dist_mm);
    I2C_writeAnything(LC_Dist_mm);
    I2C_writeAnything(LR_Dist_mm);
    I2C_writeAnything(LeftSteeringVal);

    //DEBUG!!
      //data_size = 3 * sizeof(uint16_t) + sizeof(float);
      //data_size = 4 * sizeof(uint16_t) + sizeof(float);
      //Serial.printf("Sending %d bytes RF/RC/RR/R/RS vals = %d, %d, %d, %d, %3.2f to master\n",
      //    data_size, RF_Dist_mm, RC_Dist_mm, RR_Dist_mm, Rear_Dist_mm, RightSteeringVal);
    //DEBUG!!

       //right side
    I2C_writeAnything(RF_Dist_mm);
    I2C_writeAnything(RC_Dist_mm);
    I2C_writeAnything(RR_Dist_mm);
    I2C_writeAnything(Rear_Dist_mm);
    I2C_writeAnything(RightSteeringVal);

    break;

  case VL53L0X_REAR_ONLY:

    //DEBUG!!
      //data_size = sizeof(uint16_t);
      //Serial.printf("Sending %d bytes Rear_Dist_mm = %d to master\n", data_size, Rear_Dist_mm);
    //DEBUG!!

    I2C_writeAnything(Rear_Dist_mm);
    break;

  default:
    break;
  }
  digitalToggle(LED_BUILTIN);//2/21/22 added for visual indication of I2C activity

  digitalWrite(REQUEST_EVENT_DURATION_OUTPUT_PIN, LOW);
  //digitalWrite(LED_BUILTIN, LOW);//added 01/22/22
}

As an alternative, you can send the numbers as text, as suggested by Edgar Bonet above.  Here's a short program I just whipped up that demos this capability, using two Teensy 3.x processors.  The program waits for a character on its serial port, and if any are found, they are transmitted to the other processor via a serial connection between the two, and also echoed back to the sending serial port.  This should work with any Arduino processor that has two serial ports (Serial for talking to the PC, Serial1 for talking to the other processor).  I used the built-in LED as an activity monitor.
/*
    Name:       Serial_Anything.ino
    Created:    4/26/2022 6:23:01 PM
    Author:     FRANKNEWXPS15\Frank

    Project to demonstrate passing arbitrary data types over a serial connection
    The idea is to port I2C_Anything to use over a common serial port connection
*/

#include "Serial_Anything.h"

//char buff[30];

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

  Serial.printf("Serial_Anything Demo\n");

  pinMode(LED_BUILTIN, OUTPUT);

  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);

}

void loop()
{
  if (Serial.available())
  {
    //buff[buffidx] = Serial.read();
    //buffidx++;
    char c = Serial.read();
    Serial1.write(c);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(50);
    digitalWrite(LED_BUILTIN, LOW);
    Serial.write(c);
  }

  if (Serial1.available())
  {
    //buff[buffidx] = Serial.read();
    //buffidx++;
    char c = Serial1.read();
    Serial.write(c);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(50);
    digitalWrite(LED_BUILTIN, LOW);
  }
}

Here's a short section of output from a typical run:
Teensy1:
Port closed
Opening port
Port open
Serial_Anything Demo
y
y
y
y
X
X
X
X
the quick
314159
3.14159

Teensy2:
Opening port
Port open
y
y
y
y
y
y
y
y
y
y
y
y
y
X
X
X
X
the quick
314159
3.14159

Thank you for your time with the example and sample code. i will try with client.read() based on your explanation above. Im highly appreciate the helps and suggestions.