text:
LED turning on late
I am using an Arduino nano and an ESP8266. I have burnt an Arduino, but when I send a request to the Arduino LED, it takes some time to turn ON.
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); //Pin 2 & 3 of Arduino as RX and TX. Connect TX and RX of ESP8266 respectively.
#define DEBUG true
#define led_pin 11 //LED is connected to Pin 11 of Arduino
#define LED1 6
#define LED2 7
#define LED3 4
#define LED4 5

void setup()
  {
    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, LOW);
     pinMode(LED1,OUTPUT);
 pinMode(LED2,OUTPUT);
 pinMode(LED3,OUTPUT);
 pinMode(LED4,OUTPUT);
    Serial.begin(115200);
    esp8266.begin(115200); //Baud rate for communicating with ESP8266. Your's might be different.
    esp8266Serial("AT+RST\r\n", 5000, DEBUG); // Reset the ESP8266
    esp8266Serial("AT+CWMODE=1\r\n", 5000, DEBUG); //Set station mode Operation
    esp8266Serial("AT+CWJAP=\"shubham\",\"shubh@1\"\r\n", 5000, DEBUG);//Enter your WiFi network's SSID and Password.

    //while(!esp8266.find("OK"))
    //{
     //}
    esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);
     esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);
      esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);//You will get the IP Address of the ESP8266 from this command.
    esp8266Serial("AT+CIPMUX=1\r\n", 5000, DEBUG);
    esp8266Serial("AT+CIPSERVER=1,80\r\n", 5000, DEBUG);
  }

void loop()
  {
   String IncomingString="";
 boolean StringReady = false;

 while (esp8266.available()){
   IncomingString=esp8266.readString();
   StringReady= true;
  }

  if (StringReady){
    Serial.println("Received String: " + IncomingString);

  if (IncomingString.indexOf("LED1=ON") != -1) {
    digitalWrite(LED1,HIGH);

   }

  if (IncomingString.indexOf("LED1=OFF") != -1) {
    digitalWrite(LED1,LOW);

   }

     if (IncomingString.indexOf("LED2=ON") != -1) {
    digitalWrite(LED2,HIGH);
   }

  if (IncomingString.indexOf("LED2=OFF") != -1) {
    digitalWrite(LED2,LOW);
   }

     if (IncomingString.indexOf("LED3=ON") != -1) {
    digitalWrite(LED3,HIGH);
   }

  if (IncomingString.indexOf("LED3=OFF") != -1) {
    digitalWrite(LED3,LOW);
   }

  if (IncomingString.indexOf("LED4=ON") != -1) {
    digitalWrite(LED4,HIGH);
   }

  if (IncomingString.indexOf("LED4=OFF") != -1) {
    digitalWrite(LED4,LOW);
   }

  }
 }

String esp8266Serial(String command, const int timeout, boolean debug)
  {
    String response = "";
    esp8266.print(command);
    long int time = millis();
    while ( (time + timeout) / millis())
      {
        while (esp8266.available())
          {
            char c = esp8266.read();
            response += c;
          }
      }
    if (debug)
      {
        Serial.print(response);
      }
    return response;
  }

Try changing the while to an if.

change while to if and use esp8266.readStringUntil('\n'); esp8266.readString(); has a 1 second timeout after the last received character (because it doesn't know it was the last). https://www.arduino.cc/reference/en/language/functions/communication/serial/readstringuntil/


text:
What USB to UART chip provides highest data rates with Arduino boards?
Checking out online stores for a USB/TTL adapter, I came across a wide range of products, and I'm having a hard time selecting the one which would achieve the highest data rate. I was comparing datasheets of the chips I have seen so far, to understand which baud rates are supported:

FT232R (FTDI): 183 to 3M baud, including 250k, 500k and 1M, 128 RX / 256 TX FIFO
PL2303 (Prolific): 75 to 1.2M baud, not including 250k, 500k and 1M, 256 RX / 256 TX FIFO
CP2102 (Silicon Labs): 300 to 921600 baud, including 250k and 500k, 576 RX / 640 TX FIFO
CH340G (WCH): 50 to 2M baud, not including 250k, 500k and 1M, unknown FIFO size

As explained here, 500k, 1M and 2M are particularly important, because those are the highest baud rates supported with 16MHz crystals. Moreover, data transmission becomes CPU-limited above 500k, so real data rates are practically the same with all three baud rates.
Am I right to assume that in order to get the highest data rate, I essentially have to stay away from PL2303, and prefer FT232R adapters, the other two chips being in the middle? Or are there other factors that I didn't take into account which may affect my choice?

If you really want a high data rate then you should use an Arduino that supports USB natively so you can bypass the bridge entirely.

@IgnacioVazquez-Abrams, the 32u4 for example does support USB

@IgnacioVazquez-Abrams Obviously, the question makes no sense for boards with native USB support. If I were to use Atmega32u4, why would I be shopping for a UART adapter?

At higher data rates the quality of the connection between the UART bridge and the main MCU becomes a factor. I have had reliable communication between FT232 and a PIC32 at 3Mbaud with both chips on the same board and properly routed traces. With separate boards I struggle to get reliable communication at 2Mbaud with 1Mbaud being about the limit.

For high throughput UART isn't really the best technology. As mentioned before you really want to go for direct USB if at all possible. It's all about selecting the right chip to build your project around, not just plumping for the "default" option.

@Majenko With separate boards I struggle to get reliable communication at 2Mbaud - this is a very important point IMO, it means that CP2102 may be actually faster than CH340G in this case. Regarding your second comment, I agree that UART isn't the best for high throughput, but when you have a choice between increasing the baud rate and migrating the project to a board with native USB support, a good UART chip may save you a lot of time.

I guess that another parameter to consider is the amount of internal buffers in these devices. To reach higher throughput you end up having to optimize the Arduino HardwareSerial code (for higher baudrate) and find faster methods to do conversion (e.g. dtoa). These are some of the tricks I did in Cosa to reach >90% effective throughput for up to 2 Mbit. Please see forum for further details https://forum.arduino.cc/index.php?topic=150299.555

@MikaelPatel I have added FIFO sizes to my question. Do they have a big impact on the throughput in practice?

@DmitryGrigoryev Thanks for adding the FIFO size. It is actually important to understand how data flows. The USB signalling/protocol is not each character and it has its own "baudrate". Buffering allows bursts of packages and reduction of the signaling overhead (upstream), and helps even out bit-rate (downstream).

Here's my experience with the above chips over the last two years:
FT232R is the fastest, works well with any baudrates. UART adapters with it are sometimes more expensive than alternatives.
PL2303 is good if you don't plan to go faster than 115200. Additionally, it has the strongest 3.3V reference (available on some adapters as 3.3V output) which can be abused as a 3.3V 20mA power supply. Other chips will refuse to work if you draw more than 5mA from the 3.3V reference.
Prolific is currently fighting against clones by making their up-to-date drivers incompatible with non-original chips, so if your adapter won't work in Windows with code 10, take a look at this page.
CP2102 which looks great in theory didn't work well for me (in Windows 10, with driver v10.1.3). Bulk data transfers at 115200 were in some cases 4 times as slow compared to other chips.
CH340G has a sketchy-looking windows driver, but otherwise works quite well and is often the cheapest option available. Unfortunately, it lack the intermediate baud rates, and getting 2Mbps UART link to work may be hard sometimes. Arduino clones which have this chip on-board do work at 2Mbps without issues (the ones I have seen do, anyway).

source: Stack Exchange

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

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

sort: votes


text:
Arduino motor rotation
I am a beginner in Arduino. Below is my code to propel the fans of my motor. This happens in a clockwise direction but I wish to change the direction of rotation.
How can I modify it?
// Declare the pin for the motor
int motorPin = 9;

void setup() {
  // Define pin #9 as output
  pinMode(motorPin, OUTPUT);
}

void loop() {
  // Turn motor on
  digitalWrite(motorPin, HIGH);
  // Wait 250 ms
  delay(250);
  // Reanimate motor
  digitalWrite(motorPin, HIGH);
  // Wait 250 ms
  delay(250);
  // Turn motor off.
}

can you please tell something about your motor i.e. datasheet, name of some schematics?

Rewrite your code. Your code doesn't even turn off your motor. Then tell us, which shield you are using for motor control and give us information about your wiring. Without further information nobody will be able to answer your question.

Swap the wires over?

I guess you have a DC motor in use. Likely a FET drives it on port 9.
This arrangement is enough to start or stop the motor, however to change direction, you need to swap the two wires on the motor.
I guess you may perfer to do this in software - and for that you need to replace the simple FET driver with a H-Bridge. H-Bridge is an arrangement of electric switches which allows you swapping motor polarity, and it usually comes pre-assembled to a chip.
There are a vast amount of h-bridge motor driver chips to choose from. Google for "pololu motor driver", or "adafruit motor driver".
You can find all the further details in the Arduino examples on the web, e.g.:
https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing/overview

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


text:
Wi-Fi from Arduino to computer serial COM
I am somewhat new to the Arduino world and so far having fun. I am making a gardening watering system for my first project. I am at the final stages of completion and want to add a Wi-Fi module on the Arduino to send to my computer and display via serial COM the soil moisture and other relevant measurements I have going.
Now my question is, is it possible the simple analog information from my Arduino to my computer's serial COM with the Wi-Fi module ?

I fail to see where the COM port fits into the equation.

Well like I said I am still very new, so when I usually display the analog information I can usually find it under the serial COM because thats where I printed it. Is there a simpler way I can view the information on my computer?

Well, with a WiFi module you are connected to your local network wirelessly. Your computer is already connected to that network, so you just communicate through the network. Programming that sort of thing is considerably more complex though.

But is it possible to have my Serial Monitor on my computer display the information from the arduino via wifi?

No. WiFi isn't serial. The closest you could get is through Telnet.

You can of course put a serial wifi-module at both the Arduino and the PC end and get exactly what you have asked for, but adding extra wifi hardware at the PC end just to get the data appearing on a serial port rather than a network socket seems a bit silly.

I would recommend using Bluetooth, as Bluetooth communication is
mostly done by using COM Ports.
You can use HC05/HC06 Bluetooth Modules with Arduino.
You can easily pair your PC with these Bluetooth Modules.
Now, you write an application in any programming language to get &
send data to your Arduino via Bluetooth COM ports.

ok Thank you, What is the difference between the HC05 and 06? Is one better than the other?

They are approximately the same. Either one will work. Nothing to worry about.

you can use ESP8266 with ESP-LINK firmware.
There is nothing to it.Check out github.com/jeelabs/esp-link for documentation, examples and such.
Connect ESP8266 to Arduino URXD:
connect to TX of microcontroller UTXD:
connect to RX of microcontroller GPIO0:
connect to RESET of microcontroller GPIO2:
optionally connect green LED to 3.3V (indicates wifi status) And that about it. Everything else is done over WiFi

How? Can you provide more details, circuit schematic, some code, an explanation?

There is nothing to it.Check out https://github.com/jeelabs/esp-link for documentation, examples and such. Connect ESP8266 to Arduino URXD: connect to TX of microcontroller
UTXD: connect to RX of microcontroller
GPIO0: connect to RESET of microcontroller
GPIO2: optionally connect green LED to 3.3V (indicates wifi status) And that about it. Everything else is done over WiFi

Could you edit and update your answer, and put the extra details in there, rather than in comments? It just keeps the site tidier, as well as making your answer more succinct, and means people don't have to look through comments to get the complete picture. Thx.

As @Greenonline has indicated, please update your answer to better reflect and format what you've said in your comments.


text:
Split string into an array of string
I have a SIM900 module connected to an Arduino Uno, using an AT command for listing the SMS I get this output, how can i split this based on (,) to store each data in an array?
AT+CMGL="ALL"

+CMGL: 2,"REC READ","+639321576684","Ralph Manzano","16/04/25,21:51:33+32"
Yow!!!

OK

Since arduino is very limited in memory and available flash, I suggest you to avoid trying to split the whole line in chunks, but rather just take the segments you need. If you can't, then it would still be better not to store it, but rather analyze the segments one by one while you read them. Anyway I suggest you to parse the whole line one char at a time and check it, but be careful that there is a comma also between the date and the time, so if you don't want it to be split you should also group the parameters according to the double quotes

You could try to use strtok. Code from my mind and not tested:
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char string[] = "AT+CMGL=\"ALL\"\n"
    "\n"
    "+CMGL: 2,\"REC READ\",\"+639321576684\",\"Ralph Manzano\",\"16/04/25,21:51:33+32\"\n"
    "Yow!!!\n"
    "\n"
    "OK\n";
    char delimiter[] = ",\n";

    // initialize first part (string, delimiter)
    char* ptr = strtok(string, delimiter);

    while(ptr != NULL) {
        printf("found one part: %s\n", ptr);
        // create next part
        ptr = strtok(NULL, delimiter);
    }

    return 1;
}

