text:
Can't display any number using 74HC595
I just started using elegoo UNO R3 and I have the problem displaying different numbers on the segment display using the 74Hc595. I have no problem with the uploads and the circuits are working fine. However, the segment  doesn't display any numbers besides 8. Is there a problem with the code or the wiring? any suggestion?
byte seven_seg_digits[10] = { B11111100,  // = 0
                          B01100000,  // = 1
                          B11011010,  // = 2
                          B11110010,  // = 3
                          B01100110,  // = 4
                          B10110110,  // = 5
                          B10111110,  // = 6
                          B11100000,  // = 7
                          B11111110,  // = 8
                          B11100110   // = 9
                         };
// connect to the ST_CP of 74HC595 (pin 3,latch pin)
int latchPin = 3;
// connect to the SH_CP of 74HC595 (pin 4, clock pin)
int clockPin = 4;
// connect to the DS of 74HC595 (pin 2)
int dataPin = 2;

 void setup() {
  // Set latchPin, clockPin, dataPin as output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

// display a number on the digital segment display
void sevenSegWrite(byte digit) {
  // set the latchPin to low potential, before sending data
  digitalWrite(latchPin, LOW);

  // the original data (bit pattern)
  shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]);

  // set the latchPin to high potential, after sending data
  digitalWrite(latchPin, HIGH);
}
   }

void loop() {
  // count from 9 to 0
  for (byte digit = 10; digit > 0; --digit) {
    delay(0);
    sevenSegWrite(digit - 1);
  }

  // suspend 4 seconds
  delay(0);
}

here is my circuit and the tutorial diagram:

display get stuck at 8

May be a silly comment, but you did change the argument in your two delay(0); calls to higher values, right? The display will seem to aggressively flicker while going through all digits, so it may just seem that it is "stuck" at lighting all LEDs.

You're not giving your eyes time to see the numbers change. If you were a pigeon you might just see some numbers flicker past very rapidly, but we mere humans don't have a hope of seeing them - not without introducing some delay.
void loop() {
  // count from 9 to 0
  for (byte digit = 10; digit > 0; --digit) {
    delay(0);  // <--- Number of ms to wait between each digit
    sevenSegWrite(digit - 1);
  }

  // suspend 4 seconds
  delay(0);  // <--- Number of ms to wait between counts.
}


text:
Is it possible for ESP8266WiFi client to request the number of clients currently connected to Access Point?
My system consists of several ESP8266 based 'stations', which are synchronised in a way that all of them go into deep sleep and wake up on the same schedule. All stations are WiFi clients. All stations run on batteries and energy saving is critical.
One of the stations is a Master. It contains a modem/router that serves as AP to all stations.   The AP is switched OFF during the sleep phase. When a Master wakes up it switches on the AP and thus starts a communication session available to all stations. When all stations have their data sessions completed and disconnect from AP, the Master switches off the modem/router and goes to sleep.
My question is about the Master being informed that there are no other clients actively connected to the AP. My current solution is WAN based - each station reports to the Web Service on the start and end of their connection. Is it possible to achieve the same result locally - by a request from the WiFi client to the Access Point?

You likely could simply probe the network you are on.  In Linux you would use the nmap command.  Model your code after that command.

I'm voting to close this question as off-topic because the actual question has absolutely nothing to do with Arduino.  The reality of the situation is entirely dependent on the unspecified capabilities of the AP and the other clients.

You can avoid these kinds of questions by reading the documentation or by checking the header files.

What reseache have you done on this topic? Example using a search enginee and searched for "esp8266 show clients connected"? Questions that show no research is normaly closed.

It seems you failed to read and/or understand the question. The system described is successfully implemented at several remote outback locations where it runs on solar power unattended for months. To ensure smooth failover all units are interchangeable, the system has no server, all ESPs are WiFi clients. I challenge you to find a solution to my question thru your 'research'. Anyway, I am happy with this question being closed. Thank you.

Use WiFi.softAPgetStationNum() to return the number of clients connected to an ESP8266 AP.

Thanks a lot, dandavis!
Exactly what I was looking for.

source: Stack Exchange

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

sort: votes


text:
Arduino as Modbus RS485 slave using only 2 Digital pins
I want to use RX(0) and TX(1) Pins to make Arduino as an RS485 slave. To do this I am using MAX485 IC (Breakout board) https://datasheets.maximintegrated.com/en/ds/MAX1487-MAX491.pdf
The problem here is that I don't have any other pins remaining to interface with the module in order to pull the DE/RE pin HIGH/LOW.
Can anyone suggest a way to do this without using one additional pin?

http://www.ti.com/lit/ug/tidubw6/tidubw6.pdf

@Majenko Thanks. I could definitely use the NA555.

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


text:
Servos not working properly with joystick
So, I was working with a project in which I used a joystick module to control two servos at the same time. The joystick controls the servos in a way that when the joystick is moved along x-axis, both servos move in the same direction but when joystick moves in y-axis, the servos move in different directions. I have this program:
#include <Servo.h>
Servo servo1;
Servo servo2;
int joyx = 0;
int joyy = 5;
int joyval;
int joyvalx;
int joyvaly;
void setup() {
    Serial.begin(9600);
    servo1.attach(3);
    servo2.attach(5);

}

void loop() {
    Serial.println(joyvalx + "," + joyvaly);
    int x = analogRead(joyx);
    int y = analogRead(joyy);
    if(x != joyvalx){
        joyval = map(x, 0, 1023, 0, 180);
        servo1.write(joyval);
        servo2.write(joyval);
    }
    if (y != joyvaly){
        joyval = map(y, 0, 1023, 0, 180);
        servo1.write(joyval);
        servo2.write(1023-joyval);
    }
}

However, the servos don't seem to work properly. One servo works fine but the other just gets stuck. Also, if I use the code for only one direction (x-axis or y-axis) by removing the code for the other, then both servos work good. I can't understand the problem. If anyone does, please help me.

You don't initialize joyvalx and joyvaly. 2. You never assign anything to joyvalx or joyvaly.

+1 for nicely formatted code

your answer is here if I use the code for only one direction (x-axis or y-axis) by removing the code for the other, then both servos work good   ........ you have two pieces of code that are like two dogs fighting over a bone

1023-joyval, which is 0 to 180? ...

The problem, as jsotola pointed out, is that your code writes totally different values to the servos very fast. You don't combine the two values from the joystick, but just overwrite the previous servo value. So this cannot work.
As I interpret your description, you want the x axis to move both servos the same amount in the same direction (in unity), while the y axis determines the difference of position between them. If you move the y axis to one side, the first servo will go a bit clockwise, while the other goes a bit counter-clockwise. When you then move the x axis, both servos will move to the corresponding direction, while maintaining their position difference.
It is better to first write a formula, how you will calculate each servo position from the given joystick values. The above behavior can be described with these formulas:
servo_1_value = mapped_x + mapped_y;
servo_2_value = mapped_x - mapped_y;

Now you have to map the joystick values correspondingly:
mapped_x = map(x, 0, 1023, 0, 180);
mapped_y = map(y, 0, 1023, -90, 90);

Note, that you should change the parameters for mapping y to the values you need. In the above code they are set to the maximum (meaning that moving the y axis to either end will effectively disable the x axis, since the servo cannot move past 0 or 180 degrees).
You don't really need to check, if the value changed. But if you really want to, you should check the calculated values for each servo separately. Something like this:
if(servo_1_value != old_servo_1_value){
    servo1.write(servo_1_value);
}
if(servo_2_value != old_servo_2_value){
    servo2.write(servo_2_value);
}

But you don't really need to check for a change here.

I like this answer; I'd just add one very important thing: you should not call the functions at max speed, but rather call it let's say once every 10 ms. The responsiveness is still high, but 1) the other parts of the program run better and 2) you on't try to give mechanical components commands which are too fast

Yes, you can do this, but I don't think, that writing at max speed really would do something bad. The servo is controlled via PWM and it will go to the specified position as fast as it can, you cannot control it's speed. When writing slower (with a delay or a millis() construction), then there only will be lesser positions in between, but the overall value change would be the same; at maximum an instant jump from 0° to 180°. On the other side it would prevent jitter, if you measure a bigger number of analog values and only write the average to the servo.

in fact point 2 should not be applicable for servo motors (I checked the library and it updates the value once per timer overflow, so it automatically neglects all the other commands). Nevertheless having a human interface in constant acquisition is not something very advisable in my opinion; it drains resources (even if in this case no other "tasks" have to be performed) and floods with useless information the receiver (for instance, the PC at the other end of the serial link). This, again, apart from the mechanical problems which in this case are not present due to the library design

You are right, for a bigger program this is important. I didn't include it for simplicity, but it's definitely a good point for a remark.

Thanks @chrisl, your answer did do the work. Now both servos are working great. Thanks a lot.

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


text:
Hold all "millis()" values in an array?
I'm working on a project where I could have up to six devices connected to an arduino, it might be the case that not all of them will be attached at the same time, and all of them need to be able to receive PWM signals but without using delay().
There are a number of different PWM patterns already programmed into the code, what I'd like to do is be able to assign more than one device to a single pattern, and start/stop the patterns at different times to different devices.
I have a python script (and soon an Android app) that sends a message in the following format to the device:
<int(pin_number), string(pattern_name), int(highest_pwm_value 0 - 255), int(delay_between_pulses_in_seconds)>
Is there some way of coding something like the following, and if so, how would I go about it?
array timings[];

void fade(unsigned long thisMillis, int fadeInterval, int maxPWM, int motor_pin) {
  if (thisMillis - timings[motor_pin] >= fadeInterval) {
    // yup, it's time!
    if (fadeDirection == 1) {
      fadeValue = fadeValue + fadeIncrement;
      if (fadeValue >= maxPWM) {
        // At max, limit and change direction
        fadeValue = maxPWM;
        fadeDirection = 0;
      }
    } else {
      //if we aren't going up, we're going down
      fadeValue = fadeValue - fadeIncrement;
      if (fadeValue <= minPWM) {
        // At min, limit and change direction
        fadeValue = minPWM;
        fadeDirection = 1;
      }
    }
    // Only need to update when it changes
    analogWrite(motor_pin, fadeValue);

    // reset millis for the next iteration (fade timer only)
    timings[motor_pin] = thisMillis;
  }
}

The bit that I'm unsure about is how the array should be defined etc, as I'm primarily a python developer so it's rare I have to explicitly set the type of an item in an array!

that actually already looks about right.

The answer given at https://forum.arduino.cc/index.php?topic=529364.msg3608306#msg3608306 is as follows:
struct motor_data {
   int id;
   unsigned long start_time;   //store time stamp here
   unsigned long duration;      //time ends    ...
};

