body:
I recently got an [ESP32-01 Breakout and Development Board][1] from EzSBC.com.  It is advertised as a board specifically designed for use with batteries because of it's low current draw when in sleep.

As a test I loaded the basic Arduino `blink` sketch onto the board using pin 19 as the built in test LED.  When I power the board from the computer through the USB connection the LED blinks as expected, but when I connect a battery accross VIN -> GND nothing happens.

What am I doing wrong?

  [1]: https://www.ezsbc.com/index.php/featured-products-list-home-page/wifi01-35.html

title: Why doesn't pin 19 work when powering the EzSBC Esp32 board from batteries?

Answers: 1

body:
There is a subtle design choice in this board that took be hours to figure out.

According the [connection schematic][1] the blue leg of the LS3528RGB LED is connected to `IO19` through a 1k resister (`R2-1`).  However the power leg is connected to `Vusb` *not* `3.3V` like the other RGB LED.  This means that the LED connected to IO19 is only usable when the board is connected through the micro-USB port and not when connected directly to battery.

This can be useful for programmatically reading whether the board is running on battery or USB.

  [1]: http://www.ezsbc.com/index.php/productattachments/index/download?id=30


body:
I was reading the article about tensorflow lite on SAMD51 [here][1] and tried it and failed to compile.

It was the example from the arduino tensorflow lite lirabry and doesnt seem to compile.

Selected Adafruit M4 boards and failed to compile, but can compile with ArduinoMKRZERO(SAMD21).

