text:
Whatever components we connect to the Arduino, their grounds and 5v pin connection must be the same?
I am trying to connect different types of sensors & motors to the Arduino should I make their grounds and 5v pins on the same connection.

If u didn't understand I can explain you

I understood it now, by the way thanks for asking

All the grounds must be connected. They don't have to be the same physical pin - the Arduino has multiple GND pins, but they are all connected internally.
The 5V doesn't matter where you get that from, as long as it's regulated and the associated ground is connected to all the others.


text:
How can we know the status of the DC Motor whether it is ON or OFF
A DC motor is operated using an L298n driver and Arduino UNO. How can I get to know whether the Motor is ON or OFF? Using a code in Arduino.

You control the motor via the Arduino. Thus you already know if it is on or not. Or do you want to find out, whether it actually turns?

There's nothing on the L298N that returns that status there's nothing you can read. So you have to assume if your code correctly sets the enable pin that the motor is running.

Like @chrisl said. If you're trying to detect a stall condition, you can put that into the question.

use a sensor to detect the motor shaft rotation

Unfortunately, the L298N does not return a status, so you are going to have to add sensors to detect motor movement.
Here are a few options you can try:

Current sense. Add a small resistor to the output of the L298N and measure the voltage differential across that resistor. If there is current being supplied to the motor then you will have a voltage differential.
Rotation sensor. This can be in the form of a quadrature encoder wheel, tooth sensor or Hall effect sensor detecting a magnet on the shaft. If you see pulses from the sensor then you know the motor is spinning.
Optical sensor. A camera system or other optical sensor to detect motor movement. Probably too complex for a simple application. There are however off the shelf sensors that will turn on an output if they see movement in their field of view. Alternatively you could use a PIR sensor from a home alarm system if the movement is course enough.

This may be too simple, but for completeness: You can read back the state of the output bit, in case your code doesn't save its current state. That will tell you if the motor is literally "on" or "off". Not rotating despite being "on" is another matter; an error.
If you need error detection then you need additional hardware support.
Some possibilities:

Sense rotation with a cam and a micro-switch or an optical sensor and a slotted disk;
Sense the motor current - a stalled motor will draw a high current;
Sense vibration in the motor platform;
(apply imagination here...  ;-)

source: Stack Exchange

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

sort: votes


text:
How do I add or subtract to a pre-determined value without having it default back to the original value?
Typical apologies in advance, it's been quite some time since I've tinkered with Arduinos. Using an Arduino Micro Clone (Pro Micro), TF02 LiDAR, and a Adafruit 1.2" 7-segment display, I've been working on a rangefinder that is able to be adjusted up/down by increments of 1. I've hit a wall though. I am unable to adjust the distance value without it returning to the original value. Say the distance is at 6'2". When I push the "up" button, the value is 6'3" but then returns to 6'2". Same applies for the "down" button. Also, when the distance is at, for example, 1'0", and I press the down button, instead of going to 0'11", it displays 0'99". I'm at a wall in terms of what I can do to resolve this.  Any help is appreciated!
*
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment(); //d pin 2, c pin 3
#include <SoftwareSerial.h>// soft serial port
#include <Wire.h>

//button stuff
int Up_buttonState = 0;
int Dn_buttonState = 0;
int Up_lastButtonState = 0;
int Dn_lastButtonState = 0;
const int  UpPin = 7;
const int  DnPin = 8;

//LiDAR stuff
int dist;// LiDAR actually measured distance value
int strength;// LiDAR signal strength
int check;// check numerical value storage
int i;
int uart[9];// store data measured by LiDAR
const int HEADER=0x59;// data package frame header
long inches, INCH, feet, ftin;

SoftwareSerial mySerial(9,10); //rx tx,

void setup()
{
pinMode(UpPin, INPUT);
pinMode(DnPin, INPUT);
 Serial.begin(9600);

 mySerial.begin(115200);//set the Baud rate of LiDAR and Arduino serial port
  #ifndef __AVR_ATtiny85__

  #endif
  matrix.begin(0x70);
}
void loop()
{

 if (mySerial.available())//check whether the serial port has data input
 {
    if(mySerial.read()==HEADER)// determine data package frame header 0x59
    {

      uart[0]=HEADER;

      if(mySerial.read()==HEADER)//determine data package frame header 0x59
      {
       uart[1]=HEADER;

      for(i=2;i<9;i++)// store data to array
         {
          uart[i]=mySerial.read();
         }
           check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
           if(uart[8]==(check&0xff))// check the received data as per protocols //if data received

             { //start equations
               dist=uart[2]+uart[3]*256;// calculate distance value

               //equations for converting mm to ft,in
               inches = (dist * .3937);
               INCH = inches% 12;
               feet = (dist / 2.54) / 12;
               ftin = feet*100 + INCH;

               Up_buttonState = digitalRead(UpPin); // add 1 to ftin
                if (Up_buttonState != Up_lastButtonState)
                {
                  if (Up_buttonState == HIGH)
                  {
                    ftin++;
                  }
                  delay(500);
                }
                Up_lastButtonState = Up_buttonState;

               Dn_buttonState = digitalRead(DnPin); // subtract 1 from ftin
                if (Dn_buttonState != Dn_lastButtonState)
                {
                  if (Dn_buttonState == HIGH)
                  {
                    ftin--;
                  }
                  delay(500);
                }
                Dn_lastButtonState = Dn_buttonState;

               Serial.print(ftin);
               matrix.print( ftin , DEC );
               matrix.writeDisplay();

             }
      }
    }
 }

}

Using a 'long' and dividing by 2.54 might not get the result you want, use a float.

You wrote:

ftin = feet*100 + INCH;

What is this monster? I am not very familiar with imperial units (and I
wonder why anyone would still want to use them), but I believe a foot is
not 100 inches.
Oh, I see. The monster is a kludge to manage the display in feet &
inches. But note that it is computed at every loop iteration as a
function of the measured distance. I doesn't make sense to apply a
correction to the monster as it is going to be recomputed on the next
iteration. That's why the value “returns” to what it is supposed to be.
As to why the down button changes “100” to “99”, I think it is quite
obvious: 100 minus one is 99. It is not a good idea to do arithmetics
with the monster.
If you want the correction to persist, you have to store it in a global
variable (or static local), and add that variable to the measured
distance at every loop iteration. For example:
// In global scope:
int correction = 0;

// In loop():
dist = ...;
inches = dist * 0.3937008 + correction;  // correction added here
ftin = (inches/12) * 100 + (inches%12);  // only used for display

if (Up_lastButtonState == LOW && Up_buttonState == HIGH) {
    correction++;
    delay(500);
}
if (Dn_lastButtonState == LOW && Dn_buttonState == HIGH) {
    correction--;
    delay(500);
}

Note that the monster is used for display only. No arithmetics are
performed on it, as that would not make any sense.

Monster it sure is haha. I'm making a rangefinder for focus pulling on Cinema Lenses. Our lenses are imperial so rather fork out money for metric lenses, in comes the monster. Can't thank you enough for the clear explanation, it worked!

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


text:
How to get timestamp of when the data was collected
Basically I want to be able to display the time the arduino collected the data with the data value, not the time the arduino printed off the data. Theres a timestamp feature on the console, however I want to find the time the data was collected.
I'm a bit new to this so any help is greatly appreciated!

did you record the time when the data was collected?

Which Arduino are you using (just in case you mis-tagged the question)?

By itself, an arduino-uno's only timestamp is the number of milliseconds since reset.
Serial.println(millis());

Getting a "timestamp" of when data is collected is entirely down to you.
Most Arduinos don't have any concept of the current time, only the time since the program started running. To know what the time "now" is you have to have some mechanism to tell the Arduino what the time is, along with a method of keeping track of that time.
There are devices called Real-Time Clock (RTC) modules which keep track of the time for you. They don't magically know the time - you still have to tell them at least once.
You could tell it the time through the serial port to set the clock - from then on (assuming the RTC has power) the RTC will know what the time is.
Another option to get the time into the RTC is to use an internet connection (ESP8266, WiFi shield, Ethernet shield, etc) to perform a Network Time Protocol (NTP) query to a time server on the internet (such as pool.ntp.org) to get the current time and update the RTC.  This should be done regularly to correct any drift in the RTC.
Once you have an RTC and a method of setting the time you can query the time whenever you sample some data and store that time along with the data in whatever way is most suitable for your situation.

It depends on how you define the time stamp. A Unix timestamp is the number of seconds elapsed since Unix epoch time, i.e. January 1 1970 00:00 UTC, this is a very common time stamp. You can setup with NTP via the internet, or you can use a RTC on your board. How you do it depends on how accurate you want it and what you have available. Try this link it may help: https://currentmillis.com/


text:
IMU (MPU9250) and Ticker on ESP32
I want to read the data from an IMU (MPU9250) periodically. To do that I use a ticker as shown in the following code:
#include <Ticker.h>
#include "MPU9250.h"

constexpr int SERIAL_BAUDRATE = 115200;
constexpr float SAMPLING_FREQUENCY = 1.0;

