# Question
Title: ESP8266 Software serial to ATmega 328 is not properly working
Thanks in advance..

We are having esp8266-12E chip and Atmega328 connected as follows, ESP 12 pin as Tx,13 pin as Rx && Atmega328 13pin as Rx, 12pin as Tx. Everything works fine, but while communicating via serial some low pulse is being generated. We couldn't find the issue with multimeter anyway but got it by oscilloscope signal.

When this false low pulse during communication happens Atmega328 connected pins also getting low for the same duration.

We tried using separated logic execution for ESP and Atmega and both were worked perfectly, but only during communicating via Software serial its flickers getting started.

Please help us getting this resolved.

# Answer
Don't use SoftwareSerial in esp8266. Connect the 328p's SoftwareSerial pins to Serial interface pins of the esp8266. ESP8266 has second Serial interface named Serial1. It has only TX (io 2), but it is enough for debug prints.

To change the firmware or sketch in esp8266 you can use ArduinoOTA library, but you should be ready to disconnect the esp8266 Serial pins from the 328p and use them for Serial upload if the OTA upload fails.

You should use logic level converter from 5 V to 3.3 V to protect the esp8266 RX pin.
> 1 votes

---
Tags: esp8266, atmega328, softwareserial
---


title: int on Uno more than 16 bit?

text:
# Question
Title: int on Uno more than 16 bit?
So I'm playing with a TFT screen and trying to understand the colourspace encoding. I wrote a quick `for` loop to show colours from 0 to FFFF and to print the value of colour being displayed:

```
for (int q=0; q<0xFFFF; q+=0x80) {
  tft.fillScreen(q);
  tft.setCursor(0, 0); tft.println(q, HEX);
  delay(2);
}

```

I was surprised to find values greater than FFFF being displayed - which suggest that `int` is more than 16 bits. It's running on a Uno.

What has happened?

(PS I now understand RGB565 encoding, so this is off-topic)

# Answer
I guess you're seeing some big numbers starting with FFFF...?

What you are seeing is not big numbers - it's misrepresented numbers.

You have an `int`. That's not a "16-bit number", it's a 15-bit number *plus a sign bit*.

When you print it the variable is *promoted* to a `long` and the sign bit is *extended*.

That `long` is then further mapped (cast) into an `unsigned long` to print it as hexadeximal (there is no negative in the hexadecimal representation on Arduino), and that *extended sign bit* is seen as a string of F.

For example, the value 0xABCD stored in an `int` is:

```
 1 010 1011 1100 1101

```

I broke off the first bit because that is the *sign* bit in a *signed integer*. The actual decimal value of that is -21555.

Now when that gets cast to a long the sign extension copies the leading sign bit to all the other 16 bits to the left of it, resulting in:

```
1 111 1111 1111 1111 1010 1011 1100 1101

```

Because of the way that *twos complement* works, that string of bits still represents -21555 in decimal.

However, cast it to `unsigned long` for printing as HEX and you can see how you would end up with some big numbers. It would give you:

```
FFFFABCD

```

So you can see that a 16 bit signed value can end up being printed as 8 hex digits, and all because of the way the `print()` function in the Arduino API works.

When working with unsigned values you really should be working with an unsigned variable - especially if those unsigned values (0 - 65535) fall outside the range of the signed variable type (-32768 - 32767). Switch to using `uint16_t` and you will be able to both store and represent the values correctly.

---

You might find it useful playing around with this site to learn how different variable types represent and store the data within them as binary.
> 1 votes

---
Tags: arduino-uno-smd
---


# Question
Title: Arduino IDE does not display examples folder from my custom library
I have created a custom library for local usage. I call is `ABC_node` for ESP32 and the structure is as follows:

```
.
|-- examples
|   |-- bnoCalibStorage
|   |   `-- bnoCalibStorage.ino
|   |-- influxHTTP_write
|   |   `-- influxHTTP_write.ino
|   |-- influxPing
|   |   `-- influxPing.ino
|   |-- influxUDP_write
|   |   `-- influxUDP_write.ino
|   `-- rtcTimestamp
|       `-- rtcTimestamp.ino
|-- keywords.txt
|-- library.properties
|-- README.md
|-- ABC_Node.cpp
`-- ABC_Node.h

```

I tried following the Adafruit GitHub Repository structure where each example is placed inside a folder named after the sketch.

I am hosting this repository on a private GitLab Server. I used `git tag v1.0.0` to create a tag and from GitLab I could download the `.zip` file for the stable v1.0.0 library.

I manually extracted the files to my `<user>\Documents\Arduino\libraries` folder and renamed the folder to `ABC_Node` (since my gitlab repo is named something else)

I restarted my IDE but I could not find the library `ABC_Node` in

```
Sketch\Include Library\

```

### `library.properties`

```
name=ABC_Node
version=1.0.0
author=Shan Desai
maintainer=Shan Desai
sentence=Firmware to create InfluxDB measurements and send them via HTTP/UDP to Core
paragraph=ABC_Node provides `String` based InfluxDB measurements which can then be sent via HTTP/UDP to a central InfluxDB instance.
category=Data Processing, DAQ
architecture=ESP32
repository=https://[gitlab-address]/node-repo.git

```

I followed the Libraries Guide from Arduino on local Installation

### System

Windows 10

Arduino IDE 1.8.5

# Answer
> 2 votes
Your library.properties is lacking a line. Emulating your library with blank files and copying in your library.properties content, and running on Linux from the command line, it reports to me:

```
Invalid library found in /home/matt/Arduino/libraries/ABC_Node: Missing 'url' from library

```

So you lack the line:

```
url=https://whatever.website.you.want.to/point.to

```

(Or use something like `http://example.com` if you don't want one...)

I put that line in, and magically the library appears in the list.

---
Tags: arduino-ide, library
---


# Question
Title: Standard Practice for including custom library in examples folder
I have created my custom library with `examples` folder in them. The main header file is `ABC_Node.h`. I am referring the structure of Adafruit libraries for Arduino and in some repos under the `examples` folder I found a conflict for the inclusion of their header files.

### Example

in some repos. they use **double quotes** (`""`) for including their header files e.g. `#include "Adafruit_SHT31.h"` SHT31test.ino

on the contrary, in their BNO055 Arduino library they use brackets (`<>`) `#include <Adafruit_BNO055.h>` BNO055 Bunny sketch

I locally tested my library on the IDE and I have examples in which my library is in `#include "ABC_Node.h"` and it compiles without a problem.

Soon I wish to make the repository public and want to know if there is a standard practice for including header files for examples.

# Answer
> 3 votes
You can use either. There is no "standard".

When using a raw C compiler there is a difference between the two as regards the order in which directories are searched for files to include, but with the Arduino that is completely irrelevant, so either can be used.

Personally I use `<...>` for libraries and `"..."` for header files that form part of the sketch. It makes for easier identification of which is which, and conforms to the C standard of `<...>` for system-installed headers, and `"..."` for local headers.

---
Tags: arduino-ide, library
---


# Question
Title: 2 Arduino controller boards - 1 shared input
I'm beginning with electronics and don't have all the good reflexes yet. So here is my question:

Can I do what I did here?

can i do this http://www.movod-design.com/forum\_img/canIDoThis.jpg

Do I have to add diodes between the Nano +5V and the junction point?

My goal is to have one button's state read by 2 Arduino Nano.

# Answer
> 8 votes
You don't need to add anymore components to your schematic. But you can leave some components.

Before you're adding a button to your schematic please consider first how you want to detect your signal. A logic 1 as if a button is pressed? Or logic 0 as if a button is pressed. You can do this using pull-up and pull-down resistors. These resistors should be wired like this.

(The 100Ohm resistor in an internal resistor from the MCU)

Using the pull-down resistor means that when the button is pressed you'd get a logic 1. Using pull-up resistors means that when the button is pressed you'd get a logic 0.

When I see your schematic it seems like you're trying to make a pushbutton with pull-down resistor. Then you should wire your arduino like this.

Another option is to use the Arduino internal pull-up resistors. That way you don't have to add the 10k resistor in your schematic. And your schematic will look like this.

To use the internal pull-up resistors from the Arduino you'll need to put this in your setup(): pinMode(pin, INPUT\_PULLUP); where pin should be your pin number. Please keep in mind that when you use the internal pull-up resistor a logic 0 means the button is pressed.

# Answer
> 0 votes
I have done something like this to be able to have a redundant system. Is this what you were doing: Two computers receiving the trigger, if one computer failed you have the other running?

If that is your case, then there is a problem on this setup:

* If one computer shuts down the Arduino on that computer will be powered by the second one and there will be not enough power for both.

I fixed it with a couple of diodes.

I still had some problems with false triggering from time to time, with tests on a Mac running OSX. The same tests with a Linux machine give no problem for now.

