text:
How to get average of 16bit ADC readings?
I have an Adafruit ADS1115 analog-to-digital converter, configured in single ended mode. I want to average over 3 sensor readings to increase the reading stability.
  //initialize variables
  int16_t rawData, ambient;
  int i=0;

  // start loop
  while(i<3) {
      rawData = ads.readADC_SingleEnded(0); //read from ADC
      // divide sensor reading by three
      // (doing so after summation will lead to an overflow)
      rawData=rawData/3;
      Serial.println(rawData); // print data to serial for debugging (OK)
      ambient+=rawData;
      i+=1;
      delay(100);
      Serial.println("I LIVVVVEEE"); // print text to serial for debugging (OK)
  }

  // Print signal (NOT OK)
  Serial.print("Ambient is ");
  Serial.println(ambient);

The "rawData" is printed correctly on the serial monitor. However, the value for "ambient" can be crazy: the resulting output is over an order of magnitude higher. Somehow, the summation doesn't seem to be performed correctly.

this is not avarege of 3 readings. it is a sum a of 1/3 of readings

If you are trying to average out three sensor ADC reading first you need to store and add them all then divide it by 3.
 int16_t rawData =0;
 int32_t avg=0,ambient=0;
  int i=0;

 while(i<3) {
      rawData = ads.readADC_SingleEnded(0); //read from ADC
      // divide sensor reading by three
      // (doing so after summation will lead to an overflow)
     Serial.println(rawData); // print data to serial for debugging (OK)
     avg += rawData;
      i++;
      delay(100);
      Serial.println("I LIVVVVEEE"); // print text to serial for debugging (OK)
  }
  abmient = avg /3;
  avg = 0;
  // Print signal (NOT OK)
  Serial.print("Ambient is ");
  Serial.println(ambient);

This approach is great for small numbers. However, the ADC is 16 bit. By adding three 16bit values, this may (can) lead to buffer overflow for "ambient".

@plasma, sum of 3 16 bit numbers will not run out of 32 bit

@Juraj there is nothing like that. I just made changes in his program.

appreciated....

you will actually get more stable readings if you take the median of the 3 readings instead of the mean. consider reading 12,13,5 when the true reading is 13. with avg you get 10 (err=3), but with median you get 12 (err=1). I used this method for a DMM project and it made a HUGE difference compared to my naive oversample+avg method... You can also adjust how many internal AD1115 samples are collected, and at the expense of reading time, get a more stable set of values from the get go.

@dandavis Its not necessary that always median will be the right value. It might happen in your case but I had tested it on ST controller where I take average of 4 readings and I get the expected value, though I calculated voltage using ADC, the error I got is about -0.01V from actual voltage.

Calculating a mean the way the OP does is absolutely valid. It doesn't make a difference wether the sum or the summands are divided by the number of values. Your code might fix the issue, but that's because you initialize the variables explicitly.

You forgot to initialize ambient to zero, so it got whatever happened to be in that place of memory when it got instantiated. Some unpredictable, seemingly random data.

are you saying that int16_t ambient; Serial.println(ambient, DEC); could show something besides 0?

@dandavis: Yes, absolutely. The value of ambient here is indeterminate. In some circumstances, using such a value can even lead to undefined behavior.


text:
Sending mouseX and mouseY from Processing to Arduino
I'm new to serial communication and trying to send mouseX and mouseY from Processing to Arduino. Serial monitor doesn't show anything.
Processing code:
import processing.serial.*;
Serial port;
void setup() {
  size(500,300);
  port = new Serial(this , Serial.list()[0], 9600);
}

void draw() {
   text("X Y mouse",250,50);
   if (port.available() > 0) {
    port.write(str(mouseX)+' '+str(mouseY));
   }
}

Arduino code:
int x = 0;
void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    x = Serial.read();
    Serial.print("I received: ");
    Serial.println(x);
  }
}

when I close Processing window and enter "ok" in Arduino serial monitor I see:

please add the snapshot of serial monitor with the data you are sending.

https://majenko.co.uk/blog/reading-serial-arduino

Only one program on your pc can communicate over the serial port at once. When processing is connected to it, the Serial Monitor is not ans vice versa

@Vaibhav There's nothing to show...unfortunately.

@chrisl if that means I can't use serial monitor, Can I use mouseX and mouseY data in my arduino program?

Sure can you use the mouse position on the Arduino. You rust have to send them to it via Serial and the Arduino code has to decode it correctly. Currently you are sending an ASCII string but decoding it as byte data. Finish your data, that you send with \n (newline). On the Arduino read the entire message  until you receive \n and put all received bytes into a string (or better a char array). Then you can use functions to convert the string to integers

Since you can't use the serial monitor to "see" the incoming data from Processing, here are 2 test sketches that may help you determine if data is received on the Arduino.
Upload the Arduino sketch first. Leave the serial monitor closed. Now run the Processing sketch.
I'm using frameRate(1) in the Processing sketch to send the data once per second, so the mouse X/Y values in the Processing window will be slow to update.
You should see the LED on the Arduino flash on then off quickly as the data is received. If you have a I2C LCD available, you could connect it to the Arduino and print out the incoming data.
As chrisl mentions in the comments, there is still much work to be done to get the raw data in the format you require.
Arduino
int x = 0;
const byte ledPin = 2;

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

void loop(){
  if(Serial.available() > 0){
    x = Serial.read();
    digitalWrite(ledPin, HIGH);
  }
  else{
    digitalWrite(ledPin, LOW);
  }
}

Processing
import processing.serial.*;
Serial port;
void setup() {
  size(500,300);
  background(148);
  try{
    port = new Serial(this , Serial.list()[0], 9600);
  }
  catch(Exception e){
    System.err.println(e);
    e.printStackTrace();
  }
  frameRate(1);
}

void draw() {
  background(148);
  //@chrisl comment: Finish your data, that you send with \n (newline).
  port.write(str(mouseX)+' '+str(mouseY) + "\n");
  text(mouseX,250,50);
  text(mouseY,250,70);
}

EDIT
Here is a second Arduino sketch that will display the mouse X/Y values sent from Processing on a LCD. You could change the Processing sketch's frameRate() value to 10.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

char inputBuffer[32 + 1];

LiquidCrystal_I2C lcd(0x27, 16, 2);

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

void loop(){
  if(Serial.available() > 0){
    lcd.print("                ");
    Serial.readBytesUntil('\n', inputBuffer, 32);
    lcd.setCursor(0, 0);
    lcd.print(inputBuffer);
    memset(inputBuffer, 0, sizeof(inputBuffer));
  }
}

fantastic! I'm going to learn more about LCDs. I used an lcd once with parallel wiring... it was exhausting.

If you solder a Serial Interface Board or I2C LCD "backpack" to the LCD, then there are only 4 wires to connect :) https://www.aliexpress.com/item/IIC-I2C-TWI-SPI-Serial-Interface-Board-Port-For-Arduino-1602-2004-LCD-LCD1602-Adapter-Plate/32895120140.html

source: Stack Exchange

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

sort: votes


text:
Is SPI a good way to connect two rfid modules on separate arduino boards?
RFID access control
I have two separate rfid projects on separate arduino, the first project requires 2 minutes of contact between the tag and the reader after which it turns the LED on. the second project is a simple rfid access control, but on this access can only be granted if the conditions on the first tag were met. I am trying to use SPI for this but do not know if it would work, any suggestions on any other way of communication between two arduino boards?

You can use SIMPLE GPIO for this. If set GPIO in ARDUINO1 when condition is matched and MONITOR its level on ARDUINO2 to grant access.

is it possible that you have some sort of an example since I am a beginner

why two Arduinos for a so simple task?

Sure it is possible. Have you tried it? If yes, you can ask a question about it and include the code, so that we can help you. With this question the answer is simply: yes, it is possible. But this will not help you implementing it

Its very easy.

Set one PIN of ARDUINO as ouput pin. You will write that PIN HIGH when your conditions are matched in ARDUINO1 then SET LOW after 1 mS.
Connect that PIN of ARDUINO1 to external Interrupt PIN of ARDUINO2.
Write a CODE for ARDUINO2 such that when EXTERNAL INTERRUPT OCCURS it will set variable high indicating that Conditions is Matched in ARDUINO1.
While providing access to on ARDUNO2 check that variable status if it is HIGH grant access and SET it LOW.

This is the basic Structure you can follow using interrrupt.

how would it know that is the same card?

Yeah in that case you can have UART for sending the CARD ID to ARDUINO2 also. But in that case there no need of using two ARDUINO Setup. If you are scanning and matching in ONE SETUP, then why you are SCANNING and Matching it Again in another setup. Else if SETUP1 is used to store the CARD ID In database and  SETUP2 is used to provide access to that CARD ID based on that database.

how can I connect 2 rfid modules on one Arduino board

Why you need two RFID Modules?

also once I have them on the same board do i have to do only GPIO connections or GPIO and UART

If you want to know the card number then you need the UART as well.

@Ayat.H Of Course you can use SPI or I2C on separae boards, i think you just need to define a Master board and a Slave board to access control.

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


text:
Ethernet Shield: Maximum speed
Looking at this shield here: https://store.arduino.cc/arduino-ethernet-shield-2
It states that "Connection speed: 10/100Mb". However from looking at various forums it appears that no one can get much more than 300Kb/sec with this device?
Can anyone explain what causes this limitation and how to overcome it? If its SPI that is the bottleneck is there some alternative? I am looking to get speeds of 6 mega bytes per second or more using a TCP connection.
I am extremely new to all this so apologies if I've missed something extremely obvious here. I also had a look at bluetooth/wifi shields but it appears they seem to also have some similar throughput issues. USB looked like it could work but is extremely complex for a newbie.

If you have a caravan that is rated at up to 50 mph, and you attach it to a 50cc scooter, do you think you will be able to get the full 50 mph out of it?

Also: what do you want to do with all that data? Or how are you hoping to generate so much data so fast?

The data will be streamed from a PC into a games console, the stuff I am adding will sit in the middle

"Sit in the middle"... what does that even mean?

@paulm According to your description, that PC is the best place to put that "man in the middle". However this is more like XY problem

you would have a hard time getting a reliable and constant 6MBs from a 10/100 network no matter what you hook up to it; 2/3rd utilization is respectable, so unless there's no other traffic, you're already close to the limit.