Ticker TimerIMU;
MPU9250 IMU(Wire, 0x68);

void readIMU()
{
    // read the sensor
  IMU.readSensor();
  // display the data
  Serial.print(IMU.getAccelX_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelY_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelZ_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroX_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroY_rads(),6);
  Serial.print("\t");
  Serial.println(IMU.getGyroZ_rads(),6);
}

void setup()
{
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}
  // start communication with IMU
  int retVal = IMU.begin();
  if(retVal < 0)
    Serial.println("IMU initialization unsuccessful: check your wiring or try resetting power to the sensor.");
   // start ticker
  TimerIMU.attach(1.0 / SAMPLING_FREQUENCY, readIMU);
}

void loop()
{
}

This approach does not produce the expected results: the IMU returns always the same values. Putting the readIMU function in the main loop and commenting the Ticker works well. I use an ESP32-WROVER.
Where is my error? Any suggestion would be appreciated.

readIMU() is called by the library from an ISR (Interrupt Service Routine). While the ISR runs, other interrupts cannot be handled. The IMU sensor works over I2C, which relies on interrupts being serviced. So, when initiating the communication inside an ISR, the transmission can never be finished correctly, since the needed ISRs are not executed. At least the library doesn't seem to block in that case, so the code runs, but the values are never updated.
You should not do interrupt dependent things inside of an ISR. Instead you can define a global flag variable, which you set inside the ISR. Then in your main code you just constantly check this flag and execute the ISR dependent code, if the flag is set. After the execution you reset the flag.
The response time is dependent on the speed, that your loop runs in. But this shouldn't be a problem here, since you don't have any other code in loop() and your frequency is just 1Hz, so a delay of a few microseconds should not be relevant.

Note, that using Serial is also interrupt dependent. So writing or printing to Serial inside an ISR is also not very good. Though you can get away with it, when you make sure, that you never send more data, than the Serial buffer can hold, and that you leave enough time between the interrupts for the actual transmission. Inside an ISR the printing and writing statements will just fill the buffer. The data will then gets send in the background via interrupts.

Note, that doing this with a Ticker (aka via interrupts) is really not necessary. Instead you can execute the code directly in loop() in a non-blocking style via millis(). Have a look at the BlinkWithoutDelay example, that comes with the Arduino IDE. It demonstrates how to do timed things without blocking with delay calls.


text:
Need some Hardware advice with arduino
I am fairly new(having less hands on experience) to Arduino and electronics in general. I have a project for which I know the features and required electromechanical parts. I need some advice in choosing the right Arduino. Here's my requirement :-
I need the board to handle the following Hardware/Software parts -

3 Geared motors,
1 BLDC 1000 kva
2 cameras ( one is also ok)
TinyML for object detection
Mic to receive audio commands
Speaker to talk back.
Wifi shield to send/receive information to internet or a laptop.
3 small servo motors.
2 Proximity sensor.
1 dc motor (6-9v)

Please advice which Arduino board will be perfect for the above requirements. I was thinking of Arduino Mega 2560, but after looking into various projects I couldn't decide if it was sufficient as I have many hardware parts.

To process incoming images, voice commands, produce sounds, and also do WiFi is almost certainly beyond the capabilities of any micro computer, like the Arduino (maybe some of the more recent models might). I strongly doubt that the Mega 2560 would. It doesn't have a heap of RAM for one thing (it has 8k of RAM). Look at the sizes of images produced by cameras these days, they are usually measured in megabytes, not kilobytes.
What might work for you would be a Raspberry Pi, which is basically a small Linux computer on a board, with a substantial amount of RAM.

Yeah, unless he either optimizes all of it to a tee I doubt that any arduino could do it. Unless he does all the heavy lifting off of an actual computer somewhere else (aka just use the arduino to gather the data and send signals back to the hardware

Your main bottleneck here is the camera. If you want to do real time video, I would suggest getting a Raspberry Pi or the equivalent then using it as a master over something easier to code like an arduino.
The camera and wifi would be handled by the raspberry pi ( using Robot Operating software ) and the low level stuff like motor would be handled by the arduino ( any will do, since the main computing task will be left to the Pi ).
As for the machine learning, most microcontrollers can't handle it. If you want to do machine learning, I would suggest the NVIDIA range of single board computers instead of a Pi, since they have better GPU performance.

A Pi should be able to do rudimentary ML. It might not have a multi-core GPU, but it does have good native floating point performance.

If your project is more for fun and not mission-critical, and you have an older smartphone you're no longer using, you can repurpose it. For the motors (BLDC, DC, servos) and proximity sensors you can use any arduino (e.g. Nano) through either its USB port (if it has OTG) or bluetooth (e.g. Pro Micro). Your Arduino code in this case would be very simple, just a few lines to send proximity data, and set servo angles and motor PWMs.
If you choose this path (if you CAN choose it), you can get the most CPU power, memory, and in general doing this in Kotlin or Java is simpler than on any 8-bit microcontroller (or probably on a RPi which is a very good choice otherwise). You can use its camera (very good on most phones), wifi, microphone, speaker, etc. as well. There are libraries for object detection, and many other things. Using its accelerometer, gyro, GPS, mobile internet, NFC, light sensor, touchscreen could be a plus. And they come with batteries (UPS included).
Of course you need to have an old phone (most people replace theirs in around 2-3 years, just ask around in your family and friends), buying one for this costs more than an SBC. Also, Android can kill your app if you're not careful (just uninstall/disable everything else you can, and this probably won't happen), so don't use this to control a nuclear power plant or similar. If you need to build more units, getting old phones becomes harder. But for hobby projects this could work. If not, just choose a SBC (like Raspberry Pi, Orange Pi, BeagleBoard, etc.).

I would suggest you to go with esp32 as it already has a Wi-Fi module and also the specs are pretty good

2 CPU (one dual core and other one ultra low power)
frequency 240 MHz
flask size upto 16 megabytes
also a inbuilt BLE module
it has around 34 usable pins

Hope this helps.

The esp32 won't work except ypu extend it with a reasonable amount of external hardware. Take the esp-cam for example: you can take and process images (thanks to the external ram), but it doesn't have free pins left to do anything else.


text:
Drawing a bar graph in a LCD
I'm getting my first steps on Arduino and I'm trying to do an exercise where I have to draw a graph bar in a 16x2 LCD that indicates the values read from a vector of 16 integer elements amplified by the value read from a potentiometer (connected to the analog pin A0) during runtime. The graph should change in real-time as I move the cursor of the potentiometer to the left or right.
I have the following code structure:

void loop() {
// Read the 16 vector elements and map then to the screen height ...
// Print out their values multiplied by the value read form the potentiometer, to the serial monitor ...
// Draw a bar for each one of the vector elements (you will have 16 bars in the end)...
// If the graph has reached the screen edge do not amplify it anyfurther. If it has reached the bottom, do the same
//Wait a bit. Start drawing everything from scratch.

So far what I have is:
#include<LiquidCrystal.h>

// Create an LCD object and connect control wires

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int vector[16] = {3, 7, 10, 15, 28, 12, 43, 1, 6, 19, 29, 23, 54, 76, 57, 66};

int value=0;

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

  // Specify the LCD's number of columns and rows

  lcd.begin(16, 2);
}

void loop(){

  value = analogRead(A0);

  for(int i=0; i<16; i++){
    int vector2[i] = map(vector[i], 0, 1024, 0, 20);
    Serial.println(vector2[i]*value);
  }
}

However I'm getting the following error so far:
 In function 'void loop()':
28:25: error: array must be initialized with a brace-enclosed initializer
 exit status 1

Also I can't think of a way to do the last 3 steps of the code structure I have.
I know that if i would want to print a bar like a character I could do:
#include<LiquidCrystal.h>

// Create an LCD object and connect control wires

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte bar[] ={B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111};

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

  // Specify the LCD's number of columns and rows

  lcd.begin(16, 2);
  lcd.createChar(0, bar);
}

void loop(){
lcd.setCursor(0,0);
cd.write(byte(0));

}

But even this would only print a column in the first row and column and not in both rows and first column of the LCD.
Can someone help me with the error I already have and give me some lights on how to do the last 3 steps of the code structure?

review how to operate on arrays ... https://www.arduino.cc/reference/en/language/variables/data-types/array/

your code repeatedly prints to location 0,0 ... i do not see what is unclear about that

You're using an array vector2[] inside loop() that has an undefined size because you did not properly declare it. The error is quite descriptive and will also highlight the line where the error was found.

Okay got the part of the vector2 already! Thanks

How do you hope to draw a 16 element bar graph in a text LCD? The closest you could get is to use user-defined characters to have partial blocks for a vertical graph.

@Majenko that was what I was thinking about but can't think of a way to put a column character on both rows or how to draw it deppending on the value of the value2*potentiometer

First off you're going to need to define some custom characters. There's examples for how to do that.  You want characters that gradually fill up from the bottom to full, such as:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █
Now, you have 8 lines per character and two lines of characters, which gives you a possible drawing range of 0-16. So you need to map your maximum range into that 0-16 span.
Finally you want to create a function to draw a single bar. This will take two parameters - the position of the bar (x) and the height of the bar (y). A simple little bit of mathematics later and you can work out what to print in the upper and lower characters.