Outputs:
found one part: AT+CMGL="ALL"
found one part: +CMGL: 2
found one part: "REC READ"
found one part: "+639321576684"
found one part: "Ralph Manzano"
found one part: "16/04/25
found one part: 21:51:33+32"
found one part: Yow!!!
found one part: OK

thank you so mcuh! but the strings may vary depending on the message sent, who sent the message and when it was sent, how can i parse this?

@Ralph I updated my answer. You can have multiple delimter. I think you should be able to parse all the needed information out of the string you get ;)

ohhh thank you! does this mean ill just store the response of the at command in the string[] array? and ill be able to parse it despite the content?

@Ralph imho yes

sorry im really new to parsing, will definitely try this, thanks!


text:
Strange issue with FHT library for sound-reactive LED project
I have been playing with the FHT library and have run into an interesting issue with fht_mag_octave() disrupting the output of my ADC actions.  Running on a MEGA ADK.
The idea is that I'm using FHT to read in the microphone input into A0, but also occasionally checking A2 pot to adjust the volume/brightness of the of the overall FastLED strip.
Here is the code in question...  it's barebones.  Just the standard FHT loop and then, every 100 loops, it checks A2 for the brightness setting.
#include <FastLED.h>

#define LED_PIN     6
#define BRIGHTNESS  200
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 16
CRGB* const leds(NUM_LEDS);

#define LOG_OUT 1 // use the log output function
#define OCTAVE 1 //   // Group buckets into octaves  (use the log output function LOG_OUT 1)
#define OCT_NORM 0 // Don't normalise octave intensities by number of bins
#define FHT_N 128 // set to 128 point fht
#include <FHT.h> //

void setup() {
  Serial.begin(9600);
  delay(1000);
  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness (BRIGHTNESS);

  // TIMSK0 = 0; // turn off timer0 for lower jitter (commented this out b/c I think this interferes with FastLED)
  ADCSRA = 0xe5; // set the adc to free running mode (0b11100101), prescalar=32 for higher ADC clock freq
  ADMUX = 0x40 | (0 & 0x07); // use adc0 (0b1000000)
  DIDR0 = 0x01; // turn off the digital input for adc0

}

int counter = 0;

void loop() {

  while (1) { // reduces jitter

    cli();  // UDRE interrupt slows this way down on arduino1.0

    for (int i = 0 ; i < FHT_N ; i++) { // save 128 samples
      while (!(ADCSRA & 0x10)); // wait for adc to be ready  in binary 0010000 (look for ADC Interrupt flag to be set to 1)
      ADCSRA = 0xf5; // restart adc (in binary 11110101...http://www.robotplatform.com/knowledge/ADC/adc_tutorial_2.html)
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fht_input[i] = k; // put real data into bins

    }

    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_octave();
 //   fht_mag_log();

    // every 100th loop, adjust the volume accourding to the value on A2 (Pot)
    if (counter > 10) {

      ADMUX = 0x40 | (2 & 0x07); // set admux to look at Analogpin A2

      while (!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int brightness = (j << 8) | m; // form into an int

//      brightness = map(brightness, 0, 1023, 0, 255);
      Serial.print("b: ");
      Serial.println(brightness);

      FastLED.setBrightness (brightness);

      ADMUX = 0x40 | (0 & 0x07); // set admux back to look at A0 analog pin (to read the microphone input
      counter = 0;
    }

    counter++;
    sei();

  }
}

Here's the output as shown (basically, it's outputting nonsense, non-int values):
b: ⸮
b: ⸮
b:
b:
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b: ⸮
b:
b: ⸮
b: ⸮
b:

b: ⸮
b: ⸮
b:

If I comment OUT the fht_mag_octave line and uncomment fht_mag_log(), here is the output (which looks right as I turn the Pot pin):
b: 0
b: 0
b: 0
b: 0
b: 0
b: 9
b: 35
b: 38
b: 48
b: 85
b: 143
b: 171
b: 188
b: 204
b: 224
b: 245
b: 280
b: 332

The issue is that the A2 value "brightness" does not read properly if I use fht_mag_octave().  If I comment out only the fht_mag_octave() line, it works perfectly.  I can also use fht_mag_log instead, and it works fine.
This makes me think that there is something that fht_mag_octave() does something that interferes with the ADC registers.
Any ideas?

Did you try successive readings every 100 to see if it changes?