It's not just the SPI what limits overall speed. You also need some proccessing power, and AVR based Arduinos lacks of it. It all depens what do you want to do with data.
If you need some serious processing power, it might be better to use something much more powerfull, like raspberry PI with real operating system. You can even run some web server at the speeds you can't even imagine with Arduino with the ethernet shield

Would it be possible to do it without needing a full blown OS? For just passing data between devices at higher speeds it feels like overkill?

@paulm Of course it's possible. If you are a billion dollar company that Broadcom is willing to release the datasheet for the Pi's SoC to... And if you're a good programmer that understands all the underlying hardware.

Maybe FPGAs? Though it might be a really tricky and much work to program them for implementing ethernet.

A guy on this forum reports achieving 100 Kbyte/sec with a W5100 ethernet shield, which would be 800 kbit/sec:
https://forum.arduino.cc/index.php?topic=555957.0


text:
ArduinoJSON v6 - return a StaticJsonDocument from a function
I'm reading a stored JSON file from an ESP8266. I wish to return it as a StaticJsonDocument for further use.
return it at the end of function was done OK, but I need to assign it for document.
#include <ArduinoJson.h>
#include "FS.h"
#define filename "file.json"

StaticJsonDocument<200> doc;

void createJSON() {
        doc["sensor"] = "gps";
        doc["time"] = 1351824120;

        JsonArray data = doc.createNestedArray("data");
        data.add(48.756080);
        data.add(2.302038);
}

StaticJsonDocument<512> readJSON_file(){
        StaticJsonDocument<512> read_doc;
        File readFile = SPIFFS.open(filename, "r");
        DeserializationError error = deserializeJson(read_doc, readFile);
        if (error)
                Serial.println(F("Failed to read file, using default configuration"));

        serializeJson(read_doc, Serial);

        return read_doc;
}

void setup() {
        Serial.begin(9600);
        if (!SPIFFS.begin()) {
                Serial.println("Failed to mount file system");
        }

serializeJsonPretty(readJSON_file(),Serial);
}

void loop() {
        // not used in this example
}

try StaticJsonDocument<512> doc = readJSON_file(); serializeJsonPretty(doc,Serial); (= will copy the object)

but your serializeJsonPretty(readJSON_file(),Serial); works too. a temporary object will be created for the parameter

yes, that I checked.

I would avoid a copy and supply the buffer as parameter to readJSON_file

I need to update values in json files stored in ESP8266, and then saving it again...

why not readJSON_file(JsonDocument& doc)?

@Juraj - you ROCK!

@Juraj can you please post your answer ?


text:
Using an external header file
I have a project that is part of a larger repository, and shares header files with non-Arduino C programs.
I know that it's possible to use these headers by copying them to the libraries folder, or the sketch folder, but I would rather use them with a relative path (which seems to not work), so I can avoid copying files around for every repository clone or update.
Is there a solution that doesn't involve moving/copying the header file?
EDIT:
Although there is no full solution for this question,
I have since found that using the PlatformIO
IDE instead solves the problem.

symlinks maybe?

I tried that using cygwin on windows.  The IDE didn't like it.

I use links. I link a folder into libraries folder. mklink on Windows

You can use header files with an absolute name, like:
#include "c:\Temp\x.h"

Another way that might help is to make the include path like:
#include "q:\x.h"

And use Windows to map driver letter Q to the path you need.

I guess that's better than nothing, but requires the repository to be cloned to a specific location, or changes to the code each time.

@Photon ... I tried using a define inside the include path to make that path variable, but that does not seem to work. I added another solution (mapping a drive letter). Than you need only one change.

Thanks.  I'll mark it as an answer, because it provides the best that can be done under the IDE limitations.

Thanks; and yes, it seems like a limitation of the IDE.

I tried to do this, and looked into it, a few years ago, but it doesn't appear to be possible to do what you want to do. This guy was having the same issue, #include statement with relative path.
Seems like either Michel's suggestion or copying them (which is a pain) will work, from Can I include a header file that is not a library?:

If the include file is part of a single Sketch, instructions are
  here... http://www.arduino.cc/en/Hacking/BuildProcess [new
  link]
If the include file is meant to be shared by multiple Sketches then...

Close the Arduino IDE
Navigate to the {Arduino}\hardware\libraries directory
Create a subdirectory.  I suggest something like MyCommon.
In the new subdirectory, create a header file.  I suggest something like MyCommon.h.
Open the new header file, edit it as you wish, and save it
Open the Arduino IDE
Create or open a Sketch
Add a #include to the top of the Sketch that references your new include file

This is why relative paths are not supported, from Re: how to include header file from previous folder?

Enable verbose mode when compiling. Navigate to the Testing.cpp file that is created from the Testing .ino file. Go up one level. Do you see the files you are trying to include?

and from Re: how to include header file from previous folder? (emphasis is mine)

The reason for having you go look at the something
  like/AppData/Local/Temp/build/sketch folder was
  to make you think about what the build process is doing, and maybe
  think that you could google Arduino + Build to get more details.
The IDE copies your sketch, and stuff #included by your sketch to a
  build directory.
If you #include , the file header.h, and everything else in
  the directory it is in, will be copied to the build directory, too.
If you #include "header.h", the file header.h, and everything else in
  the directory it is in, will be copied to the build directory, too.
The difference between <> and "" is where the header.h file is looked
  for. "" looks in the current directory. <> looks in the library
  directories.
If the token between the <> or the "" is not found in the appropriate
  folder, you are not told that; nothing gets copied, though.
But, that explains why relative names are useless. A sketch directory
  might contain a file called header.h. It will not contain a file
  called ..\header.h, because ..\header is NOT a valid file name.
Note that I did NOT say that ..\header.h is not a valid NAME. I said
  that it is not a valid FILE NAME.
Only file names between the <> or "" are possible, as far as the IDE
  is concerned.
If you do not like that, you are free to not use the IDE.

Finally from Re: How to specify a path to a specific header file?

The Arduino system has some severe limitations in its ability to work sensibly with the file system - can be a real PITA.

BTW, If you create multiple libraries in libraries folder, you can use relative reference path i.e in all Header files, you can use #include "..\mylib2\xxxx.h.


text:
How to get 3v3 pins on Arduino Mega Sensor shield v2.0?
I am using Arduino mega and a sensor shield (picture attached below). I need to connect three different wires to 3.3 V input. Can anybody suggest how can I achieve the same? What voltage do the VCC pins of all digital and analog pins on the sensor shield have?

Is there a pin marked with 3.3 or similar? If not, you will need an external voltage regulator. If yes, you should make sure, that is can provide enough current for the sensors

They are all 5V as the Mega2560 uses 5 V logic.  However, there is a 3V3 pin at the bottom, second pin from the left, that you could use:

However, unfortunately, the pin isn't protruding above the shield, so you'll have to make an ugly solder link to the top of the pin. Either that, or remove the row of pins and replace with a female header (carefully avoiding the SD card pins):

As an aside, the Iteaduino MEGA 2560 works at 3V3 but unfortunately the Mega shield that you have won't fit it.

The Uno equivalent of your shield will fit it though:

I guess the shield would still provide 5 V from the 5 V pin of the 3.3 V Mega

I fix it solding into the board sensor shield the point where there is the pin 3.3v