I wanted to make this really stable (next I'll try to use opto-isolators) I'm not a Programer nor a Engineer. Please tell me if I'm saying something stupid or if there is any other easy fix.

I was using two Arduino Pro micro Chinese copies and passing the data to midi to the computers - I did not test with real Arduinos to see if it was a board problem.

---
Tags: arduino-nano
---


# Question
Title: My verbose appears "unable to cache built core"
At early morning i have accidentally the error of GNOME for my OS, so I was forced reinstall my OS couse i don't have any backup for my packages and my database. i'm installed Arduino-IDE 1.8.7, Arduino AVR Boards 1.6.23 and Esp8266 Boards 2.4.2 . when i trying to upload my sketch, i get this error:

```
...
Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
...

```

I see the link, but i cannot see where my archive variable in platform file for my cores.

```
...
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
...

```

**See** my verbose log !!!.

```
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_api.cpp.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/spiffs_hal.cpp.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/time.c.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/uart.c.o
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_988288/arduino.ar /tmp/arduino_build_988288/core/umm_malloc/umm_malloc.c.o
Unable to cache built core, please tell esp8266 maintainers to follow http://goo.gl/QdCUjo
Linking everything together...
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_988288/tesHC139.ino.map -g -w -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m1m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_988288/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_988288/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_988288/libraries/SPI/SPI.cpp.o /tmp/arduino_build_988288/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_988288/libraries/Wire/Wire.cpp.o /tmp/arduino_build_988288/arduino.ar -lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_988288
/home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_988288/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_988288/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
/home/praz/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_988288/tesHC139.ino.elf
Sketch uses 259408 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28352 bytes (34%) of dynamic memory, leaving 53568 bytes for local variables. Maximum is 81920 bytes.
/home/praz/.arduino15/packages/esp8266/tools/esptool/0.4.13/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_988288/tesHC139.ino.bin

```

I don't think so if i have permissions issue, it seems my boards is fine about my permissions.

```
total 388
drwxrwxr-x  8 praz praz   4096 Okt 11 00:14 ./
drwxrwxr-x  3 praz praz   4096 Okt 11 00:13 ../
-rw-rw-r--  1 praz praz 293575 Agu  3 14:19 boards.txt
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 bootloaders/
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 cores/
-rw-rw-r--  1 praz praz    235 Agu  3 14:19 .gitmodules
-rw-rw-r--  1 praz praz   2831 Agu  3 14:19 ISSUE_TEMPLATE.md
-rw-rw-r--  1 praz praz    553 Agu  3 14:19 keywords.txt
drwxrwxr-x 28 praz praz   4096 Agu  3 14:19 libraries/
-rw-rw-r--  1 praz praz  26529 Agu  3 14:19 LICENSE
-rw-rw-r--  1 praz praz    194 Agu  3 14:19 package.json
-rw-rw-r--  1 praz praz   6844 Agu  3 14:19 platform.txt
-rw-rw-r--  1 praz praz   7136 Agu  3 14:19 POLICY.md
-rw-rw-r--  1 praz praz      0 Agu  3 14:19 programmers.txt
-rw-rw-r--  1 praz praz   7722 Agu  3 14:19 README.md
drwxrwxr-x  4 praz praz   4096 Agu  3 14:19 tests/
drwxrwxr-x  3 praz praz   4096 Agu  3 14:19 tools/
drwxrwxr-x 25 praz praz   4096 Agu  3 14:19 variants/

```

**Solved**

I think when i installed Esp8266 Boards 2.4.2 latest version is fine, i uploaded my sketch and i cannot make cache to my built core, Majenko is right, my the snippet of config are difference between my 74hc139 issue and my verbose log issue.

when i installed fresh Esp8266 Boards using boards manager, that automatically downloads source code of esp8266 core on this Github, i don't understand why my snippet of config not updated like this commit. so i updated my config of boards with copy/paste on tree links of Github, and that's works.

See my verbose below or see at this :

```
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/sqrt32.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/time.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/uart.c.o
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru /tmp/arduino_build_979295/core/core.a /tmp/arduino_build_979295/core/umm_malloc/umm_malloc.c.o
Archiving built core (caching) in: /tmp/arduino_cache_39139/core/core_8e365e854c5bfceaa27f4c371ba290d0.a
Linking everything together...
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -CC -E -P -DVTABLES_IN_FLASH /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld/eagle.app.v6.common.ld.h -o /tmp/arduino_build_979295/local.eagle.app.v6.common.ld
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -Wl,-Map -Wl,/tmp/arduino_build_979295/tesHC139.ino.map -g -Wall -Wextra -Os -nostdlib -Wl,--no-check-sections -u app_entry -u _printf_float -u _scanf_float -Wl,-static -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/lib -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/ld -L/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/sdk/libc/xtensa-lx106-elf/lib -Teagle.flash.4m.ld -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -o /tmp/arduino_build_979295/tesHC139.ino.elf -Wl,--start-group /tmp/arduino_build_979295/sketch/tesHC139.ino.cpp.o /tmp/arduino_build_979295/libraries/SPI/SPI.cpp.o /tmp/arduino_build_979295/libraries/Adafruit_BME280_Library-master/Adafruit_BME280.cpp.o /tmp/arduino_build_979295/libraries/Wire/Wire.cpp.o /tmp/arduino_build_979295/core/core.a -lhal -lphy -lpp -lnet80211 -llwip2-536-feat -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group -L/tmp/arduino_build_979295
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -eo /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/bootloaders/eboot/eboot.elf -bo /tmp/arduino_build_979295/tesHC139.ino.bin -bm dio -bf 40 -bz 4M -bs .text -bp 4096 -ec -eo /tmp/arduino_build_979295/tesHC139.ino.elf -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
Using library SPI at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /home/praz/Arduino/libraries/Adafruit_Sensor-master
Using library Adafruit_BME280_Library-master at version 1.0.7 in folder: /home/praz/Arduino/libraries/Adafruit_BME280_Library-master
Using library Wire at version 1.0 in folder: /home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Wire
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-size -A /tmp/arduino_build_979295/tesHC139.ino.elf
Sketch uses 265524 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28236 bytes (34%) of dynamic memory, leaving 53684 bytes for local variables. Maximum is 81920 bytes.
/home/praz/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/tools/esptool/esptool -vv -cd nodemcu -cb 115200 -cp /dev/ttyUSB0 -ca 0x00000 -cf /tmp/arduino_build_979295/tesHC139.ino.bin

```

Hope anyone can solve my issue, Thanks in advance.

# Answer
> 1 votes
This was fixed on the 20th August in this commit. Make sure you have the latest version of the ESP8266 core installed. If there hasn't been a release since that fix, you can pull the github version of the config file and use that instead of the one bundled with the core.

However, it's not a fatal error - it merely means that compilation will be slower than it should be.

---
Tags: esp8266, core-libraries
---


title: Garbage stored in SD card

text:
# Question
Title: Garbage stored in SD card
I am an electronics graduate and an embedded design engineer, working in this field for about two years apart from the hobby time during my graduation. I am currently working on a system that has an Atmega2560 as the core controller with an arduino bootloader, we are using an 8GB memory card to save the log data from our system and send it to our server at regular intervals of time. The system worked fine however some of them are facing issues with the writing of data, some garbage value are getting stored in the SD card. I have attached the schematic and code snippet for the same, please let me know if there is any problem with the system and how can i resolve it, please let me know if any other things are required for understanding the problem correctly.

Thank you in advance.

```
     SD_Initialize();
  if(!SD.exists(SDTransactionDirectory))
  {
    if(SD.mkdir(SDTransactionDirectory))
    {

    }
  }
  RTC_Date_Time();
  String FileName = SDTransactionDirectory + "/" + RTCSDDate + RTCSDTime + ".txt";
  SD_File = SD.open(FileName, FILE_WRITE);
  if(SD_File)
  {
    delay(100);
    digitalWrite(LED_SD, HIGH);
    SD_File.println(GSMData);
    SD_File.close();
  }

```

The SD\_Initialize() is a user function:-

```
void SD_Initialize()          //initialise SD card
{
  digitalWrite(SD_EN, HIGH);
  digitalWrite(SD_CS, LOW);

  delay(500);

  if(SD.begin(SD_CS))
  {
    digitalWrite(LED_SD, HIGH);
  }
  else
  {
    digitalWrite(LED_SD, LOW);
  }
}

```

The data stored in the filename is as follows:- CLEnT|T|M008|\00Ÿûmï°\]ŸëÜ£·zoòTÏæ{Œü\[ŸýUô~ÛcCWY`®ÞgÙë×<;wBÄgnìÇFÿÉ=XoÎ.êžÄf·®ö¯³ç~åeÝ]1_`ÏÀyÿÌÍ?ô"zBõ¬ñ

As you can see the initial values till "M008" is fine but its garbage after that, and the CLEnt|T|M008 is the start of the string after that a lot of other parameter information is to be stored which turns out to be garbage.

# Answer
> 1 votes
There are many comments, but no answer yet. This answer has only a few basic rules.

The first thing to do is to see if the problem can be replicated with a small sketch and to check the voltages.

The arduino mega 2560 works best at 5.0V, or maybe a little less. It is not reliable at 4V. When powering it with a 5V power supply, the usb connecter is the best option to power the arduino board. Powering the arduino board via the 5v pin is not advised. When a strong power supply is connected to the 5v pin, the voltage regulator can be blown.

When something is not working, fall back to something that is reliable. For example a SD module with a HC4050 to shift the voltage levels. The resistors make the signal weaker.

Make a small test sketch without the use of the String object. The more experienced someone is with arduino, the more he or she tells to avoid the String object with avr microcontrollers.

There are counterfeit SD cards. One of those might turn up in your hands someday. Beside that, not every SD card is compatible with the arduino SD library.

In your situation it is suspicious that the file system is okay, the filenames are okay, the first text is okay, but when data is written it suddenly goes wrong. That is a strong indication for a memory problem.

When data to a display or SD card is wrong, then send it also to the serial monitor. You have to know what is actually written to the SD card.

---
Tags: arduino-uno, arduino-mega, sd-card, hardware, electronics
---


# Question
Title: How would I go about measuring an analog signal on my arduino mega that has both positive and negative voltages
I have a signal that fluctuates between -70mV and 50mV. How would I get the arduino to read this.. Ultimately I am trying to graph the data in real time so it looks like this.

https://i.stack.imgur.com/a8zIE.jpg

# Answer
> 1 votes
You need to amplify your signal and add 2.5V as a "virtual ground" for the amplification. This gets a little tricky, since you need a low-impedance VCC/2 source to feed the amplifier as a virtual ground. This would require a unity-gain buffer fed from a voltage divider:

simulate this circuit – Schematic created using CircuitLab

Now you use that to feed the amplifier:

simulate this circuit

The gain is set by 1+(RF/RG), or 11 in this case, giving you -0.77V to +0.55V.

There is a simpler option, though. (There is another intermediate option but the editor lost it and I can't be bothered to spend the time recreating it).

This method does come at a cost, though: it inverts the signal. The -0.07 becomes 0.07 and the 0.05 becomes -0.05, and multiplied by the gain and added to the offset:

simulate this circuit

Here you get a transformation from -0.07V - +0.05V to +0.7V - -0.5V. That means that *in software* you then have to invert the value (simply subtract it from 0 after removing the DC offset).

You're basically shifting some of the complexity out of the circuitry and into the software.

Personally I use the inverting amplifier (the last circuit) because the virtual ground current is near zero, so you don't need a low impedance VCC/2 voltage source. It's also easier to create more sensible gains (like 10x) than the non-inverting amplifier, which always has 1 added to the gain.

# Answer
> 1 votes
Here is my try at this: if your voltage source doesn't mind sinking something like 150 µA, you could try something like this:

simulate this circuit – Schematic created using CircuitLab

This should map the input range \[−70 mV, +50 mV\] to \[0.04 V, 4.06 V\].

---
Tags: arduino-mega, analogread, voltage-level, voltage, analogreadresolution
---


# Question
Title: Arduino Hardware serial library with rts/cts flow control support
Does there exist (any user developed etc.) version of the Hardware UART serial library that has support for RTS/CTS based flow control? More interested in the Tx side (Arduino sends data, while the peripheral can back-pressure). The library should enable the Arduino to stop transmitting within 1 character of seeing a 'not ready' indication from the peripheral.

Thank you.

# Answer
> 2 votes
I am not aware of any such library. You could try to implement one yourself, and maybe share it with the community. :-)

If you take this route, you will have to copy the file HardwareSerial.cpp from the Arduino core, make your changes there, and have your version replace the one from the core. Here are some ideas that may help to get you started:

* Wire the 'ready' signal from the device to an interrupt-capable pin of the Arduino.
* Inside the interrupt handler:
    + when 'ready' is deasserted, disable the UDRE interrupt by issuing `cbi(*_ucsrb, UDRIE0)`
    + when ready is asserted, enable it again, but only if the output buffer is not empty: `if (_tx_buffer_head != _tx_buffer_tail) sbi(*_ucsrb, UDRIE0);`
* Patch `HardwareSerial::write()` to enable the interrupt only if 'ready' is asserted.
* Note that the UDRE IRQ can be explicitly called by `HardwareSerial::flush()` and by `HardwareSerial::write()` if interrupts are globally disabled. You will have to condition this on the 'ready' signal.
* Note also that `HardwareSerial::write()` can write directly to the UART if the buffer is empty. This also has to be conditioned on the 'ready' signal.

# Answer
> 0 votes
I believe that CTS would be fairly easy to implement:

```
void loop() {
  uint8_t clear_to_send = digitalRead(CTS);
  volatile char data;
  if (clear_to_send) {
    Serial.write(data);
  }
}

```

I'm not sure about RTS.

# Answer
> 0 votes
I have I discovered that RTS/CTS may be implemented in genuine Arduinos, but is not supported by Arduinos that use the CH340 USB to serial chip. I found this when my JAVA program could talk with a genuine Uno ok, but didn't send any data to several Arduino compatibles that use the CH340 chip (but did receive from them). I had RTS/CTS set on the JAVA program. When I changed it to FLOWCONTROL\_NONE it started working just fine.

---
Tags: arduino-mega, uart
---


# Question
Title: I keep on getting a stray '\302' in program error.How do I fix it.This is in arduino uno
```
#include <LiquidCrystal.h>

int trigPin = 13;  //sensor's trigger pin connected to pin 13
int echoPin = 7;  //sensor's echo pin connected to pin 11
float pingTime;  //time for the ping to hit the target and back
float ss;  //we will calculate the speed of sound
float td = 13; //target distance.

void setup() {
  // put your setup code here, to run once:

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

  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);  //TRIG AS OUTPUT
  pinMode(echoPin,INPUT);  //EHO AS AN INPUT

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.println(ss);

}

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

  digitalWrite(trigPin,LOW);  //set trig pin low.
  delayMicroseconds(2000);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin,LOW);
  pingTime = pulseIn(echoPin,HIGH);  //measure ping time traveltime in microseconds.
  ss= 2*td / pingTime;  //gives us speed in inches per microseconds.
  ss=ss/63360*1000000*3600;  //gives us speed in miles per hour.
  Serial.print("The speed of sound is ");
  Serial.print(ss);
  Serial.println(" miles per hour");

  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink(0);
  delay(3000);

}

```

# Answer
> 2 votes
The culprits are the no-break spaces (U+00A0) you sometimes use in your indentation. Each of them, when encoded in UTF-8, is represented by the pair of bytes `0xc2 0xa0` (or `0302 0240` in octal). You should indent with *regular spaces* (U+0020) instead.

Specifically, you have no-break spaces as the first characters of each of the following 8 lines:

```
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.println(ss);
[...]
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink(0);
delay(3000);

```

# Answer
> 1 votes
Beware when you copy code from sites which have formatead fonts in their content. As you copy and paste these font-formatead codes, chances are that you copy the font's formats as well. Once you paste these formatead fonts on your code, the text editor from the Arduino IDE will not recognize the special characters used on the font's formatting; thus, it will not show them on your screen. However, the compiler will read them and will strive to compile them as if they were part of your code. Since the compiler does not "understand" these special characters, it will warn you about their existence by identifying them as "stray" pieces of code. This is why some code-related sites, such as GitHub, gives you the opportunity of copying RAW CODE, so you do not copy the formatead fonts that some developers use to showcase their much appreciated contributions. I sincerely hope this works for you. Best regards.

# Answer
> 1 votes
Just try to removes extra spaces that are outside the scopes (curly braces `{` and `}`) and it'll work fine.

---
Tags: arduino-uno, programming, lcd
---


title: Why after the reset the program vanish?

text:
# Question
Title: Why after the reset the program vanish?
I buy a stm32 board as picture below, I connect the Boot0 to 3.3 and use the serial port download the program.

I use the library https://github.com/rogerclarkmelbourne/Arduino\_STM32

The second and third picture is my program. After I download the program, the led on board shine and the serial is normal, but after I press RESET on board, it is not shine. Seemly, the program vanish.

Why it is so ? And how to let the program in board after press reset ?

>

# Answer
> 2 votes
By connecting `BOOT0` to 3.3V you are telling the chip *When I reset for whatever reason you must go into the bootloader*.

So you reset, and it goes into the bootloader. You then upload your sketch.

At that point the programming software tells the bootloader "Ok, you are done now. Run the program". And it does.

Until you reset. And because *you are telling it to go into the bootloader with BOOT0* it dutifully does so, waiting for you to load a new program.

The old program is still there, but you just aren't letting run, since you are insisting that the chip go into the bootloader when you reset.

In order to get your program to run and not the bootloader you must disconnect BOOT0 so it doesn't enter the bootloader.

You *only* need to connect the BOOT0 *when you want to put a new program on there*.

# Answer
> 2 votes
From http://wiki.stm32duino.com/index.php?title=Bootloader

> Activating the bootloader is done through forcing two boot pins (and then resetting the MCU). Many boards have one or more boot pins exposed as jumpers or push buttons.
>
> Normal boot (to user firmware, which may be a secondary bootloader):
>
> * Boot0 LOW
> * Boot1 LOW
>
> Allow firmware upload through USART1:
>
> * Boot0 HIGH
> * Boot1 LOW

After uploading new software through the serial, move `Boot0` back to `GND` so that the MCU loads the firmware you uploaded, rather than it's internal serial bootloader.

---
Tags: arduino-ide
---


# Question
Title: Why are my if statements acting like the condition is always true?
Here is my code. My issue is is that the keys are getting "pressed" even though there is nothing jumping any of the pins on the Arduino.

```
// UNO-HIDKeyboard-Library - Version: Latest
// This program has been created by pcs3rd.
// Please do not change this line.
#include <HIDKeyboard.h>
HIDKeyboard keyboard;   // Initiate keyboard
// Pin deffanitions and variables...
int key0 = 2;   // Button 0 (Unused but optional)
int key1 = 3;   // Button 1
int key2 = 4;   // Button 2
int key3 = 5;   // Button 3
int key4 = 6;   // Button 4
int key5 = 7;   // Button 5
int key6 = 8;   // Button 6
int key7 = 9;   // Button 7
int key8 = 10;  // Button 8
int led0 = 13;  // Indicator light.
int state0 = 0; // Button 0
int state1 = 0; // Button 1
int state2 = 0; // Button 2
int state3 = 0; // Button 3
int state4 = 0; // Button 4
int state5 = 0; // Button 5
int state6 = 0; // Button 6
int state7 = 0; // Button 7
int state8 = 0; // Button 8

void setup() {
   keyboard.begin();    // Start keyboard emulation
   Serial.begin(9600);  // Start Serial Output
   delay(300);          // Wait to be recognized be PC.
   pinMode(key1, INPUT_PULLUP); // set pin mode
   pinMode(key2, INPUT_PULLUP); // set pin mode
   pinMode(key3, INPUT_PULLUP); // set pin mode
   pinMode(key4, INPUT_PULLUP); // set pin mode
   pinMode(key5, INPUT_PULLUP); // set pin mode
   pinMode(key6, INPUT_PULLUP); // set pin mode
   pinMode(key7, INPUT_PULLUP); // set pin mode
   pinMode(key8, INPUT_PULLUP); // set pin mode
   pinMode(led0, OUTPUT);       // set pin mode
   Serial.println("Startup Completed!");
}

void loop() {
   // write state info to vars
   state0 = digitalRead(key0); // Button 0
   state1 = digitalRead(key1); // Button 1
   state2 = digitalRead(key2); // Button 2
   state3 = digitalRead(key3); // Button 3
   state4 = digitalRead(key4); // Button 4
   state5 = digitalRead(key5); // Button 5
   state6 = digitalRead(key6); // Button 6
   state7 = digitalRead(key7); // Button 7
   state8 = digitalRead(key8); // Button 8
   if (state0 == HIGH) {       // Button 0
     digitalWrite(led0, HIGH);
     // keyboard.pressSpecialKey(0x68); (You can enter a scancode instead of 0x68,)
     Serial.println("state0");
     delay(30);
   }
   if (state1 == HIGH) { // Button 1
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x68);
     Serial.println("state1");
     delay(30);
   }
   if (state2 == HIGH) { // Button 2
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x69);
     Serial.println("state2");
     delay(30);
   }
   if (state3 == HIGH) { // Button 3
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6A);
     Serial.println("state3");
     delay(30);
   }
   if (state4 == HIGH) { // Button 4
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6B);
     Serial.println("state4");
     delay(30);
   }
   if (state5 == HIGH) { // Button 5
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6C);
     Serial.println("state5");
     delay(30);
   }
   if (state6 == HIGH) { // Button 6
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6D);
     Serial.println("state6");
     delay(30);
   }
   if (state7 == HIGH) { // Button 7
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x6E);
     Serial.println("state7");
     delay(30);
   }
   if (state8 == HIGH) { // Button 8
     digitalWrite(led0, HIGH);
     keyboard.pressSpecialKey(0x0F);
     Serial.println("state8");
     delay(30);
   }
   digitalWrite(led0, LOW);
   Serial.println("scan");
   delay(30);
}

```

Yet, even though I have 'if' statements, the code still gets executed, as shown in my monitor:

Startup Completed!

```
state0
hstate1
istate2
jstate3
kstate4
lstate5
mstate6
nstate7
state8
scan
state0
hstate1
istate2
jstate3
kstate4
lstate5
mstate6
nstate7
state8
scan

```

Are there any hints to what could be going on? I reformatted the code for readability, but it is pretty much the same as before. Also, I am not using pin 0 or one. I am using 13 for onboard LED.

# Answer
> 1 votes
Microcontroller pins tend to read LOW when left floating (but not always!). However, pin 1 is used to communicate with the USB-UART converter, and I believe it is set HIGH in the idle state. So assuming you are not pressing any buttons, keys 2-8 will be in the LOW state by default, but key 1 will be HIGH. Hence when `defaultCase = HIGH;`, the first `if` is triggered. When `defaultCase = LOW;` all `if`'s but the first one fire up. Solution — don't use digital pin 1 (edit: avoid pin 0 and maybe 13 as well).

Edit: The answer above refers to the original code without the pull-up resistors enabled.

---
Tags: arduino-uno, programming
---


title: Can now() roll over just like millis()?

text:
# Question
Title: Can now() roll over just like millis()?
I'm using now() and millis() to trigger events after a certain time has passed. I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.

However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?

# Answer
> 3 votes
If `now()` is from the `TimeLib.h` library, then this definition:

```
typedef unsigned long time_t;

```

indicates time\_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.

This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a `time_t` as a **signed** 32-bit integer, and thus experiences this rollover earlier, in year 2038.

All of this depends on how/where the type `time_t` is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.

# Answer
> 6 votes
`now()` is a function that is specific to *Intel Curie* based boards.

It returns an `unsigned long` (which on a 32-bit system is the same as an `unsigned int`) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.

If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:

* Using subtraction to "wrap around" your calculations
* Not trying to calculate any periods longer than 136 years

# Answer
> 0 votes
Time represented in seconds from 1970-01-01 is called Epoch or Unix time. Function now() and similar functions in Arduino libraries returning 'epoch' use 32-bit representation. Some use the time\_t type defined in basic includes distributed with the compiler (types.h). On some compilers or in many time and RTC libraries the 32-bit type is signed allowing to represent time before 1970, on some system the type is unsigned.

The signed 32 bit type for epoch time overflows in 2038 (Year 2038 problem). The unsigned 32-bit overflows in 2106.

I use the TimeLib library and it uses the time\_t type defined on SAMD and ESP in type.h distributed with the compiler. ARM GCC has time\_t as long, which is signed 32 bit type. The same for ESP boards with xtensa compiler. time\_t for AVR is defined in the TimeLib library as unsigned 32bit type and overflows in 2016.

---
Tags: arduino-uno, arduino-mega
---


title: How to use stm32duino control 5110?

text:
# Question
Title: How to use stm32duino control 5110?
I want to use stm32duino to control 5110, I use the library http://www.rinkydinkelectronics.com/download.php?f=LCD5110\_Basic.zip

Before, I use arduino pro mini to control 5110 by this library, it works well. But when I use stm32, it fails. Whether this library is not suitable for stm32duino ? If so, which library is suitable for me ?

>

# Answer
> 1 votes
The library you linked to does not indicate it works for STM32 architecture. The display uses SPI, and each architecture has it's own way of implementing such peripherals.

There is this library: https://github.com/KenjutsuGH/Adafruit-PCD8544-Nokia-5110-LCD-library which is a port of the Adafruit 5110 driver to STMduino.

---
Tags: arduino-ide
---


# Question
Title: Shift register with relay board behaving erratically
I have a nodemcu connected to a shift register(https://www.amazon.de/gp/product/B07CHBYR7Z) to control an 8 channel relay board (https://www.amazon.de/Elegoo-Relaismodul-Optokoppler-Arduino-Raspberry/dp/B01M61VVGV). The realy board is connected to various pumps. The setup itself works quite well normally. However after some switching cycles or when I manually bridge the relay to activate a pump the shift register suddenly either doesnt react at all. Switches on everything or is off by one. I read that it might be possible that I have flow back from the relay coil so I added the diode over the gnd and vcc pin of the relay board. However that didnt help either. Can anybody tell me what I am doing wrong? I hope the schematic is legible.

# Answer
If this is a noise issue, there are a number of mitigating actions to consider. Also, consider that most if not all noise mitigating approaches are generic and may not apply to all situations.

1. It is almost always easier to mitigate noise at the source. Filtering the power & shielding are two approaches.
2. When laying out digital integrated circuits, it is common to include bypass or decoupling capacitors as near as possible to each integrated circuit. If unfamiliar with these, these capacitors go across the power pins of the integrated circuit.
3. If an electrically noisy environment is anticipated, making all communication leads and cables as short as possible prevents the likely hood of unexpected results.
4. If cables need to be long different communications methods such as balanced line or differential signalling should be considered.
5. Bring all power grounds to a single point. This mitigates current loops which can cause unexpected power voltage fluctuations.
6. Consider the power requirements and generally use a power supply that is rated for double to have a margin of safety.
7. Avoid running cables containing high power or switched power near or in parallel to cables containing low voltage logic.

For this particular application / design:

1. Likely the reversed bias diode on the relay power supply lines is not needed. There appears to be optical isolators on the relay board which should prevent the inductance of the relays from feeding back.
2. Verify you are creating the correct signal to the 74HC595 chip. Use the timing diagrams on page 8 of this ti.com 74HC595 specification sheet as a guide.
3. Consider the gauge of the power cables. Thinner wires over longer runs will drop the voltage proportional to the current demand. If all 8 relays are active, the current demand may be as much as an Amp.
> 1 votes

---
Tags: motor, nodemcu, relay, shift-register
---


# Question
Title: ESP8266 - 12F High consumption in led blink (with pictures)
My esp is consuming 180mA with a led blink. The same consumption happens when I put it in WIFI\_STA mode with the `WiFi.mode(WIFI_STA);` function.
**What should I do to reduce consumption?** Used AMS1117 CI as tension regulator.

**My code:**

```
void setup() {
  pinMode(2, OUTPUT); // pin number 2 is on board blue led
}

void loop() {
  digitalWrite(2, LOW); // blue led highlight with LOW level
  delay(100);
  digitalWrite(2, HIGH);
  delay(100);
}

```

**Why all this consumption?**

# Answer
The SDK library of the ESP8266 remembers on flash memory the mode, SSID and password of the last WiFi network it connected. At start or by enabling STA mode it tries to connect to that network. The SDK library is always part of the compiled sketch for the esp8266.

The esp8266 WiFi library has some functions to control this:
> 2 votes

---
Tags: arduino-uno, esp8266, wifi
---


# Question
Title: Arduino Force sensitive Resistor with an lcd
So we were asked to do something with a force sensitive resistor so naturally i thought of a project which takes the name of the main component which is force and applies it ,mine works by as you apply more and more pressure to the sensor it takes this value and displays it on an lcd but the display should be a bar graph which increases as the pressure increases. the problem is i dont really know how to do a bar graph on a 16x2 lcd. Please help. (my lcd has an I2c)

here is my code for the pressure sensor so far

```
int fsrAnalogPin = 0; // FSR is connected to analog 0
int fsrReading;      // the analog reading from the FSR resistor divider

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

void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}

```

ok so i improved my code and i finally got it this code displays the force detected by the fsr into a bar graph

```
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LcdBarGraphX.h>
#include<LcdBarGraph.h>

byte lcdNumCols = 20; // -- number of columns in the LCD

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);   // -- creating LCD instance

int fsrAnalogPin = 0; // FSR is connected to A0

// -- creating a 4 chars wide bars
LcdBarGraphX lbg0(&lcd, 16, 0, 0); // -- First line at column 0 and row 0 with 16 columns

void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  lcd.begin(4, lcdNumCols); // start lcd with 2 rows and 16 columns
  lcd.clear();
  delay(100);
}

void loop(void) {
  lbg0.drawValue( analogRead(fsrAnalogPin), 9); // the 9  is the maximum range you want for pressure
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
  delay(100);
}

```

# Answer
> 1 votes
There's two ways you can do it: the *easy* way, and the *fancy* way.

The easy way really is easy. Since the display can only display characters you just display characters - enough to represent a bar graph.

If you have a display with "Rom Code A00"<sup>*</sup> then character 255 is a solid block (▇) so you just print between 0 and 16 of them in a row. 0 is 0% and 16 is 100%. (If you have ROM Code A02 then you could just use `#`, or custom design a character - see below).

```
Force:▒▒▒▒▒▒▒▒▒▒
▇▇▇▇▇▇▇▇▇▒▒▒▒▒▒▒

```

Or with `#`:

```
Force:▒▒▒▒▒▒▒▒▒▒
#########▒▒▒▒▒▒▒

```

The fancy way is to use the programmable characters facility. You would create 4 new characters that partially fill a block. Each character is 5 pixels wide, so creating a character with 1 column of pixels set (▏), one with 2 set (▍), 3 set (▌) and 4 set (▋) (you already have all 5 set on in character 255 if you have ROM Code A00 - otherwise define a 5th with all 5 columns on). Now you can be clever and work out:

1. How many full characters to print, and
2. Which of the extra characters to print on the end.

That gives you effectively 16\*5 (80) pixels of horizontal resolution (albeit with a small gap between each set of 5 pixels).

Exactly how you do whichever of those methods you choose is now up to you.

---

\*: ROM Code A00 is the character ROM with Japanese characters in the characters 128-255. ROM Code A02 has European accented characters instead.

# Answer
> 1 votes
From the Library Manager, install the LcdBarGraphX library by Balazs Kelemen.

There are several examples there as well.

---
Tags: arduino-uno, sensors, lcd, pressure
---


# Question
Title: Problem with tachometer using attachInterrupt and servo
So I am creating a tachometer using black/white detector sensor. Here's the code.

```
unsigned long WaktuOLD;
unsigned long WaktuNOW;
int Detection = HIGH;
int Counter = HIGH;
float HitungWaktu;
float HitungRPM;

void setup() {
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(3), rpm, RISING);
  WaktuNOW = millis();
}

void rpm() {
  Detection = digitalRead(3);
  if (Detection == HIGH && Counter == LOW) {
    WaktuNOW = millis();
    HitungWaktu = WaktuNOW - WaktuOLD;
    HitungRPM = 60 / (HitungWaktu / 1000);
    Counter = HIGH;
  } else if (Detection == HIGH && Counter == HIGH) {
    Counter = LOW;
    WaktuOLD = millis();
  }
}

void loop() {
  Serial.println(HitungRPM);
  delay(5000);
}

```

The code works well and it can read RPM correctly. And then from the same arduino, I am controlling a servo motor, in this case I am using GWS03N/STD/F, with this code :

```
#include <Servo.h>

Servo myservo;
int pos = 0;

void setup() {
  myservo.attach(9);
}

void loop() {
  myservo.write(90);
}

```

And this code works well too.

But, when I am trying to combine both codes, only the servo code is working well. The tachometer reading is not correct (the reading must be around 1000-1500rpm, but now it reads 3000-30krpm). I am already trying to change my tachometer interrupt to pin 2 or 3, and servo to 3, 5, 6, and 9 but still the same.

So what is wrong in here. Thank you so much.

This is my code when combining both codes.

```
#include <Servo.h>

Servo myservo;
int pos = 0;
unsigned long WaktuOLD;
unsigned long WaktuNOW;
int Detection = HIGH;
int Counter = HIGH;
float HitungWaktu;
float HitungRPM;

void setup() {
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(3), rpm, RISING);
  WaktuNOW = millis();
  myservo.attach(9);
}

void rpm() {
  Detection = digitalRead(3);
  if (Detection == HIGH && Counter == LOW) {
    WaktuNOW = millis();
    HitungWaktu = WaktuNOW - WaktuOLD;
    HitungRPM = 60 / (HitungWaktu / 1000);
    Counter = HIGH;
  } else if (Detection == HIGH && Counter == HIGH) {
    Counter = LOW;
    WaktuOLD = millis();
  }
}

void loop() {
  Serial.println(HitungRPM);
  myservo.write(90);
  delay(5000);
}

```

# Answer
Your problem is probably that of interrupt conflicts.

The 8-bit Arduinos don't have any concept of interrupt priorities. When one interrupt routine is running it is impossible for any other interrupt routine to run until that first one has finished.

Interrupts have a "natural call priority" in that lower numbered pending interrupts will be called in preference to higher numbered ones, however that doesn't mean that they can interrupt each other.

The problem here is that the servo library uses a timer (and its associated interrupt) to generate the waveform. That uses a lot of interrupt calls running all the time - and while they are running your external interrupt can't be called - at least not until the currently executing timer interrupt completes, at which point your external interrupt handler will be called since it is the highest priority.

So the results you get with all that delaying are pretty meaningless.

So what can you do? Well, there's a number of options - all of which involve *not* using interrupts.

* You could not use the Servo.h library and instead reconfigure the hardware PWM to the right frequency and use that for the servo
* You could use one of the timers with an external clock source to count your tacho pulses (I think Timer 1 has that ability on the Uno)

Or even better: do both. That would give you the most efficient system whereby the main CPU is only involved in getting the count from the timer periodically, and adjusting the PWM value for your servo. The rest is then done by hardware completely asynchronously.

Of course, for this you will want to study the datasheet so you know how to configure the various hardware modules.
> 2 votes

# Answer
All of those variables that are accessed inside the ISR need to be declared as volatile.

You are using a RISING interrupt, so there should be no need to test the pin in the ISR. You can be confident that it went HIGH for the interrupt to be run.
> 0 votes

---
Tags: arduino-uno, interrupt, servo
---


# Question
Title: Stop and continue loop by using boolean flag for traffic light
By using boolean and flag, I can now control the green light but the program cannot repeat or loop the sequence for traffic light from red to yellow to green. If I don't use flag, the sequence red-yellow-green LED can be looped but I can't control and trigger green light on app.

My current project also serial communicate from NodeMCU to Arduino.

```
#include <SoftwareSerial.h>

SoftwareSerial nodemcu(2,3);
long int data;

boolean start = true;

void setup() {
  pinMode(7,OUTPUT);//greenbulb
  pinMode(8,OUTPUT);//yellowbulb
  pinMode(9,OUTPUT);//redbulb

Serial.begin(9600);
nodemcu.begin(9600);

}

void changeLights()
{
  digitalWrite(7,LOW);// greenbulb
  digitalWrite(8,LOW); // yellowbulb
  digitalWrite(9,HIGH);// redbulb
  delay(7000);

  digitalWrite(7,HIGH);// greenbulb
  digitalWrite(8,LOW);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(5000);

  digitalWrite(7,LOW);// greenbulb
  digitalWrite(8,LOW);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(1000);
  digitalWrite(7,HIGH);// greenbulb
  digitalWrite(8,LOW);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(1000);
  digitalWrite(7,LOW);// greenbulb
  digitalWrite(8,LOW);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(1000);
  digitalWrite(7,HIGH);// greenbulb
  digitalWrite(8,LOW);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(1000);

  digitalWrite(7,LOW);// greenbulb
  digitalWrite(8,HIGH);// yellowbulb
  digitalWrite(9,LOW);// redbulb
  delay(2000);
}

void loop() {

if ( nodemcu.available() > 0 )
{
  data = nodemcu.parseInt();
  delay(100);
  Serial.println(data);

      if (( data == 10) && (start == true)){
           changeLights();
            start = false;
      }

      if (( data == 11) && (start == false)){
      digitalWrite(7, HIGH);
      digitalWrite(9, LOW);
      digitalWrite(8, LOW);
            start = true;
      }
}
}

```

# Answer
> 0 votes
This is not an answer (that is looking at the BlinkWithoutDelay as Juraj mentioned), but I want to provide a way how to greatly reduce your program and use this method in future.

You are repeating

```
digitalWrite(7,LOW);// greenbulb
digitalWrite(8,HIGH);// yellowbulb
digitalWrite(9,LOW);// redbulb
delay(2000);

```

A lot, with variations of LOW/HIGH and the delay time. Instead, use a function that has parameters:

```
void changeLight(int green, int yellow, int red, int delayTime)
{
    digitalWrite(7, green);
    digitalWrite(8, yellow);
    digitalWrite(9, red);
    delay(delayTime);
}

```

And you can call it by

changeLight(LOW, HIGH, LOW, 2000);

You can do this for all of the 4 line repeats.

---
Tags: nodemcu
---


# Question
Title: Will this sketch eventually fail because of integer limit issue?
I am a novice in Arduino programming and I'm setting up an Arduino controlled, underwater time-lapse camera to take a picture every 2 hours. It's going in the ocean for a month and I want to be sure that the code will not fail because of the upper limit that normal integers can go. The Arduino simply switches on a relay (connected to the LED\_PIN 11) and the camera does the rest, using a script from the awesome Canon Hackers Development Kit C.H.D.K.

I've tried several variations of sketch, some using simple delay, some with millis and some with counters that print what increment the loop it up to.

One of my fast running test sketches, that used a counter, stopped prematurely, I suspect due to hitting the integer limit but I'm not sure if this only occurred due to the fact that it had a counter in the sketch. So I've gone back to the simplest sketch I can find hoping it will not have this issue.

I think I read that once the integer limit is reached, the sketch will simply restart. Or maybe it will become unpredictable. I'd rather the former than the latter.

Any suggestions would be welcome.

I am sure there are many ways to go about this but I'm looking for the simplest and most robust one I can find, so that I can adjust the async timing easily ie. loop starts CameraOn for 10 seconds CameraOff for 2 hours Loop repeats

thanks in advance for your consideration

Here's the sketch I'm testing right now.

```
#define LED_PIN 11
#define LED_OFF 7200000     // 2 hours in millis
#define LED_ON  8000       // 6 seconds in millis

unsigned long ms;        //time from millis()
unsigned long msLast;    //last time the LED changed state
boolean ledState;        //current LED state

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

void loop(void)
{
    ms = millis();
    blinkLED();
}

void blinkLED(void)
{
    if (ms - msLast > (ledState ? LED_OFF : LED_ON)) {
        digitalWrite(LED_PIN, ledState = !ledState);
        msLast = ms;
    }
}

```

==================================================================

Okay, I've come up with a new, much simpler sketch based on delay. Can someone please tell me if this is more robust in terms of continued looping for weeks on end?

```
#define LED_PIN 11

void setup()
{
   Serial.begin(9600);
   pinMode(LED_PIN, OUTPUT);
   digitalWrite(LED_PIN, HIGH);
}

void loop()
   {
       delay(7200000);                 // 2 hours in millis
       digitalWrite(LED_PIN, LOW);
       delay(8000);                    // 8 seconds in millis
       digitalWrite(LED_PIN, HIGH);

   }

```

# Answer
No, the sketches will not fail or work incorrectly. The Arduino "delay()" function calls the "micros()" function for timing. The "micros()" function uses the Atmel's TIMER0 clock and waits for 1000 microseconds (1 milliseconds) each iteration. The TIMER0 overflows about every 70 minutes, but the program code used in the "delay()" function handles that overflow correctly.
> 2 votes

---
Tags: arduino-uno, programming, sketch
---


# Question
Title: 5 switches, 5 leds, 5 tones, in an Array
The idea is when a switch is pushed, the corresponding tone will be played as well as lighting up the corresponding LED. I have the circuit set up to where each array matches another, for example Switch one will play tone 1 and light LED 1. When the switch is released the LED turns off and the tone no longer plays.

However I have to use an Array for the sketch instead of declaring each individual switch, led, and tone. My issue is when I compile the code, I get the error message "i" is not declared. Not sure where my error is within the for loop in the setup portion of the sketch.

I tried following the example from the Exploring Arduino web page but it did not help.

```
#define NOTE_C   262 //HZ
#define NOTE_D   294 //HZ
#define NOTE_E   330 //HZ
#define NOTE_G   392 //HZ
#define NOTE_A   440 //HZ

const int SPEAKER = 9;   //speaker on pin 10
int LED[5] = {13, 12, 11, 10, 8};   //led pins
int ledcount = 5;
int buttonState;
int buttonState1;
int buttonState2;
int buttonState3;
int buttonState4;

//Button Array
int Buttons[5]= {3, 4, 5, 6, 7};
int ButtonCount = 5;
const int numButtons = sizeof(Buttons) / sizeof (Buttons[0]);

//Tone Note Array
int Notes[5] = {NOTE_C, NOTE_D, NOTE_E, NOTE_G, NOTE_A};

void setup()
{
  for (int i = 0; i < sizeof (Buttons) / sizeof(Buttons[0]); i++){
  pinMode(Buttons[], INPUT);
}
  for (int i = 0; i < sizeof (LED) / sizeof (LED[0]); i++);{
  pinMode(LED[], OUTPUT);
}
  for (int i = 0; i < numButtons; i++){
  pinMode(Buttons[i], INPUT);
  debouncer[i].attach(Buttons[i]);
  debouncer[i].interval(100);
}
  buttonState = digitalRead(Buttons[0]);
  buttonState1 = digitalRead(Buttons[1]);
  buttonState2 = digitalRead(Buttons[2]);
  buttonState3 = digitalRead(Buttons[3]);
  buttonState4 = digitalRead(Buttons[4]);
}

void loop()
{

  if (buttonState == HIGH)
  { tone(SPEAKER, Notes[0]);
  digitalWrite(LED[0], HIGH);
  }
  else if (buttonState1 == HIGH)
  {tone(SPEAKER, Notes[1]);
  digitalWrite(LED[1], HIGH);
 }
  else if (buttonState2 == HIGH)
  {tone(SPEAKER, Notes[2]);
  digitalWrite(LED[2], HIGH);
 }
  else if (buttonState3 == HIGH)
  {tone(SPEAKER, Notes[3]);
  digitalWrite(LED[3], HIGH);
 }
  else if (buttonState4 == HIGH)
  {tone(SPEAKER, Notes[4]);
   digitalWrite(LED[4], HIGH);
 }

  else
 {
  digitalWrite(LED[5], LOW);
  noTone(SPEAKER);
 }
}

```

# Answer
You have a rogue `;` here:

```
  for (int i = 0; i < sizeof (LED) / sizeof (LED[0]); i++);{
  pinMode(LED[], OUTPUT);                                 ^------HERE
}

```

That is terminating the `for`, making it empty, and the following block is a completely different scope.

Another thing I spotted - you aren't putting `i` into your array index `LED[]` (should be `LED[i]`). The same is true with Buttons\[\].

However, on a different subject, this:

```
buttonState == digitalRead(Buttons[0]);
buttonState == digitalRead(Buttons[1]);
buttonState == digitalRead(Buttons[2]);
buttonState == digitalRead(Buttons[3]);
buttonState == digitalRead(Buttons[4]);

```

is pretty meaningless. You are comparing values and throwing away the result.

In a similar vein:

```
if (buttonState = Buttons[0])

```

stores the current value of Buttons\[0\] into buttonState and succeeds if `Buttons[0]` is anything other than 0. The same goes for all the others.

You need to sort out your comparisons (`==`) and your assignments (`=`) and also sort out what you think you are doing with all those buttonStates at the top of loop.
> 4 votes

---
Tags: arduino-uno, led, array
---


# Question
Title: My brand new LCD screen doesn't display anything, even though there is no code errors?
I have a LCD screen, and I wanted to use it with a Simon Says game that I am making. I tried the tutorial on the Arduino website, but it doesn't work. Then I tried another tutorial on Adafruit. On this one, the LCD screen seemed brighter which is good, but it also doesn't work.

**What it is supposed to look like:**

**My code:**

```
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  lcd.print("Test!");
  delay(500);
  lcd.clear();
  delay(500);
}

```

I have verified that the wiring is correct on the official version and the Adafruit version, and my screen is brand new from the kit, so what is wrong?

**Edit 1:**

Let me define "doesn't work." I can turn the potentiometer, but nothing changes. I can't even see white rectangles or even a single pixel on the display. It is blank. Absolutely nothing to see other than the blacklight, which does work.

**Edit 2:**

Turns out that the diagram was wrong. Needed to move the potentiometer 1 pin to the right, now it works!

# Answer
> 4 votes
Turns out that the diagram was wrong. Needed to move the potentiometer 1 pin to the right, now it works!

---
Tags: arduino-uno, lcd
---


# Question
Title: How to connect Arduino to headphone jack?
I would like to connect a headphone jack to my Arduino and make it as an output. I mean I would simply send some simple beeps.

I know that there is a breadboard friendly headphone jack, but I don't know how to wire it. I really don't know if I can simply connect the Arduino to the headphone jack, or I will need some resistors, etc. Will I need some voltage measurements?

Also, can I do this simply by connecting the parts of the jack ( right, left, GND) to the Arduino?

So could you please help me with this?

# Answer
> 4 votes
This project connects the headphones directly to a digital pin. Here is the schematic:

I would, however, be more cautious and add a limiting resistor. The output of an Arduino pin should be limited to 20mA as stated here. So, using

> V=I\*R
>
> 5 = 0.02 * R
>
> R = 5 / 0.02
>
> R = 250ohms

So I would add a ~250ohm resistor in series with the head phone. Especially if I were debugging my code. That is, in case I accidentally left the output pin high for an extended period of time.

The head phones should have some DC resistance. If the sound is not loud enough you might measure that DC resistance of the head phones and subtract it from the 250 ohm resistance calculated above and use a limiting resistor of that value instead.

# Answer
> 0 votes
I had the same problem and here how I figured out a solution,

Assume your stereo jack is connected to the folowing pins; Pin 9 = Left stereo Pin 10 = Right stereo GND = Ground

The solution relies on using arduinos inner circuitry. Pin 9 and Pin 10 are our pins to control left and right stereo sounds. We need a third pin which will be the main output source for stereo both(left and right) condition.

Say this pin be Pin8. Connect Pin8 to Pin9 and Pin10 by two resistors of 1kOhm or similar depending on your sound level choice.

When you seet pin8 mode to OUTPUT, pin 9 and pin 10 modes to INPUT, and when you play a tone at pin8 as tone(pin8,duration,frequency) will play stereo on the headphone.

On the other hand if pin9 is set to OUTPUT and pin10 set to INPUT, playing tone at pin8 will flow the current through right pin of the stereo jack, right sound.

Similarly if pin10 is set to OUTPUT and pin9 is set to INPUT,and tone played at the pin8 send the current through left stereo jack connected to pin9, left sound is played.

Hope this helps.

---
Tags: arduino-uno, audio, sound
---


# Question
Title: Neo 6M GPS Module does not work properly inside own sketch
I am doing a project right now that involves a Neo 6M GPS module, a micro sd card module and 6 BH1750 light sensors. All the modules work fine when testing them standalone, especially the GPS module works as it should with TinyGPS++ example sketches. When i run the "DeviceExample" sketch, it takes around 6 seconds to revieve time and around 10 seconds to recieve the location. However in my own sketch it only updates time every 3 or more seconds as well as i think it also updates location very slow.

Sometimes it even works for a short time, sometimes it never works, no matter how long the sketch runs. Here is an example log: As you can see, the sketch did not retrieve full date 20 secs after starting, but time is updating every second. Yet you can see that the time isn't updated anymore 5 seconds before the module is retrieving location and then the update interval gets slowed down, even though the module itself still indicates the update interval of around .5-1 second.

The Neo 6M GPS module is connected directly to RX,TX,GND,VCC and works fine with the example sketches. Has anybody a solution to this?

```
ms(), longitude, latitude,month,day,year,hour,min,sec,centisecs,alt,6 lux values
17642, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
17980, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
18333, 0.000000, 0.000000,0,0,2000,22,26,13,95,0.00,106,106,6,0,3,106,
18803, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,106,106,6,0,3,93,
19131, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,33,33,6,0,3,0,
19530, 0.000000, 0.000000,0,0,2000,22,26,14,95,0.00,0,0,6,0,3,40,
19956, 0.000000, 0.000000,0,0,2000,22,26,15,95,0.00,106,106,6,0,3,106,
20311, 0.000000, 0.000000,0,0,2000,22,26,15,95,0.00,106,106,6,0,3,106,
20787, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21114, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21504, 0.000000, 0.000000,0,0,2000,22,26,16,95,0.00,106,106,6,0,3,106,
21942, 0.000000, 0.000000,0,0,2000,22,26,17,95,0.00,106,106,6,0,3,106,
22292, 0.000000, 0.000000,0,0,2000,22,26,17,95,0.00,106,106,6,0,3,106,

```

...

```
240540, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
240869, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
241249, 0.000000, 0.000000,10,14,2018,22,29,56,95,0.00,106,106,6,0,3,106,
241697, 0.000000, 0.000000,10,14,2018,22,29,57,95,0.00,106,106,6,0,3,106,
242035, 0.000000, 0.000000,10,14,2018,22,29,57,95,0.00,106,106,6,0,3,106,
242531, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,109,109,6,0,3,106,
242859, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,106,106,6,0,3,106,
243238, 0.000000, 0.000000,10,14,2018,22,29,58,95,0.00,106,106,6,0,3,106,
243687, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244016, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244425, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
244892, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
245260, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
245754, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
246083, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
246494, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,109,6,0,3,106,
246947, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,109,109,6,0,3,106,
247320, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
247820, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,109,106,6,0,3,106,
248160, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
248676, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249027, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249425, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,106,6,0,3,106,
249889, 0.000000, 0.000000,10,14,2018,22,29,59,95,0.00,106,109,6,0,3,106,
250253,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
250768,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
251097,xxxxx,xxxxx,10,14,2018,22,30,6,0,0.00,106,106,6,0,3,106,
251608,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,109,106,6,0,3,106,
252021,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
252412,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
252883,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,109,106,6,0,3,106,
253248,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
253765,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
254094,xxxxx,xxxxx,10,14,2018,22,30,8,0,646.30,106,106,6,0,3,106,
254608,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,109,6,0,3,106,
255020,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,
255412,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,
255882,xxxxx,xxxxx,10,14,2018,22,30,11,0,646.30,106,106,6,0,3,106,

```

Here is the sketch:

```
////
//initialising constants
static const  int out_min = 5;
static const  int out_max = 10;
static
const uint8_t RXPin = 0,
              TXPin = 1;
static
const uint16_t GPSBaud = 9600;
static
const uint16_t chipSelect = 4;
//initialising Objects
SoftwareSerial ss(RXPin, TXPin);
TinyGPSPlus gps;

BH1750 active_sensor(0x23); // We will use this adress for stating the active sensor
BH1750 inactive_sensor(0x5C);
SdFat sd;
SdFile file;

//initialising variables for collecting data
float lng_;
float lat_;

String month_ = "";
String day_ = "";
String year_ = "";

uint16_t lux_ = 0;
uint8_t hour_ = 0;
uint8_t min_ = 0;
uint8_t second_ = 0;
uint8_t centisecond_ = 0;
float altitude_ = 0;

unsigned long runtime_ = 0;

uint16_t values[6];
char buf[6];
char data_buffer[12];
char fileName[13] = FILE_BASE_NAME "00.csv";
uint8_t lines = 0;

void setup() {
  digitalWrite(2, HIGH);
  pinMode(2, INPUT);
  Serial.begin(115200);
  Wire.begin();

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

  for (int i = out_min; i <= out_max; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  ss.begin(GPSBaud);

  if (active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
   Serial.println(F("BH1750 Advanced begin"));
  } else {
    Serial.println(F("Error initialising BH1750"));
  }
}

void(* resetFunc) (void) = 0;
void loop() {

  while (ss.available() > 0)
    if (gps.encode(ss.read())) {
      digitalWrite(3, HIGH);
    }
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    while (true);
  }
  if (gps.location.isValid()) {
    lat_ = gps.location.lat();
    lng_ = gps.location.lng();
  }

  if (gps.date.isValid()) {
    day_ = gps.date.day();
    month_ = gps.date.month();
    year_ = gps.date.year();
  }

  if (gps.time.isValid()) {
    hour_ = gps.time.hour();
    min_ = gps.time.minute();
    second_ = gps.time.second();
    centisecond_ = gps.time.centisecond();
    altitude_ = gps.altitude.meters();
  }

  int i;
  for (i = 5; i <= 10; i++) {
    digitalWrite(i, LOW);
    switch (i) {
      case 7:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
      case 8:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
      case 9:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
      case 10:
        active_sensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
      case 5:
        active_sensor.begin(BH1750::CONTINUOUS_LOW_RES_MODE);
      case 6:
        active_sensor.begin(BH1750::CONTINUOUS_LOW_RES_MODE);
    }
    delay(15);
    lux_ = active_sensor.readLightLevel();
    values[i - 5] = lux_;
    digitalWrite(i, HIGH);
  }
  delay(10);
  digitalWrite(3, LOW);
  delay(5);
  file.print(millis());
  file.write(',');
  dtostrf(lng_, 9, 6, data_buffer);
  file.print(data_buffer);
  file.write(',');
  dtostrf(lat_, 9, 6, data_buffer);
  file.print(data_buffer);
  file.write(',');

  file.print(month_);
  file.write(',');
  file.print(day_);
  file.write(',');
  file.print(year_);
  file.write(',');

  file.print(hour_);
  file.write(',');
  file.print(min_);
  file.write(',');
  file.print(second_);
  file.write(',');
  file.print(centisecond_);
  file.write(',');
  file.print(altitude_);
  file.write(',');

  for (int i = 0; i <= 5; i++) {
    file.print(values[i]);
    file.write(',');
  }
  file.println();
  lines++;

  int state = digitalRead(2);

}

```

Example Output:

# Answer
You can't (and certainly *shouldn't* ever even try to) use SoftwareSerial on pins 0 and 1. Not when you're using `Serial`, since they are the same pins.

Pick a different pair of pins for your GPS connection.
> 1 votes

---
Tags: gps, logging
---


title: I2C LCD displaying weird characters

text:
# Question
Title: I2C LCD displaying weird characters
I have connected an LCD with an I2C backpack to my Arduino Uno but it prints the wrong characters. The weird thing is that it worked fine for a while and when I updated the code (but didn't change anything to do with the LCD) it started displaying the wrong characters. This happened earlier today too. That time, reinstalling the LiquidCrystal library worked, but it doesn't now.

Does anyone know what might be the problem so I can fix it permanently?

The LCD's SDA and SCL are connected to A4 and A5 respectively and I'm running this code:

```
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16     chars and 2 line display

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
}

void loop()
{
    }

```

and this is what's displayed on the screen:

# Answer
If you look up the ASCII codes for what you sent vs what was displayed, and also look at "Table 4 Correspondence between Character Codes and Character Patterns (ROM Code: A00)" in an HD44780U spec sheet, you will find hexadecimal values like the following.

* e 65, V 56
* l 6C, ニ C6
* o 6F, θ F2
* o 6F, π F7
* r 72, & 26
* d 64, B 24
* and so forth.

It appears that the high nibble of what you sent is being used as the low nibble of what is displayed, and the low nibble is being used as the high, but with some bits sometimes going wrong. Note, a space is 0x20, and the reverse of that is 0x02, which would access a character from the character-generator RAM, which will contain random bits and produce a random blob as in your picture.

If your mis-specification of display size (20, 4 vs 16, 2) isn't responsible for the problem, then maybe there is a hardware problem with the backpack you've soldered on to the LCD. Look at it under a bright light, using a binocular parts-examination microscope if you've got one, and see if there are loose solder particles, extra solder flux, or loose solder connections on that board. If you have an oscilloscope, check if your I2C signals are clean and have full swing.
> 7 votes

# Answer
From what I can see, it seems, in this line:

```
    LiquidCrystal_I2C lcd(0x27,20,4);

```

wrong parameters have been passed to the constructor. The last two arguments are supposed to indicate the number of columns and rows on the screen. Your screen has 16 columns and 2 rows, whereas you passed 20 columns and 4 rows to the constructor. This could be the problem.
> 2 votes

# Answer
I experienced this while using a STM32f429 discovery board, and I found out there are two reasons that this happens.

1. when using a fast microcontroller (180 MHz clock), if you send I2C packet consecutive LCD may not be that fast to understand it and as James said in other post LCD may lose some packet and get confused. To cope with that you have to put a delay between your packet.
2. If you reset your MCU board while your LCD is writing something without cutting off power, LCD may get first nibble but lose the second 4bit nibble and interprets your initialize data as second nibble data to show on LCD and simply get confused. If LCD had something like software reset it could help but I did not find anything in datasheet. Though I think there is a hardware walkaround

if you could disconnect K in 8050 transistor and connect LCD Ground to that point then you could disconnect and connect LCD power just by toggle P3 pin through PCF8574 IC when you are initializing your LCD.actually you will lose some control over LCD backlight. you can consider R/W pin too because almost all firmware just write on LCD and simply lower this pin. I bring the purpose schematic in below

in Module simply disconnect ground pin from module and LCD and in LCD board connect K pin to ground as i put the image here

in your Code When you are Initializing write 0xF7 in I2C and Delay for 200 ms then write 0 for and delay 100 ms then do your other Initialization Sorry for bad English
> 2 votes

---
Tags: arduino-uno, i2c, lcd
---


title: Output clock signal on MKRZERO

text:
# Question
Title: Output clock signal on MKRZERO
I have to port a Project written for an Arduino Micro to an MKRZERO.

It communicates via UART with an IC and should also provide a clock signal.

The former code I have used is this:

```
#define OUTPUTPIN 8
#define CLOCKOUTPIN 5
#define CONTRLEDPIN 13

void Setup() {
pinMode(OUTPUTPIN, OUTPUT);
// Needed for initialization
digitalWrite(OUTPUTPIN, HIGH);
// set clock PIN
pinMode(CLOCKOUTPIN, OUTPUT);
// sets PIN for internal LED
pinMode(CONTRLEDPIN, OUTPUT);

TCCR3A = (1 << COM3A0);
TCCR3B = ((1 << WGM32) | (1 << CS30));
TIMSK3 = 0;
OCR3A = 7;
}

```

As the MKRZERO uses a different IC the registers are not the same. I've waded through the data sheet document but cannot find something similar.

Does somebody have any experience with the MKRZERO and can help me with this?

# Answer
The IC on the MKRZERO is an Atmel SAMD21. Look up the datasheet and read the section on timer counter. Yes, it's a long document, but you will find all of the information there.
> 1 votes

---
Tags: arduino-zero
---


title: My Arduino IDE stuck on uploading

text:
# Question
Title: My Arduino IDE stuck on uploading
So for a while I get some Arduino IDE problem which I can't solve. When I try to upload any kind of code to my Arduino, Arduino IDE just stay at "Uploading". I tried to use another Arduino but I get the same problem. I used Pro Mini, Nano and Uno but it's the same. Then I decided to upload my code from another PC but I get the same problem and so I can't find where the problem is.

Is the problem in all my Arduinos or in my computers?

Note: The code which I was uploading, was from Arduino examples.

I am using Windows 10 Pro x64 and in my console I get this error:

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

```

# Answer
> 0 votes
To solve this problem, you should google the error message "avrdude: stk500\_recv()". The web shows countless records where this error comes up. The message indicates that the serial communication has malfunctioned, but incorrect driver or serial port is not the only way this can happen.

During upload, (1) Have you tried to reset the arduino, (2) ensure that the RX/TX pins are not in use?

# Answer
> 0 votes
You tried different PCs and different Arduinos, so the only constant is the Code and the USB cable I guess:

1. Try another USB cable
2. Try to upload another code

Do you have the same problem with any code you try to upload?

---
Tags: arduino-ide, uploading
---


# Question
Title: Sending arduino signal to another arduino
I'm working on a project which consists of 2 different function. since the arduino only can do 1 function so i decide to use 2 arduino instead. my idea is 1st arduino will give a output and the sketch on the 2nd arduino will run Only after the input given from the 1st arduino. So can i make a digital output which will be send to the input of 2nd arduino?

if it could be, i already make a code for the 2nd arduino which will be run after there was an input from the 1t arduino:

```
//define the input/output pins
#define FLOAT_SWITCH_PIN 2
#define PUMP_1_PIN 4
#define LED_PIN 7
#define output1starduino 3
//setup runs once
void setup()
{

  pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
  pinMode(output1starduino, INPUT_PULLUP);

  //setup output pins for relays/pumping station and LED board
  pinMode(PUMP_1_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

}

//loop() runs indefinitely
void loop()
{

  if(digitalRead(output1starduino) == HIGH) // output from 1st arduino
  if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
  {
     digitalWrite(PUMP_1_PIN, HIGH); //turn on the pump
     digitalWrite(LED_PIN, HIGH);    //turn on the LED
  }

  {
     digitalWrite(PUMP_1_PIN, LOW); //turn off the pump
     digitalWrite(LED_PIN, LOW);    //turn off the LED
  }
}

```

as i write on the line, the "output1starduino" which an digital output from the first arduino. Is this the right way for me to write if i want the program here to run only right after the output from 1st arduino given?

\*** this is the code of first arduino which will be sent to the 2nd arduino

```
int motorPin = 3; // motor pengisian (m1)
int blinkPin = 4; //
int motor1 = 5;// motor pembuangan
int motorklorin = 6;// pam topap
int switch1 = 2;// switch float
int indicator1 = 7;
int indicator2 = 8;
int indicator3 = 9;
int output1starduino = 2;
void setup()
{
  pinMode(motorPin, OUTPUT);
  pinMode(blinkPin, OUTPUT); // penujuk fasa pengisian
  pinMode(motor1, OUTPUT);
  pinMode(motorklorin, OUTPUT); // MOTOR UNTUK topap
  pinMode(switch1, INPUT_PULLUP);// PELAMPONG
  pinMode(indicator1, OUTPUT);// lampu penunjuk fasa pembuangan
  pinMode(indicator2, OUTPUT);// lampu penunjuk topap
  pinMode(indicator3, OUTPUT);// lampu menunggu
  pinMode(output1starduino, OUTPUT); // KELUARAN KE ARDUINO 2
}

void loop()

{
  digitalWrite(motorPin, HIGH); // turn on the motor
  digitalWrite(blinkPin, HIGH); // turn on the LED
  digitalWrite(motor1, HIGH);// on lampu
  digitalWrite(motorklorin,HIGH);
  delay(1000);        //

  digitalWrite(motorPin, HIGH);  //
  digitalWrite(blinkPin, HIGH);  // penunjuk fasa pembuangan hidup
  digitalWrite(motor1, LOW);// motor pembuangan jalan (air start turun/pembuangan
  digitalWrite(motorklorin,HIGH);
  delay(180000);        //tempoh pembuangan

  digitalWrite(motorPin, LOW); // turn on the motor (motorisi balik air jalan/pengisian
  digitalWrite(blinkPin, LOW); //
  digitalWrite(motor1, HIGH);// filling motor on
  digitalWrite(indicator1, HIGH); //indicator
  delay(150000);        // duration filling

  digitalWrite(motorPin, HIGH);  // turn off the motor
  digitalWrite(blinkPin,HIGH);  // turn off the LED
  digitalWrite(motor1, HIGH);//
  digitalWrite(output1starduino, HIGH);
  delay(100000);        // multiply by 60000 to translate minutes to milliseconds
  }

```

# Answer
An arduino may not be as fast as a PC or phone, but it is VERY fast indeed (16,000,000 operations /sec). Unless the code for arduino #1 is incredibly complex, the one arduino should be able to do it all on its own. P.S. Please post the code for Arduino #1
> 1 votes

# Answer
Combine them like this - I moved the duplicate pins to other pins

```
//define the input/output pins
#define FLOAT_SWITCH_PIN 2
#define PUMP_1_PIN 4
#define LED_PIN 7
#define output1starduino 3

byte motorPin = 11; // motor pengisian (m1)
byte blinkPin = 12; //
byte motor1 = 5;// motor pembuangan
byte motorklorin = 6;// pam topap
byte switch1 = 2;// switch float
byte indicator1 = 13;
byte indicator2 = 8;
byte indicator3 = 9;
byte output1starduino = 10;

//setup runs once
void setup()
{

pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
pinMode(output1starduino, INPUT_PULLUP);

//setup output pins for relays/pumping station and LED board
pinMode(PUMP_1_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);

pinMode(motorPin, OUTPUT);
pinMode(blinkPin, OUTPUT); // penujuk fasa pengisian
pinMode(motor1, OUTPUT);
pinMode(motorklorin, OUTPUT); // MOTOR UNTUK topap
pinMode(switch1, INPUT_PULLUP);// PELAMPONG
pinMode(indicator1, OUTPUT);// lampu penunjuk fasa pembuangan
pinMode(indicator2, OUTPUT);// lampu penunjuk topap
pinMode(indicator3, OUTPUT);// lampu menunggu
pinMode(output1starduino, OUTPUT); // KELUARAN KE ARDUINO 2

}

//loop() runs indefinitely
void loop()
{

if(digitalRead(output1starduino) == HIGH) // output from 1st Arduino
{
digitalWrite(motorPin, HIGH); // turn on the motor
digitalWrite(blinkPin, HIGH); // turn on the LED
digitalWrite(motor1, HIGH);// on lampu
digitalWrite(motorklorin,HIGH);
delay(1000);        //

digitalWrite(motorPin, HIGH);  //
digitalWrite(blinkPin, HIGH);  // penunjuk fasa pembuangan hidup
digitalWrite(motor1, LOW);// motor pembuangan jalan (air start turun/pembuangan
digitalWrite(motorklorin,HIGH);
delay(180000);        //tempoh pembuangan

digitalWrite(motorPin, LOW); // turn on the motor (motorisi balik air jalan/pengisian
digitalWrite(blinkPin, LOW); //
digitalWrite(motor1, HIGH);// filling motor on
digitalWrite(indicator1, HIGH); //indicator
delay(150000);        // duration filling

digitalWrite(motorPin, HIGH);  // turn off the motor
digitalWrite(blinkPin,HIGH);  // turn off the LED
digitalWrite(motor1, HIGH);//
digitalWrite(output1starduino, HIGH);
delay(100000);        // multiply by 60000 to translate minutes to milliseconds
}

if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
{
 digitalWrite(PUMP_1_PIN, HIGH); //turn on the pump
 digitalWrite(LED_PIN, HIGH);    //turn on the LED
}

{
 digitalWrite(PUMP_1_PIN, LOW); //turn off the pump
 digitalWrite(LED_PIN, LOW);    //turn off the LED
 }
}

```
> -1 votes

---
Tags: pwm
---


title: Not enough memory

text:
# Question
Title: Not enough memory
I am making a simple calculator with Arduino Uno R3. It only has +, -, x and /.

I use 3 libraries:

1. This use for LCD with I2C module. Arduino-LiquidCrystal-I2C-library
2. This use for keypad 4x4. Chris--A/Keypad
3. And this: jamesgregson/expression\_parser

My code:

```
#include "expression_parser.h"
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3', '+'},
  {'4', '5', '6', '-'},
  {'7', '8', '9', '*'},
  {'.', '0', '=', '/'}
};

byte rowPins[ROWS] = {10, 9, 8, 7};
byte colPins[COLS] = {6, 5, 4, 3};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

String s = "";
char ex[16];

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
}

int cur = 0;
bool enter = false;

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

  if ((key != '=') && (key != NO_KEY) ) {
    if (!enter) {
      Serial.println(F("key"));
      if(key=='/')
        lcd.print(F("':'"));
      else
      if (key=='*')
        lcd.print(F("'x'"));
      else
        lcd.print(F("key"));
      s = s + key;
      cur++;
      lcd.setCursor(cur, 0);
    } else {

      lcd.setCursor(0, 0);
      lcd.print("");
      enter = false;
      lcd.setCursor(0, 0);
      cur = 0;
      lcd.print(F("key"));
      s = "";
      s = s + key;
      cur++;
      lcd.setCursor(cur, 0);
    }
  } else if (key == '=') {
    enter = true;

    if ((s[0] == '=') || (s[0] == '/') || (s[0] == '*') || (s[0] == '.')) {
      lcd.setCursor(0, 1);
      lcd.print("Error");
    } else {
      lcd.setCursor(0, 1);
      lcd.print("");
      s.toCharArray(ex, 16);
      Serial.println(F("s"));
      int re = parse_expression(ex);
      String check = String(re);
      if (check.length() > 15) {
        lcd.setCursor(0, 1);
        lcd.print("Overflow");
      } else {
        Serial.println(re);
        lcd.setCursor(0, 1);
        lcd.print("=");
        lcd.print(F("re"));
      }
    }
  }
}

```

I ran it and got error:

Global variables use 3302 bytes (161%) of dynamic memory, leaving -1254 bytes for local variables. Maximum is 2048 bytes. Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint. Error compiling for board Arduino/Genuino Uno.

So what should I do?

# Answer
> 3 votes
Your own declared global variables do not use up much space.

Watch out for using string, this can be extended during the flow of the program thus using more.

The problem is in the libraries.

What you can do:

* Leave out the include and related code per library to see which is using up a lot of global space.
* When you find out which causes problems, try to follow the internals of the library to see if there is some buffered memory that you can decrease.

If not, I'm afraid the only solution is to move to an Arduino with more memory (like the Arduino Mega which has 8 KB).

With the use of PROGMEM you can save some space on

```
char keys[ROWS][COLS] = {
  {'1', '2', '3', '+'},
  {'4', '5', '6', '-'},
  {'7', '8', '9', '*'},
  {'.', '0', '=', '/'}
};

byte rowPins[ROWS] = {10, 9, 8, 7};
byte colPins[COLS] = {6, 5, 4, 3};

```

Because it will be placed in Flash instead of SRAM, but it will save you just 24 bytes.

# Answer
> -1 votes
Move up to a '1284P based board. They have 16K of SRAM and 12 more IO pins, will give you plenty of room to add and expand into more functions later.

I offer '1284P boards in several form factors at www.crossroadsfencing.com/BobuinoRev17/

It is easy to add to the IDE with MCUdude's MegaCore https://github.com/MCUdude/MegaCore

---
Tags: arduino-uno
---


# Question
Title: How to post data to database using nodeMCU?
We created a website hosted by 000webhost and we're trying to post data from our nodeMCU to the database using the sketch below, but the database doesn't seem to show any received data. How do you fix this?

and below is the php code to rtecieve the data:

```
#include <ESP8266WiFi.h>

const char* ssid = "Jino";
const char* pass = "myinternet";
char server[] = "cdgresearch.000webhostapp.com";

WiFiClient client;

int led = 2;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid,pass);
  pinMode(led,OUTPUT);
  digitalWrite(led, HIGH);

  Serial.println("Connecting to: ");
  Serial.println(ssid);
  Serial.print("Connecting");

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

  delay(300);
  digitalWrite(led, LOW);
  Serial.println();
  Serial.println("Successfully connected to the network");
  Serial.print("NodeMCU IP Address: ");
  Serial.println(WiFi.localIP());

  if (client.connect(server, 80)){
    String data = "incoming=fromDuino&incoming2=FROMDUINO2";
    client.println("POST /tag.php? HTTP/1.1");
    client.println("Host: cdgresearch.000webhostapp.com");
    client.println("User-Agent: 8266/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.print("\n\n");
    client.println(data);
    client.stop();

    Serial.println("Connected to server");
    }
    else{
    Serial.println("Failed to Connect to server...");
    }

  client.stop();
  Serial.println("Disconnected from Server");
}

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