Hi!  Yes.  The code shows the loop (I've adjusted it from every 100 cycles to every cycle...with no changes in behavior).  The values do change as I turn the Pot (when I comment out the fht_mag_octave() line, but i get gibberish otherwise.  This tells me that the Pot pin is set up correctly, and that the core ADC calls are working. The ONLY variable is fht_mag_octave()

I meant repeat consecutive A2 only

@TonyStewart, You are a genius!  That worked.  I just added a duplicate A2 read right after, and the results of the 2nd read were spot on!  What do you think the cause is?  And why wouldn't just adding a delay before the 1st call have solved it?

I have no idea of cause, I am glad my intuition was correct.  Only the OEM knows for sure.

Thanks to @TonyStewart for suggesting that I just do a successive A2 read.
I modified the code by just repeating the A2 read.  b1 is the first read, and b2 is the 2nd read.
  while (!(ADCSRA & 0x10)); // wait for adc to be ready
  ADCSRA = 0xf5; // restart adc
  byte m = ADCL; // fetch adc data
  byte j = ADCH;
  int brightness = (j << 8) | m; // form into an int

  Serial.print("b1: ");
  Serial.print(brightness);

  while (!(ADCSRA & 0x10)); // wait for adc to be ready
  ADCSRA = 0xf5; // restart adc
   m = ADCL; // fetch adc data
   j = ADCH;
   brightness = (j << 8) | m; // form into an int

  Serial.print("   b2: ");
  Serial.println(brightness);

And the readout looks good.  B1 is now legible, but incorrect/low.  B2 looks accurate and scales all the way to 1024 as I wanted.

b1: 0   b2: 688
b1: 0   b2: 739
b1: 0   b2: 816
b1: 20   b2: 915
b1: 118   b2: 1016
b1: 152   b2: 1023
b1: 172   b2: 1023
b1: 165   b2: 1023
b1: 180   b2: 1023
b1: 188   b2: 1022
b1: 184   b2: 931
b1: 127   b2: 713
b1: 0   b2: 615
b1: 0   b2: 532
b1: 0   b2: 436
b1: 0   b2: 327
b1: 0   b2: 304
b1: 0   b2: 452

I'm still curious about the reasoning behind this...but I'm glad that there is a solution, and not one that is too painful.

I was experiencing something similar, adding a delay solved the issue (?), no idea why. Later trying other things I realized that if you print a number before all of this, the output will be correct (??!).
So I have in my setup function this:
// trick to 'clean and set' Serial printer to avoid    // printing weird characters instead of numbers   Serial.println(0);

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


text:
Does WiFiClient work on a Yún to send data over a certain IP and port to be received by a Python socket?
I haven't been able to get the example code from the page WiFi:Client:connect() to work on my Arduino Yún. Is this not how I'm supposed to send data over WiFi to be read by something like a socket?
If not, how would I go about doing so? (This is the only solution I've found from the internet).

No, that code is only for the WiFi shield.  For the Yun you need to look at the Bridge library that is bundled with the IDE. It allows you to run commands and perform actions on the Linux based Atheros portion of the Yun which is what has access to the WiFi.


text:
Arduino Micro project with Bluetooth low energy
I created my project prototype with Arduino Micro and Adafruit Bluetooth low energy device.
Now I need to develop the prototype to production (like a small USB device). I just need Rx, Tx, 3V pin from Arduino Micro.
I started design with ATmega32U4, USB and BLE by using Fritzing IDE. I am confused with Arduino Micro parts like reset, bootloader and other pins. Is there any problem if I leave the unwanted pins from Arduino unconnected, for my project? Will it work correctly like a Arduino micro?
This is my first PCB design. Please help me to design a final PCB with the unwanted pins left unconnected.

Can you be more specific about what the problem is? Also, do you plan on sending the board out to be manufactured in one of those popular board fabrication shops online, or do you intend to build it yourself?

Thanx. @Ricardo.  Problem.is it need all part in arduino micro for my product production because I wana make my usb device is smallest as possible.  And also I dont know where  I connect 3.3 volt from regulator in atmega32u4.  Please hrlp through schematic diagram. I try to design my self and send board ptoduction through fritzing

How about using a RFduino SMT Module (www.rfduino.com) or something similiar?!

I have started to look at the Arduino Uno schematics, which are free on the website. To make an Arduino is very simple, just need the chip, crystal, a few capacitors and that's it.
Try to copy the same schematics then add the Bluetooth to the RX and TX pins, but be careful about the 3.3V as you don't want to fry your Bluetooth module :)


text:
Arduino thermometer and humidity display with 7 segment LED display
I want to use an Arduino Uno, a seven segment LED display (four digits) and the SevSeg library, to see temperature and humidity (alternatively).
First of all I try this code:
  #define COMMON_ANODE 1
  #define COMMON_CATODE 0
  #include "DHT.h"
  #define DHTPIN A5     // pin analogico che legge i dati
  #define DHTTYPE DHT22   // DHT 22  (AM2302)
  #include "SevSeg.h"

  // Crea un'istanza dell'oggetto
  SevSeg sevseg;
  DHT dht(DHTPIN, DHTTYPE);
  unsigned long timer; // the timer
  unsigned long INTERVAL = 5000; // the repeat interval (30 seconds)

  int segA = 6;   // Undicesimo PIN del display 7Segment x 4
  int segB = 2;   // Settimo PIN del display 7Segment x 4
  int segC = 10;  // Quarto PIN del display 7Segment x 4
  int segD = 12;  // Secondo PIN del display 7Segment x 4
  int segE = 13;  // Primo PIN del display 7Segment x 4
  int segF = 5;   // Decimo PIN del display 7Segment x 4
  int segG = 9;   // Quinto PIN del display 7Segment x 4
  int segDP = 11; // Terzo PIN del display 7Segment x 4

  int digit1 = 7; // Dodicesimo PIN - PWM che Accende il primo digit
  int digit2 = 4; // Nono PIN - PWM che Accende il secondo digit
  int digit3 = 3; // Ottavo PIN - PWM che Accende il terzo digit
  int digit4 = 8; // Sesto PIN - PWM che Accende il quarto digit

  void setup()
  {
    dht.begin();
    int numberOfDigits = 4; //Numero di cifre del display

    // Inizializzo i PIN
    sevseg.Begin(COMMON_CATODE,digit1,digit2,digit3,digit4,segA,segB,segC,segD,segE,segF,segG,segDP);
    // Imposto la luminosità (valore da 0 a 100)
    sevseg.Brightness(90);
    timer = millis(); // start timer
  }

  void loop()
  {
    if ((millis()-timer) > INTERVAL) {
      // Reset the timer and get/display the current temperature
      timer += INTERVAL;
      // Leggo dal sensore la temperatura
      float t = dht.readTemperature();
      float h = dht.readHumidity();
      //La converto in un numero intero a 4 cifre
      int a=t*100;
      sevseg.NewNum(a,2);
    }
        sevseg.PrintOutput();
  }

And it works very well!
But I cant see temperature (first) AND humidity (after) and again temperature (first) AND humidity (after)...
I have tried many ways but... nothing!! Can you help me?

You need to maintain a state which tells your program whether you are displaying the temperature or the humidity.  Every time the timer expires you need to change from one state to the other, and then display the relevant value depending on what the state is.
Something like:
bool displaying = false; // false = temperature, true = humidity

void loop() {
    if ((millis()-timer) >= INTERVAL) {
        timer = millis();
        display = !display; // Switch between display values

        if (display) {
            float h = dht.readHumidity();
            sevseg.NewNum(h * 100, 2);
        } else {
            float t = dht.readTemperature();
            sevseg.NewNum(t * 100, 2);
        }
    }
    sevseg.PrintOutput();
}

A very interesting way! After work , about at 8 PM :-) i try your suggest!

All you are implementing is a very very simple Finite State Machine (one with just two states). You might find this interesting reading: http://hacking.majenko.co.uk/finite-state-machine

Hi! thx for your suggestion! I try it five minutes ago and it's work. A nice and simple way to solve the problem, but if I want use this way for 3 value, ie temperature in celsius degree, humidity and temperature in kelvin degree, can I use the "booelan" way or i must use the "switch-case" costruct (like in the article)?

The boolean can only store two states - true or false - and so it can only be used to select between two items. For more you need to change the boolean into a different type that can store more values and then select between them. Say an "int" and use the values 0, 1 and 2. So yes, like the article.

@MicheleBorsaro If this answer solved your problem you should accept it. That is expected behavior on this site. (Accept the first/best answer that solves your problem. Once you have the reputation, you should also think about up-voting helpful answers, although that is optional.)


text:
DHT11 not giving correct value if I attaching a servo motor
So I am using a servo motor and 2 DHT11s in my Uno, when I attach them separately it works well. But when I try to attach both, servo working correctly but DHT11 giving weird number(DHT11 was side by side, one gives 22oC and another gives 30oC sometimes -999).
I am powering both devices by using 5V and GND from arduino to a breadboard and then DHT11 and Servo power pin to the breadboard. All signal pin are direct from devices to arduino.
Am I power both devices wrong? or is there's a way to solve this?
Thanks
EDIT:
this is the code
#include <Servo.h>
#include <dht.h>

dht DHT;

#define DHT11_PIN 7
#define DHT11_PIN2 6
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  int chk2 = DHT.read11(DHT11_PIN2);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

For the servo, I used GWServo S03N STD.

Maybe the moving servo drains too much the power, so the DHT are underfed. Try powering the servo separately, or at least add a capacitor on the 5V on the breadboard (maybe 100nF in parallel to a 100+ uF)

It could be a code error, but my crystal ball isn't working today and I can't see your code.  It could be a circuit issue, but as you know my crystal ball is down so I don't know.  It could be a power problem, but the force is not with me and I don't know what servo model you have so I don't know.  The more complete the information you supply is, the faster and more accurate the answers will be.

@frarugi87 ah yeah, I will try that,thanks for the suggestions

@CodeGorilla sorry, I added the code and servo model.

@NaufalB - sorry to be a pain, but what DHT library are you using, it doesn't look like the AdaFruit one.  Is it this one http://playground.arduino.cc/Main/DHT11Lib ?

@CodeGorilla no problem, I use the one from this site http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

Your code looks like there is no bug in there.  You might want to look at using a library that lets you assign a pin in the constructor, so you don't need to read from a specific pin.  There might be something internal going on that you don't know (or want to know) about.  As for the movement of the servos do you realise you a rotating 181 degrees int p = 0; p <= 180 is 181 degrees, drop the = if you wanted 180.  Also pos++ is the same as pos += 1 but requires less of those tiring key presses :)
You say that the DHT11s work on their own.  The servo works on its own.  So it not a hardware fault.  I assume its not a wiring fault, but please double check.  That means it has to be something to do with the power.  If you are powering the servo from a digital pin then this is unlikely to work, try powering it from the 5V output pin on the other side of the board.
However if you are powering it from the 5V output pin and it doesn't work then you need to power it from a external source, a mobile phone charger will do (if you have one you can chop the plug off).  The problem with using external PSU is you must tie the grounds together.  Doing this means the Arduino and the external device agree what zero volts is and things work.  This is easily done by taking the gnd of the PSU and putting it in the GND connector of the Arduino and the taking the GND for the servo from the other GND on the Arduino.
I hope that all makes sense, if not tell me what you need clarifying.

Yeah, I will try to power it from external source. Thank you for the suggestion, really help me :)


text:
Arduino Uno-Spider Robot Plan
I have been doing a lot of researching ever since Christmas when I got the Arduino Uno. Anyways, I want to build a 4 leg spider robot using 2 Arduino's. I had a lot of problems on coming up with how to do it, and I think I got it. What I want to be answered is this question, is my circuit good to go and will not fry anything? Anyways, I needed 12 servos. Only 6 pins on 1 Arduino has PWM. So I thought to use 2 Arduino's to communicate through the HC-06 blue-tooth. Power was another problem. I discovered that double AA batteries have an impressive 7 amps on my multi-meter. However, to much for the Arduino. That is why it is only supplying servos and not going directly to the Arduino. A 9v will do that. Anyways, I can't give you guys the schematic as it is to big of a file. However, I will explain the circuit in words. One Arduino is master and the other is slave. These steps go to both master and slave unless stated.

6 servos on master and 6 on slave. Power is going to 4 double AA batteries in series. This supply is not connected to the board except the ground wire. This is a battery holder with switch already on it. All PWM pin's are in use for servos.
9 volt battery going to the Vin pin. I will incorporate a switch.
Fan with positive and negative only. Positive goes to the 9 volt battery. Ground goes to ground pin on Arduino.
Bluetooth module with VCC going to 3.3v pin. Ground to ground pin. TXD going to the RX pin. RXD going to TX pin.
For master Uno only. Distance sensor with Trig going to A5 pin and echo to A4 pin. Ground going to ground pin. VCC going to 5v pin.
2 led's in circuit with 220 ohm resistor. I will use pin 4 and 2. Ground goes to ground pin.