text:
error for uploading code to esp8266 module
I am getting error for uploading code to esp8266 module. I have installed cp2109 drivers also but at the time of uploading getting follwing error message:
Sketch uses 344,292 bytes (32%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 32,276 bytes (39%) of dynamic memory, leaving 49,644 bytes for local variables. Maximum is 81,920 bytes.
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_send_command: wrong direction/command: 0x00 0x08, expected 0x01 0x08
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed

Please help me to solve this problem

Try pressing and holing the flash button while pressing reset once. After that you will see a blink of the blue LED, release the flash button and try again.

I have done the same process of Reset and flash button blue light blink but yet not able to upload code getting this error message now:                        Sketch uses 344,292 bytes (32%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 32,276 bytes (39%) of dynamic memory, leaving 49,644 bytes for local variables. Maximum is 81,920 bytes.
error: Failed to open COM1
error: espcomm_open failed
error: espcomm_upload_mem failed

the board isn't in flash mode

Did you select the COM port properly because it is very unlikely that it is on COM port 1


text:
tty doesn't list ttyUSB0 so arduino doesn't list serial ports
Okay so lsusb gives
Bus 002 Device 019: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
dmesg|grep 'ttyUSB' gives
[63723.589107] usb 2-1: ch341-uart converter now attached to ttyUSB0
but tty lists only /dev/pts/0 although in /dev there is a ttyUSB0 file (or whatever it is because vim says its not a file)
I can use cu -l /dev/ttyUSB0 -s 9600 and transmit to arduino nano as the rx LED blinks. On starting arduino I get the "java.lang.NullPointerException thrown while loading gnu.io.RXTXCommDriver" error.
System: Linux Mint 19.1 Tessa (64 bit)

tty tells you the terminal device that your current terminal session is connected to. Nothing to do with listing what terminal devices are available.

You are assuming a problem with serial ports. That is unlikely to be the case. Your real problem is something to do with the Arduino IDE's programming. What version of the IDE are you using and how did you install it?

I agree with Majenko and also don't believe it has anything to do with your ports. The exceptions you mentioned look like there is something wrong with your environment, maybe updating the arduino IDE or java itself will help. You could also check if the problem persists when using an older version of the IDE

To be sure that has nothing to do with the ports/serial communication, I suggest reading out the atmega with avrdude manually

Sorry, I was using the software center to get arduino IDE and that didn't work well. Downloading the official IDE from arduino.cc worked without hassle. Lesson learnt: Not all linux distros have package repos as up-to-date as Arch. :P


text:
STM32YYXX chip series is not defined in boards.txt
The STM32YYXX chip series is not defined in boards.txt? How can I solve this? I am using Windows 10 with Arduino IDE 1.6.6

what boards.txt?

Did the answer help? If so then please upvote and mark as the accepted answer. If you found an alternative method, then please post that as an answer and mark that as the accepted answer.

Overview
Following the guide Getting Started on the STM32 page on Github: Arduino core support for STM32 based boards:

This repo is available as a package usable with Arduino Boards
  Manager.
Use this link in the "Additional Boards Managers URLs" field:
https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
For full instructions on using the "Boards Manager", see the Getting
  Started page.

Thanks to Juraj's comment for the tip

this is not the current STM boards package. ST Microelectronic took over the development github.com/stm32duino/Arduino_Core_STM32 stm32duino.com/viewtopic.php?f=16&t=4671

Step by Step
The process is as follows (screenshots from OS X, but on Windows/Linux the process is the same):
Adding the URL in the preferences dialog (one URL per line)

Boards Manager menu

Boards Manager dialog

Boards Manager dialog - STM32 Core Boards installed

Boards Manager dialog - Boards installing

Boards Manager dialog - Boards installed

Here are the newly installed boards in the menu

As a comparison, these are the boards installed using the deprecated manual process described below:

Deprecated method

From STM32 - installation

Prerequisites
If your STM32 board does not have a bootloader yet and you want to be able to program it over USB, you'll have to upload
  the STM32duino bootloader to flash memory. See Burning the
  bootloader.
Arduino and Arduino_STM32

Download and install the official Arduino IDE. Versions 1.6.10 till 1.8.5 have been reported to work fine.

If you already have the Arduino IDE installed and it's a newer version, see the Boards Manager package method of installation.

Note: this method is deprecated and not supported in forum!

Run Arduino IDE, and open the menu Tools -> Boards -> Boards Manager. Install the "Arduino SAM Boards" package (includes the
  Arduino Due) from the list of available boards. This installs compiler
  support for ARM Cortex-M3.
Download a zip file containing the Arduino STM32 files from here.
Unzip the content of the zip file, and place the Arduino_STM32 folder to [Arduino sketches folder]/[hardware]/[Arduino_STM32].
  Create the 'hardware' folder if it does not exist yet.

Example how the path should look like:
  C:\Users\<user>\Documents\Arduino\hardware\Arduino_STM32

As an aside, for anyone using OS X, from Installation on OSX

Installation on OSX

Arduino_STM32 folder must be placed inside
  ~/Documents/Arduino/hardware (note. if the hardware folder doesn't
  exist you will need to create it)
So you should get ~/Documents/Arduino/hardware/Arduino_STM32
Note.  DFU util binaries
  have now been added to the repo, in tools/macosx/dfu-util, so there is
  no longer a need to install Homebrew to then install dfu-util, or to
  compile dfu-util from source.

I recommend the Boards Manager package method of installation.

It says that the Boards Manager method is depreciated. Is that incorrect?

this is not the current STM boards package. ST Microelectronic took over the development https://github.com/stm32duino/Arduino_Core_STM32 http://stm32duino.com/viewtopic.php?f=16&t=4671

You should post that as an answer then, as mine seems to be out of date.

If the downvoter could explain why the downvote or better still post an answer then that would be most helpful. A warm thanks.

@Juraj - I think I may may encounter a similar issue as the OP, I need to code up (what I believe to be) a Maple Mini board, but which has been customised with a 303 rather than a 103... and there doesn't seem to be that option available after installing the package, using the method described in my answer (I haven't tried your github link yet).I may need to post my own (similar) question.

the ST package has Boards Manager installation and is up-to-date. with F303 too

Ah OK, thanks. I'll give it a go. If that all works fine, I might update/correct my answer with your (github) suggestion, and credit your comment for it, if you don't mind...?


text:
Need help with wire connections and code
I am currently working on a keypad door lock mechanism (Similar to this project, Keypad door lock).
The issues with the code I have is that the keypad attached to my board does not allow me to type the full password. Only the first value displayed on the LCD screen moves but no value is excepted. Also the buttons used to open and close the servo motor do not operate as intended.
Fritzing diagram

Photo of breadboard

Below is the code I currently have:
//LCD config
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

#include <Servo.h>
#include <Keypad.h>

//Variables
int mot_min = 90;   //min servo angle  (set yours)
int mot_max = 180; //Max servo angle   (set yours)
int character = 0;
int activated = 0;
char Str[16] = {' ', ' ', ' ', ' ', ' ', ' ', '-', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' '};
//               0    1    2    3    4    5    6    7    8    9    10   11  12    13   14  15

//Pins
Servo myservo;
int buzzer = 11;   //pin for the buzzer beep
int external = 12; //pin to inside open
int internal = 13; //pin to inside close

//Keypad config
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '4', '7', '*'},
  {'2', '5', '8', '0'},
  {'3', '6', '9', '#'},
  {'A', 'B', 'C', 'D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  myservo.attach(10); //attach the servo to pin D10
  pinMode(buzzer, OUTPUT);
  pinMode(external, INPUT);
  pinMode(internal, INPUT);
  //Init the screen and print the first text
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.print("    PASSWORD");
  lcd.setCursor(0, 1);
  lcd.print("      -***     ");
  //put the servo in the close position first
  myservo.write(mot_min);

}

void loop() {
  ///////////////EMERGENCY OPEN/CLOSE/////////
  if (digitalRead(external) == LOW) // if (digitalRead(external))
  {
    myservo.write(mot_max);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("INSIDE  OPEN");
    activated = 2;
    analogWrite(buzzer, 240);
    delay(250);
    analogWrite(buzzer, 200);
    delay(250);
    analogWrite(buzzer, 180);
    delay(250);
    analogWrite(buzzer, 250);
    delay(250);
    analogWrite(buzzer, LOW);

    lcd.clear();
    lcd.setCursor(4, 0);
    lcd.print("WELLCOME");

    lcd.setCursor(2, 1);
    lcd.print("ELECTRONOOBS");

    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("DOOR  OPEN");
    lcd.setCursor(2, 1);
    lcd.print("ELECTRONOOBS");
    delay(500);

  }

  if (digitalRead(internal) == LOW) // if (digitalRead(internal))
  {
    myservo.write(mot_min);
    activated = 0;
    character = 0;
    Str[6] = '-';
    Str[7] = '*';
    Str[8] = '*';
    Str[9] = '*';
    Str[10] = ' ';
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("    PASSWORD");
    lcd.setCursor(0, 1);
    lcd.print(Str);
  }

  ///////////////KEYPAD OPEN/CLOSE////////////
  char customKey = customKeypad.getKey(); //this function reads the presed key

  if (customKey != NULL) { // if (customKey)

    if (character == 0)
    {
      Serial.println(customKey);
      Str[6] = customKey;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("    PASSWORD");
      lcd.setCursor(0, 1);
      lcd.print(Str);

    }

    if (character == 1)
    {
      Serial.println(customKey);
      Str[7] = customKey;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("    PASSWORD");
      lcd.setCursor(0, 1);
      lcd.print(Str);

    }

    if (character == 2) {
      {
        Serial.println(customKey);
        Str[8] = customKey;
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("    PASSWORD");
        lcd.setCursor(0, 1);
        lcd.print(Str);

      }

      if (character == 3)
      {
        Serial.println(customKey);
        Str[9] = customKey;
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("    PASSWORD");
        lcd.setCursor(0, 1);
        lcd.print(Str);

      }

      if (character == 4)
      {
        Serial.println(customKey);
        Str[10] = customKey;
        activated = 1;

      }
      character = character + 1;
    }

    if (activated == 1)
    {
      /*Change your password below!!!
        Change each of Str[6], Str[7], Str[8], Str[9]*/

      // if (Str[10] = 'A' && ...)
      if (Str[10] == 'A' && character == 5 && Str[6] == '3' && Str[7] == '0' && Str[8] == '0' && Str[9] == '7' )
      {
        myservo.write(mot_max);
        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("ACCEPTED");
        activated = 2;
        analogWrite(buzzer, 240);
        delay(250);
        analogWrite(buzzer, 200);
        delay(250);
        analogWrite(buzzer, 180);
        delay(250);
        analogWrite(buzzer, 250);
        delay(250);
        analogWrite(buzzer, LOW);
        delay(1000);

        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("WELLCOME");
        delay(500);
        lcd.setCursor(2, 1);
        lcd.print("ELECTRONOOBS");
        delay(1000);

        lcd.clear();
        lcd.setCursor(3, 0);
        lcd.print("DOOR  OPEN");
        lcd.setCursor(2, 1);
        lcd.print("ELECTRONOOBS");

      }
      else
      {
        lcd.clear();
        lcd.setCursor(1, 0);
        lcd.print("PASSWORD ERROR");
        lcd.setCursor(3, 1);
        lcd.print("TRY  AGAIN");
        analogWrite(buzzer, 150);
        delay(3000);
        analogWrite(buzzer, LOW);
        character = 0;
        Str[6] = '-';
        Str[7] = '*';
        Str[8] = '*';
        Str[9] = '*';
        Str[10] = ' ';
        activated = 0;
        lcd.clear();
        lcd.setCursor(4, 0);
        lcd.print("PASSWORD");
        lcd.setCursor(0, 1);
        lcd.print(Str);
      }
    }
    if (activated == 2)
    {
      if (customKey == 'B' )
      {
        myservo.write(mot_min);
        activated = 0;
        character = 0;
        Str[6] = '-';
        Str[7] = '*';
        Str[8] = '*';
        Str[9] = '*';
        Str[10] = ' ';
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("    PASSWORD");
        lcd.setCursor(0, 1);
        lcd.print(Str);

      }
    }
  }
}

To re-iterate, With this code now the LCD screen displays PASSWORD but when I enter the password into the keypad only the first number changes value and it does not move to the second value.

you have not described any problems and you have not asked any questions .... voting to close as unclear what you're asking ..... please update your post .... include a description of expected behavior, observed behavior and any errors that you get

This is the issue I'm having (https://youtu.be/aWixfn1pe3A).

needs more re-callable subroutines. a lot more...