motor_data motors[6] //declaration
motors[0].start_time = millis(); //accessing

Thoughts on this approach?

This is a classic example where you want to create a class.  A class will contain all the control logic for dealing with one pin - all the functions, all the variables, etc.
Then you just create as many instances of the class as you need for your different pins. Each one is completely separate from the other, and each one can be controlled at will.
For instance, you might make something like this (untested):
class FaderPin {

    private:
        uint32_t timestamp;
        int motor_pin;
        int fadeInterval;
        int minPWM;
        int maxPWM;
        int fadeDirection;
        int fadeValue;

    public:
        FaderPin(int pin, int minp, int maxp, int interval) {
            motor_pin = pin;
            minPWM = minp;
            maxPWM = maxp;
            fadeInterval = interval;
            fadeDirection = 1;
            fadeValue = minp;
            timestamp = millis();
        }

        void fade() {
            uint32_t thisMillis = millis();
            if (thisMillis - timestamp >= fadeInterval) {
                // yup, it's time!
                if (fadeDirection == 1) {
                    fadeValue = fadeValue + fadeIncrement;
                    if (fadeValue >= maxPWM) {
                        // At max, limit and change direction
                        fadeValue = maxPWM;
                        fadeDirection = 0;
                    }
                } else {
                    //if we aren't going up, we're going down
                    fadeValue = fadeValue - fadeIncrement;
                    if (fadeValue <= minPWM) {
                        // At min, limit and change direction
                        fadeValue = minPWM;
                        fadeDirection = 1;
                    }
               }
               // Only need to update when it changes
               analogWrite(motor_pin, fadeValue);
               // reset millis for the next iteration (fade timer only)
               timestamp = thisMillis;
           }
       }

};

Then you can:
FadePin motorOne(5, 0, 255, 10);
FadePin motorTwo(6, 0, 255, 10);

And regularly call:
motorOne.fade();
motorTwo.fade();

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


text:
can I design a User Interface to run on the arduino and display it with VGA?
I know you can design a user-interface in any language you choose and Link it with a Arduino via serial Port, but I am asking if I can design user-interface to run on the Arduino WITHOUT the need for an external laptop/desktop and display the user interface on a screen (like via VGA) ? and HOW ?

Only in the most crude and blocky manner.  There are a few game systems which come close.  realistically you should use something else; today small LCD or OLED displays are all of cheaper, more compact, and far easier to drive; if you really want VGA use a small FPGA or fast MCU for that.  But your question is far too broad to be a fit here - stack exchange sites are about specifics.

What are you asking? Can you connect a LCD? An OLED display? A 8x8 LED module (or a string of them)? There are lots of ways of doing user interface. And VGA is possible.


text:
AnalogWrite only working for one pin of RGB LED
I'm working on some code for a Nerf blaster with an LED indicator light. When attempting to use analogWrite to PWM my LED pins, only one pin (blue) behaves as expected and dims down. The other two (red, green) don't light up at all. The LED is confirmed working and the Arduino.cc fade example works fine on each pin individually when testing. Here is the code:
#include <ClickButton.h>
#include <Servo.h>

Servo esc;

ClickButton rev(6, LOW, CLICKBTN_PULLUP);
ClickButton mode(7, LOW, CLICKBTN_PULLUP);
ClickButton trig(8, LOW, CLICKBTN_PULLUP);

int flyPin = 2;
int escPin = 3;
int pushPhasePin = 4;
int pushSpeedPin = 5;
int RED = 9;
int GREEN = 10;
int BLUE = 11;

int m = 1;
int singleShot = 100;

bool shot = false;