That is the setup. I am in college where soldering is banned. So I am including a fan, like you saw, to cool down the breadboard. Let me know if you think that will work. I could not find a good schematic online for this robot, so I made one. Please let me know if you have any questions. Anyways, please tell me if there are any flaws and thank you so much for your time and effort.
Edit 1:
@gilhad
I did not know about I2C, if that is easier than blue-tooth, then I will get that. Thanks for that input. This way I don't have to use 2 blue-tooth modules. Most of the robot is running in series, not parrel.
Also, I said 4 AA batteries and not 2. If I had 2 in series, then that is 3v only, so that is why I am going for 4 in series for a total of 6v, with amps being the same as with one battery. This will supply 7 Amps. I tested it with my multi-meter. The servo motors are going to need 1 amp of power at max. I have 7. I will probably be using 4 servos at one time. So that is 4 amps. It will run for about an hour. That is fine by me.  This 4 AA battery is not connected to the arduino. There are 2 power sources per arduino. The other one is a single 9v battery, that one is going directly to the arduino, the Vin pin to be clear. If it is going to reset, could I do something in the programming to account for that like a time delay that is short?
I do not want to mess with my breadboards, that is why I am using a fan to cool them. Will that work?
The power source will not be moving all the servos at once, sorry that I did not include that.
Edit 2:
@killer rabbit
I guess I did not want to get a mega because I have 3 Uno's already, but I see they're pretty cheap online. I will ponder this idea of yours. I looked at my schematic and determine this would eliminate the 2 blue-tooth modules, 1 power source, 1 fan, and 2 leds along with their resistor. I think it would also eliminate an extra switch. Programming would be easier to because I don't have to worry about blue-tooth communication. I had no idea what to do for that one. So maybe I will get a Arduino mega.
The reason I am not using RC battery is because they're kinda heavy and SG90 servos are kinda small. I was worried about torque.  Li-ion is not to heavy, but I was worried about power. The ones you gave me though, look like that might work. There is 2 problems though. First, I can't use 2 of these batteries in series because that is 7.4 volts when the servos I am using is at max 7.2 volts. I would have to reduce voltage somehow, I have no idea how to wire that into the circuit. Problem 2 is that if I wire is parrel, that is 6 amps, which is fine, but only 3.7 volts. The motors can run on that, but that is on the low end. Will torque be less?
About the third paragraph, there is limits on the amount of current an Arduino can take. I looked them up. It is about 2 amps for the Vin pin I think or that might be the DC jack, one of the two.
I am using 2 Arduino, so that is why the blue-tooth was necessary. However, if I go with the mega, it will eliminate both of them. I forgot to mention for the distance sensor, I am using ultra sonic one. That is my fault for not mentioning that.
The reason I need 12 servos is because I am using 4 servos at the base, one for each leg to control direction of leg for steering. Then I have 4 legs, each using 2 servo motors to make the leg kick out and in. So 4 + 2(4)=12.
Yes, I would be using, if 2 Arduino, wireless communications, that is why the blue-tooth module. About the schematics, the picture is too big, so that is why I can't upload it. So sorry about that. I did try, believe me.

There are multiple points where you should reconsider your plans:
First of all, do not use multiple Arduino Unos, it's just a pain in the arse to make them work synchronously, instead use (for example) a single Arduino Mega 2560 which has 14 PWM outputs and still cheap as dirt.
I'm not sure about the life length of the AA batteries, I might consider using Li-Po (something from an RC shop, or something) or Li-ion (18650 is very popular and cheap) batteries. The Arduinos can take basically anything from 9 to 6 volts (and 5 from the USB), so you have a bit of freedom there.
A bit of electrical stuff: High available current is not a problem for the Arduino, it takes as much as it needs, so as long as you are in the voltage range of the board, you won't have any problems. Less amperage however is a problem, so be sure your battery can provide enough current!
You probably won't need cooling, there are no devices in your spider that would require more than a heatsink, if at all. But soldering is very recommended, I urge you to reconsider about that.
The Bluetooth module becomes unnecessary by going with a single Arduino.
For distance sensor I recommend an ultrasound one, those are really (ridiculously) cheap and simple to use. (HC-SR04 is very popular for example and there are tons of tutorials for it)
LED's are okay, most people don't think about the resistors, but those are important!
A question: Why do you need 12 servos?
That's all I got in the first round, feel free to share more info and I'll try to help you with your planing. I highly recommend you to share the schematics with us so we can help you to improve it!
Edit: I almost forgot: do you intend to use some kind of connection to the spider, like Bluetooth or Wi-Fi?

As far as batteries go, I'd recommend at least 6 volts, so you can use the Arduino's barrel connector. You may use 2 serial Li-ion batteries and a buck converter, but I believe you'll do fine without it, your servos will handle the extra 0.2 volts.
About the current limits: Your Arduino can supply around maximum 500 mA from all it's pins, and 40mA from a single pin, BUT it won't be a problem, because you do not connect the servos' VCC (+) and GND (-) pins to the Arduino, instead you hook them up to the battery directly. You only connect the SIGNAL pins to your Arduino which draw less then 10 mA.
For the communication with the spider I'd recommend a Wi-Fi module and UDP, as the protocol for the communication.
G.

I commented to your answer at edit number 2.

Got it, I'll edit my answer accordingly.

I can't tell if you edited or not? If you edited, can you just add some like edit 1, so I know? Thanks.

I finished it now, you'll see a line in my answer.

I saw the edit. Let us assume I am going to use the Arduino mega for now. I ordered one as it was only $13 with free shipping. If I put the Li-ion batteries in series, it will have 3 amps, I might need 4 amps at a time though. This concerns me. What can I do about that part? I won't need communication anymore because of the using Mega. Power is still a concern. In series, 3 amp is low, minimum of about 4 amp at a time will be used. In parrel, will 3.7 Volt decrease torque because it is on the low end for voltage supplied to the servo? I think I am close to a finish design now.

By the way, these are the batteries if I use Li-ion.                                                                                https://www.amazon.com/gp/product/B0129F9BXK/ref=ox_sc_sfl_title_1?ie=UTF8&psc=1&smid=A3P4UZIS42PRQV

I got an idea, since I don't want to lose torque or speed. I will get the 4 li-ion batteries. I will wire 2 in parrel and then add 1 more battery but put that battery is series with the 2 in parrel. That will give me 6 amps at 7.4 Volts. You said the extra .2 won't be bad. They are the same, so won't be mixing anything. What do you think?

3 batteries NOT OK! 4 batteries, 2 in paralel, then 2 in serial is OK http://lh6.ggpht.com/_hYIZmJ5Igu4/StP-AYEZBqI/AAAAAAAAAVY/YGNFsNjOG9U/2s2p-2p2s.jpg

Well power is still an issue then. So if 2 in paralel, that is 6 amps, then 2 in series for 7.4 volts. Then do I connect these 2 packs in paralel? Cause in series, it is to much voltage. But in parrel, it would be overkill amps, but it draws from it, so no such thing as to much amps in this circuit. So is this set up correct?

Also, what about the breadboard? I know you said it won't be a problem, but it takes max of 1 amp when we are dealing with a lot more. I can't solder cause it is banned. So will adding a fan to cool just the breadboard work?

I believe you will do fine with the 7,4 volt 2 paralel 2 series pack.

The breadboard won't be a problem, because transferring current does not generate much heat. Your servos and battery might become a bit warm, but I don't expect high temperatures.

Ok, thank you. I think I know what to do now.

For connecting 2 Arduinos use some wires - I2C works good for me, but Serial is also good. Anyway you probabely will came to problem with interrupts and many tasks running in paralel, or the spider be slow - you choose not so easy target (but reacheble).
As for bateries - Arduino need constant power, than it takes as much current as it needs (if it is aviable), so no problem in 2 AA for Arduino.
You would need a lot of servos - they are, what takes energy - even if 2AA can give a lot for short time, this will not last long. Also giving high current means voltage drops (as for cable and mainly internal batery resistence), so if you feed arduino from the same source, it can reset every time, when too much servos try to move/stang agains gravity.
Different source for Arduino is good idea, as the CPU will last longer, then those actuators and could shutdown properly (not let move just one leg or so). Also the electrical interference from servos would be much less this way. (There are other ways, more complicated to do that).
Breadbourd can be stripped the bottom plastic and have it exchange for more thinner double-size tape, then be put on large alluminium (or other heat-conducting) plate for better cooling too.
Arduino cannot move all those servos from its source, think about alimitation currrent per pin and per arduino itself - you may need some other IC/transistors to power it properly on each servo and the servo power should go direct from bateries, not via Arduino. Connect just grounds.

I commented at your answer at edit number 1.


text:
Arduino Uno: Sensor shield powering multiple servos
I posted this on the electrical side of stack exchange and they said it was off topic, so I think it will be on topic here and they confused me even more. So if you guys could clear up my confusion, that would help.I know there are sources for this, but I am still lost.  Anyways, here is the run down. I want to control multiple servos (12 of them) using a sensor shield. I need to know what kind of power supply I need. Here is the servo's I am using:
https://www.amazon.com/gp/product/B01NA80LUR/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1
Here is the sensor shield I am using:
https://www.amazon.com/gp/product/B01ACKVPTW/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1
The servos run at 3-7.2V and 750ma-1000ma full load or another person said they ran only 100-150ma. Also, another question is do I plug that power supply, when I get the right one according to what you say, into the dc jack or the external power on the sensor shield board?
Thank you for your time.

Arduino.cc forum topic 229646,  “Arduino Sensor Shield v5 (APC220) manual”, is a thread about lack of documentation for that shield.  However, post #10 in that thread states that pulling off the SEL jumper allows you to use an external power supply to power the devices you attach to the shield.  Also see Sensor Shield (Version 5X) Separate 5V for Servos at yourduino.com.
The Robotics Stackexchange question Wiring & driving TowerPro SG90 servos agrees with the 750–1000 mA current draw of SG90 servos.  You could go with a 5 or 6 V power supply, with say 12 A rating if you expect to drive 12 servos at the same time.  However, as a 12 A supply might be expensive, you probably should attach two or three servos to the shield and measure the current draw.   If, for example, your application rarely draws over half an amp per servo, you might scale back to a 10 A or 8 A supply.
Note that an Arduino Uno or Nano (in general, any based on ATmega328-like MCUs) has six pins that support hardware PWM, so you may need to use a Mega instead, or two Uno or Nano  Arduinos.  (Software-generated PWM signals are another possibility but I doubt it would work well enough if your app is at all complicated.)

Edit 1:  If the system is battery operated, you probably should use a 2S LiPo RC battery, that is, a battery with the voltage of two lithium polymer cells in series (so, 7.4 volts) and whatever number of cells you wish to pay for in parallel, as often used in radio controlled devices.
Some LiPo batteries support 25C discharge rates, ie, can discharge at 25 times their one-hour-discharge rating.  Thus, a 500 mAh battery might work fine – since 25 times .5 A is 12.5 A – if you only need to run your system for up to 2.4 minutes between battery charges.  Or, for example, a $13.49 Turnigy 1000mAh 2S 20C Lipo Pack HobbyKing RC Battery would work ok, even though only rated for 20C.  It could power a 12 A draw for 1/12 hour, or 5 minutes.

For the SEL jumper, look in the lower left corner of one of the pictures from your amazon.com link, as below.  With the jumper (the short-metal-strap-and-black-plastic-shell assembly, next to the letters SEL) removed, connect battery+ and battery- to the screw-down terminals at bottom left in the photo.  Battery+ goes to Vcc, battery- to Gnd.