You would appear to have an excess of { here:
if (character ==2) {
{    <<<< Remove this

and then remove the excess } at the end of the code.
It would seem that this is affecting the logic of your code, as you've ended up inadvertently grouping some ifs within another if.

To avoid this type of situation, you need to be much more consistent with your code style (i.e. formatting/indentation).
Either use:
if (character ==2) {

or
if (character ==2)
{

but don't mix them. Otherwise you'll end up in a right old muddle.
If you keep your coding style consistent, then you'll see, in a flash, something that is out of place - merely by quickly scrolling through the code.

In addition, use the Tools ► Auto Format menu item in the Arduino IDE to correctly format your code and make it easy to read.

Changed the code with your suggestion but still receiving similar output issue.

As it is compiling, it is most likely a logical error within your code. I strongly suggest that you tidy the code, as the indentation is all over the place, and nigh impossible to follow.  If you indent it correctly then you'll see whether the if statements are grouped correctly and follow logical sequences. The indentation has become significantly worse since your last edit. You have, inexplicably, removed the indentation on large sections of the code

I apologize for the indentation but if it helps a very similar code that I'm using is on (http://www.electronoobs.com/eng_arduino_tut11.php). Thanks for the feedback.

Unfortunately, I could no longer follow your code, with the indentation removed, and gave up. Sorry. Good luck. :-)

I've correctly formatted your code for you, please check the edit that I made to your question, in order to see how you should have improved it. Cheers :-) Note that I have not changed the code, nor corrected it, as it would change the nature of your question.  Hopefully now people can easily work out what's wrong with the code and will post an answer.


text:
Using Pro Micro without soldering pin
I'm a total newbie. I bought a Pro Micro but I didn't know that it can't be used, if you don't solder things in his holes.
I found this picture on Google:
And it seems that exists those stuffs (green and white) to test the circuit before soldering.
Do you know where can I buy them? Or do you know their name?
Thanks.

As alternative I am looking for screws that would fit the pins but i've still haven't found any.

Perhaps you are looking for items like these from from a well established seller adafruit.com.  However, what you are proposing is not cheap when compared to soldering.  I would recommend you learn soldering as it will likely be the way you want to assemble your final Arduino project.

It's exactly what I looking for! Yes, sooner or later I'll learn how to solder. Thanks!

If you're just getting started and are not comfortable with soldering I would suggest getting one of the larger boards that has headers on it. (An Uno or a Mega, for example). You can use one of those and a breadboard to experiment without having to solder at all.
MicroCenter (A US retailer) sells 100% compatible Arduino Mega 2560 knockoffs for $10 US.
I suggest using a board like that when you are first starting out. (And learn how to solder. It's very useful for electronics repair and various other things.)

I need a Pro Micro because I need its ability to emulate an HID USB device.


text:
What sensor do I use to measure the intensity of direct sunlight?
I'm trying to measure how bright the day is on a particular day to see how it affects plant growth. The brightest sun can be 120,000 lux. It possible to measure such a large brightness? What sensor do I use?
The best options I've found is the BH1750FVI since its sheet says, "[i]t is possible to detect min. 0.11 lx, max. 100000 lx"
However, it still doesn't go high enough.
Note: I live "only" 3,494 km (2171 miles) from the equator, and it can get fairly bright here.

You may not put a sensor in direct sunlight. That is too bright and too hot. Only a solar cell can deal with direct sunlight. For the accurate number of lux, use a accurate sensor under a semi-transparent filter. Extra care should be taken that the sensor does not get too hot.

I thing a simple LDR would work just as well. You won't get a nice calibrated LUX value, but you'd be able to compare different day and/or time, and see the difference in brightness.

PS the BH1750 can only measure up to 100000lx. That doesn't mean it can't handle more. It can, but will clip the value. The measurement also depends on the angle between the sensor and the sun as you can see in the graphs on page 3 of the datasheet. So you could aim the sensor slightly to the north, so the sensor values stay below the maximum value, and doesn't clip.

Maximum operating temperature for the BH1750FVI is 85  deg. Celsius.

You can use a photo resistor. It is also known as an  LDR (Light dependent resistors) and here is a great tutorial to do just that. You can also find a conversion from the 8-bit analog value to lumens if you wish. Here is a tutorial:
https://www.instructables.com/id/Measuring-Light-Using-Light-Sensor/
You can also use a LUX which is the advanced version of a LDR. Here is a tutorial:
https://www.instructables.com/id/How-to-Measure-LUX-With-Arduino/

What about SiLabs SI11xx Sensors? Some of them are designed for direct sunlight.


text:
error when trying to upload code to esp8266
Sketch uses 344,292 bytes (32%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 32,276 bytes (39%) of dynamic memory, leaving 49,644 bytes for local variables. Maximum is 81,920 bytes.
error: Failed to open COM1
error: espcomm_open failed
error: espcomm_upload_mem failed

please help me to fix this issue.

when I am trying to upload code to nodeMCU board I am getting this error message--   Sketch uses 344,292 bytes (32%) of program storage space. Maximum is 1,044,464 bytes. Global variables use 32,276 bytes (39%) of dynamic memory, leaving 49,644 bytes for local variables. Maximum is 81,920 bytes. error: Failed to open COM1 error: espcomm_open failed error: espcomm_upload_mem failed

I am sending error message coz I want solution for that.. what do u expect to send ??????????????????????????????

Try holding down the flash button when uploading the code to the board.
The ESP8266 and the ESP32 need certain buttons held down to open the COM port to upload code.


text:
Byte text file to array
I'm trying to display a bitmap on gLCD 128x64, I stored the bitmap into txt file 1.txt in a SD card this is a part of bit map  as following:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00.......
I want to convert the content of this text into array:
Unsigned char logo[] with making a split on ",".
Any help please

The most efficient way is to read the file byte-by-byte into a small character array until you get a comma or the end of file - ignoring any characters that aren't of interest (line feeds, etc).
Then for each chunk that you read you then convert it to an integer.
For example (untested):
char temp[5] = {0}; // should be more than enough
int pos = 0;
int bno = 0;

const char *hexchars = "0123456789abcdefABCDEFx";

while ((int ch = myFile.read()) >= 0) {
    if (ch == ',') { // We found a comma
        logo[bno++] = strtoul(temp, NULL, 16); // Base 16 conversion
        pos = 0;
        temp[0] = 0;
    } else if (strchr(hexchars, ch) != NULL) {
        if (pos < 4) {
            temp[pos++] = ch;
            temp[pos] = 0;
        }
    }
}

Of course, you have to know how big the logo array has to be beforehand.
One does, though, have to ask "Why are you storing a graphical logo as a textual representation of binary data" in the first place?  It would be far easier to just store it as a simple binary file and read the data directly into the logo array with a single File::read(void *buf, size_t nbyte); function call.  Using text as an intermediate format is both wasteful and needlessly increases complexity massively.


text:
compare char receive from Slave writer to Master reader with I2C
Im trying to send data from slave (writer) to master (reader) then compare it to declared 'char p[]' to turn on the lights but somehow i cant make it work.
////master reader

    #include <Wire.h>

int LED = 13;
char p[] = "YES...";

void setup() {
  pinMode(LED, OUTPUT);
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

}

void loop() {
  Wire.requestFrom(8, 6);    // request 6 bytes from slave device #8

  while (Wire.available()) { // slave may send less than requested
    char c= Wire.read(); // receive a byte as character

  Serial.print(c);         // print the character

  if(c == p){

  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)

    }else{

  digitalWrite(LED, LOW);   // turn the LED on (HIGH is the voltage level)

          }

  }

  delay(1500);

Slave
//////////////     Slave       ///////////////////////

    #include <Wire.h>

const int pingPin = 8; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 9; // Echo Pin of Ultrasonic Sensor

void setup() {
  Serial.begin(9600); // Starting Serial Terminal
  Wire.begin(8);                // join i2c bus with address #8

}

void loop() {
   long duration, inches, cm;
   pinMode(pingPin, OUTPUT);
   digitalWrite(pingPin, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(pingPin, LOW);
   pinMode(echoPin, INPUT);
   duration = pulseIn(echoPin, HIGH);
   inches = microsecondsToInches(duration);
   cm = microsecondsToCentimeters(duration);
   Serial.print(inches);
   Serial.print("in, ");
   Serial.print(cm);
   Serial.print("cm");
   Serial.println();
   delay(1500);

if( inches <= 4){

  Wire.onRequest(requestEvent); // register event
   Serial.print("Obstacle detected");
   Serial.println();
  }
  else
  {

  Wire.onRequest(requestEvent1); // register event
   Serial.print("Nothing Detected");
   Serial.println();

    }

}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {

  Wire.write("YES..."); // respond with message of 6 bytes
  // as expected by master
}
void requestEvent1() {

  Wire.write("NO...."); // respond with message of 6 bytes
  // as expected by master
}

long microsecondsToInches(long microseconds) {
   return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
   return microseconds / 29 / 2;
}

Improve you indentation.
If you want to compare two strings use strcmp function for that.
Your master part has some brackets left in your void loop() function, correct them.
In I2C you are receiving one byte at time. You should receive data till the last byte in received.
You should have some identification in your message, which is you are sending from slave to master indicating that this is last character. It helps you come out of Data reception loop in Master side.


text:
HX711 Wemos D1 Weird Characters In Serial Monitor
I am using the HX711 with a load cell attached on my Wemos D1. I have the connections correctly as if I use the same setup on my Arduino Uno board and the same code it runs fine and prints to the serial log. If I comment out the HX711 scale(DOUT, CLK); in my code the serial print is fine. I am not sure if this is an issue with the board or something I am doing with it. I would use the Arduino Uno but it does not have Wifi whereas my Wemos board does. Attached is a screenshot of the serial print from the monitor.

#include "HX711.h"

#define DOUT  3
#define CLK  2

HX711 scale(DOUT, CLK);

float calibration_factor = -117441.00; //-7050 worked for my 440lb max scale setup

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

  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0

  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}

void loop() {

  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1);
  Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();

  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 10;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 10;
  }
}

had you tried using other pins like 8,9 in place of 2,3

@Vaibhav Yup, tried that

io 3 is TX of Serial. use Dx constants to match the labels on board https://electronics.stackexchange.com/questions/402066/esp8266-free-gpios-for-relay-switching/404845#404845

@Juraj This does not make a lot of sense and does not solve my issue. My board does not look like that it looks like this https://storage.googleapis.com/stateless-www-faranux-com/2017/06/Reloaded-295x300.jpg and in this image my hx711 is hooked up to D3 and D3

ok, you have the D1 R1. on Wemos D1 R1 the pin labeled D3 is io 5 of the esp8266. in code use D3 not 3. https://github.com/esp8266/Arduino/blob/4e0e4e4340e6110cbb63ff77cb43d316cc318368/variants/d1/pins_arduino.h#L38

@Juraj I tried replacing 3 in the code with both D3 or even 0 as defined in that Github but both didn't work. I also tried replacing 2 with D2 or 4 as that code specifies but that also didn't work for me

@Juraj Okay cool now I am using D3 in the spot of 3 and D2 in the spot of 2 and it's working! Perfect.


text:
Esp8266 not responding to GET request from Android app created using MIT App Inventor
I hope I am posting this question in the right section.
I am making a Smart Home Project for my college semester finals. I am using an Atmega328p microcontroller along with an ESP8266 (Esp 01). The Atmega328p controls all the sensors and actuators and sends the data to Esp01 via serial communication.
I have created a web server on the Esp01 which I plan to access by creating an app using MIT App Inventor. My GET request is of the format "http://192.168.43.42/4" where the digit at the end is data I want to send to the server and the response I get from the server is of the format "12&0&34.8" where the '&' is used to separate different values.
My problem is , when I access the server from Chrome in my laptop I get the desired response but when I access it using the App , I get an error "Error 1101 :Cannot find the specified URL". The Esp01 is connecting to a hotspot from my phone and I have checked the IP assigned to the Esp01 to ensure my GET request is correct.
The code for Esp01 in Arduino IDE is here : https://gist.github.com/TheMagicSmoke/467d6227d670697464038056e22f302d
The blocks for the app made in App Inventor is below:

The GET request URL when entered from Chrome in laptop returns a blank page at first but upon refreshing Chrome I get the desired response I told earlier. And in the app , I have used a timer which queries the server with the same GET request every 2 seconds. But when I open the App the error keeps on popping up. Please suggest me a solution, I have googled this without any success.

Is MIT AppInventor something that runs locally on a device or computer on your network, or something that runs on a website somewhere?

I have edited the title as it seemed misleading. What I meant is that I am accessing the server using an Android app that was created using MIT App Inventor which is a website.

I'm finding it hard to find any concrete information, but it looks like the "app" on your phone may just be a front-end to the MIT web servers and the code actually runs on there, not your phone - which means that the code can't get at what is inside your network - only things that are on the internet.

You have misunderstood. The server is a local server which has been created on the esp8266. The application on my phone is sending a GET request to that server. Both my phone and the Esp8266 are on the same WiFi network. This has nothing to do with the servers at MIT.

No, you misunderstand. Like I said, I am not certain, but I think that AppInventor works like this:  1. you design your app. 2. the interface is displayed on your phone. 3. Interactions are sent from your phone to MIT. 4. MIT executes code. 5. MIT attempts to connect to your ESP8266. Your ESP8266 is not on the internet, and MIT is not on your local network, so MIT cannot connect to it.

I would suggest using some third-party communication system, such as MQTT (if AppInventor supports it), or switching to a real programming language that runs directly on your phone.

Is the phone on WiFi in the same network as the esp-01? (@Majenko, I helped here on SE with a project with App Inventor and there was no problem to access a local esp-01)

@Juraj The Esp01 is connecting to a hotspot from my phone

did you try to access the page from a browser on the phone?

@Majenko the Applications created using MIT App Inventor run code locally on the mobile and not through MIT servers. I am sure about this. Thank you for helping me. I have found out the solution and will post it below as an answer.

@Juraj thank you for helping me. I have found out the solution and will post it below as an answer.

Can Yo post. aia file? Many thx in advance.
Tom

I have found out the solution to this problem. The code that I had written in the Arduino IDE for the Esp8266 was not correct for handling the GET request.  It only accepted data as a simple Web Server and not as a HTTP server. I am posting the modified code below .
https://gist.github.com/TheMagicSmoke/adaae1e4d92f258c88184c8690e68f08

so I didn't look at your code (the first version). I expected that you used the WiFiWebServer example not a sketch, which expects data 10 milliseconds after connect, else it fails


text:
ESP8266 crashes when button is pressed
I'm building a wireless QLab Go button based on an ESP8266-01. There is a web UI to connect to a wireless network and setup the IP address of the computer running QLab. When a button is pressed, the ESP is meant to send an OSC message to that computer.
In fact, this works. But only a few times. After, let's say pressing five times the button, the ESP becomes unresponsive. The blue LED flashes, but apparently the OSC message is not sent. Also, the webserver is unreachable.
Also remarkable: my FTDI232 doesn't always communicate with the serial monitor of the Arduino IDE... Any ideas on what might be wrong here?
#define FIRMWARE "v0.4.3"
#define VERBOSE
//#define LOAD_DEFAULTS

#define BUTTONPIN 2

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <OSCMessage.h>

#include "globals.h"

void setup() {
  EEPROM.begin(128);

  #ifdef VERBOSE
    Serial.begin(9600);
    Serial.println("--------------------");
    Serial.println("QLab Spacebar Button");
    Serial.print("Firmware Version: ");
    Serial.println(FIRMWARE);
  #endif

  #ifdef LOAD_DEFAULTS
    #ifdef VERBOSE
      Serial.println("Load Default Settings:");
    #endif

    saveSettings();
    startHotSpot();
  #else
    // If we cant load settings from EEPROM, start the hotspot
    if (!loadSettings()) {
      startHotSpot();
    }
  #endif

  // Start hotspot if we're in standAlone mode otherwise we start the wifi
  if (standAlone == 1) {
    startHotSpot();
  } else {
    startWifi();
    allowHotSpot = 0; // Dont allow hotspot to run after this initial setup - must restart device to start it again
  }

  // Start WebServer
  startWebServer();

  // Start listening for UDP packets
  qUDP.begin(qlab_port);

  pinMode(BUTTONPIN, INPUT);
  attachInterrupt(BUTTONPIN, spacebar, RISING);
}

void loop() {
  webServer.handleClient();
}

void spacebar() {
  #ifdef VERBOSE
    Serial.println("Received a click -- will send OSC message now!");
  #endif
  OSCMessage msg("/go");
  qUDP.beginPacket(qlab_address,qlab_port);
  msg.send(qUDP);
  qUDP.endPacket();
  msg.empty();
  delay(500); //Safety measure: you can't press the spacebar twice
}

(Most of the other code is in other files, I think this is the only relevant part)
The wiring diagram for the ESP is as follows: (I don't know how to draw it so I'll just try to write it down...)
Gnd->Gnd
Tx -> Rx
Rx -> Tx
CH_PD -> 3.3v
Vcc -> 3.3v
GPIO2 -- 10k ohm resistor to 3.3v
      \_ Gnd (this is meant to be a button: pulled to Gnd when pressed)

How are you powering the ESP8266-01 ? A USB connection may not be able to supply sufficient power in all situations although a large value capacitor connected across the supply close to the ESP will help

You should not do too much in an interrupt routine. Ideally you would just set a flag and then poll that flag in loop() and do all the work there.

@Bra1n I'm powering the FTDI with the USB port from my laptop indeed... Do you think this draws too much current?
@Majenko I removed the interrupt and and put in the loop if(BUTTONPIN == HIGH) { spacebar(); } which seems to work better and consistently longer, although the webserver still isn't reachable all the time...

not sure if it applies to ESP's but with arduino, delay doesn't work inside an ISR, so that delay may be irrelevant anyway. But you're trying to do way too much inside the ISR as pointed out above

thanks for the comments -- moving the routine to the loop section seems to solve the problem. why is it that delays cause problems in an ISR?


text:
Transmit image file thougth the TX TR serial line
I have a digital camera with a USB port for image dowload from the camera SD card.
I will like to be able to capture this image files store in the camera SD card using the Arduino  TX TR lines (serial) then transmit this image file to the computer from the USB connection from Arduino to Computer.
The reason need this scenario responds to that the camera dissables the shutter when sensing a USB cable conneted to computer. I do not knwo why this happens but I suspect is an underdeveloped feature of the camera.
Basically, I will like to use Arduino as a USB hub for external devices but at the same time to power down the line when no longer need the device using the Arduino TX and TX line . This will give tha camera a sense that the camera is been unplugged.

simulate this circuit – Schematic created using CircuitLab

You cannot. The TX and RX lines are UART. UART is not USB. USB is a very complicated protocol, and you need a proper understanding of how it works. It's not a simple serial protocol like UART.
Add to that the fact that the Arduino can in no way handle the amount of data involved in video, and you're already on a non-starter.

Having this said, can you suggest a way to use Arduino to cut off the V data line transmition from the computer to the camera?  I need to fake the same as unplugging the USB.

What is the "V" transmission line? USB has D+ and D-, and they are both required all the time for communication.

@JoseEnriqueCalderon The closest you could possibly get would be to have the Arduino control a relay which disconnects both the D+ and D- lines from your computer, performing the same task as physically unplugging the camera. That means no communication in either direction.

If you want to read data from USB so connect an Arduino to an USB port, you must use an Arduino Leonardo. Arduinos don't have a "full USB", except the Leonardo.

@peter  , Please, I will like you to post this as an answear and in any way  elaborate a simple sketch or diagram. Thanks

@Majenko.... Thanks for the correction, I have found some places that uses this for voltage line and overlook that this is a data line.

The Leonardo's USB is device mode only. It can talk to a PC. It has no relevence to communicating with another USB device.


text:
Servo motor not working properly with arduino
I have some problem with my fyp, which is auto serving of food using train.
I have 4 servo motors, first servo motor's function is to connect the track to table no.1, and second motor for table no.2 and third and fourth motor for table no.3.
All the motors are performing well at first time..
but when I reset and give command for second or third table, motors behavior changes and they start rotating in arbitrary directions which are not defined in code.
but sometimes it works good and sometimes motors are not performing as expected.
I have check all the grounds and powers. they are all good.
Please help me, as I have my final submission in two days.
The code is given below..
Please check and tell me if I have a logical error in my code or any other issue regarding to hardware also tell me is their any cache in arduino, which I need to clean or something like that.
#include <Servo.h>

Servo motor;  // create servo object to control a servo
// twelve servo objects can be created on most boards

const int button1 = A1;
const int button2 = A2;
const int button3 = A3;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

void setup() {

  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);

  servo1.attach(9);
  servo2.attach(11);
  servo3.attach(6);
  servo4.attach(5);

  Serial.begin(9600);
}

void loop() {

  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3);

  if (buttonState1 == HIGH) {
    int pos1 = 180;
    int pos2 = 180;
    int pos3 = 90;
    int pos4 = 90;

    for (int pos2=90; pos2 <= 180; pos2 += 1) {
      servo2.write(pos2);
      delay(0);
    }
    for (int pos1=90; pos1 <= 180; pos1 += 1) {
      servo1.write(pos1);
      delay(50);
    }

    while (pos1 >= 0 && pos2 >= 0 && pos3 >= 0 && pos4 <= 180) {
//      servo1.writeMicroseconds (1000);

//      servo1.write(pos1);
//      servo2.write(pos2);
      servo3.write(pos3);
      servo4.write(pos4);
      delay(200000);                // 500ms delay
    }

  }
  else if (buttonState2 == HIGH) {

    int pos5 = 90;
    int pos6 = 0;

    for (int pos5=90; pos5 >= 0; pos5 -= 1) {
      servo1.write(pos5);
      delay(0);
    }
    for (int pos6=90; pos6 >= 0; pos6 -= 1) {
      servo2.write(pos6);
      delay(50);
    }

    while ( pos6 <= 180 && pos5 <= 180) {

//      servo2.write(pos6);
//      servo1.write(pos5);
      delay(200);
    }
//      while ( pos5 <= 180) {
//        servo1.write(pos5);
//        delay(200);
//      }

  }
  else if (buttonState3 == HIGH) {
    int pos9 = 90;
    int pos10 = 180;
    int pos11 = 0;
    int pos12 = 180;

    for (int pos10=90; pos10 <= 180; pos10 += 1) {
      servo2.write(pos10);
      delay(0);
    }
    for (int pos9=90; pos9 >= 0; pos9 -= 1) {
      servo1.write(pos9);
      delay(0);
    }
    for (int pos11=90; pos11 >= 0; pos11 -= 1) {
      servo3.write(pos11);
      delay(30);
    }
    for (int pos12=90; pos12 <= 180; pos12 += 5) {
      servo4.write(pos12);
      delay(50);
    }

    while ( pos9 <= 180 && pos10 >= 0 && pos11 >= 0 && pos12 >= 0) {

//      servo1.write(pos9);
//      servo2.write(pos10);
//      servo3.write(pos11);
//      servo4.write(pos12);
//      delay(200);
    }
//      while ( pos9 <= 180) {
//        servo1.write(pos9);
//        delay(200);
//      }
  }

}

Try to write a minimal example that works for only one of your "tracks" and then you may see where the problem lies.

I think reason for which you are not getting the expected result is because of you while loops in you if condition.
As you loops doesn't have any termination condition. In case of first button pressed you will get what you want because you have only single not terminating while loop, while in you Case of button 2 and button 3 there are two while loop's and both are not terminating.
In that case if you logic goes in first while loop, then it never comes out of it and won't go for second loop.
I don't know what are you up to so can't suggest on logic changes, but add termination in while loop might get you expected results.


text:
Class help - Same Object types seem to mix values with each other
I'm having issues with two objects of the same class type. I have a LED class, which has functions to fade in and out, a LED. In my code, I create two objects of this class, and on the board, I fade them in and out.
Code is in my FadingLED.h file, which I #include.
I instantiate these classes - and then in my setup(), I call an Init function on the classes to initialise them and pass all the parameters I need.
And then in the loop, I just keep calling an Update method, which internally, uses Millis() to handle updating the brightness of the LED.
But I think I am having cross contamination of the objects. Because if I trigger them both to fadein and out at the same time, only the first LED fades. If I stagger them, the 2nd LED works, but it's timing seems to be out. It seems like maybe I'm somehow mixing member variables within the class. I'm new to this, so it's probably an obvious fault?
My calling code:
// This #include statement was automatically added by the Particle IDE.
#include "Buzzer.h"
#include "FadingLED.h"

// Pins being used by devices.
int LED1_PIN = A4;
int LED2_PIN = A5;
int PIR_PIN = 3;
int BUZZER_PIN = 0;

// Instantiate the objects
FadingLED LED_1;
FadingLED LED_2;
Buzzer buzzer;

// Setup global variables.
bool AllStill = true;

// Setup.
void setup() {
    // Initialise the two LEDs
    LED_1.Init(LED1_PIN, 500, 0, true);
    LED_2.Init(LED2_PIN, 500, 250, true);
    // Set the PIR pinmode.
    pinMode(PIR_PIN, INPUT);
    Particle.publish("Device","Board initialised", PUBLIC);
    buzzer.Beep(100, 2200);
}

// Function to check if movement has been detected.
bool CheckMovement() {
    // Read the pin value.
    int val = digitalRead(PIR_PIN);

    // Has a new movement been detected?
    if(val==true && AllStill==true) {
        buzzer.Beep(200, 2200);
        AllStill = false;
        Particle.publish("Device", "Movement Detected", PUBLIC);
    }
    AllStill = !val; // All still is false if we have movement.

    return val != 0;
}

void loop() {
    // Check for moment.
    bool val = CheckMovement();
    // Update connected devices.
    LED_1.Update(val);
    LED_2.Update(val);
    buzzer.Update();
}

And then the class it's self.
/*
 * A class that manages a fading LED. This needs to be on PWM pin.
 */
class FadingLED {
  int             delayedStart = 0;               // Period to wait before starting.
  int             ledPin = -1;                    // The pin to control - Note, as we're fading, we must use an ANALOG pin.
  long            fadePeriod = 0;                 // The time to do a full light and dim cycle.
  unsigned long   previousMillis = 0;             // The previous millis value.
  bool            debug = false;                  // Should we output stuff?
  float           fadeChangeGap = 0;              // Calculated gap between brightness changes.
  unsigned long   firstMillis = -1;

public:
  void Init(int LedPin, int FadePeriod, int DelayedStart, bool Debug) {
    ledPin = LedPin;
    fadePeriod = FadePeriod;
    delayedStart = DelayedStart;
    debug = Debug;
    pinMode(ledPin, OUTPUT);
    Particle.publish("Debug", "LED Initialised on " + String(ledPin) + ", Fade Period is " + String(fadePeriod) + ", Start Delay is " +  String(delayedStart), PUBLIC);
  }

  void Update(bool isOn) {

      // Get the current millis since the board was started.
      unsigned long currentMillis = millis();

      // Is this the first time this code is running?
      if(firstMillis == -1)
        firstMillis = currentMillis; // Set the first time this class was run.

      // Adjust the current time to be based on the current time since the object was created.
      currentMillis = currentMillis - firstMillis;

      // Calculate the difference bwteen the last update and now.
      unsigned long diff = currentMillis - previousMillis;

      int brightness = 0;

      // Check if we have a delay set. If so, don't light up yet.
      if(delayedStart > 0 && currentMillis < delayedStart) {
        Particle.publish("LED", "In Delay Start...", PUBLIC);
         previousMillis = currentMillis;
        return;
      }

      // Map the difference which is betweem 0 and the cycle time, to a value between 0 and 512.
      // Map the difference, which is between 0 and the fade period, to a value between 0 at 512.
      int b = map(diff, 0, fadePeriod, 0, 512); // 512, as we'll brighten to 256, then then fade from 256 to 512.

      // Check if we should be bringtning, or fading...
      if(b > 255) {
        brightness = 255 - (b-255);
      }
      else
      {
        brightness = b;
      }

      if(isOn == false) {
        brightness = 0;
      }
      // Set the brightness.
      analogWrite(ledPin, brightness);

      // And then save the timestamp.
      if(currentMillis - previousMillis >= fadePeriod) {
         previousMillis = currentMillis;
      }
  }
};

Is there an error with how I am defining the class (I'd expect to use the 'new' keyword, but don't). Maybe in the class it's self, there is a way to say the field are private to that object only?
If I try:
FadingLED LED_1 = new FadingLED();

I get:

conversion from 'FadingLED*' to non-scalar type 'FadingLED' requested

Any assistance or advice would be great.

Keep it simple, keep it straightforward, don't try to do "smart" things that have consequences. You assign -1 to a unsigned long, that's no good. You compare -1 to a unsigned long, that's can't be right either. Avoiding the rollover problem is good, but introducing another similar problem by using -1 as a flag is not good. This: "currentMillis < delayedStart" is not good, even if it is only used after power on, it still causes a problem during the rollover. You need a clear and logical structured code in the update function. Think first what you want to do before writing down code.

The keyword 'new' is not needed, it would allocate it dynamically (which you don't need). In that case the statement should be FadingLED* LED_1 = new FadingLED(); Thus LED_1 would be a pointer.

Also you don't need to compare booleans against false or true, you can use if (bool_x) or  ir (!bool_x).

A4 and A5 don't work with analogWrite https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

I combined the FadingLED class with your "calling code" sketch, then removed the references to libraries that I don't have. The first error I received was regarding the seven lines of code immediately under the "class FadingLED {" line.
My answer will only address the issues with the way the class is written. As Jot and Michel Keijzers have mentioned in their comments to your question, there may be other issues that need to be fixed.
The following sketch uses a slightly modified version of the FadingLED class. There are 2 constructors. One is a "no argument" constructor, and the other accepts 4 arguments. Both constructors call the private function initStuff() to initialize other variables, pinModes, etc.
/*
 * A class that manages a fading LED. This needs to be on PWM pin.
 */
class FadingLED {

  private:

    int             delayedStart;     // Period to wait before starting.
    int             ledPin;           // The pin to control - Note, as we're fading, we must use an ANALOG pin.
    long            fadePeriod;       // The time to do a full light and dim cycle.
    unsigned long   previousMillis;   // The previous millis value.
    bool            debug;            // Should we output stuff?
    float           fadeChangeGap;    // Calculated gap between brightness changes.
    unsigned long   firstMillis;

    void initStuff(){
      previousMillis = 0;
      fadeChangeGap = 0;
      firstMillis = -1;
      pinMode(ledPin, OUTPUT);
      //Particle.publish("Debug", "LED Initialised on " + String(ledPin) + ", Fade Period is " + String(fadePeriod) + ", Start Delay is " +  String(delayedStart), PUBLIC);
    }

  public:

    FadingLED(): delayedStart(0), ledPin(-1), fadePeriod(0), debug(false){
      initStuff();
    }

    FadingLED(int LedPin, int FadePeriod, int DelayedStart, bool Debug):
      delayedStart(DelayedStart),
      ledPin(LedPin),
      fadePeriod(FadePeriod),
      debug(Debug){
      initStuff();
    }

    void Update(bool isOn) {

        // Get the current millis since the board was started.
        unsigned long currentMillis = millis();

        // Is this the first time this code is running?
        if(firstMillis == -1)
          firstMillis = currentMillis; // Set the first time this class was run.

        // Adjust the current time to be based on the current time since the object was created.
        currentMillis = currentMillis - firstMillis;

        // Calculate the difference bwteen the last update and now.
        unsigned long diff = currentMillis - previousMillis;

        int brightness = 0;

        // Check if we have a delay set. If so, don't light up yet.
        if(delayedStart > 0 && currentMillis < delayedStart) {
          //Particle.publish("LED", "In Delay Start...", PUBLIC);
          previousMillis = currentMillis;
          return;
        }

        // Map the difference which is betweem 0 and the cycle time, to a value between 0 and 512.
        // Map the difference, which is between 0 and the fade period, to a value between 0 at 512.
        int b = map(diff, 0, fadePeriod, 0, 512); // 512, as we'll brighten to 256, then then fade from 256 to 512.

        // Check if we should be bringtning, or fading...
        if(b > 255) {
          brightness = 255 - (b-255);
        }
        else
        {
          brightness = b;
        }

        if(isOn == false) {
          brightness = 0;
        }
        // Set the brightness.
        analogWrite(ledPin, brightness);

        // And then save the timestamp.
        if(currentMillis - previousMillis >= fadePeriod) {
           previousMillis = currentMillis;
        }
    }
};

// This #include statement was automatically added by the Particle IDE.
//#include "Buzzer.h"
//#include "FadingLED.h"

// Pins being used by devices.
int LED1_PIN = A4;
int LED2_PIN = A5;
int PIR_PIN = 3;
int BUZZER_PIN = 0;

// Instantiate the objects
FadingLED LED_1(LED1_PIN, 500, 0, true);
FadingLED LED_2(LED2_PIN, 500, 250, true);
//Buzzer buzzer;

// Setup global variables.
bool AllStill = true;

// Setup.
void setup() {
    // Set the PIR pinmode.
    pinMode(PIR_PIN, INPUT);
    //Particle.publish("Device","Board initialised", PUBLIC);
    //buzzer.Beep(100, 2200);
}

// Function to check if movement has been detected.
bool CheckMovement() {
    // Read the pin value.
    int val = digitalRead(PIR_PIN);

    // Has a new movement been detected?
    if(val==true && AllStill==true) {
        //buzzer.Beep(200, 2200);
        AllStill = false;
        //Particle.publish("Device", "Movement Detected", PUBLIC);
    }
    AllStill = !val; // All still is false if we have movement.

    return val != 0;
}

void loop() {
    // Check for moment.
    bool val = CheckMovement();
    // Update connected devices.
    LED_1.Update(val);
    LED_2.Update(val);
    //buzzer.Update();
}


text:
Digital Potentiometer (TPL0501) Control Issues
I'm using SPI library in my code for controlling a digital potentiometer (TPL0501) with Arduino Mega.
The code I have is:
#include <SPI.h>
byte address = 0x80;
const int CS = 53;
int SCLK = 52;
int i=0;

void setup()
{
  SPI.begin();
  pinMode (CS, OUTPUT);
  pinMode (SCLK, OUTPUT);
  SPI.setBitOrder(MSBFIRST);

}

void loop()
{

     for (i = 0; i < 256; i++)
    {
      digitalPotWrite(i);
      delay(100);
    }

    delay(5000);
    for (i = 255; i >= 0; --i)
    {
      digitalPotWrite(i);
      delay(100);
    }
}

int digitalPotWrite(int value)
{
  digitalWrite(CS, LOW);
  delay(100);
  SPI.transfer(address);
  SPI.transfer(value);
  delay(100);
  digitalWrite(CS, HIGH);

}

Following the datasheet, I think the code is correct because this is what the datasheet says:

Can someone help me identify the error in my code, if any, because when I try to read the resistance with an ohmeter, I do not get the expected values.

what is expected and actual value, can you provide any example for this?

@Vaibhav the end to end resistance is 100kOhms. It's supposed to give me output in that range, increasing values first, then decreasing. I'm using the component alongside a buck-boost converter, but am currently trying to only test the potentiometer alone.

Are you floating all H, L and W terminals? The voltage relative on this pins should not exceed GND-VDD range. Connect L to GND then measure the resistance again.

What is SPI.transfer(address); supposed to achieve? SPI has no "address" concept, unless it's for selecting registes within a chip - and that chip has none.

try and measure the voltage drop between pin W and L if H is floating or between H and W if L is floating.


text:
Where this function is defined?
This is the code for timer example in esp8266..(got from a website)
My doubt is where the function   timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE)  is defined ??
I am look in Ticker.cpp, but not found.

#include < ESP8266WiFi.h>
#include < Ticker.h >

Ticker blinker;

#define LED 2  //On board LED

//=======================================================================
void ICACHE_RAM_ATTR onTimerISR(){
    digitalWrite(LED,!(digitalRead(LED)));  //Toggle LED Pin
    timer1_write(600000);//12us
}

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

    pinMode(LED,OUTPUT);

    //Initialize Ticker every 0.5s
    timer1_attachInterrupt(onTimerISR);
    timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
    timer1_write(600000); //120000 us
}