void setup() {
  pinMode(flyPin, OUTPUT);
  pinMode(pushPhasePin, OUTPUT);
  digitalWrite(pushPhasePin, HIGH);
  pinMode(pushSpeedPin, OUTPUT);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

  esc.attach(escPin, 1000, 2000);
  esc.write(0);

  digitalWrite(RED, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(GREEN, HIGH);
  delay(500);
  digitalWrite(RED, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(GREEN, LOW);
  delay(500);
  digitalWrite(RED, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(GREEN, HIGH);
  delay(500);
  digitalWrite(RED, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(GREEN, LOW);
  delay(1500);
}

void loop() {
  rev.Update();
  mode.Update();
  trig.Update();

  if (mode.clicks != 0) {
    m++;
    if (m > 3) {
      m = 1;
    }
  }

  if (m == 1) {
    digitalWrite(RED, LOW);
    digitalWrite(BLUE, LOW);
    analogWrite(GREEN, 120);
  }
  else if (m == 2) {
    digitalWrite(RED, LOW);
    analogWrite(BLUE, 120);
    digitalWrite(GREEN, LOW);
  }
  else if (m == 3) {
    analogWrite(RED, 120);
    digitalWrite(BLUE, LOW);
    digitalWrite(GREEN, LOW);
  }

  if (rev.depressed) {
    digitalWrite(flyPin, HIGH);
    esc.write(40);
  }
  else {
    digitalWrite(flyPin, LOW);
    esc.write(0);
  }

  if (trig.depressed) {
    if (m == 1) {
      if (!shot) {
        digitalWrite(pushSpeedPin, HIGH);
      }
      delay(singleShot);
      shot = true;
      digitalWrite(pushSpeedPin, LOW);
    }
    if (m == 2) {
      if (!shot) {
        digitalWrite(pushSpeedPin, HIGH);
      }
      delay(singleShot * 3);
      shot = true;
      digitalWrite(pushSpeedPin, LOW);
    }

    if (m == 3) {
      digitalWrite(pushSpeedPin, HIGH);
    }
  }

  else {
    digitalWrite(pushSpeedPin, LOW);
    shot = false;
  }
}

The relevant portion that is failing is under the "if m == 1,2,3" blocks. Where m [for mode] == 2, the blue light works but the other leds do not light when cycling through the modes. Note the leds are on PWM pins (9,10,11). Thanks for any help!

Does it work to call analogWrite(color, 20) without all the other code? Does it work to turn the color on and off with digitalWrite?

It does. The below answer is correct though! I missed that bit of info.

You are trying to combine the use of the Servo library and PWM on pins 9 and 10. You can't do both. PWM on pins 9 and 10 uses the same timer as the servo library.
As it states on the Servo library web page:

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.


text:
Waveshare 1.54 inch ePaper display requires 5Vs from Arduino Uno
I have an Arduino Uno and I would like to attach a Waveshare 1.54“ display (red, black & white) to it.
All the specs tell me that it consumes 3.3 V which I have readily available on the Arduino Uno.
I could not get the display to work until I attached the Power pin to 5V instead of 3.3V.
I did try this with two different ePaper displays and the situation was the same.
I also tried to power the display with a Raspberry Pi‘s 3.3V (with the GNDs connected). But this did not work either.
So I am wondering what I am missing here, is it simply a power issue and my Arduino can‘t deliver the necessary current?

The answer lies in the FAQ for that display:

Why the e-Paper cant work with Arduino?
Answer:
The I/O level of Arduino is 5V, and the e-Paper should be driven with 3V3. If your Arduino cant drive the e-Paper successfully, please try to convert the level to 3.3V
You can also try to connect the Vcc pin to the 5V of Arduino to see whether the e-Paper works, but we recommend you not to use 5V for a long time.

So while you can run it from 5V, you really shouldn't, since you run the risk of breaking it.
Instead, you should employ proper logic level shifting to reduce the Arduino's outgoing signals to 3.3V and, more importantly, boost the incoming signals from the display to 5V.

https://www.instructables.com/id/A-Quick-Guide-on-Logic-Level-Shifting/

Thanks for your Reply. I was only thinking VCC but not the output levels of the Arduino. So I need a logic level shifter or a voltage divider for each output of the Arduino

Yep.  The Arduino expects minimum 3.3V on an input to recognise a HIGH.  If you're running the display at 3.3V chances are the signals coming from the display will be slightly under that, and will want to be boosted slightly for the Arduino to recognise them. Running at 5V the signals will be proportionally higher and will register, but you can damage the display.  For signals from the Arduino to the display they will be above the upper limit allowed, and could risk damaging the display, so they need reducing to around 3.3V.

Update to those who have bought the display module recently (doesn't apply to bare displays). There has been a change and the new modules support 5V. From the display's user manual:

For raw panel, its working voltage is 3.3V, note that when you designed you own driver board, level convert circuit is required if
  the working voltage of your board is 5V. Module/HAT version can
  support 5V voltage if the Module you buy is the new version which has
  been integrated convert circuit.


text:
Controlling multiple fans using arduino uno
I'm kind of new on the field of Arduino. Although I have a question concerning multiple fan connection on 1 arduino PWM pin. The goal is to connect around 8 to 16 fans on 1 arduino  pwm header pin and control their speeds separately using a potentiometer. As I seen it can be achieved by using transistors. The question is are there any limitations on how many fans can I connect and control seperatly using tranzistors? Can I for example use 16 transistors and control 16 fans seperatly ?
Thank you for your answers in advance

Need more information about can be achieved by using transistors. Furthermore, I don't think PWM multiplexing is a good idea. See the answers on this https://arduino.stackexchange.com/questions/31099/pwm-multiplexing-on-arduino-nano

You want 16 fans on one PWM pin, is that it? What is the purpose of the PWM pin?

The idea is that the goal is to connect arround 6 to 16 fans (depending on the situation I don't know how many at the moment) and I want to control them seperatly using potenciometer.
The idea is that they should be controled seperatly as in for example FAN1 - 100% (Max RPM)
FAN2 - 70%
And so on..
Do you understand the goal now? What would be the best solution for this situation?
I will also connect a 128x64 screen and  4 buttons for meniu navigation

One option for controlling multiple PWM output is to use a I2C PWM Driver (e.g. PCA9685).  It has 16 PWM outputs and is controlled from the arduino with I2C which only requires 2 pins on the arduino.
Tutorial: https://learn.adafruit.com/16-channel-pwm-servo-driver

One PWM pin can control only one fan (or one group of fans). You can't have one PWM pin outputting different values to different fans, since one pin can only have one value. (Yes, there are ways of multiplexing it through time slicing but that is both hard and not a good idea).
You need one PWM per fan if you want individual control of each fan's speed. That means a maximum of 6 fans on an Arduino.
To get more you would either have to use software PWM (which can introduce jitter which may not be a problem with simple fans), or an external PWM controller.  Or add more Arduinos.
If all you want is potentiometer control of the fans you can do it without using an Arduino. A pair of op-amps (it can be a single dual op-amp chip), one acting as a triangle wave oscillator, and the other as a comparator, will generate PWM for you.  Here's an example:

Image by ElectroBOOM (watch his videos sometime, they're hilarious)

Can I merge multiple arduino unos together? for example hook up a screen on one arduino uno, and buttons, and use 2 - 3 arduinos to control fans, but display the info on the first arduino?
Is it possible to use arduinos as extenders? If so how?

@dmxyler Sure. You just need to get them to communicate with each other. I2C and Serial are common ways - there's plenty of online resources.

ok thank you for your advice. WIll try. Have a great day :)


text:
other interrupts in rc channel reader
I have the sketch from James Waldby (Read RC receiver channels using Interrupt instead of PulseIn) working beautifully. I want to use a switch on my TX to start and stop a sequence of lights (emulating guns firing on a ship model). But first, I need the delayed flash routine to work. I have tried a loop counting millis() differences to separate the sequences, but the delays don't delay.
 void loop(){
  rc_read_values();//Mr. Waldby's interrupt routine
  currentMillis = millis();
  previousMillis = currentMillis;
  if(fireGun ==1){
    interval = 3000;
  }else{
    interval = 1500;
  }
  interval = 3000;
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

//if(fireGun ==1){
  analogWrite(led, 255);
  delay(50);
/* a real gun flash doesn't cut right off; it fades away.
  This sequence simulates that  */
  while(brightness > 0){

    // change the brightness for next time through the loop:
    brightness = brightness - fadeAmount;
    analogWrite(led, brightness);
    delay( 7);
  }
  brightness = 80;
}

The intention here is to flash the led every 3 seconds. The flash loop works fine, but the 3 second delay doesn't.
The delay routine works ok in a sketch by itself.
Any thoughts about what I might be doing wrong?

go through the loop() code listing step by step ... write values of variables on a sheet of paper as you go along

  currentMillis = millis();
  previousMillis = currentMillis;

So currentMillis and previousMillis will always be exactly the same, right?

  if (currentMillis - previousMillis >= interval) {

So if 0 >= interval (which it won't be) do something?
Therefore your fading code will never be executed.


text:
Selecting different arrays using a list of pointers
I have different arrays of different sizes, and a list of pointers to the addresses of each array. How do I select each array using the list of pointers, and access it's elements. On Teensy 3.2 board.
int * arr_list[3];
const int arr_sizes[3] = {3,4,5};  // array of the array sizes
const int ar1[3] = {12,2,8};       // arrays of  different sizes
const int ar2[4] = {41,3,6,47};
const int ar3[5] = {9,32,1,5,7};

void map_arrays(){          // list of pointers with the addresses of the
                            // arrays
arr_list[0] = (int*) &ar1;
arr_list[1] = (int*) &ar2;
arr_list[2] = (int*) &ar3;
};

int arr_number = 1;          // select array
int a = arr_sizes[arr_number];    // the size of the selected array
int *b = arr_list[arr_number];
int test = 0;

void setup() {

Serial.begin(57600);  //serial monitor

}

void loop() {

for (int i=0; i<a; i++) {     // for the selected arr_number iterate and
test = b[i];                  // return the index elements

}

Serial.println("size =");
Serial.println(a);
Serial.println();
delay(1000);
Serial.println("index =");
Serial.println(test);
Serial.println();
delay(500);

 }

You terminate each array appropriately.

You have it right, only fix initialization of test variables:

you do not call map_arrays() in setup()
you assign uninitialized arr_list item to b

const int* arr_list[3];
const int arr_sizes[3] = { 3, 4, 5 };  // array of the array sizes
const int ar1[3] = { 12, 2, 8 };       // arrays of  different sizes
const int ar2[4] = { 41, 3, 6, 47 };
const int ar3[5] = { 9, 32, 1, 5, 7 };

void map_arrays() {          // list of pointers with the addresses of the
// arrays
  arr_list[0] = ar1;
  arr_list[1] = ar2;
  arr_list[2] = ar3;
}

int arr_number = 1;          // select array
int a = arr_sizes[arr_number];    // the size of the selected array
const int *b;
int test = 0;

void setup() {

  Serial.begin(57600);  //serial monitor

  map_arrays();

  b = arr_list[arr_number];

  for (int i = 0; i < a; i++) {     // for the selected arr_number iterate and
    test = b[i];                 // return the index elements
    Serial.println(test);
  }

  Serial.println("size =");
  Serial.println(a);
  Serial.println();
  delay(1000);
  Serial.println("index =");
  Serial.println(test);
  Serial.println();
  delay(500);

}

void loop() {
}


text:
analog read only once a time
I was working on a school project in where i need to analog read form A0 and test if my value is bigger than some boundary (500 for example) to return 0 or 1
well with a simple code in an infinity loop
this will keep returning 0000000 and 1111111 for infinity
but need 1 only once when my analog value passes from 900 to 300 for example and I dont need once when It stays at 300.
and the same problem for 0 : I need 0 only once when it passes from 300 to 900 and not 0 from staying at 900
thanks for help in advance

Store the current read value AND the previous value and check if a border has been crossed.
E.g.
if Previous value < 500 AND current value >= 500
   Going from 0 to 1 -> return/send 1
else if Previous value >= 500 AND current value < 500
   Going from 1 to 0 -> return/send 0

However, to make it more complicated, you might have debouncing effects, e.g. what if the value moves for some time around 500 to go to 200... It will still result in possibly many 0 and 1 boundary changes.
You can fix this easily by using two different value: by checking going lower < 490 and going higher > 510 (or any other appropriate value. Or use a debounce mechanism where it should be below or above the 500 value for a minimum (but short) amount of time.

What you are talking about is threshold with hysteresis.  It's basically how the digital inputs work using schmit triggers.
+------+ 1023
| HIGH |
+------+ 900
| DEAD |
+------+ 300
| LOW  |
+------+ 0

What you want to do needs to be done in two distinct sections:

Detect the incoming analog level, and
Control and record the status.

The first part is simple enough:
int val = analogRead(0);
if (val > 900) {
    // High
} else if (val < 300) {
    // Low
}

With that you have two blocks of code that are valid for the two bands you are interested in.  That is effectively like a button now - you have a "HIGH" and a "LOW" signal, just like digitalRead() gives you for a digital input.  Now you just need to couple that with some standard button toggling code.  That is - only change the status if the status actually should change.  And that's simple enough.  For example:
if (newStatus != oldStatus) {
    oldStatus = newStatus;
    // Do something just once
}

To expand that concept out, you get:
static bool enabled = false; // This is the saved status

int val = analogRead(0); // The incoming value

if (val > 900) { // A HIGH signal.
    if (!enabled) { // It's not already recorded as HIGH
        enabled = true; // Record it as a HIGH
        Serial.println("1");
    }
} else if (val < 300) { // A LOW signal
    if (enabled) { // It's currently HIGH, not LOW...
        enabled = false;
        Serial.println("0");
    }
}

And there you have it.  If it goes HIGH and it's not recorded as HIGH then it's a new HIGH.  If it goes low and it's not recorded as LOW then it's a new LOW.


text:
Fade out lightbulb 220V
I am trying to make a lightbulb fade to dark and back to light, for which I found the following tutorial online:
http://bildr.org/2012/03/rfp30n06le-arduino/
Unfortunately, the tutorial makes use of a 60V light source while my intention is to use the system on 220V. Would it be enough to solve my problem to replace the 60V MOSFET in the system with one of 220V?What would otherwise be a solution?
Thank you very much for your help!

I'm voting to close this question as off-topic because the actual question being asked is about mains powered dimming circuits, not about Arduino.

Absolutely not. Not under any circumstances.
Dimming AC is a considerably harder task, and doing it with 220VAC can be deadly.
To do it you need:

A zero-crossing detection circuit
A TRIAC driver circuit
A suitable TRIAC to do the switching
Software that will use the zero crossing information to time the switch-on of the TRIAC to a certain point in the waveform.

And most importantly:
Good knowledge of working with mains electricity - without which you will probably kill yourself or those around you.

a solid state relay w/zero cross is going to be the simplest way to accomplish all that.

@dandavis No, it's not. Not unless the ssr and the zero cross are completely separate units. You need to switch the SSR at a period after the zero cross to dim it. SSRs with zero crossing built in turn on at the zero crossing to prevent spikes.

of course, duh. i somehow forgot about the dimming part and focused on the safe part...

You can buy 220V dimmer modules controllable with 5V PWM from Arduino. Here is one controllable with this PWM digital potentiometer module.
I use Kemo 4000VA regulator module with that M150 digital pot module controlled with Arduino PWM for heater regulation.


text:
How do I use digital pin on sensor to analog on arduino uno
I am working on a autonomous fire extinguisher.i have run out of pins.I have the following question in my mind while working on my project
Is it necessary that the DO pin in a flame sensor must be in a PWM digital pin in Arduino.i have this doubt since when I connected it to non PWM pin it didn't worked.
Secondly it is possible for me to use the analog pin in Arduino for the DO pin of the flame sensor or trigger/echo pins of the ultrasonic sensor.
Thanks.

Perhaps you could add a url/referens to the flame sensor. As it is now it is totaly unclear!

http://www.theorycircuit.com/arduino-flame-sensor-interface/ I am having sensor having only digital output pin

@MatsK is it clear now

PWM stands for Puls Width Modulation and is only available when the Digital Pin is in OUTPUT mode.
And YES, you can connect the flame sensor's D0 to any digital pin on the Arduino.
And yes it is possible to connect the flame sensor's D0 to a analog pin, but why not use the A0 from the flame sensor and connect it toi a analog pin on the Arduino?

I have only 3 pin flame sensor

OK, the one that you refered to is a four pin....

@MatsK, that site shows both

You can use the analog pins (A0-A5, but not A6 and A7) also as digital pins. So you can set one of them as digital input, connecting it with the D0 pin of your fire sensor. You can read this pin with digitalRead(pin).
Regarding your problem with PWM:
There is no "PWM input" on an Arduino Nano (because PWM hardware in a microcontroller means pulse with modulated output). The example code of your sensor uses an analog input (ADC: Analog Digital Converter) (with usage of analogRead()). If you want to use this functionality you have to connect the A0 pin of your sensor to one of A0-A7 and reading it with analogRead() to get the fires intensity/distance.

Will if(digital read(A1)==LOW) work if I connect my DO pin of sensor to analog pin

The documentation, you linked, says, that it outputs LOW, when nothing is detected and "+Ve" (I guess that means HIGH) when a fire is detected. So to detect the existence of fire use if(digitalRead(A1)==HIGH). But be sure to initialize the pin as input


text:
File include error while using Arduino Nano
I am using the code below to interface the Arduino nano and android cell phone to enable serial communication through the USB port. I downloaded the filter library from GitHub https://github.com/JonHub/Filters
I am getting an error saying thet the library is not found.
I would really appreciate some suggestions on this.
Here is my code:
 //This code is for arduino communicating to android phone through USb serial port.
 //For arduino nano

 #include <Filters.h>   //implements digital filters which mimic the analog filter, keep track of variable statistics in realtime

char data_read; //character datatype takes up to 1 byte of memory
unsigned int analog_out;
unsigned long time;
float filterFrequency = 10.0;
FilterOnePole lowpassFilter( LOWPASS, filterFrequency );//implements digital RC type filter; both highpass and lowpass

 void setup()
 {
  Serial.begin(115200); //open the serial port and set the baud rate for communication
  // create a one pole (RC) lowpass filter

 }
 void loop()
 {
 }

 void serialEvent() { //Used when data is unavailable yet
 if (Serial.available()) //checks the number of bytes available for reading from the serial port
 {
data_read = Serial.read();

if (data_read == '0') {
  Serial.print("#");

  //Serial.print("10100");
  analog_out = lowpassFilter.input( analogRead(0) );
  Serial.print(analog_out + 10000);

  Serial.print(":");

  //Serial.print("20200");
  analog_out = lowpassFilter.input( analogRead(1) );
  Serial.print(analog_out + 20000);

  Serial.print(":");

  //Serial.print("30300");
  analog_out = lowpassFilter.input( analogRead(2) );
  Serial.print(analog_out + 30000);

  Serial.print("p");
}
/*if(data_read == '0' || data_read == '1' || data_read == '2' || data_read == '3' || data_read == '4' || data_read == '5'){
  analog_out = lowpassFilter.input( analogRead( data_read-48 ) );
  Serial.print((analog_out)+(data_read-48)*10000);
  Serial.print(":");
  }else if(data_read =='p'){
  Serial.print("p");
  }*/
   }
 }

Here is my error message:
  Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P"

  C:\Users\daphn\Documents\Arduino\Analog_Serial_out\Analog_Serial_out.ino:4:129: fatal error: Filters.h: No such file or directory

  #include <Filters.h>   //implements digital filters which mimic the analog filter, keep track of variable statistics in realtime

                                                                                ^

  compilation terminated.

  exit status 1
  Error compiling for board Arduino Nano.

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

And where did you put the library?

I've included the library in the same folder where I had saved my code

Have you read these 2 pages? https://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC6 , https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

You have to put the folder with the library files in the folder libraries under your sketchbook folder. Then the IDE should be able to find them.
I think there is also a possibility to save them in the same folder as your .ino file, but it I don't know how exactly you have to do this.

I did try including the filters.h header file under the main libraries folder, but still I get the same error. I am wondering if there is any mistake with the source of the header file itself. Usually, when I include external libraries, I place it in the same folder as the code itself and it works.

I tested it with your code and the linked library and it works for me. Check in the IDEs settings, to where the sketchbook folder is set

The library is more than a .h file. You need ALL the files, and all placed in a folder named Filters within your libraries folder in your sketchbook. Nothing else will do.

@Majenko What do you mean by ALL the files?

@DaphFab All the files for the library. Everything in that github repository. All the .h files, all the .cpp files, etc. There's 11 of them, plus examples.

Ok got it. I had already done that before. Anyway, I solved the issue by changing #include <Filters.h> to #include "Filters.h"

please elaborate why you did that, so that people can resolve similar issues in the future

Here is your definitive answer.
You have to do the #include like the following (with double-quotes, not < > brackets)
#include "Filters.h"
This will make Arduino compiler look in the project folder.
Using < > brackets tells the compiler that it is in the standard library area.
I just tested this with the following script.
#include "mytest.h"
void setup() {
  // put your setup code here, to run once:

}

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

}

The mytest.h file is blank (has no text in it).
It wouldn't work until I included it using the double-quotes method.


text:
Is checking an if statement every loop/while iteration inefficient?
I have code that changes a bool only time in the setup(), and in my loop() I have
if (setupBool) {
// ...
} else {
// ...
}

Is checking the bool every loop slower than having a while(true) with the same code?
And what about checking it in every loop in a while(true)?
Is there any reason I shouldn't do those?

I don't understand how a while(true) can be an alternative to if()...else...

I couldn't understand why you are checking setupBool in the loop if it can change only in the setup... Moreover you usually don't need a while(true) in the loop since it automatically gets executed forever

Of course an if statement cost time, although very little. However, it changes (although once), so if you need to vary depending on the value, you have to use the if statement.
A while(true) also cost a little time (a little bit less), but less than 1 us, same as the if statement. You can do perfectly do an if statement within the while(true), but remember, the loop itself is behaving like a while(true) already.
However, I wouldn't concern at all about optimizing performance, unless:

You know beforehand you will need the fastest code possible
You have already performance issues

Always prefer readability/maintainability about performance.

The actual full structure of the loop function is like this:

while(true)

Call loop()

if (condition)

Run your code

else

Run your other code

Check for serial data

By putting a while(true) inside your if you:

Remove the overhead of calling loop() every time
Remove the overhead of checking for serial data (that is what the SerialEvent system is all about)
Remove the overhead of checking the if every iteration.

So the executing part of your code now looks like:

while(true)

Run your code.

If your code needs to run in a tight loop it can provide some speed improvements, yes, but at the cost of:

No SerialEvent processing (normal Serial works, but the SerialEvent system breaks)
Harder to "get out" of the loop to do something else (although break can help with that).
On ESP8266 boards the watchdog will time out unless you manually yield() regularly.

Would I suggest doing it? Well, there are times when it can be beneficial, but those times are few and far between. If you don't need to do it then, in general, don't do it.


text:
What is this extender?
I recently got an Arduino starter kit from a friend that he wasn't using and this came with it but, i can't find anything about it, cause i don't know how to search for it.
Anyone can enlighten me what it is?

Looks similar to:
"8 Channel 5V/3.3V IIC UART SPI TTL Logic Level Converter"
https://www.aliexpress.com/item/32977711795.html

@FilipFranik Thanks that is the correct one

@FilipFranik you should post that as an answer so the OP can accept it.

Looks similar to:
"8 Channel 5V/3.3V IIC UART SPI TTL Logic Level Converter"

Image above was screen capped from: https://www.aliexpress.com/item/32977711795.html


text:
Adding bootloader to Feather M0 Bluefruit LE
I want to make a custom Feather M0 Bluefruit LE. I know this means that I will have to add a bootloader to the ATSAMD21G18.
I have seen that there are many useful articles in relation to adding bootloader to this chip like
https://www.instructables.com/id/ATSAMD21g18-Bootloader-With-J-link-Debugger/
and
https://learn.adafruit.com/proper-step-debugging-atsamd21-arduino-zero-m0/restoring-bootloader
and
https://learn.adafruit.com/compiling-m0-atsamd21-bootloader/compile
I wanted to make sure that the bootloader will allow me to access the Bluetooth module on the board. Does anyone know if this bootloader will do that? Or is there another type of bootloader I need? Also, do I need a J-link connection on the custom board? can I just use USB?

it is unclear what this means ... allow me to access the Bluetooth module

purpose of bootloader is to load the application over USB. bootloader has nothing to do with BLE. you can't load the bootloader over USB. bootloader is what makes upload over USB possible

Hi @jsotola I didn't know if I had to set a specific module in Bootloader or if I can just use the generic bootloader files I found on those links above and then upload firmware to access the BLE afterwords.


text:
sending 16 bit command via SPI to a NCV7719 (half bridge)
I am trying to send a 16 bit command to a Half bridge (data sheet here http://www.onsemi.com/pub/Collateral/NCV7719-D.PDF) to open one of the transistors to turn on an LED. at the bottom of the data sheet (page 13) it says which bit needs to be a 1 or a 0 in order to activate the half bridge. This is the code I wrote but it isn't work (I'm assuming I'm not sending the 16 bits properly). Can someone figure out why this isn't working?
#include <SPI.h>

void setup() {
  // put your setup code here, to run once:
  pinMode(10,OUTPUT);
  pinMode(8,OUTPUT);
  digitalWrite(8,HIGH);
  SPI.begin();

}

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

  //pulling pin low to decide to write to device
  digitalWrite(10,LOW);

  //function to send information
  //truning on half bridge 4
  SPI.transfer(0000010000000000);
delay(500);
  //finish transfering data
  digitalWrite(10,HIGH);

}

FYI, 0000010000000000 is not a binary constant in C++ syntax.

SPI writes in 8-bit bytes. So the writes need to look like this:
  SPI.transfer(0b00000100);  // first byte
  SPI.transfer(0b00000000);  // second byte

Possibly in the other order depending on which byte the device expects first.


text:
High pass filtering accelerometer data on Arduino
I'm trying to use an accelerometer for user input to a device. The idea is that the user input will be tied to "taps" on the accelerometer, one tap means something, two taps something else, etc.
I'm using an Adafruit Feather M0 as my microcontroller, controlling an accelerometer that feeds me x,y,z-data at a sampling rate of 100 Hz. I now then want to high pass filter the data with a cutoff frequency of 10 Hz, since taps on the accelerometer give rise to much higher frequencies than other "noise", such as movement.
The accelerometer uses a FIFO buffer to output the data, so I collect 20 samples at a time, and I want to filter those 20 samples with a high pass filter to see if there is a tap within that sampling window. I am currently using the filter function on Arduino playground, https://playground.arduino.cc/Code/Filters.
However, and here is my problem; When I implement this in my code, the filtering "restarts" each window, so that my filtered data looks like this:
[X], [Y], [Z]
0.00,0.00,0.00
-39.67,94.13,-85.18
-29.89,71.66,-64.18
-24.02,53.99,-49.08
-17.39,40.78,-37.09
-13.00,30.51,-27.74
-9.80,22.99,-20.91
-7.58,17.00,-16.17
-7.01,13.88,-14.01
-4.86,12.04,-10.53
-4.02,9.96,-8.71
-2.44,8.05,-7.04
-1.99,6.57,-5.74
-1.60,5.26,-3.80
-2.76,3.27,-4.45
-1.43,2.67,-3.63
-1.16,2.16,-2.13
-0.94,2.55,-1.72
-0.76,1.26,-0.58
-0.62,0.21,-1.29

0.00,0.00,0.00
-40.26,94.51,-84.88
-30.38,70.55,-64.78
-22.13,53.89,-48.04
-17.42,40.60,-37.69
-13.91,29.87,-27.68
-10.99,23.61,-22.67
-10.05,19.04,-16.00
-5.78,14.79,-13.94
-4.69,12.82,-11.31
-3.84,9.69,-9.27
-3.14,7.91,-7.56
-2.52,6.35,-6.08
-2.07,5.22,-4.18
-0.88,4.29,-3.43
-2.35,4.32,-3.62
-0.29,3.54,-2.97
-1.07,2.94,-3.29
-1.63,0.74,-1.02
-0.50,1.38,-1.60

0.00,0.00,0.00
-40.51,95.10,-85.37
-30.32,70.41,-65.39
-22.86,53.10,-49.31
-17.26,40.83,-35.71
-13.45,31.81,-27.81
-9.37,22.43,-20.92
-7.80,17.62,-15.74
-6.50,13.01,-13.10
-4.04,9.56,-8.16
-3.02,7.15,-6.85
-2.29,5.42,-4.43
-2.70,3.63,-4.46
-1.38,4.56,-3.61
-1.14,2.95,-2.16
-1.73,2.38,-1.75
-1.32,2.59,-2.10
-1.05,0.47,-1.67
-0.04,1.12,-1.28
-0.03,0.90,-1.03

I don't understand why this happens, and why the data in the subsequent windows aren't suppressed from the start. I have implemented a very similar solution in Python which works very well with the filtering. Have I misunderstood how Arduinos filtering functions work?
Here is my code:
// Include SPI library
#include <SPI.h>
#include <Filters.h>

// List of addresses: 7-bit adresses, 8th bit is R/W bit, and is set in the functions readRegister and writeRegister.
char X_data_low = 0x28;
char X_data_high = 0x29;
char Y_data_low = 0x2A;
char Y_data_high = 0x2B;
char Z_data_low = 0x2C;
char Z_data_high = 0x2D;

char CTRL_REG1 = 0x20; // Controls data rate selection, low power mode, and X-, Y- and Z-axis enable
char CTRL_REG1_value = 0b00101111; // 0001 1111 = 1 Hz, LP mode, XYZ enable.

char CTRL_REG5 = 0x24; // Enables FIFO mode, among others.
char CTRL_REG5_value = 0b01000000; // 0100 0000, FIFO enabled, all else is zero.

char STATUS_REG = 0x27; // Flags for new XYZ values.

char FIFO_CTRL_REG = 0x2E; // Controls FIFO mode (Bypass, FIFO, Stream, Stream-To-FIFO)
char FIFO_CTRL_REG_value = 0b01000000; // Selects FIFO mode

char FIFO_SRC_REG = 0x2F; // Watermark level, FIFO Overrun, FIFO empty, FSS. Can read FSS to know how many unread samples FIFO buffer contains currently.

//int smpls = 20; // Number of samples

char values[240]; // buffer for storing read values.

int x_val[40]; // Arrays for storing values before filtering
int y_val[40];
int z_val[40];

float filtered_x_val[40]; // Arrays for storing values after filtering
float filtered_y_val[40];
float filtered_z_val[40];

int CS = 5; // Chip select pin

int concat_val = 0b00011111; // For concatenation with values[0] to find number of samples in FIFO buffer
int number_of_FIFO_values; // Number of FIFO samples

// Testing Arduinos own filtering

// filters out changes slower that 10 Hz.
float filterFrequency = 10.0;

// create a one pole (RC) lowpass filter
FilterOnePole highpassFilter_x( HIGHPASS, filterFrequency );
FilterOnePole highpassFilter_y( HIGHPASS, filterFrequency );
FilterOnePole highpassFilter_z( HIGHPASS, filterFrequency );

void setup() {
  // put your setup code here, to run once:
  // Opening pins
  pinMode(22, INPUT_PULLUP); // MISO
  pinMode(24, OUTPUT); // SCK
  pinMode(23, OUTPUT); // MOSI
  pinMode(CS, OUTPUT);  // CS
  pinMode(14, OUTPUT);  // VDD_IO, for use when no breadboard is available to connect both VDD and VDD_IO to 3.3V output
  digitalWrite(CS, HIGH);
  digitalWrite(14, HIGH);
  delay(50);

  // Communication with computer
  Serial.begin(9600);

  // SPI
  SPI.begin();
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
  // Loading settings
  delay(10);
  writeRegister(CTRL_REG1,CTRL_REG1_value);
  delay(10);
  writeRegister(CTRL_REG5,CTRL_REG5_value);
  delay(10);
  writeRegister(FIFO_CTRL_REG,FIFO_CTRL_REG_value);
  delay(10);

}

void loop() {
  readRegister(0x2F,1,values);
  number_of_FIFO_values = values[0] & concat_val;

  if (number_of_FIFO_values >= 20){ // It is enough to read high values since LP mode is only 8 bits
    readRegister(0x28,120,values);
    int x_count = 0; // Counters to keep track of which value in x_val, y_val, z_val to be assigned
    int y_count = 0;
    int z_count = 0;
    for(int i=0; i<120; i++){
      if (i % 6 == 1) {
        x_val[x_count] = int(values[i]);
        if(x_val[x_count] > 127)
          x_val[x_count] -= 256;
        x_count += 1;
        }
      if (i % 6 == 3) {
        y_val[y_count] = int(values[i]);
        if(y_val[y_count] > 127)
          y_val[y_count] -= 256;
        y_count += 1;
        }
      if (i % 6 == 5) {
        z_val[z_count] = int(values[i]);
        if(z_val[z_count] > 127)
          z_val[z_count] -= 256;
        z_count += 1;
        }
      }
    Serial.print('\n');
    filtering(x_val,y_val,z_val);
    writeRegister(FIFO_CTRL_REG,0b00000000);
    delay(10);
    writeRegister(FIFO_CTRL_REG,FIFO_CTRL_REG_value);
    delay(10);
  }
}

void filtering(int x_arr[], int y_arr[], int z_arr[]){
    for(int i=0; i<20; i++) {
      highpassFilter_x.input(x_arr[i]);
      highpassFilter_y.input(y_arr[i]);
      highpassFilter_z.input(z_arr[i]);
      filtered_x_val[i] = highpassFilter_x.output();
      filtered_y_val[i] = highpassFilter_y.output();
      filtered_z_val[i] = highpassFilter_z.output();
      Serial.print(filtered_x_val[i]);
      Serial.print(",");
      Serial.print(filtered_y_val[i]);
      Serial.print(",");
      Serial.print(filtered_z_val[i]);
      Serial.print('\n');
    }
  }

//This function will write a value to a register on the sensor.
// Parameters:
//  char registerAddress - The register to write a value to
//  char value - The value to be written to the specified register.
// The bits to specify write or read operation on slave device, and single
// or multiple register reading in reading operation, are included in the
// registeraddress.
// As defined by protocol, the MSB of the address indicates write/read, and the following bit indicate single/multiple reading. Cause ADXL345 support Byte operation,
// The MSB is the 8th bit, the following bit is the 7th bit. (note: if indicating multiple bits reading, ADXL345 will increasing the register address automatically to the
// next successive register like a pointer.
void writeRegister(char registerAddress, char value){
  //Set Chip Select pin low to signal the beginning of an SPI packet.
  digitalWrite(CS, LOW);
  //Transfer the register address over SPI.
  // All ADXL345 register address are smaller than 0100 0000, all are like 00** ****, so that any register address of ADXL345 can be used directly for register write operation
  // without any change on the MSB and its following bit, but the case for reading operation is the opposite.
  // Might need a delay here between CS going low and data transfer.
  SPI.transfer(registerAddress);
  //Transfer the desired register value over SPI.
  // ignored the reture of SPI.transfer in writer operation
  SPI.transfer(value);
  //Set the Chip Select pin high to signal the end of an SPI packet.
  digitalWrite(CS, HIGH);
}

//This function will read a certain number of registers starting from a specified address and store their values in a buffer.
//Parameters:
//  char registerAddress - The register addresse to start the read sequence from.
//  int numBytes - The number of registers that should be read.
//  char * values - A pointer to a buffer where the results of the operation should be stored.
void readRegister(char registerAddress, int numBytes, char * values){
  //Since we're performing a read operation, the most significant bit (bit 7(counting starts from bit 0)) of the register address should be set high.
  char address = 0x80 | registerAddress;
  //If we're doing a multi-byte read, bit 6 (counting starts from bit 0)needs to be set high as well.
  if(numBytes > 1)address = address | 0x40;

  //Set the Chip select pin low to start an SPI packet.
  digitalWrite(CS, LOW);
  //Transfer the starting register address that needs to be read.
  SPI.transfer(address);
  //Continue to read registers until we've read the number specified, storing the results to the input buffer.
  //SPI is full duplex transsmission. Every signle time SPI.transfer can and can only transmit 8 bits. the input parameter will be delived to slave, and it's return will be
  // the data that master device and get from the slave device. The data returned during master device's write operation makes no sense, hence always been ignored by not
  // doing any assignment operation.
  for(int i=0; i<numBytes; i++){
    values[i] = SPI.transfer(0x00);
  }
  //Set the Chips Select pin high to end the SPI packet.
  digitalWrite(CS, HIGH);
}

I opened an issue in the library’s project page.

This filter library is sensitive to the timing of you calling
FilterOnePole::input(). It assumes that the delays between consecutive
calls are the same as the delays between the samples being measured.
C.f. the first statement in the method, which is a call to
micros(). The pauses between your 20-sample buffers are then
interpreted like long times during which the input only changed very
little.
If you are sampling at a constant data rate, I recommend you reimplement
the filter yourself: it is simple enough and it will be way more
efficient than the one you found on Playground.

Edit: Here is a simple implementation of a first-order high-pass
filter like the one in the library, but using a constant sampling rate:
class HigPassFilter
{
public:
    HigPassFilter(float reduced_frequency)
    : alpha(1-exp(-2*M_PI*reduced_frequency)), y(0) {}
    float operator()(float x) {
        y += alpha*(x-y);
        return x-y;
    }
private:
    float alpha, y;
};

You would use it like this:
// Create the filters.
HigPassFilter highpassFilter_x(cutoffFrequency/samplingFerquency);
HigPassFilter highpassFilter_y(cutoffFrequency/samplingFerquency);
HigPassFilter highpassFilter_z(cutoffFrequency/samplingFerquency);

// Apply them.
filtered_x_val[i] = highpassFilter_x(x_arr[i]);
filtered_y_val[i] = highpassFilter_y(y_arr[i]);
filtered_z_val[i] = highpassFilter_z(z_arr[i]);

Huge thanks!
I am however quite the beginner in C++, so I'm wondering that this line in your code do? Specifically, what is alpha in this context?
: alpha(1-exp(-2*M_PI*reduced_frequency)), y(0) {}

@LarsPetersson: It initializes the filter constant alpha to the expression 1-exp(...) and the variable y to zero. This α would be equivalent to 1−ampFactor on the library, which is initialized here. The y is the initial value, which also defaults to zero in that library.

@LarsPetersson, it's called an "initialization list". Google it, and see here for one example description: https://www.cprogramming.com/tutorial/initialization-lists-c++.html


text:
Problem with motor driver shield
I have recently bought a L293D shield and 2 BO motors. Whenever I connect the motors to the shield it makes a beeping noise. I searched online and found that I need to change PWM frequency but I know nothing about it and anyone please tell me about the PWM frequency and how to change it.
I have used almost every sketch found online but condition remains same. I am using 9V battery as External power supply and it is absolutely new. Please help me.

Motor driving 101: 1) Do not use 9v batteries, they are for low current circuits not motors.  2) Do not use the antique and horribly lossy L293 or L298.

Then what should I use to drive motors from arduino @Chris Stratton

Probably an FET bridge.  Which one depends on the motor specs, for some small motors the TB6612FNG can be good.

Acting as a conduit for Google: Arduino Change PWM Frequency shows me:
https://playground.arduino.cc/Code/PwmFrequency
Which has the following example function:
/**
 * Divides a given PWM pin frequency by a divisor.
 *
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *      o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *        256, and 1024.
 *      o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *        128, 256, and 1024.
 *
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired on timer0
 *   - Pins 9 and 10 are paired on timer1
 *   - Pins 3 and 11 are paired on timer2
 *
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 *
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://forum.arduino.cc/index.php?topic=16612#msg121031
 */
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x07; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

And numerous results from this SE community also:
https://www.google.com/search?q=arduino+change+PWM+frequency+site:arduino.stackexchange.com
Which note methods for calculating/setting specific frequencies and pitfalls and side-effects of making such changes.


text:
Problems encountered when trying to program Arduino UNO via esp8266 with ESP-Link
Basically my project requires to program Arduino Board wirelessly and I have found ESP-link which seems to match my purpose.
I tried to follow the instructions in documentations on the github page https://github.com/jeelabs/esp-link I am using Arduino UNO and ESP8266-01 by the way.
Flashing ESP-link into ESP8266 was successful. I followed the configuration page and successfully connect the ESP8266 to an MQTT Server. I connect my Arduino UNO to computer via USB Serial. Connected UNO to ESP8266 using the default settings (TX - TX, RX - RX, GPIO0 - RST). When I checked the Microcontroller Console page, I could send and received messages to/from UNO as well as resetting the UNO (I programmed blink sketch into my UNO, so I can see every time I reset it, it works)
However, the next step is not that successful. I tried to program UNO via ESP8266 but it does not work out quite well. There are several methods posted on the documentation https://github.com/jeelabs/esp-link/blob/master/UC-FLASHING.md and I have tried them to some extent.
1.Use Avrdude to program. Basically I copied the command when Arduino IDE programmed UNO using avrdude, and change the port to net:{localIP_of_ESP8266}:23
By the way I tested the code by set the port to local Serial port and it works
I get the error and below is what cmd shows:
avrdude.exe: Version 6.3, compiled on Feb 17 2016 at 09:25:53
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

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

             Using Port                    : net:192.168.10.97:23
             Using Programmer              : arduino
             Overriding Baud Rate          : 115200
avrdude.exe: ser_drain(): read error: The parameter is incorrect

avrdude.exe: ser_drain(): read error: The parameter is incorrect

avrdude.exe: ser_drain(): read error: The parameter is incorrect

avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 1 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 2 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 3 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 4 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 5 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 6 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 7 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 8 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 9 of 10: not in sync: resp=0xa4
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 10 of 10: not in sync: resp=0xa4
avrdude.exe: ser_drain(): read error: The parameter is incorrect

avrdude.exe done.  Thank you.

Then I tried the post http method. Basically I sent a post request to http://{IP_of_ESP8266}/pgm/sync     in my case:

POST http://192.168.10.97/pgm/sync
I get 204 OK as response
Then I tried:
GET http://192.168.10.97/pgm/sync
It returns "sync abandoned after 8 attempts"
So I am stuck again

I tried also a small tool called avr-link https://gitlab.com/bc547-playground/avr-link
Someone used it to program a pro mini via esp8266-01 which I think is close enough to my situation. I ran it on the powershell (I am using Windos 10 btw)
The result is

PS C:\> .\avr-link.exe flash --esp 192.168.10.97 --file C:/Blink.ino.hex
AVR reset initiated...waiting for SYNC status
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
FATAL ERROR: Unexpected response:
00000000  73 79 6e 63 20 61 62 61  6e 64 6f 6e 65 64 20 61  |sync abandoned a|
00000010  66 74 65 72 20 38 20 61  74 74 65 6d 70 74 73     |fter 8 attempts|

using avrflash script. I am not sure how to run it in Windows OS so I did not use the script. If anyone could tell me about this, I appreciate it as well.

So to conclude, the problem seems to happen in getting sync after resetting the UNO (Although I am not 100% sure what does it mean - I am not familiar with the hardware process when flashing a UNO)
There is a paragraph actually in documentation suggesting the problem. Here is the quote:

If you are having trouble with the built-in programmer and see something like this:
./avrflash 192.168.3.104 blink.hex Error checking sync: FAILED to SYNC: abandoned after timeout, got:
  :\xF/\x00\xCj\xCz\xCJ\xCZ\xC\xAÜ\xC\xAä\xC\xAÜ\xC\xAä\xC\xBì\xC\xBô\xC\xBì\xC\xBô\xC\xAÜ\xC\xAä\xC
the most likely cause is a baud rate mismatch and/or a bad connection
  from the esp8266 to the AVRs reset line. The baud rate used by
  esp-link is set on the uC Console web page and, as mentioned above, it
  will automatically try 9600, 57600, and 115200 as well. The above
  garbage characters are most likely due to optiboot timing out and
  starting the sketch and then the sketch sending data at a different
  baud rate than configured into esp-link. Note that sketches don't
  necessarily use the same baud rate as optiboot, so you may have the
  correct baud rate configured but reset isn't functioning, or reset may
  be functioning but the baud rate may be incorrect.

I tried to change the baud rate (both in command and microController Console page) but it still does not work. And in Arduino IDE it programs the board in 115200 so I should be okay with this baud rate imo, but anyway it did not work even when I change it.
As for the reset connection, I could reset the UNO by pressing reset in the Microcrontroller Console page so It shouldn't be the problem (and I don't know how to change it anyway).
Thank you for your patience reading through all this crap..
So what do you think the problem is? Any suggestion would help :D

I have found out the problem: I connected TX and RX wrong way around. It should be TX - RX and RX -TX. ------ However, I still cannot access ESP-Link by host name, but I think the reason is : 1.I don't have mDNS service on my computer (or more precisely a properly functioned one) 2. The mDNS service on ESP-Link is not stable. The other computer can access esp-link server some time but cannot some other time.

@JnJ, In the answer I write about the esp-link mdns bug

I tested it some weeks ago again after a year. The default upload from IDE should work, but mDNS in esp-link has now a bug and propagates the service only in AP mode so in STA mode the IDE doesn't show the network port.
from command line you can upload OTA with arduinoOTA tool used by IDE
example:

/home/duro/.arduino15/packages/arduino/tools/arduinoOTA/1.1.1/bin/arduinoOTA
  -address 192.168.1.104 -port 80 -sketch /tmp/arduino_build_89762/Blink.ino.hex -upload /pgm/upload -sync
  /pgm/sync -reset /log/reset -sync_exp 204:SYNC

If the mdns bug was fixed, for upload from IDE some settings must be added to board.txt
uno.upload.network.endpoint_upload=/pgm/upload
uno.upload.network.endpoint_sync=/pgm/sync
uno.upload.network.sync_return=204:SYNC
uno.upload.network.endpoint_reset=/log/reset
uno.upload.network.port=80

Uno WiFi uses an old version of esp-link so the settings and tutorial apply

Thank you for replying.. I succeeded last week but forgot to update the question. It was the connection between ESP and Arduino board. Should be TX - RX and RX - TX while I connected them wrong way around.

FINALLY!!! I can just ignore that mDNS crap that's just there to get some network info I already know :O

I didn't test the avrdude network upload with esp-link. I used it with esp8266 AVRISP library. I configured the Arduino toolchain for network upload in platform.txt.

tools.avrdude.upload.network_pattern="{cmd.path}" "-C{config.path}"
  -p{build.mcu} -c{upload.protocol} "-Pnet:{serial.port}:328" "-Uflash:w:{build.path}/{build.project_name}.hex:i"

Warning: the use case in my other answer uses the original setting of tools.avrdude.upload.network_pattern


text:
GSM library_ all examples ar working except GPRS?
i am using arduino uno and sim808. i connected the sim808 to pins 2,3 on arduino uno and used GSM library. i tested all examples: make and receive a call or messages. the part of GPRS initialization is not working after many tries in changing APN and pin number.
i want to use the arduino as a webserver exactly as the example includded in the library.
any one can help?
thanks,
https://www.arduino.cc/en/Reference/GSM

I had the same problem I solved it by moving the jumper wires on the shield(if you are using one) to SW serial. if that doesn't work try testing it with AT commands


text:
Using digital pins 0/1 on Arduino Due when writing/reading over serialUSB port
I am aware that you cannot use pins 0 and 1 as digital pinouts when communicating over serial via serial.print(), but what if you are using the native port on the due with serialUSB.write()?
Thanks

Yes, you can use 0/1 while using the native USB. The two are completely separate.


text:
On a motor after a continuous input of a certain amount of time
I would like to produce an output after a constant input is detected for a certain amount of time. Below is a simple code of what I am trying to do minus the time factor. Can someone help me on how to code out the duration of an input occurrence?  i.e.
if (sensorValue > threshold);
    //if this occurs for more than 4 hours, then
    digitalWrite (3, HIGH);

A constant input would be an analog value between two bounderies. Not just a check if it is above a threshold. Use millis for timing, it can count up to 50 days. The blink-without-delay uses an interval, but it explains the use of millis: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay Provide a minimal but complete working sketch please.

You must store the state of the last readings and do something like this:
    //Off-loop:
    bool state_changed = false;
    unsigned long time_in_state = 0;
    unsigned long last_reading = 0;

    //On-loop:
    if (sensorValue > treshold && !state_changed) {
        time_in_state += millis() - last_reading;
        last_reading = millis();
    }
    else {
        state_changed = true;
        time_in_state = 0;
    }

    if (time_in_state > TIME_REQUIRED) {
      digitalWrite (3, HIGH);
    }


text:
Problem with incrementing values of an RGB LED
I'm trying to use a remote control to control the red/green/blue values of an RGB LED using an Arduino Uno. Here's what I've got so far:
#include <IRremote.h>
#define IRPin 7
#define bluePin 9
#define greenPin 10
#define redPin 11

int blueValue = 0;
int greenValue = 0;
int redValue = 0;

IRrecv irrecv(7);
decode_results results;

void RGBLED(int blue, int green, int red)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

void setup(){
  irrecv.enableIRIn();
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop(){
if (irrecv.decode(&results)){
  switch(results.value)
  {
    case 0xFF6897:
      Serial.println("Red+16");
      redValue = redValue + 16;
      if(redValue >= 256)
      {
        redValue = 255;
      }
    break;
    case 0xFF9867:
      Serial.println("Green+16");
      greenValue = greenValue + 16;
      if(greenValue >= 256)
      {
        greenValue = 255;
      }
    break;
    case 0xFFB04F:
      Serial.println("Blue+16");
      blueValue = blueValue + 16;
      if(blueValue >= 256)
      {
        blueValue = 255;
      }
    break;
    case 0xFF30CF:
      Serial.println("Red-16");
      redValue = redValue - 16;
      if(redValue < 0)
      {
        redValue = 0;
      }
    break;
    case 0xFF18E7:
      Serial.println("Green-16");
      greenValue = greenValue - 16;
      if(greenValue < 0)
      {
        greenValue = 0;
      }
    break;
    case 0xFF7A85:
      Serial.println("Blue-16");
      blueValue = blueValue - 16;
      if(blueValue < 0)
      {
        blueValue = 0;
      }
    break;
  }
irrecv.resume();
RGBLED(blueValue, greenValue, redValue);
}

Everything works fine, except the adding up to redValue. It's the same exact code that is used for greenValue and blueValue. The substraction from redValue works fine too. Everytime the problematic function gets called, the serial monitor prints Re and the whole thing just stops working.
I have tried rewriting that code from scratch, copying the other code, but nothing worked. I have switched up the codes from my IR remote but that had nothing to do with it either.
Can anyone spot the mistakes or tell me what I'm doing wrong?
Thanks in advance

try a short delay and see if that helps

Try swapping the red case with the green case, and see if now the green will give the problem. (i.e. maybe the first case somehow breaks things).

Are you sure this is the code you are using? setup() uses sensorPIN but it does not appear to be declared anywhere.

@Craig I'm also using a sound sensor as a clap sensor to turn on the LED, but that isn't causing the issue, so I removed it.

@Gerben I tried switching the two around and the red one is still broken.

@dandavis adding a short delay after the Serial.println makes it so that the message gets printed fully, but it still doesn't work.


text:
4x4 matrix keypad - Multiple inputs cause extra readings
I have the following matrix keypad -
I am using this as a sort of controller with my Arduino (Mega2560) but I can't get real multiple inputs to work. I am able to have say two individual keys pressed at a time but after that they overlap with eachother. (Using the Keypad library also).
Here is an illustration of the issue:

If I press the 3 blue buttons and use the getKeys function it thinks that the red one is also pressed. This works when any three or more buttons are pressed that produce a square.

That's a very well known issue with matrix keypads. What is your question?

See http://pcbheaven.com/wikipages/How_Key_Matrices_Works/ section "The ghosting problem"

that's just how it works, nothing you can do about it. you might find some 3 button combos are detectable, but certainly not all will be.

I have a post about keypad matrices which discusses this issue. The issue with keypads is, that if you don't install diodes, if three keys are pressed the current finds its way around those three keys and it looks like a fourth is pressed.

If you install diodes, like this, the issue goes away:

It can be a little tedious to do, but I managed it the other day with surface mounted diodes.

The above board is different from yours, mine is one with soft switches which I could lift off to get at the board.
Yours looks like it might be almost impossible to cut the tracks and install the diodes. Without them you can press two keys at once without issues. Perhaps that is enough. :)


text:
Output 20x20 Image to Arduino serial monitor
I am working on an Arduino project where I need to display a black and white (no gray) image to the serial monitor. It doesn't need to be high resolution, so something like 20x20 would work. I will be using this several times a second to make video of a sort, but it doesn't need to be a very high fps (4 or 5 would work). Currently I am just using unicode blocks and printing them (at a baud rate of 500,000) to the serial monitor, but it ends up having a very bad screen tear sort of effect. Is there any way to do this better, or at the very least make the serial monitor print everything at once instead of each character individually?
Thanks!

I think the serial monitor is clearly not the right output device for this kind of information at that update rate. It is text-line oriented and you have so little control over the "device". Consider one of the many low-res LCD or OLED displays.

Is the "screen tear" a result of not using fixed spacing fonts?  I think you can set the font to be used under File:Preferences, and it not then perhaps in preferences.txt (restart the IDE to see it).

"everything at once", I think you'll be limited to the speed of sending 20 lines across, either as 20 discrete Serial.write's, or in a for:loop.

The Arduino IDE's serial monitor is, to put it bluntly, awful.
Switch to a proper ANSI compatible serial terminal emulator (Tera Term, Putty, Minicom, whatever) and use ANSI control sequences to manipulate the screen.
The simplest ones to use are:
Serial.print("\e[2J"); // Clear the screen
Serial.print("\e[1;1H"); // Move the cursor to coordinate (1,1)

Use the first one to clear the screen in setup(), then use the second one at the start of the loop to move to the top-left corner of the screen (1,1 is top left - the coordinates are given as Y;X not X;Y and start from 1 not 0).
Print your 20 lines of 20 characters as either space (nothing) or your chosen "pixel" character.  The spaces overwrite the existing characters to help reduce flicker (clearing the screen every time would be just awful).
The way serial works (sending one character at a time sequentially) there is no such thing as "All at once". The above is the best you can get without writing your own program to interpret incoming serial data representing an image frame and displaying it.

Is there any way to do this better, or at the very least make the serial monitor print everything at once instead of each character individually?

No, serial isn't the right technology for that. By its very definition, it transmits data one bit at a time, one byte after the other. What you're after is to transmit the data in parallel. You're already making the closest approximation to parallel you can using serial - transmitting the data at the highest rate you can to minimize the skew. The longer the time between frames and the shorter the time to transmit one frame, the better your result will be. But you may have reached the limit for 5fps with the available serial hardware.


text:
Problems improving the inquiry speed of Bluetooth HC-05
I'm buiding a project with the Arduino and Bluetooth HC-05 module that receives the MACs of Bluetooth devices around (does not connect, just inquiry). It works, but I want a better performance in detecting devices, because it doesn't find devices that stay less than 2 seconds in the area. So, I want it to work faster, detecting even if the device stays for 1 second (or maybe less) in the range of the HC-05.
-First, I tried to select the baud-rate (from 9600 to 1382400) of USART, but I tested it, and it did not change anything.
-Then, I tried to config the period and the duration of the inquiry process by "AT+IPSCAN", but, for any value I adjust, also results in anything.
Thought maybe I did not configure parameters, but I tested "AT + IPSCAN?" and "AT + UART?" and the values are those that I set.
This is strange, but I could not find a solution. Does anyone know what it could be?

You can't change how fast Bluetooth devices report their presence.
Bluetooth works the opposite way that you expect. An inquiry doesn't actively request what devices are there. Instead it sits and listens passively for devices to announce that they are there.
If a device enters the target zone and then leaves again before it has broadcast it's "I am here" signal there is nothing you can do.
That is why inquiries take so long. They wait enough time for devices nearby to announce that they are here.
I am not familiar with that specific module, so I don't know if it is always listening in the background and maintaining a list, or just listening during and enquiry, but either way the onus is on the remote device to announce that it is there.

The config "AT + IPSCAN", according to the datasheet of HC-05, sets the time and duration that the device do an inquiry (if is listening) or scan (if is sending "I am here"). So, I understood that if I change these parametres, I'm doing exactly what you said thats it's not adjustable. I can maybe be wrong, but it's make sense in my mind and it's consistent with my previous research of this topic. The problem is that, in practice, it doesn'st really change anything, but would not make sense it has this configuration


text:
Bluetooth module HC-05 not finding mobile phones, only PC
I put the HC-05 in the AT mode with arduino and the comands:
AT+CMODE=1
AT+ROLE=1
AT+INQM=0,10,48
AT+CLASS=0
AT+INIT
AT+INC

It responds "OK" after all till AT+INC, and after this, shows only my notebook's adress, but it has many other mobile phones near with bluetooth on (I can find with my cell phone) and they are not found. Why? Someone help me please

Bluetooth maybe on, but some phones are "invisible" until you put them in "other Bluetooth devices can find me" -mode. Current iPhones are visible when Bluetooth is on but, Androids for example, (at least 7.0 upwards) are visible only when you have the Bluetooth settings screen open.

I'll make my comment an answer then, which you can mark as correct, so other people with the same problem can find the solution here. ;)

Bluetooth maybe on, but some phones are "invisible" until you put them in "other Bluetooth devices can find me" -mode.
Current iPhones are visible when Bluetooth is on but, Androids for example, (at least 7.0 upwards) are visible only when you have the Bluetooth settings screen open.


text:
Voltage to keep my board safe
I have recently made a home automation system using node mcu and relay module and i am powering both together using my 5V ,2A dc adapter and i am scared that if I'll keep using it for very long hours and that too daily my node mcu board would disrupt soon. So i wanted to ask that what to keep the minimum voltage. So to keep the board safe

to which pin on the NodeMcu is the 5 V input wired?

@Juraj it is the 3v3 pin

and it doesn't smoke?

@Juraj no it doesn't and i kept it running for 1 hr.

@Juraj i just wanna ask... should i lower the voltage or change the pin to keep my board safe...for longer hrs of running

@Juraj yes it has a vin pin..

https://github.com/nodemcu/nodemcu-devkit-v1.0/issues/15

@Juraj sir if i connect it to vin at 5v can keep it running daily for at least 11 to 10 hrs.?

it has a regulator on Vin. it can run 24/7 then

I'm not sure I'd trust it, after given it 5V instead of 3.3V for over an hour.

@Juraj how to check if it has a regulator

if it is a NodeMcu it has it


text:
ESP8266 doesn't detect WiFi
I try to connect my NodeMCU Amica to my WiFi network, but it doesn't detect any networks around. I chose Board "NodeMCU 1.0 (ESP - 12E Module)", upload speed of 115200 and I have the correct port selected.
When I try the blink sketch, it works perfectly, but when I try to use the WiFiScan example, I only get the message "no networks found" and I don't.
I did pay attention that the upload speed in the sketch and monitor are always the same as the one I selected. Also, I tried out different upload speeds, without any succes either.
I already changed my network to 2.4 GHz, and also tried to downgrade the libraries to older versions, but nothing helped till now.
About any help, I would be really glad.

try to erase the flash with esptool to clear sdk settings if you changed  firmwares and arduino package versions

Ok, finally managed to get it running, but it still doesn't find any networks. By erasing the flash you just meant basically esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash, am I right?

Firstly try to set it up as AP and check whether is it working ? If not, there is issue with power supply. Because WiFi Scan requires more current... than normal WiFi connection operation.

Make sure you have entered correct ssid and password for that.
It is very much case sensitive.
Second reason for this can be insufficient amount of power supply supplied to it so make sure you are using good quality of power adapter for it.
3.https://tttapa.github.io/ESP8266/Chap07%20-%20Wi-Fi%20Connections.html
Then try refering this link step by step...
Hope this will help
Thanks


text:
Tian stops working after some hours
I'm having a very strange problem. I have a Tian that is programmed to send out sensor data to a server
every x seconds.
My program run well but after 14,15 hours of operation it stops working and I don't receive datas. The program is fast at the beginning, then after 2 to 3 hours before stopping, it becomes more and more slow with the message "timeout".
I think maybe a misuse of the Ciao library on my part could be at the root of the problem. Or maybe a modification at the program level could correct the problem. So if I can have some help about this..
(the problem doesn't come from the use of String, I have already tested use of array with cstrings and it doesn't work).
Here is the part of the program that I think is problematic (there is another CiaoReadWrite nearly similar to the first) :
void CiaoReadWrite1() { CiaoData data = Ciao.read("restserver");
if (!data.isEmpty())
{
  String id = data.get(0);
  String sender = data.get(1);
  String message = data.get(2);

  splitString(message,"=",LtT2,9);

  gen            =LtT2[0].toInt(); LtT2[0]="";
  belt           =LtT2[1].toInt(); LtT2[1]="";
  genReady       =LtT2[2].toInt(); LtT2[2]="";
  hvOnOff        =LtT2[3].toInt(); LtT2[3]="";
  beep           =LtT2[4].toInt(); LtT2[4]="";
  heart1         =LtT2[5].toInt(); LtT2[5]="";
  sendConf       =LtT2[6].toInt(); LtT2[6]="";
  heart2FB       =LtT2[7].toInt(); LtT2[7]="";

  beepFB         =beep;
  heart1FB       =heart1;
  sendConfFB     =sendConf;

  Ciao.writeResponse("restserver",id, String(baroAlti*100)+"="+baroHumi*10+"="+baroPres+"="+baroTemp*10+"="+beepFB+"="+heart1FB+"="+heart2+"="+sendConfFB+"="+
                                      secCust1+"="+secCust2+"="+secEmrgSW+"="+secloop+"="+secLoop1+"="+secLoop2+"="+gndSwGnd+"="+gndSwUGnd+"="+statusA1+"="+
                                      statusA2+"="+statusA3+"="+beltStat1+"="+beltStat2+"="+beltStat3+"="+beltStat4+"="+request+"=");
  request++;
}

}

You're using the String (upper-case 'S') functions, which allocate and de-allocate memory, a limited commodity, even with 64K. The standard heap management functions will tend to fragment the heap into pieces too small for further use. That can make new allocations slower because the heap has to be searched for a big-enough piece, and can eventually make it the heap grow toward the stack, until a collision (something gets overwritten) inevitable. We can't say for sure that this is your problem; we don't have enough information.
But try allocating one or a few buffers large enough for the worst case requirement, and use the C string functions instead (lower-case 's'), sprintf(), strcpy(), strcat(), etc. instead.

Well, if your program works some time and stops, the first thing you have to check is if there's some variable entering in overflow.
Maybe some variable is concatenating and after some time it goes overflow.
I haven't check your code or the lib, because that is a common problem and already happened with me.


text:
Run python in Windows OS installed in micro SD card which is read by Arduino microcontroller board
I have a python code which runs in my computer with Windows operating system. The code reads some images as input, extends some cognitive services apis from Microsoft azure and finally give an audio output. I would like to run this code on an independent device, for which I am thinking to have a motherboard like Arduino (I can use raspberry pi, but it's a small project and I don't want to invest that much). However being an amateur in this genre, I have some questions and would really like if someone could help.
I want the system to have an independent processing power, with the operating system loaded in a micro SD card. I do not want to connect  Arduino with my pc and run the code from there. It will not make any sense since the PC/laptop is already able to do the work, what would I need Arduino for?
Can someone please tell me if it is possible to have an operating system installed in a micro SD card (bootable) and have it inserted in the Arduino board so that I can run the python code within the SD card?

please delete the first two paragraphs of your question because they are just fluff and they confuse the issue. ... your real question is the last paragraph only .... also remove the reference to windows OS in the title.

With some Arduino boards, yes.  You want a board like the Yun (unfortunately retired now, but there are probably others similar) which has a MIPS SoC on it that runs Linux (specifically OpenWRT).  The OS is installed into the SoC, but there is an SD card slot that will allow you to read your code.
An alternative is a Yun shield (available from third parties, such as the Dragino Yun Shield).  This turns any Uno-like Arduino into a Yun.   Of course, you can run it without any Arduino attached if you so wish to wire it manually.
However, with all these, you're getting into the price bracket of a Raspberry Pi, so you may as well do it properly and just get a Raspberry.


text:
Arduino Uno board with male header pins
I am currently working on a project that would greatly benefit from an arduino uno board with male headers soldered on instead of the female connectors. My question is hence extremely simple, yet I was not able to find an answer myself. Are there uno formfactor boards out there, with male header pins. I have found versions without headers for other boards, but not for the uno. Since I have already designed and 3d printed an enclosure that fits the uno and want to lower the overall height this seems like the easiest way to achieve this.

Several of the cheap Chinese clones that I've bought on eBay have come without soldered headers. Exactly the same form-factor as the Uno. Usual caveats about clone boards apply!

Along with various low-cost boards, the Adafruit Metro 328 is offered without headers soldered.  They consider this board to be a derivative of the Uno R3, but it does use the FT231X which may required different drivers than an Uno's ATMega16u2.  Also the USB connector is different so you may need to adjust your housing slightly.  Kind of ironic that while soldering headers is an extra step even with their selective solder machine, they charge slightly more for the no-headers version, perhaps stocking (or even return?) costs dominate manufacturing ones.

I often unsolder the female connectors to solder wires directly. I would simply unsolder then and solder male headers in their place.


text:
ESP8266 timer to trigger actions (logic issue)
so I have an application in which there are 2 specific times (eg 9AM, 6PM) where a variable curPos is updated. Everything is converted in ms since 00:00 (9AM = 32400000, 6PM = 64800000). Now, the actions (curPos updates) should be triggered every day at these times. To retrieve the current real time (always in ms) I'm sending a http request to a website. This is done only once in the setup().
The idea is that I have to access somehow (http request) the current real time in order to determine when are 9AM and 6PM in my ESP8266, since the start of the sketch. The current real time is needed only once at the beginning (in case there's an issue and the sketch restarts).
Then I can calculate the difference between the current real time and the timers.
The next step would be to translate the values into a 24hour cycle starting at the startup/reset time, so that it can repeat itself without need to request again the real time.
I'm lost in the logic on how to deal with this and with millis() to check when it's time to trigger one of the actions.
This is what I'm doing now with the HTPP GET payload in the setup() (I can successfully retrieve the 3 values in ms from the GET response)
      String payload = http.getString();

      int commaIndex = payload.indexOf(',');
      int secondCommaIndex = payload.indexOf(',', commaIndex + 1); //Search for the next comma just after the first

      mainTime = payload.substring(0, commaIndex).toInt(); //current real time in ms
      timers[0] = payload.substring(commaIndex + 1, secondCommaIndex).toInt(); //9AM in ms
      timers[1] = payload.substring(secondCommaIndex + 1).toInt()); //6PM in ms

      timers[0] = abs(mainTime - timers[0]); //the time difference before reaching the first timer (in ms)
      timers[1] = abs(mainTime - timers[1]); //the time difference before reaching the second timer (in ms)

      // my attempt to turn the time differences into a 24hrs "local" (in the sketch) time
      //dayMs is 24hrs in ms (86400000)
      if(timers[0] < 0)
        timers[0] = dayMs - timers[0];

      if(timers[1] < 0)
        timers[1] = dayMs - timers[1];

and in the loop I'd need a comparison (I think) but I'm just really lost on this
//I think millis need to be reset after 24hrs since the start of the sketch?

if(millis() == timers[0]){
      curPos = 1; //first timer expired then trigger
  }else if(millis() == timers[1]){
      curPos = 7; //second timer expired then trigger
  }

thanks!

you think that you catch the exact millisecond to trigger the event?

it would be better to set time to TimeLib and then test if it is 9AM or 6PM.

Indeed. You can also use NTP to grab the current time off the internet and feed it to TimeLib.

set up a tick variable ... increment it inside the loop() every second or every minute (even every hour ... whatever works for you) .... then simply monitor the value of tick

thanks, so: - I don't think I can catch the exact ms to trigger the event and I'm looking for suggestions on how to do this. - I tried NTP and there were issues with the timezone so the http request is a good substitute. - Ok for the tick variable but I'm still a bit confused on how to turn everything in 24hrs (since the original time). - I will check TimeLib (I assume is a Library?)

For time-keeping on a long-term basis, you are going to run up against clock drift and offsets from tick-tracking. You may be better off using a real-time-clock (RTC) such as the DS1307. This and RTCs like it are often available in breakout boards with a coin-cell battery holder built in.
You would still get the time from your HTTP or NTP source, but the RTC will be much better at keeping the "right" time as you would expect a wristwatch or desk clock to do, versus using the MCU for counting milliseconds.
You can use Ticks or millis() to set up a periodic read of the RTC every second or every 10 seconds, etc. Avoid using the MCU clock for long-term real-world time keeping.

I describe how I do it in my project. I use the Time library a.k.a TimeLib. I set the time I retrieved not by NTP but over modbus from a device which is the source of other data in my project. In your case, you have the http request.
The input to set the time to TimeLib is UNIX epoch. Epoch are seconds from 1970-01-01. If you set only the seconds of the current day, the date would stay 1970-01-01.
And then I have for example this function
boolean restHours() {

  const int BEGIN_HOUR = 9;
  const int END_HOUR = 22;

  int hourNow = hour(now());

  if (hourNow >= BEGIN_HOUR && hourNow < END_HOUR) {
    if (state == RegulatorState::REST) {
      state = RegulatorState::MONITORING;
    }
    return false;
  }
  if (state == RegulatorState::MONITORING) {
    state = RegulatorState::REST;
    clearData();
  }
  return true;
}

now() returns the 'epoch' time. hour(now()) returns the current hour.
or in other function I test if it the should be executed. it enables the execution of the rest of the function only in interval 9:00 to 10:00
void susCalibLoop() {

  const byte SUSCALIB_HOUR = 9;
  static boolean done = false;

  int hourNow = hour(now());

  if (hourNow != SUSCALIB_HOUR) {
    if (done) {
      done = false;
    }
    return;
  }
  if (done)
    return;
...