body:
I've compiled an Arduino program via a Makefile and have the resulting hex file.

From the Mac command line, how do I upload this hex file to my [STM32 Cortex M3][1] board?  For an ATMEL processor I would use avrdude.

  [1]: https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html

title: How do I upload an Arduino STM32 binary from the Mac command line?

Answers: 1

body:
There are several different tools for uploading binaries to a Cortex M3.  Depending on the board (not chip) configuration, they include (ht: Majenko):

- dfu-util through an FT232 adapter
- stm32flash through serial
- micronucleus through the Micronucleus bootloader
- stlink through an STLink programmer

Many Arduino flavors use a board with some kind of USB or FT232 adapter.  In this case:

the STM32 line of processors include a [DFU][2] ([device firmware update][3]) bootloader in ROM.

The [dfu-util][4] project supports a Mac version of dfu-util, their command line DFU tool.

Note that this answer is identical for any binaries which run on the processor, be they Arduino sketches or programs developed with other frameworks.

  [2]: https://www.st.com/content/ccc/resource/technical/document/application_note/6a/17/92/02/58/98/45/0c/CD00264379.pdf/files/CD00264379.pdf/jcr:content/translations/en.CD00264379.pdf
  [3]: https://www.digikey.com/en/articles/techzone/2018/jan/update-firmware-field-using-microcontroller-dfu-mode
  [4]: http://dfu-util.sourceforge.net/


body:
Before committing to learning about the ESP32 and how to program it, I would like to know if the ESP can be programme the same way for production as it can on évaluation boards (with the Arduino IDE).

Since it obviusly much easier than most for microcontrollers, I was wondering if a product is eventually mass produced, if the code used to program the evaluation board (such as this one https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/) could be used on the final product.

title: Programming ESP32 MCUs for production

Answers: 1

body:
Yes. Most manufacturers would just require a binary (or HEX depending on MCU) file of your compiled code. If it's not a system they already know how to handle you will also need to provide a procedure for them to follow to program the device. What form that takes depends on the manufacturer.

You can also generally order pre-programmed MCUs and modules direct from the manufacturer where they (for a small fee) will program the chips for you before they are then sent to the board manufacturer for population.

If there is no facility on the MCU manufacturer's website then just email their sales department and I am sure they would be happy to quote you. Again, all they will require is a HEX or BIN file (depending on manufacturer) for programming.


body:
Using a `NodeMCU` master and an `Arduino` slave (`Wire.h` on both sides), is there a maximum message size (32 bytes?) for the answer that the slave sends from `requestEvent()`?

If so, is there any solution to circumvent such a restriction WITHOUT the use of other libraries (like `I2C_Anything`, for example)?

title: I2C master/slave maximum requestEvent message size

Answers: 1