void loop()
{
}

Found your example code here. Please always provide a link, when you ask questions about a code from the web.

Also note that in C++, trivial functions are sometimes fully implemented in the .h file, so a search of the .cpp file might not reveal any code. This is especially common for access functions ("setters" and "getters"), where a function definition takes no more space (or very little more) than a declaration would.

Those functions have nothing to do with the Ticker library. Those functions are defined in the ESP8266 core.
The example you cite has this at the top of it:

Hardware Timer0 is used by WiFi Functions. We can use only Timer1. Use of timer instead of Ticker gives advantage of precision timing and You can get timer interrupt in micro seconds.

Note the use of "instead of Ticker" there. That says that the code below has nothing to do with Ticker.


text:
Multiple slave(sender) to one master (receiver)
I beg your help to my project
I wish to send the data from slave to master but only one data is receive out of two slaves.
//master

#include <Wire.h>

void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

}

void loop() {
  Wire.requestFrom(8, 1);    // request 6 bytes from slave device #8

  while (Wire.available()) { // slave may send less than requested
    char c= Wire.read(); // receive a byte as character
    char q= Wire.read();

  Serial.print(c);         // print the character
  Serial.print(q);
  }

  delay(1500);
}

////slave 1
#include <Wire.h>

void setup() {
  Serial.begin(9600); // Starting Serial Terminal
  Wire.begin(8);                // join i2c bus with address #8
}

