body:
Hi I have some code that I'm trying to port from a Mega 2560 R3 to a Wemos Mega.

    #include "SoftPWM.h"
    #include ESP8266WiFi.h

    // Outputs to PWM & H bridge direction
    // PWMs:
    // DC_pwm, left_pwm, right_pwm = 3, 4, 5
    int pwm_out[] = {3, 4, 5};
    const int num_pwm = sizeof(pwm_out) / sizeof(pwm_out[0]);

    // H bridge direction control:
    // dc_1, dc_2, left_1, left_2, right_1, right_2 = 6, 7, 8, 9, 10, 11
    int dir_pins[] = {6, 7, 8, 9, 10, 11};
    const int num_dir_pins = sizeof(dir_pins) / sizeof(dir_pins[0]);

    // Variable for reading pin inputs
    int from_r_pi_pwm = 0;
    int from_r_pi_dir = 0;

    void setup() {

      // Inputs from Raspberry Pi
      Serial.begin(38400);

      // Set up PWM pins
      SoftPWMBegin();
      for (int i = 0; i < num_pwm; i++)
      {
        SoftPWMSet(pwm_out[i], 0);
      }

      // Set up H bridge direction pins
      for (int i = 0; i < num_dir_pins; i++)
      {
        pinMode(dir_pins[i], OUTPUT);
        digitalWrite(dir_pins[i], LOW);
      }
    }

    void loop() {

      // Check input from R Pi & send it to the H bridges
      while (Serial.available() < 2){}

      if (Serial.available()) {
          // read the incoming bytes:
          from_r_pi_dir = Serial.read();
          from_r_pi_pwm = Serial.read();
          Serial.print("Serial in: directions - ");
          Serial.print(from_r_pi_dir);
          Serial.print(" PWM - ");
          Serial.print(from_r_pi_pwm);
          Serial.println();
      }

      // Set direcions on H bridges
      for (int i = 0; i < num_dir_pins; i++)
      {
        digitalWrite(dir_pins[i], bitRead(from_r_pi_dir, i));
        Serial.print("pin ");
        Serial.print(dir_pins[i]);
        Serial.print(" : ");
        Serial.print(digitalRead(dir_pins[i]));
        Serial.println();
      }

      // PWM to motors
      for (int i = 0; i < num_pwm; i++)
      {
        analogWrite(pwm_out[i], from_r_pi_pwm);
        Serial.print("pin ");
        Serial.print(pwm_out[i]);
        Serial.print(" : ");
        Serial.print(digitalRead(pwm_out[i]));
        Serial.println();
      }
    }

This compiles and runs fine on a Mega & is my go to code for setting up pwm & h bridges.

So when I was playing with WiFi I selected the Wemos R1 board from the programmer & everything worked fine but if I try that with this code I get,

    #include <avr/io.h>
                        ^
    compilation terminated.

    exit status 1 Error compiling for board WeMos D1 R1.

So after a bit of searching I found that I should be selecting `Arduino/Genuino Mega 2560` but now the upload keeps timing out,

    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_getsync(): timeout communicating with programmer
    An error occurred while uploading the sketch

Anybody come across this before?

**Edit #1:**  As per the comment below I tried setting DIP switches 1 & 2 ON and all the rest OFF (I also tried 1, 2, 3 & 4 ON and the rest OFF) but still the same compliation error if I select Wemos board.

If I select the Mega 2560 I get `ESP8266WiFi.h: No such file or directory` which is a new error!

title: Mega code not compiling on Wemos Mega board

Answers: 1

body:
The Wemos/Mega board and IDE setup is complex and not for the faint hearted. Here is the table for the DIP switch setting:

    1=ON  2=ON  3=OFF 4=OFF 5=OFF 6=OFF 7=OFF 8=OFF (ATmega2560<->ESP8266)
    1=OFF 2=OFF 3=ON  4=ON  5=OFF 6=OFF 7=OFF 8=OFF (USB <->ATmega2560)
    1=OFF 2=OFF 3=OFF 4=OFF 5=ON  6=ON  7=ON  8=OFF (USB<->ESP8266 (Update firmware or sketch))
    1=OFF 2=OFF 3=OFF 4=OFF 5=ON  6=ON  7=OFF 8=OFF (USB<->ESP8266 (communication))
    1=OFF 2=OFF 3=OFF 4=OFF 5=OFF 6=OFF 7=OFF 8=OFF (All independent)

Table DIP switch Special Solution:

    1=ON 2=ON 3=ON 4=ON 5=OFF 6=OFF 7=OFF 8=OFF (USB <-> ATmega2560<-> ESP8266)
    USB converter CH340G connect to RX0/TX0 of ATmega2560
    ESP8266 connect to RX3/TX3 of ATmega25

https://arduino-esp8266.readthedocs.io/en/latest/index.html for ESP8266 documentation.

Set the Additional Boards URL to http://arduino.esp8266.com/stable/package_esp8266com_index.json in preferences

Under Tools select Board then Board Manager, then install the esp8266 by ESP8266 Community

The Arduino IDE setup requires understanding what board setting and communication setting to use to build and upload a sketch.

Under Tools select Board then select the "Arduino/Genuino Mega or Mega 2560"

Set the DIP switches on the actual board to `1=OFF 2=OFF 3=ON 4=ON 5=OFF 6=OFF 7=OFF 8=OFF (USB <->ATmega2560)`

That was the DIP switch and USB setup.

Ref. https://forum.arduino.cc/index.php?topic=578430.0

The error `ESP8266WiFi.h: No such file or directory` is easy. The file name should be a string: `#include "ESP8266WiFi.h"`.


body:
I followed [this][1] tutorial for a demo code for the SR04 ultrasonic distance sensor (without the LCD display). I've installed the Arduino IDE and wrote the code in it and saved it in some location. Compilation of the code is successful. However when I try to upload the code, I get the message:

    Invalid library found in C:\Users\Dame\Documents\Arduino\libraries\arduino_144469: no headers files (.h) found in C:\Users\Dame\Documents\Arduino\libraries\arduino_144469

There are no header files in the directory and I'm wondering if I need to download additional header files or if I should configure something else.

  [1]: https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/

title: No headers (.h) found in Documents\Arduino\libraries\arduino_144469 with demo code

Answers: 2

body:
If the folder is not needed then delete it.

The Arduino IDE uses the folders in the `library` folder to search for library header files (ie. `.h` files). It expects one library in each folder. When it see's a folder without any header files in it, it will count this as an invalid library.

body:
i had similar problem and I Fix it by changing in preferences field Sketchbook location to different drive (from c:\ to d:\).

This problem can ocure on system windows 10 (probably also 8) where you have sequred drive with system installed to protect you data (or system files) against some unwanted changes. Probably there is missing in Arduino some rights to make directory and save files in temporary directories, but i'm not an expert.


body: I'm going to create an IoT system. I use a Raspberry Pi as a MQTT broker and as a webserver. Every day, the Pi gets a new IP address, so I need to find its new IP address via ESP8266 to use this information in my code. I know that I can use a fixed IP, but I don't want to, so it is better if I can find a solution.

title: How to get a list of IPs in a LAN using NodeMcu?

Answers: 2

body:
First of all, if your Raspberry Pi acts as webserver and mqtt broker, in my opinion you should assign a fixed ip-address, either via configuration in the access point/router or via static ip.

However, if you insist on your approach you could do some hands-on method of pinging all addresses in your LAN-subnet and checking for the MAC-address of the respondents.
If the MAC-address matches to that of your Pi, you have found it.

I have not tested it myself, but this [library][1] seems to have what you need for this purpose.
After finding a responsive ip-address via ping, it tries to resolve the corresponding MAC-address using the [etharp_find_addr][2] function.

This struct field is the reference to a 6 byte character array that you can use for comparing with the Raspberry Pi's MAC address:

    response.DestMacAddress->addr

----------

Update:
If you only want to find the IP address of the Raspberry Pi, using mDNS as suggested by @Majenko is the superior choice.
If you are looking for all devices in your LAN, as your title suggests, pinging makes more sense.

  [1]: https://github.com/bluemurder/esp8266-ping/blob/master/examples/Ping/Ping.ino
  [2]: https://github.com/esp8266/Arduino/blob/master/tools/sdk/lwip/src/netif/etharp.c