```

# Answer
> 0 votes
HTTP requires \r\n as line ending. println adds \r\n. So to print the host name to client use println and remove \n from the string. And replace `client.print("\n\n")` with `client.println(); client.println();` (or println the length and then use one println)

# Answer
> -1 votes
You are using POST method in the php script ($\_POST\['var'\]) and trying to pass parameters to the script by adding them in the URL. This addition of the parameters would work only if it were a GET method in place of a POST method.

Change wherever you have written POST to GET (Both in the php script and the node mcu code) and your data will be inserted into the database.

1) Change both the $\_POST\['var'\] to $\_GET\['var'\] in the php file.

2) Change client.println("POST /tag.php HTTP/1.1") to client.println("GET /tag.php?incoming=fromDuino&incoming2=fromDuino2 HTTP/1.1")

Also, you can go through this link to learn more about how to make a POST request. And can you show me the whole code or the classes that you have instantiated?

# Answer
> -1 votes
1st I would check each part i.e. First check your PHP script can insert by setting some values in the script i.e. incomming = "somejunk";

I assume the PHP include file connects to your DB and changes into the corresponding DB? I assume you have setup a user for the DB in say cPanel and set privileges

Your method of sending data is different to my working format... You are sending the data at the end rather than the beginning...

Also if you look at your server log you can see if the values get sent

```
if (client.connect(server, httpPort)) {
  // connected to resource
  // send data
  client.print("POST /dir/file.php?field1=");
  client.print(data1&field2=data2); // must be url encoded
  client.println(" HTTP/1.1");
  client.println("Host: www.domainname.com");
  // client.println("Content-Length: " + String(data.length())); // you dont need
  client.println("User-Agent: ESP8266");
  client.println("Connection: close");
  client.println();

```

---
Tags: esp8266, nodemcu
---


# Question
Title: My Serial plotter isn't working (arduino)
I'm trying to upload this code and it works properly but I can't see anything on my serial plotter

```
const int AnalogIn_Pin0=  A0;
const int AnalogIn_Pin1=A1;
const int Pwmout_PIN=11;
float AnalogIn_Val0=0;
float AnalogIn_Val1=0;
int Pwmout_Val=0;
float Error=0;
float ErrorInteg=0;
float Control=0;
float ControlFilt=0;
float kp=0.2;
float Pole =-10;
float Ki =0.01;
int deltaT=0.01;
int deltaT_ms=(int)deltaT*1000;

void setup() {
  pinMode (Pwmout_PIN,OUTPUT);
  Serial.begin (9600);
}

void loop() {
  AnalogIn_Val0=(float)constrain (analogRead(AnalogIn_Pin0),0,600);
  AnalogIn_Val1=0.97*AnalogIn_Val1+0.03*(float)analogRead(AnalogIn_Pin1);
  Error= (AnalogIn_Val0-AnalogIn_Val1);
  ErrorInteg=ErrorInteg+Error*deltaT;
  ControlFilt=kp*Error+Ki *ErrorInteg;
  Pwmout_Val= constrain (map ((int)ControlFilt,0,1023,0,255),0,220);
 analogWrite (Pwmout_PIN,Pwmout_Val);
 Serial.print(AnalogIn_Val0);
 Serial.print("");
 Serial.print(AnalogIn_Val1);
 Serial.print("");
 Serial.print( Pwmout_Val);
 delay (deltaT_ms);

}

```

# Answer
> 1 votes
You must have each set of data point (or points) on a separate line and if you are plotting more that one value you need a space or a tab between each value.

So to have 3 lines on your plot, I think you want this:

```
 Serial.print(AnalogIn_Val0);
 Serial.print(' ');
 Serial.print(AnalogIn_Val1);
 Serial.print(' ');
 Serial.println(Pwmout_Val);

```

The output in the serial monitor should be something like this:

```
123 456 789
234 567 901
...

```

---
Tags: arduino-uno, arduino-ide
---