If the value is = 0:

Both top and bottom are spaces

If the value is <= 8:

The bottom character is the one with the same number of lines as the value
The top character is empty.

If the value is > 8:

The bottom character is the one with all 8 lines filled
The top character is the one with the value - 8 number of lines filled.

So you may end up with something like (note - untested):
const uint8_t bars[8][8] = {
    { 0, 0, 0, 0, 0, 0, 0, 0xff },
    { 0, 0, 0, 0, 0, 0, 0xff, 0xff },
    { 0, 0, 0, 0, 0, 0xff, 0xff, 0xff },
    { 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff },
    { 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
    { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
};

void setup() {
    // other stuff, like setting up the LCD...

    for (uint8_t i = 0; i < 8; i++) {
        lcd.createChar(i, bars[i]);
    }
}

void drawBar(uint8_t x, uint8_t y) {
    char top, bot;

    if (y == 0) { // Both spaces
        top = ' ';
        bot = ' ';
    } else if (y <= 8) { // Bottom has bar graph, top is empty
        top = ' ';
        bot = val - 1; // Characters start at 0, so 1-8 is 0-7
    } else if (y <= 16) { // Bottom is full, top has bar graph
        top = (y - 9); // Characters start at 0, so 9-16 is 0-7
        bot = 7;
    } else { // Overflow - both top and bottom full
        top = 7;
        bot = 7;
    }

    lcd.setCursor(x, 0);
    lcd.write(top);
    lcd.setCursor(x, 1);
    lcd.write(bot);
}

void loop() {
    // your stuff in here
}

Then to draw a bar you just call drawBar 16 times:
for (uint8_t i = 0; i < 16; i++) {
    uint8_t y = <your calculation on vector2[i] here>
    drawBar(i, y);
}

If you've done it right you should end up with something like:
▁█ ▄ ▆█▇   ▃ ▃▇
██▃█▇███▅▆▇█▆██▃


text:
WiFiManager library question (wm.setConfigPortalBlocking(false) + big delay = not working)
I'm trying to use the library in my project. An implementation with wm.setConfigPortalBlocking(false) is needed, but when a large delay is used in the loop, the portal either does not work at all, or it freezes very much and the web interface does not load. What can be done?
For example:
#include <WiFiManager.h>
WiFiManager wm;

void setup() {
    WiFi.mode(WIFI_STA);
    Serial.begin(9600);
    wm.setConfigPortalBlocking(false);
    if(wm.autoConnect("TEST-AP")){
        Serial.println("connected...yeey :)");
    }
    else {
        Serial.println("Configportal running");
    }
}

void loop() {
    wm.process();
    Serial.print(".");
    delay(60000);
}

examine the blinkWithoutDelay example sketch in the Arduino IDE

Use a shorter delay.
WiFiManager only gets to run when you call wm.process(). When you use a large delay you prevent it from doing any processing during that time, as you saw. This is the way it works. If you want it to work best, don't use a delay at all.

there is no way to get working portal with another lib or code with big delay? am i right?

Why do you think you need a big delay? You almost certainly don't.

because in the loop i sending data from sensors to google script and i need them only once per 60 sec

So you write your loop to send data only one per 60 seconds. You can do other stuff during that time, you don't have to not do anything for 60 seconds.


text:
uint8_t issues when linking libraries outside of INO file
I've been trying to start my project out split into multiple files, knowing it will grow. I was templating it off of how I've done C++ files in the past: classes in an individual .h/.cpp pair and linked into the main file. I'm using the OneBitDisplay library for my OLEDs. When I include the library in my ino file and call functions within it, all works fine. When I have it linked from one of my class header files, it gives this output:
In file included from C:\Users\Kyle\Documents\Arduino\libraries\OneBitDisplay-master\src/OneBitDisplay.h:4:0,
                 from C:\Users\Kyle\Projects\EOS-OSC\OLED.h:1,
                 from C:\Users\Kyle\Projects\EOS-OSC\OLED.cpp:1:
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:67:1: error: 'uint8_t' does not name a type
 uint8_t iSDA, iSCL; // pin numbers (0xff = disabled)
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:68:1: error: 'uint8_t' does not name a type
 uint8_t bWire; // use the Wire library
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:69:1: error: 'uint8_t' does not name a type
 uint8_t iSDABit, iSCLBit; // bit numbers of the ports
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:70:1: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 uint32_t iDelay;
 ^~~~~~~~
 char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:75:10: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 volatile uint32_t *pSDADDR, *pSDAPORT; // data direction and port register addr
          ^~~~~~~~
          char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:76:10: error: 'uint32_t' does not name a type; did you mean 'char32_t'?
 volatile uint32_t *pSCLDDR, *pSCLPORT;
          ^~~~~~~~
          char32_t
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:82:26: error: 'uint8_t' has not been declared
 int I2CRead(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                          ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:82:41: error: 'uint8_t' has not been declared
 int I2CRead(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                                         ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:34: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                  ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:49: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                                 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:86:69: error: 'uint8_t' has not been declared
 int I2CReadRegister(BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen);
                                                                     ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:92:27: error: 'uint8_t' has not been declared
 int I2CWrite(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                           ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:92:42: error: 'uint8_t' has not been declared
 int I2CWrite(BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen);
                                          ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:100:1: error: 'uint8_t' does not name a type
 uint8_t I2CTest(BBI2C *pI2C, uint8_t addr);
 ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:104:27: error: 'uint8_t' has not been declared
 void I2CScan(BBI2C *pI2C, uint8_t *pMap);
                           ^~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:110:27: error: 'uint32_t' has not been declared
 void I2CInit(BBI2C *pI2C, uint32_t iClock);
                           ^~~~~~~~
C:\Users\Kyle\Documents\Arduino\libraries\BitBang_I2C-master\src/BitBang_I2C.h:115:36: error: 'uint8_t' has not been declared
 int I2CDiscoverDevice(BBI2C *pI2C, uint8_t i);
...

This keeps going for quite a while where any types from the stdint library are referenced.
It seems to only occur when the library is included in a header file, not when it is in the main ino sketch. I have it linked in the ino, knowing that the compiler needs all referenced libraries placed there.
When I remove the include from the header, it gives errors that it can't find types for variables that I've declared (as it should, given that these types are defined in the library I'm trying to include)
Any clues? I've never posted anything on StackOverflow, because I usually can find the answer but this one has stumped me.
I'm happy to provide any other code or debugging output if needed.

In Oled.cpp (or Oled.h), try including Arduino.h before any other includes.

That did it. Thanks. I had them in there, just needed to have Arduino.h before everything else. Makes sense, dependency-wise. Just a bit strange because looking at the source code the libraries already include Arduino.h themselves. Must have to do with the way Arduino searches for dependencies.

The uint8_t and the uint32_t types reported in your compile errors are defined in the stdint.h file. In .ino the stdint.h is included  with Arduino.h (which is added at ino to cpp conversion by Arduino builder).
The BitBang_I2C.h should include Arduino.h or stdint.h, but the author forgot to add it. Then if BitBang_I2C.h is included in .ino, the Arduino.h is included above it and the types are defined, but if you include BitBang_I2C.h in a cpp file which doesn't include Arduino.h or stdint.h, then the stdint defines are missing.
The workaround for this bug is to add #include <stdint.h> at the top of your OLED.cpp file.

Thanks. I had included both Arduino.h and stdint.h, but it looks like I had them out of order. Feels kinda stupid now

Arduino IDE implicitly includes some headers. Especially "arduino.h".
You need to include "stdint.h" into your header files for completeness.


text:
Error in reading wind speed from esp32
I need your assistance with a problem I am facing. I built a weather station. esp32 board was used in this project. I used a hall sensor with a magnet in the wind speed measuring part (ANEMOMETER). Previously the method I used was when 20 counts of magnet counted by the hall sensor, it will count the time for 20 counts and output the average wind speed. Code worked fine with the esp32 board. But for better accuracy, I changed the method. Now the method is within 20 seconds how many counts of the magnet were detected will be output as an average wind speed. Since then the wind speed reading couldn't be seen on the serial monitor. ( I have the wind speed part of the code built for the Arduino Uno & it works fine with both methods). The Arduino sketch is below. The only change I did in 2 methods are
if (revolutions>=20) { was changed to if ((millis ()-timeold)==30000) {
    //Define all libraries in here....

#include<FirebaseESP32.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include "DHT.h"

#define FIREBASE_HOST "https://digital-weather-station-default-rtdb.firebaseio.com/"
#define FIREBASE_AUTH "jbqMg4BPxhCTTicMJAXXvV3LiuFW85PZVb8e8GZY"

const char *ssid = "SVITIN-70A0";
const char *password = "10237684";
String D;

#define DHTPIN 4
#define DHTTYPE DHT22   // DHT 22  (AM2302)
#define Offset 0;

// Connect pin 1 (on the left) of the sensor to GROUND
// Connect pin 2 of the sensor to +3.3V
// Connect pin 3 (on the right) of the sensor to whatever your DHTPIN is

DHT dht(DHTPIN, DHTTYPE);

FirebaseData firebaseData;

//Variables For Humidity & Temperature
float h=0;  //Define Humidity value Default Value = 0
float t=0;  //Define Temp value in celcius Default Value = 0

//Variables For Wind Speed
volatile byte revolutions;
float rpmilli;
float Speed;
unsigned long timeold=0;

//Variables For Wind Direction
int VaneValue;// raw analog value from wind vane
int Direction;// translated 0 - 360 direction
int CalDirection;// converted value with offset applied
int LastValue;

//Defined new void funtion for get temp and hum...
void Temp(){
   // Wait a two seconds between measurements.
  delay(2000); // Reading temperature or humidity takes about 250 milliseconds!
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));

  if (Firebase.pushFloat(firebaseData, "/Weather Results/Temperature",t))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());
    Serial.println("ETag: " + firebaseData.ETag());
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }

  if (Firebase.pushFloat(firebaseData, "/Weather Results/Humidity",h))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());
    Serial.println("ETag: " + firebaseData.ETag());
    Serial.println("------------------------------------");
    Serial.println();
 }
 else
 {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }
  }

void WSpeed(){
    // if (revolutions>=20) {
   if ((millis ()-timeold)==30000) {
    //Update RPM every 30 seconds, increase this for better RPM resolution,
    //decrease for faster update

    // calculate the revolutions per milli(second)
    rpmilli = ((float)revolutions)/(millis()-timeold);

    timeold = millis();
    revolutions = 0;

    // WHEELCIRC = 2 * PI * radius (in meters)
    // speed = rpmilli * WHEELCIRC * "milliseconds per hour" / "meters per kilometer"

    // simplify the equation to reduce the number of floating point operations
    // speed = rpmilli * WHEELCIRC * 3600000 / 1000
    // speed = rpmilli * WHEELCIRC * 3600

    Speed = rpmilli * 0.7665 * 3600;

    Serial.print("RPM:");
    Serial.print(rpmilli * 60000);
    Serial.print(" Speed:");
    Serial.print(Speed);
    Serial.println(" kmph");

  if (Firebase.pushFloat(firebaseData, "/Weather Results/Speed",Speed))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());
    Serial.println("ETag: " + firebaseData.ETag());
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }
  }
}

  void rpm_fun()
{
  revolutions++;
}

