message:
Reverse engineering LIN bus on E-bike system

As a project I am trying to 'hack' an old E-bike.
The electronic system of the bike consists of:

 - A torque sensor measuring deformation of the rear.
 - A 'spin' sensor measuring if the person is pedeling.
 - A battery pack with BMS
 - A speed controller inside the hub motor.
 - A display to control speed, lights and display distance information etc.

From researching I concluded that the sensors, dislay and speed controller are communicating over LIN because they have a ATA6661 LIN transceiver and they are all connected parallel over the VS, LIN and GND wire.
When I power up the speed controller on its own I can see some LIN communication on my oscilloscope:
[![LIN communication][1]][1]

I do not have a LIN transceiver to log the data but I attached a USB-TTL transceiver to the uart-side of the LINtransceiver. From my oscilloscope a deduced that the baud rate was 9600. I used termite to listen on my serial port and set it to hex view. This is what I got:

[![serial communication][2]][2]

I'm not sure if I should change the amount of bits or parity bits.

My goal is to understand the frames that are send and to deduce which frame holds which sensordata or results in a certain activity.
When I compare this to an CANbus project I was doing it was fairly easy to for example deduce which command was controlling my car's left window because with can-utils (candump) I could see every packet. I could filter unchanged packets and it colorcoded which bit(s) in each packet recently changed.

Any advice/ideas on how to do this for LINbus?

  [1]: https://i.stack.imgur.com/EPlT2.jpg
  [2]: https://i.stack.imgur.com/glyAU.png

body:
As a starter point I would hookup your rigol ds1054z via usb to sigrok
https://sigrok.org/wiki/PulseView this will enable you to log dump and analyze your lin frames . It has a frame decoder for LIN protocol.
This should give you a great view of what is transiting over the lin bus and which slave PID to call .
From there you may use a macchina.cc  to comunicate over lin or use
https://github.com/macchina/LIN with a arduino due and a lin tranceiver.
Cheerz


sender: user

sender: assistant

body: If you are using "go swissdrive" controller (I'm looking at the picture) the bikebus protocol (bulls green mover) was used and in later, linbus (e-technology, Alber etc.) Display is master, motor and bms as slave .. Good luck :)


message:
RS-485 Serial communication problem with arduino

I use 485 modules to transmit data serially from one arduino uno to another uno.

If I connect the 2 arduino boards directly without using the rs485 module, the data is sent and received without a problem. But when using the rs485 module, the transmission stops.

Tx code:

```c++
void setup() {
    Serial.begin(9600);
}

void loop() {
    Serial.write(200);
    Serial.flush();
    delay(50);
}
```

Rx code:

```c++
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

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

void loop() {
    if (Serial.available()) {        // If data has come in from Master
        int reply= Serial.read();    // Read the byte
        delay(10);

        lcd.print(reply);
    }
}
```

I can't see what is the problem. I checked every thing wiring and the code is so simple. I'm just sending one number 200 and want to display it on the rx.

Please help. If anyone has an idea about this problem thanks any way.

body:
In modbus there are two pins which are as DE and RE which you need to set and reset while transmitting the data. Also you can check [Modbus][1] this library it has some examples which could be useful to you also in arduino Uno don't use software serial for transmitting the data use the hardware serial only I will suggest implement your code on arduino Mega if you have any and then port the code for Uno. Just go through the library you will find some helpful examples and it will solve your issue

  [1]: https://github.com/4-20ma/ModbusMaster


body: I polished my glasses, I did not find the schematic and parts list. It appears you have to enable the transmitter and or receiver to make them work. DE and RE are pins on the Max RSS 485 driver chip and others. They will not transmit or receive if these are wrong. Many connect the DE and RE together to simplify the switching.  In your case you have to enable the transmitter on the transmitting Arduino and the Receive on the receiving Arduino. Do not enable the transmitter on the receive side as it wall cause bus contention and it will probably stop working. The receive can be enabled on the transmitter. This is done is some protocols to validate the message sent. Since you are only sending one way you can hardwire them to the correct logic level. Also you should terminate the buss, it may work without but best to add the resistors.


message:
Leading Zeroes on Arduino Ethernet MAC Address

How can I pass the MAC address to Ethernet shield with leading zeroes?

I change the default MAC address from ```DEADBEEFFEED``` to something like ```DEADBEEFFE01```. So I only change the last number from ```0xED``` to ```0x01```. My board is communicating to a separate server and when I look at the MAC in that server, my board is listed as ```DEADBEEFFE1```.

It's not as simple as printing the MAC address with padded zeroes as the board is actually removing it.

I've looked at the Ethernet library and I saw that the mac is passed as an array of ```uint8_t```. I think that's why, the last number is read as 1 (which is correct) but passed as just that.

Is there a way for the MAC to pass leading zeroes?

body:
Writing this in case someone in the future might be interested.

The values passed in the Ethernet library is correct. The last value, 0x01 must be 1 and is written correctly, ```0x01``` in the registers of the W5500 inside the Ethernet shield.

Where I've got it wrong is how I pass the MAC address to the server. I'm basically creating a string for a json message. In there, I've put ```x``` to make sure that zeroes are padded.


message:
I want to make mesh network with nodemcu (esp8266)

in this all the nodemcu are in both mode receiving and transmitting, if i made 6 nodemcu connected with each other as mesh network to control home appliances, using mac address.  suggest how i will start to reach the destination.

body:
there are libraries for this already, i have used [this one,][1] but i have not tested the mesh function yet

  [1]: https://github.com/martin-ger/esp_wifi_repeater


message:
Can't turn off fan using PWM and analogWrite(x, 0)

I'm trying to make PWM Signal Generator with Arduino Uno.
I'm trying to control 230V 50hz "[NRG118][1]" combi boiler fan.  The fan powered by AC and have 3pins for PWM control. "vcc,gnd,pwm" Wired them to arduino "5v, GND, 11" pins.

I can control the card on the arduino "0to100% with a simple code below but I can't turn it off.
I tried digitalWrite nothing changed. Tried different pins 5-6-9-11 nothing changed. Tried to wire gnd+vcc to outsource powersuply nothing changed.

Also I have a simple PWM generator ["HW-723 XY-LPWM PWM Signal Generator Module"][2]. The "HW-753" can control the fan without any other component but it may have builtin special component like a NPN but im not sure about it.

In description I found this and maybe its a requirement but I have no idea about electronic components:
"The PWM output pin on the microcontroller drives an NPN MMBT3904 type transistor which in turn drives the PWM output pin of the module.  The transistor has a series 1K resistor tied to VIN+, so the PWM signal will swing between ground and the module supply voltage on the VIN+ pin."

With the HW-753; at startup the fan is not running but when I wire to my arduino it starts with 100% power and when i set "analogWrite(x, 0)" dutycycle reducing but fan still running at %1 speed and I read 0.07volt with multimeter on "PWM+GND" pins.

Most people can not run, I cant stop.... It's killing me people...
What am I doing wrong?

    void setup() {
      pinMode(6, OUTPUT);
    }
    void loop() { //the code only for test. Using loop is dumb.
      //digitalWrite(6, LOW);
       analogWrite(6, 0);
       delay(5000);
    }

  [1]: https://ebmpapst-ventilator.hu/userfiles/webshop/products/resized/2689.jpg
  [2]: https://protosupplies.com/product/xy-lpwm-pwm-signal-generator-module

body:
If you are working with the AC motor, then it is probably works even PWM cable is not attached. In this case there is no reason to use "analogWrite(PIN, 0)".  It will not work.

"An external resistor divider connected to the VMIN input sets the minimum fan speed by fixing the minimum PWM duty cycle (1.25V to 2.65V = 0% to 100%, typical).  It depends on controler card manufacturer. check datasheet"

If you cant find datasheet like me then check how others do. There is diagram of "HW-753 Signal Generator Module" below. As you can see between VIN+ and PWM there is 1k Resistor and both wired to an NPN, also the mid leg of NPN passing 1k resistor while going to pwm to protect the card. Also 3rd leg is wired to gnd. So it is not the same thing I was doing before. If you work with AC then you must always consider that and just forget what people say. Do not drown like me. I hope it will helps someone.

[![][1]][1]

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


message:
Cutting neopixel routine code short

I've been working on a level meter with a neopixel strip (WS2812).

The code is very simple: reading a potentiometer, mapping the input and showing the output in the led strip.

So far, so good. The code I include below is working fine but, obviously, ugly and repetitive.
Since my knowledge of programming is very weak, I wonder if there is any loop way to cut the code short. Please note that the seven led have different colours. Actually this is the confusing point for me to build a loop. Any idea, folks?

Yes, I also know that using so many delays isn't the mos elegant solution, but it does not compromise the device performance and the bar led appearing is quite nice.

```c++
void leveller () {
     int millivolts;
     int level;

     millivolts = analogRead(A3);

     level = map(millivolts, 0, 1024, 0, 7);
     if (level <=0){
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
         strip.show ();
      }
      else if ((level > 0)&&(level<1)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
       strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
      }
      else if ((level>= 1)&&(level<2)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
     strip.show ();
      }
      else if ((level>= 2)&&(level<3)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
             delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(3, 0, 128, 0);
          delay(30);
     strip.show ();
      }
      else if ((level>= 3)&&(level<4)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(3, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(4, 0, 128, 0);
          delay(30);
         strip.show ();
          }
      else if ((level>= 4)&&(level<5)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(3, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(4, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(5, 0, 128, 0);
          delay(30);
         strip.show ();
      }
      else if ((level>= 5)&&(level<6)) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(3, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(4, 0, 128, 0);
          delay(30);
        strip.show ();
       strip.setPixelColor(5, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(6, 0, 128, 32);
          delay(30);
         strip.show ();
      }
      else if (level>= 6) {
       strip.clear();
       strip.setPixelColor(0, 128, 0, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(1, 128, 32, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(2, 128, 64, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(3, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(4, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(5, 0, 128, 0);
          delay(30);
         strip.show ();
       strip.setPixelColor(6, 0, 128, 32);
          delay(30);
         strip.show ();
       strip.setPixelColor(7, 0, 128, 64);
          delay(30);
       strip.show ();
    }
}
```

body:
First, a small remark:

> ```c++
> if ((level > 0)&&(level<1))
> ```

`level` is an integer, and there is no integer that is both strictly
larger than zero and smaller than one.

> ```c++
> if ((level>= 1)&&(level<2))
> ```

There is only one integer that verifies this condition. It would be
clearer then to just write

```c++
if (level == 1)
```

Now, for your actual question: one trick that often works to shorten
repetitive code is to turn code into data, store the data in arrays and
run through them with loops. Here the sequence of colors can be stored
in an array:

```c++
const uint8_t colors[8][3] = {
    {128,   0,   0},
    {128,  32,   0},
    {128,  64,   0},
    {  0, 128,   0},
    {  0, 128,   0},
    {  0, 128,   0},
    {  0, 128,  32},
    {  0, 128,  64},
};
```

You can then call `setPixelColor()` within an loop that runs through the
array. As the end point of the loop depends on the measured level, it
could be written like this:

```c++
void leveller() {
    int level = map(analogRead(A3), 0, 1024, 1, 9);
    strip.clear();
    for (int i = 0; i < level; i++) {
        const uint8_t *color = colors[i];
        strip.setPixelColor(i, color[0], color[1], color[2]);
        strip.show();
        delay(30);
    }
}
```

Note that, since the output of `analogRead()` is always smaller than
1024, the variable `level` will always be smaller than 9, i.e. it will
take values between 1 and 8 inclusive. And that is the number of colors
that will be shown.


message:
I want to create 10 levels with one button but this code shows only level 1?

```c++
#include <Adafruit_NeoPixel.h>
const int PIN = 4;
const int NUMPIXELS = 10;
const int BUTTONPIN = 6;
int buttonState = 0;
int PINState = 0;
int level = 1;
int dt = 100;
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pinMode(BUTTONPIN, INPUT);
  Serial.begin(9600);
}

void loop(void) {
Serial.println(buttonState);
  buttonState = digitalRead(BUTTONPIN);
  if (digitalRead(BUTTONPIN) == HIGH) {
    if (buttonState == 0) {
      buttonState = 1;
    } else {
      buttonState = 0;
    }
  }

  if (buttonState == 1) {
    opdracht(level);
  }
  else {
    if (level >= 10) {
      level++;
    } else {
      level = 1;
    }
    pixels.clear();
  }
}

//level 1
//void opdracht1() {
//  pixels.setPixelColor(0, pixels.Color(150, 0, 0));
//  pixels.setPixelColor(5, pixels.Color(0, 0, 150));
//  pixels.show();
//}

void opdracht(int x) {
  if (x == 1) { //level 1
    pixels.setPixelColor(0, pixels.Color(150, 0, 0));
    pixels.setPixelColor(5, pixels.Color(0, 0, 150));
    pixels.show();
  }

  if (x == 2) { //level 2
pixels.setPixelColor(8, pixels.Color(150, 0, 0));
pixels.setPixelColor(6, pixels.Color(150, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 150));
pixels.show();
  }
```

body:
You forgot to ask a question. So I will assume the intended question is
“Why does this code always show level 1?” and I will try to answer that.

The variable `level` is defined here:

```c++
int level = 1;
```

Its initial value is 1. Then it is updated here:

```c++
if (level >= 10) {
  level++;
} else {
  level = 1;
}
```

The first time this section of code runs, `level` has its initial value,
namely 1. The condition in the `if` evaluates to false, then the
statement

```c++
level = 1;
```

is executed, which assigns the value 1 to `level` (which has no effect,
as that was already its value anyway).

The next time that section of code runs, `level` has still the vale 1,
and the effect is the same as the previous time.


message:
Programming an arduino using only switches to give 0 or 1

I am not too experienced about the working of arduino but I know that it involves data in computer language  ( 0 and 1)

I have an array of 8 switches plus a few extra. As I am unable to (due to some reasons) program it through my pc, I wanted to know if it is possible to manually use switches to send data and program it? (complexity doesn't matter).

If yes, then could you tell me how I could do it (taking into consideration my limited knowledge).

If no then why?

body:
Short answer: If you are unable to program your Arduino using a computer, you are unable to program your Arduino at all.

The Arudino is built to be programmed using a serial interface (usually USB) that interacts with the bootloader, plus an IDE on the other end of the cable. It is not set up to be programmed with switches.

You could conceivably build an Arduino programmer that would let you enter a program using 8 switches plus an enter button. Such a programmer would collect the program into a memory buffer, and then load it into the Arduino using the USB interface but it would take WEEKS of working constantly to enter the simplest of programs, and the odds that you could do it without multiple errors is pretty much zero. Plus, it would probably cost several hundred dollars to build such a programmer. It would be a pointless exercise in masochism.

(Not to mention the fact that you would have to somehow compile your Arduino program into machine code, and convert that into binary in order to enter it.)

Some of the earliest computers required that the operator enter the first few instructions via switches as you describe, and then the computer would read and begin executing the rest of its program from a tape drive. Those computers only had a few thousand bytes of memory, and even then, the instructions the operator had to enter were just enough to start the machine booting from tape.


body:
While not *physically* impossible it would be a really silly thing to attempt.

However, if *I* were to attempt it I'd probably use just 3 switches (or rather 2 switches and one button though you could use a switch instead of the button).

I'd wire it up so that the RESET, MISO and SCK pins were all connected to the switches in such a way that I could hold the whole board in RESET for extended periods (i.e., switch between RESET and GND), set a HIGH or a LOW as needed on the MISO pin, and toggle the SCK pin HIGH and LOW (I'm not sure off hand if you need to idle LOW or HIGH with the clock - the datasheet will tell you).

Then I'd become extremely intimate with the ICSP protocol of the ATMega328P.

That would then allow me, extremely slowly, to act like a hardware programmer and instruct the ATMega328P to program itself with data I sent.

You might also like to attach a shift register to the MOSI and SCK pins with 8 LEDs on it so you can monitor the responses from the Arduino while programming.

It would take forever to upload even the simplest of programs, and the error rate would be far to high, but it *could* be done if you were *really* desperate and had nothing else to do (including eat or sleep) for a number of days.


message:
9 volt battery not being able to power motor driver

Currently I am using a 9 Volt Duracell A one like this:
[![enter image description here][1]][1]

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

I am using it to power a motor driver which contains 2 motors within. I  can see where the main problem is coming and that is to do with that the voltage is not big enough. But I don't understand why this is. I see in the manual for the robot that I am building it is using a smaller voltage battery than what I am using. I tried using another set of batteries but the motors did not move at all then. The 9V Duracell battery that I am currently using has only been used for about a week (so it probably hasn't ran out), its practically brand new.