Regarding a second Arduino, you could split the processing across two of them so that each one only needs to know the current time; or could communicate between them by an SPI, I2C, or RS232 interface; or could move up to a Mega2560 Arduino, which has a lot more PWM channels.
Edit 2:  If battery weight is an issue, you may be able to use lower-capacity (hence lighter-weight) batteries if your software only moves a few of the servos at the same time.  For example, if you move three or four at a time, and if most of the servos are idle most of the time, you might be able to use a light-weight cellphone battery.
Addicore.com has some useful current measurements for the SG90:
Voltage                        4.0V to 7.2V, 4.6V - 5.2V nominal
Running current with 5V supply (no mechanical load)    220 ±50mA
Stall current with 5V supply (horn locked)             650 ±80mA
Idle current with 5V supply                              6 ±10mA
Weight                                                0.32oz (9g)

However, you probably need to make current measurements on your own to see how big the battery needs to be.

Ok, that is kinda what I thought as regards to the power supply. Problem is I can't find a battery with 6v and 12 amps that is not a car battery size...so if you guys can tell me what I can do about that would be appreciated. Secondly, my project is a spider robot, so I kinda need it to be one arduino unless the both communicate somehow? Third, I can't find a "SEL jumper" so could you explain that?

I did mention that I am building a spider robot with these servos that are kinda small, that battery is heavy as I personally do RC cars myself so I know they are too heavy for this project. There must be another way. How do people build a spider robot? Like seriously, this is  hard for getting a power supply that is correct and not to heavy. About the other things, I will change to the mega and for the sel, I have to pull the jumper or what am I suppose to do with that? I can see like a "pin" kinda that might be able to be pulled out? Again, thanks for all the help. I know I'm a noob at this.

@Sean.D, see edit 2 and slight change to Edit 1.  Note, please upvote answer or mark as accepted

I might be able to get it to only run 6 at a time, but have no idea until i build it. I really think it will use at least 6. I will do some measuring on my own and see. I will continue looking for a battery that is suitable. Thanks for your help.

I upvoted but says i need like 15 rep or something, I then hit the check mark and it turned green.

@Sean.D, thanks!  I forgot to mention there are some really small boards (not shields) available with chips on them that develop the PWM there, like  “PCA9685 16 Channel 12-bit PWM Servo Motor Driver I2C Module Robot WC For Arduino”  and  “16-Channel 12-bit PWM/Servo Drive shield module I2C PCA9685 For Arduino NEW D” on ebay.    These can be used ok AFAIK with Uno and Nano.  Nano is ~ 1/3 as big as Uno and draws a little less current

Thanks, I just need a battery that is no to heavy, but I will keep that in mind.

two things make servos fairly easy to control:

they take a slow pwm input; generating pwm is fairly easy on a mcu;
they are generally not that sensitive to the duration of the off state: I have tried from 5ms to 40ms (the longest) and they are fine with that.

so if you combine the two attributes together, it is easy to control multiple servos with from one timer interrupts.
I wrote a few pages on this recently:
1. driving multiple servos on AVR Timer2: https://dannyelectronics.wordpress.com/2017/02/08/driving-multiple-servos-with-avr-timer2/

driving multiple servos on PIC: using TIMER0 (https://dannyelectronics.wordpress.com/2017/02/08/driving-multiple-servos-with-pic-timer0/) or TIMER1 (https://dannyelectronics.wordpress.com/2017/02/07/driving-multiple-servos-with-pic-timer1/).

The following is a combination of the two: driving 8 servos independently on PORTB with TIMER1 and another 8 servos independently on PORTD with TIMER2.

the user code is quite simple:
//set up servo controller 1
srvo1_init();                           //reset the servo module
srvo1_setpr(1, 1000);                   //for 1ms
srvo1_setpr(2, 1200);                   //for 1.2ms
srvo1_setpr(3, 1400);                   //for 1.4ms
srvo1_setpr(4, 1500);                   //for 1.5ms
srvo1_setpr(5, 1800);                   //for 1.8ms
srvo1_setpr(6, 2000);                   //for 2ms
srvo1_setpr(7, 2500);                   //for 2.5ms
srvo1_setpr(8, 4000);                   //for 4ms

//set up servo controller 2
srvo2_init();                           //reset the servo module
srvo2_setpr(1, 1000);                   //for 1ms
srvo2_setpr(2, 1100);                   //for 1.1ms
srvo2_setpr(3, 1200);                   //for 1.2ms
srvo2_setpr(4, 1300);                   //for 1.3ms
srvo2_setpr(5, 1400);                   //for 1.4ms
srvo2_setpr(6, 1500);                   //for 1.5ms
srvo2_setpr(7, 2000);                   //for 2ms
srvo2_setpr(8, 4000);                   //for 4ms

Once it is set-up, you can just leave it alone and no addition attention is required. You can change the duration of course, or disable / re-enable output on a given channel.
Total CPU drain is about 150K ticks in a second for 16 channel controller.
works on Arduino as well.
edit: if you port the code to TIMER0 (easily done),  you can control 32 servos independently.
and if you combine this code with making timers out of the output compare functionality, you can shrink them all on one timer.


text:
concurrent display of BMP file and text on Arduino TFT LCD screen
I am using an Arduino TFT LCD screen (1.7'') on Arduino Due for displaying .bmp file of 80X60 pixels. Is it possible to display a .bmp image on the lcd screen and also display text/draw an object such as a rectangle, simultaneously in the extra free space available on the screen?
The code I'm using is from the examples section in arduino IDE. File->Examples->TFT->Arduino->TFTBitmapLogo

Yes, after drawing the BMP, draw pixelwise over the TFTs framebuffer (without deleting any other pixels) or compute the whole framebuffer locally and transfer it one go. What library and display exactly are you using?

Thank you for your quick response. I'm using the TFT LCD display 160X128 size by Arduino and TFT.h library. The .bmp file has to be retreived from the SD card. Could you please help me with an example of computing the framebuffer for text/object display?

I looked at the library and it already does direct writes to the TFT's framebuffer over SPI. So you should be able to just call TFTScreen.text() and draw over your bitmap after you called the TFTScreen.image(). function. Can you edit your question to include the current code you're running?


text:
OVF in serial monitor instead of data
I am currently working with two Arduinos and I'm trying to synchronize them. I want to get data from four LIS3DH accelerometers. The LIS3DH accelerometers are connected to the Arduino using I2C interface. I have managed to get the Arduinos to synchronize using SPI but when I get the third set of data it keeps on showing OVF rather than the values. My code is below can someone please help me out?
Thanks
// SPI Master
#include <Wire.h>
#include <SPI.h>
#include "SPI_anything.h"
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

//#define LIS3DH_CLK 13
//#define LIS3DH_MISO 12
//#define LIS3DH_MOSI 11
//#define LIS3DH_CS  10

// I2C
Adafruit_LIS3DH lisch1 = Adafruit_LIS3DH();
Adafruit_LIS3DH lisch2 = Adafruit_LIS3DH();
// Adafruit_LIS3DH lisch3 = Adafruit_LIS3DH();
struct event3;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using
// programming port to program the Zero!
#define Serial SerialUSB
#endif

void setup() {
#ifndef ESP8266
  while (!Serial)
    ; // will pause Zero, Leonardo, etc until serial console opens
#endif

  Serial.begin(9600);

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);

  // turn on SPI in slave mode
  SPCR |= _BV(SPE);

  Serial.println("LIS3DH test!");

  if (!lisch1.begin(0x19)) { // change this to 0x19 for alternative i2c address
                             // - Voltage SDO

    Serial.println("Couldnt start");
    while (1)
      ;
  }
  Serial.println("LIS3DH1 found!");
  if (!lisch2.begin(0x18)) { // change this to 0x18 for alternative i2c address
                             // - Ground SDO
    Serial.println("Couldnt start");
    while (1)
      ;
  }
  Serial.println("LIS3DH2 found!");

  lisch1.setRange(LIS3DH_RANGE_16_G); // 2, 4, 8 or 16 G!
  lisch2.setRange(LIS3DH_RANGE_16_G); // 2, 4, 8 or 16 G!

  Serial.print("Range = ");
  Serial.print(2 << lisch1.getRange());
  Serial.print("Range = ");
  Serial.print(2 << lisch2.getRange());
  Serial.println("G");
}

void loop() {

  lisch1.read(); // get X Y and Z data at once

  /* Or....get a new sensor event, normalized */
  sensors_event_t event;

  lisch1.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print(" \t ");
  Serial.print(event.acceleration.x);
  Serial.print(" \t ");
  Serial.print(event.acceleration.y);
  Serial.print(" \t ");
  Serial.print(event.acceleration.z);

  lisch2.read(); // get X Y and Z data at once
  lisch2.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print(" \t ");
  Serial.print(event.acceleration.x);
  Serial.print(" \t ");
  Serial.print(event.acceleration.y);
  Serial.print(" \t ");
  Serial.print(event.acceleration.z);

  struct event;

  SPI_readAnything(event);
  //  sensors_event_t event;

  //  lisch3.getEvent(&event);
  Serial.print(" \t "); Serial.print(float2s(event.acceleration.x,6);
  Serial.print(" \t "); Serial.print(event.acceleration.y);
  Serial.print(" \t "); Serial.print(event.acceleration.z);
  Serial.println ();

  delay(500);
}

/ SPI Slave

#include <Wire.h>
#include <SPI.h>
#include "SPI_anything.h"
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
#define LIS3DH_CS 10

    // I2C
    Adafruit_LIS3DH lisch3 = Adafruit_LIS3DH();

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using
// programming port to program the Zero!
#define Serial SerialUSB
#endif

void setup() {
#ifndef ESP8266
  while (!Serial)
    ; // will pause Zero, Leonardo, etc until serial console opens
#endif

  Serial.begin(9600); // start serial for output

  SPI.begin();

  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);

  Serial.println("LIS3DH3 test!");

  if (!lisch3.begin(0x19)) { // change this to 0x19 for alternative i2c address
                             // - Voltage SDO

    Serial.println("Couldnt start");
    while (1)
      ;
  }
  Serial.println("LIS3DH3 found!");

  lisch3.setRange(LIS3DH_RANGE_16_G); // 2, 4, 8 or 16 G!

  Serial.print("Range = ");
  Serial.print(2 << lisch3.getRange());

  Serial.println("G");
}