body:
The I2C protocol itself does not have a transmission size restriction. But the implementation in the Wire library only reserves a specific amount of RAM for the buffers. [This site](https://playground.arduino.cc/Main/WireLibraryDetailedReference/) mentiones 32 bytes for normal Arduinos (couldn't find the source code currently) and I found 128 bytes for the ESP8266 in the [source code](https://github.com/esp8266/Arduino/blob/master/libraries/Wire/Wire.h).

You cannot have unlimited message length, since the buffer has to hold the whole message and the RAM on normal Arduinos is very limited.

But you can make the buffers of the libraries bigger by changing the corresponding defines in the header files to a bigger value. Keep in mind, that the actual used memory space is with a factor 2, since the buffer size gets used for both send and receive buffer.

---

If you need bigger messages, than is fitting in the available RAM, you should either change to a board with more RAM, or develop a way to process one part of a message, deleting it and then process the next part (multi part message). Though that raises the question, why the messages have to be that big in the first place.


body:
I have a simple script that listens on pin 0 for input, and if it gets anything, it `Serial.prints` it. But I cannot make sense of the results. I have a basic app that sends text over Bluetooth (in the code I see `utf8.encode(message)` if that helps), and I'm able to validate that the message is **not** corrupted by the module, by simply touching the RX and TX pins together, the app receives the same message it sent. But the Arduino cannot understand it.

Here's my code:
```cpp
void setup() {
 Serial.begin(9600);
}

void loop() {
 if (Serial.available() > 0) {
  Serial.print("New value: ");
  Serial.println(Serial.read());
 }
}
```

The TX on the HC-01 is connected to pin 0, and the RX is connected to pin 1. Power and ground are connected to the Arduino's (and I even tried different grounds just in case that one was fried). The Arduino is powered by USB and I'm using the Serial moniter. Here is some sample input-output:

```yml
Me through the app: a. Arduino: 255
Me through the app: a. Arduino: 254
Me through the app: a. Arduino: 254
Me through the app: a. Arduino: 254
Me through the app: a. Arduino: 254
Me through the app: a. Arduino: 255
Me through the app: aa. Arduino: 254
Me through the app: aaa. Arduino: 252
Me through the app: aaaa. Arduino: 252
```

I just don't understand any of it. Please help me out.

title: Cannot make sense of values from Bluetooth HC-01

Answers: 0


body:
on an ardunio, is there a way to detect if a data connection (vs power only) is present? I want to have my arduino behave differently if connected to a pc, or on stand alone power.

specifically, I have a project that sends keystrokes to a midi piano program I wrote, but when a pc is not connected, I would like to have the arduino send the notes to a peizo buzzer attached to the circuit instead.
Im using a teensy, or a leonardo, or an Uno.

title: how do I detect a data connection?

Answers: 0


body:
I'm trying to build a fire fighting robot, that uses 2 BO DC motors, 2 Servos - MG996R and SG90. For them I'm using Motor Shield v1 of Adafruit's make that uses 2 L293D IC's and a 74HC595 shift registers.

Now, I'm placing the motor shield over Arduino Mega and trying to connect other components such as Flame Sensor, Ultrasonic Sensor and submersible DC Water Pump.
As soon as I try to power up ultrasonic sensor, the power indicating LED's on both the shield and Mega goes off.

I've been testing this with simple USB connected power supply and to my understanding the power being supplied is insufficient.
Since **it would be a moving cart, I would like to know whether there is any way to power up Shield and Mega separately by a 9v Battery?**

title: Powering Motor shield and Arduino Mega Separately

Answers: 1

body:
On the side of the DC Motor Shield v1, there is an external power - +  2 pin terminal.

This can be used to supplement the shield with power.

Adafruit: "The motor controllers on this shield are designed to run from 4.5V to 25V.
MOST 1.5-3V MOTORS WILL NOT WORK"

If you are lucky to have the motor specs and ratings on hand, you will be able to account for how much power your motor(s) will need in your application.

Adafruit: "The motor driver chips that come with the kit are designed to provide up to 600 mA per motor, with 1.2A peak current. Note that once you head towards 1A you'll probably want to put a heatsink on the motor driver, otherwise you will get thermal failure, possibly burning out the chip."

Here is an important tid-bit for your scenario... (So no 9v Batteries for the motors!):

Adafruit: "You can't run motors off of a 9V battery so don't even waste your time/batteries! Use a big Lead Acid or NiMH battery pack. Its also very much suggested that you set up two power supplies (split supply) one for the Arduino and one for the motors. 99% of 'weird motor problems' are due to noise on the power line from sharing power supplies and/or not having a powerful enough supply!"

...

So makes sense,  get the Arduino powered, by itself, then get another power source for your motor shield.

Your sensors might be able to hop on the Arduino power supply if it's providing enough power.  I'd keep them separate from the motor power line, due to noise interference as suggested.

Try this, and see if the Arduino stays powered.

There is a lot of helpful info here, some new things I've learned just now.
https://learn.adafruit.com/adafruit-motor-shield/power-requirements


body:
I am trying to address an I2C device on my Huzzah Feather (Adafruit) ESP8266, but the I2C scanner tool does not detect anything.  All is sufficiently powered and quadruple checked the wiring.

Is there something I am missing for this board in regards to I2C connections?

I've had no issue on an Arduino, which uses the 2 pins on the Analog rail for I2C...

The Huzzah has no Analogue But the one pin, regardless, Huzzah Feather has different (still pin 4 & 5 tho) I2C,  and not via A0 A1 like on the Uno.

Do I need to dig deep and change some pin configurations for the Huzzah?

Thought I would ask before wasting more time on trial and error experiments.

**Update Note:**

I failed to mention there is a Feather Neopixel board (4x32) hard soldered to the board. Which I suspect is not the culprit as this issue also persists on same board without the neopixel shield attached.

**Update**

The soldering job was good, but discovered a faulty wire.  This allowed the I2C scanner to detect the i2C controller (LCD2004) at the address of 0x3F...

I checked with a I2c LCD library example, and I don't get any characters to come up... This is the same with both Huzzah Feather boards, one with Neopixel shield and the other is bare.

title: ESP8266 (Huzzah Feather) I2C scanner finds nothing

Answers: 1

body:
This particular issue was due to a faulty wire on the I2C bus. I replaced the wire and I was able to scan and get an address to the I2C LCD controller.

I still cannot get text to the LCD.  I will start a new question for that.

EDIT:

Upon scrapping my I2C_LCD_DISPLAY library, I downloaded one that was linked in a ESP32/8266 tutorial for the LCD, and finally got it working.


body:
I am trying to program my Arduino Uno board for a 24 hour cycle.
I have the Arduino board and two relays.
The aim is; every 24 hours relay 1 has to switch on for 5 seconds, and 1 second later relay 2 has to switch on for 15 seconds.
I have a sketch for a 12 hour cycle, and that works fine, but when I try for a 24 hour cycle, by changing the const unsigned int totalTime from 43200 seconds to 86400 seconds, everything goes wrong.

24 hour sketch - what is wrong?

    //turn relays on and off at certain times.
    //when the digital output pin is HIGH, then the relay is off.
    //when the digital output pin is LOW, then the relay is on.

    enum actioEnum {
      RELAY1_ON,
      RELAY1_OFF,
      RELAY2_ON,
      RELAY2_OFF,
    };

    struct tableStruct{
      unsigned int time;
      actionEnum action;
    }
    const table [] = {
      {0,RELAY1_ON},
      {5,RELAY1_OFF},
      // remaining 86395 for a total of 86400.
      {0,RELAY2_OFF}, // not needed, it is already off.
      {6,RELAY2_ON},
      {6+15,RELAY2_OFF},
      // remaining 86379 for a total of 86400.
    };

    const unsigned int totalTime = 86400; // total amount for sequence
    unsigned int seconds;

    unsigned long previousMillis;
    const unsigned long interval = 1000; // 1000 ms; // 1000 ms is one second

    const int relay1Pin = 2;
    const int relay2Pin = 3;

    void setup() {
       serial.begin(9600);

      // the relay is off when the pin is high.
      // turn output high before setting the pinMode.
      // then the output changes from a floating pin to high,
      // and the relays will not be activated.
      digitalWrite (relay1Pin, HIGH);
      pinMode (relay1Pin, OUTPUT);
      digitalWrite (relay2Pin, HIGH);
      pinMode (relay2Pin, OUTPUT);
    }

    void loop () {
      // a one second timer with millis
      if (millis() - previousMillis >= interval) {
        previousMillis += interval;
        // scan table
        for ( int i = 0; i < int (sizeof(table) / sizeof (tableStruct)); i++) {
          if (table [i] . time == seconds) {
            switch (table [i] . action) {
              case RELAY1_ON:
                Serial.println("Relay 1 on");
                digitalWrite (relay1Pin, LOW); // low is relay on.
                break;
              case RELAY1_OFF:
                Serial.println("Relay 1 off");
                digitalWrite (relay1Pin, HIGH); // high is relay off.
                break;
              case RELAY2_ON:
                Serial.println("Relay 2 on");
                digitalWrite (relay2Pin, LOW); // low is relay on.
                break;
              case RELAY2_OFF:
                Serial.println ("Relay 2 off");
                digitalWrite (relay2Pin, HIGH); // high is relay off.
                break;
              default:
                Serial.println ("Error, a bug in the scketch");
            }
          }
        }
        seconds++;
        if (seconds >= totalTime) {
          seconds = 0;
        }
      }
    }

title: Difficulties programming Arduino uno for 24 hour cycle

Answers: 1

body:
On the Uno `unsigned int` is a 16 bit number. That means, that it can hold values between (and including) 0 and 65535. If you try to write a bigger value to this variable, it will cut of the higher bits, so that the rest fits into 16 bits. That gives you a totally different value, which is significantly small than 24h.

The solution is to use a bigger variable type for `totalTime`.
 You can use `unsigned long`, which has 32 bits and can hold way bigger values ( 0 to 4,294,967,295 (2^32 - 1)). That should be plenty enough for all your cases.


body:
First, my setup:
I have an Arduino Uno with an Adafruit Audio Shield.  I have a Wemos D1 Mini controlling the project.

I need for the D1 to know when a file is playing.

I have a GPIO pin on the Uno programmed to be high when a file is playing.  Low otherwise.  I have two GPIO pins on the Wemos that are unused, D3 and D4 (GPIO0 and GPIO2).  (I use a divider circuit of a 10K over a 20K resistor to bring the 5V from the Uno down to 3v3 for the Wemos). D4 is already a problem because it has to be high to boot and the GPIO from the Uno is normally low. D3 (GPIO0) has to be high to boot and has an internal pullup.

Here's my problem.  How do I turn off the pullup on GPIO0? Even when the Uno GPIO is low (0V), the GPIO0 measures 2.4V, which my sketch sees as a logical 1.

Any tips would be appreciated.  (I thought of reversing the polarity on the Uno so that low=true, but even when the Uno is driving the pin low, the Wemos GPIO0 pin is still at 2.4V, so low-true logic won't work either.).

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

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

title: esp8266- how to use GPIO0 as an input?

Answers: 1

body:
Don't use the voltage divider and never set the Uno pin HIGH.

Pull io 0 of esp8266 LOW with pinMode of the Uno pin.

    pinMode(TO_ESP_IO0, OUTPUT); // sets the pin LOW

    pinMode(TO_ESP_IO0, INPUT); // let it to the io0 pull-up resistor


body: I have been working on water flow sensor which measures volume then i need to restrict the amount of water which disperse from depend on the user input form the keypad so how can i store the input form the keypad into a variable.

title: how to use keypad button multiple integer value input

Answers: 1

body:
When you use the keypad library, there is a command to read a key:

     myKeypad.getKey();

Store these keys in a (string) buffer, and after a certain key is pressed (e.g. #), parse the string buffer to retrieve the integer (with the c function `atoi`, see [here for a description][1]).

  [1]: https://fresh2refresh.com/c-programming/c-type-casting/c-atoi-function/


body:
I'm trying to display a scrolling number on my MAX7219 display using the LedControl library, but can only ever get the first digit (digit 0) updating. When I reference digits 1-7 the 7 segments don't light up.

This also happens even with the example sketch LCDemo7Segment. Is there an issue with my display unit perhaps?

Using an Uno board and [this][1] module. Using pin 11 for DataIn, 13 for CLK, and 12 for Load.

  [1]: https://www.jaycar.com.au/medias/sys_master/images/9285639274526/XC3714-manualMain.pdf

title: MAX7219 only displaying on first digit

Answers: 0


body:
     LiquidCrystal 1cd(12, 11, 5, 4, 3, 2);

     void setup() {
       1cd.begin(16, 2);
       1cd.print"abbu, kya, chalrelaye!");
     }

     void loop() {

     }

title: please tell me how do I fix this code down here(please tell in my easy English)

Answers: 2

body:
Variable names MUST NOT start with a digit. Only '_' and a-z are allowed!

`1cd` really should be `lcd` with an 'ell' instead of a one (1).

body:
I suggest you modify the LiquidCrystal "Hello World" sketch:

[![drop down menu used to open the sketch][1]][1]

Here is the example code:

    // include the library code:
    #include <LiquidCrystal.h>

    // initialize the library by associating any needed LCD interface pin
    // with the arduino pin number it is connected to
    const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
    LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(16, 2);
      // Print a message to the LCD.
      lcd.print("hello, world!");
    }

    void loop() {
      // set the cursor to column 0, line 1
      // (note: line 1 is the second row, since counting begins with 0):
      lcd.setCursor(0, 1);
      // print the number of seconds since reset:
      lcd.print(millis() / 1000);
    }

Good luck!

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


body:
I have a microcontroller: `ATMega328P`.
I don't have any `Arduino Uno board`.

I want to program the `ATMega328P` using my `FTDI programmer`.

But when I try to program the `ATMega328P` without `Arduino` board I always get this **error**:

`avrdude: stk500_recv(): programmer is not responding`

I've followed this [YouTube Tutorial][1] to build this.

And ended up with this diagram:

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

All the connections seems OK.

I choose the board: `"Arduino Pro or Pro Mini"` because only with this one I can choose the correct processor: `"ATMega328P (5V, 16MHz)"`

The port is correct: `"/dev/ttyUSB0"`

And as for the the programmer I've choose: `"USBasp"`, which I don't know if this is correct. I've used this `FTDI programmer` to program the `STM32 microcontroller` and the programmer was `"Serial"`, which I don't see the very same option here.

I'm lost, what am I missing up here?

BTW I've seen [this][3], [this][4] and [this][5] but couldn't get it fixed.

[![enter image description here][6]][6]

  [1]: https://www.youtube.com/watch?v=Sww1mek5rHU&t=31m39s
  [2]: https://i.stack.imgur.com/9TGcM.png
  [3]: https://arduino.stackexchange.com/questions/22191/avrdude-stk500-recv-programmer-is-not-responding
  [4]: https://arduino.stackexchange.com/questions/16732/program-an-atmega328p-and-use-it-without-arduino-board
  [5]: https://arduino.stackexchange.com/questions/29348/atmega328p-programming-with-arduino-libraries
  [6]: https://i.stack.imgur.com/Gssiz.png

title: Programming the ATMega328P without Arduino board always returns the error: avrdude: stk500_recv(): programmer is not responding

Answers: 1

body:
A new chip cannot be programmed in that manner until it has the Bootloader installed. The Bootloader starts after a reset and monitors the serial interface to see if something is attempting to download code via the serial port.

Selecting a Programmer has no effect on serial download, that only comes into play when Programming via the SPI pins SCK/MOSI/MISO/Reset/Power/Gnd.

Your "design" needs a couple more parts: 0.1uF caps between VCC and Gnd, and AVCC and Gnd.

The Cryslal and 22pF caps could also be a lot closer to the device - like right next to it.

I can't read the FTDI markings, so I can't tell if you have Rx and Tx swapped there.


body:
im trying to connect to my wifi with mit Nodemcu, i recently got a new router and since then i can't connect anymore. I use simple example sketches from esp library but it will not connect. Instead i get a lot of dots in the console. I disabled firewalls of my router, mac filter is disabled(as i tried to manually add the nodemcus mac to mac filter it said "invalid macadress" ) if intry to connect to my phones hotspot, everything is fine.but i can't connect to my home wifi, ssid and Passwort are 100% correct. My hardware is fine, i ordered a second nodemcu and it has the same problems as the old one.

Can someone help me please, i've set my entire rooms ligthing on the node mcu and now im living in the dark ...

title: Node mcu does not connect

Answers: 0


body:
I am trying to send the data from DHT sensor (temperature and humidity on 2 channels of Thingspeak cloud server) and firstly display them on Thingspeak cloud. Afterwards I will need to get those data from the cloud and use them with Python in order to make some calculations. Sensor data is sent via SIM900 GSM module.

I succeeded to send some constant value to Thingspeak by executing AT commands, one by one, which I put later in this code: https://pastebin.com/4bP6hgk7 EDIT: Here is the code:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    #include "DHT.h"

    #define DHTPIN 2
    #define DHTTYPE DHT11

    // Initialize DHT sensor for normal 16mhz Arduino
    DHT dht(DHTPIN, DHTTYPE);

    // Create global varibales to store temperature and humidity
    float t; // temperature in celcius
    float f; // temperature in fahrenheit
    float h; // humidity

    SoftwareSerial gsm(7, 8);

    void setup() {
      // put your setup code here, to run once:
      dht.begin();

      gsm.begin(9600);
      Serial.begin(9600);

      gsm.println("AT+IPR=9600");
      delay(1000);

      gsm.println("AT+CGATT=1");
      delay(1000);

      gsm.println("AT+SAPBR=1,1");
    delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
      delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=3,1,\"APN\",\"prepaidnet\"");
      delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=3,1,\"USER\",\"mts\"");
      delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=3,1,\"PWD\",\"064\"");
      delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=1,1");
      delay(1000);

      ShowSerialData();

      gsm.println("AT+SAPBR=2,1");
      delay(1000);

       ShowSerialData();

       gsm.println("AT+HTTPTERM");
      delay(1000);

       ShowSerialData();

      gsm.println("AT+HTTPINIT");
      delay(2000);

      ShowSerialData();

      gsm.println("AT+HTTPPARA=\"CID\",1");
      delay(3000);

      ShowSerialData();

    }

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

     t=readTemp();
    h=readHum();

    gsm.print("AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=Z1Q5633A4S1GHIHU&field1=26");
    //gsm.print(t);
    //gsm.println();
    delay(5000);
    //gsm.println((char)26);

    ShowSerialData();

    delay(1000);
    gsm.println("AT+HTTPPARA=\"REDIR\",1");
    delay(3000);
    gsm.println("AT+HTTPSSL=1");
    delay(3000);
    gsm.println("AT+HTTPACTION=0");  /* Start POST session */
    delay(5000);
    gsm.println("AT+HTTPREAD");
    delay(3000);
    gsm.println("AT+HTTPTERM"); /* Terminate HTTP service */
    delay(5000);
    gsm.println("AT+SAPBR=0,1");
    delay(3000);
    ShowSerialData();

    }

    float readTemp() {
      // Read temperature as Celsius
      t = dht.readTemperature();
      //Read humidity
      h = dht.readHumidity();

      // Compute temperature values in Celcius
      t = dht.computeHeatIndex(t,h,false);

      // Check if any reads failed and exit early (to try again).
      if (isnan(t)) {
        Serial.println("Failed to read temp from DHT sensor!");
        return 1;
      }

      return t;
    }

    float readHum() {
      //Read humidity
      h = dht.readHumidity();
      // Read temperature as Celsius
      t = dht.readTemperature();

      // Compute temperature values in Celcius
      t = dht.computeHeatIndex(t,h,false);

      // Check if any reads failed and exit early (to try again).
      if (isnan(h)) {
        Serial.println("Failed to read hum from DHT sensor!");
        return 1;
      }

      return h;
    }

    void ShowSerialData()
    {
      while(gsm.available()!=0)
        Serial.write(gsm.read());
        if(Serial.available()) {
        gsm.write(Serial.read());
      }
    }