void loop(){
  Wire.onRequest(requestEvent); // register event

  delay(1500);
}
void requestEvent() {

  Wire.write('Q');
  Serial.println("Sent");
}

////slave 2
#include <Wire.h>

void setup() {
  Serial.begin(9600); // Starting Serial Terminal
  Wire.begin(8);                // join i2c bus with address #8
}

void loop() {
  Wire.onRequest(requestEvent); // register event

  delay(1500);
}
void requestEvent() {

  Wire.write('Y');
  Serial.println("Sent");
}

I think both slaves has same address that's why you are facing this issues, because master communicate with both slave with same address and receive only one data, that might be slave 1 or 2. You need to change slave address and synchronize the communication of both slave with master.

What hardware, i.e. microcontroller, are you using?

You cannot have 2 devices with the same address at the I2C bus. If they both try to send at the same time with different data, the data will either get corrupted, or one of the slaves will stop to send. You cannot request data from more than 1 device at once with I2C.
You have to give the slaves different addresses. Then you have to do the requests sequentially, first a request (with the corresponding read) to the first slave and after that is done, you can start a second request (with the corresponding read).

Besides that, the reading code is not good. You are testing in the condition of the while loop, if there is anything to read (which can be only 1 byte), but then you read 2 bytes. In your case you only have to read 1 byte, since you also request only 1 byte. In the case, when you request more than 1 byte, you can either check, if there are enough bytes in the buffer (with something like if(Wire.available()>=2) ), or you can just work through the buffer byte by byte (with while(Wire.available()){ data = Wire.read();} , note the single read in the while loop).