void loop() {

  lisch3.read(); // get X Y and Z data at once

  /* Or....get a new sensor event, normalized */
  sensors_event_t event;

  lisch3.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print(" \t ");
  Serial.print(event.acceleration.x);
  Serial.print(" \t ");
  Serial.print(event.acceleration.y);
  Serial.print(" \t ");
  Serial.print(event.acceleration.z);
  Serial.println();

  digitalWrite(SS, LOW); // SS is pin 10
  SPI_writeAnything(event);
  digitalWrite(SS, HIGH);
  //  delay (1000);  // for testing

  delay(100);
}

OVF means overflow, you probably exceeded the range of the data type you're using. Try /1000; /10000000000 etc to your variable until you don't get the OVF or use a datatype with a bigger range.


text:
Unable to connect Arduino Uno to Ubuntu 16.04
I've received an Arduino Uno today only. I have zero experience prior to Arduino boards or any other micro controller. I followed every step very carefully from the setting up guide for Linux based OS, but I still can't connect the board with my Ubuntu 16.04 PC. After googling the problem I found that the device must show up as ttyACM* but I don't see any such device in /dev. Its also not listed under the command lsusb but the LED's on the board are working properly. The ON LED is turned on when I connect it with my PC and the inbuilt LED starts to blink.
This is what the IDE displays:

Have you tried a different cable?

yes I have two cables

@Majenko can you help me please

In a terminal, run dmesg -w. Then plug in the Arduino. Post the additional lines that should appear into your question.

Some things that may help you: https://hackingmajenkoblog.wordpress.com/2016/08/24/diagnosing-arduino-problems-in-linux/

@Majenko I tried dmesg -w but no new lines show up when i connect the board

Is it a genuine Arduino or a Chinese clone?

@Majenko its a clone

Ah well, there you go then. Maybe it's just dead. Maybe you were sold a lemon.

@Majenko but it can't be dead the LEDs are working just fine

There are two parts: the main MCU, which is working, and the USB interface which, on clones, often dies. Does it have a square or a rectangular chip next to the USB socket?

@Majenko A rectangular one

CH340G - notoriously bad.

Did you select the port in the Tools menu? Check that it shows up there and is selected.

You may have to add yourself to the dialout group in Ubuntu so that your user account can access the serial ports.
Then, in the Arduino IDE, the Tools->Port menu should show you options. Right now, the screenshot you gave shows that it's set for COM1, which is a Windows-style serial port naming and definitely won't work on Ubuntu.

I've already done that and the Port menu is grayed out.

Did you log out and log back in after adding yourself to the dialout group?

yes I did.
I even tried rebooting but nothing works


text:
Can I reduce UIPEthernet library size (perhaps by ditching TCP)?
I am using the excellent UIPEthernet library to get an Arduino Nano to drive an ENC28J60 Ethernet Shield for a UDP-based application. But I think the poor library has to do a lot of work to make up for the limitations of the ENC28J60, and that makes the library large compared to the W5x00 family devices.
My sketch is starting to run out of the 32K (actually 30720 bytes) program space; I'm at 26K and I've still got functionality to add. Right now, the application is using DHCP to get the IP address, it picks up UDP discovery broadcasts from a controller PC on the LAN and then asynchronously chats to it (and only it) with UDP msgs. My uip-conf.h, condensed, looks like:
#define UIP_CONF_MAX_CONNECTIONS   0
#define UIP_CONF_MAX_LISTENPORTS   0
#define UIP_CONF_BUFFER_SIZE      98
#define UIP_CONF_TCP_MSS          64
#define UIP_CONF_RECEIVE_WINDOW  256
#define UIP_CONF_LOGGING           0
#define UIP_CONF_UDP               1
#define UIP_CONF_UDP_CONNS         2
#define UIP_CONF_UDP_CHECKSUMS     1
#define UIP_CONF_BROADCAST         1
#define UIP_CONF_STATISTICS        0

So I'm looking at ways to shave some KBs. There is much made of the fact that you can disable the library's UDP subsystem to save ~5KB (which is sort of how much I'm looking for, maybe less, though more is always nice!). And I was rather hoping I could disable TCP, but I can't see an easy way.
Are there any configurations or tricks I can play with UIPEthernet to save code space, given I'm not using TCP?
(I do have other options: switch to a W5x00 board, get a CPU with bigger memory, etc - but I want to explore this option before I revise the hardware spec).

you could use the EtherCard library

@Juraj I was wondering that - but it's quite a lot of rewriting and testing. Also, the EtherCard docs say it has no ARP cache, so it can't talk to LAN non-gateway hosts; this app is all about doing that!

now I can recommend my EthernetENC library which has a setting to disable TCP


text:
Arduino Control TV over RS232
I have a LG TV(LG 32SL800 ZB), which has a RS232-Port for Control and Service.
And I am wondering if I could control this port with my Arduino (NODE-MCU) and a module like this one RS232 Board?
How could I then control the TV? This is the Manual for the TV at page 124 there are the commands how to control it, but how can I send them?
My last question is, how long can the cables from the arduino to the module be? They have to be about 2-3m long! Is that possible without any other hardware?

And I am wondering if I could control this port with my Arduino (NODE-MCU) and a module like this one?

Yes, you can, though choose a board based around the MAX3232 for a 3.3V MCU board.

How could I then control the TV? This is the Manuel for the TV at page 124 there are the commands how to control it, but how can I send them?

Exactly as they show in the manual. For example:
Serial.print("ka 0 01\r");

That would turn on every TV connected to the serial bus.

My last question is, how long can the cables from the arduino to the module be? They have to be about 2-3m long! Is that possible without any other hardware?

You can get away with no more than maybe 1 meter between the Arduino and the RS232 board. Keep that as short as possible. However between the RS232 board and the TV you can have up to 15 meters of cable.

I now have tried the commands! The "ka 01 00\r" which should turn on the TV works perfectly but any other command doesn't work?


text:
ESP8266: Is it safe to use pin 0?
This (maybe stupid) question is bothering me for a long time...
If the pin 0 has to be connected to the ground for uploading a sketch into ESP8266, and after the uploading the chip automatically starts the uploaded sketch (without waiting for reboot with pin 0 to be disconnected), then won't it destroy the chip if I do digitalWrite(0, HIGH) in my sketch? Correct me if I'm wrong, but it should short 3.3V directly to the ground through this pin... Is this problem secured somehow? Or maybe this pin can be safely used for reading only?
Edit:
I have seen it connected to ground directly on every schematic about ESP8266, but maybe I should just use a pull-down resistor? Or maybe the chip already has a resistor before this pin to solve this problem?

You can absolutely use GPIO0 as an output. The ESP will read the state of GPIO0 once at boot (And never again thereafter) to determine what boot mode to enter. During this time it is an input, so, whatever you hook GPIO0 up to must not hold this pin low (Unless you want to enter bootloader mode, of course), at least until the chip boots. As long as you satisfy this condition, you can use the pin for anything else. On my board for example, I use it to drive a simple status LED, and have never seen any issue from it.

What do you consider pin 0?
As I look at the schematics it could either be GND, VCC, RX or TX pin. Or do you mean GPIO0?
GPIO0 when connected to GND and in combination with RST to GND will put ESP into programing mode.
Good practice is to have separate programing board, something like This here. Go down to "Writing a program to the ESP8266" section and check out the schematic. Voltage regulator can be omitted if you are already powering it with 3.3v.

When I write digitalWrite(0, HIGH)  I mean GPIO0. I know how to flash ESP8266 and I'm using a circuit in which I just press Upload and it just uploads (no manual reset needed). I've got a switch by which I toggle when the GPIO0 is connected to GND or not (and I switch it off only if I have to restart the program without uploading the new version). I'm just wandering if I could use this pin as an output pin because I'm out of pins. And I'm using ESP-12 with its standard breakout board that you can just plug into a breadboard.

It may be stated that GPIO0 is safe to use as an output, but I challenge anyone to show he has actually done it. When configuring GPIO0 as an output I get only oscillations (about 70kHz), loaded or open, when driving this pin LOW.
Even GPIO15 works without issues when used as an output.
Several new ESP8266-12F modules were tested.


text:
Synchronous communication between two Arduino boards using two ESP8266 modules
I am trying to establish communication between two Arduino boards to send data from sensors through a WIFI module. The problem is that I need them to connect to each other whenever they are in range of each other and send the sensor data.

The esp8266 WiFiMulti system allows to configure more access points and with the rigth code in loop it always searches the best AP.
Configure one of the esp8266 as AP and setup the other with WiFi Multi only for this one  access point.
You can then use events like onStationModeConnected to handle data exchange if the connection is established.


text:
Sketch works on MEGA 2560 timer2, but does not work on timer1
I set the PWM frequency on MEGA 2560 like this:
  TCCR2A = 0;
  TCCR2B = 0;
  TCNT2  = 0;

  TCCR2A = _BV(COM2A1)
           | _BV(COM2B1)
           | _BV(WGM20);
     TCCR2B = (TCCR2B & 0b11111000) | 0x02;

it works good, now I want to use timer1 on PWM and I changed the code like follow but no work:

TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;

  TCCR1A = _BV(COM1A1)
           | _BV(COM1B1)
           | _BV(WGM10);

  TCCR1B = (TCCR1B & 0b11111000) | 0x02;

What's wrong with the changes?
I added 'TOP = ICR1', and when I tested, the ICR1's value effected both the PWM's frequency and duty cycle, how to avoid ICR1 effect dutu cycle?

what is your question? ..... what does this mean? but no work ................ are the two timers interchangeable?

I don't know much, I just mechanically changed 2 as 1 relatively.

Thank you jsotola. I'm using a pair RC remote control module to test some thing, when I set Timer2 on MEGA 2560 , the communication is OK. It is no communication when I modified the timer set from timer2 to timer1.


text:
Passing variable value in structure object
in this code i want to pass value of variable char array 'pass' in object "MyObject". But i am getting this error.
    Arduino: 1.6.11 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\XXX\Desktop\EEPROM_put\EEPROM_put.ino: In function 'void setup()':

EEPROM_put:17: error: array must be initialized with a brace-enclosed initializer

};

^

exit status 1
array must be initialized with a brace-enclosed initializer

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

when i change pass to *pass, result of EEPROM.get() is 1 and 6, instead of 1, 62345, 7539514682.
#include <EEPROM.h>
struct MyObject {
boolean stat;
char password[6];
char mobile[11];
};

char pass[6]="62345";
void setup() {
Serial.begin(9600);
while (!Serial);
MyObject customVar = {
  1,
  pass,
  "7539514682"
 };
EEPROM.put(1, customVar);
Serial.print("Written custom data type!");
}