body:
It is likely not a question of the voltage being "big enough". You do need to feed the correct voltage to your robot, but max current and capacity are also very important.

Those "9V transistor batteries" have very low peak current and very low total power capacity (measured in milliamp-hours, or mAh.) They are not up to the job of powering motors. You could easily drain a 9V battery like that in 15 minutes, much less a week.

You should connect 6 D cells in series, and use that instead. That would give you enough peak current and total capacity for your robot.


message:
Using Arduino to create a countdown that unlock a box

Am new to Arduino. So permit me if I sound so novice.

I want to create a countdown device (a clock that will countdown or something) that will unlock a box when the time is up.

As an example, let say, I set the clock to start counting down from 2hours, but when it remains 5mins for the countdown to elapse, the box will unlock

What are the things needed for it to work as all examples I see are mostly for opening the door or box when the temperature changes.

body:
This sounds as an escape room puzzle.
From an electronic point of view you need something to lock/unlock the box like a servo motor, a stepper motor or (best option) a normally closed solenoid. You might need some components to drive such locking mechanism, like a mosfet or transistor (possibly a darlington), depending on which device you choose and what voltage it requires to operate. Simplest solution is a servo motor which doesn’t require anything, but has a low torque, meaning the box can easily be forced. Most robust and reliable solution is a NC solenoid, common ones are 12V so you’ll need a p-channel enhance mosfet and a couple of resistors to drive it from an Arduino.

To display the time you’ll probably want to go for an LCD, common ones are 16 col x 2 rows, most have an integrated chip to drive them using only a few wires.

Apart from that, you need a battery pack (voltage and power depending on your locking circuit choice) and may be a push button (for safety unlock).

From a software perspective you want to create a loop which starts by locking the box and then counts down the time: when the time left is less than 5 mins it activates the unlocking mechanism circuit.

    int current = 0;
    const int max = 2 * 60 * 60; // 2hrs in sec
    const int grant = 5 * 60; // 5mins in sec
    bool unlocked = false;

    void setup() {
        lock();
    }

    // executed once every second
    void loop() {
        // any safety open check should be performed here...
        // if still locked and less than 5 mins to end
        if (!unlocked && current > max - grant) {
            unlock();
        }

        display(current++);
        wait(1000);
    }

    // does what it is needed to unlock and sets the unlocked variable to true
    void unlock() { ... }

    // does what it is needed to lock and sets the unlocked variable to false
    void lock() { ... }

    void display(int secs) {
        int h = secs / (60 * 60);
        int m = (secs / 60) % 60;
        int s = secs % 60;
        // display on LCD the values above with the proper formatting
    }

A couple of notes:

 - if you go for a normally closed solenoid be sure to have a way to get inside the box if something goes wrong with your circuit or if the batteries get drained
 - you might want to have a hidden button or other way to force the unlock, especially for debugging and testing


message:
Help needed!!! I have an upcoming exam

I have an upcoming exam about the codes and stuff. Its about the basics like "blink with delay" and the "millis function". I need to get these things learned but i have no idea how?! Does anybody know a good site or how i can learn this?

body:
Learning to write code really takes practice - you learn far more by doing it than by reading about it. Start with the basic Blink example - search for a tutorial online if you want one, there are many - and get that running. Then play with it. Change the blink interval. Try adding a second LED, perhaps it turns off when the other turns on, for instance.