Here follows the error message:

    Arduino: 1.8.12 (Mac OS X), Board: "Adafruit Grand Central M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 50 MHz (standard), Arduino, Off"

        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                         from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:58:5: error: unknown type name 'int16_t'
             kiss_fft_scalar r;
             ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:59:5: error: unknown type name 'int16_t'
             kiss_fft_scalar i;
             ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly2':
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: note: each undeclared identifier is reported only once for each function it appears in
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
         # define SAMPPROD int32_t
                           ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                       ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
         #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                        ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:33:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                         from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly4':
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:61:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
         # define SAMPPROD int32_t
                           ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                       ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
         #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                        ^
        Multiple libraries were found for "Adafruit_ZeroDMA.h"
         Used: /Users/ansonhe/Library/Arduino15/packages/adafruit/hardware/samd/1.5.4/libraries/Adafruit_ZeroDMA
         Not used: /Users/ansonhe/Documents/Arduino/libraries/Adafruit_Zero_DMA_Library
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:61:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                         from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly3':
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:109:10: note: in expansion of macro 'C_FIXDIV'
                  C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
                  ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
         # define SAMPPROD int32_t
                           ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                       ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
         #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                        ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:109:10: note: in expansion of macro 'C_FIXDIV'
                  C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3);
                  ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                         from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly5':
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:160:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
         # define SAMPPROD int32_t
                           ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                       ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
         #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                        ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:160:9: note: in expansion of macro 'C_FIXDIV'
                 C_FIXDIV( *Fout0,5); C_FIXDIV( *Fout1,5); C_FIXDIV( *Fout2,5); C_FIXDIV( *Fout3,5); C_FIXDIV( *Fout4,5);
                 ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:19:0,
                         from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c: In function 'kf_bfly_generic':
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/kiss_fft.h:48:27: error: 'int16_t' undeclared (first use in this function)
         #  define kiss_fft_scalar int16_t
                                   ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:26: note: in expansion of macro 'kiss_fft_scalar'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:8: note: in expansion of macro 'sround'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:217:13: note: in expansion of macro 'C_FIXDIV'
                     C_FIXDIV(scratch[q1],p);
                     ^
        In file included from /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:16:0:
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:51:19: error: 'int32_t' undeclared (first use in this function)
         # define SAMPPROD int32_t
                           ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:65:47: note: in definition of macro 'sround'
         #   define sround( x )  (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS )
                                                       ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:64:25: note: in expansion of macro 'SAMPPROD'
         #   define smul(a,b) ( (SAMPPROD)(a)*(b) )
                                 ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:74:16: note: in expansion of macro 'smul'
          (x) = sround( smul(  x, SAMP_MAX/k ) )
                        ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/third_party/kissfft/_kiss_fft_guts.h:77:10: note: in expansion of macro 'DIVSCALAR'
          do {    DIVSCALAR( (c).r , div);  \
                  ^
        /Users/ansonhe/Documents/Arduino/libraries/Arduino_TensorFlowLite/src/tensorflow/lite/experimental/micro/tools/make/downloads/kissfft/kiss_fft.c:217:13: note: in expansion of macro 'C_FIXDIV'
                     C_FIXDIV(scratch[q1],p);
                     ^
        exit status 1
        Error compiling for board Adafruit Grand Central M4 (SAMD51).

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

Please let me know if anyone has any ideas, much appreciated.

  [1]: https://blog.adafruit.com/2019/06/24/tiny-machine-learning-on-the-edge-with-tensorflow-lite-running-on-samd51-arduino-tensorflow-tinyml-tensorflow/

title: Compile error with Arduino tensorflow lite library

Answers: 0


body:
Good day everyone! what code should i used for sending sms message depends on the area. the things that i used in my protoype i have MPU6050 accelometer, SIM800C GSM MODULE, NEO6MV2 GPS MODULE. So the flow is if the Accelometer triggred the GSM module will get the GPS location only if the area is on the target location 1 so it will only send to the recepient 1. But if its triggred in another location, Targetlocation2 it will only send on receipient 2.
My question is how to used the longitude and latitude data to get the exact data of what my gps module gets? so that i can use that data to send sms message on specific place or area thank a lot
also i used TINYGPS.H LIBRARY thank you!

title: How to send sms message on specific area using Longitude and Latitude

Answers: 0


body:
I want to read a 4-20 mA analog signal from a 24V flowmeter. I've read the simplest way is to convert it into 1-5V signal using a 250 ohm resistor. The thing is I want my reading to be precise so my question is; is there any resolution loss when converting it to 1-5V?

I've also looked up on current to voltage converting boards similar to this one: https://www.sparkfun.com/products/14544

but I don't think they can detect 4mA signal.

I am a beginner in this so need some guidance here.

title: Reading 4-20ma signal on arduino

Answers: 1

body:
Using a resistor is the "Normal" way, yes. 250Ω will give you 1-5V, yes, which means that you get 4/5 of the actual resolution of the ADC at your disposal.

That means instead of 0-1023 you're actually reading 204-1023, or 819 possible values. Spread over 16ma (or 4V, which are the same thing) that gives you about 20µA resolution.

If you really really care about that extra 1/5 of the resolution you can instead use a 300Ω resistor to give you 1.2 to 6V, then pass that through a subtracting amplifier (see [this post](https://electronics.stackexchange.com/a/18265/4245)) and subtract 1.1V from it (you need to create that 1.1V, of course).  That will give you 0.1 to 4.9V, which then covers more of the ADC's available range (20-1002, or about 16µA resolution).

Is it worth it? Probably not. Any increase in resolution will likely be swamped by the inaccuracy of the resistor and potential drift though self heating.


body:
I'm making an IR Macro keyboard, and about 10% of the code is dedicated to the `Keyboard` commands, would having `Keyboard.begin()` and `Keyboard.end()` in the method responsible for typing make any difference to the speed or size?
My code:

    void decodeCode(){ // send the macros.
      int pos = 0;
      for(int i = 0; i<output.length(); i++){
        if(output.charAt(i) == '$' && i!=output.length()-1){ //the $ is a symbol for "$pecial" characters
          i++;
          specialDecodeChar(output.charAt(i));
        }
        else if(output.charAt(i) == '%'){
          Keyboard.releaseAll();
        }
        else{
          Keyboard.press(output.charAt(i));
        }
      }
      Keyboard.releaseAll();
    }

I currently have `Keyboard.begin()` in `setup()`.

title: Does Keyboard.begin() and Keyboard.end() make my code slower?

Answers: 1

body:
The `Keyboard::begin()` and `Keyboard::end()` functions,  if you actually [look at the code](https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.cpp#L69-L75) are empty functions. They do nothing.

In theory the compiler should just optimise them out.


body:
any reference site for the format code for tinygps.h to measure distance?
or any codes for tinygps.h for measuring distance i'm just a beginner in learning arduino thank you

title: How to use tinygps.h library to measure distance? using NEO6mv2

Answers: 1

body:
You don't use the `tinygps.h` library to measure distance. You use the `tinygps.h` library to get coordinates. Over short distances those coordinates (longitude and latitude) can be equated to x,y coordinates on a plane (over greater distance - hundreds or thousands of miles - it gets a whole lot more complex).

Two sets of x,y coordinates form a line. A line is one side of a right-angled triangle (the hypotenuse).

Pythagoras (remember him from math class? That rubbish you thought you'd never need? Well, now you do...) says that the square of the hypotenuse is equal to the sum of the squares of the other two sides.

You know the other two sides - they're just the difference between the two x coordinates and the two y coordinates.

We're not going to write the code for you, and Google is probably better at finding websites with example code on than we are.


body: I am working on installing an alarm system using Konnected IO on a NodeMCU esp8266. I have multiple bay widows which will use 4 SW-420 vibration sensors. I would like to wire all 4 of the SW-420 vibration sensors to a single pin. When any of the 4 sensors detect vibration the pin will go to high. I attempted to simply wire the d-outs from all four together and all four sensors stoped working. I'm out of ideas on how to do this any help would be greatly appreciated. I believe sensors send out a low signal when no vibration is detected and high signal when vibration is detected. Link to sensors: https://www.amazon.com/XLX-Vibration-Normally-Sensitive-High-Efficient/dp/B07V8FJRN1/

title: Wire multiple SW-420 Vibration sensors to a single pin

Answers: 1

body:
Two ideas came to my mind, first is to connect each output to four digital pins and then do something like this:

    if(digitalRead(pinOne) == HIGH || digitalRead(pinTwo) == HIGH || ...){
    do something
    }

Or you can use an opamp or comparator for that purpose:

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

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

<!-- End schematic -->

 In above configuration if any of the sensors output is HIGH, op amp will drag it's output to the positive rail (~5V). otherwise output is LOW (~0 V).


body:
Hi I am new to IOT and I am now in love with this. However I'm a little confused right now with the jargon. My question is similar to [this][1]. But I do have some extra questions though.

1. When using ESP as standalone microcontroller, and if I uploaded a sketch written on the Arduino IDE, does that count as 'Arduino firmware' other people are referring to?

2. On the Arduino IDE, uploading sketches onto the ESP8266 seems easy by just installing extra libraries from Board Manager and selecting the right board. Is this step equivalent of doing [this][2] but for different firmwares such as AT, NodeMCU and Micropython?

3. For the NodeMCU dev boards, is the default firmware on the module [NodeMCU firmware][3]? If I were to use the Arduino IDE to upload a sketch, does that mean I have overwritten the NodeMCU firmware with my custom 'Arduino firmware' sketch?

4. To the extent of my knowledge, when using NodeMCU firmware, I would need to code in LUA language using some sort of LUA IDE and if I flashed/uploaded micropython I would need to code in micropython using exclusively the [Thonny IDE][4]. And there is no way to code in micropy or LUA from the Arduino IDE.

5. Is the reason for using other firmware is because of how the code is compiled and the language used?

If someone could clear things up for me I would greatly appreciate it. Thanks!

  [1]: https://arduino.stackexchange.com/questions/43446/when-uploading-a-sketch-to-an-esp8266-isnt-that-the-same-as-flashing-firmware
  [2]: https://www.instructables.com/id/Flash-or-Upgrade-Firmware-on-ESP8266-ESP-01-Module/
  [3]: https://github.com/nodemcu/nodemcu-firmware
  [4]: https://thonny.org/

title: Does flashing ESP8266/ESP-01 firmware mean uploading a new 'sketch' and why different firmware?

Answers: 1

body:
> When using ESP as standalone microcontroller, and if I uploaded a sketch written on the Arduino IDE, does that count as 'Arduino firmware' other people are referring to?

Yes. "Firmware" is application code running on the microcontroller.

> On the Arduino IDE, uploading sketches onto the ESP8266 seems easy by just installing extra libraries from Board Manager and selecting the right board. Is this step equivalent of doing this but for different firmwares such as AT, NodeMCU and Micropython?

Yes. "Firmware" is application code running on the microcontroller.

> For the NodeMCU dev boards, is the default firmware on the module NodeMCU firmware? If I were to use the Arduino IDE to upload a sketch, does that mean I have overwritten the NodeMCU firmware with my custom 'Arduino firmware' sketch?

Yes. "Firmware" is application code running on the microcontroller.

> To the extent of my knowledge, when using NodeMCU firmware, I would need to code in LUA language using some sort of LUA IDE and if I flashed/uploaded micropython I would need to code in micropython using exclusively the Thonny IDE. And there is no way to code in micropy or LUA from the Arduino IDE.

No. The Arduino IDE is for coding in C++ with the Arduino API extensions.

> Is the reason for using other firmware is because of how the code is compiled and the language used?

The firmware is just what runs on the chip. If that firmware provides its own programming language then you can use that to execute that programming language.

If you write your own firmware in the Arduino IDE then the chip runs that firmware. If you upload the AT firmware then the chip runs the AT firmware and you can control it with AT commands. If you upload the NodeMCU Lua firmware then the chip runs the NodeMCU Lua firmware and you control it using Lua commands and scripts.


body:
On [A post from Arduino forum][1] , someone mentioned that a pull up resistor over RX/TX pin could help the reliably of UART communication.

Is that really the case for nano and uno board?

  [1]: https://forum.arduino.cc/index.php?topic=282291.0

title: Will a pull up resistor help the UART transmission accuracy on Arduino nano?

Answers: 1

body:
No. That is not the case. Adding a pullup resistor on a normal UART will do nothing except maybe reduce your reliability.

You only want pullup resistors on something which is "open drain" (AKA "open collector") which has no way of raising the voltage of a signal line, only lowering it - such as I2C signals, or a shared open-drain, interrupt signal.


body:
I have several devices on the I2C bus:

 1. RTC [DS3231SN][1]
 2. [TMP100][2] temperature sensor
 3. EEPROM [24LC256][3]

All devices are powered by 3.3V. The voltage on the I2C bus is 5V.

**Question:**
Is the voltage difference on the bus and device power normal?

  [1]: https://eu.mouser.com/datasheet/2/256/DS3231-1513891.pdf
  [2]: https://www.ti.com/lit/ds/symlink/tmp100.pdf
  [3]: http://ww1.microchip.com/downloads/en/DeviceDoc/21203N.pdf

title: Is it permissible to connect 3.3V powered devices to the 5V I2C bus?

Answers: 1

body: There are 3.3V devices that have 5V-tolerant inputs; that may be the case for your devices, but I would not risk it. Use a level converter designed for I2C, such as https://www.adafruit.com/product/757. Or you can make your own; https://cdn-shop.adafruit.com/datasheets/an97055.pdf explains how such a level converter works. Use a BSS138 if you are comfortable with soldering SMT components; otherwise use a 2N7000.


body:
I am using Arduino Mega 2560

I have built an structure with plastic 3D pieces to move this water tap.:

![water_tap](https://i.stack.imgur.com/HRnLpm.png)

I am using the ["Servomotor Parallax Inc 140 mA, 4 6 V"](https://es.rs-online.com/web/p/servomotores/7813058/) to rotate the tap:

![servomotor](https://i.stack.imgur.com/10NJcm.png)

Some more images to show how I mounted it:

![mounted](https://i.stack.imgur.com/cT9mf.jpg)
![piece_for_thetap](https://i.stack.imgur.com/WNLZ8.jpg)
![another_piece](https://i.stack.imgur.com/qBehg.jpg)

[Video 1](https://youtu.be/vkz76wxOnTA). I tried to use the power of the arduino directly (5V). But the motor is not steady in all the positions I set, in some positions the noise you hear in the video do not stop, and my impression is that the motor will burn soon because it keeps pusshing all the time.

[Video 2](https://youtu.be/Szx_OhX2ELU). Without almost any load, the motor is also making a small sound. I don't know if you can appreciate it in the video. They are like cracks or clicks

Possible solutions:

* Is there a way to cut the power supply when the motor already moved the tap? Or just to stop the motor to keep pushing?
* Using a external power should solve the problem? I found [this tutorial](https://www.instructables.com/id/Arduino-How-to-Use-a-Servo-Motor-With-an-External-/) where they use that system. Which will be the benefits of that? It will fix the problem?
* Using another stronger servomotor?
* A [stepper motor](https://www.adafruit.com/product/324)?
* Is my servomotor faulty?
* Would I need some controller?

Any other suggestion?

title: How can I make a Parallax Servomotor move a water tap correctly and prevent from vibrations?

Answers: 1

body:
When you set a servo motor to be in a specific position it is constantly and actively striving to keep in that position. The feedback from the internal potentiometer is constantly being processed and the motor adjusted to ensure that it remains at the right position.  Potentiometers, of course, aren't 100% perfect, and there will always be a certain amount of "noise" in the signal that means the motor will always be making really tiny adjustments.

That's perfectly normal.

The simple way to stop it trying to keep precisely to one position is to stop telling it to be in that position.

1. `.attach()` the motor
2. Move it to the desired position
3. Wait long enough for the motor to get to that position
4. `.detach()` the motor

When you call `servo.detach()` the PWM signal is terminated and the motor no longer has a position to keep to - so it just stops doing anything and goes to sleep.

The down-side of this is that if you have a load under tension (for example if you are lifting a weight with the servo) the tension is then free to move the motor.


body:
I have ESP8266 which is connecting to MQTT broker and it is working ok using user+pass with following code:

    #include <ESP8266WiFi.h>
    #include <PubSubClient.h>

    const char* ssid = "WIFINAME";
    const char* password = "WIFI_PASS";

    const char* mqtt_server = "SERVER_IP";
    const char* mqttUser = "user";
    const char* mqttPassword = "pass";

    WiFiClient espClient;
    PubSubClient client(espClient);
    unsigned long lastMsg = 0;
    #define MSG_BUFFER_SIZE (50)
    char msg[MSG_BUFFER_SIZE];
    int value = 0;

    void setup_wifi() {

      delay(10);
      // We start by connecting to a WiFi network
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);

      WiFi.begin(ssid, password);

      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }

      randomSeed(micros());

      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }

    void callback(char* topic, byte* payload, unsigned int length) {
      Serial.print("Message arrived [");
      Serial.print(topic);
      Serial.print("] ");
      for (int i = 0; i < length; i++) {
        Serial.print((char)payload[i]);
      }
      Serial.println();

      // Switch on the LED if an 1 was received as first character
      if ((char)payload[0] == '1') {
        digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
        // but actually the LED is on; this is because
        // it is active low on the ESP-01)
      } else {
        digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
      }
    }

    void reconnect() {
      // Loop until we're reconnected
      while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        // Create a random client ID
        String clientId = "ESP8266Client-";
        clientId += String(random(0xffff), HEX);
        if (client.connect(clientId.c_str(), mqttUser, mqttPassword)) {
          Serial.println("connected");
          client.subscribe("CoreElectronics/test");
        } else {
          Serial.print("failed, rc=");
          Serial.print(client.state());
          Serial.println(" try again in 5 seconds");
          // Wait 5 seconds before retrying
          delay(5000);
        }
      }
    }

    void setup() {
      pinMode(BUILTIN_LED, OUTPUT);
      Serial.begin(115200);
      setup_wifi();
      client.setServer(mqtt_server, 1883);
      client.setCallback(callback);
    }

    void loop() {

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

As this is insecure usage I have setup TLS on MQTT broker and I can connect over command line:

    mosquitto_sub --cafile ca.crt -h server_ip  -t "#" -p 8883 -d --cert client.crt --key client.key

Problem is that I cannot find any working (for me) sample with using TLS connection on ESP8266 client.

I have tried generating self-signed certs by manually script and over LetsEncrypt.

Thank you

title: How to connect to MQTT broker with TLS?

Answers: 2

body:
You could make the following changes to your code by making use of WifiClientSecure (which is already part of the ESP8266 Wifi library).

The tricky part is finding out the SHA1 fingerprint for your own MQTT server and hard coding it into the __*fingerprint PROGMEM = "..."__  part (for example by examining the certificate via a PC browser and copying the SHA1 fingerprint).

Alternatively, you could set the connection to setInsecure. This means that the connection will be encrypted but it will accept any server certificate without checking.

    ...
    const char* mqttPassword = "pass";

    WiFiClientSecure espClient;     // <-- Change #1: Secure connection to MQTT Server
    PubSubClient client(espClient);

    // Change #2: Set the SHA1 fingerprint for the connection -->
    static const char *fingerprint PROGMEM = "44 14 9A 3F C3 E9 F1 F3 84 1A B4 9F B6 4D 19 8A B2 92 31 D6";
    ...
    ...
    void setup() {
        ...
        setup_wifi();

        espClient.setFingerprint(fingerprint);   // <-- Change #3: Set the SHA1 fingerprint
        // Alternative: espClient.setInsecure;

        client.setServer(mqtt_server, 8883);  // <-- Change #4: Set the port number to 8883
        client.setCallback(callback);
     ...

Good luck!

body:
There is an example of client certificates here.

https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino

I believe the answer by @StarCat should be expanded to use the ca cert and client certs.  With MQTT, we don't want clients being faked either.


body:
I'm rather new to Arduino. I've been performing some current consumption measurements lately, with a INA219 current sensor, on the blue LEDs from a starter kit.

I plugged three LEDs, on pins 2, 3, and 4 of my Arduino UNO, and wrote a simple script:

    digitalWrite(led1, 1);
    delay(2000);
 digitalWrite(led2, 1);
    delay(2000);
    digitalWrite(led3, 1);
    delay(2000);
 digitalWrite(led1, 0);
    digitalWrite(led2, 0);
    digitalWrite(led3, 0);

Which turns on the leds one by one, and finally turn them off at once.
I measured the current consumption of the first LED, and measured that:

 - When it's the only one on, LED 1 consumes ~23.5 mA
 - When the second one is on, LED 1 consumes ~21.7 mA
 - When the third one is on, LED 1 consumes ~20.2 mA

Could you please tell me why it behaves that way ? Is there any source I should read that would formalize that ?

Thank you

title: Why does per-led current consumption diminishes when more leds are on?

Answers: 1

body:
If using a constant voltage source it is advisable to use current limiting resistors in series with LEDs.

If these LEDs are different colors that may explain the different current readings.

Or, if all LEDs are of the same color and you are powering the project from a source with internal resistance (a battery), the more current you draw the lower the supply voltage.  This may show up as a reduced incremental current increase.

Or, if using a poor power source or operating at the current capacity of the power supply - again - this may show up as a reduced incremental current increase.

Note that different generations of LEDs operate at slightly different voltages.  But, in general, RED, GREEN & BLUE LEDs of the same generation operate at slightly increasing voltages respectively.  Details can be found here in [this wikipedia.com page][1]:

> Typically, the forward voltage of an LED is between 1.8 and 3.3 volts.
> It varies by the color of the LED. A red LED typically drops 1.8
> volts, but since both voltage drop and light frequency increase with
> band gap, a blue LED may drop from 3 to 3.3 volts.

Use the LED current (Iled) and voltage (Vled) specifications to determine the proper resistor value for a given supply voltage (Vbatt).

The following equation from [this article][2] should prove useful for this calculation:

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

  [1]: https://en.wikipedia.org/wiki/LED_circuit
  [2]: https://www.nutsvolts.com/magazine/article/calculating_current
  [3]: https://i.stack.imgur.com/NPEJk.png


body:
I am new to arduino.I try to read temperature using DS18B20 temperature sensor.I connected the pins as bellow.But,When I connected 1-pin to ground and 3-pin to +5V the sensor heated and all the little lights on the UNO board turned off and it stopped working.

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

When I connected 3-pin to ground and 1-pin to +5V the board worked normally.But,I gives -127 as the temperature when I uploaded the bellow code.

    #include <OneWire.h>
    #include <DallasTemperature.h>
    // Data wire is connected to the Arduino digital pin 2
    #define ONE_WIRE_BUS 2
    // Setup a oneWire instance to communicate with any OneWire devices
    OneWire oneWire(ONE_WIRE_BUS);
    // Pass our oneWire reference to Dallas Temperature sensor
    DallasTemperature sensors(&oneWire);

    void setup(void)
    {
    // Start serial communication for debugging purposes
    Serial.begin(9600);
    // Start up the library
    sensors.begin();
    }
    void loop(void){
    // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
    sensors.requestTemperatures();
    Serial.print("Celsius temperature: ");
    // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
    Serial.print(sensors.getTempCByIndex(0));
    Serial.print(" - Fahrenheit temperature: ");
    Serial.println(sensors.getTempFByIndex(0));
    delay(1000);
    }

I connected with both Normal mode and Parasite mode.But, same results..

I use this:
[![enter image description here][2]][2]

Help me to solve the problem.
Thank you!

  [1]: https://i.stack.imgur.com/BtYt6.jpg
  [2]: https://i.stack.imgur.com/U2Pk7.jpg

title: DS18B20 temperature sensor not working

Answers: 0


body:
I find difficulties to measure correctly the voltage at the AREF pin.
I would measure voltages with a resolution not exceeding 1 mV . nda voltage divider
In one of my trials, I was using a  9V battery and a voltage divider made with a 1k resistor and a 2k one.

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

The battery voltage was about 8890 mV and the reference voltage was about 2960 mV (confirmed by a multimeter).
I  connected the output of the divider to the AREF pin of an Arduino Uno board. The output voltage value dropped to about 1800 mV. Reading the voltage value at AREF pin with a simple sketch:.

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

the serial monitor printed:

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

as if the voltage dividere did not exist.
What am I doing wrong? or what I don’t understand?
Thank you for your attention.

  [1]: https://i.stack.imgur.com/3bvsr.jpg
  [2]: https://i.stack.imgur.com/ybUtu.jpg
  [3]: https://i.stack.imgur.com/zwQ2C.jpg

title: Voltage at AREF pin

Answers: 1

body:
> I was using a 9V battery and a voltage divider made with a 1k resistor and a 2k one.

Using a battery is not a good way of getting a stable voltage. A battery's voltage will change over time.

Using a voltage divider is not a good way of generating a reliable stable voltage. The output impedance is very high and will be affected by any loading you apply to it causing it to droop.

If you want 1mV per LSB then you need a 1024mV voltage reference (since there are 10 bits of resolution, or 1024 possible divisions, in the ADC). For that you want a 1024mV voltage reference, which is a standard value for precision voltage reference chips such as the LM4140CCM-1.0/NOPB from Texas Instruments. Personally I like to use a precision DAC like the MCP4821 to provide a settable analog reference voltage.

> Reading the voltage value at AREF pin with a simple sketch the serial monitor printed 8890 as if the voltage dividere did not exist. What am I doing wrong?

You cannot read anything from the AREF pin. It is merely a voltage reference, not an active pin you can read. When you use `analogRead(EXTERNAL)` you are actually doing `analogRead(0)` since `EXTERNAL` is a macro that expands to `0`. That means you are really reading from pin A0 not the AREF pin.  And then you just map that to 8890 when it's at maximum anyway. Since A0 is (probably, since you don't show anything else in your circuit) floating it will most likely be above the voltage you are feeding in to AREF and will return 1023 all the time anyway.


body: Tried to install Arduino IDE on Juno, install script gave warnings about icons not being installed on desktop (which is fine since no desktop folder for eOS) but then when try to launch the IDE icon from Applications it doesn't go. I'm guessing it's a java app? I don't want to run java on eOS unless it's already there. Any insight to running this IDE on Juno would be welcome.

title: Arduino IDE on eOS? Java?

Answers: 0


body:
I would like to flash my Arduino Due from my Synology DS218+ NAS which runs on an Intel 64bit Linux-derivate platform. Previously, I was able to flash a Mega 2560 from this NAS via avrdude and currently, I am able to flash an Arduino Due via bossac through the Due's programming port. The port is registered as /dev/ttyACM0 (as was the Mega 2560) after I installed the necessary usbserial kernel module.
However, the native port is not detected likewise, or rather it is deregistered immediately:

```
[8336388.471865] usb 1-2: new high-speed USB device number 27 using xhci_hcd
[8336388.613119] Got empty serial number. Generate serial number from product.
[8336388.685041] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[8336389.331596] usbcore: deregistering interface driver cdc_acm
```

The programming port shows up like this:
```
[8338189.956730] usb 1-2: new full-speed USB device number 29 using xhci_hcd
[8338190.100022] usb 1-2: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[8338190.615513] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[8338190.621705] usbcore: registered new interface driver cdc_acm
[8338190.628534] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
```

Is there anything I need to install in addition to the usbserial kernel modules to get the native port working?

P.S.: I know that the programming port is more stable, but it is also rather slow with its 115200 bps. Uploading a sketch that just takes up 50% of the Due's flash memory takes almost a minute, and if you want to see the effects of code changes, this is quite time consuming.

title: How to access native USB port of Arduino Due on Synology NAS?

Answers: 0


body:
So the previous two questions could be found here:
https://arduino.stackexchange.com/questions/72665/esp8266-computtion-error and https://arduino.stackexchange.com/questions/72642/esp8266-not-working-with-mpu-6050-over-wire-library-and-i2c

However, it was not resolved, and with updates and debugs, I'm going to delete them later and summarize in this single post.

**Issue:**

An ESP8266  CP2102 ESP-12E was trying to access MPU 6050. However, it's not working.

**Attempts:**

1. You can see the diagram picture. I tried pairs of pull up resistor from 0 to 100 k(the one used in the picture was standard 4.7 k).

2. Many MPU 6050s have been attempted and tested. They were working, and you can see in the picture, the green light lighted up.

3. Different ESP 8266 -12E from two different brands have been attempted, both have the same issue.

4. Various of version of board manager has also been attempted.

5. Different wires have been attempted. The I2C bus in the graph are twisted wires.

6. The adjustment of the program has also been attempted. Eventually, an [online version of code][1]  was attempted, and not working.

7. The power supply was ruled out through the usage of power board, capacitors, and external power sources. The issue persisted.

8. Wire library pins, frequencies, have been checked as correct. As well as constant restart of IDE and hardware.

9. Different bread boards and have also been attempted, the issue persisted.

The above attempts all resulted failure. Could you help me to figure out why ESP 8266 does not work with MPU 6050 over I2C?

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

  [1]: https://www.electronicwings.com/nodemcu/mpu6050-interfacing-with-nodemcu
  [2]: https://i.stack.imgur.com/o7pce.jpg

title: ESP8266 NodeMCU CP2102 ESP-12E I2C with MPU 6050 Error

Answers: 0


body:
I am trying to send AT commands to SIM800L through Arduino's Serial Monitor. However when I type any command in the serial monitor nothing happens. I'm using an Arduino MEGA 2560 and the TX/RX of the SIM800L is connected to 9 and 10 respectively. Here is the code:

```
#include <SoftwareSerial.h>

SoftwareSerial GPRS(9, 10);
boolean state, lastState;

void setup()
{
  pinMode(2, INPUT_PULLUP);
  state = digitalRead(2);
  lastState = state;

  GPRS.begin(9600);
  Serial.begin(9600);

  GPRS.println("AT+CMGF=1");

  delay(1000);
}

void loop()
{
  while(GPRS.available()) {
    Serial.write(GPRS.read());
  }

  lastState = state;
  state = digitalRead(2);

  if ( state != lastState ) {
    sendSMS();
  }

  delay(500);
}

void sendSMS() {
  Serial.print("Switch was turned ");
  Serial.println(state ? "on" : "off");

  GPRS.println("AT+CMGS=\"+64XXXXXXXXX\"");

  delay(500);

  GPRS.print("Switch was turned ");
  GPRS.println(state ? "on" : "off");
  GPRS.write( 0x1a ); // ctrl+Z character

  delay(500);
}
```
Any help would be much appreciated!

EDIT2: I forgot to mention but I am able to send, receive, and call from the GSM Module (with a different code). However I am not able to read the the received messages, since I only get a +CMT "SM", <index> message and I can't exactly use AT+CMGR or CMGL commands because the serial monitor does nothing with them. here's the code for that:
```
#include <SoftwareSerial.h>
SoftwareSerial sim(9,10);
int _timeout;
String _buffer;
String number = "+639XXXXXXXXX"; //-> change with your number
void setup() {
  delay(1000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Lets go!");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}
void loop() {
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
}
void SendMessage()
{
  Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Wala kang jowa!";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}
void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}
String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}
void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}
```

title: SIM800L - AT Commands not doing anything on Arduino Serial Monitor

Answers: 2

body:
Do not use `SoftwareSerial` on a Mega2560 unless you *absolutely know what you are doing*.

SoftwareSerial does not work on many of the pins of the Mega2560, and since there are other *hardware* serial ports available there is seldom any reason to resort to using SoftwareSerial anyway.

Connect your SIM800L to the TX1/RX1 pins of the Mega2560 then communicate using the pre-defined `Serial1` object.

body:
 1. Make sure the RX of your arduino board is connected to TX of GSM and the TX should be connected in RX of GSM module.
 2. Next try to do this

```
   GPRS.begin(9600);
   Serial.begin(115200);
```
 3. Also double check your wirings, if you have a tester you might wanna check if both end are connected with each other. And in the loop try to print this `Serial.println(GPRS.available())` if it is not greater than 0 then you have a problem with your connection.

```
    #include <SoftwareSerial.h>
    SoftwareSerial sim(2,3);

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      sim.begin(9600);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      while(Serial.available() > 0){
        sim.write(Serial.read());
      }

      while(sim.available() > 0){
        Serial.write(sim.read());
      }
    }
```
> diagram reference. [![enter image description here][1]][1]

Hope this help.

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


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

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

(https://circuitdigest.com/microcontroller-projects/arduino-based-accident-alert-system-using-gps-gsm-accelerometer)

the code is

    Serial.println(zValue);
    ..... .....
    ........ ...
Here we have also created some other function for various purposes like `void gpsEvent()` to get GPS coordinates, `void coordinate2dec()` for extracting coordinates from the GPS string and convert them into Decimal values, `void show_coordinate()` for displaying values over serial monitor and LCD, and finally the `void Send()` for sending alert SMS to the predefined number.

Complete code and demo video is given below, you can check all the functions in the code.

Code

    #include<SoftwareSerial.h>
    SoftwareSerial Serial1(2,3); //make RX arduino line is pin 2, make TX arduino line is pin 3.
    SoftwareSerial gps(10,11);
    #include<LiquidCrystal.h>
    LiquidCrystal lcd(4,5,6,7,8,9);

    #define x A1
    #define y A2
    #define z A3

    int xsample=0;
    int ysample=0;
    int zsample=0;

    #define samples 10

    #define minVal -50
    #define MaxVal 50

    int i=0,k=0;
    int  gps_status=0;
    float latitude=0;
    float logitude=0;
    String Speed="";
    String gpsString="";
    char *test="$GPRMC";

    void initModule(String cmd, char *res, int t)
    {
      while(1)
      {
        Serial.println(cmd);
        Serial1.println(cmd);
        delay(100);
        while(Serial1.available()>0)
        {
           if(Serial1.find(res))
           {
            Serial.println(res);
            delay(t);
            return;
           }

           else
           {
            Serial.println("Error");
           }
        }
        delay(t);
      }
    }

    void setup()
    {
      Serial1.begin(9600);
      Serial.begin(9600);
      lcd.begin(16,2);
      lcd.print("Accident Alert  ");
      lcd.setCursor(0,1);
      lcd.print("     System     ");
      delay(2000);
      lcd.clear();
      lcd.print("Initializing");
      lcd.setCursor(0,1);
      lcd.print("Please Wait...");
      delay(1000);

      Serial.println("Initializing....");
      initModule("AT","OK",1000);
      initModule("ATE1","OK",1000);
      initModule("AT+CPIN?","READY",1000);
      initModule("AT+CMGF=1","OK",1000);
      initModule("AT+CNMI=2,2,0,0,0","OK",1000);
      Serial.println("Initialized Successfully");
      lcd.clear();
      lcd.print("Initialized");
      lcd.setCursor(0,1);
      lcd.print("Successfully");
      delay(2000);
      lcd.clear();
      lcd.print("Callibrating ");
      lcd.setCursor(0,1);
      lcd.print("Acceleromiter");
      for(int i=0;i<samples;i++)
      {
        xsample+=analogRead(x);
        ysample+=analogRead(y);
        zsample+=analogRead(z);
      }

      xsample/=samples;
      ysample/=samples;
      zsample/=samples;

      Serial.println(xsample);
      Serial.println(ysample);
      Serial.println(zsample);
      delay(1000);

      lcd.clear();
      lcd.print("Waiting For GPS");
      lcd.setCursor(0,1);
      lcd.print("     Signal    ");
      delay(2000);
      gps.begin(9600);
      get_gps();
      show_coordinate();
      delay(2000);
      lcd.clear();
      lcd.print("GPS is Ready");
      delay(1000);
      lcd.clear();
      lcd.print("System Ready");
      Serial.println("System Ready..");
    }

    void loop()
    {
        int value1=analogRead(x);
        int value2=analogRead(y);
        int value3=analogRead(z);

        int xValue=xsample-value1;
        int yValue=ysample-value2;
        int zValue=zsample-value3;

        Serial.print("x=");
        Serial.println(xValue);
        Serial.print("y=");
        Serial.println(yValue);
        Serial.print("z=");
        Serial.println(zValue);

        if(xValue < minVal || xValue > MaxVal  || yValue < minVal || yValue > MaxVal  || zValue < minVal || zValue > MaxVal)
        {
          get_gps();
          show_coordinate();
          lcd.clear();
          lcd.print("Sending SMS ");
          Serial.println("Sending SMS");
          Send();
          Serial.println("SMS Sent");
          delay(2000);
          lcd.clear();
          lcd.print("System Ready");
        }
    }

    void gpsEvent()
    {
      gpsString="";
      while(1)
      {
       while (gps.available()>0)            //Serial incoming data from GPS
       {
        char inChar = (char)gps.read();
         gpsString+= inChar;                    //store incoming data from GPS to temparary string str[]
         i++;
        // Serial.print(inChar);
         if (i < 7)
         {
          if(gpsString[i-1] != test[i-1])         //check for right string
          {
            i=0;
            gpsString="";
          }
         }
        if(inChar=='\r')
        {
         if(i>60)
         {
           gps_status=1;
           break;
         }
         else
         {
           i=0;
         }
        }
      }
       if(gps_status)
        break;
      }
    }

    void get_gps()
    {
      lcd.clear();
      lcd.print("Getting GPS Data");
      lcd.setCursor(0,1);
      lcd.print("Please Wait.....");
       gps_status=0;
       int x=0;
       while(gps_status==0)
       {
        gpsEvent();
        int str_lenth=i;
        coordinate2dec();
        i=0;x=0;
        str_lenth=0;
       }
    }

    void show_coordinate()
    {
        lcd.clear();
        lcd.print("Lat:");
        lcd.print(latitude);
        lcd.setCursor(0,1);
        lcd.print("Log:");
        lcd.print(logitude);
        Serial.print("Latitude:");
        Serial.println(latitude);
        Serial.print("Longitude:");
        Serial.println(logitude);
        Serial.print("Speed(in knots)=");
        Serial.println(Speed);
        delay(2000);
        lcd.clear();
        lcd.print("Speed(Knots):");
        lcd.setCursor(0,1);
        lcd.print(Speed);
    }

    void coordinate2dec()
    {
      String lat_degree="";
        for(i=20;i<=21;i++)
          lat_degree+=gpsString[i];

      String lat_minut="";
         for(i=22;i<=28;i++)
          lat_minut+=gpsString[i];

      String log_degree="";
        for(i=32;i<=34;i++)
          log_degree+=gpsString[i];

      String log_minut="";
        for(i=35;i<=41;i++)
          log_minut+=gpsString[i];

        Speed="";
        for(i=45;i<48;i++)          //extract longitude from string
          Speed+=gpsString[i];

         float minut= lat_minut.toFloat();
         minut=minut/60;
         float degree=lat_degree.toFloat();
         latitude=degree+minut;

         minut= log_minut.toFloat();
         minut=minut/60;
         degree=log_degree.toFloat();
         logitude=degree+minut;
    }

    void Send()
    {
       Serial1.println("AT");
       delay(500);
       serialPrint();
       Serial1.println("AT+CMGF=1");
       delay(500);
       serialPrint();
       Serial1.print("AT+CMGS=");
       Serial1.print('"');
       Serial1.print("9821757249");    //mobile no. for SMS alert
       Serial1.println('"');
       delay(500);
       serialPrint();
       Serial1.print("Latitude:");
       Serial1.println(latitude);
       delay(500);
       serialPrint();
       Serial1.print(" longitude:");
       Serial1.println(logitude);
       delay(500);
       serialPrint();
       Serial1.print(" Speed:");
       Serial1.print(Speed);
       Serial1.println("Knots");
       delay(500);
       serialPrint();
       Serial1.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
       Serial1.print(latitude,6);
       Serial1.print("+");              //28.612953, 77.231545   //28.612953,77.2293563
       Serial1.print(logitude,6);
       Serial1.write(26);
       delay(2000);
       serialPrint();
    }

    void serialPrint()
    {
      while(Serial1.available()>0)
      {
        Serial.print(Serial1.read());
      }
    }

title: LCD not displaying text (16x2)

Answers: 0


body:
I have a class which has a `const char *` property:
```c++
    class A
    {
    public:
     const PROGMEM char* text;
    };

    void setup()
    {
     // A a{"Hello World!"};
     // A a{PSTR("Hello World!")};

     A a;
     a.text = PSTR("Hello World!");

     Serial.begin(9600);
     delay(30);
     Serial.println(a.text);
    }

    void loop()
    {
    }
```

I’d like to spare some RAM using `PROGMEM`.

How to initialize `a` object then?

Obviously, it can’t be like this:
```c++
    A a{PSTR("Hello World!")};
```
This will do:
```c++
    A a;
    a.text = PSTR("Hello World!");
```
However, I need to pass string to the constructor.

title: Initialize object with PROGMEM constants

Answers: 2

body:
`const char* text;` is a pointer to constant not a constant pointer (`char * const text` is a constant pointer). So you can assign a pointer to a constant char array to `const char* text;` even a pointer to an array in PROGMEM.

The compiler doesn't know the difference between a PROGMEM pointer and a pointer in SRAM. It is on you to work in code with a pointer to PROGMEM the right way.

so remove PROGMEM from `const PROGMEM char* text;`

----------

add constructor to initialize an object.

    A(const char* _text) {
      text = _text;
    }

and then

    A a(PSTR("Hello World!"));

----------
EDIT:

you could use Arduino's F() macro and __FlashStringHelper type, because it is supported by Serial print and co.

    class A
    {
    public:
      A(const __FlashStringHelper* _text) {
        text = _text;
      }
      const __FlashStringHelper* text;
    };

    void setup()
    {
        A a(F("Hello World!"));

        Serial.begin(9600);
        delay(30);
        Serial.println(a.text);
    }

    void loop()
    {
    }

__FlashStringHelper type is trick to distinguish PROGMEM strings from char arrays in SRAM..

body:
It is a shame that gcc only supports the `__flash` qualifier in C mode,
not in C++, so we have to use `PROGMEM` instead. Unlike `__flash`, which
qualifies a variable just like `const`, the `PROGMEM` attribute only has
effect when allocating room for a variable. Once the allocation is done,
the compiler forgets about the attribute. In particular, a declaration
such as

```c++
const PROGMEM char* text;
```

does not allocate flash space, so it generates the warning

```text
warning: ‘__progmem__’ attribute ignored [-Wattributes]
     const PROGMEM char* text;
                         ^
```

You can thus forget the attribute when declaring a pointer, as there is
no such thing as a “pointer to `PROGMEM`”. You just use a `const char *`
instead.

Now, the second issue is that, as far as `Serial.println()` is
concerned, the pointer above is a plain `const char *`, so it will
interpret it as an address in RAM, and print garbage. If you want
`Serial.println()` to know you are giving it an address in flash, you
should provide it with a `const __FlashStringHelper*` pointer.

Here is the solution I propose. Tested on an Uno-compatible board:

```c++
class A
{
public:
    A(const char* s)
        : text(reinterpret_cast<const __FlashStringHelper *>(s)) {}
    const __FlashStringHelper* text;
};

void setup()
{
    A a{PSTR("Hello World!")};
    Serial.begin(9600);
    Serial.println(a.text);
}

void loop(){}
```

------------------------------------------------------------------------

**Edit**: After seeing the last version of Juraj’s answer, I must say
that I agree with him. Since we are using the Arduino API, it makes more
sense for the constructor to take a `const __FlashStringHelper*`, and
for the caller to use the `F()` macro.


body:
I write a piece of code in online GDB using c++, the code calculates some coefficients for a IIR filter which tries to approximate a fractional derivative and integral for a fractional PID control. The code works as expected in the online IDE, but when I try to execute it in a Arduino Due, the results and only overflows and nan, and really don't know what's the problem so,

Here is the code in GDB online https://onlinegdb.com/rycwt62XL which gives the expected results:

Array A, Array B

 1.41421,1

-0.707107,0.5

-2.12132,-1.5

0.883883,-0.625

0.883883,0.625

-0.265165,0.1875

-0.0883883,-0.0625

0.0110485,-0.0078125

And here is the code for the Arduino Due, which only change the printing method using the serial commands, https://onlinegdb.com/ByAs5xyVU, and the results are:

Array A, Array B

ovf,1.00

ovf,ovf

ovf,0.00

inf,ovf

ovf,0.00

inf,ovf

ovf,3.89

inf,ovf

And really don't know where to start for fix this results, thanks. The Method is  exactly the same.

title: Gauss solver for IIR filter

Answers: 1

body:
I can't find the root cause of the problem - it's probably because the Due is possibly the worst board that Arduino ever made, and the compiler / linker / support libraries barely work at the best of times.

However, some things you need to look at in your code:

```
    double* h = new double[L];
    for(int n = 0; n <= L; n++){
        for(int k = 0; k <= n; k++){
            h[n] += pow(operador,-alpha-n+k)*pow(1.0-operador,n-k)*Binomial_E(alpha,k)*Binomial(-alpha,n-k);
        }
    }
```

There you allocate `L` (15) doubles in an array. But then you go on to access array slices 0-15. That's 16 entries in an array of size 15, so you're overflowing it and corrupting other memory.

Also you have no `delete` to balance the `new`, so you have a memory leak.  You would be better using:

    double h[L+1];

instead of `new`.


body:
I have an ESP8266 which I'm using the Arduino IDE to compile a program which
uses soft access points to talk to an Android App compiled using MIT App Inventor. The app seems to work the first couple times but then my cell phone looses connection and I have to go to Settings->Wifi connections and rescan and wait for it to connect. Sometimes it says: "Denied access to network" and sometimes (most always) after I connect I will get a message that says I'm not connected to the internet, which I don't want, and then choose 'No' to stay connected to the current network. My cell phone is right next to the ESP8266 and the signal strength is 'Excellent'. I'm only powering the board via the USB cable connected to it. Do I need to run 3v3 to the pin marked '3V3'?

Here's the code:

    // server running on ESP8266 to get commands from Android App
    // Load Wi-Fi library
    #include <ESP8266WiFi.h>

    // Replace with your network credentials
    const char *ssid = "PanzerD"; // The name of the Wi-Fi network that will be created
    const char *password = "testasdf";   // The password required to connect to it, leave blank for an open network
    // Set web server port number to 80
    WiFiServer server(80);
    IPAddress local_IP1(192,168,0,15);
    IPAddress gateway1(192,168,0,1);
    IPAddress subnet(255,255,255,0);

    // Variable to store the HTTP request
    String header;

    // Auxiliar variables to store the current output state

    // Assign output variables to GPIO pins
    int tool_box_lights = 0;
    int pass_side_lights = 0;
    int drv_side_lights = 0;
    int rear_lights = 0;
    int winch = 0;

    // Current time
    unsigned long currentTime = millis();
    // Previous time
    unsigned long previousTime = 0;
    // Define timeout time in milliseconds (example: 2000ms = 2s)
    const long timeoutTime = 2000;

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

      Serial.print("Setting soft-AP configuration ... ");
      Serial.println(WiFi.softAPConfig(local_IP1, gateway1, subnet) ? "Ready" : "Failed!");
      Serial.println(WiFi.softAP(ssid,password,1,4) ? "Ready" : "Failed!");

      Serial.print("Soft-AP IP address = ");
      Serial.println(WiFi.softAPIP());

      // Connect to Wi-Fi network with SSID and password
      Serial.print("Connecting to ");
      Serial.println(ssid);
      WiFi.begin(ssid, password);
    /*
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    */
      // Print local IP address and start web server
      Serial.println("");
      Serial.println("WiFi connected.");
    //  Serial.println("IP address: ");
    //  Serial.println(WiFi.localIP());
      server.begin();
    }

    void loop(){
      WiFiClient client = server.available();   // Listen for incoming clients

      if (client) {                             // If a new client connects,
    //    Serial.print("Client: ");          // print a message out in the serial port
        String currentLine = "";                // make a String to hold incoming data from the client
        currentTime = millis();
        previousTime = currentTime;
        while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
          currentTime = millis();
          if (client.available()) {             // if there's bytes to read from the client,
            char c = client.read();             // read a byte, then
    //        Serial.write(c);                    // print it out the serial monitor
            header += c;
            if (c == '\n') {                    // if the byte is a newline character
              // if the current line is blank, you got two newline characters in a row.
              // that's the end of the client HTTP request, so send a response:
              if (currentLine.length() == 0) {
                // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
                // and a content-type so the client knows what's coming, then a blank line:
                client.println("HTTP/1.1 200 OK");
                client.println("Content-type:text/html");
                client.println("Connection: close");
                client.println();
                //Serial.println(header);
                // turns the GPIOs on and off
                if (header.indexOf("/tb/on") >= 0)
                {
                  Serial.println("toolbox on");
                  client.println("toolbox on");
         tool_box_lights = 1;
                } else if (header.indexOf("/tb/off") >= 0)
                {
                  Serial.println("toolbox off");
                  client.println("toolbox off");
         tool_box_lights = 0;
                } else if (header.indexOf("/ps/on") >= 0)
                {
                  Serial.println("pass side on");
                  client.println("pass side on");
         pass_side_lights = 1;
                } else if (header.indexOf("/ps/off") >= 0)
                {
                  Serial.println("pass side off");
                  client.println("pass side off");
         pass_side_lights = 0;
                } else if (header.indexOf("/ds/on") >= 0)
                {
                  Serial.println("drv side on");
                  client.println("drv side on");
         drv_side_lights = 1;
                } else if (header.indexOf("/ds/off") >= 0)
                {
                  Serial.println("drv side off");
                  client.println("drv side off");
         drv_side_lights = 0;
                } else if (header.indexOf("/rr/on") >= 0)
                {
                  Serial.println("rear lights on");
                  client.println("rear lights on");
         rear_lights = 1;
                } else if (header.indexOf("/rr/off") >= 0)
                {
                  Serial.println("rear lights off");
                  client.println("rear lights off");
         rear_lights = 0;
                } else if (header.indexOf("/wc/in") >= 0)
                {
                  Serial.println("winch in");
                  client.println("winch in");
         winch = 1;
                } else if (header.indexOf("/wc/out") >= 0)
                {
                  Serial.println("winch out");
                  client.println("winch out");
         winch = 2;
                } else if (header.indexOf("/wc/off") >= 0)
                {
                  Serial.println("winch off");
                  client.println("winch off");
         winch = 0;
       }
                // Display the HTML web page
                // The HTTP response ends with another blank line
                client.println();
                // Break out of the while loop
                break;
              } else { // if you got a newline, then clear currentLine
                currentLine = "";
              }
            } else if (c != '\r') {  // if you got anything else but a carriage return character,
              currentLine += c;      // add it to the end of the currentLine
            }
          }
        }
        // Clear the header variable
        header = "";
        // Close the connection
        client.stop();
    //    Serial.println("Client disconnected.");
    //    Serial.println("");
      }
    }

Here's the blocks for the MIT App Inventor:
[![enter image description here][1]][1]
Each one of the blocks responds to a button press and depending on what the global variable is (upper left block is for toolbox lights) it will send the URL "/tb/on" in the case for turning the toolbox lights on.
[Edit:] It works fine when I use the modem as an access point but I need soft access points because I don't want to have to carry a router around in my truck.

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

title: ESP8266/Android app: slow response when using soft access point and keeps dropping connection

Answers: 0


body:
I was hoping to get your advice on what Arduino boards to look at for a project I'm working on. The project involves two separate boxes in different rooms of my apartment (~ 5-10 feet away from each other) and needs to allow wireless communication of very small amounts of information (think like 5 bytes). However, this transfer needs to be very rapid (within 200 milliseconds).

While I have worked a good bit with the Arduino Uno, I haven't worked with boards with Wifi capabilities.

The boards I know of are: Esp32, Esp8266, Arduino MKR 1010, Arduino Mega RobotDyn.

What would be the best board for a project like this / are there other boards that are well-suited for a project like this?

Thanks!

title: Which board to use for wireless communication of small packages?

Answers: 1

body:
WiFi round trip time is about 2-50 ms (50 is the worst case), so, you can use the ESP's and the UDP/TCP.

On the other hand, you can use the NRF433 module, but in this case, you have to develop your own channel level protocol, with error detection/correction and so on.

Also, there are [ZigBee][1] module. They developed for home automation specially.

  [1]: https://en.wikipedia.org/wiki/Zigbee


body:
I am trying to get both the motors to run simultaneously once the motion detector senses an obstacle. Both motors run fine by themselves but when I implement the sensor the motors only move one step per motion detected.

- Arduino Mega (ATMega 2560)
- (2) NEMA 17 stepper motor/ A4988
- Digital IR Sensor Module

~~~
#include <Arduino.h>
#include <avr/io.h>
#include <AccelStepper.h>

AccelStepper stepper(1,5,4); // w/Driver (1,Step, Direction)
AccelStepper stepper2(1,9,8);

const int pin_ir_in = 3;
int prev_state = 1;
int curr_state = 1;
int counter =0;

void setup() {
  Serial.begin(9600);
  pinMode(6,OUTPUT); // Enable
  pinMode(10,OUTPUT);

  digitalWrite(6,LOW); // Set Enable low
  digitalWrite(10,LOW);
}

void loop() {
  digitalWrite(6,LOW); // Set Enable low
  if (stepper.distanceToGo() == 0)
  {
    delay(1000);
    stepper.moveTo(100);
    stepper.setMaxSpeed(200);
    stepper.setAcceleration(100);

  }

   digitalWrite(10,LOW); // Set Enable low
     if (stepper2.distanceToGo() == 0)
  {
    delay(1000);
    stepper2.moveTo(100);
    stepper2.setMaxSpeed(200);
    stepper2.setAcceleration(100);

  }

int curr_state = digitalRead(pin_ir_in);
if (curr_state != prev_state)
{
  if (curr_state == 0)
  {
    stepper.run();  // Actually makes stepper move
    stepper2.run();
    delay(500);
  }
  prev_state = curr_state;

}

}
~~~

title: Stepper motor is only moving one step at a time with an IR sensor

Answers: 1

body:
As chrisl said, you need to call `run` repeatedly.

I tried to rewrite the code you've given, though I'm not entirely sure what it is you try to achieve.

    void loop()
    {
      stepper.run();  // Actually makes stepper move
      stepper2.run();

      int curr_state = digitalRead(pin_ir_in);
      if (curr_state != prev_state)
      {
        if (curr_state == 0) // Motion sensor activated
        {
          stepper.moveTo(100);
          stepper.setMaxSpeed(200);
          stepper.setAcceleration(100);
          stepper2.moveTo(100);
          stepper2.setMaxSpeed(200);
          stepper2.setAcceleration(100);
        }
        prev_state = curr_state;
      }
    }


body:
I am making a custom wall-clock, and need the Arduino (Uno or Nano) to connect to a DS1302 real time clock module and a WS2811 LED chain.

So I’m using [DS1302](http://www.rinkydinkelectronics.com/library.php?id=5) for the clock, and [FastLED](https://github.com/FastLED/FastLED) for the lights. Individually these two libraries work fine, so I can either echo the time to the serial console, or I can drive the LEDs as I need.

But when I combine them there is some conflict happening and I get no LED output. The LED data goes over pin 6 and the clock uses pins 2,3,4 (these pins are customisable in code).

Even just adding a DS1302 initialisation to a working FastLED sketch causes no more LED output

    #include <FastLED.h>
    #include <DS1302.h>

    #define NUM_LEDS 50
    #define DATA_PIN 6

    // Init the DS1302 - stops LEDs working
    DS1302 rtc(2, 3, 4);

    CRGB leds[NUM_LEDS];

    void setup() {
      FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
    }

    void loop() {
      for (int i=0; i<NUM_LEDS;i++) {
        leds[i] = CRGB::Red;
      }
      FastLED.show();
      delay(100);
    }

What are my troubleshooting steps - should I try alternative libraries, or could I dig into the libraries themselves and see what hardware resources they might be using?

I guess as both the lights and the clock probably operate over a serial protocol, it could be a conflict with the serial drivers - maybe both using the same time-critical operations.

Edit: inserted sketch which demonstrates the issue

title: Which libraries for DS1302 real time clock and WS2811 LED strip do not conflict?

Answers: 1

body:
I installed a library from within the IDE as StarCat suggested.

https://github.com/Makuna/Rtc

    #include <FastLED.h>
    #include <ThreeWire.h>
    #include <RtcDS1302.h>

    #define NUM_LEDS 50
    #define DATA_PIN 6

    ThreeWire myWire(3,4,2); // IO, SCLK, CE
    RtcDS1302<ThreeWire> Rtc(myWire);

    CRGB leds[NUM_LEDS];

    void setup() {
       FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
       Rtc.Begin();
    }

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

       for (int i=0; i<NUM_LEDS;i++) {
         leds[i] = CRGB::Red;
       }

    FastLED.show();
    delay(100);
    }

I am able to get and use the time, and the LED output works.


body:
So I'm having a little bit of difficulty here in my NEO-6M. `The problem is it doesn't show any data in my serial monitor.` My NEO-6M Led is already blinking so its already ok.

    RX -> Pin3 , TX -> Pin4 , VCC -> 3.3v , GND -> GND

>Serial Monitor:
[![enter image description here][1]][1]

Code:
_<https://github.com/mikalhart/TinyGPSPlus/blob/master/examples/FullExample/FullExample.ino>_

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

title: NEO-6M is working but it doesnt show data

Answers: 1

body:
I found a solution to my problem. On my first setup, I separate my GND of NEO-6M to Arduino and put connect it in breadboard that has powerboard on it because I thought it is only for electrical purposes but it doesn't since I encounter it.

Solution:
>The GND of every module must still connect on the Arduino.


body: How can i convert file .ino to hex file so that i can compile new sketch via bluetooth. Can you help me to figure out the way to do this? thanks for helping

title: upload sketch via bluetooth for android

Answers: 1

body:
It is very hard to understand exactly what you want to do, but from what I can gather you want to:

1. Write an Android application that lets you edit sketches
2. Compile those sketches on an android device, and
3. Upload those compiled sketches to an Arduino over Bluetooth

While what you are asking is *technically* possible, it is not *realistically* practical.

Writing a text editor in Android is easy enough. That's not a problem. It's the compilation of the code that is not practical.

You would need to port the compiler (a very large project written in C) to Android. That would essentially need to remain as compiled C code, and so you would have to individually port it to each possible platform you want it to run on (various different types of ARM, Intel, etc) and for different versions of android.

Unless you're a genius at Android and C programming that's just not going to happen.

A more practical way would be to write a web-based application that allows you to edit your sketches, which can then run the compiler on a real computer (no porting needed then), which can then download the compiled HEX file to your Android device, then use a pre-existing application to program that HEX file over bluetooth.

Alternatively, just use the Arduino Create website to compile and download your HEX file.


body:
I've been designing a product for some time using arduino language, but on our own hardware. Recently a need arose to add some Bluetooth capability to our product. We decided to use BT classic instead of BLE, because not every phone has BLE capability yet. Of course immediately I went to check [HC-05][1] modules and their cousins. The issue is I believe they are a chinese product and have no FCC certification and I can't buy them from any reputable source (digikey,mouser,farnell etc.).

Seeing that this is an issue for a product I went and checked the mentioned suppliers to see what they offer. The thing is though, I'd like to stay in the arduino environment so I'm looking for a module that has some support from the arduino side.

I found [this][2] module from Cypress, that has [this][3] "arduino-compatible" code. However when a tried to find any library that I could use to program this board using arduino environment on Cypress's site I only found mentions of their own SDK.

Thus comes the question: are there any FCC compliant bluetooth modules that have an easy to use arduino library available?

  [1]: https://www.amazon.com/DSD-TECH-HC-05-Pass-through-Communication/dp/B01G9KSAF6
  [2]: https://www.mouser.com/ProductDetail/Cypress-Semiconductor/CYBT-213043-02?qs=sGAEpiMZZMu3sxpa5v1qrgkV%2BmLWY283etI2l9FHofA=
  [3]: https://www.mouser.com/new/cypress-semiconductor/cypress-cybt-213043-eval-board/

title: Arduino-compatible Bluetooth classic module to use in a product

Answers: 0


body:
I have 2 questions.

 1. Why we have to put our functions before void loop and void setup into VScode+platformio?
 2. I switched from arduino IDE to VScode+platformio today, when I upload the sketch with platformio into my esp-12, it doesn't work. (It works with arduino IDE)

I have this Warning: ```src\main.cpp:46:24: warning: large integer implicitly truncated to unsigned type [-Woverflow]
 const byte menuColor = 0XF206;```

[EDIT]The problem comes from these lines:

```
attachInterrupt(digitalPinToInterrupt(enA), enAin, RISING);
attachInterrupt(digitalPinToInterrupt(enB), enBin, RISING);
attachInterrupt(digitalPinToInterrupt(enBtn), enBtnIn, FALLING);

title: ESP-12 + FTDi + platformio

Answers: 1

body:
> Why we have to put our functions before void loop and void setup into VScode+platformio?

Because that is how C works. The Arduino IDE hides it from you by adding *function prototypes* at the start of your code.

> I switched from arduino IDE to VScode+platformio today, when I upload the sketch with platformio into my esp-12, it doesn't work. (It works with arduino IDE)

    const byte menuColor = 0XF206;

That can never work. The value 0x06 will be assigned to menuColor since a byte is only 8 bits.  You need to learn to use data types that are suitable for the values you are trying to store in them.


body:
>Does the MB-102 can handle Arduino Uno, SIM900 and 3 other modules that requires 5v? If yes, does 9v battery is enough? If no, please suggest me what should I use that uses only 1 barrel jack(if possible).

Im afraid that I might fry it if I try cause I dont have enough knowledge about electric currents.

title: MB-102 BreadBoard Power Supply Limitation

Answers: 1

body:
> Does the MB-102 can handle Arduino Uno, SIM900 and 3 other modules that requires 5v?

You mean because the current requirements? The answer is yes and no. No, because the needed current must not flow through the Arduino. The SIM900 draws up to 2A, that current would fry the protection diode/voltage regulator on the Arduino (though you may get away with a bit less than that by using a big capacitor to accommodate current spikes). Depending on the version of the Uno, it can provide 200mA or 1A (in case of rev3)(including what is needed for the Uno to operate). You need to provide the 5V of these modules from outside of the Arduino, via an extra voltage regulator, which can handle the big current.

> does 9v battery is enough?

If you mean the standard 9V block battery, then no, never. These batteries are meant for low power applications and are almost never a good choice for an Arduino project (unless you have really a low power application). You need to use different batteries, for example a series of AA batteries or a LiPo pack (including the needed circuitry for such a pack).


body:
I have a stepper motor **28BYJ-48** rated 5 V and I want to use a **DVR8825** driver so I can use the 1/32 micro-stepping feature. My problem is that DVR8825 has a minimum operating voltage of 8.2 V. Would the 28BYJ-48 stand a 10 V input?

Is there any alternative to the DVR8825 that operates at 5 V and has at least 1/32 micro-stepping?

title: Can I control a 28BYJ-48 5V stepper with a DVR8825 driver?

Answers: 1

body:
Stepper motors are rated in two different ways. Some provide a "rated voltage" in combination with a "DC resistance", others provide a "phase current" and a "phase resistance". The way they operate is identical.

Stepper motors such as your 28BYJ-48 are usually intended to be driven with a fixed voltage, their rated voltage. At this voltage, the maximum permittable current flows in the steppers windings - determined mostly by cooling and wire thickness. If you exceed that voltage, more current will flow and will damage / destroy the stepper motor.

The DRV8825 is a current controlled stepper motor driver - it always uses the full available supply voltage - 8.2V+ - but uses PWM to limit the current actually flowing in the stepper. This is possible because the stepper motor coils are inductors, which inhibit the flow of current.

To use your stepper motor with a DRV8825 driver, you'll have to calculate the steppers equivalent "maximum phase current". According to [this datasheet][1], it's rated 5 V at 50 Ohms, giving us a current of 0.1 A. You can then set this current via the potentiometer on the driver chip. The Vref voltage should be set so that `Vref = Imax / 2`.
Start at a Vref of 50 mV, and see how warm the motor gets and whether it's as strong as you would expect it to be.

  [1]: https://www.digikey.at/de/datasheets/mikroelektronika/mikroelektronika-step-motor-5v-28byj48-datasheet


body:
I have 2 Arduino Nano, they are connected via ports 2 and A2

While I use only one port to receive, it works properly. But if I activate the second port, system crash (and even first port don't work properly)

Code of first Arduino:

    #include <SoftwareSerial.h>
    SoftwareSerial SerialPort2(2,A2);
    SoftwareSerial SerialPort3(3,A3);

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

    void loop() {
      delay(500);
      SerialPort2.listen();
      if(SerialPort2.available()){
        char value = SerialPort2.read();
        Serial.print(value);
        Serial.print(" First port\n");
      }
      // IF YOU REMOVE PART BELLOW, THE 'SerialPort2' WILL WORK PROPERLY
      SerialPort3.listen();
      if(SerialPort3.available()){
        char value = SerialPort3.read();
        Serial.print(value);
        Serial.print(" Second port\n");
      }
      // END OF THIS PART
    }

Code of second Arduino:

    #include <SoftwareSerial.h>
    SoftwareSerial SerialPort2(2,A2);

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

    void loop() {
      SerialPort2.write('a');
      delay(1000);
    }
PS in real system I need to listen 6 ports

title: Reading from 2 serial ports

Answers: 2

body:
`SoftwareSerial` can only listen to one port at a time. You cannot listen to both, no way. To really listen to both, you need an Arduino with more hardware Serial ports, where most of the protocol is done in hardware, thus can receive without CPU intervention. The Arduino Mega has 4 hardware Serial ports.

Or you could impose a protocol on the Serial stream to make the listening Arduino the master. You would listen to the first serial interface, send a start byte over this interface, that tells the slave Arduino to start sending. It sends and the listening interface receives (The transmission has to be delimited by either a time limit, e.g. listen for a specific time, or by a stop byte). Then you listen to the next interface, send again the start byte and receive. And so on.

With such a protocol, you could even use a single serial interface. The protocol makes sure, that only one slave is transmitting at a time. Though you should add resistors to every slave to protect their TX pins.

> in real system I need to listen 6 ports

Serial (UART) is really not the best interface type for such topology. You should consider using interfaces like SPI. It doesn't need additional electronics and is better fit for multiple slaves.

body:
SoftwareSerial is only a "good" choice (for certain values of "good") if you only use *one* instance, and that is the *only* serial port in the system.

Using SoftwareSerial to read from 2 ports simultaneously is not possible.  Using SoftwareSerial to read data in tandem with any other hardware serial ports *will result it data loss*.

SoftwareSerial is only any real use when you are using it to request data from another device and times when you command it to happen.

To receive data in an "unsolicited" fashion SoftwareSerial is not good.

Instead you need a hardware serial port for *each* incoming signal. And obviously you can't do that with a small board like a nano.  So you need to think more creatively.

If you have one real serial port you can talk to one device. But there are other communication channels at your disposal. So you take one board and have that communicate to one of your serial devices. Then you take the data read and convert it into another communication protocol that is capable of sharing time with other boards. Then that, and 5 other boards, all send their data (or get data from) one central "master" board.  In effect you have 6 "UART to Protocol X" converter boards, and one "Protocol X" master board.

Alternatively choose a board that has 6 UARTs. There are many higher-end chips like some ATSAMD, SAMX, and PIC32 chips, that have 6 UARTs available to you.


body:
How to create a USB CDC device. (I'm using stm32f103c8 black pill board) and I want to read the data through USB in my raspberry pi as a serial port.

I am using a black pill to read RFID-rf522 to read a tag (SPI) and send it to raspberry pi through a USB (using DM and DP pins).

Quick responses are welcomed.

Answers: 1

body:
You can use the one provided by generating it with [STMCubeMx][1]. This is going beyond arduino though. But it is highly feasible.

  [1]: https://www.st.com/en/development-tools/stm32cubemx.html


body: I have a 10 DOF sensor with wire outputs labeled "VIN", "GND", "SCL", and "SDA".  I would like to wire these into my arduino and ultimately obtain x, y, and z displacement.  This might sound like a simple problem for a veteran but I have gotten lost in the literature and code.  Where can I learn how to do this or is there a library that I can use?

title: 10 DOF gyro and accelerometer to x,y,z displacement

Answers: 0