void loop() {

}

Use class and constructor
#include <EEPROM.h>
class MyObject {
    boolean stat;
    char password[6];
    char mobile[11];
  public:
    MyObject(bool tempStat, char tempPassword[], char tempMobile[])
    {
      stat = tempStat;
      strcpy(password, tempPassword);//As suggested by mikael
      strcpy(mobile, tempMobile);
    }
};

char pass[6] = "62345";
void setup() {
  Serial.begin(9600);
  while (!Serial);
  MyObject customVar(true, pass, "7539514682");
  EEPROM.put(1, customVar);
  Serial.print("Written custom data type!");
}

getting output like this:
Read custom object from EEPROM:
1
62345 7539514682T
7539514682T

What is the expected Output

Should copy with the sizeof(password) and not break on zero? strcpy() might be easier.

Sorry forgot NULL terminating character. Made changes

@Sniper still not getting correct output, now getting some random characters, output is :
1
62ÿ! 75
75
Expected output is 1, 62345, 7539514682

Did strcpy worked?

While the method from Sniper's answer works, it involves copying the
data, which is something you often want to avoid on an Arduino. The
simplest fix to your problem is probably to initialize your password
field with a literal string, just like you did with the mobile field:
MyObject customVar = {
    1,
    "62345",
    "7539514682"
};

or maybe, if you want the password to be written near the top of the
program,
#define PASS "62345"

MyObject customVar = {
    1,
    PASS,
    "7539514682"
};

Another option is to not store the strings in the object. Instead, store
them elsewhere and have the object only hold pointers to them:
struct MyObject {
    boolean stat;
    const char *password;
    const char *mobile;
};

char pass[6] = "62345";

[...]

MyObject customVar = {
    1,
    pass,
    "7539514682"
};

Note that, in this case, the mobile number is stored by the compiler as
an unnamed string constant. Because it is constant, the mobile field
has been typed as const char *. I typed the password field
identically for symmetry, but in this use case it need not be const.


text:
Too many amps for Step motor
I have an adafruit motor shield and attached the Nema 17 stepmotor. Now the big problem is trying to power it without it overheating. I was originally using a 12v 6a power supply but quickly switched to a 12v 2a and then a 12v 1a. All of them still make the Nema stepper motor very hot.
I'm using the accelstepper and adafruit modules on the arduino to control the stepper motor. I noted that the magnets are all always on in my code which might explain why it gets hot but I need to maintain some form of torque for the system I'm developing.
I will attach code as that might be the problem. Is there a second device I need to attach to the adafruit motor sheild and the nema stepper motor.
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

int ComControlValue = -1;

/* Define pins for motor and define step motor function */
const int SlowStepPerRev = 400;                              // Define slow speed constant
const int MotorB = 2;
int rpm = 60;                                                // Rotation per minute
int acelspeed = 40;                                          // Acceleration speed
int distrot = 200;
int destinationunknown = 0;                                  // Destination of plate 1

/* Initialize the stepper library on the motor shield */
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotorB = AFMS.getStepper(SlowStepPerRev, MotorB);

/* you can change these to SINGLE or DOUBLE or INTERLEAVE or MICROSTEP! */
// wrappers for the motor!
void forwardstepB() {
   myMotorB->onestep(FORWARD, INTERLEAVE);
}
void backwardstepB() {
   myMotorB->onestep(BACKWARD, INTERLEAVE);
}

AccelStepper stepperB(forwardstepB, backwardstepB);

void setup() {
   Serial.begin(115200);                                     // Establish Serial connection to computer
   Wire.begin();                                             // join i2c bus as master
   AFMS.begin();                                             // Begin useage of conveyorbelt motor

   stepperB.setMaxSpeed(rpm);                                // Initialize max speed
   stepperB.setAcceleration(acelspeed);                      // Initialize and set speed of acceleration for spinning
}

void loop() {
   switch(ComControlValue){
        case -1: //wait
            Serial.println("Waiting for Command");
            Serial.println(stepperB.currentPosition());
            while (Serial.available()==0){}
            ComControlValue=Serial.parseInt();               // Pull value from serial port
            break;                                           // break loop & return to start
        /* 1 : Move plates into the system */
        case 1:
// Arduino using accelmotor, move to position X
        if (plateNum < platelimit){
               plateNum++;
               ComControlValue= 11;                          // After establishing plate num & location, move to case 11 to start stepmotor movement
               destinationunknown = destinationunknown + 200;
        }
        else {
               ComControlValue = -1;                         // To many plates, cancel move command
        }
        stepperB.moveTo(destinationunknown);
        break;

        /* 2 : Move plate out of system */
        case 2:
        // Arduino using accelmotor, move to position Y
        if (plateNum > 0){
               plateNum = plateNum--;
               ComControlValue= 11;                         // After establishing plate num & location, move to case 11 to start stepmotor movement
               destinationunknown = destinationunknown - 200;
        }
        else {
               ComControlValue = -1;
        }
        stepperB.moveTo(destinationunknown);
        break;

        /* 1 : Run Stepmotor to completion */
        case 11:
        // Step motor requires an uninterrupted while loop to move to completion
        // code setup will utilize while loop and allow for movement
        stepperB.run();                                     // run stepmotor
        if (stepperB.distanceToGo() == 0 ){
                ComControlValue = -1;                       // Completed movement, go back to case -1
        }
        break;
   }
}

Stepper motors get hot. It's a fact of life. More so when they are held stationary.
A typical 12V Nema 17 stepper motor has a coil resistance of 30Ω per phase. With 12V across a single phase it will consume 0.4A.  That is the equivalent of about 4.8W of power. That comes out in the form of heat.
Reducing the current capacity of your power supply will not "fix" the problem. All that will happen is that as you go to lower and lower current supplies the supply will get hotter and eventually break.
You can test the coil resistance of your motors with a DMM set to the Ohms range, then calculate the power dissipation using:
Current = V ÷ R = 12 ÷ <measured resistance>

and:
Power = V² ÷ R = 144 ÷ <measured resistance>

Also if you go with decreasing the voltage (instead of reducing the current value), you would have to compromise with a decrease in torque.

Sounds like the 12v 1a power supply should be used then and just compromise with the head via heatsinks

You have 2 phases. That's a potential peak of 0.8A for just the motors alone. I would derate it and use at least the 2A. You can't have "too many" amps - it only draws what it needs.

I think you will have a better chance reducing the heat by lowering the supply voltage (which will reduce the current as a consequence). You won't get the nominal torque if you go below 12V, but this is a compromise and there's no free cheese there.
Limiting the available current only works in a predictable manner with power supplies which can work as current sources. If your power supply is only a voltage source, then trying to draw more current than it can provide will eventually result in the power supply going into self-protection (not delivering any voltage) or breaking down. With voltage sources, maximum current is a limit you have to respect, not a limit the power supply will impose.


text:
Arduino losing connection to Serial port after running function
For some reason when I loop my code through a separate function the serial port hangs up. The serial connection appears fine when I call cases within the loop but not when I call outside.
I tried to figure out where the problem is and for some reason using the Serial.print(ComControlValue); and the output is

-1

But the error still persists.
Previous it was this before I changed the baudrate

-b⸮⸮⸮⸮ Waiting for Command

It's not printing out the -1 I'm using as the main case. Could this be the problem?
#include <Wire.h>
/* RPi Army variables */
int RPi[3] = {3,6,9};                                        // SDA/SCL code names for the different Raspberry pi's

/* Define parameters for computer control */
int ComControlValue = -1;

void setup() {
  Serial.begin(115200);                                     // Establish Serial connection to computer
  Wire.begin();                                             // join i2c bus as master
}

void loop() {
 switch(ComControlValue){
  /* -1 : nothing happened yet */
  case -1:
     Serial.println("Waiting for Command");
     while (Serial.available()==0){}
     ComControlValue=Serial.parseInt();                             // Pull value from serial port
     break;

  case 111:
     Serial.println("Eat more Toast");
     ComControlValue = -1;
     break;

  case 210:
     Sendsignals(RPi[0],333);
     Sendsignals(RPi[1],333);
     Sendsignals(RPi[2],333);
     ComControlValue= -1;
     Serial.print(ComControlValue);
     break;
  }
}

void Sendsignals(int Rpi, int code){
   char str[4];
   sprintf(str, "%3d\n", code);
   Wire.beginTransmission(Rpi);                                 // transmit to device of choice
   Wire.write(str);                                             // sends 16 bytes
   Wire.endTransmission();                                      // stop transmitting
}

Consider adding more debug lines during your Sendsignals function.
Perhaps it hangs up during the Wire transmission.
You should also consider changing sprintf to snprintf - apparently it's more robust against buffer issues, and requires the buffer size to be set manually.

I tried that and it seems everything runs fine up until the break; when going through my separate function.

Arduino Uno with an Adafruit motor shield

reconnecting Serial Monitor resets the board. while (Serial.available()==0){} blocks the loop

Everything seems to work fine though when not calling Wire.h . Once I call the Wire.h functions the serial connection messes up.

Your str variable in function Sendsignals is short. sprintf writes 5 bytes to it, 3 digits, the \n and terminating zero. The terminating zero is written outside of the allocated array and causes the crash.

This causes the serial terminal to disconnect? How to fix? Should I increase the str to 8 bits?

Thanks. I changed the size of the str to 16 and it fixed the issue.

str[5] would be enough, if your codes have always 3 digits


text:
USB and Arduino: Power Arduino, charge LiPo, and transfer data at the same time
I was hoping to design my own Arduino board for a recent project of mine, a portable project that was powered by a 3.7 LiPo battery. Most ideally, I wanted to replace the USB B port with a single USB Micro port that implements the following features:

Provides power to the Arduino while it is plugged in (just like a regular Arduino does).
Connect the D+ and D- pins of the USB to the Arduino somehow to allow for on-board programming (however the Arduino accomplishes this already, I'll refer to this as the "onboard usb/serial converter"). I want it to keep it programmable on-the-go.
Charges an on-board 3.7V LiPo Battery. I was hoping to use Adafruit's PowerBoost 500 Shield as a reference for my schematic.

However, I haven't been able to find a schematic or example that implements all 3 features above at the same time from the same USB port. I don't have much experience with charging circuits, so the following questions might sound dumb. Below are some solutions I was thinking of that probably won't work, but I wanted to make sure:

Connect the Output Voltage of the LiPo Battery to the V+/GND supply of the USB cable (probably not safe to connect all V+ sources together).
Just connect the D+/- data cables to the "onboard usb/serial converter" without connecting the Vbat/Vusb somehow, have the USB V+/GND connect to the LiPo charging circuit, and the Battery Voltage power the Arduino.

I know some devices have this charging/data-transfer functionality (e.g. my phone can transfer photos to my computer while being powered on and charging at the same time), but I'm wondering how it's possible to have similar functionality for an Arduino board. Any advice?
Absolute worst case, I'll just have 2 USB ports, one for charging the LiPo and one for Serial Communication/Programming
EDIT: The idea of using an ATMega32U4 seems appealing (despite the 3.3V vs 5V operating voltage), mainly because it has a pin for VBUS for USB and Vcc for main power. But I was wondering how to do this on say an ATMega328P that doesn't have a pin for VBUS.

just wire the micro usb to an "ftdi", the ftdi to the MCU, and the ftdi's power pass though pin (5v) to a lithium charging board (about 50 cents); and bob's your uncle;  all three for under $2...

I'd recommend using the Arduino Leonardo as a reference for your circuit. Its pretty much the same as an Arduino UNO but has a built in USB interface so you don't need the USB-Serial converter.
I'd also recommend running the chip at 3.3V. That way you can use a linear regulator to regulate the 3.7V battery voltage down. Otherwise you'd need a boost converter to bump the voltage up to 5V which needs more parts.
If you follow those recommendations then all you will need is a LiPo charging IC to handle the charging. You'll need to add an ISCP header to flash the initial Leonardo bootloader, but after that you can use USB and the Arduino IDE to program it.
I did exactly this for a school project a while back. You can find the schematics here: https://github.com/seanwatson/ece4416-project/blob/master/hardware/rev2/sw-4416-project-v2-sch.pdf

Hmm, I was hoping to avoid using an ATMega32U4 because I don't have much SMD Soldering experience. But it seems like it has a pin for USB power AND a separate Vcc power? That looks awfully convenient! I will give this a try

The presence of those two pins does not mean that they are dual inputs and the chip will run off of whichever is powered; they have specific purposes.

Personally I'd avoid using a linear regulator on a battery powered system... Losing 25% of the energy stored just to heat the regulator is not very efficient. In any case I second the 3.3V suggestion: with a simple buck regulator (even already pre-soldered in modules like the ones sold on ebay at around 1$) you get more efficiency than with a boost regulator and a 3.3V uC consumes less power

Oh, sorry for the necroposting. I didn't notice that this was a very old post that was bumped because @GeorgeTroulis didn't accept an answer...

@frarugi87 it's ok, the reason I haven't accepted an answer yet is because I never actually tried any of these solutions yet :| Should I still accept one of these solutions? Because they are all so good! Thank you for your feedback :)

Use a TP4056 1A LiPo charger board (it has overdischarge protection) and a boost converter, like the XL6009. It will run you at most 5$ if you are prudent. Overdischarge protection is important.
If you want a port for programming, add a micro-USB breakout board, and if necessary a pushbutton for bringing RST down to GND. I prefer just having GND, TX, RX pins on a 3 pin header, and plugging my cable into that.

Following on from Sean Watson's answer, I would probably use the Bare Conductive Touch Board as your reference. It's a Leonardo derivative with all the features you're asking for. Full disclosure - I work at Bare Conductive and worked on the design of the board.
Eagle schematic and board file are here. Also, since this board successfully passed CE and FCC radiated emissions and immunity testing, you know that the reference design is sound for this if you want to create a product to sell.
The design uses a boost converter to allow for 5V operation - if you run the Atmega32u4 (or Atmega328) at 3.3V, you don't get guaranteed correct operation with a 16 MHz clock (check the data sheet). Since the Arduino bootloader for the Leonardo is written for a 16 MHz clocked MCU, this saves you the task of modifying the bootloader - and gives you the full 16 MIPS maximum performance.

How do you mean "at 3. V, you don't get guaranteed correct operation with a 16 MHz clock"? Looking at section 29.3 of the Atmel datasheet, it's hard to distinguish that 3.3V @ 16 MHz is in the safe operating area, but since the Arduino Leonardo already works at 16 MHz, doesn't that mean it's "guaranteed"? I'm guessing you mean that if I buy my own 32U4, I'll have to modify the bootloader to get guaranteed 16 MIPS performance (with an external 16 MHz Oscillator of course)?

The Leonardo works with a 5V VCC (take a look at the schematics) - so you can't be sure that 3.3V operation is guaranteed from that. Looking at this datasheet I can see that 3.3V is clearly NOT in the Safe Operating Area - it's section 29.6 here. Also there is a typo above - the curve is clearly linear between 2.7V < VCC < 4.5V, not 2.7V < VCC < 5.5V as written.

Oh my bad, I was looking at the datasheet for the ATMega328P, which does not include the 32U4. Also how silly of me, I was under the impression that the Leonardo operated at 3.3 V (what is wrong with me?). Perhaps using a boost converter for 5V operation then is my best option if I want 16 MHz guaranteed. I might be willing to go 8 MHz though, just to avoid the boost converter. I don't think my project will be affected, and it seems to be what the lilypad does


text:
How do I update library h-file in arduino create online editor?
I'm working on a sketch that includes i2c with a SSD1306 OLED and need to update a constant in Adafruit's h-file in the library.
How can I do this in the online editor?
/Jonas


text:
How to keep warm arduino uno board with 12v dc supply
I have an arduino uno board with ESP8266 module and i have done all connection using breadboard.
Now when i run arduino uno with USB cable for long time then its not getting hot ! but when i supply power with 12v dc adapter in black barrele then its getting too much hot (i cant touch with my fingure).
Now when i remove the ESP8266 module power and test it again with 12v dc power supply then its not getting hot !
So what is the problem with ESP8266 module ? Is my wiring creates heat ?

need to show wiring diagram, and give specs on the power supplies. But the esp should not be getting that hot

What is the "it" that is getting hot?

@NickGammon Arduino bottom part of that black barrele.

@ChadG yes its readlly getting hot. ! i have also attchaed 5 v realy

Also asked at: http://forum.arduino.cc/index.php?topic=538176 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.

Is the ESP8266 working as expected?

you're not supposed to power the esp01 from an UNO. if you do, at least drop vin down to 7v.

See Can I use arduino's 3.3 V output directly to esp8266?
From that page:

The specs for the Uno say that it does not provide as much current on the 3.3V line as the specs for the ESP8266 requires. You will need to provide another regulator that can supply enough current.

Also, putting 12V into the barrel jack is making work for the on-board voltage regulator (located near the barrel jack) because it has to convert 12V to 5V (making heat in the process). You would be better off putting a lower voltage into the barrel jack, ideally around 7V (but not lower).
Alternatively, just power through the USB port as you have been, and plug the USB cable into a USB charger.

To summarize, both the 5V and 3.3V voltage regulators are probably working very hard, thus getting hot.


text:
Arduino eeprom_put sketch writes data in two locations?
Using precisely this code - the eeprom_put example in the Arduino IDE, and am seeing some strange results...
The sketch does write correctly to eeAddress = 0, and the corresponding eeprom_get sketch does return the data.
Please note that I've initialized the entire EEPROM with 'FF's before any test...
The weird part is this sketch writes exactly the same data starting at Address = 2048. The loop is not running; I see no jump to offset 2048... I gotta be missing something!
I'm dumping EEPROM using avrdude, and viewing results in an external hex editor.
How is this stuff stored? Apart from not being able to directly view a float - OK, I get it - should the other data be simply viewable in hex?
My own experiments in writing hex bytes directly also work, but also write in two locations.
Small update to this: Precisely the same behavior seen with a RobotDyn Mega. Both the 'clone' Mega and the RobotDyn report: Device signature = 0x1e9801 (probably m2560)
#include <EEPROM.h>

struct MyObject {
  float field1;
  byte field2;
  char name[10];
};

void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  float f = 123.456f;  //Variable to store in EEPROM.
  int eeAddress = 0;   //Location we want the data to be put.

  //One simple call, with the address first and the object second.
  EEPROM.put(eeAddress, f);

  Serial.println("Written float data type!");

  /** Put is designed for use with custom structures also. **/

  //Data to store.
  MyObject customVar = {
    3.14f,
    65,
    "Working!"
  };

  eeAddress += sizeof(float); //Move address to the next byte after float 'f'.

  EEPROM.put(eeAddress, customVar);
  Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}

void loop() {
  /* Empty loop */
}

What board/mcu are you using? And did you give a larger eeprom size to avrdude to dump?

It's a mega2560 - in fact, avrdude correctly detected it, and its 4k EEPROM size. No, did not override any EEPROM size parameters.

What is probably happening is aliasing.  Let's say your processor has a 16 bit address bus.  16 bits can count up to 2^16 = 65536 = 64k memory addresses.  Each address is a byte (B) so your processor has 64k-Bytes of address space.  It can physically address 64kB of memory.
What happens if you only have one memory chip with 4KBytes of memory, with  only 12 address lines?  Well, if the designer was lazy (or cost-conscious), the first 12 address lines on the processor will be connected to the 12 lines on the memory chip.  The other 4 lines on the processor will be ignored.
So it doesn't matter what the processor does with address lines 13-16 -- they're not connected to the memory chip.  Therefore the contents of the memory chip appears where you expect, starting at address 0, but also again at address 4096, and again at address 8192 and so on.

Ah! I had no idea about this. And I imagine it seems a reasonable possibility for a cheap clone Arduino Mega2560? Supposed to have 4k of EEPROM, but sounds like you're saying a big chunk of it may not be usable!

The Arduino Mega 2560 has 4k of EEPROM and all 4k is usable. Only a few ATmega chips have 2k EEPROM, for example the ATmega644. Perhaps you are doing something wrong, perhaps avrdude is limited, or perhaps you hit a bug. When you do a read from 2048 in the sketch, you only see FF ?

Well, it's slightly more nuanced than that. Board reports it has 4k bytes, as I'd expect. Its behavior at this point seems consistent with Mark Smith's comment above. A good test will be an attempt to write to addresses above 2048 - will try this tomorrow.

Another update: Yup, similarly weirdness when writing to address: byte eeAddress = 0x800.
Data is written to both 0x800 and 0x00. Wow!
@Mark Smith - whaddaya think?
Anybody else interested in testing this on their own boards?

That's exactly the same behavior. 0x800 = 2048. Because of the incomplete decoding of the addresses, those addresses address the same piece of memory. They are the same piece of memory.