Every time you touch the code you'll have an "opportunity" to make a mistake or a typo. Fixing those will give you some insights you'll never get from reading about coding.

Once you've "squeezed all the juice" out of Blink, move on to Blink Without Delay. Run it, just as it is, at first. Than start tweaking it. Change one or both of the blinking periods. Again, try adding another LED with yet another blink rate.

These hands-on games are the best way to learn this stuff. Having someone (or Arduino Stack Exchange) who can help you when you're stuck is a great resource but the things you discover and the skills you acquire on your own when you fix your own mistakes are the ones that will stick with you (even 50 years later! ;-)


message:
Whatever components we connect to the Arduino, their grounds and 5v pin connection must be the same?

I am trying to connect different types of sensors & motors to the Arduino should I make their grounds and 5v pins on the same connection.

body:
All the grounds must be connected. They don't have to be the same physical pin - the Arduino has multiple GND pins, but they are all connected internally.

The 5V doesn't matter where you get that from, as long as it's regulated and the associated ground is connected to all the others.


message:
ESP8266 RF Calibration

As an off-Topic to my main [question][1], regarding Robodyn's Uno+Wifi - it seems that Wifi does not work ( fail to connect and fail find any network ).

Juraj advised to use External Antenna ( did not work ) and try to make an RF calibration as shown [on espressif's site][2]. Which I fail to understand how it is done.

a) Can anyone help with RF Calibration ?

b) Might it be another reason for that ?

Guy

**EDIT_1**
Just to be clear, a sלetch was uploaded and executed successfully to the ESP8266 module (Basic WiFi connect and network scan ).

**Edit_2**
[![close up pic][3]][3]

  [1]: https://arduino.stackexchange.com/questions/78808/robotdyns-unowifi-r3-atmega328pesp8266-32mb-flash-usb-ttl-ch340g-micro-usb?noredirect=1#comment174934_78808
  [2]: https://docs.espressif.com/projects/espressif-esp-faq/en/latest/development-environment/debugging.html?highlight=calibration#how-can-i-modify-the-default-method-of-rf-calibration-in-esp8266
  [3]: https://i.stack.imgur.com/sIedI.jpg

body:
You can't do anything else with the RF calibration then to clean the flash area where it is stored. There are two reason for doing it:

First is reason to delete the RF calibration area is, if it was written by different version of Espressif SDK, including changing between AT firmware and Arduino. Then it is almost always wrong. I think they changed the data structure so some values are swapped.

Second reason is if the SDK did the calibration in wrong conditions like without antenna.

There is not much information about RF calibration. The [FAQ][1] has "Please erase the RF parameters to trigger overall calibration."

The AT firmware reference has (addresses for 4MB-C1):
* blank.bin 0x3FB000 Initializes RF_CAL parameter area.
* esp_init_data_default.bin 0x3FC000 Stores default RF parameter values, has to be downloaded into flash at least once. If the RF_CAL parameter area is initialized, this bin has to be downloaded too

The esp8266 Arduino core writes the data of esp_init_data_default.bin as part of the sketch's binary.

EDIT: the SDK does the 'digital calibration' at boot. it takes some microseconds. it is not done at every boot, but after some count of resets. this can be configured in the init section

  [1]: https://docs.espressif.com/projects/espressif-esp-faq/en/latest/development-environment/debugging.html?highlight=calibration#how-can-i-modify-the-default-method-of-rf-calibration-in-esp8266


message:
Can I use and external power supply and USB at the same time on my Arduino?

Can I use the Arduino with an External wall-wart and the USB at the same time?  I need to power more LEDs, and the USB on my computer can only supply so much.  But, I didn't want to destroy my computer because I had the USB and the external plugged in.

I saw this,

https://arduino.stackexchange.com/questions/28282/external-power-supply

But I am still unsure.  The reason I want to at all is because when I connected this circuit, the Arduino would cease to be recognized on the USB.  I don't know if it is because there wasn't enough power to the LED, if I short-circuited something, or something else.  I do not wish to break my laptop though.

https://arduino.stackexchange.com/questions/893/what-happens-if-i-power-the-arduino-with-both-the-usb-and-external-power-voltage

These all seem to indicate you don't just "plug in" with both, and you need some other kind of regulator or something.  But in that same answer, one person says,

https://arduino.stackexchange.com/a/896/69706

And that indicates when the power is plugged in the USB is cut off.  Again, my fear is breaking my laptop, and that is the main question.  Especially in light of this,

https://arduino.stackexchange.com/questions/11885/is-supplying-5v-from-both-external-5v-and-usb-harmful

The external power is [this][1],

9 VDC 1000mA regulated switching power adapter

  [1]: https://www.adafruit.com/product/63

body:
Yes, you can simultaneously connect external power supply and USB. As explained in one of the answers, that you linked, the Arduino chooses it's power input through the supplied voltage on Vin/barrel jack. Vin has no direct connection to the VUSB, so the USB port will not get any voltage from the external supply, thus it does not get damaged.

**BUT:** Your thinking is wrong. Clearly your LEDs need more than 500mA. This current should never flow through the Arduino. You can easily fry the protection diode or the voltage regulator (which is an inefficient linear regulator), if you connect all the LEDs to the 5V pin. One GPIO pin can only provide about 20mA (40mA at absolute max, you should stay below 20mA) and only 100mA through all GPIOs together. They are not made to provide power, but for switching.

Instead you should connect the LEDs outside of the Arduino to the power supply. If you want to use the specified 9V power supply, you need to buy a buck switching voltage regulator, which gets the voltage down to 5V for you. Make sure, that this regulator is rated for a current significantly higher, than what you need.

**How to control the LED then?** That depends on your LEDs. If you just have some bare LEDs, you could use a transistor to switch the higher voltage from the Arduino. If you have a plain LED strip you can also use a transistor. Best use a MOSFET for this. If you have an addressable LED strip, just connect the power lines to the 5V output of your new switching regulator and the data line to the Arduino.


message:
Run HEX program from SD with another program

I want to write a program in which I can select a HEX file recorded on a SD card (via a LED screen, etc.) and run it, i.e. transfer control to it, like launching programs on a PC. Is this possible and if so, how? I only found ways to directly run a sketch from an SD card without that "program"

body:
Not with an Uno, no, it's not possible. Or it's very very hard and the results would be less than desirable. You need a proper MCU with lots of RAM and the ability to run code from it, which you can't with an Uno.

It would be less work to write your own scripting language to control things from a text file.


body:
The HEX files on SD card would have to be linked for a specific address in flash. Normal program is linked for address zero on ATmega, but the bootloaders are an example on how to link for specific address in flash.

Then you could use the do_sdm() function provided by Optiboot 8 (see [the example][1]) to write the bytes from the HEX file to the right location in flash memory. Next step would be to call the start address as function same way as do_spm() is made accessible with optiboot.h in the example.

```
typedef void (*loaded_function_t)();

const loaded_function_t loaded_function = (loaded_function_t)(ADDRESS_OF_LOADED_FUNCTION);
```
then you can use
```
  Serial.prinln("Execute the loaded code...);
  loaded_function();
  Serial.prinln("Loaded code finished.");
```

  [1]: https://github.com/Optiboot/optiboot/blob/master/optiboot/examples/demo_dospm/demo_dospm.ino


message:
Stepper motor not working as expected

Kunal Gupta:
Guys plss help me .... I am having issues in using stepper motor

I have tried both 28bjy with uln2003 and l293d .. giving it output supply of 5V .
Motor is vibrating but its shaft is not moving.
And even if shaft runs then it is different from what is expected by the logic of code

Similarly tried NEMA 17 stepper motor 4.5 KG using drv8825 driver and L293D driver ... Giving 12 v external supply.

And same results as 28bjy .... motor vibrating but its shaft is mot moving as expected or absolutely not moving

I have read and understood all the concept of driving stepper motor by full step method and hafl step method ....and using at first direct examples from net .. but still not figuring out what is the problem

body: Try  lowering the rpm in the code. I had a similar issue with anything over about 18rpm using certain libraries with certain stepper motors.


message:
Arduino Uno R3, WS2812B, 1 strip of 60 leds, segmented in to 4

.

Problem: Only want a single segment/fx_mode to run at any one time.

---

    #include <WS2812FX.h>

    #define LED_COUNT 60

    #define LED_PIN 13

    WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

    void setup() {

    ws2812fx.init();

    ws2812fx.setBrightness(85);

    // divide the strip of 60 LEDs in to 4 segments

    ws2812fx.setSegment(0,  0, 14, FX_MODE_COMET, BLUE,  3000, false);

    ws2812fx.setSegment(1, 15, 29, FX_MODE_SCAN, RED, 3000, true);

    ws2812fx.setSegment(2, 30, 44, FX_MODE_SCAN, BLUE,  3000, false);

    ws2812fx.setSegment(3, 45, 60, FX_MODE_SCAN, RED, 3000, true);

    ws2812fx.start();
    }

    void loop() {

    ws2812fx.service();
    }

body:
The used library doesn't give you the direct possibility to automate the segment changes. So you need to write that code yourself.

Currently you are setting up all segment in `setup()` and starting them together via `start()`. Instead you should add the corresponding segment only, when it should be on, and removing all segments, that should not run. In the following I don't remove and add a segment, but I'm replacing the previous segment (described below)