void WDirection(){
VaneValue = analogRead(34);
Direction = map(VaneValue, 0, 4095, 0, 360);
CalDirection = Direction + Offset;

// Only update serial monitor if change greater than 5 degrees.
if(abs(CalDirection - LastValue) > 1){
Serial.print(VaneValue); Serial.print("\t\t");
Serial.print(CalDirection); Serial.print("\t\t");
getHeading(CalDirection);
LastValue = CalDirection;
}
  }

// Converts compass direction to heading
void getHeading(int Direction) {
if(Direction < 35){
Serial.println("N");
 D="N";
}

else if (Direction < 100){
 Serial.println("NE");
 D = "NE" ;
}

else if (Direction < 170){
  Serial.println("E");
  D = "E" ;
  }

else if (Direction < 200 ){
  Serial.println("SE");
  D = "SE" ;
  }

else if (Direction < 210){
  Serial.println("S");
  D = "S" ;
  }

else if (Direction < 245){
  Serial.println("SW");
  D = "SW" ;
  }

else if (Direction < 259){
  Serial.println("W");
  D = "W" ;
  }

else if (Direction < 268){
  Serial.println("NW");
  D = "NW" ;
  }

else
Serial.println();

if (Firebase.pushString(firebaseData, "/Weather Results/Wind Direction",D))
  {
    Serial.println("PASSED");
    Serial.println("PATH: " + firebaseData.dataPath());
    Serial.println("TYPE: " + firebaseData.dataType());
    Serial.println("ETag: " + firebaseData.ETag());
    Serial.println("------------------------------------");
    Serial.println();
  }
  else
  {
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println(F("DHTxx test!"));
  dht.begin();                                                               //DHT and TEMP sensor starting.....
  attachInterrupt(digitalPinToInterrupt(27), rpm_fun, RISING);                // Attaching Interrupt funtion for wind speed....
  revolutions = 0;
  rpmilli = 0;
  timeold = 0;
  LastValue = 1;
  Serial.println("Vane Value\tDirection\tHeading");

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);
}

void loop() {
  Temp();
  delay(2000);
  WSpeed();
 delay(2000);
  WDirection();
 delay(2000);
  }

the problem is probably the == ... think about it


text:
Unexpected character added to char buffer array in serial monitor only when SD card initialized
I'm getting an unexpected extra character added to the serial monitor print line only when I initialize an SD card in the code.
Normal
The code below gives me this expected result in the serial monitor:
Serial Monitor
23:31:12.745 -> inputString: abc

Code
const int BUF_DIM = 3;
char inputString[BUF_DIM];

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  inputString[0] = 'a';
  inputString[1] = 'b';
  inputString[2] = 'c';

  Serial.print("inputString: ");
  Serial.println(inputString);
}

void loop() {
}

Unexpected Character
However, the serial monitor prints an unexpected extra M at the end of inputString's value abc when I add initialization of an SD card.
Serial Monitor
23:24:30.319 -> Initializing SD card...initialization done.
23:24:30.319 -> inputString: abcM

Code
#include <SPI.h>
#include <SD.h>

File myFile;

const int BUF_DIM = 3;

char inputString[BUF_DIM];

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  //-------------Toggle this block to see the M dissapear-----------
  Serial.print("Initializing SD card...");
  if (!SD.begin(5)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  myFile = SD.open("DATA.TXT");
  //-------------Toggle this block------------

  inputString[0] = 'a';
  inputString[1] = 'b';
  inputString[2] = 'c';

  Serial.print("inputString: ");
  Serial.println(inputString);
}

Why is this happening and how can I get the serial monitor to behave as expected with the SD card.

const int BUF_DIM = 3;

char inputString[BUF_DIM];
...

  inputString[0] = 'a';
  inputString[1] = 'b';
  inputString[2] = 'c';

...

  Serial.println(inputString);

You have allowed three characters in your array and indeed put three characters there, however you have not put a "null terminator" there at the end (nor is there room for one) so you will naturally get garbage at the end of the string until the processor happens to find a 0x00 byte.
Put it another way, how does the code know to print three characters and not 20 characters? The answer is that the underlying function (Serial.println in this case) looks for a null-terminator.
You need to read up on how null-terminated strings work.

Ahh yes inputString[2] = '\0'; fixed the issue. Didn't know about null-terminators. Thanks!


text:
Connecting Common-Anode Seven Segment Display to Shift Register
I recently wired up the following ill-advised circuit:
A common-anode display is wired with its cathodes connected directly to LEDs connected to ground. But the strange thing is that it worked exactly as intended: when an LED turned on, the corresponding segment turned off.
My first question is, why didn't it burn out all the LEDs (plus maybe my microprocessor)? 3.3V should be passing directly from the chip, through the 7-Segment and the LED, and into the ground rail. One page on the chip's website (https://www.pjrc.com/teensy/techspecs.html) says it emits a max of 9mA, but that's just a warning about their tolerances, and the pins don't actually throttle output, right? But if all that's true, why is nothing fried? (note that the real circuit is doubled up from what you see in the diagram, using daisy-chained shift registers. I realized after drawing it that that might make a difference, since the current would be split 14 ways instead of 7).
My other question is, I added a resistor at the input of the 7-Segment to limit current, and the circuit still works as originally intended. How is that possible? If a segment is being lit up, that means there's current passing through it, but once on the other side, it should be going directly into the ground via the standalone LED, not "swimming upstream" through a resistor to reach ground via the shift register. Multimeter readings at the cathodes of the 7-Segment are emitting 2V and 0.3 mA. If 0.3mA are insufficient to light up the standalone LEDs, why do they suffice to light up the internal LEDs of the 7-Segment? (and as I recall, they weren't turning on when it was running with no resistance, either.)
Finally, all this has made me wonder, if the digitalWrite pins are capable of emitting 3.3V, what's the point of having a 3.3V pin?

the shift register powers the LEDs, not the Teensy pin

What you are experiencing here is the forward voltage of diodes. When a diode (here you have light emitting diodes, so LEDs) is places in the forward direction in a circuit, it will only conduct when a certain threshold voltage is reached. This voltage is called forward voltage and is dependent on the individual diode (you can find this info in the diodes datasheet) and on other factors like the temperature. To visualize this you can look at a diodes characteristics curve (plotting current against voltage):

I got this image from the German wikipedia article on diodes. As you can see the current stays minimal until the voltage gets in the range of 0.7V. Then the current rises exponentially.
You yourself measured the forward voltage of the 7-Segment LED. You measured 2V between ground and the LED cathode. With 3.3V power you get a forward voltage of 1.3V.
What's happening? Your other LEDs likely have a higher forward voltage, so that the remaining 2V from the 7 Segment LEDs aren't enough to light them. There might be flowing a small current on the path through both types of LEDs, but it will be very small and cannot burn anything. So that path isn't as favorable for the current as you thought. Then taking into account that the shift register pulls its output to either ground or 3.3V it gets clear, that the shift register still provides the easiest current path.

