body:
I have two original (designed and assembled in Italy) Arduino Nano Every Boards from a German Web Shop. They came sealed in original packaging. When I try to connect them to my PC, they don't power up.

What I've tried so far:

  * 6 different USB cables
  * 1 Desktop PC with Arch Linux as well as Windows 10, all USB Ports available (front headers, back side motherboard)
  * 1 Laptop PC with Arch Linux
  * 1 Google Pixel 4 XL using a USB-B to -C adapter

No combination of the USB cables with any of the aforementioned USB Ports / Machines / Operating Systems allow the Arduino Nano Every Boards to boot up (no LEDs flashing).

I tried powering the boards using a 9V battery block on the V_in and GND pins, which works. I also tried powering the boards using a 9V battery block and then connecting the USB, but the aforementioned machines / operating systems do not recognize a new device connected via USB, despite the boards being powered (LEDs flashing).

I also triple-checked the physical connection of the USB cables on both ends to be sure they are inserted properly. I can use the aforementioned USB cables, USB ports, machines, and operating systems to charge other devices or transfer data with other devices (like, e.g., smartphones, e-book readers, USB flash memory sticks, external hard drives, ...).

What should I try next to get the Arduino Nano Every working?

Please let me know which extra information I should provide. Thanks!

Note: As far as I can see, using `lsusb` on Linux should always list connected USB devices, regardless of the groups my user's in. Nevertheless, I also loaded the `cdc_acm` module and added `SUBSYSTEMS=="usb-serial", TAG+="uaccess"` to a udev rule located at `/etc/udev/rules.d/01-ttyusb.rules`, and reloaded the udev rules, to no avail.

title: Arduino Nano Every USB Connection not working

Answers: 3