I propose a code like the following, to light up each element after the other for a specific time each (**not tested**):

    #include <WS2812FX.h>

    #define LED_COUNT 60

    #define LED_PIN 13

    #define SEGMENT_INTERVAL    3000
    unsigned long segment_timestamp;
    uint8_t current_segment = 0;
    #define SEGMENT_N   4

    WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

    void setup() {
        ws2812fx.init();
        ws2812fx.setBrightness(85);
        ws2812fx.start();
    }

    void loop() {
        if(millis()-segment_timestamp > SEGMENT_INTERVAL){
            segment_timestamp += SEGMENT_INTERVAL;
            switch(current_segment){
                case 0:
                    ws2812fx.setSegment(0,  0, 14, FX_MODE_COMET, BLUE,  3000, false);
                    break;
                case 1:
                    ws2812fx.setSegment(0, 15, 29, FX_MODE_SCAN, RED, 3000, true);
                    break;
                case 2:
                    ws2812fx.setSegment(0, 30, 44, FX_MODE_SCAN, BLUE,  3000, false);
                    break;
                case 3:
                    ws2812fx.setSegment(0, 45, 60, FX_MODE_SCAN, RED, 3000, true);
                    break;
            }
            current_segment = (current_segment + 1) % SEGMENT_N;
        }
        ws2812fx.service();
    }

**What happens here?** First we use the `millis()` function in the pattern of the `BlinkWithoutDelay` example to time the change of segments to every 3s (3000ms) without blocking the execution of the other code (here the service routine of the LED animation). I will not go into detail here, since this principle is described at numerous places through the web and this site. Just search for something like "Arduino millis" or "Arduino Blink without delay". Now is only important, that the code inside the if statement will be executed every 3s (can be changed with `SEGMENT_INTERVAL`).

In the if statement we use a switch statement to set the corresponding segment, that should be activated at that time. Here we always set the segment 0, since only one segment is active at any time. Instead of removing the previous segment and adding the new one, we just change the previous segment to the data of the new segment.

With the line

    current_segment = (current_segment + 1) % SEGMENT_N;

we increment to the next segment, while wrapping around from segment 3 to segment 1 via the modulo operator `%`. This is needed to loop through the segments.

The call to `ws2812fx.service()` is still needed, since it handles the actual animation of the current segment.

---

Note, that the above code can still be improved. You could save all the segment data in an array of structs and replace the switch statement with one line, using the `current_segment`'th element of the array. I will leave that improvement to you.


message:
Uploading sketch to ATTiny84 with Nano as "Arduinio as ISP" stopped working

Update 12/11
Working through the answer posted.