If 0.3mA are insufficient to light up the standalone LEDs, why do they suffice to light up the internal LEDs of the 7-Segment?

I'm not very sure about that value. Typical LEDs need current in the range of  maybe 5mA. For your LEDs we cannot definitely state it (since we don't know what LEDs you have), but 0.3mA seems to low for me. How did you measure it?

One page on the chip's website (https://www.pjrc.com/teensy/techspecs.html) says it emits a max of 9mA, but that's just a warning about their tolerances, and the pins don't actually throttle output, right?

That's only the current range for the digital outputs of the Teensy. Each digital pin has a driver hardware incorporated in the microcontroller. This hardware can only withstand a certain amount of current, until it fails. And it might fail short (shorting to either 3.3V or ground) or disconnected. When you drive the pin near and over its max ratings the voltage will dip on it, since some of the voltage gets lost on the driver components, which are loaded with more current than they were made for. The internal driver can then be killed by the power dissipation in it (voltage lost on the driver multiplied by the current gives you the waste power, which is dissipated as heat there, until something gets fried).

if the digitalWrite pins are capable of emitting 3.3V, what's the point of having a 3.3V pin?

As mentioned the digital output pins can only provide low current. They are meant for doing digital signaling, not for powering devices. The current is enough to drive a single small LED, but not enough to power a motor or other current hungry devices.
The 3.3V pin is not controlled by anything. It is directly connected to the power supply of the whole board. When you power the Teensy via USB it gets 5V from it. A voltage converter regulates that down to 3.3V and feeds it to the Teensys microcontroller to power it and also to the 3.3V pin. In fact you can also use it to connect your own regulated 3.3V power supply and thus power the Teensy through the 3.3V pin.


text:
Set time() on ESP8266
If I call configTime() on a ESP8266 using ESP8266 Core, then time() gets changed from uptime to unixtime. However this sends a SNTP request. I have a DS3231 RTC attached without internet. How can I set time() without calling configTime()?
Thanks in advance

Probably settimeofday(...) is what you want.

Whenever you have epoch time, either from RTC, NTP, etc., use the POSIX function settimeofday() to set system time as @Majenko said
The sample code is as follows:
// Assuming we already have Unix `epoch` time, which is time from Jan 1 1970.
// From RTC, NTP, etc.
time_t epoch_t = epoch;

// set the time to UTC
setTime(epoch_t);

// set the system time to UTC
timeval tv = { epoch_t, 0 };
settimeofday(&tv, nullptr);

// Now we can have system time by calling time()
time_t timeNowUTC;
struct tm * timeInfo

timeNowUTC = time(nullptr);
timeInfo = localtime(&timeNowUTC);

For the record, the issue has been solved in Arduino Forum : Update time() from DS3231


text:
Alternatives to Radio Transceivers
So i am creating a haunt project that needs a way of detecting when an Arduino passes it and makes that Arduino do something. the problem I'm having is that none of the transmitter and receiver that has a small enough range that won't interfere with other patrons walking through on the other side of the wall. does anyone have any ideas what i can use?

Not a question about Arduino

RFID tags would be fitting

There is a discussion of a similar question at the Arduino forum where they leaned towards passive UHF RFID tags.
If your budget stretches to it, there would be a range of active RFID tags that might suit.
There’s a good intro to RFID at Sparkfun, and Wikipedia has a good starting reference point.


text:
Arduino Nano BLE 33 default example sketch `USBHID>Keyboard` makes the Arduino unusable
How the problem started
I was playing around with using the Arduino Nano BLE 33 as a keyboard, and stumbled upon the USBHID>Keyboard sketch which I got via the default suggestion from the Board Manager to install Arduino Mbed OS Nano Boards:
See the source on github.com/arduino/ArduinoCore-mbed, or reproduced below:
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"

USBKeyboard Keyboard;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
  Keyboard.printf("Hello world\n\r");
}

It seemed fairly innocent, so I uploaded it without a second thought thinking that I could trust anything provided from Arduino itself as an example script.
What the problem is
But now, as soon as I plug in the Nano, it types Hello world followed by a newline every. single. second.
If I try to upload the blink sketch to clear it, I first need to select the Port, but the act of going through the menu to choose the correct port takes over a second, and typing in Hello world selects the library manager and ends up opening it when enter is pressed due to the \n\r. So my Arduino Nano has been rendered useless by code included as an example in the default sketches. That's not cool.
Failed Solution Number 1
I tried creating a custom keyboard shortcut to select the port in less than a second, and then pressing cmd-U to upload, but I think there might also be a problem there because I get this error:
    ...
    Found upload port: /dev/cu.usbmodem11401
    /Users/<my username>/Library/Arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac -d --port=cu.usbmodem11401 -U -i -e -w /var/folders/y1/md9_k_td4rz1f0pq26d24crh0000gn/T/arduino_build_230227/<my script name>.ino.bin -R
->  No device found on cu.usbmodem11401
    An error occurred while uploading the sketch
    ....

I'm absolutely certain that cu.usbmodem11401 is the correct port, because that's what shows up when I ls /dev/cu* while the Arduino is plugged in. So I think that the Arduino IDE is attempting to upload to cu.usbmodem11401, but sees that it's a keyboard, and decides that it can't upload code to a keyboard so aborts.
Failed Solution Number 2
I tried uploading blink.ino from a different laptop (also macos) but nothing changed.
Failed Solution Number 3
I tried looking for ways to 'distrust' a keyboard to prevent the Arduino from sending keyboard strokes, but couldn't anything.
Failed Solution Number 4
Maybe attempting to short circuit whichever wire the Arduino uses to communicate with the laptop will work, but I don't know nearly enough to do that so I'd just be randomly connecting wires to ground which I don't really want to do...
Fin
I'm at a loss for what to try. I've logged an issue with the github repo, but I can't think of other solutions.

According to the datasheet...

3.6 Board Recover
All Arduino boards have a built-in bootloader which allows flashing the board via USB. In case a sketch locks up the
processor and the board is not reachable anymore via USB it is possible to enter bootloader mode by double-
tapping the reset button right after power up.

So, plug it in, and press the RESET button twice. That should then load the bootloader and it will sit there waiting for you to reprogram it.

Legend. Thanks so much! Imma go read the datasheet now...


text:
Motor rotates well in one direction but runs slower in other with L298N and L293d
I connected 2 motors with an L293Nn driver. When I control it with my joystick, one motor works fine (Out 1 and 2 of driver.) It rotates in one direction and the other very smoothly.
The problem occurs in the second motor (Out 3 and 4 of driver.) It rotates smoothly in one direction (clockwise) but when rotated in the other(anti-clockwise), the 4000 RPM motor rotates at around 60 RPM. My voltmeter shows a reading of 1V. When I reverse the polarity at the driver, it rotates slowly in the clockwise direction and at proper speed in the anticlockwise direction.
I tried it with another L298N driver and had the same problem. I tried with an L293D driver and still had the same error. The code is the same for both drivers. The motors work fine when just connected to the 12V battery (both directions.)
I do not understand the problem.
My code:
struct Signal{
  uint16_t y1; // Joystick-1 Y 0 to 1023
  uint16_t y2; // Joystick-2 Y 0 to 1023
};
int x1 = 0; // Joystick-1 Y 0 to 255
int x2 = 0; // Joystick-2 Y 0 to 255
Signal data;
#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
RF24 radio(7,8);
const byte address[6] = "HexaT";
void setup() {
  Serial.begin(9600);
  pinMode(1, OUTPUT); // motor b
  pinMode(2,OUTPUT); // motor b
  pinMode(6,OUTPUT); // motor b key

  pinMode(5,OUTPUT); // motor a key
  pinMode(9, OUTPUT); // motor a
  pinMode(10,OUTPUT); // motor a

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

}

void loop() {
  while(radio.available()){
    radio.read(&data, sizeof(Signal));

//motor A
    if(data.y1 > 530){
      x1 = map(data.y1,530,1023, 0, 255);
      analogWrite(5,x1); // motor a key
      digitalWrite(9,LOW); // motor a
      digitalWrite(10,HIGH); // motor a
    }else if(data.y1 < 500){
      x1 = map(data.y1,500,0, 0, 255);
      analogWrite(5,x1); // motor a key
      digitalWrite(9,HIGH); // motor a
      digitalWrite(10,LOW); // motor a
    }else{
      digitalWrite(5,LOW); // motor a key
      digitalWrite(9,LOW); // motor a
      digitalWrite(10,LOW); // motor a
    };

//Motor B
    if(data.y2 > 530){
      x2 = map(data.y2,530,1023, 0, 255);
      analogWrite(6,x2); // motor b key
      digitalWrite(1,LOW); // motor b
      digitalWrite(2,HIGH); // motor b
    }else if(data.y2 < 500){
      x2 = map(data.y2,500,0, 0, 255);
      analogWrite(6,x2); // motor b key
      digitalWrite(1,HIGH); // motor b
      digitalWrite(2,LOW); // motor b
    }else{
      digitalWrite(6,LOW); // motor b key
      digitalWrite(1,LOW); // motor b
      digitalWrite(2,LOW); // motor b
    };

    Serial.println(x1);
    Serial.println(x2);
  }
}