The problem is that not the whole script is executed - AT+HTTPPARA command with the parameter "URL" and the URL where the data should be sent is not being executed. I have read many answers but could't find the answer for this. Could anybody help with this issue? Thanks in advance!

title: HTTP request is not being executed in Arduino script for sending sensor data to Thingspeak cloud

Answers: 0


body:
I'm trying to connect an ESP32-CAM to a 3d printer using a serial connection.
When powering the ESP from the 5V rail on the 3D printer(and using 3.3V zener diodes between tx, rx & gnd), everything works fine. The ESP expects 3.3V on the serial pins, hence the diodes.

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

[circuit diagram][2]

Common ground not shown.

Then when I try to run the ESP32 from its own 5v power supply, I cannot establish a serial connection, regardless of whether I connect the gnd from the 5v from the 3d printer with that of the ESP power supply.
In fact, the ESP doesn't function then.

Any suggestions?

PS: the ESP has its own power since it should trigger a relay to cut power to the printer.

  [1]: https://i.stack.imgur.com/DxYBK.jpg
  [2]: https://i.ibb.co/QFJXBQG/Ender3-relay-pptx-Microsoft-Power-Point-000291.jpg

title: Serial connection two devices two power supplies

Answers: 1

body:
The 3.3V zener diodes are connected backwards. The anode should be connected to ground and the cathode (banded end) to the GPIO signal. Zener diodes work in reverse bias...as you have them connected now they are forward biased and will clamp the signals to about 0.7V.

The zener diode on the line for data transmitted at 3.3V to a 5V input doesn't do any good. You need to **increase** that signal voltage to a proper 5V logic level. The best thing to do would be to get rid of the zener diodes altogether and use a proper logic level converter.

Also, you really should have resistors between GPIO output pins and the zener diodes, to limit the current through the zeners when the GPIO pin is at 5V.


body:
I am in the process of implementing power down alerting system suing Arduino UNO and ZMPT101B Single phase relay.

My code as follows,

    #include <Filters.h> //Easy library to do the calculations

    float testFrequency = 50;                     // test signal frequency (Hz)
    float windowLength = 40.0/testFrequency;     // how long to average the signal, for statistist

    int Sensor = 0; //Sensor analog input, here it's A0

    float intercept = -0.04; // to be adjusted based on calibration testing
    float slope = 0.0405; // to be adjusted based on calibration testing
    float current_Volts; // Voltage

    unsigned long printPeriod = 1000; //Refresh rate
    unsigned long previousMillis = 0;

    void setup() {
        Serial.begin( 9600 );    // start the serial port
    }

    void loop() {

        RunningStatistics inputStats;                //Easy life lines, actual calculation of the RMS requires a load of coding
        inputStats.setWindowSecs( windowLength );

        while( true ) {
            Sensor = analogRead(A0);  // read the analog in value:
            inputStats.input(Sensor);  // log to Stats function

            if((unsigned long)(millis() - previousMillis) >= printPeriod) {
                previousMillis = millis();   // update time every second

                Serial.print( "\n" );

                current_Volts = intercept + slope * inputStats.sigma(); //Calibartions for offset and amplitude
                current_Volts= current_Volts*(40.3231);                //Further calibrations for the amplitude

                Serial.print( "\tVoltage: " );
                Serial.print( current_Volts ); //Calculation and Value display is done the rest is if you're using an OLED display

                if (current_Volts <229) {
                    test_loop();
                }
            }
        }
    }

    void test_loop(){
        Serial.print( "Warning!! Server Room Power Down" );
        delay(1000);
    }

I am getting the correct voltage reading. When power down it says power down. But when power got up, it still shows power down with older reading. I think the reason for this because my code unable to stop the loop. And if I remove the delay (1000) in test_loop function it works, But my intention to use this sms alerting system and for that I need this delay to stop unnecessary alerts.

My code for SMS Alerting,

    Serial.print( "\tVoltage: " );
    Serial.print( current_Volts ); //Calculation and Value display is done the rest is if you're using an OLED display

    if (current_Volts <229) {
        SendMessage();
    }

    void test_loop() {
        mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
        delay(1000);  // Delay of 1000 milli seconds or 1 second
        mySerial.println("AT+CMGS=\"xxxxxxxxx\"\r"); // Replace x with mobile number
        delay(1000);
        mySerial.println("Warning!! Server Room Power Down");
        delay(100);
        mySerial.println((char)26);// ASCII code of CTRL+Z
        delay(150000);
        mySerial.println("AT+CMGD=2");
    }

This code works for the very first outage but after power up also it send power down. First part of serial priniting in test_loop code of Serial.print is used for debugging.

title: Monitoring Power Down Using Arduino UNO and ZMPT101B

Answers: 1

body:
Got a answer for the issue,

Attaching code for anyone interested.

```
/*
   Design by Vinod Amarathunga 26.08.2018
   FSSG R&D Team
*/

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>
#define ONE_WIRE_BUS 2
SoftwareSerial mySerial(11, 10); //SIM800L Rx Tx
char msg;
String textMessage;

bool D7_alarmSent = false;
bool Temp_alarmSent = false;

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}

void PowerSMS()
{
  Serial.println("Warning!! Server Room Power Down");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No1\"\r");
  delay(1000);
  mySerial.println("Warning!! Server Room Power Down");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No2\"\r");
  delay(1000);
  mySerial.println("Warning!! Server Room Power Down");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No3\"\r");
  delay(1000);
  mySerial.println("Warning!! Server Room Power Down");
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

}

void SendMessage()
{

  Serial.println("Warning!! Server Room Temperature is Critical");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No1\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("Warning!! Server Room Temperature is Critical");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No2\"\r");
  delay(1000);
  mySerial.println("Warning!! Server Room Temperature is Critical");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No3\"\r");
  delay(1000);
  mySerial.println("Warning!! Server Room Temperature is Critical");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  mySerial.println("AT+CMGD=2");

}

void loop()
{
  sensors.requestTemperatures(); // Send the command to get temperature readings
  delay(1000);
  Serial.println(String("Temp Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  Serial.println(String("Voltage Digital: ") + digitalRead(7));
  Serial.println(Temp_alarmSent ? "True" : "False" );
  Serial.println(D7_alarmSent ? "True" : "False" );
  Serial.println("***********");
  ReceiveMessage();

  if (digitalRead(7) == 1 || sensors.getTempCByIndex(0) > 29 || D7_alarmSent == true || Temp_alarmSent == true ) {
    if (digitalRead(7) == 1 ) {
      if (!D7_alarmSent) {
        D7_alarmSent = true;
        PowerSMS();
      }

    }

    else if (sensors.getTempCByIndex(0) > 29 ) {
      if (!Temp_alarmSent) {
        Temp_alarmSent = true;
        SendMessage();
      }

    }

    else {

      if (D7_alarmSent){                  //alarmSent == true means that previous state was "Power Down"
          SendMessage_After_Power_Down();          //Send message
          D7_alarmSent = false;
          Temp_alarmSent = false;             //Reset alarmstate
        }

    }
  }

}

void SendMessage_Normal()
{
  Serial.println("Temperature and Power is OK");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No1\"\r");
  delay(1000);
  mySerial.println("Temperature and Power is OK");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No2\"\r");
  delay(1000);
  mySerial.println("Temperature and Power is OK");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No3\"\r");
  delay(1000);
  mySerial.println("Temperature and Power is OK");
  mySerial.println(String("Reading : ") + sensors.getTempCByIndex(0) + String("*C"));
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

}
void SendMessage_After_Power_Down(){

  Serial.println("Power Back Online");

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No1"\r");
  delay(1000);
  mySerial.println("Power Back Online");
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No2\"\r");
  delay(1000);
  mySerial.println("Power Back Online");
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"No3\"\r");
  delay(1000);
  mySerial.println("Power Back Online");
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

  }

void ReceiveMessage()
{
  if (mySerial.available() > 0)
  {
    mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
    delay(1000);
    textMessage = mySerial.readString();
    Serial.print(textMessage);
    delay(10);
  }
  if (textMessage.indexOf("Status") >= 0) {
    SendMessage_Normal();
    mySerial.println("AT+CMGD=2");

  }
}
```


body:
I trying to use a new sensor the KMX63 with a Arduino Uno board, my sensor is on a evaluation board made by kionix.
For the connexion il linked as follows:

| Pin Uno | Pin evaluation board |
| A5 | 5 |
| A4 | 7 |
| 3.3 | 1 |
| GND | 8 |

Here the schematic of the evaluation board:
[![eval board schematic][1]][1]