body:
These types of questions often requires considerable trouble shooting until the cause is found.  In order to make this useful to as many people as possible, let us compile a list of actions. *(Add a comment if any have additional actions to try and I'll add them to the list.)*

 - "...powering the boards using a 9V battery block on the V_in and GND pins..."

Confirm the 9V supply is connected to VIN. An internal voltage regulator will then provide the necessary 5V and 3V3 to the rest of the Nano-Every. Consider if 9V was accidentally connected to either the 5V or 3V3 pins, parts of the Nano-Every my be damaged.

 - "using lsusb on Linux should always list connected USB devices"

Yes, it should. If "lsusb" is typed before and after plugging in the Nano Every there should be an additional USB device listed.  If there is no change, there may be something physically wrong (bad cable or incorrect cable (i.e. charging only), bad Nano or burnt out part).

Also, "lsusb" normally does not require root privileges. But consider trying "sudo lsubs" to confirm all USB devices are seen.

Here is an example output of "lsusb" run when an Nano-Every was connected to a Ubuntu computer:

    $ lsusb
    ...
    Bus 001 Device 004: ID 2341:0058 Arduino SA Arduino Nano Every

 - "I also loaded the cdc_acm module ..."

Inspecting a Ubuntu system that can successfully program a Nano-Every, I see no package with the words cdc_acm in it installed.

*(I'm going to have to look into the above. While Ubuntu's package manager does manage cdc-acm.ko, cdc-acm.ko exists.)*

 - "...and added SUBSYSTEMS=="usb-serial", TAG+="uaccess" to a udev rule located at /etc/udev/rules.d/01-ttyusb.rules"

Be aware that adding a udev rule with a low value such as "01*" is likely to be obscured by any udev rule with a higher number should a match be found. Most developers add udev rules which start with a high number such as "99*" to mitigate this problem.

This said, it is unlikely a modification to udev rules is necessary. Most if not all Linux distributions will handle a [USB/CDC][1] type of peripheral adequately with out modifications. Plugging in a Nano-Every into the above mentioned Ubuntu computer generates a new device at /dev/ttyACM0.

 - "I tried powering the boards using a 9V battery"

Avoid using [PP3 type 9 Volt batteries][2]. They can be problematic when their lower current capacity has been reached.  At which point their output voltage may drop. Leading to unexpected results. If such a battery is necessary, pay close attention to current needs adding up all the expected maximum currents. In brief, lower powered processor on Arduino boards built using an [LDO (Low DropOut regulator)][3] have the best chance of working as expected. Other Arduino boards may not work as well and high current components such as a motor, solenoid or relay will likely not work.

  [1]: https://en.wikipedia.org/wiki/USB_communications_device_class
  [2]: https://en.wikipedia.org/wiki/Nine-volt_battery
  [3]: https://en.wikipedia.org/wiki/Low-dropout_regulator

body:
It's some regression in linux core and 1200baud touch doesn't work properly (it seems it's used switching between updi mode and serial link).

I started using script mentioned in https://github.com/arduino/ArduinoCore-megaavr/issues/124 and i was able to upload it in most cases (but better than mostly failing) when I execute it few seconds before the upload.

For example curiosity nano board with Atmega4809 works perfectly as it's emulating debugger+serial+mass storage (but needs correct VID/PID in udev rules or connecting storage)

Mentioned script:

<!-- language: python -->

    #!/usr/bin/python3
    #   Run this script to reset the Arduino Nano Every
    #   eg. sudo python3 mcu_reset.py
    #
    # Note: You must install pyserial first; i.e. sudo pip3 pyserial

    import serial
    import os, sys
    # total arguments
    n = len(sys.argv)
    if n >= 2:
        port = sys.argv[1]
    else:
        port = '/dev/ttyACM0'

    print("Port: {}".format(port))

    #re-enable hupcl temporarily (necessary for arduino reset using serial port)
    os.system('sudo /bin/stty -F {} hupcl'.format(port))

    try:
        #perform Arduino Nano Every reset "handshake"
        ser = serial.Serial()
        ser.baudrate = 1200
        ser.port = port
        ser.open()
        ser.close()

    except serial.SerialException:
        print("Error: serial.SerialException")
        exit()

body: I've ordered an Arduino Nano (not "Every") from a different web shop now, and it powers up as soon as I connect to USB. Since the Arduino Nano uses mini-USB (the Arduino Nano Every uses micro-USB), I'm using a different cable from the ones I tried on the two Arduino Nano Every boards I have. But given that I tried multiple cables that also work with other devices, I'm confident now that the two boards I have are just broken. I've had bad luck.


body:
I am trying to get this display working on a Arduino Mega2560: https://newhavendisplay.com/content/specs/NHD-320240WG-BxTFH-VZ.pdf

Below how the display is supposed to be connected to an MPU (in my case the Arduino ATMega2560):

[![enter image description here][1]][1]

I used this code: https://support.newhavendisplay.com/hc/en-us/articles/4414078359191-NHD-320240WG-B-with-Arduino provided by Newhaven themselves.

I used pins 22 to 29 for PORTA (according to https://docs.arduino.cc/hacking/hardware/PinMapping2560):

[![enter image description here][2]][2]

When I upload and run the code, nothing happens.

The thing that I do not really get is the "negative voltage" of -25V, which is apparently built-in in this version of the display, but I measure nothing between ground and pin 17 of the display, when powered it through the Arduino's 5V on pins 1 and 2.

I also tried to power just the backlight with a separate source (takes about 140mA) or even the entire setup (total current 190mA, so the Arduino takes an extra 50mA).

  [1]: https://i.stack.imgur.com/yZTzb.png
  [2]: https://i.stack.imgur.com/mLoep.png

title: Newhaven NHD-320240WG-BxTFH-VZ# display does nothing

Answers: 0


body:
Consider the following code:

```cpp
    #include <Arduino.h>

    unsigned char testimage [] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    ... many more rows ...
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };

    void setup()
    {
        Serial.begin(115200);
        while(!Serial);

        Serial.println("start");

        for (int i = 0; i < 10; i++) {
            Serial.println((int)(testimage[i]));
        }

        Serial.println("stop");

    }
    void loop()
    {}
```
I found out that then the array gets a certain size, there is nothing being sent to the serial monitor. It looks like the entire program freezes. I do not even see the `start` message appear.

I haven't tried to find the exact size, but it is somewhere between 4500 and 8000. (When sized around 4500, it works, when around 8000 it doesn't).

When I do not address the array though, I do see the `start` and `stop` messages appear.

I am using an Arduino ATMega2560.

title: Is there a maximum length of an array in ROM?

Answers: 2

body:
In this case the RAM size is the limit. And you'd need some space for stack/heap,..

If you use non-const array, it'll be copied from flash to RAM at the startup

On the mega2560 even using const it still be copied into the RAM as each FLASH/RAM/EEPROM has different address space

Only way would be using [PROGMEM](https://www.arduino.cc/reference/en/language/variables/utilities/progmem/) and it can't be used directly (again different address spaces for flash/ram)

You can guess the mega2560 has 8KB RAM and you should keep some RAM for runtime. If there isn't enough of space, the stack and heap will be smashing each other and it would behave completely unpredictably (overwritten return addresses, runaway code and so on)

body:
It isn't clear whether you meant to put your array in ROM as your question implies, but the code you presented assigns it to RAM. That would surely restrict to your array to less than the 8K of of RAM minus whatever is needed by (globals + your libraries' statics + your code's statics + the stack).

Update:

> I assumed the data section of the code would end up in ROM.

In fact, an image of the *initialized data* section does become part of the ROM image. The initial values need to be saved somewhere so RAM can be initialized each time the program is(re-)started but it is not accessed from ROM during run-time. (Note we're not talking about PROGMEM data here, which *is* kept in ROM and accessed from there even at run-time.)


body:
I may have done some things incorrectly here, but this I what I have for publishing image that I read from serial camera to the MQTT broker:

```
void capturePicture() {
  if (!cam.takePicture())
    client.publish("info", "Failed to snap!");
  else
    client.publish("info", "Picture taken!");

  char length[21];
  uint32_t jpglen = cam.frameLength();

  sprintf(length, "buffer length: %d", jpglen);
  client.publish("info", length);

  byte wCount = 0;  // For counting # of writes
  client.publish("info", "transfer about to begin");
  client.beginPublish("picture", jpglen, false);
  client.publish("info", "after beginPublish");

  while (jpglen > 0) {
    uint8_t* buffer;
    uint8_t bytesToRead = min((uint32_t)16, jpglen);  // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);

    client.write(buffer, bytesToRead);

    jpglen -= bytesToRead;
  }

  client.endPublish();
  client.publish("info", "transfer should have ended;");
}
```

I know the board is working, I am connected to the broker and I can receive messages.
In the `loop` I am reading few sensors and pushing the string into the topic
```
void loop() {
  delay(1000);

  if (count == 5) capturePicture();

  if (!client.connected()) {
    reconnect();
  }

  int multi = analogRead(A2);
  int odor = analogRead(A1);
  int voc = analogRead(A0);

  char name[21];
  sprintf(name, "%d;%d;%d", multi, odor, voc);

  bool pubScss = client.publish("measurement", name);

  count++;
  client.loop();
}
```
and all that works fine.

what happens when `capturePicture()` gets executed is this:

```
Picture taken!
buffer length: 49048
transfer about to begin
```
--that's what I see on the topic's subscriber side, then it freezes for about 10secs and then it continues with sending messages from the `loop`.

So it seems like it never gets past `client.beginPublish("picture", jpglen, false);` call.
I'm setting PubSubClient's buffer size to `client.setBufferSize(10235);`

What can be happening here? Something I can further test??

Thanks for advices!

title: PubSubClient hanging on ESP32C3

Answers: 1

body:
The short form of the below is something like: **"After calling `.beginPublish()`, call `.endPublish()` before making a call to either `.publish()` or `.beginPublish()`.**

---

We don't have your actual code. And that makes things difficult.
However, this is **a** source of problems in what you have shown:

```c++
  client.beginPublish("picture", jpglen, false);
  client.publish("info", "after beginPublish");
  ...
  client.endPublish();
```

It kind of looks like you may intended the second publish to help you debug the initial problem. But again, we don't have your code. I don't know if this (or something just like it) is in your original. In any case, it's not doing you any good as a debug aid.

---

The `.beginPublish()`/[`.write()`-type stuff]/`.endPublish()` constructs a message in the MQTT protocol as you make these calls.
**By inserting `.publish()` call between them you are corrupting the communication.** In short, you're embedding an MQTT message part way inside of another MQTT message.

Something a bit like saying
```
HowHello. are you today?
```

instead of

```
Hello. How are you today?
```

This is confusing something, probably the server. Perhaps also the library itself and any client that receives whatever the server ends up passing along.

---

I tested with a few variations on this code:

```c++
//#define CAUSE_TROUBLE

void one_shot_message() {
  client.publish(MQTT_TOPIC, "[hi]");
}

void do_test() {
  static const char part1[] = "<Hello";
  static const char part2[] = " World>";
  static const char both_parts_length = // just being very explicit
      (sizeof part1 - 1) // part1 sans null terminator
    + (sizeof part2 - 1);// part2 sans null terminator
                       // the .publish accepting strings doesn't null terminate, so we aren't.

#ifndef CAUSE_TROUBLE
  one_shot_message(); // okay before beginPublish or after endPublish
#endif

  client.beginPublish(MQTT_TOPIC, both_parts_length, false);
#ifdef CAUSE_TROUBLE
  one_shot_message(); // not okay between beginPublish/endPublish
#endif
  client.print(part1);
  // tested with one_shot_message() called here (not-okay location) as well
  client.print(part2);
  client.endPublish();
}
```

What happens in the case of `#define CAUSE_TROUBLE` (at the least with server I'm using and the client I've written on a PC) is that a single corrupt-looking message comes through and then the ESP32 client reconnects to the server. Probably the server is closing the connection. It does this on a cycle of about 6 seconds. The corrupt message has the correct topic, which makes *some* sense because the topic is written as part of the `.beginPublish()` before there's an opportunity to corrupt the message. This may not be exactly what you're seeing, but I don't have good cause to think I should be seeing exactly what you're seeing; not the same exact code, client, server. It is similar anyway.

---

So, you can have `client.publish("info", "before beginPublish");`
or a `client.publish("info", "after endPublish");` at those locations, but not between the begin and end calls. If you wanted to try doing something like that, you probably could probably do so by creating a second `PubSubClient` so that you could fire off these smaller messages in a separate protocol stream while in the middle of constructing/sending a larger message on the main stream.  However the messages may not arrive in order, either because the of how the library works or because of timing in the network. So if you want to do that you may also want to send a counter value with each message so you can reconstruct the timeline in the sending code.

An aside regarding `sprintf` vs `snprintf`:

```
  char name[21];
  snprintf(name, sizeof name, "%d;%d;%d", multi, odor, voc);
```

`sprintf()` is something that exists to support very old code or very old compilers.  There's otherwise no use case involving `sprintf()` that would not be better using `snprintf()`


body:
I am trying to upload a simple blink program on my Adafruit Feather M0 Radio with LoRa Radio Module to ensure that it connects to my PC. So far, I have:

 - Gone through 4 data cables
 - Tested for connection on 3 different devices (laptop on Windows 11, desktop on Windows 10, and computer running CentOS respectively)
 - Followed the direction for using the board with the IDE [here][1] and [here][2]

But the Port submenu is greyed out and when it isn't, it just doesn't have the port that recognizes my Feather. When going into Device Manager, I can't see it in the list of devices even when I refresh.

  [1]: https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/setup
  [2]: https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-with-arduino-ide

title: Feather M0 doesn't show up as a COM or Serial port

Answers: 1

body: Turns out the bootloader/USB firmware wasn't loaded in, which is why the double-tap reset wasn't working. I looked into the option of using another board as a programmer to get the bootloader in my Feather, but it proved to be more of a hassle than I thought so I'm just going to get a replacement. Hope this helps someone out in the future.


body:
Hello there I am trying to install `Digistump` library to support ATTiny85 by digispark. But I am encountering a problem when trying to install Digistump AVR boards after adding an additional board URL preference as the library doesn't shows up after searching.I dont know what's the problem even after I tried from the fixes from other solutions across the web.
[![enter image description here][1]][1]

 So, I made an alternative method to work the board by installing `ATTinyCore` library. But it doesn't support `DIGIKEYBOARD` actions. So when I try to download from library manager there is only packages for AZERTY & Belgian AZERTY layout.
[![enter image description here][2]][2] [![enter image description here][3]][3]

So for me I need a package that support QWERTY layout. How to install the library.?

  [1]: https://i.stack.imgur.com/tWlqs.png
  [2]: https://i.stack.imgur.com/2I0jE.png
  [3]: https://i.stack.imgur.com/mwhgR.png

title: Need Digistump library for QWERTY keyboard and Fixes for my issues!

Answers: 1

body:
The description of DigiKeyboardFr says it is “based on
[DigisparkKeyboard][] library”, and gives the link to that library.
DigisparkKeyboard doesn't seem to be available from the Arduino library
manager: you will most likely have to install it manually. Manual
installation of Arduino libraries is widely documented.

[DigisparkKeyboard]: https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard


body:
I saw a library called LowPower_LowPowerLab that can set the Arduino in sleep mode. In their example they put the Arduino to sleep using an external button, is there anyway to invert this behavior? I want the Arduino to save battery power by being in sleep mode and then when I need it, hold a button down to keep the Arduino awake and then release the button to put it back to sleep. In their example below I have tried changing the attachInterrupt to HIGH/RISING/FALLING with no change. Also coul

LowPowerLab's Example:
``` // **** INCLUDES *****
#include "LowPower.h"

// Use pin 2 as wake up pin
const int wakeUpPin = 2;

void wakeUp()
{
    // Just a handler for the pin interrupt.
}

void setup()
{
    // Configure wake up pin as input.
    // This will consumes few uA of current.
    pinMode(wakeUpPin, INPUT);
}

void loop()
{
    // Allow wake up pin to trigger interrupt on low.
    attachInterrupt(0, wakeUp, LOW);

    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

    // Disable external pin interrupt on wake up pin.
    detachInterrupt(0);

    // Do something here
    // Example: Read sensor, data logging, data transmission.
}
 ```

title: I want the Arduino to be in sleep mode by default and have a button wake it up

Answers: 1

body:
> In their example they put the Arduino to sleep using an external button, is there anyway to invert this behavior?

Of course. Put the Arduino to sleep in `setup` and make the button wake it up.

Some tips [here](http://www.gammon.com.au/power).

Also, I wouldn't use LOW, I would use FALLING. LOW keeps interrupting the processor, so while you hold the button down it keeps entering the interrupt, which would make it unresponsive.


body:
I am using an Arduino UNO and the official arduino Motor Shield Rev3. I need Pin 3 for the rotary encoder attachInterrupt() output. Can I use a different pin for the motor shield, such as pin 6?

[![enter image description here][1]][1]

[![In this code, IF I replace the pin 3 with pin 6 in code then motor 1 is not working][2]][2]

  [1]: https://i.stack.imgur.com/Tyt0q.png
  [2]: https://i.stack.imgur.com/VvrQT.png

title: I am using an Arduino UNO and the official arduino Motor Shield Rev3, need Pin 3 for rotary encoder output. Can I use different pin for motor shield?

Answers: 0


body:
I ordered a ADS1115 so I could measure temperature of a type K thermocouple, but I am not managing to get accurate readings. I had it working while having a normal A0 pin, but since the [type K table][1] shows pretty low voltages, the 0-1023 scale is not accurate.

When the thermocouple is at room temperature (around 22°c), it shows 00.0 millivolts on the multimeter (which I dont understand since it does not match with the table), and my program outputs a value of around -40 and a voltage of -0.005. When I heat it up until I measure 10.0 millivolts (around 250°c according table), the Arduino prints a value of 53 and a millivolts of 300.

What am I doing wrong? I suspect something with the calculation, but I am not able to find out how I should do it, I know very little about millivolts.

Can someone help me out what I am doing wrong here and what I should do?

I have the thermocouple and ADS1115 connected as shown in the image below.
[![wiring][2]][2]

The code I am using is as following

```cpp
#include <Adafruit_ADS1X15.h>

const int analogFruitPin = 0;

Adafruit_ADS1115 ads;

void setup()
{
  Serial.begin(9600);
  ads.begin();
  ads.setGain(GAIN_FOUR);
  ads.setDataRate(RATE_ADS1115_860SPS);
}

void loop()
{
  int sensorValue = ads.readADC_SingleEnded(analogFruitPin);
  float voltage = sensorValue * (5.0 / 32768.0);
  Serial.println(voltage,3);
  Serial.println(sensorValue);
  delay(500);
}
```

  [1]: https://www.thermocoupleinfo.com/type-k-thermocouple.htm
  [2]: https://i.stack.imgur.com/gy4yA.jpg

title: Arduino read thermocouple Type K with ADS1115

Answers: 2

body:
Welcome! Interesting but expected. Thermocouples need what is called a cold junction compensation. That is a circuit or another thermonuclear that compensates for the thermocouple effect where the lead wires are connected to your measuring device. These thermocouple lead wires should be the same metallic material as the wires in the thermocouple. The metals are different where you connect to the measuring device and will generate a voltage as the temperature changes regardless of the sensing probe, that is how the thermocouple works. This link will help: https://www.tegam.com/what-exactly-is-cold-junction-compensation/

For more information check this link: https://randomnerdtutorials.com/arduino-k-type-thermocouple-max6675/

body:
To simplify your thermocouple temperature sensor project, consider using an [ADC][1] which also contains a cold junction temperature sensor.  [This product][2] from Adafuit.com integrates both into one package by using a Microchip.com [MCP9601 integrated circuit][3].

In short, thermocouples generate small amounts of voltage where dissimilar metals touch. This is true where the thermocouple wires are touching each other. And is also true where the thermocuple wires are touching the metal connecting them to the ADC circuit (commonly called the "cold junction"). To find the temperature where the thermocouple wires are touching we need to subtract the effects of the "cold junction". To do that, we need to first know the temperature of the "cold junction". We commonly do this with a second temperature sensor as it is a more practical (and portable) solution than a traditional zero centigrade ice bath (likely where the term "cold junction" came from).

  [1]: https://en.wikipedia.org/wiki/Analog-to-digital_converter
  [2]: https://www.adafruit.com/product/5165
  [3]: https://www.microchip.com/en-us/product/mcp9601


body:
I have an ESP32 Joy-it - SBC NodeMCU-ESP32 that should be use with board "ESP32 Dev Module". IDE says : Chip is ESP32-D0WDQ6 (revision v1.0).

Website product: https://joy-it.net/en/products/SBC-NodeMCU-ESP32

When I make a wifi scan, I find my AP, but if I connect with SSID + Password (both WPA (Internet box router - Freebox Crystal France) and WPA2 Personal (Xiaomi A2 Lite)), it doesn't work.

So I tried to make an AP without password on my phone, and ESP32 can connect without problem.

To do that, I used the default sketch "Wifi -> Wifi Client". My SSID and my password contain only letters/numbers (Only ASCII chars).

I tried to burn the bootloader, but nothing change.

I am using :

 - IDE Arduino 2.2.1
 - esp32 by espressif 2.0.14

Does somebody have an idea ?

title: Connect to wifi works only without password (Problem around WPA security)

Answers: 1

body:
Solution, I'm using an old Freebox, which has only Open or WPA security,

Just add : `WiFi.setMinSecurity(WIFI_AUTH_WPA_PSK);` to allow connection to my router.

For people with *WEP* security, just use `WIFI_AUTH_WEP`


body:
Below is the error displayed while uploading the Blink example in Arduino Nano:
```
FQBN: arduino:avr:nano:cpu=atmega328old Using board 'nano' from platform in folder: C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6
Using core 'arduino' from platform in folder: C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6

Detecting libraries used... C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++
-c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino
-IC:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs C:\Users\Admin\AppData\Local\Temp\arduino\sketches\662E4E1C72524160050FD4EC91DA330F\sketch\Blink.ino.cpp
-o nul Generating function prototypes... C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++
-c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -IC:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino
-IC:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\variants\eightanaloginputs C:\Users\Admin\AppData\Local\Temp\arduino\sketches\662E4E1C72524160050FD4EC91DA330F\sketch\Blink.ino.cpp
-o C:\Users\Admin\AppData\Local\Temp\1422417153\sketch_merged.cpp C:\Users\Admin\AppData\Local\Arduino15\packages\builtin\tools\ctags\5.8-arduino11/ctags
-u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\Admin\AppData\Local\Temp\1422417153\sketch_merged.cpp Compiling sketch... "C:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
-c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\eightanaloginputs" "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F\\sketch\\Blink.ino.cpp"
-o "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F\\sketch\\Blink.ino.cpp.o" Compiling libraries... Compiling core... Using precompiled core: C:\Users\Admin\AppData\Local\Temp\arduino\cores\arduino_avr_nano_cpu_atmega328old_6be783227e5bc0d57f51230f0c71f584\core.a Linking everything together... "C:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc"
-w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.elf" "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F\\sketch\\Blink.ino.cpp.o" "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/..\\..\\cores\\arduino_avr_nano_cpu_atmega328old_6be783227e5bc0d57f51230f0c71f584\\core.a" "-LC:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F"
-lm "C:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy"
-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.elf" "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.eep" "C:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy"
-O ihex -R .eeprom "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.elf" "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.hex"

"C:\\Users\\Admin\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size"
-A "C:\\Users\\Admin\\AppData\\Local\\Temp\\arduino\\sketches\\662E4E1C72524160050FD4EC91DA330F/Blink.ino.elf" Sketch uses 924 bytes (3%) of program storage space. Maximum is 30720 bytes. Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes. "C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\Admin\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
-v  -patmega328p -carduino "-PCOM5" -b57600 -D "-Uflash:w:C:\Users\Admin\AppData\Local\Temp\arduino\sketches\662E4E1C72524160050FD4EC91DA330F/Blink.ino.hex:i"

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:\Users\Admin\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600 avrdude: ser_open(): can't open device "\\.\COM5": The system cannot find the file specified.

avrdude done.  Thank you.

Failed uploading: uploading error: exit status 1
```

I searched online for any solution but wasn't able to find one.

title: Upload Issue in Arduino Nano

Answers: 0


body:
I'm new to using electronic boards, and have followed a guide online for printing a 6 DoF (degree of freedom) mouse. I'm stuck on an optional step that requires me to change the PID and VID of a "Arduino Leonardo" board.

I've located the appropriate "boards.txt" file, but I'm not sure which line to change. I've edited a few, but I'm worried I'll mess things up ([a tutorial for it][1] mentions they had destroyed 3 trying to rename it, and is back from 2009), and the ones I've changed do not result in a change.

I have checked out previous questions people have made regarding this topic, but quite frankly I can't understand the technical terms used in those.

[This is the code in question][2] I'm trying to compile, and lists example PID and VIDs as well.

I would love a clear explanation on which PID/VID I need to edit in the "boards.txt", so I can safely modify the board to be read as the space mouse in the code.

  [1]: https://forum.arduino.cc/t/customize-your-arduino/6983
  [2]: https://pastebin.com/z7yZXiBB

title: Change USB VID and PID (Leonardo)

Answers: 1

body:
[![Leave "boards.txt" alone. It is wrong side of your goal.][1]][1]

  [1]: https://i.stack.imgur.com/kKq69.png

> C:\Users\\%USERNAME%\AppData\Local\Arduino15\packages\arduino\hardware\avr

    leonardo.build.mcu=atmega32u4
    leonardo.build.f_cpu=16000000L
    leonardo.build.vid=0x2341     <--- here
    leonardo.build.pid=0x8036
    leonardo.build.usb_product="Arduino Leonardo"

----------

    leonardo.build.vid=0x256f
    leonardo.build.pid=0xc631
    leonardo.build.usb_product="SpaceMouse Pro Wireless (cabled)"


body:
Is it possible to access to I/O from M4 Co-Processor on an Arduino Giga ?

If so, how works concurrency with main CPU if both are trying to access to the same port ?

Does each CPU (Main and M4) have its own RAM memory ?

title: Arduino Giga M4 Co-Processor can't access to I/O?

Answers: 0


body:
Actually I want to check my HRSC-04 ultra sonic sensor by connecting to arduino.

I did it by taking an example of ping problem from the ide software.

When I opened serial monitor it is showing 0.02937 reading for 3 sensors i am having.

I want to know whether they are working or not?

title: Ultra Sonic Sensor

Answers: 0


body:
[![circuit diagram here][1]][1]

  [1]: https://i.stack.imgur.com/1jjpH.png

I have only ever been able to get this servo to “somewhat” work when connected to 5v pin on the shield, the ground on the shield, and the signal line attached to whatever pin. But 5v is not enough and 9v is too much. I'm trying a million different ways to power this thing, but I don't understand why I give it an appropriate voltage from X source (while still having the signal line connected of course), and it doesn't want to move at all.

So currently my Arduino is powered via USB. The shield/motor is powered from a 12v 2a power supply, which with a simple voltage divider circuit gets me 6.29V. Multimeter seems to show this works. Also the “Vin Connect” jumper on back was cut to make the screw terminals a dedicated power line for the motor, per Arduino website. I tried this set up without cutting the jumper too, same - no result.

Can anyone help me out? All I want to do is power my arduino with shield, and motor, however that has to happen, and be able to run the "Servo Sweep" example code.

https://docs.arduino.cc/hardware/motor-shield-rev3

https://www.amazon.com/ANNIMOS-Digital-Voltage-Stainless-Waterproof/dp/B07KTSCN4J

title: 6v High Torque Servo Won't Function On Motor Shield?

Answers: 1

body:
It may pay to think about current required as well as voltage. Looking at a data sheet I found online ([data sheet link)][1] it refers to a stall current of 3.5A when running at 6V.

What do you mean by “somewhat”? Can you give more detail on the behavior you see? It may be useful to hook your multimeter up as an ammeter to get an idea of whether current draw is approaching the limit of the wall plug (2A) used.

  [1]: https://m.media-amazon.com/images/I/81EFGw8qkhL.pdf


body:
So I am currently working on a small project which involves Arduino, LINX LabVIEW and LM35 temperature sensor. I dont know why but sometimes the output graph plots weird fluctuate value (kinda looks like sine wave with noise), sometimes it just plots a stable value and could be adjust by increase the temperature around the sensor.

[![enter image description here][1]][1]

I take a look at the datasheet (https://www.ti.com/lit/ds/symlink/lm35.pdf), at fig 13 they recommend to add a resistor or a bypass capacitor at the output of the sensor. What is the problem ? I mean sometimes it still work like it should be but most of the time it just some weird wave. My the image of my vi and my setup is attached below so hopefully someone could help me to identify the problem and the solution.
[![enter image description here][2]][2]
[![enter image description here][3]][3]

  [1]: https://i.stack.imgur.com/90x7B.png
  [2]: https://i.stack.imgur.com/xeHUw.png
  [3]: https://i.stack.imgur.com/G7bHv.jpg

title: Fluctuate output produce by LM35 temperature using Arduino and LINX LabVIEW

Answers: 1

body:
I don't use LabVIEW with Arduino (UNO) often, so you might have to do some troubleshooting yourself (i.e. is the A0 really just the 0 in the sub-VI?), but!

Even without the resistor (which is useful for multiple things), your values are a little bit out of the range--I'd expect at least 20mV for 2C; moreover, assuming a normal ambient temperature, you should be seeing values around ~250mV (but next time, please label your graphs!). Therefore, what you are seeing is simply noise and while there are ways to mitigate that, I would start with a new sensor and this time *correctly* connect it. You should've flipped your 5V and GND to accommodate the fact that you've changed the way it's facing referencing the datasheet. You could try flipping it and seeing if it works, but there is a good chance you might have burned it up.

When you get the value acquired correctly, you should probably do some smoothing on it before you convert it into temperature--if you're sampling at 10 Hz, you could build a value once per second. I'm not sure what you're using it for, but if it's for simple ambient temperature monitoring, that will get rid of some noise--you could simply fill up an array and average it every second and put that number to be further processed and displayed. Simple averaging will work like a low pass filter, as you're getting rid of all the fast-changing values and keeping the base value.

A resistor might be helpful as it helps the sensor with driving high-capacitance loads--as in, the load would require a certain charge to be delivered before they change the voltage and the LM35 cannot easily do it, but you could decouple and form, essentially, a low-pass filter by adding a resistor in series with the capacitive load. In your case, I would consider it because usually breadboards contain a lot of capacitance; in other words, they can act as capacitors pretty well! Either way, the datasheet promises a 0.5 C linearity around room-temperatures, so at best you might get +/- 2.5mV of fluctuations or a range of 5mV of noise, but of course, you can always make this worse :)

Let me know if you need any further help!


body:
I am new to this,  this is what I have for my hardware, but I don't have any code if someone could please help thank you

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/YKEnp.png

title: trying to make a circuit that uses an IR sensor, after the sensor gets an input it delays the output signal by 3 seconds before turning on the motor

Answers: 0


body:
I am trying to get my DHT20 and Oled (Both from the Arduino Sensor Kit) to work at the same time. I am able to get them working separately with their respective test codes but when I try to combine the codes the Oled display no longer works. Both are I2C connections but I checked and each device has a different address so that shouldn't be a problem.

Here is my DHT20 test code:

    #include "Arduino_SensorKit.h"

    //uncomment line below if using DHT20
    #define Environment Environment_I2C

    void setup() {
      //uncomment line below if using DHT20
      Wire.begin();
      Serial.begin(9600);
      Environment.begin();
    }

    void loop() {
      Serial.print("Temperature = ");
      Serial.print(Environment.readTemperature()); //print temperature
      Serial.println(" C");
      Serial.print("Humidity = ");
      Serial.print(Environment.readHumidity()); //print humidity
      Serial.println(" %");
      delay(2000);
    }

Here is my Oled display test code:

    #include "Arduino_SensorKit.h"
    void setup() {
      Oled.begin();
      Oled.setFlipMode(true);
    }

    void loop() {
      int random_value = random(0, 1023);   // create a random value

      Oled.setFont(u8x8_font_chroma48medium8_r);
      Oled.setCursor(0, 3);
      Oled.print("Value: ");
      Oled.print(random_value);
      delay(1000);
    }

This is my code where I tried to get both devices working at the same time:

    #include "Arduino_SensorKit.h"
    #define Environment Environment_I2C

    void setup() {

      Oled.begin();
      Oled.setFlipMode(true);

      Wire.begin();
      Serial.begin(9600);
      Environment.begin();
    }

    void loop() {

      Oled.setFont(u8x8_font_chroma48medium8_r);
      Oled.setCursor(0, 3);
      Oled.print("Testing");

      Serial.print("Temperature = ");
      Serial.print(Environment.readTemperature()); //print temperature
      Serial.println(" C");
      Serial.print("Humidity = ");
      Serial.print(Environment.readHumidity()); //print humidity
      Serial.println(" %");

      delay(2000);

    }

When I use the above code the temp and humidity values are printed in the serial monitor but the Oled does not display anything.

Any help is much appreciated!

title: DHT20 and Oled display not working together

Answers: 1

body:
### The basic problem

I don't have this sensor kit. But am able to observe what you're describing with substitutes and stand-ins. There seem to be two things you can do.

The basic problem is that the Arduino_SensorKit library is written to use software/bit-banged I2C for the display. Or rather, it tells U8G2LIB to do this, for what reason I don't know. When the ATmega328P I2C peripheral is enabled the GPIO hardware is no longer driving the pins. So the moment you enable the hardware I2C (via the DHT20 code) the GPIO bit-banging code in U8G2LIB cannot work correctly.

So, there are at least two ways this can be made to work.

* Modifying your code so it works with how the Arduino_SensorKit library is written.

* The other is modifying the Arduino_SensorKit library to use hardware I2C, in which case your original code works verbatim.

## Modifying the sketch

You can modify your sketch as follows:

```
#include "Arduino_SensorKit.h"
#define Environment Environment_I2C

void setup() {
  Oled.begin();
  Oled.setFlipMode(true);

  Serial.begin(9600);

  Wire.begin(); // only here to match the subsequent .end()
}

void loop() {
  Wire.end();  // make I2C release control back to GPIO
  {
    Oled.setFont(u8x8_font_chroma48medium8_r);
    Oled.setCursor(0, 3);
    Oled.print(millis()); //Oled.print("Testing");
  }
  Wire.begin(); // re-enable I2C for use by DHT20 ("Environment")

  Serial.print("Temperature = ");
  Serial.print(Environment.readTemperature()); //print temperature
  Serial.println(" C");
  Serial.print("Humidity = ");
  Serial.print(Environment.readHumidity()); //print humidity
  Serial.println(" %");

  delay(2000);
}
```

For the most part the AVR Wire library doesn't care if you use repeated `begin()` or repeated `end()` calls. It may affect your speed setting though. The braces around the `Oled` usage are just there for visual effect.

Anyway, it works when you make sure `Oled` can use GPIO.

## Modifying Arduino_SensorKit

With the following changes to Arduino_SensorKit library version 1.2.1 (current as of writing) I am able to use your sketch code verbatim. I also modified it to print `millis()` rather than `"Testing"` to be sure it was *continuing* to update the display.

### Arduino_SensorKit.h

On [line 24 of the libraries Arduino_SensorKit.h file](https://github.com/arduino-libraries/Arduino_SensorKit/blob/1.2.1/src/Arduino_SensorKit.h#L24), change:

```c++
extern U8X8_SSD1306_128X64_NONAME_SW_I2C Oled;
```

to

```c++
extern U8X8_SSD1306_128X64_NONAME_HW_I2C Oled;
```

Note `HW` (hardware) rather than `SW` (software).

### Arduino_SensorKit.cpp

Likewise make [the counterpart change to the definition of](https://github.com/arduino-libraries/Arduino_SensorKit/blob/1.2.1/src/Arduino_SensorKit.cpp#L14) `Oled` corresponding to above change in `extern` declaration of `Oled`, from:

```c++
U8X8_SSD1306_128X64_NONAME_SW_I2C Oled(/* clock=*/ _PIN_SCL, /* data=*/ _PIN_SDA, /* reset=*/ U8X8_PIN_NONE);
```

to:

```c++
U8X8_SSD1306_128X64_NONAME_HW_I2C Oled(/* clock=*/ _PIN_SCL, /* data=*/ _PIN_SDA, /* reset=*/ U8X8_PIN_NONE);
```

You can probably remove the arguments from the constructor call here; the ATMega328P has no options with respect to configuring TWI/I2C for more than one set of pins.

---

There's also nothing stopping you from leaving it as `U8X8_SSD1306_128X64_NONAME_SW_I2C`, but changing the pins so that the software I2C uses pins other than A4/A5 so as not to conflict with the DHT20 libraries use of hardware I2C.

---

For reference the U8G2LIB version I tested with was 2.33.15. arduino-cli version 0.32.2. arduino:avr core 1.8.7. *I don't think you need these. I'm just being complete in case someone finds this 5 years from now or whatever.*


body:
I tried to generate 2 independent PWM signals with their inverted signals on Arduino UNO R3. I can change the frequency for just one PWM signal, but the frequency of the second signal is constant at 62.5 kHz. How can I change it? How can I change the frequency of Timer 0, which I use for the second PWM signal?

The code that I used:

```c
#include <SoftwareSerial.h>
#include "Filter.h"
#include "MegunoLink.h" // for plotting

ExponentialFilter<float> Filterd_Current(20, 0);

SoftwareSerial mySerial(12, 7); // 232_TX, 232_RX

const byte intr1 = 2; // Pin D2 is "short" interrupt
const byte intr2 = 3; // Pin D3 is "open" interrupt

// PWM Parameters
//100kHz
//const byte param_a = 10;     // This is OCR1A register
//const byte param_b = 30;     // This is OCR1B register
//const byte freq_param = 40; // This is ICR1 register

const byte param_c = 45;     // This is OCR2A register
const byte param_d = 5;     // This is OCR2B register
//const byte freq_param2 = 50; // This is ICR2 register

//50kHz
const byte param_a = 10;     // This is OCR1A register
const byte param_b = 22;     // This is OCR1B register
const byte freq_param = 32; // This is ICR1 register

/* Default state of interrupt pins. When one of pins D2,D3
    is LOW we don't generate PWM signal on D9,D10 */
//volatile byte state_D2 = HIGH;
//volatile byte state_D3 = HIGH;

// PWM output pins
const byte D11 = 11; // High while generating PWM signal
const byte D13 = 13;
const byte D5 = 5;
const byte D6 = 6;

// Analog read //
int Supply_Sense = A0;
int Voltage_Sense = A2;
int Current_Sense = A4;
int Supply_Val = 0;
int Voltage_Val = 0;
int Current_Val = 0;

void setup() {
  // D2 & D3 are normally pulled up internally to ~5V
  pinMode(intr1, INPUT_PULLUP);
  pinMode(intr2, INPUT_PULLUP);
  /* Interrupts: When D2 OR D3 go from HIGH to LOW we stop generating waves W1,W2
     Normal operation is guaranteed only when both D2 & D3 are HIGH */
  attachInterrupt(digitalPinToInterrupt(intr1), stop_D2, CHANGE);
  attachInterrupt(digitalPinToInterrupt(intr2), stop_D3, CHANGE);
  pinMode(D11 , OUTPUT); //output  @D11 Signaling PWM is on
  pinMode(D13 , OUTPUT); //output  @D11 Signaling PWM is on
  digitalWrite(D11, LOW);
  digitalWrite(D13, HIGH);
  // Open serial communications and wait for port to open:
  Serial.begin(9600); // Port of the USB
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600); // RS232 port names "mySerial"
  // We start generating the waves when the arduino wakes up
  Gen_Waves();
}

void loop() {
  /* From here
  delay(1);
  if (mySerial.read() == 115){
    Serial.println("Stopped");
    digitalWrite(D11, LOW);
    digitalWrite(D13, LOW);
   }
  delay(1);
  if (mySerial.read() == 99){
     Serial.println("Continued");
     digitalWrite(D11, HIGH);
     digitalWrite(D13, HIGH);
     //delay(1);
     Gen_Waves();
   }
   To here is only for debugging purposes. */
   //static ArduinoTimer MeasurementTimer;
   // Analog read
   Supply_Val = analogRead(Supply_Sense);
   float temp_supply = Supply_Val*4.997/1024*6;
   Current_Val = analogRead(Current_Sense);
   float temp_current = Current_Val*4.997/1024*1;
   Voltage_Val = analogRead(Voltage_Sense);
   float temp_voltage = Voltage_Val*4.997/1024*1;
   float power = temp_voltage*temp_current;
   mySerial.println("Supply: " + String(temp_supply) + " Current: " + String(temp_current) + " Voltage: " + String(temp_voltage)+ " Power: " + String(power));
}

void stop_D2() {
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  TCCR0A = 0;
  TCCR0B = 0;
  TCNT0 = 0;
  digitalWrite(D11, LOW);
  digitalWrite(D13, HIGH);
  Serial.println("D2 Intr");
}

void stop_D3() {
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  TCCR0A = 0;
  TCCR0B = 0;
  TCNT0 = 0;
  digitalWrite(D11, LOW);
  digitalWrite(D13, HIGH);
  Serial.println("D3 Intr");
}

void Gen_Waves() {
  //clear timer registers
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  TCCR0A = 0;
  TCCR0B = 0;
  TCNT0 = 0;
  //Set OC1A and OC1B as PWM outputs
  DDRB |= (1 << DDB1) | (1 << DDB2);
  // Set OC0A and OC0B as PWM outputs for Timer 0
  DDRD |= (1 << DDD6) | (1 << DDD5);
  // Set OC1A and OC1B as outputs
  TCCR1A |= (1 << COM1A1) | (1 << COM1B1);
  TCCR0A |= (1 << COM0A1) | (1 << COM0B1);
  // Set OC1A as non inverted and OC1B as inverted
  TCCR1A |= (0 << COM1A0) | (1 << COM1B0);
  TCCR0A |= (0 << COM0A0) | (1 << COM0B0);
  // set the PWM mode
  TCCR1A |= (0 << WGM10) | (0 << WGM11);
  TCCR1B |= (0 << WGM12) | (1 << WGM13);
  TCCR0A |= (1 << WGM00) | (1 << WGM01);
  //START the timer with no prescaler
  TCCR1B |= (1 << CS10);
  TCCR0B |= (1 << CS00);
  //PWM mode counts up and back down for 320 counts
  ICR1 = freq_param;
  //ICR0 = freq_param2;
  // Pin A config (Pin D9)
  OCR1A = param_a;
  OCR0A = param_c;
  // Pin B Config (Pin D10)
  OCR1B = param_a;
  OCR0B = param_c;
  // Using D11 as a flag for generating the PWM signals on D9+D10
  digitalWrite(D11, HIGH);
  digitalWrite(D13, LOW);
}
```

title: 2 independent PWM signals with an ability to change frequency on Arduino UNO R3

Answers: 0


body:
I'm trying to extract numbers from a string sent via serial and then convert the numbers to integer values which I can use for arithmetic operations or toggle an Led. But the problem is I have to send the string twice before the module can receive it.

I am sending via serial monitor and bluetooth.

Example: if I first power the module and send voltage 100 via serial monitor, it will print voltage 0 instead of voltage 100.

But if I send voltage 100 again, then it will now print voltage 100 and the led will toggle.

Now If I decide to change the string and send voltage 50, it will still print voltage 100 instead of voltage 50.

If I send voltage 50 again, it will now print voltage 50.

So it seems to be printing the previous string for every new string sent to the serial.

So I had to send the same string twice for the device to receive it.

---

**How can I send the string once that the module will receive it and print on serial?** I don't want to be sending twice.

See my code and results below, any help would be appropriated.

Results of the code on the serial monitor with Autoscroll enabled:

When power is connected.
```
voltage: 0
voltage: 0
voltage: 0
voltage: 0
voltage: 0
```

When I sent "voltage 100".
```
voltage: 0
voltage: 0
voltage: 0
voltage: 0
voltage: 0
```

Then I sent "voltage 100" again.
```
voltage: 100
voltage: 100
voltage: 100
voltage: 100
```

Sent "voltage 50".
```
voltage: 100
voltage: 100
voltage: 100
voltage: 100
```

Sent "voltage 50" again.
```
voltage: 50
voltage: 50
voltage: 50
voltage: 50
```

Sent "voltage 120".
```
voltage: 50
voltage: 50
voltage: 50
voltage: 50
```

Sent "voltage 120" again.
```
voltage: 120
voltage: 120
voltage: 120
voltage: 120
```

This is my code:

```c++
int CD;
int maxvoltage = 100;
String readString, data;
const int Led = PB5;

void setup()
{
    Serial.begin(38400);
    pinMode(Led, OUTPUT);
}

void loop()
{
    if (Serial.available())
    {
        char c = Serial.read();  //gets one byte from serial buffer
        if (c == ' ')
        {
            Serial.println(readString); //prints string to serial port out

            if (readString.indexOf("voltage") >= 0)
            {
                data = readString.substring(0, 3); // extract numbers from the string
                CD = data.toInt(); // convert the extracted numbers to integers
                readString = ""; //clear variable for new input
                data = ""; // clear data
            }
        }
        else
        {
            readString = readString + c; //makes the string readString
        }
    }

    if (CD >= maxvoltage)
    {
        digitalWrite(Led, HIGH);
    }
    else
    {
        digitalWrite(Led, LOW);
    }
    Serial.print("voltage: ");
    Serial.println(CD);
    do_something(1000000); // do some delay
}

int do_something(int moment)
{
    volatile int i, j;

    for (i = 0; i < moment; ++i)
    {
        j++;
    }
}
```

title: Clear serial data for new incoming values

Answers: 2

body:
It is difficult to help with out knowing exactly what characters are being sent and why.  If we assume this is what is being sent:

    "voltage 24\n"
    "voltage 24\n"
    "voltage 55\n"
    "voltage 55\n"

Then we can speculate on how the code will react:

 1. The code will accept 7 new characters.
 2. The 8th character is a space (0x20) so the code will print out "voltage" (not mentioned in the question).
 3. This string is tested and found to be a match. Consequently the code will attempt to convert the characters "volta" (characters in position 0 through 4) into an integer.  This likely fails and the function likely returns zero. So the this is printed out "voltage: volta OK0" (the zero mentioned in the question, but the "volta" is not).
 4. The code will accept an unknown number of characters which were likely "20". But since there are likely no spaces (0x20) in the string, these are not processed as above.
 5. The process then repeats.

It is clear in the question the expected numbers are eventually printed.  So there is problem with the above. Either the assumed behavior is wrong or the received string is different then the expected.

If we assume this is what is being sent instead:

    "voltage 24 \n"
    "voltage 24 \n"
    "voltage 55 \n"
    "voltage 55 \n"

Then the expected output would change to:

    "voltage"
    "voltage: volta OK0"
    "24"
    "voltage: 24  OK24"
    "voltage"
    "voltage: volta OK0"
    "24"
    "voltage: 24 OK24"
    "voltage"
    "voltage: volta OK0"
    "55"
    "voltage: 55  OK55"
    "voltage"
    "voltage: volta OK0"
    "55"
    "voltage: 55 OK55"

While closer, this output still does not completely agree with how the question was worded.

So...

 - Edit your question to either make it clear what the program is printing out or copy and past the output of the program into the question. This answer can be adjusted if the question is edited.
 - Unlike human to computer communications, computer to computer communications is best kept short and with out spaces. Spaces are confusing to parse and often leads to coding problems. Better to use characters like ":" or "," to separate words and numbers.
 - It is assumed if the string, say, "voltage 24" is received it is not to be processed until it is received in its entirety. Consider ending the string with a, for example, ";".  Then testing for that character instead of for a space.  Also adjust your substring() parameters to pick off the number.  Likely passing 8 & 9 will result in the expected values.

body:
The error lays in your algorithm to collect the command. Your sketch uses the space character `' '` as the separator between incoming messages.

After the first transmission of "voltage 100", the resulting string in `readString` is `"voltage"`. The method `indexOf()` returns 0 as the index, because the keyword matches. Therefore, your sketch tries to parse an integer from the first characters of that string, which fails and returns zero. Therefore, the voltage is printed as "0".

With each next transmission, the following happens. For example, let's look at your second transmission, "voltage 100". The resulting string in `readString` is `"100\nvoltage"` or  `"100\r\nvoltage"`, depending on the end-of-line marker. It is composed of the remainder of the former transmission and the beginning of the current transmission. The method `indexOf()` returns a positive value greater than zero as the index. Therefore, your sketch tries to parse an integer from the first characters of that string, which succeeds this time and returns 100. But it is the value of the former transmission. Therefore, the voltage is now printed as "100".

The solution is to drop the space character as separator and instead use the end-of-line marker. Read the complete transmission into `readString`. Then check for the keyword and parse the later part. The actual implementation is left as an enlightening exercise.


body:
I am writing about the pictured ch3v003 development board for  use with the arduino IDE.

Regarding the standard EEPROM read and write functions described here at

https://docs.arduino.cc/learn/built-in-libraries/eeprom

my question is simply , does the Arduino
IDE support the standard EEPROM
read and write functions (used in an ino sketch) for this board? Reading the datasheet of the MCU of the board it does not have EEPROM like atmega328. The board is pictured-but I would think the answer applies to any board built around the same MCU.

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/MSmam.jpg

title: Arduino EEPROM support for ch3v003?

Answers: 0


body:
Have a nice day.

Experiment title:
PH Sensor calibration and Utilization.

Experiment description:
I am working on an experiment where I am interfacing the esp32 with [a DFRobot PH Sensor Kit V2][1]. This kit is developed for 3.3V devices.

They have provided the user manual how to connect, calibrate and use this PH sensor meter.

In the description they have mentioned that this sensor should be calibrated with a buffer solution to detect the proper PH value.

This is [the link][2] for the library. They have also mentioned the procedure to calibrate it. I have done it and it's working fine.

Now I want to automate this calibration process. Which means that I want to automate whatever serial command I am currently entering manually with sketch/function calls. I don't want to enter commands in the Serial Monitor.

Let's say, when I press a button first it should execute "enterph" then it should wait in a loop for 10 times then it should execute "calibrateph" then again it should wait in a loop for 10 times and at last it should execute the "exitph" command.

Can anyone guide me how to do this?

  [1]: https://www.dfrobot.com/product-1782.html
  [2]: https://github.com/DFRobot/DFRobot_PH

title: Automating Serial Monitor / Execute Serial Monitor Command without CMD input

Answers: 1

body:
You're going to have to write a piece of software on your computer with whatever is your favorite language, and run it, connected to the proper serial port. I do this a lot in applications that communicate with an IOT device connected to a USB port. It's not very difficult.

Even a simple Python script should do the trick.

**UPDATE** (following comment)

In which case, towards the end of `setup()`, you read in a while loop the pin where the button is connected. When it goes HIGH, you send the first command. Then you wait for whatever period you feel is appropriate, then send the next command, then rinse and repeat.


body:
I am using an ISR, which is written to be as minimal as possible:

``` c++
volatile bool interrupt1{};

void ISR1() {
    interrupt1 = true;
}
```
The interrupt is handled by polling the interrupt1 variable in ```loop()```:

```c++
if (interrupt1 == true) {

// Do stuff

interrupt1 = false;
}
```

Even though the interrupt signal coming in on the gpio isn't polled, the method described above is instead polling the interrupt variable from ```loop()```.

As an alternative to the above, is it possible to use some kind of push logic on the software side whenever an interrupt occurs, instead of continuously polling the interrupt variable? I hesitate to handle the full task from the ISR, as it's performing a lot of things.

What are my options here?

title: Alternative to polling interrupt flag from main loop?

Answers: 2

body:
If the task is pretty short and time sensitive, your best option is to
put it in the interrupt handler.

If the task is big and not too urgent (like: it could well wait for a
millisecond or so), your approach of polling the flag within `loop()` is
the best one, provided the main program is non-blocking.

If the task is both big and urgent... you may have a difficult problem.
You could try both approaches and see which one works best. Or you may
try to split the task into a top half (short and urgent) and a bottom
half (long but not so urgent). The interrupt handler would then perform
the top half and set a flag, whereas the main loop would poll the flag
and perform the bottom half.

**Edit**: for a short discussion on the top half / bottom half approach,
see the first paragraphs of [this article on Linux kernel
development][1].

[1]: https://litux.nl/mirror/kerneldevelopment/0672327201/ch07lev1sec1.html

body:
Since you tagged it Teensy: You could also reduce the priority of the interrupt, so that it can be interrupted by higher priority interrupts. Thus you can implement interrupts with longer durations without blocking important system functions.

Here is an example using the GPT1 and GPT2 timers running at different priorities:

```c++
#include "Arduino.h"
#include "TeensyTimerTool.h"

using namespace TeensyTimerTool;

PeriodicTimer loPrioTimer(GPT1);
PeriodicTimer hiPrioTimer(GPT2);

void onLowPrioTimer() // some long task running from interrupt with low prio
{
    Serial.printf("  Start low prio isr @t=%d ms\n", millis());

    for (int i = 0; i < 10; i++)
    {
        Serial.printf("    lowPriority task %d\n",i);
        delay(10);
    }

    Serial.println("  Stop low prio isr");
}

void onHiPrioTimer() // high prio, will interrupt the low prio isr
{
    Serial.printf("high priority @t=%d ms\n", millis());
}

void setup()
{
    while (!Serial) {}

    loPrioTimer.begin(onLowPrioTimer, 500ms); // GPT1
    hiPrioTimer.begin(onHiPrioTimer, 50ms);   // GPT2

    NVIC_SET_PRIORITY(IRQ_GPT1, 128); // lowest prio
    NVIC_SET_PRIORITY(IRQ_GPT2, 16);  // high prio
}

void loop()
{
}
```
which prints:
```
high priority @t=1057 ms
high priority @t=1107 ms
high priority @t=1157 ms
high priority @t=1207 ms
high priority @t=1257 ms
high priority @t=1307 ms
high priority @t=1357 ms
high priority @t=1407 ms
high priority @t=1457 ms
high priority @t=1507 ms
  Start low prio isr @t=1507 ms
    lowPriority task 0
    lowPriority task 1
    lowPriority task 2
    lowPriority task 3
    lowPriority task 4
high priority @t=1557 ms
    lowPriority task 5
    lowPriority task 6
    lowPriority task 7
    lowPriority task 8
    lowPriority task 9
high priority @t=1607 ms
  Stop low prio isr
high priority @t=1657 ms
high priority @t=1707 ms
high priority @t=1757 ms
high priority @t=1807 ms
high priority @t=1857 ms
high priority @t=1907 ms
high priority @t=1957 ms
high priority @t=2007 ms
  Start low prio isr @t=2007 ms
    lowPriority task 0
    lowPriority task 1
    lowPriority task 2
    lowPriority task 3
    lowPriority task 4
high priority @t=2057 ms
    lowPriority task 5
    lowPriority task 6
    lowPriority task 7
    lowPriority task 8
    lowPriority task 9
high priority @t=2107 ms
  Stop low prio isr
high priority @t=2157 ms
high priority @t=2207 ms
high priority @t=2257 ms
high priority @t=2307 ms
```

This shows that the high priority timer (running at 50 ms interval) intercepts the low priority ISR which runs every 500 ms for about 100 ms.


body:
I need some help with my code using mq-7 and esp8266.

Components I used:
MQ-7 (i've heated it up for 48hours)
ESP8266
4-channel relay
24vdc fan
mb102

All i wanna to do is mq-7 to constantly reading the co value, then the 4-channel relay will activate based on the ppm value to control the fan speed using different vinput on each relay channel.

I'm using the mq7.h library and here's my code for reference:

 ```
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <MQ7.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);
MQ7 mq7(A0,5.0);
const int relay1Pin = D6;
const int relay2Pin = D7;
const int relay3Pin = D8;
const float lambat_threshold = 10; //in ppm
const float med_threshold = 20; //in ppm
const float cepat_threshold = 30; //in ppm

void setup()
{
 Serial.begin(115200);
 pinMode(A0, INPUT);
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
digitalWrite(relay1Pin, LOW);
digitalWrite(relay2Pin, LOW);
digitalWrite(relay3Pin, LOW);
 lcd.begin();
 lcd.backlight();
 lcd.setCursor(00,00);
  lcd.print("Cooked Hood CO");
  lcd.setCursor(00,1);
  lcd.print("Istiyo Budi");
  delay(2000);
  lcd.clear();
}

void loop()
{
  float co = mq7.getPPM();
  lcd.setCursor(1, 0);
  lcd.print("CO: ");
  lcd.print(co);
  lcd.print(" PPM");
  delay(1000);
    Serial.print(co);
    Serial.println(" PPM");
    if (co < lambat_threshold) {
    digitalWrite(relay1Pin, HIGH);
    digitalWrite(relay2Pin, LOW);
    digitalWrite(relay3Pin, LOW);
    lcd.setCursor(1, 1);
    lcd.print("Speed: LOW");
  } else if (co >= med_threshold) {
    digitalWrite(relay1Pin, LOW);
    digitalWrite(relay2Pin, HIGH);
    digitalWrite(relay3Pin, LOW);
    lcd.setCursor(1, 1);
    lcd.print("Speed: MED");
  } else if (co >= cepat_threshold) {
    digitalWrite(relay1Pin, LOW);
    digitalWrite(relay2Pin, LOW);
    digitalWrite(relay3Pin, HIGH);
    lcd.setCursor(1, 1);
    lcd.print("Speed: HIGH");
    delay(2000);
}
}
 ```
Problem is, somehow when the value is around 30 or more, the relay won't switch. I'm stuck with this problem right now.

title: Relay switch when CO value is met

Answers: 2

body:
When `co >= cepat_threshold` it is also `> med_threshold`
Reverse the tests, starting with the highest value:

    if (co >= cepat_threshold) {
        digitalWrite(relay1Pin, LOW);
        digitalWrite(relay2Pin, LOW);
        digitalWrite(relay3Pin, HIGH);
        lcd.setCursor(1, 1);
        lcd.print("Speed: HIGH");
    } else if (co >= med_threshold) {
        digitalWrite(relay1Pin, LOW);
        digitalWrite(relay2Pin, HIGH);
        digitalWrite(relay3Pin, LOW);
        lcd.setCursor(1, 1);
        lcd.print("Speed: MED");
    } else {
        digitalWrite(relay1Pin, HIGH);
        digitalWrite(relay2Pin, LOW);
        digitalWrite(relay3Pin, LOW);
        lcd.setCursor(1, 1);
        lcd.print("Speed: LOW");
    }

body:
Look at the structure of your `if ... else` statements (your "decision tree"). Imagine what happens when your CO sensor returns a value of 30 (for example).

Your code first evaluates `if (co < lambat_threshold)`, which is not true because lambat_threshold is 10 and co is 30. It will skip to the `else` part of the first `if` statement.

It then evaluates `if (co >= med_threshold)`, which evaluates to true because med_threshold is 20 and 30 is greater than 20. It will then carry out the commands in that block of code (i.e. turn on relay 2 and turn off the other relays) and print "MED" on the display.

Your code will then *skip* the last part of your decision block (i.e. `else if (co > cepat_threshold)` ) because this piece of your code comes after the `else` part of an `if` statement that has already evaluated to true.

The easiest way to solve this is to swap the `if (co >= med_threshold)` and the `if (co >= cepat_threshold)` parts of your decision tree.


body:
With Arduino IDE v2.2.1, I've connected Arduino UNO board and it automatically tries download the avr board - however it repeatedly throws errors while downloading the boards.

As the PC that I'm trying to connect with, is an office workdesk, and has proxy / VPN configured. So, I believe the IDE is not able to reach the proxy server. I tried to configure the proxy settings manually, however I'm not able to find the Proxy settings in my Windows machine.

1. First the Arduino IDE is run with "No Proxy" settings under  `File -> Preference -> Network` check on No Proxy option, and I get the below error:

     ```Failed to install platform: 'Arduino AVR Boards:1.8.6'. 2 UNKNOWN: read tcp <X.X.X.X>:62430-> <X.X.X.X>:80: wsarecv: An existing connection was forcibly closed by the remote host.```

2. With Manual proxy configuration set under `File -> Preference -> Network -> Manual Proxy Configuration` - here I've left the `Host name`, `Port Number`, `Username`, `Password` as BLANK. It returns the below errors:

```error
Some indexes could not be updated. Get "https://downloads.arduino.cc/libraries/library_index.tar.bz2":
proxyconnect tcp: dial tcp: lookup _: no such host: https://downloads.arduino.cc/libraries/library_index.tar.bz2
Get "https://downloads.arduino.cc/packages/package_index.tar.bz2":proxyconnect tcp:
dial tcp: lookup _: no such host: https://downloads.arduino.cc/packages/package_index.tar.bz2

Could not install Arduino AVR platform: Error: 2 UNKNOWN:
Get "http://downloads.arduino.cc/tools/avrdude-6.3.0-arduino17-i686-w64-mingw32.zip":
proxyconnect tcp: dial tcp: lookup _: no such host
```

 I've tried different forums to find a resolution around this error, but none of the answers helped to find a fix for this issue.

title: Error downloading arduino:avr:1.8.6 in Arduino IDE with Network Proxy

Answers: 0


body:
I'm trying to make a onetime URL with a random string to for example give a user onetime access to a house with a smart lock. I have a function to make a fixed 8-character string and the following code with the address that is randomly made.

```c++
  controlserver.on(userurl, HTTP_GET, [](AsyncWebServerRequest *request){
   if(urlactive==true){
   if(request->authenticate("admin","admin")){
      running=true;
      request->send(200);

      Serial.println("entered");
      urlactive=false;
      }else {
       return request->requestAuthentication();
      }
   }else{
       generateRandomString();
       request->send(200, "text/html", HTML_CSS_STYLING+ "<body>"
    "<br><h1 style=\"color:white; direction: rtl;\">LInk is not valid!</h1></body>" );

   }
  });
```
the following function generates the `userurl` which is a `const char*` because the requirement of ESPAsyncWebServer library.

```cpp
void generateRandomString() {
  const char specialChars[] = "0123456789";
  const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  String randomStringurl = "";
  String keppmyuserpass = "";
  randomStringurl += letters[random(26, 51)];
  for (int i = 0; i < 6; i++) {
    randomStringurl += letters[random(0, 51)];
  }
  randomStringurl += specialChars[random(0, 9)];
  Serial.println(randomStringurl);
  userurl = randomStringurl.c_str();

}
```
everything works fine when I enter the generated string that I convert into `const char*` using `c_str()` but I noticed an error when I copied the string partially by accident and too much to my surprise, I saw that the popup for the username and password showed up and I didn't expecte it, because I have a `notFound` function that will show an error when the entered URL doesn't exist. entered different strings but the problem is persistent. I think there is a problem with my string conversion to `const char*` using `c_str()`. but is it?

Here is compliable code, the wifi mode is STA ```WiFi.mode(WIFI_STA);``` :
```cpp
#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>

const char* userurl;
String  randomStringurl = "";
String  keppmyuserpass = "";

AsyncWebServer server(80);

const char* ssid = "your_ssid";
const char* password = "your_password";

const char* PARAM_MESSAGE = "message";

void notFound(AsyncWebServerRequest *request) {
    request->send(404, "text/plain", "Not found");
}
void generateRandomString() {
  const char specialChars[] = "0123456789";
  const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  randomStringurl = "";
  keppmyuserpass = "";
  randomStringurl += letters[random(26, 51)];
  for (int i = 0; i < 6; i++) {
    randomStringurl += letters[random(0, 51)];
  }
  randomStringurl += specialChars[random(0, 9)];
  Serial.println(randomStringurl);
  userurl = randomStringurl.c_str();
  keppmyuserpass = randomStringurl;
  keppmyuserpass += letters[random(26, 51)];
  keppmyuserpass += specialChars[random(0, 9)];
  Serial.println(keppmyuserpass);

}
void setup() {

    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        Serial.printf("WiFi Failed!\n");
        return;
    }

    Serial.print("IP Address: ");
    Serial.println(WiFi.localIP());

    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Hello, world");
    });

    // Send a GET request to <IP>/get?message=<message>
    server.on(userurl, HTTP_GET, [] (AsyncWebServerRequest *request) {
        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        } else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, GET: " + message);
    });

    // Send a POST request to <IP>/post with a form field message set to <message>
    server.on("/post", HTTP_POST, [](AsyncWebServerRequest *request){
        String message;
        if (request->hasParam(PARAM_MESSAGE, true)) {
            message = request->getParam(PARAM_MESSAGE, true)->value();
        } else {
            message = "No message sent";
        }
        request->send(200, "text/plain", "Hello, POST: " + message);
    });

    server.onNotFound(notFound);

    server.begin();
    generateRandomString();
}

void loop() {
}
```
And here is the code from ESPAsyncWebServer.h library, that required the ```url``` to be a  ```const char* uri``` what am I doing wrong?
```cpp
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody);
```
New Update: So, I forgot to add a ```"/"``` before the URL, by doing so it solved the problem and here is the new function:
```cpp
void generateRandomString() {
  const char specialChars[] = "0123456789";
  const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  randomStringurl = "";
  keppmyuserpass = "";
  randomStringurl +="/";
  randomStringurl += letters[random(26, 51)];
  for (int i = 0; i < 6; i++) {
    randomStringurl += letters[random(0, 51)];
  }
  randomStringurl += specialChars[random(0, 9)];
  Serial.println(randomStringurl);
  userurl = randomStringurl.c_str();
  keppmyuserpass = randomStringurl;
  keppmyuserpass += letters[random(26, 51)];
  keppmyuserpass += specialChars[random(0, 9)];
  OTUPC = keppmyuserpass.c_str();
  Serial.println(keppmyuserpass);

}
```
But when I renew the link, the new link is not recognized and the first generated link was working. I think that @6v6gt might be right about this: "Could it also be that the value of ```userurl``` must be known when ```setup()``` runs and the callback is registered?"

title: How to properly declare a random URL in ESPAsyncWebServer?

Answers: 1

body:
6v6gt is right, that the URI for the handler must be known, when you use the `on()` function to set the handler. Inside the library, the `on()` function calls `setUri(const String& uri)`, which which saves the `uri` in the classes interal `String` member variable. Thus the handle will not notice, if the originally used variable changes.

I think the most elegant solution here would to be to use a regular expression for your handler URI (A regular expression is a string expression, that describes a template that can match other strings). That will let the handler match any URI, that fits that regex. Inside the handler you can then get the relevant part of the URI and check, if it is currently valid. If yes, you serve your content, otherwise you serve an error (for example a 404 Not Found).

The third answer to [this question][1] has a code snippet for this:

    #include <uri/UriRegex.h>

    web_server.on(UriRegex("/home/([0-9]+)/first"), HTTP_GET, [&]() {
        web_server.send(200, "text/plain", "Hello from first! URL arg: " + web_server.pathArg(0));
    });

The part of the URI, that's between the brackets, is the regex group, that is then made available via `web_server.pathArg(0)`. Your current code creates a string with one capital letter, 6 lower case letters and one digit, thus a regex group `([A-Z][a-z]{6}[0-9])`. You can read about how regex work online.

When you look at [this repo][2] of ESPAsyncWebServer (I'm not sure, which version you have), in the Readme right at the end under "path variable" you find this snippet:

    server.on("^\\/sensor\\/([0-9]+)$", HTTP_GET, [] (AsyncWebServerRequest *request) {
      String sensorId = request->pathArg(0);
    });

And a note, that regex support must be enabled.

As I didn't test this, I suggest you try both methods and see, what works for you.

  [1]: https://stackoverflow.com/questions/35816454/setting-a-wildcard-in-esp8266webserver
  [2]: https://github.com/me-no-dev/ESPAsyncWebServer#the-async-web-server


body:
I finished my first PCB design and overlooked an important aspect in regards to connecting VBUS and UVCC to the correct nodes. Instead I wired these up directly to VCC.

Additionally, I incorrectly spec'd the Linear regulator for USB power, so it has been removed completely and the board is powered via the ISP programmer.

When attempting to connect the device via USB, no connection is established and dmesg reports the following:

```
[153286.347767] usb 1-4: new full-speed USB device number 33 using xhci_hcd
[153286.347898] usb 1-4: Device not responding to setup address.
[153286.554614] usb 1-4: Device not responding to setup address.
[153286.761078] usb 1-4: device not accepting address 33, error -71
[153286.884410] usb 1-4: new full-speed USB device number 34 using xhci_hcd
[153286.884534] usb 1-4: Device not responding to setup address.
[153287.091353] usb 1-4: Device not responding to setup address.
[153287.297830] usb 1-4: device not accepting address 34, error -71
[153287.297974] usb usb1-port4: unable to enumerate USB device
```

According to the datasheet, VBUS is used as an interrupt to enable USB.

Is it possible to artificially trigger this interrupt via software to bypass this mistake until the next PCB revision?

The board is currently programmable, I have a blink sketch running. Unfortunately, one of the main features is a serial shell over usb, and serial1 being used externally. I can work around this but it'd be useful if I could get USB working on this prototype.

EDIT: I resolved to bodge it by lifting up the two pins and wiring them correctly. It immediately worked.
[![Abandon hope if you see this, grab some enamel wire][1]][1]

  [1]: https://i.stack.imgur.com/qBwtd.jpg

title: Atmega32u4 USB connectivity with incorrect wiring

Answers: 0


body:
I'm making a program to show numbers in a WS2812 LED and TM1637. I'm also using a common 4x4 keypad.

The WS2812 LED is just DIY with 25 x 10. Only two values can be displayed in a LED matrix just now. Without the LED part of the program, just the TM1637 and keypad connected to the Arduino, everything is fine. But adding the LED part of the program, I found out that entering 2 on keypad puts  an erroneous value in my variable (-256 to exact). I tried debugging my code and found out that replacing the last iteration

`for (int i = 225; i <= 231; i++) {`

with this line

`for (int i = 225; i <= 230; i++) {`

mysteriously solved my problem. Any thoughts why this is happening?

```
#include <Keypad.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <Wire.h>
#include <FastLED.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
#define NUM_LEDS  225
#define LED_PIN   12
CRGB leds[NUM_LEDS];
TM1637Display display(CLK, DIO);
int DisplayNos=0;
int KeyNum;
char key;
boolean NewKey = false;
boolean DeleteAll=false;
int SavedNum;
// for 3 digits
int ExtractDigit[3] = {0, 0, 0};
byte DigitPoint= 1;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
  Serial.begin(9600);
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(250);
}
void loop(){
int k;
//  uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
//  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display.setBrightness(0x0f);
  key = keypad.getKey();// Read the key
  // Print if key pressed
  if (key){
    Serial.print("Key Pressed : ");
    Serial.println(key);
    if (isDigit(key)){
      KeyNum = key-48;
      Serial.println(key);
      Serial.println(DisplayNos);
      if (DigitPoint==1){
        DisplayNos = 0;
        DisplayNos = KeyNum;
      }
      if (DigitPoint==2){
        DisplayNos = KeyNum + (DisplayNos*10);
      }
      if (DigitPoint==3){
        DisplayNos = KeyNum + (DisplayNos*10);
      }
      DigitPoint= DigitPoint+1;
      if (DigitPoint==4){
        DigitPoint=1;
      }
    }
      if (key=='*'){   // asterist key cancels all char
      DisplayNos = 0;
      DigitPoint = 1;
    }
    if (key=='#'){   // asterisk key cancels all chars

    }
    NewKey = true;
  }
  display.showNumberDec(DisplayNos,false,3,0);
  if (NewKey == true){
    DisplayLED();
    FastLED.show();
  }
}
void DisplayLED(){
int LedNum;
byte digitnos;
NewKey = false;
  ExtractDigit[3] = (DisplayNos/100);
  ExtractDigit[2] = (DisplayNos/10);
  ExtractDigit[1] = (DisplayNos);
  for (int digitnos= 1; digitnos <= 3; digitnos++) {
    LedNum = (digitnos-1)*9;
    if (ExtractDigit[digitnos] == 1){
      leds[21-LedNum]= CRGB::Blue;
      leds[28+LedNum]= CRGB::Blue;
      leds[29+LedNum]= CRGB::Blue;
      leds[71-LedNum]= CRGB::Blue;
      leds[78+LedNum]= CRGB::Blue;
      leds[121-LedNum]= CRGB::Blue;
      leds[128+LedNum]= CRGB::Blue;
      leds[171-LedNum]= CRGB::Blue;
      leds[178+LedNum]= CRGB::Blue;
      leds[221-LedNum]= CRGB::Blue;
      leds[229+LedNum]= CRGB::Blue;
      leds[228+LedNum]= CRGB::Blue;
      leds[227+LedNum]= CRGB::Blue;
    }
    if (ExtractDigit[digitnos] == 2){
      for (int i = 20; i <= 22; i++) {
        leds[i-LedNum] = CRGB::Blue;
      }
      leds[26+LedNum]= CRGB::Blue;
      leds[30+LedNum]= CRGB::Blue;
      leds[68-LedNum]= CRGB::Blue;
      leds[74-LedNum]= CRGB::Blue;
      leds[76+LedNum]= CRGB::Blue;
      leds[122-LedNum]= CRGB::Blue;
      leds[128+LedNum]= CRGB::Blue;
      leds[170-LedNum]= CRGB::Blue;
      leds[180+LedNum]= CRGB::Blue;
      leds[218-LedNum]= CRGB::Blue;
      leds[225+LedNum]= CRGB::Blue;
      leds[226+LedNum]= CRGB::Blue;
      leds[227+LedNum]= CRGB::Blue;
      leds[228+LedNum]= CRGB::Blue;
      leds[229+LedNum]= CRGB::Blue;
      for (int i = 225; i <= 231; i++) {
        leds[i-LedNum] = CRGB::Blue;
      }
    }
  }
  }
```

title: Why is my variable giving the wrong value?

Answers: 1

body:
    #define NUM_LEDS  225
    ...
    CRGB leds[NUM_LEDS];
    ...
      leds[225 + LedNum] = CRGB::Blue;
      leds[226 + LedNum] = CRGB::Blue;
      leds[227 + LedNum] = CRGB::Blue;
      leds[228 + LedNum] = CRGB::Blue;
      leds[229 + LedNum] = CRGB::Blue;

Your RGB matrix has 225 LEDs, but you're writing to RAM out of range and destroying their stored data and/or variables.


body:
My CircuitPlaygroundExpress using [Adafruit's CircuitPlayground library](https://github.com/adafruit/Adafruit_CircuitPlayground) reports a temperature that is roughly 9ºF higher than ambient temperature.

### Details

The code I'm using:

    #include <Adafruit_CircuitPlayground.h>

    void setup() {
      CircuitPlayground.begin();
      Serial.begin(9600);
      Serial.println("Temperature Logger");
    }

    void loop() {
      float temperatureC = CircuitPlayground.temperatureF();
      // Log temperature to the serial console
      Serial.print("Temperature: ");
      Serial.print(temperatureF);
      Serial.println(" °F");

      delay(1000);  // Update every second
    }

I'm seeing results around 78–80ºF, but the room I'm in is below 71ºF according to my thermostat.

### Question

Should I just chalk this up to temperature differences between the air around me and the air around the thermistor on the PCB?

Are there known issues with the coefficients used in Adafruit's library? Something else I haven't though of?

title: Why does my CircuitPlaygroundExpress temperature reading seem high?

Answers: 0


body: While I was using a L293D motor shield on my UNO, the negative wire of my total 7.4v was connected in the motor shield. But mistakenly the positive wire got connected in the UNO and the lights turned on(I don't know if it was a problem or not). Now when I connect the UNO with laptop the IDE says not connected and did not detect the UNO. On the UNO all the lights are on. Can anyone tell me whats the problem?

title: Arduino IDE is still saying not connected even after I connected it

Answers: 1

body:
The grounds are shared on the motor shield and the Arduino.

If your 7.4v wire was connected to Vin, you should be fine, but if the wire was connected to your Arduino 5v supply rail, it now has 7.4v on it and your Arduino is likely dead.


body: When tested in 3D space, all the values(Y, P, R) change even though the motion is only in a single direction. Is there any other better algorithm or library that can be used to tackle this, apart from the DMP?

title: The Y, P, R (Yaw Pitch Roll) values obtained by DMP (Digital Motion Processor) are not getting stabilized,

Answers: 1

body:
Are you calibrating the gyro and accelerometer?
```
mpu.CalibrateAccel(6);
mpu.CalibrateGyro(6);
```

Check the official Arduino github for examples.
https://github.com/ElectronicCats/mpu6050/blob/master/examples/MPU6050_DMP6/MPU6050_DMP6.ino


body:
I'm not quite new to the Arduino, I did some projects and some of which was using hx711 and load cells, they used to work in the past.

However, I tried it today, and it shows this error
*HX711.h: No such file or directory*, on the line:

'''#include <HX711.h>'''

however, I am sure that the library is installed in *C:\Users\zeyad\OneDrive\documents\Arduino\libraries*. I tried to downgrade from IDE 1.8 to IDE 1.6.11 and it didn't work. This error also shows when I am using TMRpcm library, although both TMRpcm and HX711 are both installed, found in sketch/include library, and I tried several versions with each one! I also tried using quotation marks "" instead of <>, didn't work also.

The capitalization is also correct! This leaves me clueless of what to do, and I am thinking of removing all the folders (except for the sketch ones) and re-installing the ide

title: HX711.h: No such file or directory although every thing is installed correctly!

Answers: 0


body:
I'm trying to include the thing...
```cpp
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

BLEServer* pServer = NULL;

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

}

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

}
```

But it simply doesn't see what's inside the .h files:

```
C:\Users\void\AppData\Local\Temp\.arduinoIDE-unsaved20231028-7016-1na7gr9.y1do\sketch_nov28b\sketch_nov28b.ino:6:1: error: 'BLEServer' does not name a type; did you mean 'Server'?
 BLEServer* pServer = NULL;                        // Pointer to the server
 ^~~~~~~~~
 Server
```

May it be, I bought the wrong board? I've set it as lolin s2 mini.

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/ws3LW.jpg

title: Some of my <include> statements do not work

Answers: 1

body:
Many of the [ESP32 variants][1] have Bluetooth/BLE support. The ESP32-S2 board/module you're trying to use does not. [The module](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) has WiFi, but not Bluetooth.

[![Crop from original board image showing S2 markings highlighted.][2]][2]

So you need another board, Lolin seems to have an -S3 version of your board. But many other boards would work.

The majority of the `<BLEServer.h>` header's contents are [conditionally compiled based on whether or not](https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/BLE/src/BLEServer.h#L11) `CONFIG_BLUEDROID_ENABLED` is `#define`d.

And this only done for modules that have support for Bluetooth. The Lolin S3 version of the Mini would have Bluetooth support and in the configuration file it would use you can [see it defined](https://github.com/espressif/arduino-esp32/blob/2.0.14/tools/sdk/esp32s3/qio_qspi/include/sdkconfig.h#L178). In the one for the S2 board you are trying to use [it is missing](https://github.com/espressif/arduino-esp32/blob/2.0.14/tools/sdk/esp32s2/qio_qspi/include/sdkconfig.h#L17-L18).

In effect, although you're including the header, it is as though it were blank. So no definition of the `BLEServer` type. It would have been nice if they'd handled this a different way, but this is not uncommon.

  [1]: https://en.wikipedia.org/wiki/ESP32#ESP32-xx_family
  [2]: https://i.stack.imgur.com/X4d42.jpg


body:
I have two ESP32 cards. I want to set one of these cards as Master and the other as Slave and communicate via SPI. I have done this before on Arduino Uno, but I cannot do this on ESP32.
Below are my Master and Slave codes that I have prepared simply. I can't get what I want in any way. Can anyone help?

**Master Code:**
```cpp
#include <SPI.h>

#define CS_PIN 5  // Choose the appropriate pin for Chip Select (CS)

void setup() {
  Serial.begin(115200);
  SPI.begin();
}

void loop() {
  char dataToSend = 'A';

  digitalWrite(CS_PIN, LOW); // Start communication with the slave
  SPI.transfer(dataToSend); // Send data to the slave
  digitalWrite(CS_PIN, HIGH); // End communication with the slave

  delay(2000); // Delay for demonstration purposes
}
```

**Slave Code:**
```cpp
#include <SPI.h>

#define CS_PIN 5  // Choose the appropriate pin for Chip Select (CS)

void setup() {
  Serial.begin(115200);
  SPI.begin();
}

void loop() {
  if (digitalRead(CS_PIN) == LOW) {  // Check if CS (Chip Select) is LOW, meaning the device is selected
    char receivedData = SPI.transfer(0); // Read received data from the master

    // Display received data on the serial monitor
    Serial.println("Received Data: " + String(receivedData));

    delay(1000);  // Optional delay for demonstration purposes
  }
}

```

***New Code - New Problem:***

I tried to adapt the codes at https://microcontrollerslab.com/esp32-spi-communication-tutorial-arduino/. From what I understand it uses the following pins for SPI: MISO-12; MOSI-13; SCLK-14; SS-15.
I set my connections the same way, but I cannot get the output I expected from the Slave. It remains waiting at the slave.wait line.

**Master Code:**

```cpp
#include <SPI.h>

// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus

  #define HSPI_MISO   MISO
  #define HSPI_MOSI   MOSI
  #define HSPI_SCLK   SCK
  #define HSPI_SS     SS

static const int spiClk = 1000000; // 1 MHz

//uninitalised pointers to SPI objects
SPIClass * hspi = NULL;

void setup() {
  //initialise instance of the SPIClass attached to HSPI
  hspi = new SPIClass(HSPI);

  //initialise hspi with default pins
  //SCLK = 14, MISO = 12, MOSI = 13, SS = 15
  hspi->begin();

  pinMode(HSPI_SS, OUTPUT); //HSPI SS
}

// the loop function runs over and over again until power down or reset
void loop() {
  hspi_send_command();
  delay(100);
}

void hspi_send_command() {
  byte data_on = 0b00000001; // data 1 to turn on LED of slave
  byte data_off = 0b0000000; // data 0 to turn off LED of slave

  hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(HSPI_SS, LOW);
  hspi->transfer(data_on);
  digitalWrite(HSPI_SS, HIGH);
  hspi->endTransaction();

  delay(1000);

  hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(HSPI_SS, LOW);
  hspi->transfer(data_off);
  digitalWrite(HSPI_SS, HIGH);
  hspi->endTransaction();
  delay(1000);

}
*/
```

**Slave Code:**

```cpp
#include <ESP32SPISlave.h>

ESP32SPISlave slave;

static constexpr uint32_t BUFFER_SIZE {32};
uint8_t spi_slave_tx_buf[BUFFER_SIZE];
uint8_t spi_slave_rx_buf[BUFFER_SIZE];

#define LED 2

void setup() {
    Serial.begin(115200);
    delay(2000);
    pinMode(LED, OUTPUT);
    // begin() after setting
    // HSPI = CS: 15, CLK: 14, MOSI: 13, MISO: 12 -> default
    // VSPI = CS:  5, CLK: 18, MOSI: 23, MISO: 190
    slave.setDataMode(SPI_MODE0);
    slave.begin();
    // slave.begin(VSPI);   // you can use VSPI like this

    // clear buffers
    memset(spi_slave_tx_buf, 0, BUFFER_SIZE);
    memset(spi_slave_rx_buf, 0, BUFFER_SIZE);
}

void loop() {
    // block until the transaction comes from master
    Serial.println("Initialize...");

    slave.wait(spi_slave_rx_buf, spi_slave_tx_buf, BUFFER_SIZE);

    Serial.println("*********************");

    // if transaction has completed from master,
    // available() returns size of results of transaction,
    // and buffer is automatically updated
    char data;
    while (slave.available()) {
        // show received data
         Serial.print("Command Received: ");
         Serial.println(spi_slave_rx_buf[0]);
         data = spi_slave_rx_buf[0];
         slave.pop();
    }
    if(data == 1 )
    {
        Serial.println("Setting LED active HIGH ");
        digitalWrite(LED, HIGH);
    }
    else if(data == 0 )
    {
        Serial.println("Setting LED active LOW ");
        digitalWrite(LED, LOW);
    }
}
```

title: ESP32 SPI Mutual Communication

Answers: 1

body:
For ESP32, unless the exact board variant is specified, by default the macros for `MISO`, `MOSI`, `SCK` and `SS` are defined as follows and are used for VSPI(i.e. SPI0):
```cpp
static const uint8_t SS    = 5;
static const uint8_t MOSI  = 23;
static const uint8_t MISO  = 19;
static const uint8_t SCK   = 18;
```

This can be seen in the [source code](https://github.com/espressif/arduino-esp32/blob/master/variants/esp32/pins_arduino.h#L12C1-L15C33) and HSPI is automatically configured to use SCLK 14, MISO 12, MOSI 13 and SS 15 when `SPI.begin()` is called, see this part of the [source code](https://github.com/espressif/arduino-esp32/blob/master/libraries/SPI/src/SPI.cpp#L100-L103).

Since you defined `HSPI_SS` as `#define HSPI_SS SS`, when you do `pinMode(HSPI_SS, OUTPUT);`, you are actually setting pin 5 as output, not the pin 15 that you thought it was.

There are two ways to properly set up the HSPI port.
1. What you can do is to define the macros as follows and call `hspi->begin();` by passing your configuration:
```cpp
#define HSPI_MISO   12
#define HSPI_MOSI   13
#define HSPI_SCLK   14
#define HSPI_SS     15

void setup() {
  hspi = new SPIClass(HSPI);
  hspi->begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
  // rest of your setup code
}
```
2. As you can see from the source code shown in the above link, if you don't explicitly pass the pins as parameters when calling `SPI.begin()`, the library will automatically assign the pins based on whether VSPI is used (SCLK 18, MISO 19, MOSI 23, SS 5), or HSPI is used (SCLK 14, MISO 12, MOSI 13 and SS 15). So all you need to define is your `HSPI_SS` pin:

```cpp
#define HSPI_SS     15

void setup() {
  hspi = new SPIClass(HSPI);
  hspi->begin();
  // rest of your setup code
}
```


body:
I connected the 12v power supply with 9v battery. The problem is that when i run 1 motor at time from any side (out 1, 2 out 3, 4) it works perfectly, but when I try to run both of them, only one will run and the other won't. They work if I run one motor at a time.

Is this a problem with not enough power? The motors are DC gear motors. This is the code:
```cpp
int in1 = 12;
int in2 = 13;
int in3 = 8;
int in4 = 9;
int en1 = 11;
int en2 = 10;
void setup() {
   pinMode(in3, OUTPUT);
   pinMode(in4, OUTPUT);
   pinMode(en1, OUTPUT);
   pinMode(in1, OUTPUT);
   pinMode(in2, OUTPUT);
   pinMode(en2, OUTPUT);
}

void loop() {
   analogWrite(en1, 255);
   digitalWrite(in1, LOW);
   digitalWrite(in2, HIGH);
   analogWrite(en2, 255);
   digitalWrite(in3, LOW);
   digitalWrite(in4, HIGH);
}
```

title: L298n driver with Arduino with 2 motors won't work

Answers: 1

body:
Yes, most likely. Motors can draw a lot of power and your 9v battery is probably struggling to output enough voltage. 50-100 mA is about the max current you want to draw from a 9v. 9v batteries have a high internal resistance and the voltage will drop *potentially* well below 9v when you draw a lot of current from them. Used to make Altoids tin USB chargers back in the day with a 9v but cellphones now need multiple Amps of power and so do motors.

Here's a couple things you can do to check:

Set up your code to run both motors. Connect a motor to one side and see if it works. Then connect it to the other side (without changing the program or other wiring.) If that motor runs on both sides, check the other motor. This will make sure both motors are good and that both channels on the driver are good. Check the voltage on the battery and the motor and write down the values each time.
If the current you measure with a single motor is much higher than 25-50 mA, 2 motors will exceed the limit. Note the motor (label them) and the channel it is connected to.

If that seems to check out, connect both motors. We know they don't both spin, but take this time and measure battery voltage and motor voltage. Measure the current if possible too. If you are getting greater than 50-100mA from the battery, you are likely going to have issues.