* Upload reset appearance - [Works blinks correctly.]
* Convince yourself that reset appearance code reliable indicates DTR resets. [Opened the serial monitor 5-6 times, nothing changed or blinked]
* 10uF cap between Arduino Nano RESET and adjacent GND. [Done]
* Plug the board back in and you should see the LED Blink rapidly for the power-on (not DTR) reset. [Blinks rapidly same as after upload of sketch in Step one]
* Open (or Reopen) the serial monitor and see that the LED remains OFF. [No LED's]
* Break the RESET leg of whatever circuit you chose for defeating DTR reset. Upload the ArduinoISP sketch [Uploaded and verified, no problem]
* You should see a signature check error like this: [Yes this error occured same message as you posted]
* Upload Empty sketch [ IT WORKS !!!!!]
* Check using one of my previous sketchs [WOOT! It works]

Thanks, that resolved the issue!! (although I've aready bought a universal programmer because I didn't think I would ever get it working).

Update - 11/Nov

As suggested, I have taken the nano out of any board and it is dangling from the USB cable. I have tried to upload the default sketch.
```
void setup() {
  // put your setup code here, to run once:

}

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

}
```
using the settings:
* Board Attiny22/44/84
* Processor Attiny84
* Programmer Arduino as ISP

I still get the problem of programmer not responding. Did this for all 3 nanos I have available.

===

Update - 11/nov
I have now wiped all the IDE from my machine and reloaded. I have attempted to program an ATmega168PA instead of the tiny. Same problem.

Update - 10/nov:

After swapping between 2 different nanos and different capacitors to check that the cap is working. I noticed some different behavour. Nano A fails as below, however Nano B fails, but the message is slightly different. Instead of resp=0x00 I have resp=0xFF

Also on Nano B the L light doesn't flash it is on constantly and the 10 getsync messages go really fast.

---

I really could do with a solution if anyone has one.

I am trying to upload a sketch into a ATTiny84 with Nano as "Arduinio as ISP". This worked last week, same sketch, no changes. I have attempted to troubleshoot:

Changed ATTiny chips, changed between 3 different Nanos (and even bought another which also failed), I have changed all the USB cables, changed all the wires. I have installed the IDE on different machines.

In summary, I have tried:

*    3 different machines: Linux, Raspberry Pi, Windows 10
*    7 different ATTiny84 chips (I have ten, but don't want to use the other 3 in case this is bricking them!)
*    4 different Nanos
*    different USB cables, different wires, replaced the capacitors

I have triple checked the configuration. Nothing seems to fix the problem.

I have no issue with any of the Nanos, I can use them directly, but just can't seem to use them to push into the AVR. It worked with the same configuration for weeks, now it doesn't. I'm really scratching my head.

I'm using:
* [ATTiny core][1] by David A. Mellis
* Boards: Attiny24/44/84
* Processor: Attiny84
* Clock: Internal 1 Mhz
* Programmer: Arduinio as ISP
* "Upload using Programmer"

Verbose Error messages:

```
Arduino: 1.8.13 (Linux), Board: "ATtiny24/44/84, ATtiny84, Internal 1 MHz"

/home/rick/arduino-1.8.13/arduino-builder -dump-prefs -logger=machine -hardware /home/rick/arduino-1.8.13/hardware -hardware /home/rick/.arduino15/packages -hardware /home/rick/Arduino/hardware -tools /home/rick/arduino-1.8.13/tools-builder -tools /home/rick/arduino-1.8.13/hardware/tools/avr -tools /home/rick/.arduino15/packages -built-in-libraries /home/rick/arduino-1.8.13/libraries -libraries /home/rick/Arduino/libraries -fqbn=attiny:avr:ATtinyX4:cpu=attiny84,clock=internal1 -vid-pid=1A86_7523 -ide-version=10813 -build-path /tmp/arduino_build_476590 -warnings=default -build-cache /tmp/arduino_cache_440110 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.arduinoOTA.path=/home/rick/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/rick/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/rick/arduino-1.8.13/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/rick/arduino-1.8.13/hardware/tools/avr -verbose /home/rick/Arduino/Light_detector_Example/Light_detector_Example.ino
/home/rick/arduino-1.8.13/arduino-builder -compile -logger=machine -hardware /home/rick/arduino-1.8.13/hardware -hardware /home/rick/.arduino15/packages -hardware /home/rick/Arduino/hardware -tools /home/rick/arduino-1.8.13/tools-builder -tools /home/rick/arduino-1.8.13/hardware/tools/avr -tools /home/rick/.arduino15/packages -built-in-libraries /home/rick/arduino-1.8.13/libraries -libraries /home/rick/Arduino/libraries -fqbn=attiny:avr:ATtinyX4:cpu=attiny84,clock=internal1 -vid-pid=1A86_7523 -ide-version=10813 -build-path /tmp/arduino_build_476590 -warnings=default -build-cache /tmp/arduino_cache_440110 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.arduinoOTA.path=/home/rick/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/rick/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/rick/arduino-1.8.13/hardware/tools/avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/rick/arduino-1.8.13/hardware/tools/avr -verbose /home/rick/Arduino/Light_detector_Example/Light_detector_Example.ino
Using board 'ATtinyX4' from platform in folder: /home/rick/.arduino15/packages/attiny/hardware/avr/1.0.2
Using core 'arduino' from platform in folder: /home/rick/arduino-1.8.13/hardware/arduino/avr
Detecting libraries used...
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=attiny84 -DF_CPU=1000000L -DARDUINO=10813 -DARDUINO_attiny -DARDUINO_ARCH_AVR -I/home/rick/arduino-1.8.13/hardware/arduino/avr/cores/arduino -I/home/rick/.arduino15/packages/attiny/hardware/avr/1.0.2/variants/tiny14 /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Alternatives for SendOnlySoftwareSerial.h: [SendOnlySoftwareSerial]
ResolveLibrary(SendOnlySoftwareSerial.h)
  -> candidates: [SendOnlySoftwareSerial]
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=attiny84 -DF_CPU=1000000L -DARDUINO=10813 -DARDUINO_attiny -DARDUINO_ARCH_AVR -I/home/rick/arduino-1.8.13/hardware/arduino/avr/cores/arduino -I/home/rick/.arduino15/packages/attiny/hardware/avr/1.0.2/variants/tiny14 -I/home/rick/Arduino/libraries/SendOnlySoftwareSerial /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Using cached library dependencies for file: /home/rick/Arduino/libraries/SendOnlySoftwareSerial/SendOnlySoftwareSerial.cpp
Generating function prototypes...
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=attiny84 -DF_CPU=1000000L -DARDUINO=10813 -DARDUINO_attiny -DARDUINO_ARCH_AVR -I/home/rick/arduino-1.8.13/hardware/arduino/avr/cores/arduino -I/home/rick/.arduino15/packages/attiny/hardware/avr/1.0.2/variants/tiny14 -I/home/rick/Arduino/libraries/SendOnlySoftwareSerial /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp -o /tmp/arduino_build_476590/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
/home/rick/arduino-1.8.13/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_476590/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-g++ -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=attiny84 -DF_CPU=1000000L -DARDUINO=10813 -DARDUINO_attiny -DARDUINO_ARCH_AVR -I/home/rick/arduino-1.8.13/hardware/arduino/avr/cores/arduino -I/home/rick/.arduino15/packages/attiny/hardware/avr/1.0.2/variants/tiny14 -I/home/rick/Arduino/libraries/SendOnlySoftwareSerial /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp -o /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp.o
Compiling libraries...
Compiling library "SendOnlySoftwareSerial"
Using previously compiled file: /tmp/arduino_build_476590/libraries/SendOnlySoftwareSerial/SendOnlySoftwareSerial.cpp.o
Compiling core...
Using precompiled core: /tmp/arduino_cache_440110/core/core_attiny_avr_ATtinyX4_cpu_attiny84,clock_internal1_8328ca5f502560caf6997d9e8039b097.a
Linking everything together...
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-gcc -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=attiny84 -o /tmp/arduino_build_476590/Light_detector_Example.ino.elf /tmp/arduino_build_476590/sketch/Light_detector_Example.ino.cpp.o /tmp/arduino_build_476590/libraries/SendOnlySoftwareSerial/SendOnlySoftwareSerial.cpp.o /tmp/arduino_build_476590/../arduino_cache_440110/core/core_attiny_avr_ATtinyX4_cpu_attiny84,clock_internal1_8328ca5f502560caf6997d9e8039b097.a -L/tmp/arduino_build_476590 -lm
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_476590/Light_detector_Example.ino.elf /tmp/arduino_build_476590/Light_detector_Example.ino.eep
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino_build_476590/Light_detector_Example.ino.elf /tmp/arduino_build_476590/Light_detector_Example.ino.hex
Using library SendOnlySoftwareSerial in folder: /home/rick/Arduino/libraries/SendOnlySoftwareSerial (legacy)
/home/rick/arduino-1.8.13/hardware/tools/avr/bin/avr-size -A /tmp/arduino_build_476590/Light_detector_Example.ino.elf
Sketch uses 1666 bytes (20%) of program storage space. Maximum is 8192 bytes.
Global variables use 152 bytes (29%) of dynamic memory, leaving 360 bytes for local variables. Maximum is 512 bytes.
/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -pattiny84 -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/tmp/arduino_build_476590/Light_detector_Example.ino.hex:i

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

         System wide configuration file is "/home/rick/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/rick/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

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

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

```

[![My setup][2]][2]
* VCC & GND connected
* White wire (Pin 9) -> D13
* Yellow wire 1 (Pin 8) -> D12
* Red wire (Pin 7) -> D11
* Yellow wire 2 (Pin 4) -> D10
* 10 Capacitor between RST & Gnd

The only change I can remember making was adding a library for SerialOutOnly. But I did a clean install on the Windows and Rasberry with only the ATTiny libraries and it still does the same time.

People missed my comment, so I've uploaded a second photo of the entire breadboard. It is powered there are two wires which were out of frame in the first photo.

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

  [1]: https://github.com/damellis/attiny
  [2]: https://i.stack.imgur.com/7tLDl.jpg
  [3]: https://i.stack.imgur.com/MkG4m.jpg

body:
From your picture, it looks like your ATtiny84 is not powered (connected to unpowered power rails).

The positive (red) and negative (blue) rails on both sides of a breadboard are usually not connected. You should either manually connect the power rails on opposite sides of your breadboard or connect your ATtiny power pins (1 and 14) to the corresponding rail on the other side of your board. See below (apologies for the crude drawing).

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

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


body:
Differences in my environment
=============================
I don't have a normal Nano on a ATTiny84 on hand at this moment.

For our purposes, I'm using the ATTiny44, which is essentially what you have, only with smaller memories.  The Nano that I'm using is Nano Clone that I have retrofitted with a ATMega328PB rather than the regular 328P.  To make matters slightly more confusing it is running the regular UNO (rather than NANO) bootloader.  The bootloader lies about the chip signature (saying it is 328P) and uses the UNO baudrate 115200 rather than the Nano's 57600.  So you will see in my screenshots/examples and menu selections "UNO" rather than "Nano", "328PB" rather than "328P", and "ATTiny44" rather than "ATTiny84."

These differences are inconsequential.

Build trust in your RESET-defeating mechanism
=============================================

Upload reset appearance code
----------------------------

Remove all external circuitry from your Nano.  All means ALL.  That includes
whatever you did to defeat reset as well.

Choose Arduino Nano from the Tools/Boards menu.
Choose your Arduino Nano's port from the Tools/Port menu.

Upload the following sketch:

````c++

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

void loop() {
  static bool led_state;
  static size_t toggle_counter;

  if (toggle_counter < 20LU * 6) {
    led_state = !led_state;
    digitalWrite(LED_BUILTIN, led_state);
    delay(50);
    ++toggle_counter;
  }
}
````
The LED should blink rapidly for 6 seconds and then remain off indefinitely.

The Nano's optiboot bootloader blinks the builtin pin 13 LED three times, but it is a very short event and maybe difficult to distinguish form SPI clock action (which also happens on pin 13).  By contrast, it's hard to miss the blinking that this code produces.

Convince yourself that reset appearance code reliable indicates DTR resets.
--------------------------------------------------------------------------
Open (or Reopen) the serial monitor and see that it does this again.  Close and
Reopen the serial monitor however many times you want until you feel
comfortable that you're seeing clear indication of the board having reset.

Install your DTR RESET-defeat circuitry for a test.
-----------------------------------------------
Unplug your board and install your choice of reset defeating circuitry.

The typical suggestion is a 10uF cap between Arduino Nano RESET and adjacent
GND.  Make sure you don't have your electrolytic cap backwards.

I frequently use a hard pullup of about 60 Ohms.

Plug the board back in and you should see the LED Blink rapidly for the
power-on (not DTR) reset.

Convince yourself that DTR reset has been defeated.
---------------------------------------------------
Open (or Reopen) the serial monitor and see that the LED remains OFF.
Reopen the serial monitor however many times and see that the LED stays OFF.

Upload the arduinoisp.ino sketch
================================

NOTE: At time of writing the current IDE version is 1.8.13.  Though, everything
said here should be find for old and likely future IDE/arduinoisp.ino releases.

In the IDE, from menu File/Examples/11.ArduinoISP, choose the ArduinoISP
sketch.  In its current from in IDE 1.8.13 it requires no modifications for a factory-fresh ATTiny84(A) (or pretty much any AVR), that is with its default configuration fuse values.

Break the RESET leg of whatever circuit you chose for defeating DTR reset.

Upload the ArduinoISP sketch.

You should see that the LED does NOT blink rapidly for 6 seconds as it had previously.
This should indicate that you have successfully uploaded the arduinoisp.ino sketch.

Reconnect RESET leg of whatever circuit you chose for defeating DTR reset.

Attempt to program (without target chip attached) to see that you do not get SYNC errors.
=========================================================

Open a new empty sketch.

Choose your target chip's settings from the Boards menu.  That is your D.
Mellis ATTiny84 "board" should be selected.  Or more generally: any compatible "board" from any board support package that supports whatever AVR you want to do this with.

Verify that your Arduino Nano's port is still selected in Tools/Port menu.

From the Tools/Programmer select "Arduino as ISP".  Barring some internationalization effort, it should say exactly that. It should NOT say "ArduinoISP" or "ArduinoISP.org".  Yes, the Arduino people are usually BAD at picking names.

Choose "Upload using programmer".

You should see a signature check error like this:

````
avrdude: AVR device initialized and ready to accept instructions

An error occurred while uploading the sketch
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x00ffff
avrdude: Expected signature for ATtiny44 is 1E 92 07
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.
````

You may need to turn on "Verbose" for uploading in preferences.

Because you have not wired anything to the SPI pins the returned device
signature will be pure junk.  The important thing here is you got a device
signature failure and NOT a sync error.  A sync error represents failure of avrdude to talk to the arduinoisp.ino sketch's implementation of the STK500v1 programming protocol.  What you're seeing here is successful STK500v1 communication (to arduinoiso.ino) reporting a perfectly reasonable failure to identify the chip (that you have not even attached yet).

Wire your ATTiny84 (or whatever)
================================

Unplug your Nano and wire AVR to it.  With the exception of your attempt to use VIN, I didn't notice anything wrong with your wiring.

The ATTiny84 should be wired as:

````
Nano 5V (not VIN) to ATTiny84 pin  1
Nano GND          to ATTiny84 pin 14
Nano PIN 13       to ATTiny84 pin  9
Nano PIN 12       to ATTiny84 pin  8
Nano PIN 11       to ATTiny84 pin  7
Nano PIN 10       to ATTiny84 pin  4
````

Or more broadly for any ISP supporting AVR tiny/mega:

````
Nano 5V (not VIN) to ALL AVR (A)VCCs.
Nano GND          to ALL AVR GNDs
Nano PIN 13       to AVR (U)SCK
Nano PIN 12       to AVR MISO
Nano PIN 11       to AVR MOSI
Nano PIN 10       to AVR RESET
````

You may want to add a pull-up resistor from the target AVR's RESET to its VCC.  This should be not needed for use with arduinoisp.ino sketch, but you might want it for running on the breadboard.  You may also want to add a decoupling cap between your AVR's VCCs and GND.  I've never needed this for just programming on solderless breadboard though.

I don't typically use breadboard power rails when programming AVR devices with single VCC an GND pins.

Generally keep your connection short in any case.  They should not be longer than 20 cm really, and can usually be less than half that. Keep them together with the GND where possible. Your SCK signal should probably receive the most care.  I don't see anything wrong with the length of your connections.

Upload
=========================================================

Plug your Nano (and AVR wired to it) back into USB.

Make sure you power light hasn't gone out on the Nano, that it doesn't drop off the USB bus, and nothing feels hot to the touch.  That nothing smells odd.

Choose whatever you want to upload.  An empty sketch is fine for testing uploading.

Verify that Tools/Port is the port of the Nano.
Verify that the programmer is still "Arduino as ISP".
Verify that the "board" is still whatever it should be for your target chip (not the Nano).

Choose "Upload using Programmer".

You should get a successful output, that would look something like:
````
/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -pattiny44 -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/tmp/arduino_build_656744/sketch_nov12b.ino.hex:i

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

         System wide configuration file is "/home/user/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/user/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATtiny44
         Chip Erase delay              : 4500 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         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     6     4    0 no        256    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      4096   64     64  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9207 (probably t44)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino_build_656744/sketch_nov12b.ino.hex"
avrdude: writing flash (286 bytes):

Writing | ################################################## | 100% 0.46s

avrdude: 286 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_656744/sketch_nov12b.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_656744/sketch_nov12b.ino.hex:
avrdude: input file /tmp/arduino_build_656744/sketch_nov12b.ino.hex contains 286 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.22s

avrdude: verifying ...
avrdude: 286 bytes of flash verified

avrdude done.  Thank you.
````

The above was generated using the process described with my slightly different setup.

With everything being correct in the IDE, if you get SYNC error now you
probably have a wiring issue that's causing the Nano to fail, interfering with its ability to execute the stk500v1 implementation.  This was part of the thinking behind pointing out your VIN connection in the original post:

[![Vin is not 5V][1]][1]

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


message:
TQFP Atmega328pu-th cant upload sketch sync error (breadboard)

So I have a USB to ftdi connected to my qtfp 32 socket trying to upload a sketch but I get a sync error , as far as I am aware I have uploaded the sketch correctly

body: Hey guys I managed to figure it out I had to remove the dtr pin from pin 29 , I made a video to help anyone else looking to do it, I don't know if it breeches any self promotion? But hope it helps because i found it difficult to find any resources. https://youtu.be/5CPYz6Kde7M


message:
ST7789 TFT display only shows a correct image while Arduino reset button is held down - Why?

I am trying to get the ST7789 TFT display to work with Arduino. I followed online guides  for connections and am using the fast library fron github and included workbench ino (https://github.com/cbm80amiga/Arduino_ST7789_Fast).
Problem: The program runs and drives the display but the image is corrupt and only partial. I discovered that if I quickly and firmly press the reset button - and keep it pressed down - the image at the moment of reset press suddenly becomes full and good (albeit static because reset is pressed). Ofcourse as soon as I release the reset button the program restarts with the same corrupt image (the pictures below illustrate the issue).

[![This is the final screen of the demo showing the corrupt image][1]][1]
[![This is what happens when I press and hold the reset button - the image suddenly becomes nice!][2]][2]

I could not find a description of this particular problem by online searching. Here is what I tried to fix it (all to no avail):
* I confirmed all pins are correct as defined in the ino script.
* I ensure only the 3.3v power line is used. I have never connected the Vcc to 5 v
* I tried with a genuine Arduino UNO as well as a clone - both show the same behaviour.
* I used 1k:2k resistor voltage dividers for the data lines, res and DC - these did not help. In fact the display did not work at all with the voltage dividers, only the backlight came on and the screen flickered slightly. I checked that I was getting ~3v in the middle of each divider.
* I used two separate ST7789 display boards, bought from two separate sellers on different occasions - both show the same behaviour.

[Edits in response to comments below]
* The same behviour occurs when using a sketch that uses the standard Adafruit libraries (as opposed to the fast library linked above).
* The same corruption is seen when run on an arduino nano clone. However, with the nano, pressing the reset button shows only a fleeting glimpse of the full image prior to resetting (i.e. holding down the reset button does not preserve a static image on the screen).

Any ideas about what is going on and how to fix it? Thanks.

  [1]: https://i.stack.imgur.com/ZUgBV.jpg
  [2]: https://i.stack.imgur.com/sS5XO.jpg

body:
I found the answer to this problem. After reading multiple web pages / YouTube videos from multiple authors on this device and ~all of them warning you must never connect the Vcc to 5v or it will destroy the display, I found one or two that suggested you *could* use 5v because in this particular module there is a built-in regulator. So, faced with the thing being useless anyway, I decided to take the plunge and connect the Vcc of the TFT to the 5v pin of the Arduino and - hey presto - it works perfectly (see picture below: note the clear full image without the reset button being held down and also notice the voltage pin of the TFT is now connected to Arduino 5v compared to the pictures in my question).
[![enter image description here][1]][1]

The picture below shows the back of my TFT display module and, from what I have read, it is the J3Y transistor that is key to the voltage regulation in this module.
[![enter image description here][2]][2]

I hypothesise that pressing the reset button must have allowed equalisation of the voltages somehow but it is beyond my knowledge to explain it. I tried measuring the 3.3v pin on the Arduino with a voltmeter while holding down the reset button but I could see no change (the TFT module was not in situ for this test so maybe there is some interaction between Arduino and the TFT circuitry during reset).

Please note: I suspect this is a peculiarity of the particular TFT display module I have. Please DON'T run your 3.3v devices at 5v unless you have good reason to believe that they can take it. I only tried this after reading a couple of pages (including the detailed specs on the TFT module seller's listing) that suggested it would be OK with my particular TFT module - your's may be different. But if you have the same problem you see in my question then maybe that is something to consider.
Thanks to those who have responded.

  [1]: https://i.stack.imgur.com/3UYuk.jpg
  [2]: https://i.stack.imgur.com/Uv7CH.jpg


message:
Code for Degrees not

Using Audrino Nano and MKS SERVO42 42 Stepper Motor With Driver Board Closed Loop with the LCD. I have got the motor going by using the menu on board. Now able to run Code1 <https://github.com/makertut/Arduino-Closed-loop.git> out of GitHub and it runs as it is designed. Line 5 int numstep = 1030; cc runs the number of steps indicated and changing this number will determine the movement.
I can do the math to calculate the degrees for number of step for a particular stepper. I would like to use degrees instead of steps for my program. Does anybody know how to code this?
 Thanks Greg

body:
This is basic algebra 1.

Say `steps / degree = 5`

So write that as 2 fractions:

```
steps   5
----- = -
degree  1
```

Then take the reciprocal of both sides:

```
degrees   1
------- = -
step      5
```


message:
sro4m-2 waterproof ultrasonic sensor

I bought this waterproof ultrasonic sensor about 5 of them with the part number SR04M-2 Written on the PCB silkscreen Which is different from the usual SR04t-0.2, they are just not working, I don't know if its using a different communication protocol or its faulty because no output is coming out of the sensor at all.
if anyone out there has ever came across this type and was able to walk his/her way around it should help

body:
I found this code for the SRF05 and it works for the SRO4M-2 as well.
Good Luck!

```c++
const unsigned int TRIG_PIN=13; //RX
const unsigned int ECHO_PIN=12;  TX
const unsigned int BAUD_RATE=9600;

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  Serial.begin(BAUD_RATE);
}

void loop() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  const unsigned long duration= pulseIn(ECHO_PIN, HIGH);
  int distance= duration/29/2;
  if(duration==0){
    Serial.println("Warning: no pulse from sensor");
  } else {
    Serial.print("distance to nearest object:");
    Serial.println(distance);
    Serial.println(" cm");
  }
  delay(100);
}
```


body: RX = trig and TX = Echo  this is counter intuitive but it works. The manufacturer did not bother to indicate trig and echo on the PCB. I discovered this on link : https://bitbucket.org/teckel12/arduino-new-ping/issues/40/aj-sr04m-board.  When I switch RX & TX as indicated in the pics it worked


message:
need to make my partners pill box turnover sensitive

ive done some arduino stuff back in uni like 7 years ago; and reserached premade items-ive looked online at many pill organisers and the best and cheapest one is $149 and isn't shipping to the UK rite now. but basically my partner needs to take 1 pill a day without fail. second set of pills is less urgent and not an issue if he misses, but basically is there like a thing I could whip together to sense when he has turned the pill case over that day or not? maybe sync to phone(would be super useful)  so he knows when he has actually taken it.

body:
I wouldn't go with a "turn-over" sensor, but would just use a (big) button. I'd go with something like an ESP8266/ESP32. Those can connect to WiFi. Then have it send a push notification when being pressed (that is; the pill has been taken). Maybe light up an LED to also indicate the pill has been taken. Turn off the led at midnight. Also send a different notification when the button hasn't been pressed before, say noon.

For push notifications, you can use PushSafer, PushBullet, or Prowl (which I had most success with).

Have a look at Kevin Darrah [article](https://www.kevindarrah.com/wiki/index.php?title=TrigBoardV7), and youtube channel. He uses it's own boards, but most of the code will work on any ESP board.

But try to imaging how the system would work, in your head first. Just throwing technology at a problem isn't always the best solution. My grandma has 7 pill boxes, one for each week. Which helped to keep track of whether a pill was taken that day.

Best of luck.


message:
blink led 5 times with for loop

Is it possible to let a led blink, for example 5 times with Arduino?
Should I use a For loop?

Something like this works within the setup loop, but it will run continuesly in the void loop. So my led keeps blinking.

      for (int i = 0; i <= 5; i++) {
        led HIGH
        delay(500);
        led LOW
        delay(500);
      }

Also the blink sequence has to be triggered, and have a reset after it is done.
The complete code is to big to share, but it runs a bit like the following:

There is a "bankValue", it is filled by a user, and counts back to zero.
If it's zero, then blink 5 times.
After the blink, the leds are off.
The sketch is waiting for a new user, who will fill the bankValue again and the ledblink should again be initiated.

body:
Its really heavy to give a correct answer, if you don't show us the context where the for loop is used. But I'll try:

There should be a part in the void loop method where you detect that the "bankValue" is down to zero. Like:

    if (bankValue == 0)
    {

    }

First you must be sure that, the for loop is called within this block.

    if (bankValue == 0)
    {
      // I corrected the loop to run exact 5 times (<= -> <)
      for (int i = 0; i < 5; i++)
      {
        led HIGH
        delay(500);
        led LOW
        delay(500);
      }
    }

Then you need a flag `int blinkingDone = 0;`  to indicate that the for loop has executed. This flag must be initialize with a falsy value, set to trueish after the loop is done and reset if the user "fills" the bankValue again.

Then you could use it as a guard to enter the for loop. Like:

    int blinkingDone = 0;
    int bankValue = 0;

    ..... somewhere else

    if ( coin inserted or so )
    {
      // fill bankValue
      blinkingDone = 0;
    }

    ..... somewhere else

    if (bankValue == 0 && ! blinkingDone)
    {
      // I corrected the loop to run exact 5 times (<= -> <)
      for (int i = 0; i < 5; i++)
      {
        // led HIGH
        delay(500);
        // led LOW
        delay(500);
      }
      blinkingDone = 1;
    }

There are potential better ways to do it. But I don't know your code. So this is the simplest way I can imagine.


message:
Seems like I cant control 4 stepper motor at once

Im trying to control 4 stepper motors with the AccelStepper library.

Something like this:

    AccelStepper FL(1,stepPin,dirPin);
    AccelStepper FR(1,stepPin2,dirPin2);
    AccelStepper BL(1,stepPin3,dirPin3);
    //AccelStepper BR(1,stepPin4,dirPin4);

The problem is, It works just fine if I declare 3 instance of the AccelStepper, but once I uncomment the 4th one there's an error.

    Error message: Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "ESP32 Dev Module, Disabled, Default, 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

    In file included from C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1/tools/sdk/include/esp32/xtensa/xtruntime.h:30:0,

                     from C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1/tools/sdk/include/freertos/freertos/portmacro.h:80,

                     from C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1/tools/sdk/include/freertos/freertos/portable.h:94,

                     from C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1/tools/sdk/include/freertos/freertos/FreeRTOS.h:105,

                     from C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1\cores\esp32/Arduino.h:32,

                     from sketch\Test_file.ino.cpp:1:

    C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1/tools/sdk/include/esp32/xtensa/config/specreg.h:40:13: error: expected unqualified-id before numeric constant

     #define BR  4

                 ^

    C:\Users\Parit\Desktop\Test_file\Test_file.ino:31:14: note: in expansion of macro 'BR'

     AccelStepper BR(1,stepPin4,dirPin4);

                  ^

    Multiple libraries were found for "WiFi.h"

     Used: C:\Users\Parit\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.1\libraries\WiFi

     Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\libraries\WiFi

    exit status 1

    Error compiling for board ESP32 Dev Module.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

Im not sure if the problem is the ESP 32 or the code. I use the A4988 driver to connect with all 4 stepper motors.

body:
The variable name `BR` is already used somewhere else.

Use a different variable name

    AccelStepper FL(1,stepPin,dirPin);
    AccelStepper FR(1,stepPin2,dirPin2);
    AccelStepper BL(1,stepPin3,dirPin3);
    AccelStepper BackRight(1,stepPin4,dirPin4);


message:
Sensor that detects when metal sieve is clogged with debris

I'm a newbie here and would really appreciate all kinds of suggestions and answers from the experts here.

I am trying to make a small grey water recycling system project, and for the my primary filtration process tank, I will be using a combination of Metal Sieve and Cloth filter medium.
The problem is, I will be making the system alert the user when filters are in need of changing and maintenance.
[![enter image description here][1]][1]

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

I made a quick sketch of my idea on paint, and as you can see, I am planning to make my grey water collection tank to look that way.

I am thinking of using pressure sensor to sense the change of weight in the sieve and cloth part of the tank for a minimum amount of time so that the system will not confuse water flow weight vs. the weight of the debris on the metal sieve, but I'm thinking that the pressure sensor is not waterproof.

I'm also thinking of like the laser module, and when the light breaks at certain level, meaning there is too much debris that has to be removed.
I also googled load cells or weight sensors, but I'm really sorry I'm new to this, I don't know what is the best sensor to use for my problem.

I'm thinking of a float switch a few inches on top of my metal sieve and cloth and when it does not go on a OFF state for a certain amount if time, then the sieve is clogged, but my tank could overflow..

I need something that, when the sieve is clogged, the tank will no longer accept grey water input to avoid overflow.
It has to be submersible in water too :'(

Is there a type of sensor that is most suitable for my problem?

Thank you so much everyone. Have a nice day.

body:
I would tackle this not from the point of view of the filter, but from the point of view of the water itself.

The water will be impeded by the filter. As the filter gradually clogs that impediment will increase.  The net result will be a slower flow of water through your filter.

There's a number of things you could do to detect that:

1. Measure the incoming water flow rate and the outgoing water flow rate and calculate the difference.

This would mean having all the water flowing through two flow meters which would complicate your design as the filter will no longer be able to deposit directly into the tank. But when the difference in flow between the in and out sensors gets above a certain point (to be determined by you) then you can safely say that the filter is blocked.

2. Measure the "backlog" of water. To do this the input portion of the filter will have to be sealed (or largely sealed). Again the filter will impede water flow, and the more it's clogged the more it impedes. Once the impediment becomes too high the water will start "backing up" up the input pipe as it can't get through the filter fast enough. At this time you can detect that rise in water level with a float switch.

You'd have a simpler design now, as the filter can deposit straight into the tank. Whether you want to detect the rise in water level in the incoming pipe itself or in the gap between the filter and where the pipe comes in depends largely on the size of your filter. With a large filter it may be better to have a smaller space at the top and measure in the pipe. That will "amplify" the level rise and make it easier to detect.


body: Have you considered a Differential Pressure Sensor, They can be gotten for a few dollars complete with the basic electronics and drift compensation on board.  Try looking for: nxp pressure sensor for a start. These will interface to the Arduino A/D.  I use an absolute one for barometric pressure and a differential to measure the air pressure my fish pond, this tells me if the air line is open or broken.


body:
It seems to me what you want to detect is when the filter starts backing up and the flow of water out of the filter can't keep up with the in-flow. That will let you turn off the in-flow before the tank overflows.

So put a float switch or other level sensing switch on the space **above** the filter. Set it so it trips when the water standing on top of the filter gets close to the top of the tank. If the filter gets clogged and the water can't flow through fast enough, the water level on top of the filter will start to rise, and when it gets high enough, the level sensor will trip and your Arduino can shut off the flow of gray water into the filter tank.


message:
How can I measure maximum range of my ohm meter?

Hello everyone I am working on a project that will measure ohm value of a resistor .

[Schematic / article link][1]
https://create.arduino.cc/projecthub/iasonas-christoulakis/how-to-make-an-arduino-ohm-meter-90fda8

And

Here is the code below

    int analogPin= 0;
    int raw= 0;
    int Vin= 5;
    float Vout= 0;
    float R1= 1000;
    float R2= 0;
    float buffer= 0;

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

     void loop()
    {
    raw= analogRead(analogPin);
    if(raw)
    {
    buffer= raw * Vin;
    Vout= (buffer)/1024.0;
    buffer= (Vin/Vout) -1;
    R2= R1 * buffer;
    Serial.print("Vout: ");
    Serial.println(Vout);
    Serial.print("R2: ");
    Serial.println(R2);
    delay(1000);
    }
    }

There need to be a known and another unknown resistor.

The ohm value of known resistor is supposed to be 1k ohm

So my question is, what is the max ohm range will my arduino ohm meter be able to measure of the unknown resistor with 1k reference resistor and how to calculate it?

5 - 10% accuracy is enough for me

Thanks for giving me your attention :D

  [1]: https://create.arduino.cc/projecthub/iasonas-christoulakis/how-to-make-an-arduino-ohm-meter-90fda8]Schematic

body:
Your *resolution* of the ADC (the analogRead) will be 1/1024 * 5V (since you get a reading in the range 0 to 1023), that is, you can tell the difference in increments of 5/1024 which is 0.00488V, so say roughly 0.005V.

Now, I wrote a little bit of code to work out the voltages that you would get with various values for your varying resistor:

    r1 =      0, v = 5.000
    r1 =    100, v = 4.545
    r1 =    200, v = 4.167
    r1 =    300, v = 3.846
    r1 =    400, v = 3.571
    r1 =    500, v = 3.333
    r1 =    600, v = 3.125
    r1 =    700, v = 2.941
    r1 =    800, v = 2.778
    r1 =    900, v = 2.632
    r1 =   1000, v = 2.500
    r1 =   1100, v = 2.381
    r1 =   1200, v = 2.273
    r1 =   1300, v = 2.174
    r1 =   1400, v = 2.083
    r1 =   1500, v = 2.000
    r1 =   1600, v = 1.923
    r1 =   1700, v = 1.852
    r1 =   1800, v = 1.786
    r1 =   1900, v = 1.724
    r1 =   2000, v = 1.667
    r1 =   3000, v = 1.250
    r1 =   4000, v = 1.000
    r1 =   5000, v = 0.833
    r1 =   6000, v = 0.714
    r1 =   7000, v = 0.625
    r1 =   8000, v = 0.556
    r1 =   9000, v = 0.500
    r1 =  10000, v = 0.455
    r1 =  20000, v = 0.238
    r1 =  30000, v = 0.161
    r1 =  40000, v = 0.122
    r1 =  50000, v = 0.098
    r1 =  60000, v = 0.082
    r1 =  70000, v = 0.070
    r1 =  80000, v = 0.062
    r1 =  90000, v = 0.055
    r1 = 100000, v = 0.050
    r1 = 110000, v = 0.045
    r1 = 120000, v = 0.041
    r1 = 130000, v = 0.038
    r1 = 140000, v = 0.035
    r1 = 150000, v = 0.033
    r1 = 160000, v = 0.031
    r1 = 170000, v = 0.029
    r1 = 180000, v = 0.028
    r1 = 190000, v = 0.026
    r1 = 200000, v = 0.025
    r1 = 210000, v = 0.024
    r1 = 220000, v = 0.023
    r1 = 230000, v = 0.022
    r1 = 240000, v = 0.021
    r1 = 250000, v = 0.020
    r1 = 260000, v = 0.019
    r1 = 270000, v = 0.018
    r1 = 280000, v = 0.018
    r1 = 290000, v = 0.017
    r1 = 300000, v = 0.017

You can see that the difference in voltage is only 0.005V (the ADC resolution) between r1 of 90k and 100k. Further down, you can't tell the difference (within 0.005V) of 270k and 300k.

I'm not sure how to express that as an error percentage, perhaps someone better at maths than me can do that. :)


message:
Switching from one color to another

I'm using ws2812b 2x2 LEDs and have it switching between green and red, but only one of my LEDs on my 2x2 is lighting up.

I'm using the "blink" FastLED sketch with Data pin 3 on my Arduino Uno, define led 4.

    void loop() {
     // Turn the LED on, then pause
     leds[0] = CRGB::Red;
     FastLED.show();
     delay(5000);
     // Now turn the LED off, then pause
     leds[0] = CRGB::Green;
     FastLED.show();
     delay(5000);
    }

body:
For changing the led color or making any other led to glow you have to put the led number instead of `leds[led number]`  in this case so your code will basically look like.

    void loop() {
     // Turn the LED on, then pause
     leds[0] = CRGB::Red;
     leds[1] = CRGB::Red;
     leds[2] = CRGB::Red;
     leds[3] = CRGB::Red;
     FastLED.show();
     delay(5000);
     // Now turn the LED off, then pause
     leds[0] = CRGB::Green;
     leds[1] = CRGB::Green;
     leds[2] = CRGB::Green;
     leds[3] = CRGB::Green;
     FastLED.show();
     delay(5000);
    }

Hope this helps


body:
This is an addition to the answer of xbox gamer (which I upvoted), to prevent much duplicated code.

**`For` loop**

First we see, the 4 LEDs are made red or green (using green in the following case):

    leds[0] = CRGB::Green;
    leds[1] = CRGB::Green;
    leds[2] = CRGB::Green;
    leds[3] = CRGB::Green;

For this a `for` loop can be used counting from 0 to (excluding) 4:

    for (led = 0; led < 4; led++)
    {
        leds[led] = CRGB::Green;
    }

**Variant 1: Color argument**

Next we see the first and last lines are almost identical. For this we can make a function, and change the variable items (like the color) with a variable passed to that function, which is called an argument:

First we create the `loop` function:

    void loop()
    {
       turnLEDs(CRGB::Red);   // Turn LEDs on (i.e. red), then pause
       turnLEDs(CRGB::Green); // Turn LEDs off (i.e. green), then pause
    }

Then we need to make just a single function to change the color (place this before the `loop` function. The type of the color is `enum HTMLColorCode`, see http://fastled.io/docs/3.1/struct_c_r_g_b.html.

    void turnLEDs(enum HTMLColorCode color)
    {
        for (led = 0; led < 4; led++)
        {
            leds[led] = color;
        }
        FastLED.show();
        delay(5000);
    }

**Variant 2: Boolean argument**

Another way, is to not pass the color, but pass ON or OFF, which is a boolean.
For this we can use the so-called ternary operator: `a ? b : c` which means: if `a` is true, use `b`, otherwise `c`. We get:

    void turnLEDs(bool enable)
    {
        for (led = 0; led < 4; led++)
        {
            leds[led] = enable ? CRGB::Red : CRGB::Green;
        }
        FastLED.show();
        delay(5000);
    }

    void loop()
    {
       turnLEDs(true);
       turnLEDs(false);
    }


message:
Send custom HID values instead of keys

I've been building a small macro keypad based on the ATmega32U4. So far, I've been able to send standard key presses to the host. But since I want a program on the host system to react to the key presses, I only send the keys to serial to avoid typing anything. For now, this does work.

I want to send custom HID values to the host which won't result in regular key presses. As I've been reading around different blog and forum posts, most of them are just about building a regular keyboard or gamepad but don't go into how to make use of anything else.

This is what I got so far:
```
#include <Keypad.h>

const byte rows = 3;
const byte cols = 5;

char keys[rows][cols] = {
  { '1', '2', '3', '4', '5' },
  { 'q', 'w', 'e', 'r', 't' },
  { 'a', 's', 'd', 'f', 'g' }
};

byte rowPins[rows] = { 10, 16, 14 };
byte colPins[cols] = { 9, 8, 7, 6, 5 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

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

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}
```
The only obvious way I see to achieve this is to change the keys array but I don't know to which values.

----------

**UPDATE**

I changed the code according to the answer by Majenko:

```
#include <HID-Project.h>
#include <HID-Settings.h>

uint8_t rawhidData[255];

byte rows[] = { 10, 16, 14 };
byte cols[] = { 9, 8, 7, 6, 5 };

const int rowCount = sizeof(rows)/sizeof(rows[0]);
const int colCount = sizeof(cols)/sizeof(cols[0]);

void setup() {
  for (int row = 0; row < rowCount; row++) {
    pinMode(rows[row], OUTPUT);
    digitalWrite(rows[row], HIGH);
  }

  for (int col = 0; col < colCount; col++) {
    pinMode(cols[col], INPUT_PULLUP);
  }

  RawHID.begin(rawhidData, sizeof(rawhidData));
}

void loop() {
  for (int row = 0; row < rowCount; row++) {
    digitalWrite(rows[row], LOW);

    for (int col = 0; col < colCount; col++) {
      if (digitalRead(cols[col]) == LOW) {
        String coordinatesString = String(row+1) + String(col+1);
        uint8_t coordinates = coordinatesString.toInt();

        uint8_t megabuff[sizeof(coordinates)];

        megabuff[0] = coordinates;

        RawHID.write(megabuff, sizeof(megabuff));

        while (digitalRead(cols[col]) == LOW) {
          delay(50);
        }
        break;
      }
    }

    digitalWrite(rows[row], HIGH);
  }
}
```

I removed the serial output since I don't need that anymore. The code looks crude and needs further refactoring but it does work.

body:
HID is a strange beast to get your head around.

It operates by way of "Report Descriptors". These are "maps" that lay out what the values you send mean. It's these descriptors that make a keyboard a keyboard and a mouse a mouse.

When you use `Keyboard.h` you attach a Keyboard report descriptor to the USB HID endpoint, and the computer knows to interpret the data coming in as keypresses. When you use `Mouse.h` you attach a Mouse report descriptor and the computer knows to interpret the data coming in as mouse movements and button presses.

If you want your computer to ignore the data that you send and allow your own program to be able to receive the raw data instead then you need to use a descriptor that the computer doesn't recognise. In such a case it just ignores the data.

There's a "Raw HID" library for Arduino that does that - it uses a "blank" report descriptor that just gives you a plain 64 byte block of data to do what you want with.

There's a good [HID library by Nico Hood](https://github.com/NicoHood/HID) that implements the raw mode (as well as others).

For receiving the data on your computer you will have to have your program directly interface with the USB HID system. There's plenty of libraries for most languages to do this for you ([hidapi](https://github.com/signal11/hidapi) in C / C++, [hid](https://pypi.org/project/hid/) in Python, [hid4java](https://github.com/gary-rowe/hid4java) for Java, etc).


message:
ESP-NOW with esp32 and esp8266

I want to use ESP-NOW with esp32 and esp8266. The esp32 will mostly send data to esp8266.I was not able to find any good tutorial on YouTube to achieve this. The only videos I found was for either communicating with esp32 to esp32 or esp8266 to esp8266. Is it possible to do this if yes how.

body:
In general, ESP-NOW uses the WIFI radio in an ESP processor as a physical layer.  But uses it's own protocol which likely looks like garbage to a normal WIFI equipment.  So, it's like being in a meeting room with a bunch of people only knowing German and occasionally someone pipes up taking French.  As no one understands the French speaker, the French speaker is ignored.

Other things you need to know.  ESP-NOW is more like UDP.  There is not a higher layer looking out for you like in TCP.  Any number of reasons can cause your ESP-NOW "blurp" from being received.  For this reason ESP-NOW is better suited for periodically repeating information.  Like reporting the temperature.  Or for situations where the user can provide immediate feed back of success.  Such as a remote control.

> The esp32 will mostly send data to esp8266

This infers reversing the direction of data flow over the ESP processor's WIFI radios.  While this may be possible it may not be a trivial task.

> Is it possible to do this (communicate between an esp32 and esp8266) if yes how.

This shouldn't be problem.  [This link][1] provided by Majenko appears to be a good place to start.  [Espressif][2] them selves maintains [this ESP-NOW web site][3].  Likely, after programming the ESP8266 and ESP32 using the correct libraries, they will be able to send data over an ESP-NOW link.

  [1]: https://github.com/yoursunny/WifiEspNow
  [2]: https://www.espressif.com/en
  [3]: https://www.espressif.com/en/products/software/esp-now/overview


message:
Crash when disabling bluedroid

i have an ESP32 and i want to use deepsleep when it's not used. Before sending it to sleep i clean up everything, so disconnect, deinitialize and disable everything i build before. But i get a crash when i try to disable bluedroid. Does anyone have an idea why this happens?

```c++
void bt_deinit() {

 Serial.println("Deinit AVRC");
 if (esp_avrc_ct_deinit() != ESP_OK)
  Serial.write("Failed to deinit avrc");

 Serial.println("Deinit A2DP");
 if (esp_a2d_source_deinit() != ESP_OK)
  Serial.println("Failed to deinit a2dp");

 Serial.println("disable bluedroid");
 if (esp_bluedroid_disable() != ESP_OK)
  Serial.println("Failed to disable bluedroid");

 Serial.println("Deinit bluedroid");
 if (esp_bluedroid_deinit() != ESP_OK)
  Serial.println("Failed to deinit bluedroid");

 Serial.println("Stop BT");
 if (btStop() == false)
  Serial.println("Failed to stop bt");
}
```

output:
```
Port closed
Uploading to I/O board
Opening port
Port open
Hello there!
Bluetooth init success
good night
Deinit AVRC
Deinit A2DP
disable bluedroid
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:719 (xQueueGenericSend)- assert failed!
abort() was called at PC 0x4008de6f on core 0

Backtrace: 0x40091918:0x3ffce3b0 0x40091b49:0x3ffce3d0 0x4008de6f:0x3ffce3f0 0x4013bfb6:0x3ffce430 0x4013c5f6:0x3ffce460 0x400fdbe2:0x3ffce480 0x400fdc35:0x3ffce4a0 0x400fe12e:0x3ffce4c0 0x400f6bd9:0x3ffce4e0 0x4008e559:0x3ffce510

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
Hello there!
Bluetooth init success

```

it works fine if i just do not deinitialize everything and send him directly to sleep. But this is not the elegant way.

body:
decoded backtrace in your question is missing, one of the choices to see stack trace is https://github.com/littleyoda/EspStackTraceDecoder

i dont know exactly if this is your case or not, but calling esp_ble_gap_stop_scanning() before esp_bluedroid_deinit() possibly avoids your crash.