In the serial monitor, I get proper values from 0 to 255 for both the joysticks and send that PWM signal to the driver.

I can't reproduce it now but may I suggest you to don't use PIN 1 as output while using hardware Serial? It uses PIN 1 to transmit and this could cause interference with motor (it should do the same in both directions....)


text:
Internet in ESP32 is not working with IPv6
I am using ESP-WROOM-32D in STA mode with Arduino IDE(2.0.5) ESP32 board(2.0.9).
I am trying to do http post request with ESP32. Router that provides internet supports only IPv6.
Here I am getting http code -1. I have tried different network with IPv4 which works fine and returns 200.
So my question is do I need to enable something to make this work ? I have used WiFi.enableIpV6(); and got IPv6 IP also.
void setup() {

Serial.begin(115200);
  delay(2000);
  WiFi.onEvent(WiFiEvent);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(300);
    Serial.println(".");
  }
  Serial.println("wifi connected");
  delay(2000);

  HTTPClient http;
  http.begin("https://www.google.com/");
  int httpCode = http.GET();
  Serial.printf("HTTP code: %d\n", httpCode);
  http.end();
}

void loop() {

}

void WiFiEvent(WiFiEvent_t event) {
  switch (event) {
    case ARDUINO_EVENT_WIFI_STA_CONNECTED:
      Serial.println("Enabling IPv6");
      WiFi.enableIpV6();
      break;
    default:
      break;
  }
}