I found a technical note from the constructor that advice to do some steps after the power up of the sensor to insure it's well functioning I wrote a code following it:
<!-- language-all: lang-cpp -->
~~~~~
#include <Wire.h>
#include "KMX62.h"

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

  Serial.println(F("Starting"));

  byte error=7;
  byte id=0;
  byte command=0;
  delay(60);
  Wire.beginTransmission(KMX62_I2C_ADD_2);
  Wire.write(0x7F);
  Serial.println(F("Write 0x7F"));
  Wire.write(0x00);
  Serial.println(F("Write 0x00"));
  delay(100);
  error=Wire.endTransmission();
  Serial.print(F("retour 1 : "));
  Serial.println(error);
  if( error==0 ){
    Wire.beginTransmission(KMX62_I2C_ADD_2);
    Wire.write(CNTL2);
    Wire.write(0x00);
    error=Wire.endTransmission();
    if( error==0 ){
      Wire.beginTransmission(KMX62_I2C_ADD_2);
      Wire.write(CNTL1);
      Wire.write(0x80);
      error=Wire.endTransmission();
      if(error==0){
        delay(5);
        Wire.beginTransmission(KMX62_I2C_ADD_2);
        Wire.write(WHO_AM_I);
        Wire.endTransmission(false);
        Wire.requestFrom(KMX62_I2C_ADD_2,1);
        id=Wire.read();
        error=Wire.endTransmission();
        if(id==0x18||id==0x2D){
          Wire.beginTransmission(KMX62_I2C_ADD_2);
          Wire.write(COTR);
          Wire.endTransmission(false);
          Wire.requestFrom(KMX62_I2C_ADD_2,1);
          command=Wire.read();
          error=Wire.endTransmission();
          if(command==0x55){
            Serial.println(F("device ok"));
          }else{
            Serial.println(F("Issue with the sensor step e : need to be rebooted"));
          }
        }else{
          Serial.println(F("Issue with the sensor step d id=wrong : need to be rebooted"));
        }
      }else{
        if(error==2||error==3){
        Serial.println(F("Issue with the sensor step c : need to be rebooted"));
        }
      }
    }else{
      if(error==2||error==3){
        Serial.println(F("Issue with the sensor step b : need to be rebooted"));
      }
    }
  }
}

void loop(){

}
~~~~~~

but i have an issue the steps , the program seem to freeze when i try to write into the register 0x7F.
I don't get any trace that i should have after the wire.endtransmission().
Here the trace i obtain :
````
09:56:35.477 -> Starting
09:56:35.511 -> Write 0x7F
09:56:35.511 -> Write 0x00

``````

i have use the I2C scanner to check if the sensor appear, i had to modify the scanner to add a delay before Wire.beginTransmission and the Wire.endTransmission to avoid the scanner to be freeze too at the first address tried. After the modification i did saw the sensor at the address it was mean to be.
here the trace for the I2C scanner :
````
Scanning...
I2C device found at address 0x0F  !
done
````

Anyone have an idea of why i can't write anything to my sensor without making my program freeze indefinitely each time ?

PS : After the advice of chrisl i rerunned all my programs on a arduino mini pro on 3.3V / 8Mhz and got the same result.

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

title: Communication with sensor KMX63 in I2C

Answers: 1

body: I finally found where the problem was, i had made a error on the reading of the schematic of the evaluation board. I thought that the pin J1-9 was already wired in intern but it was wrong. I wired it to the VCC output of my board and it work perfectly now.


body:
I have a arduino pro micro that runs on 5v.
I also have a Max4466 that needs 3.3v, however the pro micro doesn't seem to have a 3.3v VCC.
Is there any way to attach the max4466 to the Board?

title: 3.3v pin on a 5v Pro Micro?

Answers: 1

body:
You need to add an external 3.3V voltage regulator. You can get these quite cheap on eBay (etc) as a module - some even come in a breadboard friendly format.

Power it from the 5V from the Arduino, then power your MAX4466.

However, the MAX4466 can run at up to 5.5V, so I fail to see why you think you need 3.3V.


body:
Am trying to setup logic level converter with arduino for eps8266 WiFi module. Am using this logic level converter but it’s not working not sure what am doing am not getting any output.

My circuit

    Red wire : 3.3v power source
    Orange wire : 5v power source
    Blue wire : ground.
    Yellow wire : arduino TX1 on B2
    White wire : output on A2

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

**Multi meter it red wire : 3.3 v showing on display**

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

**Multi meter it orange wire : 4.68 v showing on display**

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

**Multi meter it yellow wire : 4.36 v showing on display**

[![enter image description here][4]][4]

**Multi meter it white wire : no voltage showing on display ??? **

[![enter image description here][5]][5]

Update : have set OE pin to enable and swapped red and orange. Still no output for yellow wire

[![enter image description here][6]][6]

  [1]: https://i.stack.imgur.com/8vjMw.jpg
  [2]: https://i.stack.imgur.com/DlfgW.jpg
  [3]: https://i.stack.imgur.com/xftbT.jpg
  [4]: https://i.stack.imgur.com/W4cFA.jpg
  [5]: https://i.stack.imgur.com/ysBH7.jpg
  [6]: https://i.stack.imgur.com/KASwO.jpg

title: TSX0108 logic level converter not working

Answers: 1

body: When the output-enable(OE) input is low, all outputs are placed in the high-impedance (Hi-Z) state.  You must connect the OE pin to logic high to enable the outputs.


body:
I am looking for a way to increment a variable by one each time a button is pressed. Current approach is the following :

        if (redButton.isPressed())
        {
            a++;
            delay(100);
        }

`isPressed()` just return true if the pin state is HIGH.

`delay(100)` is used to compensate the small amount of time the button is being pressed. Otherwise `a` would be incremented multiple times in a single press. But it's blocking behavior, my program can't do anything else during that delay.

In short I'm looking to add a method in my Button class to detect if the button "has just been released".

title: Non-blocking incrementation with single button pressure

Answers: 1

body:
In your approach a button press will be detected every 100ms when you just keep the button pressed. So you have to set a flag when the button is pressed. When the button is **not** pressed while your flag is set, that's the event you're looking for. In this way you can detect both a button press and a release respectively.
As @JRobert mentioned, there still has to be an amount of time between two calls to such a routine to provide some button debouncing.

    bool pressed_flag=false;
    bool button_timestamp=millis();
    uint16_t button_period=100;

    if(millis()-button_timestamp>button_period){
      button_timestamp=millis();
      if(redButton.isPressed() && !pressed_flag){
        // button has just been pressed
        // you can do sth. here
        pressed_flag=true;
      }
      else if(!redButton.isPressed() && pressed_flag){
        // button has just been released
        // you can do sth. here
        pressed_flag=false;
      }
    }


body:
I'm setting webserver with toggle led. I want to create global webserver. I`m mean hat use server with global ip. For it I must use port too. global ip/local ip:port.
I want to create on 5000 port. I'm used for ESP-01f and connect it arduino. Communicating by SoftwareSerial. I used AT+CIPSTA for static ip. When I used AT+CIPSERVER=1,5000 it worked. But when I connect to it, it works, but in second connection it doesn't want to connect itor when I use digitalWrite it doesn't connect to this server. How can I solute this problem?

code:

```cpp

#include <SoftwareSerial.h>

SoftwareSerial softSerial(10, 11);
String ssid = "ssid";
String ip = "staticip";
String gateway="gateway";
String sub="submask;
String password = "password";
String _response = "";
#define DEBUG true
void setup()
{

  Serial.begin(115200);

pinMode(2,OUTPUT);

  softSerial.begin(115200);
  connectWifi();
}

void connectWifi() {

  do {

    sendData("AT+RESTORE\r\n", 5000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT\r\n", 2000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CWMODE=1\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"\r\n", 5000, DEBUG);
  } while (softSerial.find("OK"));
   do {

    sendData("AT+CIPSTA=\"" + ip + "\",\"" + gateway +"\",\"" + sub + "\"\r\n", 2000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIFSR\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIPMUX=1\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));
  do {

    sendData("AT+CIPSERVER=1,5000\r\n", 1000, DEBUG);
  } while (softSerial.find("OK"));

}

String sendData(String command, const int timeout, boolean debug)
{

  String response = "";

  softSerial.print(command);        long int time = millis();
  while ((time + timeout) > millis())
  {
    while (softSerial.available())
    {

      char c = softSerial.read();
      response += c;
    }
  }

  if (debug)
  {
    Serial.print(response);
  }

  return response;
}

void loop()
{

if(softSerial.available()){
  if(softSerial.find("+IPD,"){
   int connectionId = softSerial.read()-48;
softSerial.find("pin/");
int pin = softSerial.read()-48;

String htmlCode = "<label>"+String(pin)+"</label>";
digitalWrite(pin,HIGH);
sendData("AT+CIPSEND="+String(connectionId)+","+htmlCode.length()+"\r\n",1000,DEBUG);
sendData(htmlCode+"\r\n",1000,DEBUG);

sendData("AT+CIPCLOSE="+String(connectionId),3000,DEBUG);

  }
}
}

```

title: Creating WebServer with 5000 port with AT command(ESP-01f)

Answers: 0


body:
I am making an LED controller that reads instructions from a text file on my computer. I need to get the arduino to read this text file line by line and put each line into the appropriate variables. I'm using a sparkfun pro micro which is a knock off arduino pro micro. The pro micro is connected via USB

I've seen people use the SD library, but I don't know if this will work for my situation because I am reading directly from the computer and not an SD card. Is this the correct approach, or is there an additional/alternate library that I need to use?

title: How to read a text file line by line

Answers: 2

body:
What you can do is:

- Read character by character and copy it to a temporary buffer of the maximum length of one line.
- When you parsed an end of line symbol, you start parsing the (complete) line in the buffer.
- In this line parsing (preferably a separate function), you parse the line, using string to type conversion functions, like `atoi` (string to an inter) etc. Also you can use the C function `strtok` to split the string based on a symbol (e.g. comma).
- After parsing the line, clear the buffer (you already processed it), and continue filling the buffer again until it is full.
- Don't forget to check for end of file.

body:
The Arduino cannot read data on the PC.

Instead the PC has to send the data to the Arduino, and the Arduino has to parse (interpret) that data.

You need two things:

1. A piece of software running on the PC that sends the file contents to the Arduino over serial
2. Software on the Arduino that accepts the stream of data coming in over the serial port and does something with it.

It is no different to handling commands that are manually typed by someone using the Serial Monitor - it's just they tend to come in a lot faster when being sent by the PC from a file.


body:
I am trying to create a program to operate my arduino based LED controller. I'm pretty sure that my C# program is outputting to serial port correctly as I double checked the output in Debug.WriteLine(). The program is supposed to send information to the arduino in the following format (newlines included):