text:
Getting gibberish serial port until button is pressed, plus the button is turning the leds off instead of on
I'm connecting a button to ESP8266.
Connection goes like this:
3v to one side of button, other side connected with GND and pin number 2 (no resistor).
Every time I connect the ESP both built in LED's stay on until I press the button, they turn off until I let go (even though code states otherwise).
Plus, When I monitor the serial, gibberish runs while ignoring my print commands, until I press the button then the serial stops outputting altogether.
When I run the serial without the button, everything works fine.
Am I connecting it wrong, or is the button damaged, or any other problem source?
Thanks in advance.
EDIT: I added the pinMode(BTN_PIN, INPUT_PULLUP) to take the resistor role; to the code, still not helping.

You definitely need a resistor. Currently you are shorting your power supply. This will turn off your esp and eventually kill your power supply or the esp (depending on how you have everything connected

Thought so. Are you 100% sure I need a resistor? I think I have everything connected right as I described above.

You need a resistor somewhere. You can decide if you want to use an external one or the internal one that you activate with the INPUT_PULLUP statement

I added the statement to the input pin. But is there a work around for the GND pin resistor? or do I have to insert an actual physical one?

Got it to work eventually, apparently if I use the PULLUP command, I should remove the GND connection. Thanks for the help!

When pin 2 is connected to ground as you have done it puts the chip into an invalid boot mode. It will be spewing out messages at 74880 baud complaining about the boot mode being invalid.
You must not connect pin 2 to ground. It must, at boot time, be connected to 3.3V through a resistor (which is should be provided by the board for you if you use a development board not a bare module).
By connecting the button between 3.3V and GND you are causing a short circuit that removes the power from the module and risks damaging the power supply on your board.
The proper way of wiring a button is to use:
pinMode(2, INPUT_PULLUP);

and then connect the GPIO pin to ground through the button.
The INPUT_PULLUP acts like the required pullup resistor keeping the input HIGH while "idle", and the button connects the input to GND when you want to "activate" it, making it LOW.
Those are the only connections you should make.  If you want to use an external resistor instead of the internal one with INPUT_PULLUP, then that goes between the input pin and 3.3V.
Never ever cause 3.3V to be directly connected to GND.


text:
Using 18650 batteries with a 3.7v to 5v boost converter
I'm looking to set up a 1-meter strip of WS2812B LEDs (60 LEDs) with an off-the-shelf RF LED controller with a remote. The LEDs want a 5V supply - I've tried running them off 3.7v but the colour accuracy goes out the window and they start flickering and doing all sorts of other nonsense.
To work around that I'm considering using a DC boost converter like one of these pololu ones. I'll wire up a couple 18650 batteries in parallel to supply the voltage and my plan is to hook them up to the LEDs via the boost converter.
Idiot question time: is it safe to wire the boost converter directly to the output terminals of the battery/batteries and take the 5V off the +5v pin using a common ground? Or am I doing something dumb?
Also, I'm not 100% sure how to go about charging this setup. One option would be to put the batteries in cases and use an external charger with replaceable cells.
Would it make more sense to get one of these? This should be able to handle both charging AND stepping up the voltage, am I right?

How many LEDs are you going to be using?

Interesting question, but it's off topic.  Try Electrical Engineering SE

is it safe to wire the boost converter directly to the output terminals of the battery/batteries and take the 5V off the +5v pin using a common ground?

Yes. That is the normal way of using them.

Also, I'm not 100% sure how to go about charging this setup. One option would be to put the batteries in cases and use an external charger with replaceable cells.

That is the simplest option, yes. You shouldn't charge Li-Poly / Li-Ion batteries whilst using them - the load messes with the charge termination detection and can cause your batteries to over-charge and explode.

Would it make more sense to get one of these? This should be able to handle both charging AND stepping up the voltage, am I right?

That gets around the problem of charging while running, yes. A proper charger like that should bypass the battery when charging so the load is running from the incoming charge power rather than the battery.
One option you haven't considered though is to not use step-up.  Step-up is harder to manage with heavy loads. As you can see that first step-up module you link to has an upper limit of only 1.2A.  If you have 60 LEDs per meter, and 1 meter of LED strip, that's a maximum of 3.6A (60 * 0.02 * 3) which is 3x what that module can provide.
A better solution would be to use two batteries in series, not parallel, to give you about 7.2V. Then you can use a step-down switching regulator to give you your 5V and have far higher current limits.  Looking for a "UBEC" or "SBEC" in a model RC supplier shop is usually a good bet. For example:

Turnigy 5A (8-26v) SBEC for Lipo

HobbyKing™ HKU5 5V/5A UBEC

These are all designed for use with two or more LiPoly batteries in series.

Great answer. (Voted.)

Would those work with Li-ion batteries as well? Li-poly batteries are a bit wide for what I'm looking to do - the cylindrical form factor of the 18650 batteries feels like a better option.
I like the idea of using a step-down regulator - I hadn't considered that! Thank you!.

@poolski Yes, for all intents and purposes Li-Poly and Li-Ion are interchangeable. The main difference is the binding used to contain the battery components which gives the different shape.

@Majenko How would charging be handled with a step-down regulator? Those both look like they're just for regulating power, not charging. Would I need to build a charging circuit in or use removable cells?

Would wiring in something like this deal with the charge control and making sure that the circuit is powered from the right source while charging, do you think?
Edit: that seems like it has the same problem - it can't output more than 1A :(

You would typically use removable batteries with a UBEC


text:
HX711 Soft WDT Reset
I am using the following code to check if the value is 0 e.g there is no weights placed and if so, it will ignore this value and do nothing with it. The code runs correctly but keeps outputting the following:

Soft WDT reset

stack>>>

ctx: cont sp: 3ffffd70 end: 3fffffc0 offset: 01b0 3fffff20:  00000050
  00000000 31310010 36323439   3fffff30:  00000000 00000000 00000010
  00000001   3fffff40:  3ffee408 00000000 00000000 40202927   3fffff50:
  4022dff2 a0000000 bf2cc404 3ffe84dc   3fffff60:  3ffee408 bf2cc404
  3ffee408 40202962   3fffff70:  3ffeeb9c 40202c00 3ffee408 40202996
  3fffff80:  3ffee448 bf2cc404 3ffee408 40202664   3fffff90:  3fffdad0
  fffe2d7e 3ffee448 3ffee4b0   3fffffa0:  3fffdad0 00000000 3ffee480
  40203848   3fffffb0:  feefeffe feefeffe 3ffe8514 40100a41
  <<

If I remove if(reading < 0.01){ the code runs fine. What could be causing this?
#include "HX711.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define DOUT  D3
#define CLK  D2
const char* ssid = "Curtis";
const char* password = "password";

HX711 scale(DOUT, CLK);
float calibration_factor = -118470; //-7050 worked for my 440lb max scale setup
void joinwifi(){
    WiFi.begin(ssid, password);
  Serial.println();
  Serial.print("Connecting");
   while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("success!");
  Serial.print("IP Address is: ");
  Serial.println(WiFi.localIP());
}
void setup() {
  Serial.begin(9600);
  joinwifi();
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}
void loop() {
  while (WiFi.status() == WL_CONNECTED)
  {
    scale.set_scale(calibration_factor); //Adjust to this calibration factor
    float reading = scale.get_units(1);
    if(reading < 0.01){
      Serial.print("no need");
       Serial.println();
    }
    else{
      Serial.print("Reading: ");
      Serial.print(reading);
      Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
      Serial.print(" calibration_factor: ");
      Serial.print(calibration_factor);
      Serial.println();
      if(Serial.available())
      {
        char temp = Serial.read();
        if(temp == '+' || temp == 'a')
          calibration_factor += 10;
        else if(temp == '-' || temp == 'z')
          calibration_factor -= 10;
      }
    }
  }
  while (WiFi.status() != WL_CONNECTED)
  {
    joinwifi();
  }

}

Because your code is all running in a while inside your loop (which is redundant - loop() loops, hence its name), and you have no delays or yield() calls, you are not giving the watchdog the required kick that it needs to stay alive.
Either remove your whiles and turn them into ifs instead, or add yeild() calls inside your while loops.

@CurtisBoylan if it solves the issue then please accept Majenko's answer as the solution.


text:
ESP-12F responds only to a few basic AT commands
I previously read a few guides and tutorials about the ESP8266 and i just started using the ESP-12F module as i think that it is a terrific replacement for Arduino with the added benefit of Wi-Fi. I only have the module itself which is basically a metal casing so, i wired up the ESP-12F module according to this schematic.
My USB-TTL board is operating at 3 V for its VCC and also for the TX and RX logic levels. I use Arduino IDE 1.8.9 (i made sure that i am using the latest stable version) and then set the COM port to the USB-TTL RS232 connected to the ESP12F and typed "AT" and got a response "OK". Then, i tried, "AT+RST" and got a big bunch of text which proved that there is successful communication with the ESP module. But then, i tried to connect the ESP-12F to my Wi-Fi network, so i entered: AT+CWJAP_CUR="SSID","password" replacing the SSID and password with my own and it gave the response "ERROR", so i tried the old format AT+CWJAP="SSID","password" and again i got "ERROR". So, what am i doing wrong? How to fix this? I was thinking that maybe the firmware on my ESP is old and needs to be updated, so i entered "AT+GMR" and i got this info:
19:07:27.560 -> ready
19:07:27.560 -> AT+GMR
19:07:27.560 -> AT version:1.2.0.0(Jul  1 2016 20:04:45)
19:07:27.560 -> SDK version:1.5.4.1(39cb9a32)
19:07:27.560 -> Ai-Thinker Technology Co. Ltd.
19:07:27.560 -> Dec  2 2016 14:21:16
19:07:27.560 -> OK

Do i need to update my module to be able to connect it to my Wi-Fi? If yes, how? I want to update it as safely as possible as this is my only ESP module and i don't want to inadvertently damage it.

Try AT+CWMODE=1 first to put it into STA mode.

I did as you said and it worked! Thanks for the help. I will keep digging into the Espressif AT commands datasheet to learn more. By the way, is it advisable to update the firmware at this point?

Personally I never use the AT firmware. I always program the ESP8266 directly from the Arduino IDE (well, from UECIDE actually, but the principle is the same).

AT+CIUPDATE after you connected it to Internet

You can't connect to an access point until you put the module into Station mode.
AT+CWMODE=1

That will put it in STA mode.  You can alternatively make it an access point (AP mode) with:
AP+CWMODE=2


text:
avrdude: stk500_getsync(): not in sync: resp=0xyy ... where to find the response values?
Last week I retried some of my Arduinos and one Mega was working without a problem, but two Uno's didn't work anymore. The error I got was something like:
avrdude: stk500_getsync(): not in sync: resp=0xyy

Where yy where all different kind of values (I cannot copy/paste it as I'm not near the Arduino's).
Does anybody know where to find a document what the response values mean?

They don't mean anything.
AVRDude sends a packet, and expects a certain response. When it gets something that it's not expecting it tells you it's "out of sync", and tells you what the actual response was it got. That is, what byte it received over the serial port.  That could be something that your sketch is sending, or complete garbage if you're communicating with a floating serial input, or anything at all.

Thanks, no wonder I couldn't found an 'error table'  ... I would hope it would mean something more useful ... in that case I try it on another computer and otherwise I have some dead Uno's.

Are they real ones? Or the dreaded CH340G?

One is a real one (even with a removable DIP Atmel) and the other is a CH340G.

Step one of diagnosis is to try a loopback test. Hold the board in RESET, and connect pin 0 to pin 1. Try and communicate and see if what you send is echoed back.

Good advice thanks ... I will try it (probably in weekend, not much home until that time).


text:
I have a problem with my nano arduino and the nrf24l01 as receiver
Hello I have a problem with my nano arduino and the nrf24l01 as receiver . I'm trying to upload my code to my board, but it say that my code have this mistake:
Receiver:45:10: error: void value not ignored as it ought to be
exit status 1
void value not ignored as it ought to be
the complet code is:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

//Receiver Code (Hand)

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem

//define the servo name
Servo myServo1;
Servo myServo3;
Servo myServo4;
Servo myServo2;
Servo myServo5;

RF24 radio(9,10);     /*This object represents a modem connected to the Arduino.
                      Arguments 9 and 10 are a digital pin numbers to which signals
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int msg[5];

void setup(){

  //define the servo input pins
  myServo1.attach(15); //A1
  myServo2.attach(16); //A2
  myServo3.attach(17); //A3
  myServo4.attach(18); //A4
  myServo5.attach(19); //A5

  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);   //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }

void loop(){
  if(radio.available()){
    bool done = false;
    while (!done){
    done = radio.read(msg, sizeof(msg));

    myServo1.write(msg[2]); //A1
    myServo2.write(msg[4]); //A2
    myServo3.write(msg[3]); //A3
    myServo4.write(msg[1]); //A4
    myServo5.write(msg[0]); //A5
    }
  }
}

and the problen is here:
done = radio.read(msg, sizeof(msg));
I don't know hoy to make that comes out as a code. I'm sorry.
I'm trying to program a bionic hand but i have just started to work with arduino boards and their respective prongram. If someone can help me I would be very grateful. thanks

radio.read() does not return a value.  You can't assign "no value" to a boolean.
If radio.available() is true then radio.read() will succeed. There is no need to test if it worked or not.