This is the debug message I got
[     4][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[  2053][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 0 - WIFI_READY
[  2144][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 2 - STA_START
[  2313][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
Enabling IPv6
.
[  2620][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[  2620][D][WiFiGeneric.cpp:1098] _eventCallback(): STA IP: 192.168.1.3, MASK: 255.255.255.0, GW: 192.168.1.1
.
wifi connected
[  4035][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 8 - STA_GOT_IP6
[  4774][D][HTTPClient.cpp:263] beginInternal(): unexpected protocol: https, expected http
[  4775][D][HTTPClient.cpp:303] beginInternal(): protocol: https, host: www.google.com port: 443 url: /
[  4781][D][HTTPClient.cpp:598] sendRequest(): request type: 'GET' redirCount: 0

[  5035][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 8 - STA_GOT_IP6
[  9829][I][ssl_client.cpp:112] start_ssl_client(): select returned due to timeout 5000 ms for fd 48
[  9830][E][WiFiClientSecure.cpp:144] connect(): start_ssl_client: -1
[  9833][D][HTTPClient.cpp:1163] connect(): failed connect to www.google.com:443
[  9840][W][HTTPClient.cpp:1483] returnError(): error(-1): connection refused
HTTP code: -1
[  9858][D][HTTPClient.cpp:408] disconnect(): tcp is closed

Did you find an answer? I'm having this issue now, and it's pretty much what you're describing.

They said it is pending from the development. It will be solved in ESP 3.0 version. Follow this roadmap for update : https://github.com/orgs/espressif/projects/3/views/14. There are other alternatives on there GitHub page but are quite complicated. You can dig into that, I didn't.


text:
Is there any way to secure Esp32 BLE server?
I've got a project in which currently I am using Bluetooth classic (with SSP - Simple secure pairing) to communicate to my esp32 board with my android app, but Bluetooth classic serial communication is not supported on ios devices therefore I want to switch to using BLE instead, but I can't find any way to secure the BLE that will ship with the product!
Any help would be appreciated,
Thanks :)

you could use higher level routines like digest, shared secret, public key, etc.

could you please elaborate a bit, I didn't understand. Thanks for helping :)


text:
Can not burn arduino pro mini 8 MHz bootloader with usbasp
I am using schematic of Arduino Pro mini 3.3v/8 MHz version. Please see below circuit diagram I built.

Power supply to circuit is 3.3V.
I have a USB ASP programmer which I used in previous version of same circuit running at 5V/16MHz. It was working fine.
It is connected to board like this.

I want to burn bootloader in this controller so that I can use with arduino IDE. I have done following settings.

When I connect USBASP to PC (Windows 10), in device manager, I see the USBASP. Driver installed through Zadig.

When I click Tools -->  Burn Bootloader in arduino IDE , I get this error
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override
     this check.

Error while burning bootloader.

What I have tried:
1 - Changed firmware of USBASP to official fishl.de website.
2 - Put JP3 on USBASP.
3 - Changed driver of USBASP from libusb-k to libusb-win32 from Zadig. Error changes to
Arduino: 1.8.15 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328P (3.3V, 8 MHz)"
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override

     this check.

4 - Replaced microcontroller from some other board to this board.
5 - Checked voltage on 8 MHz crsytal pins of controller. 3.12V and 3.28V. Cant see wave on oscilloscope.
Nothing works. Same error. I was hopeful that maybe atemga328 is faulty but even after changing it, it doesnt work and I cant burn bootloader and get same error.
Can this be due to crystal capacitor values of 10 pF instead of 20pF? (I chose 10nF after reading datasheet carefully).
Any ideas why this problem?

The problem was related to crystal. When I changed to another crystal (different part number), it worked.


text:
Digital potentiometer DS3502 question
I am using adafruit DS3502 breakout board for arduino. When I follow procedure written in
https://learn.adafruit.com/ds3502-i2c-potentiometer/arduino
My serial display shows correct voltage values.
My question is: When I remove RL,RH, RW pins from arduino and measure resistance between RW and RL or RW and RH with a multimeter, it doesnt show correct value in ohms. It shows between 300 to 400 K Ohms. Anyone knows is this known behaviour or am I doing something wrong.

If you ground the (-) lead of the meter and probe the RW pin while programmatically  changing the steps, do you get reasonable values?  See https://electronics.stackexchange.com/questions/590633/is-there-a-better-way-to-determine-the-resistance-of-a-digital-potentiometer-tha

NO...doesnt read values at all like this.


text:
Connecting various devices to Arduino
I need to connect the following devices to an Arduino UNO board. The problem is that I run out of pins to be able to connect them all. Is there any way to do it?

ultrasonic sensor
yellow led
green led
red led
buzzer
keypad 4x4

I'm doing the project in Tinkercad
In the picture below I tried to do it, but I am missing 2 pins for the ultrasonic sensor trig and echo

Another option would be one of these: https://www.instructables.com/PCF8574-GPIO-Extender-With-Arduino-and-NodeMCU/

As cguck70 already stated in the comments: The pins A0 to A5 can be analog input pins, but they can also be normal digital input/output pins. You can use them to your liking, just like any other digital input/output.
So just connect two of these pins to your ultrasonic sensor and use the pin names A0, A1 and so on in your code.


text:
Adjusting Threshold for Digital Pins
I am working on a project using Force Sensors to build a keyboard for MD patients.
I have connected the sensors (each with 4 input pins) to digital pins to Arduino Due.
I want to adjust the threshold of the digital pins in order to cancel out the initial weight of a user's hand when using the keyboard.
I have read that digital pins have a built-in threshold ("low"<0.3 Vcc and "high">0.6Vcc). I can't connect my sensors to Analog pins (due to needing 20 input pins), and was wondering if adjusting the threshold is possible?
I have researched and found one project that used Analog pins and adjusted the threshold, which I am trying to emulate: https://www.instructables.com/Arduino-Programmable-Button-Panel-As-Keyboard/
P.S: I am a beginner at Arduino and would appreciate the help

Could you consider using an analog multiplexer?

I like Edgar Bonet's idea.  Backing up a bit more.  Would it be easier for an MS patient to control a chorded keyboard?

No, you cannot change these threshold. They are set by the digital input hardware (technically a Schmitt trigger) inside the microcontroller. They are not meant to be adjustable, since they are digital input, not analog inputs.
So you either need to build your own adjustable logic (involving opamps and variable resistors), feeding the output of that to the Arduino, or you need to use analog inputs.
I would suggest using the second method. You can extend the number of analog inputs basically by 2 means:

You can buy analog multiplexers. These are chips that can connect one analog input of the Arduino on one side to X pins on the other side. Most of them are controlled via digital pins. Then you cycle through each setting of the multiplexer to connect one sensor at a time and do a measurement on each of them. Each analog pin can be connected to one analog multiplexer

You can buy an external ADC board. These are often connected via interfaces like I2C or SPI (for example this one from Adafruit with 4 channels each). You can use multiple of them.


text:
How to toggle a pin (LED) simply
I am not a programmer but rather a hardware guy. In the good old machine code days, you could 'read' the status of the port and flip it.. admittedly a much simpler processor. Is it not possible to do this with the 328 without many lines of code?

When you google for "Arduino toggle pin" you will get good results. When doing it the Arduino way it would be: digitalWrite(pinToToggle, !digitalRead(pinToToggle));

The other cores apart of oficial ones often provides toggle funcionality. And if you don't like super slow arduino functions, you can access ports directly (for example if you write something to PINx it'll toggle corresponding bits on PORTx)

what @KIIV said ... official info is at section 17.2.2 of https://ww1.microchip.com/downloads/en/DeviceDoc/40001906A.pdf

To toggle a pin, just read the pjn and invert the value:
#define LEDPIN 2

void loop() {
    digitalWrite(LEDPIN, !digitalRead(LEDPIN));
}

You can also just "remember" the last value:
#define LEDPIN 2
bool led_on = false;
unsigned long led_time = 500; // 1/2 sec on and 1/2 sec off
unsigned long lasttime = 0; // last millis() time we turned the led off or on

void setup() {
    digitalWrite(LEDPIN, LOW);
    pinMode(LEDPIN, OUTPUT);
}
void loop() {
    unsigned long now = millis();
    if (lasttime - now > led_time) {
        led_on = !led_on;
        digitalWrite(LEDPIN, led_on);
        last_time = now;
    }
}

It is perfectly possible to do this without "many lines of code". The ATMega328P is actually a pretty simple chip (certainly by today's standards). Reading and writing pins is just the same as it has always been - read a port's byte value from the PINx register, modify it, and write it back to the PORTx register.
Much of what the Arduino API does is abstract things to make complex operations simpler. One side effect is it can make simple operations seem more complex (and in fact can slow things down as a result). But you don't have to always use the Arduino API for everything.
It is common to directly manipulate the IO registers to perform higher speed manipulation of the IO pins especially when you want to do such things as emulate other communication protocols, or shrink your code to fit into a really small microcontroller with as little flash usage as possible.


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

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

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

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

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

Usage:
  arduino-cli upload [flags]

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

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

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


text:
Convert Int to HEX, HEX to string and to byte? General converting problem
Since Cpp is not my main language, I struggle to find the best way to convert between types for my needs.
So my starting point is
struct can_frame {
    canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
    __u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
    __u8    data[CAN_MAX_DLEN] __attribute__((aligned(8)));
};

So first I needed it bo send to Serial as a hex string, so solution I've found and used was
String frame = "CAN:";
char dataString[1] = {0};
sprintf(dataString, "%03X", can1Msg.can_id);
frame += dataString;
for (int i = 0; i < can1Msg.can_dlc; i++) {  // print the data
  char dataString[1] = {0};
  sprintf(dataString, "%02X", can1Msg.data[i]);
  frame += " " + String(dataString);
}

Doesn't seem elegant byt it did the job.
But then I needed to do some checking of ID and specific bytes
So I've saved all String ins String bytes[8]
So  now I could something like
if (id == "2A0" && bytes[0] == "A0") {

And that was almost over, but then I realized that I need to do some checking of Integer number that is saved on 3 bytes.
E.G byte[2] + byte[3] + byte[4] which would something like 0020A0 whih will be 8352 as an Int
But converting things around gave all the problems such us String to const char* etc.
I wanted to convert __u8 to byte array so I can do checks and conversions and eventually convert it to string, but I've failed.
Can anyone suggest best approach for this ?

Note that you are overflowing the 1-cell arrays dataString. This is probably corrupting some of your memory.

The main problem that you are having is a lack of understanding in what "hex", "byte", etc are.
You are trying to work with four data types (int, hex, string and byte) when in reality there are only two types: String and binary. Everything else is just a representation we as humans use to make easier sense of the binary data.
You have a "source" type (can1Msg.data) which is, at one and the same time, binary, integer, hex and byte. The only thing it is not is String and you create that manually with your sprintf calls.
To compare the third "hex pair" value in your data you simply:
if (can1Msg.data[2] == 0x42) { ...

That is, compare the 8-bit binary value stored in array slice 2 (arrays count from 0 so 2 is the third entry) with the binary value represented by the hex notation 42.  The exact same thing can be done with:
if (can1Msg.data[2] == 66) { ...

66 is the decimal (base 10) equivalent of 0x42.  You can also use binary or octal. These two are also exactly the same:
if (can1Msg.data[2] == 0102) { ... // octal
if (can1Msg.data[2] == 0b01000010) { ... // binary

If you need to examine groups of bytes, such as if you have two bytes that form a 16-bit integer, you simply combine those two bytes into an integer, taking care to obey the correct endianness of the values.  For example if you have a 16 bit integer that is stored as can1Msg.data[7] and can1Msg.data[8] in big endian form, you can use:
uint16_t val = (can1Msg.data[7] << 8) | can1Msg.data[8];

Then simply compare the numeric (binary) integer value at will.  All that line does is take the first 8 bit value and "shift" it 8 bits to the left to make it a 16 bit value with the lower 8 bits set to 0, then overlay the second value over those lower 8 zeroes, to make it a single 16-bit value.

Thank you very much. My mistake was that for some reason I assumed that what I have in data is not a byte and it got stuck in my head that I need to convert it to byte.


text:
ESP32-S3 Stuck at a Crash and Not Auto Resetting
Given below is a short version of the Arduino code I used to program ESP32-S3. On some occasions the program crashes and unlike normal crashes this one get stuck there without Auto-resetting
static void setup2()
{
    Serial.println("Setup (runnning on 2nd core)");
}

static void loop2()
{

    HandleConfigButton();
    HandleActivity();

    // To resolve core panic because of Watch Dog Timer not being reset
    delay(1);
}

// This is task running on the second core of ESP32
void TaskOnCore2( void * pvParameters ){
    Serial.print("Task running on core ");
    Serial.println(xPortGetCoreID());

    // One time setup
    setup2();
    for (;;)
    {
        // Loop function
        loop2();
    }
}

TaskHandle_t HandleTaskOnCore2;
void LaunchLoopOnSecondCore()
{

    xTaskCreatePinnedToCore(
                TaskOnCore2,         /* Task function. */
                "TaskOnCore_2",      /* name of task. */
                10000,               /* Stack size of task */
                NULL,                /* parameter of the task */
                1,                   /* priority of the task */
                &HandleTaskOnCore2,  /* Task handle to keep track of created task */
                ESP32_SECOND_CORE);  /* pin task to second core */

}

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

}

void loop()
{
    HandleActivity();
}

The Crash Log:
Task running on core 0
Setup (runnning on 2nd core)Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (ipc1)
Core  1 register dump:
PC      : 0x4037db37  PS      : 0x00060036  A0      : 0x8037c750  A1      : 0x3fcf1b10
A2      : 0x3fc94510  A3      : 0xb33fffff  A4      : 0x0000cdcd  A5      : 0x00060023
A6      : 0x00060023  A7      : 0x0000abab  A8      : 0xb33fffff  A9      : 0xffffffff
A10     : 0x00000000  A11     : 0x3fc94450  A12     : 0x7e140000  A13     : 0x08bb0000
A14     : 0x02c94510  A15     : 0x00ffffff  SAR     : 0x0000000e  EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000

Backtrace: 0x4037db34:0x3fcf1b10 0x4037c74d:0x3fcf1b50 0x4037b02c:0x3fcf1b80 0x4037b022:0xa5a5a5a5 |<-CORRUPTED

ELF file SHA256: d451f74eeae971ec

I used ESP Exception Decoder and got this result
PC: 0x4037db37EXCVADDR:
0x00000000

Decoding stack results

0x4037db34: xPortEnterCriticalTimeout at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_hw_support/include/soc/compare_set.h line 25
0x4037c74d: vTaskSwitchContext at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/include/freertos/portmacro.h line 578

Can Someone explain what is wrong here ? I am clueless here.

HandleActivity() appears to be called from the normal loop() task and also indirectly from your task named TaskOnCore2 . Does it contain mutexs/semaphores and what size is it at runtime ? Whatever, this does appear to  indicate that the stack sizes defined are insufficient: Stack canary watchpoint triggered (ipc1)


text:
Robot car not working
My robot car won’t respond to my command. The code below worked before however, this time there is no response. I’ve tried experimenting with the code in the first while loop. I’ve tried different code from other projects similar to this. I’ve played with the schematics however, nothing seems to work.
This is my code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library
Servo myservo1, myservo2, myservo3; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
int motorOne = 4;
int motorOne2 = 5;
int motorTwo = 6;
int motorTwo2 = 7;
int enA = 3;
int enB = 2;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

//initial motors pin

char command;
char Value;

void setup()
{
  myservo1.attach(2); // attach servo signal wire to pin 9
  myservo2.attach(8);
  myservo3.attach(12);

  //Setup usb serial connection to computer
  Serial.begin(9600);
  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}
void loop()
{
  while (bluetooth.available() > 2) {
    Value = bluetooth.read();
    Serial.println(Value);
  }

  if ( Value == 'F') {
    // Robo Pet Run Forward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'B') {
    //Robo Pet Run Backward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, HIGH);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, HIGH);
  } else if (Value == 'L') {
    //Robo Pet Turn Left
    digitalWrite(enA, 255);

    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'R') {
    //Robo Pet Turn Right

    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'S') {
    //Robo Pet Stop
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  }

  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);
    if (realservo >= 1000 && realservo <1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println("Servo 1 ON");
      delay(10);
    }
    if (realservo >= 2000 && realservo <2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println("Servo 2 ON");
      delay(10);
    }
    if (realservo >= 3000 && realservo <3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println("Servo 3 ON");
      delay(10);
    }

  }
}

I’m using this app:
https://play.google.com/store/apps/details?id=com.giumig.apps.bluetoothserialmonitor&hl=en&gl=US
And here are the schematics:

Is Serial.println(Value); printing what you expect?

test if everything is wired correctly ... write simple code that tests each motor ... test servo

@timemage When it worked before, the app would print a series of numbers and then the letters. It only prints command if my Nano is connected to the computer.

@jsotola I've tested the motors and servos individually and controlled them with potentiometers before moving on to Bluetooth. I've also tested the Bluetooth module with a simple blink command on the app and it works fine.

I've tested the motors and servos individually and controlled them with potentiometers before moving on to Bluetooth ... that was before ... test them now ... run one of the motors for a second in setup()

What get from that is that it Serial.print(Value); used to do what you expect, which is not what I'm asking. It's broken now. What is it doing now?

@jsotola i tested each motor again with just a simple sketch and they both work fine.

@timemage  Now nothing is printed on the Serial monitor even if the Arduino Nano is plugged to the computer.

A annotated schematic as you have wired it in place of your fuzzy frizzy picture would be a big help. Besure it shows all connections including power and ground.  Include links to the hardware devices that give "Technical" information.

@timemage
Your answer was part of the solution!
Thank you very much! In the first while loop I switched it from bluetooth.available > 2 to bluetooth.available > 0 and then switched the signs of the TX and RX. Now the robot car is responding and running. However it won't turn left even though both motors work fine.

In short, among whatever other problems you might have, you've wired your TX and RX connections backwards according to your diagram and code.
Swap them either in hardware or in software.

According to the documentation:
SoftwareSerial var_name(rxPin, txPin)

SS Operation

RX

TX

You've constructed your SoftwareSerial object as:
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

SS Operation
Pin Variable

RX
bluetoothTx

TX
bluetoothRx

Defined your pin variables to these pins:
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SS Operation
Pin Variable
Arduino Pin

RX
bluetoothTx
10

TX
bluetoothRx
11

Connected them as:

SS Operation
Pin Variable
Arduino Pin
BT Operation

RX
bluetoothTx
10
RX

TX
bluetoothRx
11
TX

So, you have them backwards. Connecting their RX (inputs) which is is harmless but not helpful and connecting their TX (outputs) which may damage something.
In case this isn't clear, the RX and TX on the HC-05 are labeled from its perspective and not from the perspective of the Arduino. Except for some things like an old external modem, RX and TX on device are nearly always labeled from that device's perspective.

A variable name like bluetoothTx can be confusing if you're not sure which thing is doing the transmitting. Is this the pin number for transmitting to Bluetooth or the pin that will be connected to the Bluetooth transmitter (in other words, for receiving)?
In some cases I just describe the situation in the variable name:
static const int PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX = 11;
static const int PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX = 10;
/// ...
SoftwareSerial bluetooth(
  PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX,
  PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX
);

I dunno that I'd go with a name quite that long, but you get the idea.
I'm swapping them in software here, leaving your physical connections as they were in the diagram mostly because I don't feel like redrawing your diagram. Though, if it were my project I would swap the wires (and defined pin numbers above), because the convention is to have SoftwareSerial receive on 10 just like hardware receives on pin 0 and to have SoftwareSerial transmit on 11 just like hardware transmits on pin 1; in order words, keeping the relative order of the pin numbers.
So this is what you have with the above code:

SS Operation
Pin Variable
Arduino Pin
BT Operation

RX
PIN_SOFTSERIAL_RX_TO_BLUETOOTH_TX
11
TX

TX
PIN_SOFTSERIAL_TX_TO_BLUETOOTH_RX
10
RX

Transmitters connected to receivers.
If you get confused build your own table and make sure your variable names make sense.
This has nothing to do with our question really, but: Most Arduino users, new ones anyway, are better off with an Arduino that has connectivity that displaces the need for SoftwareSerial. A minimal change from the Nano for what you're doing is a Micro or Pro Micro board. That board has native USB support which it uses to send "Serial" to the computer. That leaves the one actual hardware serial peripheral on the (Pro) Micro available for you to to connect to HC-05 (or whatever). There are a pile of options, including ones that just do Bluetooth also (without need of HC-05). Anyway, there are lots of ways to not use SoftwareSerial.


text:
How to properly set CS for SPI applications on Arduino Due
I needed SPI with CPOL=1 and CPHA=1. I read, that I could achieve this via SPI_MODE3. Further, I read to put the CS low and CS high code after SPI.beginTransaction(...) and before SPI.endTransaction() (See official doc). But the result does not look right.
Minimal example program:
void setup() {   // put your setup code here, to run once:
    pinMode(52, OUTPUT); // CS high
    digitalWrite(52, 1);
}

void spi_transfer() {
    uint8_t buffer[] = {0, 0};

    delayMicroseconds(1);
    SPI.begin();
    SPI.beginTransaction(SPISettings(SPI_BAUD, MSBFIRST, SPI_MODE3));
    delayMicroseconds(1);

    digitalWrite(52, 0); // CS Low
    delayMicroseconds(1);

    SPI.transfer(buffer, 2); // Data
    delayMicroseconds(1);

    digitalWrite(52, 1); // CS High
    delayMicroseconds(1);

    SPI.endTransaction();
    SPI.end();
    delayMicroseconds(1);
}

void loop()
{
  spi_transfer();
}

In yellow we see the CS signal (I use pin D52). In lila we see the clock signal.
To my understanding, this is not CPOL=1, as the Clock signal is low when the chip select goes low.
To my understanding, this is CPOL=0.
Is there a proper way to handle this? Setting CS outside of the begin/end Transfer would make the whole concept a bit superfluous.

it looks like the clock idles high ... it goes low before data transfer and returns to idle high after the transfer ... the second clock edge(rising) latches data


text:
Shiftout only handles one shift register at a time
I am making a 7x10 led matrix and I am having problems with the shiftout function. It is only able to show me the output in one shiftout register at a time. How can I fix it?

For example:
void setup(){
    // PORTB as output.
    // Pin 13: Clock 74HC595
    // Pin 12: Latch
    // Pin 11: Data
    // Pin 10: Reset
    // Pin 9: Clock CD4017
    DDRB = 0b111111;
    // Makes sure the 4017 value is 0.
    PORTB = 0b100;
    delayMicroseconds(5);
    PORTB = 0;
}

void loop(){
  shiftOut(11, 13, LSBFIRST, 0b1000111101);
  PORTB = 0b10000;
  delayMicroseconds(800);
  PORTB = 0;
  delay(10000);
}

This is the output it produces:

But with numbers of 8 bits or less the output is displayed correctly.
shiftOut(11, 13, LSBFIRST, 0b10001111);

shiftOut works on bytes. To do more than one byte you have to do more than one shiftOut. Also you have to take note of the bit ordering. You should shift the most significant bit first, not the least.
For example, this:
  shiftOut(11, 13, LSBFIRST, 0b1000111101);

should be:
  shiftOut(11, 13, MSBFIRST, 0b10);
  shiftOut(11, 13, MSBFIRST, 0b00111101);

The same thing still happens, in this case only the sixth led of the first row lights up.

What could it be? :(

I think it's the bit ordering that is wrong. Use MSBFIRST and not LSBFIRST?

It still does not work correctly, in this case the output on the LEDs is 1011110000. Could it be the simulator?

I just finished making my board, I loaded a programming with two shiftout and the output was displayed correctly, it is a problem of the simulator. Thanks for the help.

Have a look at the implementation of shiftOut() (you can find it where you installed the Arduino IDE in the file hardware/arduino/avr/cores/arduino/wiring_shift.c):
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
  uint8_t i;

  for (i = 0; i < 8; i++)  {
    if (bitOrder == LSBFIRST) {
      digitalWrite(dataPin, val & 1);
      val >>= 1;
    } else {
      digitalWrite(dataPin, (val & 128) != 0);
      val <<= 1;
    }

    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
  }
}

Do you see, that the value (parameter val) is of type uint8_t, so only 1 byte big? And do you see, that the for loop only counts to 8 (one iteration for each bit in a byte)? This means, that the shiftOut() function only handles one byte at a time. When you want to shift out more bits than 8, you need to call it repeatedly.
In your first example the code behaves accordingly. The provided data gets cast to uint8_t, cutting away the upper 2 bits.

I tried sending two shiftout but still the same thing happens :/

Could it be the simulator?

Yes, it might be, that the simulator doesn't handle the output of additional shift data to the next shift register. Though that is something, that only the creator of the simulator software can answer you.

I just finished making my board, I loaded a programming with two shiftout and the output was displayed correctly, it is a problem of the simulator. Thanks for the help.