body:
You should use mDNS.  Install (if it isn't already) `avahi-daemon` on your Raspberry.

Then check out the ESP8266mDNS library and the examples it has. Especially the mDNS-SD_Extended example, which performs a query for a service on the network.


body:
[![nRF24L01 6TXA_1RXA network + 6TXB_1RXB network with arduino][1]][1]

How to build nRF24L01 network shown above with arduino ?
SPI pins are shared between RXA,RXB and separate pins for both CE, CSN, IRQ.

Which nRF24L01 library supports my requirements ?

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

Answers: 1

body:
You can use the RF24 library that you can install right away from the Arduino IDE. It provides you all you need. Just use two instances of `RF24` with different CSN and CE pins assigned to get started.

```
RF24 radioA(7, 8); // CE, CSN
RF24 radioB(5, 6); // CE, CSN
```

Use the simple ping sketch as a starting point and add a second radio to it.


body:
I am trying to compile and upload code to an Arduino Uno from the command-line, however I seem to be experiencing an odd issue.

When I compile this code:

```C
#include <avr/interrupt.h>
#include <stdbool.h>

ISR(TIMER0_OVF_vect) {
}

int main() {
  while (true);
}
```

With these commands:

```
$ avr-gcc -mmcu=atmega328p -DF_CPU=16000000 -std=c17 -O3 -Wall -Wextra -c boot_loop.c -o boot_loop.o
$ avr-gcc boot_loop.o boot_loop.elf
$ avr-objcopy -j .text -j .data -O ihex boot_loop.elf boot_loop.hex
$ avrdude -p atmega328p -c arduino -P /dev/ttyUSB0 -U flash:w:boot_loop.hex
```

My Arduino ends up in a boot loop, flashing the LED 3 times every second or so (similarly to when you press the reset button or the device powers up).

I've tried it without an empty ISR and also with different interrupt vectors (e.g. `TIMER0_COMPA_vect`) but to no avail. Completely removing the ISR definition stops the boot loop.

title: ISR definition causing boot loop?

Answers: 1

body:
Your problem is not with your code. It's with how you're linking your elf file.

You haven't specified the chip to link for.

    $ avr-gcc -mmcu=atmega328p boot_loop.o -o boot_loop.elf


body:
I have searched everywhere and can't seem to find the exact model/part number for this Stepper Motor Driver.
[![enter image description here][1]][1]

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

title: Can't find exact Part type of Stepper Motor Driver

Answers: 0


body:
Has anyone tried using a setup of RGB LED directed to cuvette and the LDR on the opposite side? using arduino to and get the RGB values..

Currently having problems with calibration... I was able to get R,G,B values of colored papers... however with colored liquids inside a cuvette I'm not getting any good results (i.e the Red/Blue/Green values goes way up like 5000++)

Used white and black paper for callibration..

No idea for liquid...

title: Using LDR and RGB Led to get R,G,B values

Answers: 1

body:
Your are probably doing the white calibration with some clear liquid,
like water. The LDR is then lit directly by the LEDs, and is getting too
much light. It's resistance is then very low compared to the pull-down
resistor in series with it. You end up measuring something very close to
5 V.

You should try to reduce the amount of light hitting the LDR. A neutral
density filter (the kind used in photography) would be ideal.
Alternatively, you could increase the distance between the LEDs and the
LDR, and put some translucent paper in between. You could also add a
diaphragm (a small hole). Then, you can also lower the resistance of the
pull-down in order to get lower voltage readings, but beware not to draw
too much current.

A comment about the instructable you linked to: owing to the highly
non-linear characteristic of the readings you get, it is quite likely
that you get unequal RGB vales from a neutral grey. Some kind of
linearization (estimating actual light fluxes) would be needed if you
want neutral greys to be measured as neutral greys.


body:
Can I program a factory fresh ATMega328P using the UART pins without burning a bootloader? These pins are TX, RX, VCC, GND, and DTR pins in the schematic below. They are *not* the ISP/SPI pins 10-13.

[Arduino Pro Mini schematic][1]

For example, if you program an Arduino Pro Mini (which requires an ICSP programmer) with a programmer, you're not connected to the ISP pins (basically the SPI interface: MOSI, MISO, SCLK, SS), but rather to the serial i/o and reset pins.

My understanding is that a bootloader *is* required if you want to program through these pins, because the Arduino bootloader looks for UART traffic at these pins upon startup and hands off operation to the user's code if no attempt at programming happens during this time.

That said, I also understand burning a bootloader is done through the ISP/SPI pins, and my PCB is already manufactured, which makes burning a boatloader somewhat of a hassle. So...

Can I program an ATMega328P through the UART pins fresh off the reel, or will I need rig up a way to burn a bootloader through the ISP pins first?

[1]: https://cdn.sparkfun.com/assets/0/7/5/5/1/51eec304ce395f104c000000.png

title: Can I program a factory fresh Atmega328P through UART pins without burning a bootloader?

Answers: 1

body:
No, the ATmega's ISP does not operate over the UART pins but only the ISP pins.

To program it via a UART, you need to first load a bootloader, unless your chip was pre-programmed by the vendor, something some offer as a value-added service (or even as an essential stock item, with an Arduino type bootloader)


body:
When I try to upload my code onto the Arduino it just gives me the error message: "avrdude: ser_open(): can't open device "/dev/cu.usbmodem14201": No such file or directory
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions."

My Arduino used to function just fine. Now when a plug it in, the lights on the Arduino do not blink like they used to, and the only pins that do anything are the ones to power. It also said something like: Arduino is not optimized for mac os. It seems that the Arduino is taking in the power but not the code. here's the code:

    int led = 13; // the pin the LED is connected to
    void setup() {
      pinMode(led, OUTPUT); // Declare the LED as an output
    }

    void loop() {
      digitalWrite(led, HIGH); // Turn the LED on
    }

title: Arduino not responding to macbook pro

Answers: 2

body:
I had this issue and it was because the port was not set in my Arduino IDE.

I fixed it by going to Tools -> Port, and selecting my usb device.  In my case it was called /dev/cu.SLAB_USBtoUART

body:
I fixed it by plugging it into my other USB port (which I had previously been using)

So possibly this is caused by switching USB ports


body:
I can't get this code to work. The button code and the step motor code works separately. However, when I code using an if statement saying when the button is pressed the motor will move or else it won't. PLEASE HELP.

```c++
const int buttonPin = 7;

int buttonState = 0;
int serialData = 0;

#define IN_1 8
#define IN_2 9
#define IN_3 10
#define IN_4 11
#define DELAY_TIME 30

int i = 0;

void setup() {
  Serial.begin(9600);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.print ("start");
}

void loop() {
  buttonState = digitalRead (buttonPin);
  if (buttonState == HIGH) {
    //delay(1000);
    for (i=0; i<4; i++)
      Serial.println ("pressed");
    switch (i) {
      case 3: // ASCII value for '1'
        digitalWrite(IN_1, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_1, LOW);
        break;
      case 1: // ASCII value for '2'
        digitalWrite(IN_2, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_2, LOW);
        break;
      case 0: // ASCII value for '3'
        digitalWrite(IN_3, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_3, LOW);
        break;
      case 2: // ASCII value for '4'
        digitalWrite(IN_4, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_4, LOW);
        break;
      default:
        Serial.println("Not a valid case");
        break;
    }
    if (i == 4) {
      i = 0;
    } else {
      i = 5;
    }
  }
}
```

title: Connecting a push button to a stepper motor problem

Answers: 1

body:
Your code makes no sense at all.  Let's break it down. First we'll reformat the code using the auto-formatter (AStyle) in UECIDE:

    const int buttonPin = 7;

    int buttonState = 0;
    int serialData = 0;

    #define IN_1 8
    #define IN_2 9
    #define IN_3 10
    #define IN_4 11
    #define DELAY_TIME 30
    int i = 0;

    void setup()

    {
     Serial.begin(9600);
     pinMode(IN_1, OUTPUT);
     pinMode(IN_2, OUTPUT);
     pinMode(IN_3, OUTPUT);
     pinMode(IN_4, OUTPUT);
     pinMode(buttonPin, INPUT);
     Serial.print("start");
    }

    void loop()

    {
     buttonState = digitalRead(buttonPin);

     if (buttonState == HIGH) {
    //delay(1000);
      for (i = 0; i < 4; i++) {
       Serial.println("pressed");
      }

      switch (i) {
       case 3: // ASCII  value for '1'
        digitalWrite(IN_1, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_1, LOW);
        break;

       case 1: // ASCII  value for '2'
        digitalWrite(IN_2, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_2, LOW);
        break;

       case 0: // ASCII  value for '3'
        digitalWrite(IN_3, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_3, LOW);
        break;

       case 2: // ASCII  value for '4'
        digitalWrite(IN_4, HIGH);
        delay(DELAY_TIME);
        digitalWrite(IN_4, LOW);
        break;

       default:
        Serial.println("Not a valid case");
        break;
      }

      if (i == 4) {
       i = 0;
      } else {
       i = 5;
      }
     }
    }

Now that we have fixed the formatting we can see some very strange things:

    if (buttonState == HIGH) {

First we're doing this for every loop iteration where the button is pressed. That means we're doing it over and over again until you release the button.

        for (i = 0; i < 4; i++) {
            Serial.println("pressed");
        }

Now we're printing the word "pressed" four times.  After this `i` will be set to 4.

The `switch` will now take an input value of 4, which is "Not a valid case". So nothing will happen.

Then:

        if (i == 4) {
            i = 0;
        } else {
            i = 5;
        }

`i` is always 4, so it will always set it to 0.  Quite what this block is supposed to achieve I have no clue. If it were supposed to be inside the `for` loop above then it would just kill the loop on the first iteration, since `i`, when 0, would not be 4, so would be changed to 5, which is > 4. It makes no sense and can achieve nothing of value.

As for the `switch`: if it were inside the `for` loop and able to get some varying values of `i`, it would just make each output briefly activate in turn. If that's what you need to drive your motor, then fine. However, it's never going to run since the rest of the program is just nonsense.


body:
I am an mid experienced Programmer but I have no clue about electronic circuits. I want my Arduino to do sth if he gets a signal from an external source. The external source has 5V and is 0V or 5V and when it has 5V I want my Arduino to send me a Message, the Code for the Message is no problem, but please help me with the circuit:
The external source is independent and runs on battery and the device has a 2.5mm jack, normally there is an LED attached that lights up, but I want my Arduino to receive the signal. Are there any opportunities for realising this?
Thank you for your help

title: Receive Signal from different circuit

Answers: 2

body:
Unless there are exceptional circumstances you can just connect the two ground connections together. Then the 5V of your other circuit will be the same voltage as the 5V of the Arduino and you can just connect your signal direct to an input.

However, if there are exceptional circumstances (ground isn't really ground, for example) then you can use an opto-coupler to act like an optically-controlled button:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/YAjFg.png)

<!-- End schematic -->

R1 can be replaced by the internal pullup resistor of the Arduino by setting the pinMode to INPUT_PULLUP.

Note that this inverts the logic of the input: a HIGH input signal is detected on the Arduino as a LOW logic level, and vice versa.

body: the external source is an indicator that sends a 5V signal via a 2.5mm mono jack, I think this just has +&- so no ground. But I only need to measure if it is on or off, not the intensity


body: I started by plugging my Wroom 32 into my Kubuntu desktop. I checked my /dev before and after, and found no changes. After opening Arduino IDE, I only found my other Arduino, the Arduino Due, in the port list. I already installed the ESP 32 board. What's wrong?

title: Wroom 32 can't be recognized by Arduino 1.8.9 on a ubuntu 19.04 computer

Answers: 0


body:
I have a PIR sensor which I use to detect the motion and turn ON and OFF the lights on the basis of it.

I have PIR connected with NodeMCU (ESP8266) based board. I find that sometimes it trigger false positive value. Even when there is no motion. As per my understanding I think any of the following reasons can be there:

 1. I have NodeMCU close to it. So may be because NodeMCU heatness triggers it.
 2. Some hot air blow near it. But I don't know. It trigger the false positive even in mid-night.
 3. It can be trigger by mosquitoes.
 4. I have my other electric wires going from near by.

I am considering these scenarios correct? If yes then how can I prevent from them?

I tried to put it in a box and make it tightly pack. but still its false trigger. I checked even with multiple sensors and have same problem.

**Any suggestions to protect this?** I also check people put capacitor to smooth it. And put some resistance on Vin.

My Vin of PIR is connected to 5v and OUTPUT pin to D2.

For reference I am having this code for checking.
<!-- language-all: lang-cpp -->

    #define SIGNAL_PIN D2

    void setup()
    {
      Serial.begin(115200);
      pinMode(SIGNAL_PIN, INPUT_PULLUP);
    //  digitalWrite (SIGNAL_PIN, LOW);
    }

    void loop() {

        static uint32_t lastSeenHigh = millis();
        static bool pirState = false;
        Serial.println(digitalRead(SIGNAL_PIN));

        // If it's active then record that fact along with the time
        if (digitalRead(SIGNAL_PIN) == HIGH) {
            lastSeenHigh = millis();
            pirState = true;
        } else {
            if ((millis() - lastSeenHigh) > 10000) {
                pirState = false;
            }
        }

        if (pirState == true) {
            Serial.println("Pir Is active");
        }
    //
        if (pirState == false) {
          Serial.println("PIR sensor inactive");
        }
        delay(1000);
    }

title: PIR motion sensor (HC-SR501) false results with NodeMCU

Answers: 4

body: I had the same issue. PIRs have very sensitive circuitry and can be triggered by the WiFi signal from the ESP8266. The answer is to move them apart and with some decoupling of the power supply lines you should see much better performance. My PIR and ESP are now a couple of metres apart and I use shielded cable to connect them together.

body:
I had the same issue. I tried various solutions on the net. Finally i solved my issue like this.

- Supplied the PIR sensor 3.3 v (from the NodeMcu board) instead of 5v (my main PS is 5V)
- Connected VCC (3.3v) cable to "HIGH PIN" of trigger pins instead of main (+) pin.
- It's not generate false positive signals about 2 hours.

Actually, I'm applied that solution -> https://www.youtube.com/watch?v=2HbbQIqJHoE

body:
I was also going through the same issue. But finally, the issue got resolved.

The issue is the PIR sensor that comes with ESP8266 can work with 3.3V as well as 5V.
By default, the wiring is connected to the 5V which may work fine for the Arduino device but not for ESP8266.

I just removed the red cable (power cable) from the connector and connected to the other side where you can see H. That side also there are 3 pins.
Remove the jumper completely and connect to the first PIN from top.

Just make sure you leave the GND and OUTPUT as it is, but only the RED wire will be connected to the first pin on the other side of the PIR sensor[![please see the attached image][1]][1].

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

body: I glued some aluminum foil onto a piece of a cereal box and folded it around the PIR sensor. Works like a charm!


body:
When I start the arduino IDE as regular user from my debian testing system, I get a crash right after the splash screen:

```
Temp/arduino-1.8.9/arduino                                                              :)
Picked up JAVA_TOOL_OPTIONS:
java.lang.NullPointerException
        at processing.app.BaseNoGui.onBoardOrPortChange(BaseNoGui.java:679)
        at processing.app.Base.onBoardOrPortChange(Base.java:1317)
        at processing.app.Base$12.actionPerformed(Base.java:1544)
        at processing.app.Base.rebuildBoardsMenu(Base.java:1494)
        at processing.app.Base.<init>(Base.java:275)
        at processing.app.Base.main(Base.java:151)
Temp/arduino-1.8.9/arduino  7,28s user 0,50s system 183% cpu 4,243 total
```

When I start it with `sudo` I can use everything regularly. There are quite a few bug reports mainly in the archlinux community about a similar issue, where they suggest to install a package `arduino-avr-core` to solve it. But I assume, the reason why it happens for me, is different, since it runs fine with root privileges, and we do not have such a package in debian. Debians arduino IDE from the repos is way to old to use it these days with modern boards.

My Groups: `tty uucp dialout cdrom floppy sudo audio dip video plugdev systemd-journal netdev bluetooth lpadmin scanner docker`

The file permissions are fine for the ide and the arduino data directory.

The permissions for the usb device are also correct, just in case:`crw-rw----+ 1 root dialout 188, 0 Mai  4 11:42 /dev/ttyUSB0`

My Java environment:

```
java --version                                                                          :)
openjdk 11.0.3 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+1-Debian-1)
OpenJDK 64-Bit Server VM (build 11.0.3+1-Debian-1, mixed mode, sharing)
```

Maybe someone ran into the same problem as well?

title: How can I run the arduino IDE 1.8.9 on debian testing as regular user?

Answers: 1

body: It turned out, that the current Arduino IDE is using a directory `~/.arduino15` for data. I was not aware of the existence of it. The comments to my question made that clear. I tried to delete the `~/Arduino` and `~/.arduino` direcory several times, but to no avail. Deleting `~/.arduino15` indeed fixed the issue.


body:
I understand the HMAC with SHA256 example provides a set of keys:
(https://github.com/Cathedrow/Cryptosuite/blob/master/Sha/examples/hmacsha256test/hmacsha256test.pde)

```
#include "sha256.h"
uint8_t hmacKey1[]={
  0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b
};
uint8_t hmacKey2[]={
  0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,
0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19
};
...
```

I did a bit research and have a sense that these keys are in hexadecimal form with 0x added as prefix. If I like to use my own key, like a string, abece123*, do I just convert the key string to hex?

I tried to use this site below to convert above hmacKey2 to see what the key may look like. But the result is not recognizable. Here's what I did: copy and past
```
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,
0x0f,0x10,0x11,0x12,0x13,0x14, 0x15,0x16,0x17,0x18,0x19
```
to the site below to convert to string.
https://codebeautify.org/hex-string-converter

I am very new to this field. Please help me understand how these key works and and the steps needed to replace one of the preset hmac keys with my own key string (e.g. abece123*). Thanks.

title: How to read this hmackey for arduino?

Answers: 1

body:
Those are examples for keys. You need one key and you can choose any text with any length.

Did you see this line in the example:

    sha.initHmac((uint8_t*)"Jefe",4);

It uses the key "Jefe" with a length of 4.
You can use your own key, but you also need the length.

    char myKey[] = "abece123*";
    int length = strlen(myKey);
    sha.initHmac((uint8_t*)myKey, length);


body:
I have connected an active piezo buzzer to my arduino: [KY-012 Active buzzer module][1].

I was a bit surprised that it drew like ~10mA on the signal pin from my nodemcu, which I find a bit weird, since the signal generator itself is powered separately. Even if 10mA is in spec of the GPIO pins I wonder if that much current is considered a normal amount to expect.

The module draws an additional ~10mA from the power supply line.

Has probably someone the possibility to provide comparable measurements?

  [1]: https://tkkrlab.nl/wiki/Arduino_KY-012_Active_buzzer_module

title: Shall an active piezo buzzer module draw as much as 10mA on its signal pin?

Answers: 0


body:
I have a Velleman VMA101 Arduino Mega 2560.

https://www.velleman.eu/products/view/?id=435498

When I connect it to my computer, I can see it on Port COM18 with a yellow triangle, which means something is wrong. On IDE I had COM3 available, so I went to device manager and chaged the port to COM3.

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

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

[![enter image description here][3]][3]

The drivers are installed correctly when I installed the Arduino IDE 1.8.7.

I tried to get the board's info and I got this:

    BN: Unknown board
    VID: 04E8
    PID: 6860
    SN: Upload any sketch to obtain it

After that, I tried to upload an empty project to see whether it will work or not. It didn't work and I got this error message:

    avrdude: Version 6.3-20171130
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "C:\Users\Desktop\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf"

             Using Port                    : COM3
             Using Programmer              : wiring
             Overriding Baud Rate          : 115200
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_ReceiveMessage(): timeout
    An error occurred while uploading the sketch
    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_getsync(): timeout communicating with programmer

    avrdude done.  Thank you.

What's wrong with my board?

How can I solve this problem?

> ***The board was working perfectly for months***

  [1]: https://i.stack.imgur.com/UuyAx.png
  [2]: https://i.stack.imgur.com/46o4Z.png
  [3]: https://i.stack.imgur.com/CQpJM.png

title: VMA101 Mega 2560 upload error

Answers: 0


body:
Hey guys I have a LED strip with 6 LEDS
(I control these through Kinect & processing. It sends 1,2,3,4,5,6 to Arduino. This seems to work fine.)

In Arduino LED0,LED1,LED2,LED3,LED4 work perfectly but the last one don't work. it doesn't light up at all.

Anyone know what's going on?

```

#include <FastLED.h>

#define LED_PIN     13
#define NUM_LEDS    6

CRGB leds[NUM_LEDS];

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Serial.begin(9600);

}

void loop() {

  if (Serial.available() > 0) {
int incomingByte = Serial.read();

  //1
if(incomingByte=='1'){
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();}
if(incomingByte=='2'){
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='4'){
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[0] = CRGB(0, 0, 0);
  FastLED.show();}

 //2
 if(incomingByte=='1'){
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='2'){
  leds[1] = CRGB(255, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();}
  if(incomingByte=='4'){
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[1] = CRGB(0, 0, 0);
  FastLED.show();}

  //3
   if(incomingByte=='1'){
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='2'){
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[2] = CRGB(255, 0, 0);
  FastLED.show();}
   if(incomingByte=='4'){
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[2] = CRGB(0, 0, 0);
  FastLED.show();}

  //4
   if(incomingByte=='1'){
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='2'){
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();}
    if(incomingByte=='4'){
  leds[3] = CRGB(255, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[3] = CRGB(0, 0, 0);
  FastLED.show();}

  //5
   if(incomingByte=='1'){
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='2'){
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='4'){
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[4] = CRGB(255, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();}

  //6
   if(incomingByte=='1'){
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();
if(incomingByte=='2'){
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='3'){
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='4'){
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='5'){
  leds[5] = CRGB(0, 0, 0);
  FastLED.show();}
if(incomingByte=='6'){
  leds[5] = CRGB(255, 0, 0);
  FastLED.show();}

}
  }
}

```
here's the processing code:

```
float x = 100;
float y = 50;
float w = 150;
float h = 80;

import org.openkinect.freenect.*;
import org.openkinect.processing.*;
import processing.serial.*;

// The kinect stuff is happening in another class
KinectTracker tracker;
Kinect kinect;
Serial myPort;

void setup() {
  size(512, 424);
  kinect = new Kinect(this);
  tracker = new KinectTracker();
  String portName = Serial.list()[3]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
}

void draw() {

  tracker.track();
  tracker.display();

  PVector v1 = tracker.getPos();
  fill(50, 100, 250, 200);
  noStroke();
  ellipse(v1.x, v1.y, 50, 50);

   //1
    if (v1.x > 0 && v1.x < 50 ){
    println('1');
    //rect(0,200,200,200);
    myPort.write('1'); }
    //println('0'); }

    //2
  if (v1.x > 50 && v1.x < 100){
    println('2');
    myPort.write('2'); }
 //3
   if (v1.x > 100 && v1.x < 150 ){
    println('3');
    myPort.write('3'); }

    //4
   if (v1.x > 150 && v1.x < 200 ){
    println('4');
   myPort.write('4'); }

    //5
   if (v1.x > 200 && v1.x < 250 ){
    println('5');
    myPort.write('5'); }

    //6
   if (v1.x > 250 && v1.x < 300 ){
    println('6');
    myPort.write('6'); }

}

```

title: Serial input help

Answers: 1

body:
Your problem lies in the position of the closing bracket of the first if statement for LED 6:

    //6
    if(incomingByte=='1'){
      leds[5] = CRGB(0, 0, 0);
      FastLED.show();         // here the closing bracket is missing
    if(incomingByte=='2'){
      leds[5] = CRGB(0, 0, 0);
      FastLED.show();}
    if(incomingByte=='3'){
      leds[5] = CRGB(0, 0, 0);
      FastLED.show();}
    if(incomingByte=='4'){
      leds[5] = CRGB(0, 0, 0);
      FastLED.show();}
    if(incomingByte=='5'){
      leds[5] = CRGB(0, 0, 0);
      FastLED.show();}
    if(incomingByte=='6'){
      leds[5] = CRGB(255, 0, 0);
      FastLED.show();}

    } // this is the missing closing bracket
      }
    }

This means, that this whole block will only be executed, when `incomingByte` has the value `'1'`. This also means, that the last if statement will never be executed. Correct the position of the marked closing bracket and it should work.

---

Besides that, your code is a very complicated way of doing this. Why not simply switching the `incomingByte`? Also, to write less code and making it more understandable, use a function to turn all LEDs to off ("resetting" them):

    void reset_LEDs(){
        for(int i=0;i<NUM_LEDS;i++){
            leds[i] = 0;
        }
    }

    void loop(){
    if (Serial.available() > 0) {
        int incomingByte = Serial.read();

        switch(incomingByte){
            case '1':
                reset_LEDs();
                leds[0] = CRGB(255, 0, 0);
                break;
            case '2':
                reset_LEDs();
                leds[1] = CRGB(255, 0, 0);
                break;
            ...
        }
        FastLED.show();
    }
    }

When you stay with such easy conditions, you can even optimize more:

int incomingByte = Serial.read() - '0'; //Convert ASCII character value to decimal int value, by subtracting the ASCII value of zero

    if(incomingByte > 0 && incomingByte <= NUM_LEDS){ //Test, if the incomingByte lies between 1 and NUM_LEDS including
        reset_LEDs();
        leds[incomingByte - 1] = CRGB(255, 0, 0); // -1 because array counting starts with 0, we start counting with 1
        FastLED.show();
    }

For both versions, you save time, because you we only call `FastLED.show()´ once, when a change happens, not multiple times.


body:
I realize this generic error has been asked about lots of times before, but I have been unable to find an answer that works for me.

I have a bunch of pro mini's that I program with an FT232RL. It works perfectly fine for some time, but eventually it stops working and I get the error:

    avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

Using the same FT232RL on an unused pro mini still works fine. Burning a new bootloader through an Uno as ISP works fine, as well as uploading code to the pro mini that way, but even after burning the bootloader the FT232RL does not work on that pro mini again.

I have experienced this exact behavior on three different pro minis in a row now. Is there any sort of factory reset-ish thing I can do other than the bootloader to try to get these back to square one?

title: Programming arduino with FT232RL, not in sync: resp=0x00

Answers: 0


body: I got a sample of program to generate 3 phase SPWM from this https://arduino.stackexchange.com/questions/59925/controlling-output-frequency-of-3-phase-spwm-inverter. As far as I understood, the frequency generated is constant. My question is how can I make it a variable frequency generated? I am using Arduino mega right now.

title: Generating variable frequency of 3 phase SPWM

Answers: 1

body: I've edited the code in that post to my latest code! I suggest you take a look at the signal on proteus scope, but first try to filter all signals with 1K ohm resistor and 0.37uF capacitor connected in series. Put your scope probe at the end of resistor. Hope that will help!


body:
I would like to use the Radiohead library and control a servo from the same Leonardo board.

Now the Radiohead library occupies `timer1` and therefore cant be used together with the `servo` library. (It does offer to use `timer2` which the Leonardo does not have.)

Are there any other Servo libraries that use `timer3` or `timer4` which the Leonardo has?

I have already tried:

* https://github.com/nabontra/ServoTimer2  does not compile
* https://www.pjrc.com/teensy/td_libs_TimerOne.html does not work (calling function blocks)

title: Using Servo on Timer3 on a Leonardo

Answers: 3

body:
I wonder if you could use this PWM version of the Servo library written for the Arduino MEGA? Looking at the code, it looks like you would have to remove the "else if (pin == 44)" and "else if (pin == 45)" blocks of code in the attach() and detach() functions in Update Servo_Hardware_PWM.cpp. Just guessing here. I haven't tried it out.

https://github.com/dadul96/Arduino-Servo-Hardware-PWM-Library

body:
You could try manually sending the servo pulses with something like:

    digitalWrite(SERVOPIN,HIGH);
    delayMicroseconds(pulseWidth);
    digitalWrite(SERVOPIN,LOW);

As long as the duration of the pulses is consistent, it doesn't matter if they don't occur regularly.

Downsides will be that there may be jitter if there are interrupts running, although there is the advantage that this will work on just about any pin.

If you are looking for a simple proof of concept, this may enough to test it out.

body:
In file `ServoTimers.h`in standard Arduino Servo library change the timer

    #elif defined(__AVR_ATmega32U4__)
    #define _useTimer3
    typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t;

on Windows the file `ServoTimers.h` is located in `C:\Program Files (x86)\Arduino\libraries\Servo\src\avr`


body:
I'm facing a weird situation, where the UDP behavior seems different in STM32 porting (stm32duino).

Short question
--

Besides port and address, what are the other parameters that characterize the UDP protocol?

Long description
--

My code listens for incoming UDP packets and answer.
The actual packets contains [OSC][1] messages, but they are just UDP messages with binary data.

On host side there is a proprietary software (MAX) that send those packets. The issue is the following:

1. run both Arduino board and MAX software
2. from software send a packet
3. the Arduino receives the packet, and answer
4. the software receive the answer
5. now if the software sends more packets, **they are not received anymore** from Arduino

The weird thing is if I use another application to send **the very same packets** (i.e. PacketSender) all works fine and I can always send and receive correctly.

Furthermore, this happens with the STM32 porting *only*. The same code compiled for the standard Arduino Uno works fine.

Now some code:

    //#define STM32
    #define UNO

    #if defined(UNO)
    #include <SPI.h>
    #include <Ethernet.h>
    #elif defined(STM32)
      #include <LwIP.h>
      #include <STM32Ethernet.h>
    #endif

    #include <EthernetUdp.h>

    #include <OSCMessage.h>
    #include <OSCBundle.h>
    #include <OSCData.h>

    #if defined(UNO)
    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    };
    #endif

    IPAddress remoteIP;
    int remotePort;
    OSCBundle bundleOut;
    EthernetUDP Udp;
    OSCErrorCode error;

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

    #if defined(UNO)
      Ethernet.init(10);
    #endif
      IPAddress localIP(192, 168, 100, 1);
      IPAddress subnet(255, 255, 0, 0);
      IPAddress dns(192, 168, 1, 1);
      IPAddress gateway(192, 168, 1, 1);

    #if defined(UNO)
      Ethernet.begin(mac, localIP, subnet, dns, gateway);
    #elif defined(STM32)
      Ethernet.begin(localIP, subnet, dns, gateway);
    #endif

    #if defined(STM32)
      uint8_t *mac = Ethernet.macAddress();
    #endif
      char macString[32];
      sprintf(macString, "X:X:X:X:X:X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
      Serial.print("IP Address: ");
      Serial.println(Ethernet.localIP());
      Serial.print("MAC Address: ");
      Serial.println(macString);

      int port = 8888;
      Udp.begin(port);
      Serial.print("UDP port: ");
      Serial.println(port);
    }

    void processOSCMessage(void)
    {
      OSCBundle bundle;

      int size = Udp.parsePacket();
      if (size > 0)
      {
        remoteIP = Udp.remoteIP();
        remotePort = Udp.remotePort();

        while (size--) bundle.fill(Udp.read());
        Serial.print("Source: ");
        Serial.print(remoteIP);
        Serial.print(":");
        Serial.println(remotePort);
        if (bundle.hasError())
        {
          error = bundle.getError();
          Serial.print("Error: ");
          Serial.println(error);
        }
        else
        {
          int size = bundle.size();
          for (int i = 0; i < size; i++)
          {
            OSCMessage msg = bundle.getOSCMessage(i);
            char buffer[32];
            msg.getAddress(buffer);
            Serial.print("Message: ");
            Serial.println(buffer);
          }

          bundle.route("/version", version_handler);
        }
      }
    }

    void version_handler(OSCMessage &msg, int patternOffset)
    {
        OSCBundle bundle;
        Serial.println("Answer to message");
        bundle.add("/version").add(1).add("0.1");
        Udp.beginPacket(remoteIP, 8888);
        bundle.send(Udp);
        Udp.endPacket();
    }

    void loop()
    {
      processOSCMessage();
    }

I can't understand the difference between the MAX application and PacketSender. They are both configured to send the same data, to the same address and same port, what else?

MAX is still working after point 5 because if I redirect the address to another pc where I have PacketSender I still receive the messages. It **seems** it's just the STM32 Arduino library that doesn't receive anymore the packets.

For STM32 I'm using the following setup:

* Nucleo F429ZI
* STM32Ethernet (https://github.com/stm32duino/wiki/wiki/STM32Ethernet)
* LwIP per STM32 (anche questa la trovi nel gestore librerie)

Any further idea how to fix this issue?

  [1]: http://opensoundcontrol.org/spec-1_0

UPDATE
--
Following the suggestion, using WireShark I found the only difference between the two packets: the source port. I'm not saying this is the cause, but it's the only difference I can see.

PacketSender sends packets from the same port it also listens too (i.e. 8888).
MAX sends packets from a random port while it listens to the 8888.

Now I can partially replicate the behavior using PacketSender:

1. open two instances of PacketSender
2. A: set UDP port to 8888
3. B: set UDP port to another, say 50127
4. from B send the packet to Arduino (STM32)
5. Arduino receives the packet and answers to 8888
6. A receive the answer
7. now if I send more packets from B, they are not received anymore from Arduino, this is the same behavior using MAX
8. **BUT if now I send packets from A they are received from Arduino and answered**!

So it seems the problem rises when Arduino answer to a different port than the source one. This make no sense to me because the involved port is the source one (host side). Because UDP has no connection, why this might lead to such an issue!?

Furthermore, using the same code compiled for Arduino UNO, it works fine even at point 7.

title: UDP behavior different for STM32

Answers: 0


body:
I want to use the CTC on the ATmega328P to play same notes with a speaker, a project that I find in [this book][1].

In the data sheet I read:

> For generating a waveform output in CTC mode, the OC0A output can be set to toggle its logical level on each compare match by setting the Compare Output mode bits to toggle mode (COM0A1:0 = 1). The OC0A value will not be visible on the port pin unless the data direction for the pin is set to output.

So I suppose that after I initialize the CTC and set as output the PIN PD5 (where I connected the speaker) the TCNT0 will change as a sawtooth wave (during time) and the PIN PD5 will be or 0V or 5V depending on the TCNT0 value. Is it correct?

So I change a little bit the code that is in the book:

    #include <avr/io.h>
    #include <util/delay.h>
    #include "scale8.h" //Use to convert C2,C3 ... in numbers, for instance C2 = 100

    static inline void initTimer(void) {         //Inializzazione del timer
        TCCR0A |= (1 << WGM01);                  /* CTC mode */
        TCCR0A |= (1 << COM0A0);                 /* Toggles pin each cycle through */
        TCCR0B |= (1 << CS00) | (1 << CS01);     /* CPU clock / 64 */
    }

    static inline void playNote(uint8_t period, uint16_t duration) {

        TCNT0 = 0;                                 /* reset the counter */
        OCR0A = period;                            /* set pitch */
        DDRD |= (1 << PD5);                        /* enable output on speaker */

        for(int i=0; i<duration; i++){             /* Variable delay */
            _delay_ms(1);
        }

        DDRD &= ~(1 << PD5);                        /* turn speaker off */
    }

    int main(void) {
        // -------- Inits --------- //
        initTimer();

        // ------ Event loop ------ //
        while (1) {
                                                        /* Play some notes */
            playNote(C2, 200);
            playNote(E2, 200);
            playNote(G2, 200);
            playNote(C3, 400);

            _delay_ms(1000);
            _delay_ms(1000);
            _delay_ms(1000);

        }
        return 0;
    }

**The problem is that the voltage of the PIN PD5 doesn't change!** I try to print the voltage using serial but it's always 0V.

  [1]: https://www.amazon.it/Make-Programming-Learning-Software-Hardware/dp/1449355781/ref=asc_df_1449355781/?tag=googshopit-21&linkCode=df0&hvadid=90702551580&hvpos=1o1&hvnetw=g&hvrand=2812171719654097289&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=1008870&hvtargid=pla-93694981500&psc=1

title: Clear Timer on Compare or CTC in ATmega328P, Toggle OC0A on Compare Match

Answers: 0


body:
I have a project with 7 May Deadline, i really need help on this. Here is the problem, I need to use my Arduino MEGA 2560 as transmitter and Ardino UNO(CH340G) as receiver. I can use uno as transmitter and mega as receiver , but vice versa doesn't works.
I've used the tutorial on this site :
https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/

All codes, connections are same, but when i set MEGA as transmitter and uno as receiver, there is no data coming to Serial port of Uno. I really need help on this, i will be very very very grateful. Thank you so much.

Code on MEGA(transmitter)

```
/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}

```

Code for receiver(UNO)
```
/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

    PINS ON MEGA :
    3.3 -- VCC
    GND -- GND
    8   -- CSN
    7   -- CE
    51  -- MOSI
    52  -- SCK
    50  -- MISO
    PINS ON UNO :
    3.3 -- VCC
    GND -- GND
    8   -- CSN
    7   -- CE
    11  -- MOSI
    12  -- MISO
    13  -- SCK

title: Can't use MEGA as Transmitter and UNO as Receiver nRF24L01

Answers: 0


body:
I basically have a bread board with an rgb led and a peizo buzzer with a photocell.

I have the codes for both. If I put a code for the rgb, it works. If I put the code for the peizo, it works. Once I paste both codes onto it it says there's an error because "void setup" and "void loop" are already defined. What do I do to get both things to work?

rgb led code:

    /*
    Adafruit Arduino - Lesson 7. RGB Fader
    */
    int redLEDPin = 11;
    int greenLEDPin = 10;
    int blueLEDPin = 9;
    int redSwitchPin = 7;
    int greenSwitchPin = 6;
    int blueSwitchPin = 5;
    int red = 0;
    int blue = 0;
    int green = 0;

    void setup()
    {
      pinMode(redLEDPin, OUTPUT);
      pinMode(greenLEDPin, OUTPUT);
      pinMode(blueLEDPin, OUTPUT);
      pinMode(redSwitchPin, INPUT_PULLUP);
      pinMode(greenSwitchPin, INPUT_PULLUP);
      pinMode(blueSwitchPin, INPUT_PULLUP);
    }

    void loop()
    {
      if (digitalRead(redSwitchPin) == LOW)
      {
        red ++;
        if (red > 255) red = 0;
      }
      if (digitalRead(greenSwitchPin) == LOW)
      {
        green ++;
        if (green > 255) green = 0;
      }
      if (digitalRead(blueSwitchPin) == LOW)
      {
        blue ++;
        if (blue > 255) blue = 0;
      }
      analogWrite(redLEDPin, red);
      analogWrite(greenLEDPin, green);
      analogWrite(blueLEDPin, blue);
      delay(10);
    }

peizo code:

    int speakerPin = 12;
    int photocellPin = 0;

    void setup()
    {
    }

    void loop()
    {
      int reading = analogRead(photocellPin);
      int pitch = 200 + reading / 4;
      tone(speakerPin, pitch);
    }

title: There's an error I don't know how to fix

Answers: 1

body:
Putting all other possible issues aside such as pin and timing conflicts.

Rename the sketch `setup()` and `loop()` functions, for instance, `rgb_led_setup()` and `rgb_led_loop()`, and `peizo_setup()` and `peizo_loop()`, then rewrite:

    void setup() {
      rgb_led_setup();
      peizo_setup();
    }

    void loop() {
      rgb_led_loop();
      peizo_loop();
    }

Cheers!


body:
[![enter image description here][1]][1]I have a L298 motor controller connected to a motor with a 6 volt power sources. the motor however isn't spinning any ideas I'm using a esp 8266 node mcu board. I would like to use pwm but for right now I'm just trying to get it to work so I disabled the pwm.

    //int d0 = 16;
    const int d0 = 16;
    const int d4 = 2;

    //=======================================================================
    //                    Power on setup
    //=======================================================================
    void setup() {
      Serial.begin(115200);
      pinMode(d0,OUTPUT);
      //pinMode(d1,OUTPUT);
      pinMode(d4,OUTPUT);
    }

    //=======================================================================
    //                    Main Program Loop
    //=======================================================================
    void loop() {
      //PWM Value varries from 0 to 1023
      Serial.println("10 % PWM");
      //analogWrite(d0,102);
      digitalWrite(d0,HIGH);
      digitalWrite(d4,LOW);
      delay(2000);

      Serial.println("20 % PWM");
      //analogWrite(d0,205);
      digitalWrite(d0,HIGH);
      digitalWrite(d4,LOW);
      delay(2000);

      Serial.println("40 % PWM");
      //analogWrite(d0,410);
      digitalWrite(d0,HIGH);
      digitalWrite(d4,LOW);
      delay(2000);

      Serial.println("70 % PWM");
      //analogWrite(d0,714);
      digitalWrite(d0,HIGH);
      digitalWrite(d4,LOW);
      delay(2000);

      Serial.println("100 % PWM");
      //analogWrite(d0,1024);
      digitalWrite(d0,HIGH);
      digitalWrite(d4,LOW);
      delay(2000);

    }

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

title: Motor isnt spinning when using L298N motor controller

Answers: 1

body:
You need two supply voltages for this board to work: motor supply, which goes directly to your motor (up to 35V for this L298N board, depends on what your motor needs), and logic supply of 5V, which powers the board's logic chips. If the motor supply voltage is between 7V and 12V, you can derive 5V logic supply from motor supply by enabling this board's built-in linear regulator.

* The actual motor power supply should be connected to the `VCC` terminal of the L298N board you have in your picture. This is the **leftmost** terminal in the block of 3 in the picture (sometimes it is labeled `+12V` instead of `VCC`). In your case it is not connected to anything at all. This is already wrong.

* It is not clear what the purpose of the red wire is in your picture.

 In your comments you mention different voltages of motor power supply (6V in one place, 9V in another...). If you are feeding this board 9V through the red wire, you are doing it wrong. The rightmost terminal in the block of 3 is the `5V` pin. Don't attempt to feed more than 5V to that pin.

 If you'll be using the red wire to supply 5V logic power **to** the L298N board from an external source, then you need to disable this board's own linear regulator - remove the jumper that is shown above the 3-terminal block.

 If you'll decide to use it to supply 5V logic power **from** the L298N board (e.g. to your Arduino), then you have to keep the jumper.

 In any case, the leftmost terminal has to be connected to motor power supply.


body:
I connected my ArduCam mini to es8266 board and opened serial monitor. Then this message appeared. It started to appear continuously. I used the code in examples "functions of ov2640". What does it mean?  Why that message appears?  Plz help. Thank you.

![enter image description here](https://i.stack.imgur.com/UXoRX.jpg)

title: Serial monitor error message

Answers: 0


body:
According to espressif datasheet of the ESP8266 it uses
MTMS (I2C_SCL) and GPIO2(I2C_SDA) for I2C.

However in several examples I've seen the typically use is GPIO(4&5) or GPIO(0&4) to connect to the I2C.
I guess all method works? but what is the real difference?

title: ESP8266 I2C datasheet pins not the same as several examples

Answers: 1

body:
Many modules don't have the right pins for I2C available. Thus it was decided that the sensible option would be to use a bit-banged implementation of I2C using software only.

Also GPIO2 has a special meaning for booting, and using it is risky at best, and should be avoided.

Doing it 100% in software has the advantage that any pin combination can be used for I2C.


body:
I wonder if there may be any problems using the pins that the UART are using as GPIOs, if now I want to be able to reprogram the circuit?
(Of course I will detach the ESP12-E from the mainboard before so)

title: Nodemcu ESP12-E (ESP8266), Can I reprogramming when the UART pins are defined as GPIO?

Answers: 1

body:
Sure, you *can* use the UART pins as general purpose IO pins - however, it's far from ideal - for one simple reason:

* The ROM issues messages on the UART at boot time.

This means that when you power the chip up whatever is connected to the UART TX pin will receive pulses of HIGH and LOW.

That may or may not be a problem, depending on what is connected. It's something you need to bear in mind though.


body:
I'm using RTC and when the if condition is true the Time gots stuck and the condition keeps looping. Please help

Here is my code:

    // CONNECTIONS:
    // DS1302 CLK/SCLK --> 5
    // DS1302 DAT/IO --> 4
    // DS1302 RST/CE --> 2
    // DS1302 VCC --> 3.3v - 5v
    // DS1302 GND --> GND
    #include <Servo.h>
    #include <ThreeWire.h>
    #include <RtcDS1302.h>

    ThreeWire myWire(4,5,2); // IO, SCLK, CE
    RtcDS1302<ThreeWire> Rtc(myWire);
    int servoPin = 3;
    Servo Servo1;
    void setup ()
    {
        Serial.begin(57600);
        Servo1.attach(servoPin);
    //    Serial.print("compiled: ");
    //    Serial.print(__DATE__);
        Serial.println(__TIME__);

        Rtc.Begin();

        RtcDateTime compiled = RtcDateTime(__TIME__);
        printDateTime(compiled);
        Serial.println();

        if (Rtc.GetIsWriteProtected())
        {
            Serial.println("RTC was write protected, enabling writing now");
            Rtc.SetIsWriteProtected(false);
        }

        if (!Rtc.GetIsRunning())
        {
            Serial.println("RTC was not actively running, starting now");
            Rtc.SetIsRunning(true);
        }

        RtcDateTime now = Rtc.GetDateTime();
        if (now < compiled)
        {
            Serial.println("RTC is older than compile time!  (Updating DateTime)");
            Rtc.SetDateTime(compiled);
        }
        else if (now > compiled)
        {
            Serial.println("RTC is newer than compile time. (this is expected)");
        }
        else if (now == compiled)
        {
            Serial.println("RTC is the same as compile time! (not expected but all is fine)");
        }
    }

    void loop ()
    {
        RtcDateTime now = Rtc.GetDateTime();

        printDateTime(now);
        Serial.println();
        delay(5000);

    //here is my problem>>>>

        if(now.Hour() == 22 && now.Minute() == 40)
        {
          Servo1.write(0);
          delay(1000);
          Servo1.write(90);
          delay(1000);

        }

    //////////////////////

        delay(5000);

    }

    #define countof(a) (sizeof(a) / sizeof(a[0]))

    void printDateTime(const RtcDateTime& dt)
    {
        char datestring[20];
    //u/u/u
        snprintf_P(datestring,
                countof(datestring),
                PSTR("u:u:u"),
    //            dt.Month(),
    //            dt.Day(),
    //            dt.Year(),
                dt.Hour(),
                dt.Minute(),
                dt.Second() );
        Serial.print(datestring);
    }

title: My Arduino got stuck and continuous looping in if condition

Answers: 1

body:
What is being brought to your attention is the following part of your code...

    //here is my problem>>>>

    if(now.Hour() == 22 && now.Minute() == 40)
    {
      Servo1.write(0);
      delay(1000);
      Servo1.write(90);
      delay(1000);
    }

In this code you use an "if" statement and ask:
   if the now.Hour is equal 22 AND if the now.Minute is equal 40 then
    write a 0 to your servo then
    delay for 1000
    then write a 90 to your servo
    and wait another 1000

What is being brought to your attention is that until now.Hour changes or
until now.Minute changes your write 0, delay, write 90, delay will continue
on and on and on until now.Hour changes (which will take a while) or now.Minute
changes. Since minutes are 60 seconds long your code will repeat for all of those
60 seconds...

If you were to change your code to include, oh, lets say now.Second() (like this)--

    if(now.Hour() == 22 && now.Minute() == 40 && now.Second() == 00)

Then your code will repeat over and over until now.Second changes (which will take 1 second).

By the time your loop gets back to the "if" statement now.Second will no longer be 00 and it will not be "stuck" for you...

********
As has been brought to my attention, your 5 second delay will be a problem, so you might find that changing it will allow the now.Second "fix" to work.

In the following part of your code change delay(5000)

    void loop ()
    {
        RtcDateTime now = Rtc.GetDateTime();

        printDateTime(now);
        Serial.println();
        delay(5000);
    }

to something like delay(1000) or so.

That way it will only wait 1 second before dropping out of the loop and checking the loop with the newly added now.Second(). This will make the printDateTime(now) happen every second instead of every 5 seconds, but it shouldn't get "stuck".

Hopefully this helps you to better understand how time (and its parts) work.


body:
When I use esp8266 as **STATION** mode and connect a speaker between VCC(3.3v) and GND pin a sound appears like "doop doop". what is this sound?
I test this in version 01 and 12 of esp8266 module and this appear in both versions.
maybe you ask me why I connect speaker to this pins. problem is that when I use pwm of esp8266 for playing a sound, this sound ("doop doop") appear to it also.
What is problem? How can I fix this?

title: why sound appears between VCC and GND pins in esp8266 module?

Answers: 1

body: It's called "noise" and is to be expected. Wi-Fi devices are generally very electrically noisy - and the ESP8266 is no exception.


body:
I need to output a serial message on a 500 microsecond interval (10 bytes), can be a little slower but no more than 1 milisecond between messages.

Can it be done with an Arduino? I know there is a delayMicro(), but not sure if it has the resolution.

title: Can Arduinos keep a 500mu timer?

Answers: 1

body:
It's not related to the delayMicro, but to the max speed of the Serial/UART driver, which is not documented, but according to some people it can reach 500 kbps.

However, 10 bytes, each 500 us (2000 Hz) means 10 * 11 (including some stop/start bit) * 2000 = 220.000 bits, so you have some headroom left. Maybe there is also some timing overhead.

Anyway, probably the only way to go is using an interrupt, and expect the Uno is not able to do anything else.

A better option might be to send less or send smarter (i.e. not 10 bytes, but maybe some compressed/binary form if not already thought about).


body:
New to Arduino and programming so forgive me if this is trivial but I've searched and can't find an answer...

Goal: I want to convert decimal values to their equivalent fraction... eg: 0.125=1/8. I think I came up with a simple solution, having one array of decimal values and one array of fraction values and when the input value matches a decimal value return the corresponding fraction value and display it on a tft screen...

Problem: well my simple solution doesn't work for some reason and as stated previously I searched and can't figure out why... I tried declaring the arrays in many ways but with the same result, here is the relevant code but it's only a small fraction of the complete code... the line that is commented out is the one giving me the problem...

    //Serial.print("decimal test result: ");Serial.print(fracarray[i]);Serial.println(" match");

when I use that line a random smiley face character appears on the tft screen and keeps the code from running properly.

    int checkformatting(char *input, int button){
      char *decarray[]={"0.015625", "0.03125", "0.046875", "0.0625", "0.078125", "0.09375", "0.109375", "0.125", "0.140625", "0.15625", "0.171875", "0.1875", "0.203125", "0.21875",
                      "0.234375", "0.250", "0.265625", "0.28125", "0.296875", "0.3125", "0.328125", "0.34375", "0.359375", "0.375", "0.390625", "0.40625", "0.421875", "0.4375", "0.453125",
                      "0.46875", "0.484375", "0.5", "0.515625", "0.53125", "0.546875", "0.5625", "0.578125", "0.59375", "0.609375", "0.625", "0.640625", "0.65625", "0.671875", "0.6875",
                      "0.703125", "0.71875", "0.734375", "0.75", "0.765625", "0.78125", "0.796875", "0.8125", "0.828125", "0.84375", "0.859375", "0.875", "0.890625", "0.90625", "0.921875",
                      "0.9375", "0.953125", "0.96875", "0.984375"};
      char *fracarray[]={"1/64", "1/32", "3/64", "1/16", "5/64", "3/32", "7/64", "1/8", "9/64", "5/32", "11/64", "3/16", "13/64", "7/32",
                      "15/64", "1/4", "17/64", "9/32", "19/64", "5/16", "21/64", "11/32", "23/64", "3/8", "25/64", "13/32", "27/64", "7/16", "29/64",
                      "15/32", "31/64", "1/2", "33/64", "17/32", "35/64", "9/16", "37/64", "19/32", "39/64", "5/8", "41/64", "21/32", "43/64", "11/16",
                      "45/64", "23/32", "47/64", "3/4", "49/64", "25/32", "51/64", "13/16", "53/64", "27/32", "55/64", "7/8", "57/64", "29/32", "59/64",
                      "15/16", "61/64", "32/32", "63/64"};
        for (int i=0; i<63; i++){
          if (strcmp(decarray[i], input)==0){
            //Serial.print("decimal test fracarray: ");Serial.print(fracarray[i]);Serial.println(" match");
           Serial.print("decimal test result: ");Serial.println(decarray[i]);Serial.println(" match");
          }
        }

        Serial.print(("result mm= ")); Serial.println(conversionresult, 6);
      }
    }

Thanks in advance for any help...

title: problem with char array iteration and strcmp

Answers: 0


body:
I am looking for a way to exchange a few bytes of data from one Arduino to two or more additional Arduinos. It's a one way communication and speed is not a problem. 10Hz is fast enough.

**Data Collector Arduino:** I have one Arduino with SPI and I2C shields which collects and analyzes data from a CAN-BUS in a motorcycle. The CAN-BUS supplies lots of information but I filter it down to few info like which lights are on, intake temperature, motor RPM, which gear.

**Light Control Arduino:** This Arduino should know which lights are on. Depending on low beam, high beam, indicators, etc. it will control additional lights which are not part of the original bike.

**Motor Control Arduino:** This Arduino should know the current RPM, gear, etc. and work with that data.

**The question is how do I "transfer" the data from the data collector to the other Arduinos?** If it would be a little simpler I would connect some digital pins which the data collector would write and the others would read. But there are not enough pins for my needs and why use 10 pins when maybe 2 are enough.

All the Arduinos use SPI and I2C connected devices so I don't think it's a good idea to use SPI or I2C for communication between the Arduios.

I guess Serial communication would work with 2 Arduinos but not with 3 or even more. Maybe I could use multiplexing or something like that?

Maybe I could let the data collector Arduino write data into some kind of shared memory and the other Arduinos could read it?

**What do you suggest? I am sure there are simple solutions out there but I didn't find anything. I don't mind any extra ICs.**

Before someone suggest to do all in one Arduino: Maybe it would be possible. But I really like to keep the modules (Arduinos) separate and I want to be able to add others later if I want to. Then I only want to change the software of the collector Arduino and don't touch the others.

title: One Arduino collects data, several other Arduinos use the data. What is a simple way to do this?

Answers: 2

body: You can do it simply by addition of extra RX and TX pins by use of library like Software Serial Library. For reference you can go here https://www.arduino.cc/en/Tutorial/TwoPortReceive . By using this library you can increase number of ports in master arduino and you probably can give command to other slave arduino commands through master arduino. In this way each arduino can communicate with each other.

body:
It is possible to send out data from one Arduino to multiple others at once via serial (UART). You simply connect the TX of your master Arduino to the RX of all the slave Arduinos. All receiving Arduinos will get the same data with that. You only need 1 pin (for the connection sender TX to the multiple RX). This is a bit limited to the number of slaves and the speed, but that doesn't seem to be an issue here (since you only have a few).

This is a 1-way communication, since at any line there must not be more than 1 TX (sender). If you have more than 1 TX on a line, you will burn your hardware as soon as both TX send out data simultaneously.

I remember some sites that stated it to be possible to also do multiple sender UART, when you adhere to a protocol and put in some safety hardware (I think they used diodes and current limiting resistors). But that is somewhat out of scope here. If you really need a 2-way communication, you maybe should rethink the whole structure of your solution. As Juraj suggested in his comment, it might then be easier to unite the functions to less Arduinos.

---

Be sure, that the Arduinos share the same ground. This is needed for any communication, when you don't utilize extra hardware (like an optocoupler).


body:
I am controlling a motor with an Arduino Nano, that motor is controlled by Cytron MD-10c motor controller.

i want to wire a momentary switch in parallel with the analog output PIN from the Arduino and PWM input on the MD-10c, the switch will connect the 5v output from Arduino to the PWN input on the MD-10c. Basically an override to go full power.

Is there any risk of damage with this sort of wiring with the switch?

title: Applying 5v to analogWrite Pin

Answers: 1

body:
Yes, depending on the current that will flow.

If your PWM output pin is connected to 5V without a current limiting resistor, nothing will happen during the `HIGH` phases of the PWM, but you will short the input pin during the `LOW` phases.

According to the [manual of your motor controller][1], you should be able to use a current limiting resistor to prevent this.
Since the ATMega328P on your Arduino Nano can sink a maximum of 40 mA, that resistor should be at least 125 Ohms. A resistor larger than 1 kOhm should work fine.

The other option would be installing a diode between your Arduino Nano and the motor controller.
This does not require the use of a current limiting resistor.
The motor controller would still work, since the minimal voltage for the pin state to be detected as `HIGH` is 3V ([1]), much lower than the ~4.3V you're left with after a diode.

  [1]: https://www.robotshop.com/media/files/pdf2/cyt-132-v2.3.pdf


body:
I am trying to burn a bootloader onto an ATmega328P-AN using an Microcenter knock-off Arduino Uno R3 as my ISP for several days with no luck. The farthest I've gotten is writing and reading a few fuses prior to bootloader burn.

I have checked and rechecked the connections:

    Uno    ATmega328P-AN
    GND    GND
    VCC    VCC
    MISO   MISO
    MOSI   MOSI
    SCK    SCK
    SS     RESET

 - I have a 2.2 uF cap from ground to RESET on my Uno, and a 16 MHz crystal with two 22 pF load caps to ground on my ATmega328P's XTAL pins.
 - I have ArduinoISP loaded onto the Uno and my bootloader target is "Arduino Pro or Pro Mini", and my processor is set to "ATmega328P (5V 16MHz)".

I am using Arduino 1.8.9 on Windows 10.

Things I've tried:

- Multiple boards and ATmega328P ICs - No difference.

- Burning a bootloader to an Ebay Arduino Pro Mini knockoff, *which worked*, but there's no obvious electrical difference between this part and a raw ATmega328P. (Weirdly, the slight progress I made (setting some fuses - see below) was done by bypassing the DTR-cap-pullup reset path and running the ISP SS directly to the reset pin on the ATmega328P chip.)

- Using Arduino IDE 1.0.x - No success.

- Using a genuine Arduino Uno R1. No success.

- Checking all the rails. I have a clean 5V and a clean ground. Unfortunately my lousy scope isn't picking up any of the 16 MHz oscillators, so I'm not sure what my clocks are up to.

- In-circuit programming in a populated board with flying leads from the appropriate ICSP nodes. No success.

- In-circuit programming with fresh board and just a power supply bypass cap, oscillator, load caps, and supply rails available.

Here's my Arduino IDE terminal output:

        C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m

        avrdude: Version 6.3-20171130
                 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                 Copyright (c) 2007-2014 Joerg Wunsch

                 System wide configuration file is "C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf"

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

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

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

        avrdude: AVR device initialized and ready to accept instructions

        Reading | ################################################## | 100% 0.00s

        avrdude: Device signature = 0x1e950f (probably m328p)
        avrdude: erasing chip
        avrdude: reading input file "0x3F"
        avrdude: writing lock (1 bytes):

        Writing | ################################################## | 100% 0.01s

        avrdude: 1 bytes of lock written
        avrdude: verifying lock memory against 0x3F:
        avrdude: load data lock data from input file 0x3F:
        avrdude: input file 0x3F contains 1 bytes
        avrdude: reading on-chip lock data:

        Reading | ################################################## | 100% 0.01s

        avrdude: verifying ...
        avrdude: 1 bytes of lock verified
        avrdude: reading input file "0xFD"
        avrdude: writing efuse (1 bytes):

        Writing | ################################################## | 100% 0.02s

        avrdude: 1 bytes of efuse written
        avrdude: verifying efuse memory against 0xFD:
        avrdude: load data efuse data from input file 0xFD:
        avrdude: input file 0xFD contains 1 bytes
        avrdude: reading on-chip efuse data:

        Reading | ################################################## | 100% 0.01s

        avrdude: verifying ...
        avrdude: 1 bytes of efuse verified
        avrdude: reading input file "0xDA"
        avrdude: writing hfuse (1 bytes):

        Writing | ################################################## | 100% 0.02s

        avrdude: 1 bytes of hfuse written
        avrdude: verifying hfuse memory against 0xDA:
        avrdude: load data hfuse data from input file 0xDA:
        avrdude: input file 0xDA contains 1 bytes
        avrdude: reading on-chip hfuse data:

        C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b19200 -Uflash:w:C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m
        Reading | ################################################## | 100% 0.01s

        avrdude: verifying ...
        avrdude: 1 bytes of hfuse verified
        avrdude: reading input file "0xFF"
        avrdude: writing lfuse (1 bytes):

        Writing | ################################################## | 100% 0.02s

        avrdude: 1 bytes of lfuse written
        avrdude: verifying lfuse memory against 0xFF:
        avrdude: load data lfuse data from input file 0xFF:
        avrdude: input file 0xFF contains 1 bytes
        avrdude: reading on-chip lfuse data:

        Reading | ################################################## | 100% 0.01s

        avrdude: verifying ...
        avrdude: 1 bytes of lfuse verified

        avrdude done.  Thank you.

        avrdude: Version 6.3-20171130
                 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                 Copyright (c) 2007-2014 Joerg Wunsch

                 System wide configuration file is "C:\Users\jms\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/etc/avrdude.conf"

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

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

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

        avrdude: AVR device initialized and ready to accept instructions

        Reading | ################################################## | 100% 0.00s

        avrdude: Device signature = 0x000000 (retrying)

        Reading | ################################################## | 100% 0.01s

        avrdude: Device signature = 0x000000 (retrying)

        Error while burning bootloader.
        Reading | ################################################## | 100% 0.01s

        avrdude: Device signature = 0x000000
        avrdude: Yikes!  Invalid device signature.
                 Double check connections and try again, or use -F to override
                 this check.

        avrdude done.  Thank you.

If I try to burn the bootloader again, I just get the "Device signature = 0x000000 (retrying)" messages, but no fuse write/read cycles.

[![My circuit][1]][1]

I am really stumped at this point.
Questions

 - Am I bricking my ATmega328P parts when the bootloading process is not successful?

 - What am I missing?

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

title: What would cause fuses to be writeable but bootloader not to be writeable?

Answers: 0


body:
What I aim to do:
To measure the frequency of an AC analog signal generated by an electrodynamic shaker, which has a peak voltage of 10V-- using an Arduino Uno.

What I have tried:
Tried using a circuit similar to an optocoupler (using a 2N2222) transistor to take pulse input, using the `pulsein()` function. However the duration is always returning as 0.

My questions:

* Is this method an acceptable way of measuring frequency?
* What could I be doing wrong such that the time duration is always returning 0?
* Is there an easier way of carrying out this work?

Will put up the code if asked for. However it is basically just defining a few variables (for pins, duration etc), and then using the `pulsein` function.

![Here is the image of the circuit diagram]
(https://i.stack.imgur.com/jW4ll.jpg)

title: Frequency measuring using Arduino (AC analog input)

Answers: 2

body:
This project includes a frequency counter.

https://www.instructables.com/id/Oscilloscope-in-a-Matchbox-Arduino/

From the project page:
This oscilloscope costs the price of an Arduino Nano (£2 and a display (£3) plus a few pence for resistors, etc. It's specification is:

 - max 1M samples/second, min 1000sps
 - 8-bits per sample
 - DC 0-5V; AC +/- 550mV, AC +/- 117mV, AC +/- 25mV
 - USB "PC scope" or built-in display
 - could be battery-powered
 - optional logic display
 - **optional frequency meter**
 - optional voltmeter
 - optional signal generator

My comment: I build it, it's a nice little project and the author is an expert programmer.

body:
> Is this method an acceptable way of measuring frequency?

Nope, not at all.

> What could I be doing wrong such that the time duration is always returning 0?

You are misusing pulsein(), it doesn't work like that; look up the documentation for it!

> Is there an easier way of carrying out this work?

Yes; there are many ways, you can research many of them. One thing you can do is make a peak detector, either in hardware or software, and then design a way to get a counts/time, which should correlate to the frequency!


body:
Refer to

 - https://arduino.stackexchange.com/questions/61229/esp8266-deep-sleep-and-mqtt

I executed the code in the given link. However i am not able to receive the subscribe message that are send from MQTT test broker(MQTT Lens) on the serial console.

Please help.
I am receiving successful call to both publish methods

    #include <ESP8266WiFi.h>
    #include <PubSubClient.h>
    const char* ssid = "honored";
    const char* ss_pswd = "12345678";
    const char* mqtt_server = "iot.eclipse.org";

    void callback(char* topic, byte* payload, unsigned int length);
    WiFiClient EspClient;

    PubSubClient client(EspClient);

    void wifi_setup() {
      Serial.print("Connecting to: ");
      Serial.println(ssid);
      WiFi.begin(ssid, ss_pswd);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.println(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }
    void reconnect() {
      while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        String ClientId = "ESP8266";
        ClientId += String(random(0xffff), HEX);
        if (client.connect(ClientId.c_str())) {
          Serial.println("connected");
          client.publish("outtopic", "hello world, finally");
          client.subscribe("/room/test");
        } else {
          Serial.print("failed, rc=");
          Serial.println(client.state());
          Serial.println("Try again...");
          delay(5000);
        }
      }
    }
    void sendMQTTMessage() {
      Serial.println("sending your message");
      if (!client.connected()) {
        reconnect();
      }
      client.publish("/sensor/pir", "on");
    }
    void callback(char* topic, byte* payload, unsigned int length) {
      Serial.print("Message arrived: ");
      Serial.println(topic);
      for (int i = 0; i < length; i++) {
        Serial.print((char)payload[i]);
      }
    }

    void setup() {
      Serial.begin(115200);
      wifi_setup();
      client.setServer(mqtt_server, 1883);
      sendMQTTMessage();
      client.setCallback(callback);
      delay(2000);
      Serial.println("going into deep sleep");
      ESP.deepSleep(10 * 1000000);
    }

    void loop() {

    }

title: MQTT subscribe callback fails to be called in ESP8266 deepsleep mode

Answers: 1

body:
My solution:
update_mqtt() is called before deepSleep

    PubSubClient mqtt_client(client);
    boolean cb = false;

    void callback_mqtt_switch(char* topic, byte* payload, unsigned int length) {
      String lowerstr = "";
      for (uint8_t i = 0; i < length; i++) {
        lowerstr += (char)payload[i];
      }
      lowerstr.toLowerCase();
      DebugOut("Sleep payload: " + lowerstr);
      if (!back_to_sleep) {
        sleep_on = lowerstr == "ein";
      }
      cb = true;
    }

    void update_mqtt() {
      int i = 0;
      while (!cb && i++ < 30) {
        mqtt_client.loop();
        delay(10);
      }
      #ifdef TEST
        Serial.print("Warte ");
        Serial.println(i * 10); // max. 300ms gewartet
      #endif
      cb = false;
    }


body:
[Sparkfun rfid qwiic][1]

[id-20la][2]

I am using an Arduino UNO R3.

You should assume that i don't know anything. If yes can you give some information about how to do it? Thanks for any help.

  [1]: https://www.sparkfun.com/products/15191
  [2]: https://www.antratek.com/rfid-reader-id-20

title: Can i use a sparkfun rfid qwiic without an id-xxla?

Answers: 1

body: No. It is not an RFID reader. It just interfaces to an RFID reader. You need an RFID reader to read RFID tags. That Sparkfun board just controls the reader and reads the data from it.


body:
Hope you can see this.

https://gist.github.com/DevilWAH/60ad144d2858f53845ac2e80f84bb070

The main file in this is "morse-led-rfid" which is taking reading data of an RFID tag and then displaying the text as Morse code on to a APA102 / Dotstar LED strip.

The issue is when the function updatestrip(tempbuffer[i]); is called.

    Serial.println(F("\n**Start Reading**\n"));

      for (uint8_t i = 1; i < 15; i++)
      {
       if (i != 3 && i!= 7 && i != 11 && i != 15 ) // Skip the non data blocks
        {
         readblock (i, key);
           for (uint8_t i = 0; i < 16; i++)
             {
          updatestrip(tempbuffer[i]);
          Serial.write(tempbuffer[i]);
            }
        }
      }

This is what I am calling to scroll the LED strip and write the letter in morse. if in the code snip it above i comment out "updatestrip...." then i get the txt from the RFID tag printer to serial as i would expect.

as a soon as i un comment it, the strip displays the morse code but the serial output gets garbled, it misses letters, prints reversed "?'s" and repeats its self?

Good output = "My Bunny is the best"
Bad output = "?Bunny is the ?t" (question marks reversed)

Further investigation i found if i leave it uncommented but go all the way to the bottom of the "more-strip" sheet and comment out the "else statement in the shiftLED function" the serial again displays correctly, but of course the led don't :)

    void shiftLED() // shift all LED up 1
      {
        for(uint16_t i = ledCount; i > 0; i--)
        {

          if ((colors[i - 1].red == 0 ) && (colors[i - 1].green == 0 ))
           {
              colors[i] = cblack;
            }
          else if (i > 19 && i < 40)
          {
            colors[i] = cred;
          }
         // else
         // {
         //   colors[i] = cgreen;
         // }
         // }

     }

Can any one suggest why the else statement a few function down is affecting the "serial.write(tempbuffer[i])" in the main loop?

title: Strange artifact in writing to serial while executing loop

Answers: 1

body:
In your code `colors` is declared as

    rgb_color colors[ledCount];

This means that the very first iteration of this cycle in `shiftLED`

    for (uint16_t i = ledCount; i > 0; i--)
    {
      // access colors[i]
    }

will access `ledCount[ledCount]` which is obviously out of bounds (and will actually *write* into that location!). The behavior is undefined after that.

Using unsigned types for "backward" array iteration requires a bit of skill. The common idioms are

    for (uint16_t i = ledCount; i > 0;)
    {
      --i; // do this ASAP

      // access colors[i]
    }

or

    for (uint16_t i = ledCount; i-- > 0;)
    {
      // access colors[i]
    }

or

    // Careful: this technique is not usable with unsigned types
    // narrower than `unsigned int`
    for (uint16_t i = ledCount - 1; i != -1; --i)
    {
      // access colors[i]
    }

This is assuming that you want to iterate over the whole array: from `[ledCount - 1]` all the way back to `[0]`.

But if you intended to iterate back to `[1]` and stop short of `[0]` (which is apparently the case), then a simple fix for your cycle would be

    for (uint16_t i = ledCount - 1; i > 0; i--)
    {
      // access colors[i]
    }

I.e. simply start from `ledCount - 1`, not from `ledCount`.