```
mode
number of colors
blend speed
beats until color change
Red   <---
Green <---
Blue  <---
Brightness <---
```
the last 4 are the only ones that matter for now as I am trying to get the LED's to show up one solid color first before worrying about other modes or patterns. The debug writeline loop output of my last test looks like this
```
1
1
0
1
209
255
255
219
```

This should be translating to the relevant arduino variables the same way but instead, I only get white light that seems to randomly brighten or darken when I mess with the color/brightness sliders

My code for the arduino is below. I am very new to this so it's probably not even close to right. getData() at the bottom is the function that most likely is the culprit, but I'll put the rest in just in case:

```
#include <SPI.h>
#include <Adafruit_DotStar.h>

#define NUMPIXELS 60

Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);

// Variables
int mode;
int numColors;
int fadeSpeed;
int BBCC;
int R;
int G;
int B;
int Bright;
String buff;

void setup() {
  strip.begin();
  strip.show();
  //Serial.begin(9600);
}

void loop() {
  getData();

  if (mode == 1)
  {
    //strip.setPixelColor(0, R, G, B);
    strip.setBrightness(Bright);
    strip.show();
  }
}

void getData()
{
 // if (Serial.available() > 0)
 // {
    buff = Serial.read();
    int result = buff.toInt();
   mode = result;
   if (mode != -1)
   {
    buff = Serial.read();
    int result = buff.toInt();
    numColors = result;
    buff = Serial.read();
    result = buff.toInt();
    fadeSpeed = result;
    buff = Serial.read();
    result = buff.toInt();
    BBCC = result;
    buff = Serial.read();
    result = buff.toInt();
    R = result;
    buff = Serial.read();
    result = buff.toInt();
    G = result;
    buff = Serial.read();
    result = buff.toInt();
    B = result;
    buff = Serial.read();
    result = buff.toInt();
    Bright = result;//Serial.read();
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
   else
   {
    strip.setPixelColor(0, R, 0, 0);
    //strip.setBrightness(Bright);
    strip.show();
   }
//  }
}
```

title: Arduino is incorrectly reading serial input from C# program

Answers: 2

body:
Your Serial receive code is not correct in some ways:

1. You should only read from Serial, if there is really something to read. For the first read, that is not the problem, since you checked against the return value being -1 (which is the return code for "there is no new data in the buffer). But after that, you read without ever checking, if there is something to read. You need to understand, that the data is really send serially. The bytes come in one after another and there is no concept as messages on the Serial interface (which is actually called UART in non-Arduino environments). More over, there might be small pauses somewhere in the transmission, since you cannot foresee, when exactly the PC will send the data (the PC has a bunch of other tasks to do, too). So it might be, that you have received one byte, which will lead you into the `if` statement, but the rest of the data will arrive later. All data is then read as -1, since there is no data in the buffer.

    You have to check, if there is actually data to read, before reading. This can be done with `Serial.available()`. It will return the number of new data bytes in the buffer. For example, if you want to read 8 bytes, you should wait, until at least 8 bytes are inside the buffer by using `if(Serial.available >= 8)`.

2. You are sending the data from the PC as ASCII encoded text. That means, that every number above 9 consists of multiple data bytes. The 4 values, that you are interested in, are all over 200, which means, that you need to read 3 bytes to get them. But you only call `Serial.read()` once for every value. That will give you the first digit, which is a 2 for all values in the shown data. More over, since you only read 1 byte, where there is the whole number (which may be multiple bytes) plus 1 or 2 bytes for the new line (depending on the chosen line ending `\n` or "\n\r"), The whole reading gets misaligned to the data structure. Now the read data (if there is any) is also dependent on how much data was send for the values before.

    Keep in mind, that with ASCII encoded text, you may need multiple `Serial.read()` calls to actually read a full number. I will describe the way to go here in the next point.

3. As I already mentioned above, there is no message protocol on the Serial interface. Lost data would lead to misalignment and thus garbled data. But you can impose an own protocol onto the Serial stream of data. It is a good practice, to first receive a full message (maybe with multiple data values inside it) and then process it. For that I would suggest a new data structure

        mode|number of colors|blend speed|beats until color change|Red|Green|Blue|Brightness\n

    The new line is here realized only with a newline character (`\n`). The values are separated with a vertical dash. You should put an `if(Serial.available()>0)` into your loop function. Then inside that if statement, you read one character and add it to a buffer. If you read the `\n` character, you start to process the buffer. You can then convert one value after another from the buffer and save them into variables. After that, you clear the buffer. You can see this style in the `SerialEvent` example, that comes with the Arduino IDE. You should also read Majenko's blog article about [reading the Serial interface on the Arduino][1].

---

That said, you should be cautious with using `String` object on the Arduino. Sure, `String`s are convenient, but they dynamically allocate the needed memory during the runtime. On microcontrollers, which normally have very limited RAM memory, that can lead to heap fragmentation (heap is the memory area for dynamic memory allocation). When using `String` objects, the underlying buffer get's often recreated. As buffers get allocated and deleted later, that can lead to small memory areas, which are unused, but to small to actually be used by the buffer. You can fill up your RAM very fast with that.

It is better to not use `String`, but directly a `char` array with a fixed length. Majenko also wrote an article about the `String` problem: [The Evils of Arduino Strings][2]

  [1]: https://majenko.co.uk/blog/reading-serial-arduino
  [2]: https://majenko.co.uk/blog/evils-arduino-strings

body:
First off this is **NOT** how to read from the serial USART!

    buff = Serial.read();
    int result = buff.toInt();

`Serail.read` returns a single byte, you are treating it as a string, then trying to parse it; you will never see anything other than 0-9 if your lucky (its very unlikely that buff contains a valid string, chances are it will just keep going till it finds a \0, and return some random number, or just fail.

EDIT: It seems I was mistaken, the 'read()' returns an int, nominally only a byte is returned, but a 16-bit -1 (0xffff) is returned for an error; the documentation could be clearer here.

<s>Second the arduino serial library has a huge flaw, -1 is used as a failure to read, but -1 (i.e. 255) could be a valid piece of data, this makes the return value useless, as you don't know if 255 is the correct value, or an error. The only way around this is with `Serial.available` so you must use this to control your code or you won't know whats going on.</s>

Finally, you can write binary data in c# with `.Write(byte[] ...)` and then read it in binary back, so you don't have to parse it.


body:
So I currently have this for arduino.ino:

    Serial.println(Variable1);

that does this in Unity:

    string variable1 = stream.ReadLine();
    float x = float.Parse(variable1);
 transform.Rotate (0, -x/1000, 0);

My question is; How would I send 3 variables from the Arduino to Unity so I can put each value into the `transform.Rotate` function at once?

For example in pseudocode:

    Arduino.ino
    send(Variable1, Variable2, Variable3);

    Unity
    transform.Rotate(Variable1,Variable2,Variable3);

I hope this makes sense.
Thank you.

title: How do I send multiple variables via stream to Unity?

Answers: 1

body:
What you need to do is define a communication scheme/protocol. You appear to be using the Serial UART via USB.

Your first example has a simple scheme its simply the ASCII representation of the variable followed by a newline. i.e. :

    float x = 123.45;
    Serial.println(x);

this simply outputs

    "123.45\n"

you could continue this pattern

    float x, y, z,
    ... // assume x, y and z have values in them
    Serial.print(x);
    Serial.print(' ');
    Serial.print(y);
    Serial.print(' ');
    Serial.println(z);

this outputs something like:

    "123.43 23.34, 42.24\n"

then your receiving code will do do something like

    string line = stream.ReadLine();
    string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries)
    float x = float.Parse(parts[0]);
    float y = float.Parse(parts[1]);
    float z = float.Parse(parts[2]);

but this is very inefficient, since the arduino needs to convert the float to an ASCII string, then transmit that over the serial port, where its read on the other side, then parsed back into a float. One doesn't need to do this, you can do in binary, it won't be human readable, but it will use much less transmission space.

    float x, y, z; // assume these are valid
    Serial.write(&x, sizeof(float));
    Serial.write(&y, sizeof(float));
    Serial.write(&z, sizeof(float));
    // n.b. one should write an end of message here or something else to frame the data

and on the other side

    byte[] data = new byte[12];
    stream.Read(data, 0, 12);

    float x = BitConverter.ToSingle(data, 0);
    float y = BitConverter.ToSingle(data, 4);
    float z = BitConverter.ToSingle(data, 8);

You will generally also want some way to frame the data, so you might want to start with a simple message header, i.e.:

    struct head
    {
      int length;
      int code;
    };

and you write it like:

    head header; //assume this is valid
    Serial.write(&header, sizeof(header));

then you can write you message.

You might also want to implement some sort of checksum, so you can verify that you got the data correctly.

You can create multiple message structures this way, i.e.

    struct vect3d
    {
      head header;
      float x;
      float y;
      float z;
    }

just fill and send

    vect3d v3;
    v3.head.length = sizeof(vect3d); // one could subtract sizeof(head) off so the reader can always read the first 8 bytes and read the rest of the message from there
    v3.head.code = VECT3D; // assume this is defined somewhere
    v3.x = 123.5;
    v3.y = 23.4;
    v3.z = 42.24;

    Serial.write(&v3, sizeof(v3));

On the other side one would read in the first 8 bytes, then read in the rest of the message based on the length, and parse it based on the code.


body: My arduino pro micro started behaving weird. I noticed it had crashed with very simple code on it (basically just two lines of fastled code followed by a delay. Then it didn't appear as a USB device on my macbook anymore. I reset it (pulling the rst pin to gnd) and that then allowed me to upload smaller sketches but not bigger ones. The smaller sketch only works for a short period of time. then the arduino just stalls. (Serial output also stops). Any idea what i can do? Or do i just have to toss the board and get myself a new one?

title: Arduino pro micro crashing

Answers: 0


body:
It gives reliable readings for a couple of seconds and then it becomes unreliable.

My arduino code is this:

    #include<Wire.h>
    const int MPU6050_addr=0x68;
    int16_t AccX,AccY,AccZ,Temp,GyroX,GyroY,GyroZ;
    void setup(){
      Wire.begin();
      Wire.beginTransmission(MPU6050_addr);
      Wire.write(0x6B);
      Wire.write(0);
      Wire.endTransmission(true);
      Serial.begin(9600);
    }
    void sendVector(float x, float y, float z) {
      Serial.print(x, 4);
      Serial.print("|");
      Serial.print(y, 4);
      Serial.print("|");
      Serial.println(z, 4);
    }

    void loop(){
      Wire.beginTransmission(MPU6050_addr);
      Wire.write(0x3B);
      Wire.endTransmission(false);
      Wire.requestFrom(MPU6050_addr,14,true);
      AccX=Wire.read()<<8|Wire.read();
      AccY=Wire.read()<<8|Wire.read();
      AccZ=Wire.read()<<8|Wire.read();
      Temp=Wire.read()<<8|Wire.read();
      GyroX=Wire.read()<<8|Wire.read();
      GyroY=Wire.read()<<8|Wire.read();
      GyroZ=Wire.read()<<8|Wire.read();
      //Serial.print(AccX);
      //Serial.print(AccY);
      //Serial.print(AccZ);
      //Serial.print(" || Temp = "); Serial.print(Temp/340.00+36.53);
      //Serial.print(" || GyroX = ");
      //Serial.println(GyroX);
      //Serial.print(" || GyroY = ");
      //Serial.println(GyroY);
      //Serial.print(" || GyroZ = ");
      //Serial.println(GyroZ);
      sendVector(GyroX, GyroY, GyroZ);
      delay(100);
    }

The above sends data to unity which controls an object. The object works with the gyroscope and then due to the random readings it rotates quickly and randomly.

title: MPU6050 Gyroscope does not give reliable readings

Answers: 1

body:
I don't think you have given enough information to help you debug this, but i can try to give some advice:

First verify that the chip works correctly
=

Use the arduino plot monitor, and a sample program, to see the behavior of the chip and values over time; make sure its not a problem with the chip

Second verify that you are interpreting the values correctly
=

The MPU6050 outputs 16-bit data, but doesn't have 16-bit resolution, this means that the lower bits of the data are random, meaningless noise, and should be ignored/discarded.

If you are assuming that all 16 bits contain valid data, and your code is sensitive enough to be affected by those lower bits, then you will see unstable random data.

Third consider other (possible) obstacles
=

Try increasing the serial BAUD rate, you may be taking too much time and causing problems that way.

Maybe you are getting out of sync while reading from the chip, if there is additional data being sent, you could could build up a backlog in the buffer, and start interpreting messages incorrectly because you are reading part of one and part of another. Try using a library to talk to the chip, one that other people have used and is known to work; this could remove bugs you are blind to, or bugs that everyone will run into, but they have already been fixed in the library!


body:
So I'm Setting up webserver with esp-01f+arduino uno. I'm using WiFiEsp library.
I want to toggle led on. Pin will be given in GET request by url.
Example:
host.com/?ledpin=9
How can I parse it, then get 9 number?

Code:
```cpp

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

char ssid[] = "Twim";            // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;

int ledStatus = LOW;

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(9600);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
  printWifiStatus();

  // start the web server on port 80
  server.begin();
}

void loop()
{
  WiFiEspClient client = server.available();  // listen for incoming clients

  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer

        // printing the stream to the serial monitor will slow down
        // the receiving of data from the ESP filling the serial buffer
        //Serial.write(c);

        // you got two newline characters in a row
        // that's the end of the HTTP request, so send a response
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /H")) {
          Serial.println("Turn led ON");
          ledStatus = HIGH;
          digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /L")) {
          Serial.println("Turn led OFF");
          ledStatus = LOW;
          digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
        }
      }
    }

    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}

void sendHttpResponse(WiFiEspClient client)
{
  // 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();

  // the content of the HTTP response follows the header:
  client.print("The LED is ");
  client.print(ledStatus);
  client.println("<br>");
  client.println("<br>");

  client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
  client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");

  // The HTTP response ends with another blank line:
  client.println();
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
  Serial.println();
}
```
Details gives me only this:
```
GET /favicon.ico HTTP/1.1
Host: 192.168.0.165:5000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://192.168.0.165:5000/H
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7

```

title: Parsing HTML GET request with params with WiFiEsp

Answers: 1

body: The answer is to use indexOf and substring functions of response String


body:
I am trying to send an HTTP request from from an Arduino UNO through an ESP-01 connected by Serial.
Communication with the ESP and connection to the AP work fine. But when i try to send an HTTP request to a server, it fails with a strange response from the ESP:

[![Serial output][1]][1]

What are those strange characters coming from the ESP ?

(Note that other characters are mistaken as well, like the "http://xxx.col" instead of "http://xxx.com")
Here is the code I am using:
<!-- language-all: lang-cpp -->

    #include <SoftwareSerial.h>
    #define RX 10
    #define TX 11
    String AP = "xxx";
    String PASS = "xxx";
    String HOST = "\"http://xxx.com\"";
    String PORT = "80";
    String tcp = "\"TCP\"";
    String field = "field1";
    int countTrueCommand;
    int countTimeCommand;
    boolean found = false;
    int valSensor = 1;
    SoftwareSerial esp8266(RX,TX);

    void setup() {
      Serial.begin(115200);
      esp8266.begin(115200);
      sendCommand("AT",5,"OK");
      sendCommand("AT+CWMODE=1",5,"OK");
      sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
    }
    void loop() {
     sendCommand("AT+CIPMUX=1",5,"OK");
     //String connection = "AT+CIPSTART="+ tcp +"," + remoteip + "," + portnum + "\r\n");

     String getData = "GET battery/add.php?RAWVOLT=99&VOLT=99&RAWCURR=99 HTTP/1.0\r\n"; //this is mockup data for testing purpose
     getData += "Host: xxx.000webhostapp.com\r\n"; // add the required header
     getData += "\r\n";

     sendData("AT+CIPSTART="+ tcp +"," + HOST + "," + PORT + "\r\n",150000,true);
     sendData("AT+CIPSEND=0," +String(getData.length()+4),4000,true);

     //sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
     esp8266.println(getData);delay(1500);countTrueCommand++;
     sendCommand("AT+CIPCLOSE=0",5,"OK");
    }

     void sendCommand(String command, int maxTime, char readReplay[]) {
       ***similar to sendData below***
     }

     String sendData(String command, const int timeout, boolean debug)
    {
        String response = ""; // ESP8266 sendData String
        esp8266.print(command); // send the read character to the esp8266

        long int time = millis();

        while( (time+timeout) > millis())
        {
          while(esp8266.available())
          {
            // The esp has data so display its output to the serial window
            char c = esp8266.read(); // read the next character.
            response+=c;
          }
        }

        if(debug)
        {
          Serial.print(response);
        }
        return response;
    }

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

title: Send HTTP request from Arduino UNO+ESP8266

Answers: 0


body:
I'm trying controll the power of attity13a and turn off/turn on the led.

I'm going to goals:

After to click on the button0
led will blicking 5 second nad then the attiny13a going to sleep.

After to click on the button1 then wake attiny13a up and then led will shane.

The button0 to sleep and blink the led.
the button1 to wake up and turn on the led.

Could you explain what is wrong in this sketch, please?
thank you for your answers.

**code:**
```c
    #define F_CPU  1200000UL
    #define LED     PB2 // PB2
    #define BUTTON1 PB1 // PCINT1
    #define BUTTON0 PB0 // PCINT0

    #define HIGH    1
    #define LOW    0
    #define INPUT    0
    #define OUTPUT    1
    #define INPUT_PULLUP 2
    #define FALSE    0
    #define TRUE    1
    #define _BV(bit)  (1 << (bit))

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <avr/sleep.h>
    #include <util/delay.h>

    void pinMode(uint8_t pin, uint8_t mode)
    {
     if(mode == OUTPUT) // Pin as output
      DDRB |= _BV(pin);
     else // Pin as input or input pullup
     {
      DDRB &= ~_BV(pin); // Set pin as input
      if(mode == INPUT_PULLUP)
       PORTB |= _BV(pin); // Enable pullup resistors
     }
    }

    void digitalWrite(uint8_t pin, uint8_t val)
    {
      if(val)
        PORTB |= _BV(pin);  // Set pin high
      else
        PORTB &= ~_BV(pin); // Set pin low
    }

    uint8_t digitalRead(uint8_t pin)
    {
      return !!(PINB & _BV(pin));
    }

    // go to sleep
    ISR(PCINT0_vect)
    {
       if(digitalRead(BUTTON0)){
         int i=0;
      while(i<10){
       blink();i=i+1;
      }
      set_sleep_mode(SLEEP_MODE_PWR_DOWN);
      sleep_enable();
      sleep_cpu();
     }
    }

    //wake up
    ISR(PCINT1_vect){
       if(digitalRead(BUTTON1)){
     digitalWrite(LED, HIGH);
       }
    }

    void blink(){
     digitalWrite(LED, LOW);
     _delay_ms(500);
     digitalWrite(LED, HIGH);
        _delay_ms(500);
    }

    int main(void)
    {
     pinMode(BUTTON0, INPUT_PULLUP);
     pinMode(BUTTON1, INPUT_PULLUP);

     pinMode(LED, OUTPUT);
     digitalWrite(LED, LOW);

     // Sets the Pin change interrupt mask PB0, PB1
     PCMSK |= _BV(PCINT0)|_BV(PCINT1);

     //Enables Interrupts globally after setup
     //sei();
     SREG |= _BV(SREG_I);

     while(TRUE){}
    }
```

title: How to control the power of attiny13a via pin change interrupt?

Answers: 1

body:
```c
#define F_CPU   1200000UL

#define LED     PB2 // PB2
#define BUTTON1 PB1 // INT0
#define BUTTON0 PB0 // PCINT0

#define HIGH         1
#define LOW          0
#define INPUT        0
#define OUTPUT       1
#define INPUT_PULLUP 2
#define FALSE        0
#define TRUE         1
#define _BV(bit)    (1 << (bit))

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>

void pinMode(uint8_t pin, uint8_t mode){
 if(mode == OUTPUT) // Pin as output
  DDRB |= _BV(pin);
 else // Pin as input or input pullup
 {
  DDRB &= ~_BV(pin); // Set pin as input
  if(mode == INPUT_PULLUP)
   PORTB |= _BV(pin); // Enable pullup resistors
 }
}

void digitalWrite(uint8_t pin, uint8_t val){
  if(val)
 PORTB |= _BV(pin);  // Set pin high
  else
 PORTB &= ~_BV(pin); // Set pin low
}

uint8_t digitalRead(uint8_t pin){
  return !!(PINB & _BV(pin));
}

//wake up
ISR(INT0_vect){
   sleep_disable();
   //cli(); // Turn off global interrupts
   digitalWrite(LED, HIGH);
}

void blink(){
 digitalWrite(LED, LOW);
 _delay_ms(1000);
 digitalWrite(LED, HIGH);
 _delay_ms(1000);
}

// go to sleep
ISR(PCINT0_vect)
{
   //cli(); // Turn off global interrupts
   if(!digitalRead(BUTTON0)){
  cli(); // Turn off global interrupts

  blink();

  digitalWrite(LED, LOW);

  sei(); // Turn on global interrupts
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
 }
}

int main(void)
{
 //enabled external interrupt
 MCUCR=0;
 //MCUCR=0b00000000;
 GIMSK|=_BV(INT0); // enabled external interrupt INT0 - PB1

 // Sets the Pin change interrupt mask
 GIMSK|=_BV(PCIE);
 PCMSK|=_BV(PCINT0);//PB0

 pinMode(LED, OUTPUT);
 digitalWrite(LED, LOW);

 pinMode(BUTTON1, INPUT_PULLUP);//INT0 - PB1
 pinMode(BUTTON0, INPUT_PULLUP);//PCINT0 - PB0

 //Enables Interrupts globally after setup
 //SREG |= _BV(SREG_I);
 sei(); // Turn on global interrupts
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
 sleep_enable();
 sleep_cpu();

 while(TRUE){}

 return 0;
}
```


body: I'm creating a web server with using host.com/?ll="some". But I read that I can use for it ESPAsyncWebServer for this things. And how can I use it without flashing esp? If possible give me link to the libraries.

title: How to use ESPAsyncWebServer with SoftwareSerial communicating ESP01f

Answers: 0


body:
I buy an ESP-10 module and I want to upload custom room to its flash. The problem is that there is no way to access GPIO 0 pin! Is there some way around it to upload custom room without connecting GPIO 0 to the ground?
How in the earth should I program it without this pin?
here is an address to supplier's page which contains schematic and some other details.
https://www.tindie.com/products/George/esp8266-esp-10-module/#product-description

title: How can I program an ESP 10 module

Answers: 1

body: You can't.  Not without physical modification to the PCB itself (remove the chip, scratch off a pad and trace, replace pad with fine enamelled copper wire tinned at the end, replace chip).  All you can use is whatever firmware is currently installed in the module.


body:
i have been trying to use NO2 spec senor in arduino UNO. how to write the code for it to get the output in terms of 'ppm' and how to give connection.with the helo of cross-sensitivity given in datasheet how to detect the interference gases from this sensor itself..the datasheet URL:

https://www.spec-sensors.com/wp-content/uploads/2016/10/3SP_NO2_5F-C-Package-110-508.pdf

title: use of spec sensor in arduino uno

Answers: 1

body:
In the specification sheet linked to in the post we find this:

> -30+/-10nA/ppm

This is a very small amount of current.  The Arduino ADC is a voltage sensing device and (unless modified) has a range of 0 to the operating voltage of the Arduino.  Usually 3.3V or 5V.

Converting nano Amps to that range of voltage will require additional hardware.  A stock Arduino and code are unlikely to make use of such a sensor.

The conversion of such small amounts of current to voltages measurable by a stock Arduino is not trivial. And most answers do not fit into the short format of stack exchange.  [Here is an Engineering Design News article][1] on the subject.

  [1]: https://www.edn.com/design/analog/4315417/Measuring-nanoamperes


body:
Please help. I am learning a lot about Arduino. Most all in lightning. I am a newbie. I play with nano and LED ws2812 and use fastled library.

What ask is to make effect like fill effect. For example with larson scanner/chaser.

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

From that code above how to make LED stop and lit up and loop again and stop and lit up.  I want every LED stop the LED lit up even LED looping start again from first LED. It like this:

> 10000 01000 00100 00010 00001 10001 01001 00101 00011 10011 01011
> 00111 10111 01111 11111

title: led chaser fill color effect

Answers: 1

body:
You need two counter for this, one to keep track of how far the LED bar is filled, and one about the current 'running' LED to eventually 'touch' the LEDs which are already moved to the right.

Every led (currentLed) will run from index 0 until the last filled index, while the last filled index is decreased with 1 after every loop.

(note: I haven't checked the code).

    // Fill from the right, thus count backwards.
    for (int filledLedIndex = NUM_LEDS; filledLed >= 0; filledLed--)
    {
       // Now let a LED run from 0 upto filedLedIndex;
       for (int currentLed = 0; currentLed < filledLedIndex)
       {
          // Make previous LED black
          if (currentLed > 0)
          {
             leds[i - 1] = CRGB::Black;
          }

          // Make current LED red
          leds[i] = CRGB::Red;

          // Show.
          FastLED.show();
          delay(50);
       }
    }

    // Clear all LEDs.
    for (int led = 0; led < NUM_LEDS; led++)
    {
        leds[i] = CRGB::Black;
    }

    FastLED.show();
    delay(50);


body:
I am trying to read a signal with a DC offset of 511 (as seen by the ADC). The signal's tiny with regards to the offset, and I'm feeding it to a library that does a Fourier transform on it. It comes from a 3.5mm audio jack with AC coupling and the offset so I can see the full signal.

How may I increase the range of the signal? I am thinking something like the input signal is (490-530) and I want an output of (400-630) or something (numbers solely for example). The issue is that I still need the resulting signal to be centered around 511 AND I don't know the exact amplitude of the input (since it varies based on volume and particular audio going in at the moment).

I can assume that the volume of the audio input is relatively fixed (I need to be able to adjust this gain later, but I'm assuming the volume will be constant at some value per time I'm running the project), so I don't need envelope-following or something, but I'm not sure how to do this even so.

title: Increasing range of a DC-offset signal (software)

Answers: 1

body:
You can't magic more resolution out of thin air (well, you can, but it slows down your sampling - you would "oversample" and average a number of sequential samples).

Instead you need to boost your signal *before* it gets to the ADC using an op-amp.  The simplest circuit (which also inverts the signal, but you don't really care about that I suspect) is:

<!-- 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/kSpiP.png)

<!-- End schematic -->

That circuit will both invert the signal (if you care, just do a little bit of maths in your program to flip the signal, but for FFT you don't really care) and double the amplitude around the mid-point. The doubling is controlled by the ratio of R1 to R2 (20000:10000 = 2:1 = doubled). The mid-point offset is created by R3/R4 - you don't need to manually add your own offset.


body:
Is this battery:

>Polymer Lithium-ion Battery

>Model Number: PGEB014461

>https://www.powerstream.com/p/PGEB014461.pdf

Producing enough energy to power the following Arduino-micro project:

Battery (thin, flexible) to be worn. It will be safely encased (See below)

I would also be using a micro heart pulse sensor module:

>https://pulsesensor.com/

>https://cdn-shop.adafruit.com/product-files/1093/Pulse+Sensor+Data+Sheet-2018.pdf

 and a transmission module

(bluetooth, WiFi, IR, etc...  whichever is suggested or judged appropriate for an alpha project(Needs to be reliable for short range))

Edit: Clarifications about safety standards applied and "do not bend" comments...

> They do not have to be kept flat. The 0.5 mm cells can be flexed or bent into a cylinder, into a hat band, belt, etc.

As previously mentioned, the battery will be safely encased and will not go against these warnings...

>Do not immerse the battery in water or seawater, and keep the battery in a cool dry environment during stands by period.

>Do not use or leave the battery near a heat source such as fire or heater.

>When recharging, use the battery charger specifically for that purpose.

>Do not reverse the position (+) and negative (-) terminals.

>Do not connect the battery to an electrical outlet.

>Do not dispose the battery in fire or heat.

>Do not short-circuit the battery by directly connecting the positive (+) and negative (-) terminal with metal objects such as wire.

>Do not transport or store the battery together with metal objects such as necklaces, hairpins etc.

>Do not strike or throw the battery against hard surface.

>Do not directly solder the battery and pierce the battery with a nail or other sharp object.

title: Arduino Micro & Thin polymer lithium batteries

Answers: 2

body:
The [Arduino Micro](https://store.arduino.cc/arduino-micro) requires 5V. It runs at 16MHz, and you can't run at 16MHz at voltages below about 4V.

To run off a 3.7V battery you need an Arduino board that runs at 8Mhz, such as the ["3.3V Pro Micro" from Sparkfun](https://www.sparkfun.com/products/12587).

To know if your battery is suitable for your project you need to work out the hourly average current draw. That is the proportion of "active" and "inactive" times for each of the devices (transmission duty cycle for your transmitter, sleep times for your MCU, etc).  Until you know that you can't know the capacity (mAh) you need for your project to run for the desired amount of time between charges.

----

You can also drop the idea of an Arduino and branch out. A board that is probably tailor made for your project is the [Adafruit Feather M0 Bluefruit LE](https://www.adafruit.com/product/2995) which is designed to run from a Lithium Polymer batter (and even includes the charger) and has bluetooth built in.

body:
In a word, no. You need to provide an Arduino Micro with either > 6.5V unregulated into the barrel connector, or a regulated 5V supply directly to the 5V line.

You could use a buck/boost DC/DC converter to boost your 3.7V battery output to 5V and feed that directly into the 5V line on the Arduino (or better, feed it into the USB connector, since that will use the input switching on the Arduino.)

This one, for example:

https://www.banggood.com/DC-DC-3V-15V-to-5V-Fixed-Output-Automatic-Buck-Boost-Step-Up-Step-Down-Power-Supply-Module-p-1355829.html?gmcCountry=US&currency=USD&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=frank&utm_campaign=pla-elc2-us-pc-0720&ad_id=368005069105&gclid=EAIaIQobChMI2pfb0Zj54wIVmeDICh2egQ_iEAQYAyABEgLVgvD_BwE&cur_warehouse=CN

Or this one: https://www.digikey.com/reference-designs/en/ac-dc-and-dc-dc-conversion/dc-dc-smps-single-output/1592?utm_adgroup=Converters&gclid=EAIaIQobChMIvM6-9pf54wIVxMDICh36XAxlEAAYASAAEgJsF_D_BwE

Or this one: https://www.adafruit.com/product/2190


body:
 it´s a school project, but I'm having some problems to create a menu selection. In the LCD, all the character are overwriting, I'm a beginer, so i dont have any idea of what i was doing wrong (ps.: sorry about my english, i'm a brazilian.
Here goes the code:
//A portable "atari" videogame project, including 3 games

    #include <LiquidCrystal.h>
    //define os pinos a ser utilizados no arduino uno,etc.
    #define btcima 9
    #define btbaixo 8
    #define bttiro 10
    #define menu 11

    LiquidCrystal lcd(7,6,5,4,3,2);

    int vel=100;
     int pxnave,pynave,pxaste,pyaste,pxtiro,pytiro;//px=posição x, py=posição y, etc
    bool game1,game2,game3,vtiro;//vtiro=variavel de tiro
    int pontos;
    int maxpontos=15;
    int vtela;
    byte nave[8]={B00000,B01100,B00110,B11111,B00110,B01100,B00000,B00000};
    byte asteroide[8]={B01110,B10111,B11111,B11101,B10111,B01110,B00000,B00000};
    byte explosao[8]={B10101,B00010,B11000,B10101,B01010,B10110,B01101,B10011};
    byte tiro3[8]={B00000,B00000,B11110,B11111,B11111,B11110,B00000,B00000};

    int      line[4] = {0,1,2,3},
             line_bk[4],
             index,
             menu_number = 0;

    boolean  menu_flag  = 0,
             enter_flag = 0,
             sub_menu = 0;

    void readButts();
    void list_menu();
    void menu_select();

    void setup()
    {
      //--configuração do menu--
     pinMode(menu,  INPUT_PULLUP);
      pinMode(bttiro, INPUT_PULLUP);

     lcd.begin (16,4);
     //lcd.setBacklight(HIGH);--apenas para lcd i2c
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print(">");

    pxnave=pynave=pyaste=pontos=pytiro=0;
    pxtiro=-1;
    pxaste=12;
    vtela=0;
    lcd.createChar(1,nave);
    lcd.createChar(2,asteroide);
    lcd.createChar(4,explosao);
    lcd.createChar(6,tiro3);
    //lcd.begin(16,2);
    //lcd.clear();
    game1=-false;
    game2=false;
    game3=false;
    vtiro=false;
    }

    void loop(){

      if(!sub_menu)
      {
       lcd.clear();
        lcd.setCursor(1,line[0]);
        lcd.print("1) NAVE: THE GaMe       ");
        lcd.setCursor(1,line[1]);
        lcd.print("2) PING PONG       ");
        lcd.setCursor(1,line[2]);
        lcd.print("3) lula & dilma      ");
        lcd.setCursor(1,line[3]);
        lcd.print("4) Creditos     ");

      }

      readButts();

      if(game1){
        lcd.clear();
        vtela=0;

      if (digitalRead(btcima)==1){
        pynave=0;

      }
      if(digitalRead(btbaixo)==1){
        pynave=1;
      }
      if(digitalRead(bttiro)==1){
        pxtiro=1;
        vtiro=true;
    pytiro=pynave;
      }
      pxaste-=1;
      desenhaNave(pxnave, pynave);
      desenhaAsteroide(pxaste, pyaste);
      if(vtiro){
        desenhaTiro3(pxtiro, pytiro);
        pxtiro+=1;
      }

      if(pxaste<0){
      pxaste=12;
      pyaste=random(0,2);
      }
      if(pxtiro>16){
        vtiro=false;
        pxtiro-=1;
      }
      if (((pxtiro==pxaste+1)&&(pytiro==pyaste))||((pxtiro==pxaste)&&(pytiro==pyaste))){
      vtiro=false;
      pxtiro=-1;
      desenhaExplosaoAsteroide(pxaste, pyaste);
      pyaste=random(0,2);
      pxaste=12;
      pontos+=5;
      if((pontos>=maxpontos)){
        game1=0;
        vtela=7;//rever
      }
    }
    if((pxnave==pxaste)&&(pynave==pyaste)){
    game1=0;
    desenhaExplosaoNave(pxnave, pynave);
    vtela=6;
    }

      delay(vel);

      }else{
        tela(vtela);
        if(digitalRead(bttiro)==1){
          reset1();
        }
      }
    }

      void readButts()
    {

       if(!digitalRead(menu))  menu_flag  = 0x01;
       if(!digitalRead(bttiro)) enter_flag = 0x01;

       if(digitalRead(menu) && menu_flag)
       {
           menu_flag = 0x00;
           list_menu();
           menu_number+=1;
           if(menu_number > 5) menu_number = 1;

       }

       if(digitalRead(bttiro) && enter_flag)
       {
          enter_flag = 0x00;
          sub_menu = !sub_menu;
          menu_select();

       }

    }

    void list_menu()
    {
      for(int i=4; i>-1; i--)
      {
         index = i-1;
         line_bk[i] = line[i];

         if(index < 1) line[i] = line_bk[i+4];

         else line[i] = line[i-1];

      }

    }

    void menu_select()
    {

        switch(menu_number)
        {
           case 1:
            vtela==0;
            game1= true;
            game2=false;
            game3=false;

                   break;
           case 2:
                vtela==4;
                  game1= false;
            game2=true;
            game3=false;
                   break;
           case 3:
               vtela==5;
               game1= false;
            game2=false;
            game3=true;
                   break;
           case 4:
                   vtela==8;
                   game1= false;
            game2=false;
            game3=false;
                   break;
           //case 5: ---pensar---

        } //end switch

    }
      void desenhaNave(int px, int py){
      lcd.setCursor(px,py);
      lcd.write(1);
    }
    void desenhaAsteroide(int px, int py){
      lcd.setCursor(px,py);
      lcd.write(2);
    }

    void desenhaTiro3(int px, int py){
      lcd.setCursor(px,py);
      lcd.write(6);
    }
    void desenhaExplosaoNave(int px, int py){
     lcd.clear();
      lcd.setCursor(px,py);
      lcd.write(4);
      delay(1000);
      lcd.clear();
    }
    void desenhaExplosaoAsteroide(int px, int py){
      lcd.setCursor(px,py);
      lcd.write(4);
      delay(1000);
      lcd.clear();
    }
    void reset1(){
      pontos=0;
      game1=true;
      vtela=0;
    }
    void reset2(){
      pontos=0;
      game2=true;
      vtela=0;
    }
    void reset3(){
      pontos=0;
      game3=true;
      vtela=0;
    }

    void tela(int cond){//0=jogo da nave 1=ganhou 2= perdeu 3= menu de seleção 4=jogo pingpong 5=jogo plataforma

    if(cond<1){
       lcd.setCursor(3,0);
         lcd.print("Nave: THE GAmE");
         lcd.setCursor(0,1);
    lcd.print("PRESSIONE START");
    }
    if(cond==6){
      lcd.setCursor(9,0);
      lcd.print("pts:");
      lcd.setCursor(13,0);
      lcd.print (pontos);
      lcd.setCursor(1,0);
      lcd.print("Perdeu");
    lcd.setCursor(0,1);
    lcd.print("PRESSIONE START");
    }
    if(cond==7){
      lcd.setCursor(9,0);
      lcd.print("pts:");
      lcd.setCursor(13,0);
      lcd.print (pontos);
      lcd.setCursor(1,0);
      lcd.print("Ganhou");
    lcd.setCursor(0,1);
    lcd.print("PRESSIONE START");
    }
    if (cond==3){
      sub_menu=true;
      lcd.clear();
    }

    if(cond==4)
    {
      lcd.setCursor(3,0);
      lcd.print ("Ping Pong");
      lcd.setCursor(0,1);
      lcd.print ("PRESSIONE START");

    }
    if (cond==5)
    {
      lcd.setCursor(3,0);
      lcd.print("Lula e Dilma");
      lcd.setCursor (0,1);
      lcd.print ("PRESSIONE START");
    }
    if (cond==8)
    {
      lcd.setCursor(3,0);
      lcd.print("Equipe LULA Livre");
      lcd.setCursor(0,1);
      lcd.print("Obrigado por Jogar");
    }
    }`enter code here`

title: I´m trying to make a kind of videogame with Arduino UNO

Answers: 1

body:
Probably since you set the cursor at a position in the middle of a line, only the new text is overwritten over the old text. But if there are some characters from the previous text, those will stay.

So the easiest way is to either clear the screen (if you can do the updating of the screen from a single place), or rewrite the entire line (and probably having to add spaces before/after the text you want to write to overwrite the old text).

Some other tips:

- Write comments and variable names in English (I know it's not your mother
language, but you can learn two languages at once, C and English).
- Align your code (make sure each { and } is aligned nicely; this will make life much easier and prevent mistakes.
- game1, game2 and game3 are booleans where only one can be true. For this the `enum` (enumeration) is invented. So make an enum `enum Game { game1, game2, game3 };` as a type, and declare a variable `Game currentGame = game1;`
- You use a switch statement for menu_number, but why not for cond?
- You use a lot of text, all text also takes up precious SRAM, where you only have 2,048 bytes of. If for each string you add F in front (thus e.g. F("MENU"); this will be stored only in Flash.


body:
Sorry my English is poor.

I use nodemcu to get a json data.

By this `String alldata = client.readString();`

But it turn this:

      HTTP/1.1 200 OK
      Server: nginx
      Date: Sat, 10 Aug 2019 04:53:16 GMT
      Content-Type: application/json; charset=utf-8
      Content-Length: 152
      Connection: keep-alive
      X-RateLimit-Limit-day: 20000
      X-RateLimit-Remaining-day: 19968
      Cache-Control: no-cache
      Pragma: no-cache
      Expires: -1
      X-Powered-By: ASP.NET
      Access-Control-Allow-Origin: *
      X-Kong-Upstream-Latency: 23
      X-Kong-Proxy-Latency: 2
      Via: kong/0.14.1
      Strict-Transport-Security: max-age=63072000; includeSubdomains; preload

      [{"Direction":0,"EstimateTime":364,"StopStatus":0,"MessageType":0,"SrcUpdateTime":"2019-08-10T12:53:00+08:00","UpdateTime":"2019-08-10T12:53:05+08:00"}]

I need '364' to display on oled.

Is it possible to split it.Thanks!

title: About split string

Answers: 0


body:
I am strain guages in a wheatstone bridge along with hx711 . For testing amplifier I used potentiometers to change the input voltage for hx711. It is outputting only zero. Here is my code.

    #include "HX711.h"

    // HX711 circuit wiring
    const int LOADCELL_DOUT_PIN = 2;
    const int LOADCELL_SCK_PIN = 3;

    HX711 scale;

    float calibration_factor = 282650.0;

    void setup() {
      Serial.begin(57600);
      scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
      scale.set_scale();
      scale.tare(); //Reset the scale to 0
    }

    void loop() {
      if (scale.is_ready()) {
        long reading = scale.read();
        Serial.print("HX711 reading: ");
        //Serial.println(reading);
        Serial.println(scale.get_units(), 5);
      } else {
        Serial.println("HX711 not found.");
      }
      delay(1000);
    }

title: Hx711 is outputting only zero

Answers: 0