text:
Output of Hex of ino
I have a hex file of a sketch i.e. sketchname.ino.hex. Can I find out anything from that hex file ?  Can I see the output or anything ? Can I upload it on arduino ?

Not really...  I mean, if it was mission-critical there might be a way, but in general the effort to do so would be more than simply rewriting the program.

I have a hex file of a sketch i.e. sketchname.ino.hex. Can I find out anything from that hex file ?

That is a binary image of the compiled sketch in a hexadecimal notation. You could spend hours disassembling it if you understood the right tools to use.

Can I see the output or anything ?

You can convert it back to a crude form of assembly language maybe, but that is all. Understanding what that means takes skill and knowledge.

Can I upload it on arduino ?

Sure. It's a compiled program ready to be uploaded to an Arduino.
avrdude -D -patmega328p -PCOM3 -b115200 -C/path/to/avrdude.conf -c arduino -Uflash:w:sketchname.ino.hex:i

Thanks, I just few queries regarding uploading the code. I have Arduino Uno and Due so how do I change the command for them and will it harm the Arduino ? And how can I find what the code is doing after uploading it ?

Arduino and Due use completely different programs, and the entire systems are completely different. You can only upload the HEX to the chip it was compiled for.

How will I verify for which system is it for. I have few lines of hex code only.

You won't. You'd need to see the source and know what the compilation options were when compiling.

"a few lines of hex code" is unlikely to be of any use on either board.  You could attempt to disassemble it and see what it might imply as instructions for either system, but it is probably an incomplete fragment.

@Majenko Oh okay.

@ChrisStratton It gives error objdump -d chall.ino.hex : objdump: can't disassemble for architecture UNKNOWN!

Disassembling raw files is a pain, you have to specify the architecture as a distinct command line option (and you need to use an avr or arm objdump, not the one for the host system!), may need to tell it about or translate the input format, etc.   And as I said before, if you only have a few lines it's unlikely to yield anything interesting.

@ChrisStratton I got around 400 lines after disassembling it ! . I don't know what to do now. Can I convert it into C program ?

No. Now you need to learn assembly language. Welcome to the world of real embedded system programming.

What are you trying to do anyway? You have some binary, you don't know what device it's for or what it does. Why are you interested in it? What are you REALLY trying to do?


text:
Arduino Mega Timer1 in pure C problem - doesn't work
Does somebody know what can be wrong in this, where I try to set Timer1 interrupt in Arduino Mega in C code only. I'm trying CTC Mode and the purpose is LED blinking with 1[s] Period.
I work with documentation program doesn't work completely.
 #include <avr/io.h>
 #include <avr/interrupt.h>

 void setup()
 {
   //LED -> PB7 (Digital pin 13
     DDRB |= (1<<PB7);

  //FCPU = 16MHz, Prescaler :256 | CTC
   TCCR1B |= (1<<CS12) | (1<<WGM12);
   TIMSK1 |= (1<<OCIE1A);  // Compare Match A interrupt allowing
     OCR1A = 62500;

    sei();
    }

  void loop()
  {

   }

   ISR(TIMER1_COMPA_vect)
   {
     PORTB ^= (1<<PB7);
    }

Where is your main procedure? For toggling you can use PINB = _BV(PB7); // or (1<<PB7), for setting up timer you can use assigments directly, as you don't care about previous values...

Actually you should use assignments. The Arduino core library configures timer 1 for its own purposes (for phase-correct PWM at 490 Hz), so you should set both TCCR1A and TCCR1B to whatever suits your application, and not rely on their previous values. Alternatively, if you are not using the core, you could write your own main(), which would skip the Arduino hardware initialization.

Btw the arduino IDE requires using setup() and loop() section as a main(). So you suggest using "=" instead of  "|=" regarding to preliminary arduino settings?

So that "pure C" doesn't really mean you have simple *.c file with everything? You have *.ino and you're just using registers directly? Then yes, you have to make sure everything for Timer1 is in correct states. For example all counters are configured to the 8bit fast PWM mode and setting WGM12 doesn't change anything as it's already set.

Ok, ok. I catch it. To be clear. I'm want to code in pure C but using Arduino IDE. So It requires specific arduino's program structure with setup() and loop(). And apart from it, everything is as a normal pure C language, working with uC registers not with arduino's libraries. That's my purpose.

You wrote: “the arduino IDE requires using setup() and loop()”. No, the IDE does not require setup() and loop(), the Arduino core library does. You can use the Arduino IDE and write your own main() if you don't need the functionality from Arduino core. And that's the closest you can get to “pure C” with the Arduino IDE (but technically it's C++).

Edgar Bonet, Ok. But Is using just main() instead of setup() and loop(), possible with bootloader? Doesn't Arduino's bootloader need those 2 arduino's loops()? I'm not sure, I'm just asking. I need to programme via bootloader not via external programmator.

@M_K No, the Bootloader is completely unrelated to the main program. Bootloader waits short time to the control characters and if there are none, it just jumps to the address 0000H (there are few more steps, but that jump is the most important)

I work with documentation program doesn't work completely.

simple:
1) check out the datasheet;
2) identify those registers needed to get tmr1 to work;
3) set or clear, as appropriate, ALL bits that are needed. Do NOT rely on default values.
4) done.

source: Stack Exchange

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

sort: votes


text:
How to get ip information of arouter/AP with ESP8266
i, I would like to get ip number, DHCP ip range subnet mask information of an external AP/router autonomusly through the ESP8266 sketch, so the ESP8266 code can determine a suitable static ip range to configure. Any example code or references would be appreciated.

All you can do is get what DHCP gives you.

Connect to the AP
Use DHCP to get an IP address
Store the IP, netmask and gateway in variables
Use the netmask to determine the "fixed" bits in the IP address.
Replace the "unfixed" bits of the IP with your own chosen IP portion
Re-set the IP information with your static information.

What you cannot do is determine what the DHCP range is. Only the router knows that, and it doesn't broadcast it.
The proper way of handling it, though, is to get the router to provide a fixed DHCP IP address for the MAC address the ESP8266 has. Most routers have this functionality available.

Thank you for your response Majenko. WHat I want to do is to handle all configuration for connecting to the network by ESP 8266 or an Android app. User should only need to select the AP and enter password. No other configuration should be needed from user. I need to make sure that the ip that I pick does not conflict wit already assigned dynamic or static ip addresses. For example if I configured a router for a specific IP with a MAC address, I cannot reconfigure same IP for another MAC address unless I reset the router to factory settings.

May be I can use the DHCP assigned ip as static IP, I would like to try if it works.

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


text:
How does one **get** attributes for SD files?
To be able to set the date and time of the files on my SD card I followed this answer: https://arduino.stackexchange.com/a/39127/49678
Now I am wondering How do I read the values out in the microcontroller?
To clearify, I get the correct timestamps when I remove the SD card and view them on a PC, but I also want to be able to read this on the microcontroller.
Inside SdFile.cpp on line 1025 there is a function called timestamp which is used to set the timestamp but I cant seem to find any function to read it.
https://github.com/adafruit/SD/blob/master/utility/SdFile.cpp
I would prefer a solution where I don't have to add it to the library myself.
The underlying problem I am facing is that I want to log files, and once the memory is full I which to remove the oldest files.

There are two libraries. The standard arduino SD library and the SdFat library by Bill Greiman ( https://github.com/adafruit/SD/blob/master/utility/SdFile.cpp ), the rest are copies, sometimes with a few extras. Even the arduino SD library was originally written by Bill Greiman. An example with the callback is here: https://github.com/greiman/SdFat/blob/master/examples/Timestamp/Timestamp.ino An example to print the date is here: https://github.com/greiman/SdFat/blob/master/src/FatLib/FatFilePrint.cpp You could avoid all of this and put the date and time in the filename.

In the FAT filesystem the timestamps and other attributes are stored in the directory, not in the file.  So you need to read the "file" that is the directory that contains the file you're interested in.
That "file" contains entries in a pre-defined structure. Reading each block of data using that structure gives you the information for each file in turn.
You can just do a normal SD.open(...) call to open the directory that contains your file, and then read chunks of data from it to get each file entry.
That data is arranged in the directoryEntry structure (here), so reading a block of data with File.read(...) into a variable of that structure type will yield your data:
struct directoryEntry dirent;

// myDir has already been opened and points at the start of your dir
while (myDir.read((uint8_t *)&dirent, sizeof(struct directoryEntry))) {

    // Names are tricky to print. Also you should check for deleted files here.
    Serial.print("Name: ");
    for (int i = 0; i < 11; i++) {
        Serial.print(dirent.name[i]);
        if (i == 7) {
            Serial.print(".");
        }
    }
    Serial.println();
    Serial.print("Creation Time: ");
    Serial.println(dirent.creationTime);
    Serial.print("Creation Date: ");
    Serial.println(dirent.creationDate);
}

You need to get an SdFile object for your file then use the SdFile::dirEntry method to get the directory entry for the file.
The directory entry (struct directoryEntry) has the timestamps.

Please tell that this is for the SdFat library. The example for dirEntry is the same I gave: https://github.com/greiman/SdFat/blob/master/examples/Timestamp/Timestamp.ino

@Jot, the SD library is the SdFat library wrapped into simplification with Stream implementation. it should be possible to use the SdFat part to get to timestamp

Thank you for your answer, however I am unsure how to do this. How would I go about to get an SdFile object? The only function I can find that returns SdFile in SDClass is:
SdFile SDClass::getParentDir(const char *filepath, int *index)

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


text:
Increase PWM bit resolution on only one timer 2 output
I am new here and I know that this basic question has been answered in the past but what I want to know is this. And I cant figure out how to add this to one of those threads. Sorry in advance if I am posting this wrong.
Arduino Uno
I have a motor driven PWM off output 10 and output 9 is used for the display, can I change the resolution of output 10 only to 16 bit? or will both outputs need to be used as PWM when changing timer 2 to 16 bit? All of the coding samples I see are for changing both outputs.

I'm sorry, I'm not familiar with PWM libraries within the Arduino framework, but I've taken a look at the microcontroller datasheet, and it appears there is a way to operate 16-bit PWM on pin 9 (OC1A) while retaining normal port operation on pin 10 (OC1B). Please refer to table 20-4 on page 170 of the datasheet if you are willing to configure the timer manually. It is rather involving unfortunately. Perhaps there is a library for that.

I think I agree with you, after reading the datasheet, therefore I will just rewire the board and not use output pin 9. If I get a little time I will do some testing with variations but for now I don't have the time. Thank you for the info!

@user49780, read the updated answer from Gerben

You mean “Timer 1”. Both outputs 9 and 10 are driven from Timer 1, not Timer 2.

Yes, you are correct, I did mean timer 1.

As long as you don't use PWM (i.e. analogWrite) on pin 9, any changes made to timer1 won't affect pin 9.
It will change both outputs, as both use the same (single) timer.
But you can use code to convert a 8-bit PWM value to a 16-bit value by simply multiplying the 8-bit value by 256.

The title is misleading. I don't think that the question was if you can have different PWM resolution on 9 and 10. I understand  the question so that one of the pins 9 and 10 should be PWM and second a simple digital pin. (I am not the downvoter)

@Juraj I think you might be right there.

Some of the stuff I had read about changing the timer 1 to 16 bit mode made it sound like both pin 9 and 10 could only be used for PWM then. Of course this seemed incorrect but I could not find anything with a clear answer. I have since rewired the project to not use pin 9 in case it was true. I will sometime soon figure this out with some testing. Currently have little time for that. I do have a new issue that I am trying to figure out. It has to do with the scaling. It is not working as expected. But I will look more into it before starting a new thread if I can't figure that one out.

The COM1A1 and COM1A0 bits in the TCCR1A enable PWM on pin 9. As long as you leave them at 0, pin 9 will act like a normal GPIO pin.

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


text:
ESP32 - JPEGDecoder from SPIFFS
Hello i've try to decode JPG image from FS so, i create and upload spiffs image (using /data directory and Arduino Ide Plugin )
On every jpg i've same error: "pjpeg_decode_init() failed with status 19"
here is my same code:
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include "GfxUi.h"

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

#define DEBUG
#define LOAD_SPIFFS

GfxUi ui = GfxUi(&tft);

void writeFile(fs::FS &fs, const char * path, const char * message);
void readFile(fs::FS &fs, const char * path);
void listDir(fs::FS &fs, const char * dirname, uint8_t levels);

void setup(void)
{
  Serial.begin(115200);
  Serial.print("Start");
  SPIFFS.begin(true);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);

  listDir(SPIFFS, "/", 0);
  fs::File jpeg = SPIFFS.open("/star.jpg", "r");
  //readFile(SPIFFS, "/star.jpg");
  boolean decoded = JpegDec.decodeFsFile(jpeg);
  Serial.println("===============");
  Serial.println("JPEG image info");
  Serial.println("===============");
  Serial.print  ("Width      :"); Serial.println(JpegDec.width);
  Serial.print  ("Height     :"); Serial.println(JpegDec.height);
  Serial.print  ("Components :"); Serial.println(JpegDec.comps);
  Serial.print  ("MCU / row  :"); Serial.println(JpegDec.MCUSPerRow);
  Serial.print  ("MCU / col  :"); Serial.println(JpegDec.MCUSPerCol);
  Serial.print  ("Scan type  :"); Serial.println(JpegDec.scanType);
  Serial.print  ("MCU width  :"); Serial.println(JpegDec.MCUWidth);
  Serial.print  ("MCU height :"); Serial.println(JpegDec.MCUHeight);
  Serial.println("===============");
  Serial.println("");
}

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\r\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("- failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println(" - not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("\tSIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\r\n", path);

    File file = fs.open(path);
    if(!file || file.isDirectory()){
        Serial.println("- failed to open file for reading");
        return;
    }

    Serial.println("- read from file:");
    while(file.available()){
        Serial.write(file.read());
    }
}

void writeFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\r\n", path);

    File file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("- failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("- file written");
    } else {
        Serial.println("- frite failed");
    }
}

void loop() {

}

Output from serial:
Listing directory: /
  FILE: /logo.jpg       SIZE: 16346
  FILE: /arduino.jpg    SIZE: 8426
  FILE: /star.jpg       SIZE: 3853
pjpeg_decode_init() failed with status 19 <--- here is
===============
JPEG image info
===============
Width      :0
Height     :0
Components :0
MCU / row  :0
MCU / col  :0
Scan type  :0
MCU width  :0
MCU height :0
===============

19 is PJPG_NOT_JPEG https://github.com/Bodmer/JPEGDecoder/blob/master/src/picojpeg.h

you should add a test if (jpeg) for file existence.

as far as I can determine uploading to SPIFFS via the Arduino IDE is broken as of the beginning of 2018. The files are uploaded but are corrupted on a read. There are a few fixes reported.  I am using a core from Dec 2017 and that works fine.


text:
Arduino Trinket and CCS811 sensor
I have connected trinket and CCS811
I am trying to build and upload sketch to the module:
  /******************************************************************************
  Read basic CO2 and TVOCs

  Marshall Taylor @ SparkFun Electronics
  Nathan Seidle @ SparkFun Electronics

  April 4, 2017

  https://github.com/sparkfun/CCS811_Air_Quality_Breakout
  https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library

  Read the TVOC and CO2 values from the SparkFun CSS811 breakout board

  A new sensor requires at 48-burn in. Once burned in a sensor requires
  20 minutes of run in before readings are considered good.

  Hardware Connections (Breakoutboard to Arduino):
  3.3V to 3.3V pin
  GND to GND pin
  SDA to A4
  SCL to A5

******************************************************************************/
#include <Wire.h>

#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811

#define CCS811_ADDR 0x5B //Default I2C Address
//#define CCS811_ADDR 0x5A //Alternate I2C Address

CCS811 mySensor(CCS811_ADDR);

#include <SoftwareSerial.h>
const int rx = 0; //3
const int tx = 2; //4
const int alarmPin = 4;
SoftwareSerial mySerial(rx, tx);

void setup()
{
  mySerial.begin(9600);
  mySerial.println("CCS811 Basic Example");

  Wire.begin(); //Inialize I2C Hardware

  pinMode(alarmPin, OUTPUT);
}

void loop()
{
  //Check to see if data is ready with .dataAvailable()
  if (mySensor.dataAvailable())
  {
    //If so, have the sensor read and calculate the results.
    //Get them later
    mySensor.readAlgorithmResults();

    mySerial.print("CO2[");
    //Returns calculated CO2 reading
    double val = mySensor.getCO2();
    mySerial.print(val);
    if(val>=2000){
      digitalWrite(alarmPin, HIGH);
    }
    //Serial.print("] tVOC[");
    //Returns calculated TVOC reading
    //Serial.print(mySensor.getTVOC());
    //Serial.print("] millis[");
    //Display the time since program start
    //Serial.print(millis());
    //Serial.print("]");
    //Serial.println();
  }

  delay(10); //Don't spam the I2C bus
}

However when I verify the sketch I get following errors:
In file included from C:\Users\Nitin\Desktop\co2\co2.ino:26:0:

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:77:28: error: 'TwoWire' has not been declared

  CCS811_Status_e beginCore(TwoWire &wirePort);

                            ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:97:2: error: 'TwoWire' does not name a type; did you mean 'Wire'?

  TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware

  ^~~~~~~

  Wire

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:112:13: error: 'TwoWire' has not been declared

  bool begin(TwoWire &wirePort = Wire);         //Use the Wire hardware by default

             ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:113:34: error: 'TwoWire' has not been declared

  CCS811_Status_e beginWithStatus(TwoWire &wirePort = Wire);    //Use the Wire hardware by default

                                  ^~~~~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:112:33: error: could not convert 'Wire' from 'TinyM_USI_TWI' to 'int&'

  bool begin(TwoWire &wirePort = Wire);         //Use the Wire hardware by default

                                 ^~~~

C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library\src/SparkFunCCS811.h:113:54: error: could not convert 'Wire' from 'TinyM_USI_TWI' to 'int&'

  CCS811_Status_e beginWithStatus(TwoWire &wirePort = Wire);    //Use the Wire hardware by default

                                                      ^~~~

Multiple libraries were found for "Wire.h"
 Used: C:\Users\Nitin\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
 Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Multiple libraries were found for "SparkFunCCS811.h"
 Used: C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library
 Not used: C:\Users\Nitin\Documents\Arduino\libraries\arduino_613982
Using library Wire at version 1.0 in folder: C:\Users\Nitin\AppData\Local\Arduino15\packages\adafruit\hardware\avr\1.4.13\libraries\Wire
Using library SparkFun_CCS811_Arduino_Library at version 2.0.1 in folder: C:\Users\Nitin\Documents\Arduino\libraries\SparkFun_CCS811_Arduino_Library
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
Error compiling for board Adafruit Gemma (ATtiny85 @ 8MHz).

I see that this library - SparkFun_CCS811_Arduino_Library is not compatible with trinket
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library/issues/19
can anyone give me pointer to write sketch for trinket connected to CCS811 sensor?

read the error printout carefully ... what is it telling you?

Looks like you have two choices

Use a different controller that is compatible with the normal Arduino Wire library - maybe something like the Nano?
Modify SparkFunCCS811.h to #include TinyWireM.h instead of Wire.h. This is actually not hard at all - just takes a bit of patience and the knowledge that "there is no magic".

Frank


text:
Using arduino shield seems to break serial.print and uploading new code?
Hello Stack Exchange Community!
For an arduino project I am working on, I modify the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 to support DSSCircuit's I2C Master Library (https://github.com/DSSCircuits/I2C-Master-Library). This is to combat the known issue of arduino's Wire library to often get hung up while trying to run the EndTransmission function, and it works some of the time. Code was from Stack Exchange community (Modifying Arduino IMU library to rely on DSSCircuit's I2C Master Library).
#include <I2C.h>
#include "FIMU_ADXL345.h"

ADXL345 acc = ADXL345();
int x=0,  y=0, z=0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  I2c.begin();
  delay(100);
  acc.init(ADXL345_ADDR_ALT_LOW);
  delay(100);
  Serial.print("Is ACC OK?: ");
  Serial.println(acc.status);
  Serial.print("Any Error code?: ");
  Serial.println(acc.error_code);
  Serial.println("********Print all register current values********");
  acc.printAllRegister();
  Serial.println("********END register print******");
  Serial.println(acc.getRate());
}

void loop() {
  // put your main code here, to run repeatedly:
  acc.readAccel(&x,&y,&z);
  Serial.print(x);
  Serial.print('\t');
  Serial.print(y);
  Serial.print('\t');
  Serial.println(z);
  delay(500);
}

Also, the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 libraries must be modified from using Wire.h to I2C.h .
// Writes val to address register on device
void ADXL345::writeTo(byte address, byte val) {
  I2c.write((uint8_t) _dev_address, (uint8_t) address, (uint8_t) val);
}

// Reads num bytes starting from address register on device in to _buff array
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  I2c.read((uint8_t) _dev_address, (uint8_t) address, (uint8_t) num);  // request 6 bytes from device
  if(I2c.available() != num){  // device may send less than requested (abnormal)
    status = ADXL345_ERROR;
    error_code = ADXL345_READ_ERROR;
  }

  int i = 0;
  while(I2c.available())
  {
    _buff[i] = I2c.receive();    // receive a byte
    i++;
  }
}

I'm using an arduino shield, and it prevents me from uploading the code at the same time as the shield is on. My best guess is that the shield is continually triggering the device to restart in a way that does not harm performance but harms upload of code.
Sketch uses 8,244 bytes (25%) of program storage space. Maximum is 32,256 bytes.
Global variables use 600 bytes (29%) of dynamic memory, leaving 1,448 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

When I open the serial port and let it run for a few seconds, it shows no current register values, and returns 0 for x y -- as expected.
Is ACC OK?: 1
Any Error code?: 0
********Print all register current values********
0x00: B00000000
0x1D: B00000000
0x1E: B00000000
0x1F: B00000000
0x20: B00000000
0x21: B00000000
0x22: B00000000
0x23: B00000000
0x24: B00000000
0x25: B00000000
0x26: B00000000
0x27: B00000000
0x28: B00000000
0x29: B00000000
0x2A: B00000000
0x2B: B00000000
0x2C: B00000000
0x2D: B00000000
0x2E: B00000000
0x2F: B00000000
0x30: B00000000
0x31: B00000000
0x32: B00000000
0x33: B00000000
0x34: B00000000
0x35: B00000000
0x36: B00000000
0x37: B00000000
0x38: B00000000
0x39: B00000000
********END register print******
0.10
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0

Problem is, when the arduino shield is put on during serial transmission the loop will stop, and the device will stop outputting any information to serial even if the shield is taken off. This also usually disallows the uploading of new code even if the shield is off, and the only solution I've found to sometimes work is waiting a few minutes, disconnecting the arduino from computer to kill its power source, and restart the arduino IDE.
Can someone help me understand why this happens?
Thanks Community!
John Doe

Which shield are you trying to use? Could you add a photograph?

@JohnDoe can you confirm to us the connection diagrams you have? Also the sample output you get is with the shield connected to arduino or without? I see a strange thing because register 0x00 is fixed according to datasheet and should be B11100101. Have you tried the old libraries to see if sensor is not broken?


text:
avrdude: stk500_rcv :programmer is not responding
I'm a newbee to Arduino programming and hoping someone can help me with this. These are the error messages.
avrdude: stk500_rcv() : programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10:not in sync:
Problem uploading to board.
I'm using a Arduino UNO clone on com port 3,the blink sketch is functioning. I get the mentioned error message on all sketches I have ran. Not sure what to do.

Are you running Arduino IDE, and get the message when you click upload?  What board model and speed is the IDE showing at its bottom right?  What programmer, in preferences?   Have you tried things suggested in 'Related' questions in sidebar?  Have you uploaded to any other boards?  Please answer the above by editing your question

And what do you mean by "the blink sketch is functioning" and "error message on all sketches"? Is the blink sketch working or not?

Yes the blink sketch works fine. In fact all the LED sketches work. I get the

Yes the blink sketch works fine, in fact all the LED sketches upload successfully. When I upload  any other sketches such as LCD, stepper and servo I get the mentioned errors.  Thanks for your help

I had a same problem with UNO R3 (CH340G) MEGA328P for Arduino UNO R3
On Ubuntu 14.04 I checked the whether the USB chip not recognized, but it looks ok:
~$ dmesg | tail -n 6

[ 3350.417900] usb 2-2: new full-speed USB device number 5 using xhci_hcd
[ 3350.546759] usb 2-2: New USB device found, idVendor=1a86, idProduct=7523
[ 3350.546763] usb 2-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 3350.546764] usb 2-2: Product: USB2.0-Serial
[ 3350.547255] ch341 2-2:1.0: ch341-uart converter detected
[ 3350.547996] usb 2-2: ch341-uart converter now attached to ttyUSB0

But the upload went wrong like this:
~$ avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P/dev/ttyUSB0 -Uflash:w:/home/oliver/Arduino_Build/Blink/Blink.hex:i

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
         User configuration file is "/home/oliver/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v1
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: Send: 0 [30]   [20]
....

After reading bunch of articles 1, 2, 3, 4, 5, 6 it turned out my bad Chinese Arduino clones does not have bootloader installed on the Atmel microcontroller ship. To solve this problem you need a working Arduino and the clone Arduino we want to fix.
Walk trough who to burn the bootloader: http://www.instructables.com/id/How-to-fix-bad-Chinese-Arduino-clones/
Shortly: Burn the bootloader

You need a working Arduino
Connect the working Arduino with a usb to the computer
Upload Examples->ArduinoISP on working Arduino
Connect the wires from the working Arduino to the clone as follows:

Pin 10 goes to reset pin
Pin 11 -> 11, 12 -> 12, 13 -> 13
5v to 5v and ground to ground

Go to Tools->Board and select the chinese board that is not working. in my case it's an Arduino Uno.
Go to Tools->Programmer and select Arduino as ISP.
Go to Tools again and select "Burn Bootloader".
Your clone should work just fine now, but don't forget to restore Programmer (set back to ArduinoISP or AVRISP).

My clone board does not had integrated LED on 13 pin :) you need to connect it for Blinking test.

try this site: https://github.com/Makeblock-official/Makeblock-USB-Driver/ , it works for me. This is a driver for arduino, and command for bash

I assume that you're trying to upload the code with the Rx and Tx pins connected..
Try removing the Rx and Tx and then click the upload button in the IDE..
This happens because your computer communicates with the Arduino via Serial communication. The Rx and Tx pins also do communicate via Serial communication. An Arduino does not have the capability to handle two such communications simultaneously. So, it goes out of sync.. And that's how you get this error...

this has been such a headache! thank you!

Anytime @Ryan Loggerythm

You mentioned arduino uno clone, do you know what USB chip it's using and what chip you are uploading the sketches to?
The clone I have is very fussy and hangs up continuously. I have had luck once or twice with uploading the sketches. Depending on the chips on the board downloading the proper driver will help and selecting the proper chip under the board setting i.e. Atmega328 or atmega8 depending on the chip. Hope this helps as it worked for me.

I'm not familiar with Arduino Uno, but in case of a Nano switching to another Processor in the Tools menu of the Arduino IDE solved the problem for me. For my Nano the ATmega328P (Old Bootloader) is the one that works, maybe there is a similar option for Uno.
Steps and screenshot: https://gyorgybalassy.wordpress.com/2020/10/16/arduino-programmer-is-not-responding-not-in-sync-error/

authors: влад орехович


text:
Unknown USB Device (Device Descriptor Request Failed) - Win 10
I am posting a possible solution here for any online searches happening upon this exact issue.
So I have a third party board (Mega 2560) and I was plagued with my board intermittently working, on some rare occasions it worked but in most cases it just threw me the "USB device not recognized" after plugging it into my pc.
Upon closer inspection I have noticed the following
The one coupling capacitor (Blocks DC but allows AC and signal to pass) was poorly soldered, barely making contact!
So if your pc intermittently connects to your arduino, maybe check what the physical signal path looks like, you might find something like this.

We are getting the same error completely out of the blue. We have an Arduino Uno board. We have tried just about everything from changing out the USB cable, uninstalling ALL programs associated with our machine and reinstalling them. Changed settings, updated our computer, used a different laptop to see if our computer was the issue (no problems there). Thought it was a driver issue to redownloaded and attempted updating... no go... Help!
We as a last resort have ordered a new Arduino Uno... Have we not thought of something to check? Thanks ahead of time!

SMD soldering is not easy but here is the fix. Continuity achieved!

Continuity achieved but... Did this solve the problem? Did you get again some errors or not?

It did solve the problem. Zero errors afterwards, connected every time I plugged it in. It does seem that the capacitor was to blame


text:
Connecting RCA audio cables to Arduino
I'm working on a project which needs better audio quality than just a piezo buzzer, so I went out and bought a pair of used cheap speakers for $3. It turns out that they have RCA audio inputs rather than 3.5mm inputs. There is a separated left and right speaker, with a left and right RCA audio wire coming out of each.
I've looked around on the internet about connecting speakers to Arduino, but I've only found ways to connect 3.5mm/TRRS to Arduino, or the RCA video jack to Arduino, but not the RCA audio.
How should I go about wiring the RCA audio wires to my Arduino Uno so that I can play basic melodies off it? Are any amplifier circuits, voltage dividers, etc. needed?
I am okay with splicing the cables.
Thanks

lookup "rca to headphone pinout" and pretend you have headphones. they are the same once you cut the connector off anyway (given one extra common with RCA)

I am trying to connect male RCA cables (which come on the speaker) to the Arduino, not the headphone jack

ahh. if it's on the speaker itself, you need some type of amplifier circuit; the arduino can only pump out a few dozen millwatts. get an amp that has RCA speaker-level outputs.

Can you elaborate? Can I build this amp or do I have to buy one? How would I connect the RCA cable to the amplifier (what are the individual wires inside the RCA cable)?


text:
Using SD shield for extra external memory?
I am an Arduino beginner and I am planning to make a musical instrument with it. I want to add record and playback functionalities into the instrument.
I figure I will have to store lots of data to meet this feature, but the Arduino I'm using (Uno/Nano) probably won't have enough memory to hold lots of songs.
My question is, is using an SD card with an SD shield a good way to expand memory? If not, what should I use to do so?
Thanks

As a beginner this MIGHT be a bit of a big thing to take on. Not that you shouldn't do it, just be aware that trying to write the code that will read and process data from SD is not trivial.   Also don't think of this as EXPANDING the memory of the arduino, as the memory you are adding cannot be used for your program.

they make hardware audio modules, for example with mp3 playback from sdcards or bluetooth, and that would be mounds eaiser than implementing it all yourself using low-lever hardware and from-scratch software. Checkout adafruit et al.'s offerings in that area before you spend week re-inventing a wheel.

By "record and playback" do you mean audio recording, or something more akin to MIDI where you just record the instructions of what notes to play when?

@Majenko I would be recording what note/pitch is being played, and playback would just play audio based on this data

So like MIDI then.  Sure, you can do that with SD.

@ChadG I'm assuming there are libraries I can use from online to read/write to SD?

Yep, there are 'built in' ones with examples in the IDE

There are different options:

SD shield: much memory (GB's), however keep in mind that it will take time to retrieve the data from the SD card. Also you can retrieve 512 bytes every time (which also means it costs 512 precious bytes of arduino SRAM).
External SRAM: There are external SRAM ICs, like 23LC1024 or 24K256. These are much faster and offer 128 or 32 KB. There are many others too, these are most 'common'. These are much faster than SD cards, you can get 1, 2 or more bytes per time. But it's not the same as Arduino SRAM, e.g. you cannot really store variables, so you have to copy data to internal SRAM to be used.

So first, check how much you need, and more important: what is the latency you can live with.

SRAM is probably not going to get the OP very far when it comes to audio, although it could be used as a buffer between "disk" and the arduino to improve latency issues.

True, I now read playback and record.

ESP32 modules have more RAM and 4mb of flash for less money than those ICs ;)

For audio processing, you might better use a Raspberry PI.

Thanks for the response! Based on your description I think an external SRAM would probably be better for the purpose.

@ChadG could you clarify on why it wouldn't work?

Also keep in mind this is for a educational project, and I'm not that willing to spend a lot of money on it. (Which is why Arduinos are being used rather than raspberry pi)

It depends on how much memory you need, the types I mentioned are 32 KByte or 128 KByte, if you want to store samples on stero 44.1 KHz you will run out of memory very quickly.

The recorded data would be very small, something that size should be sufficient.

In that case it should work ... a 23K256 cost about a dollar, but are mostly found not in DIP8 format so you have to do some 'smd' soldering, or buy a 23LC1024 for about 5 dollar.

Would it be difficult to get it working with beginner experience?

The 23K256 is easier (but need some tricky soldering), the 23LC1024 involves a lot of wires (has many more pins).

Since you are working just with instructions on how to play audio, not the audio itself, you effectively have very small amounts of data (comparatively).
You can store that data in a file on SD card and read it back simply enough (there's plenty of examples for reading from and writing to SD).
You don't need the whole song in memory all the time - you only care about the note you're playing (or recording) at any one instance in time, so you don't need lots of memory.
How you format the data is entirely up to you, but I would suggest following the MIDI standard which will allow you to work with other tools to create and edit the files as well as the Arduino. You can also then export your music simply to other applications, such as MuseScore, Finale, Sibelius, Ardour, etc.


text:
Help with simple gradually brighter flickering led
im a newcomer for arduino and sorry for any grammar error.
So what im trying to do is replicating a flickering effect found on spacecraft thruster when they about to take off where the fire bursting from dim to bright with flickering,similiar to afterburner on aircraft model which use neopixel led but this time only using common led.
I could mimic the flickering on the led with various  brightness level using the simple analogWrite,the problem is i cant really merge them since i use delay which is affecting how fast the flickering effect is and i need 1 sequence of flickering to stay a while before going next to brighter flickering and so on.
My code is quite too simple
    Int led = 9;
    void setup () {
    pinMode (led, OUTPUT);
    }

    void loop() {
    {analogWrite (led, random (10,15));
    delay (30);}

    }

Im thinking adding a new line with higher random led states (ex. 50,100) should be okay,but then the delay which affect the flickering speed are too short and making both line merging useless since its will go to the brightest in no time.
Is there's any way to hold the first dim line for an amount of time then continue to the next brighter line and so on without affecting the filckering delay?
Any help will be appreciated
Thank you!

first learn the BlinkWithouDelay example

@Juraj thank you for your response juraj,already playing around with milis for a few times,but all its do is holding the line while the other line overlapping it(which is okay for cosmetic purpose,but i didnt want to wasting resource),and its become too complex if i want to address each line with each their own milis

you have only one LED?

@Juraj i have 1 WIRE to distribute this effect from pin 9,i believe i can power as many led as i like with or without the arduino later,so yeah you can say 1 led but not really

then add second analogWrite and a delay after it

Before using millis() you can try to create the thruster effect with delay().
I think 40Hz update rate for the led should be enough.
The sketch starts with a random value between 5 and 15 and ends with a random value between 80 and 256.
The part in the middle that gradually increases between those values is a mathematical problem.
// Led mimic spacecraft thruster.
//
// Update rate 40Hz for the led.
// That is a delay of 25ms.

#define RATE 40  // update rate of led in Hz
const int ledPin = 9;   // it must be a PWM pin !

void setup () {
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);

  randomSeed(analogRead(A0));
}

void loop() {
  int n;

  Serial.println("10 seconds low brightness");
  n = 10*RATE;
  for(int i=0; i<n; i++) {
    analogWrite(ledPin, random(5,15));
    delay(1000/RATE);
  }

  Serial.println("5 seconds gradually brighter");
  n = 5*RATE;
  for(int i=0; i<n; i++) {
    //   random start: from 5 to 80     (75 increase)
    //   random end  : from 15 to 256   (241 increase)
    //   The calculation is with long, it might not fit in a 16 bit integer

    int random_start = 5 + int((long(i) * 75) / long(n));
    int random_end   = 15 + int((long(i) * 241) / long(n));
    analogWrite(ledPin, random(random_start,random_end));
    delay(1000/RATE);
  }

  Serial.println("10 second full thrust");
  n = 10*RATE;
  for(int i=0; i<n; i++) {
    analogWrite(ledPin, random(80,256));
    delay(1000/RATE);
  }

  analogWrite(ledPin,0);
  delay(2000);
}


text:
my button won't work, why?
I have been trying to get the button to work properly for over a day, but it just won't, can you help me.
The lcd display is for another part of this project, not important at the moment, but I can't take it away.
Also, the piezo plays the sound within else{}.
const int buttonPin = A0;

int buttonState = 0;

void setup() {

  Serial.begin(9600);

  pinMode(buttonPin, INPUT);
}

void loop() {

  if (buttonState == HIGH) {
    tone(8, 400);
  }else{
    tone(8, 300);
    delay(375);
    tone(8, 200);
    delay(375);
    tone(8, 100);
    delay(750);
    tone(8, 400);
    delay(250);
    noTone(8);
    delay(5000);
  }

}

You seem to have forgotten to actually read the button state from the button...

@Majenko you mean this? buttonState = digitalRead(buttonPin);

buttonState = digitalRead(buttonPin);

Yes. Without that how can your program know what the button is doing?

i have that in the code i'm using, I forgot to copy it to this code. @Majenko

I didn't want to add all the code, because half of it are some custom characters i have made. @Majenko

So try your posted code for yourself and see if it does what it should do. Don't try and second guess yourself - the first step of debugging something is to write a program that tests that one thing and then see what the results are.

@Majenko Well, i have a program that sees if my code has any problems, I already tried my posted code for myself and it doesn't do what it should do.

Did you include the digitalRead in the program you tested?

@Majenko Yes i did.

@Majenko do you want me to post all the code i have, including the custom characters for the lcd?

No. With your test code did you hold in the button and wait the 7 or so seconds before it came time to test it again? Or did you just tap it hoping that all those delays would not matter?

@Majenko Okay, so with the 7 second delay it works, is there a way to make it work when i just tap it?

Define "work". At the moment it does exactly what you have programmed it to. If you want it to do something else you will have to program it to do something else. What do you want it to do?

@Majenko Well eventually I want to make a side-scrolling game, where you have to jump over obstacles, the sounds will be on a different place, except that one if you press the button

It sounds like you need to learn the art of writing non-blocking code. The use of delay() should be avoided at all costs.

@Majenko Got it, but can i use those delays for a death sound.

You can only use delay at a time when you are not wanting to do anything else at all. If all you are doing is playing the tune then sure, use delays. But never if you are doing anything else, like reading a button.

@Majenko Okay, thank you for taking the time to help me


text:
How to make DC motor rotate a specific number of turns?
Can someone please give the code which can be used to rotate the dc motor a specific number of rotations like 2 rotations or 5 rotations. I'm using arduino uno board.

I'm voting to close this question as off-topic because this isn't a gimme da code site.

Hi @Rohit and welcome to the Arduino SE community. Unfortunately your question doesn't meet our quality standards. Please edit and improve it. How to ask

You can't. You either have to attach a sensor to the motor shaft to measure the numbers of rotations or use a stepper motor.

No! That is not how motors work.
If you need precision control you need to use a stepper motor or servo.
You could implement some solution with a geared motor and position sensor, but this really only works (imprecisely) with a slow rotation speed.

Can someone please give the code which can be used to rotate the dc motor a specific number of rotations like 2 rotations or 5 rotations.

fairly simple:
rotation_count = 0; //initialize rotation counter
motor_on();  //turn on the motor
while (rotation_count < DESIRED_COUNT) {
  rotation_count = count_rotation(); //update rotation count
};
motor_off(); //turn off the motor


text:
FastLed (WS2812B) and IRRemote problem
I am trying to control my WS2812B with a remote control. To archive this, I am using IRRemote library. The problem is that this two libraries doesn't work together.
I did some research and found out that it is a problem with timers.But, inside the IRRemote library file (boarddefs.h) there is a possibility to choose different timer (It uses TIMER2 as default, so I supposed that FastLed uses also Timer2).
So when I change the timer in boarddefs.h file to TIMER1, it is also now working fine for me. I keep recieving random IR codes. When I stop using FastLed library, I recive correct codes.
Some workaround to this problem is to read IR signal only once irrecv is idle:
  while (!irrecv.isIdle());  // if not idle, wait till complete
  if (irrecv.decode(&results)) {
     ...
  }

It makes around 80% of readings correct.
I am using arduino NANO clone. My question is, if there is any way to use IRRemote and FastLed libraries together other than using two arduino NANO (use one to read IR and other to control LEDs)?

update in 2021, similar problem, fastLED causing unintelligible IR codes,
adding that while loop:
while (!irrecv.isIdle());  // if not idle, wait till complete

just before the ir check
worked for me, not 100% of the codes are correct but more than good enough for my use,
you life saver

The WS2812B chips are highly timing-dependent. You have to clock out bits within a range of ±150 ns. This isn't likely to work well with clocking in bits from an IR remote. You are finding errors on the IR codes - that doesn't surprise me.
I suggest you use your idea of two Nanos. One can be reading IR codes. The other can display a stream of pixels and then "ask" the other one (eg. via serial or I2C) if a different command has arrived. That way the timing can be shifted in such a way that both processors are not interrupted when they are busy.

But as I read, Arduino NANO can use two or even three timers. I do not fully understand timer topic, but what I understand is, than I could use timer1 for LED and timer2 for IRRemote - but it does not work...

Yes, but just having timers doesn't necessarily solve your problem. You are clocking out bits to the WS2812B every 350 ns or so. That doesn't give you spare time to read incoming IR bits, timer or not.

I want to add my two cents at the solution posted bt @BenAshmore, that allow to mediate between fast updates and receiving sensible data:
void loop() {

 if(IrReceiver.decode()){
    if( IrReceiver.decodedIRData.protocol == UNKNOWN ){
        wantData=true;
    }else{
        wantData=false;
        Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
    }
    IrReceiver.resume(); // Enable receiving of the next value
  }

  if(!wantData || IrReceiver.isIdle() ){
    FastLED.show();

  }

basically if I receive messy IR data I know there is something incoming and just in that case I interrupt the FastLed updating until I read something good.


text:
Why doesn't my LEDs turn on?
i have just started learning Arduino, so please be patient to me :)
Why doesnt my circuit below doesn't work?

Here's the code:
#define led_green 2
#define led_yellow 8
#define led_red 13

void setup() {
  pinMode(led_green, OUTPUT);
  pinMode(led_yellow, OUTPUT);
  pinMode(led_red, OUTPUT);

  // Strarting all turned off
  digitalWrite(led_green, LOW);
  digitalWrite(led_yellow, LOW);
  digitalWrite(led_red, LOW);
}

void loop() {
digitalWrite(led_red, HIGH);

delay(1000);

digitalWrite(led_red, LOW);
digitalWrite(led_green, HIGH);

delay(1000);

digitalWrite(led_green, LOW);
digitalWrite(led_yellow, HIGH);

delay(1000);

digitalWrite(led_yellow, LOW);

}

I'm trying to reproduce this circuit that I saw in a tutorial:

Thank you.

"I'm trying to reproduce this circuit that I saw in a tutorial" But your connections don't look anything like that.

Is it better now? http://s33.postimg.org/z4xey1jxr/now.jpg

No.  The outputs all are shorted directly to the GND rail, and could damage your arduino.  Also the top-ends of the LEDs are shorted to the bottom ends of the LEDs, so no current will flow through them.

The tutorial you showed has the LEDs "jumping the gap" in the middle. You can't move them to one side like you did. That just shorts them together.

The code  that you posted, is that the same code you put on the Arduino in the image?

If you are doing what is in the first picture then you're doing it wrong.
You have to make sure the led is horizontal, not vertical. The signal is going through the led and not making it into ground. And your ground is in the same lane as your signal.
I think you should learn how breadboards work and then move on from there. Its pretty simple and I think you'll learn it quickly.
For your code part, instead of defining the variables, you could just use int.
 Refer to this as a starter tutorial, https://www.arduino.cc/en/Tutorial/.

This is how your wiring should look like if you followed the tutorial,

Thanks, i 'll look into it... just one thing, though: it looks to me that the led is vertical in the picture of the tutorial!

Haras' circuit is fine.  The 'verticalness' in the pic you posted has the leds bridging the center gap, and the resistors jumping to the common GND rail.  Contrary to your circuit, Haras is twisting the LEDs sideways so both terminals of the LEDs are not shorted together, but are on different 5-tie-point segments on the breadboard.


text:
What are the causes of Arduino lockup?
We know watchdog timer if enabled RESETs when Arduino is locked up somewhere inside the code. As the title suggests has anyone experienced this unless they put deliberately a while(1) loop inside the code? Of course, buffer overflow or memory related issues are excluded.
I mean is it worth in Arduino to use watchdog and RESET rather than to fix the code to not get locked up. Are there still some behavior which are not predictable here?

Your code might communicate with an external sensor. If the sensor doesn't respond (correctly) your could could get stuck. Or there could be noise on the signal wires resulting in a response that you wouldn't get ordinarily. You could do a lot of checks in software, but you might just miss that edge case that only occurs once in a blue moon.

@Gerben    the case is I have made a Mega based device with GSM to send certain sensor data to my server. It works fine everywhere, but at a specific place I have seen the device stops communicating with GSM; it simply gets struck. What I believe it could be a power issue, or ground mismatch with the sensor device which communicates with RS-232. So I consider implementing watchdog here and see the result.

The watchdog doesn't necessarily reset the processor. It can call a watchdog ISR. Also it's worth noting that sometimes the issue is external hardware, like an SD card interface or an RFID card reader. Resetting the processor in these cases doesn't fix the underlying problem that the attached hardware is locked up. A totally independent watchdog might be useful, which completely powers down, and back up, the entire device (including peripherals).

Agreed, the watchdog ISR has the option to RESET or raise an interrupt, whichever is necessary. Yes, the above case is equivalent to disconnect and reconnect power to the device and periperials again.

Most Arduino projects involve sensing the physical world or controlling the physical world (hopefully with some feed back).  When sensing the physical world, it is best to add extra code to protect the project from locking up.  And then, even more code concerned with what to do when the unlikely happens.  Unfortunately, many projects leave out this extra code.  Reasons vary:

The project is a prototype and the effort is thought necessary.
There is no time in the schedule to create this "extra code".
The unexpected event is thought to be an impossible situation.
There is no room left to add code that is not expected to run.

As an example:
A bicycle is outfitted with an Arduio base digital speedometer.  Speed is calculated based on the period of a wheel mounted magnet passing a frame mounted Hall Effect switch.  It works as long as the bicycle is moving at a reasonable speed.  However, the program does not take into account what happens if the bicycle is not moving.  If the magnet does not pass the Hall Effect switch.  The program's period counter continues to count up.  Eventually the watch dog timer reset the program.  Over and over again.
Approaches to avoid lockup or to avoid using the watch dog timer:

Place all "non-blocking" polling in an infinite loop which also check the elapsed time.  Consider the amount of time allowed to make a successful reading.  If that time expires consider a good course for the program to follow.  For instance a warning to the user or a default value when the measured value is unavailable.
Use interrupts.  That is, use the above method, but relay on external signal changes to generate interrupts to set values and / or flags.  This is a good (however more complex) alternative if the external signal occurs too fast for "non-blocking" polling.

If you want a heavily studied heavily reviewed real world example of watch-dog-timers simply search the Internet using a term similar to: "toyota watchdog timer".

That seems a good explanation. Well any idea on how to implement in real code which are complex and don't return within 8 seconds timebound set by watchdog timers.

One approach, place all non-blocking polling in an infinite loop which also checks the elapsed time.... I'll add this to the answer.

Yes, these are the alternatives to using watchdog timer and a good understanding of code flow is mandatory for prevention of lockup.

Thanks to @st2000 it was a good understanding of what watchdog does. What I gather is when dealing with a time-critical situation, where a mistake would cost you a lot, it is a must to use watchdog as a failsafe. Most importantly the code should be deterministic in time, where the system or the programmer is aware of how much time every action takes to complete. Unlike in GSM, where a majority of the tasks are dependent on network quality, it will hard to make a deterministic call on time.
Here is a good [ckecklist](https://criticaluncertainties.com/2013/11/13/watchdog-timers-the-unsung-heroes

If acceptable, consider accepting the answer.  Otherwise the system might kick the question back to the top of the list soliciting for more or better answers.

authors: Андрей Леонов

authors: Стоян Стоянов


text:
How to create objects with their own variables?
So i created a class and when i created objects and use them, they seem to share their variables between each other ( the currentReading, previousReading and the time variable). how can i create objects that have their own variables so that type of conflict cant happen?
code : ( read the buttons and print them in the lcd screen)
#include <LiquidCrystal.h>

LiquidCrystal lcd(6, 5, 3, 2, 1, 0);

class button {
  public:
    void SetupButton(int pino);
    int Read();

  private:
    int _pin;
};

void button::SetupButton(int pin) {
  pinMode(pin, INPUT_PULLUP);
  _pin = pin;

}

int button::Read() {
  static boolean currentReading, previousReading = 1;
  static unsigned long time;

  currentReading = digitalRead(_pin);// reading
  if (previousReading - currentReading  == 1) { // when reading gos from 1 to 0
    time = millis();
  }

  if (currentReading - previousReading == 1 && (50 < (millis() - time) < 500)) {     // when reading gos back to 1 before 500ms
    previousReading = currentReading;
    return 1;
  }

  if (3000 > (millis() - time) && (millis() - time) > 500 && !currentReading) { // when reading keeps in 0 after 500ms
    previousReading = currentReading;
    return 2;
  }

  if ((millis() - time) > 3000 && !currentReading) { // // when reading keeps in 0 after 3000ms
    previousReading = currentReading;
    return  3;
  }

  previousReading = currentReading; // current reading becomes the previous

  return 0;
}

button up;
button down;

void setup() {
  lcd.begin(16, 2);
  up.SetupButton(A0);
  down.SetupButton(A1);

}
void loop() {

  lcd.setCursor(0, 0);
  lcd.print(up.Read());
  lcd.print(down.Read());

}

ps :  i already know how to do this without using classes but doing it with classes makes the code much cleaner so i am trying to achieve this

you can test the code in https://www.tinkercad.com/things/8oXS6FQNK6A-dazzling-jaban

Your class has only 1 attribute _pin - which is private. If you want to have variables for each instance these should be in your class. Your code doesn't seem to create any class instances.

So if i create one more attribute for each variable ( like _currentReading,_previousReading, _time ) and use them in the fuctions will this solve my problem?

This would be the first step, but you need to create instances of your class e.g. up = button(4); It is normal to pass essential attributes in  the constructor.

thank you very much! i just created the new attributes and changed all the variables by it attribute counterpart and it worked flawlessy, post it as an answer so i can upvote it.

this question is not about Arduino. it is about C++

I was tempted to re-write your code (I am quite rusty on c++), but you may be better to start with an existing class.
There is a Button class on the Arduino site. See https://playground.arduino.cc/Code/Button
You could use this or study to see a more usual c++ implementation and adapt your code.
Virtually ALL c++ classes include a constructor. I would use instead of SetupButton
void button::button(int pin) {
  this->_pin=pin;
  pinMode(pin, INPUT_PULLUP);
}

and add uint8_t previousReading; and unsigned long time; to your class as private variables.


text:
is it possible to code microservo automatically stop when the speed of rotation getting slower?
my group is doing a project which call automatic bed maker. we want to use a servomotor to pull the sheet of the bed. can we possibly make the servomotor stop rotate when the speed of rotation decrease? or is there any way to make the servo motor automatically stop beside using timer.
sorry for broken english.

Not without feedback to the MCU.

Is this a very small model to show the idea? What is causing the speed of the servo to slow down? A standard microservo is only going to have a very small movement, and it is easier to get information from a DC motor with motor drive than from a continuous rotation servo.


text:
Why was the Due retired?
Looking at the Sparkfun comparison, it seems that the Due is by far the fastest of the Arduinos and has I/O capabilities similar to the Mega. So why was it retired with no obvious successor?

I had assumed it was either because it wasn't successful, or to allow Intel to differentiate their products more easily.

It's a quite expensive and clumsy board. It also runs on 3.3V. It's also not based on the ATMega328(P) and may thus be incompatible with some libraries (that rely on low-level hardware).
Arduino's are (mostly) for hobbyists, which require reasonably priced, not too big board, which they can use for anything. Most tutorials are based on the Uno and a few on Mega, thus someone looking to buy an Arduino, will most likely choose one of them.

I'd say the 3.3V thing matters the most because most shields require 5V.

I bought a Due thinking it was the best thing ever.  I cringed at the $50 (at the time) cost.  But I bought it anyway.  I actually think it's a great board.  But, within a short amount of time I was finding many libs that would not work with it.  I think most people realized that if you need something more advanced that UNO, and have $50 to spend, there are much better options out there.  Not that I know what they are...I'm just thinking that is why you don't see the DUE mentioned as much.  Shame really.  I think it has potential.  A Teensy3.x could be a good alternative for the DUE.

The Due is (was) a great board ! 32 bits bus, 86Mhz, same price as the Mega... Badly, the Arduino Drivers never worked well for the Due. If you want to program it, ASF was a better alternative

"Why was the Due retired?" - It is quite interesting that Arduino.CC never explained that. One would think, that a professional company or organisation places a notice in advance with at least a short explanation as to why.
Most of the Arduinos, that have been available on both projects (CC and ORG) have suddenly and without further notice or explanation been retired on CC (the exceptions being Uno and Mega 2560, the cash-cows), but are still alive on ORG.
It would seem, that either the "divorce" is proceeding or that the copyright case at the US court is not going as smoothly as Banzi hoped. Well, he could repeatedly "bend the truth" by claiming Arduino being completely his idea and design in front of the press (that never bothered to check the obvious facts), but laying such a claim at court is borderline criminal. (see also: arduinohistory.github.io and make your own opinion)
CC has still the biggest chunk of the overall community and also serves as the central nexus for developers. But it seems there is a lot of movement... some people move to Wiring (from which the Arduino IDE was forked), others to 3rd Party sites and yet others try out different  and newly emerging products (eg. Adafruits MCUs and Pi or the Renesas GR series).
ORG on the other hand seems to become the bigger (Arduino branded) hardware supplier and developer. CC has apparently out-sourced this to Intel and tries to live of royalties and "certification" fees (which is the central point where Banzi and Martino started to heavily and openly disagree).
"Why was the Due retired?" - Unless CC doesn't give an explanation, there is no real answer. A lack of interest is certainly not the reason.

Because, basically (in my opinion, anyway) it was rubbish.
Yes, it has grunt. Yes, it has IO, but the chips themselves are pretty rancid.
There are far better options than the SAM3X from other manufacturers.
Also, since all the in-fighting began between the two Arduino factions (.org / .cc) the majority of actual progress and innovation has been by third parties (Intel mostly).

Tiva comes to mind (if only they made LaunchPads compatible with shields [if only shields used a sane pin arrangement]).

I use the pic32 based chipKIT boards most.

@IgnacioVazquez-Abrams, I don't get the idea behind shields. It's rather impossible to allow multiple shields to be stacked, since you know they'll take up the same pins at some point? IMHO, they could've better gone with some "standard connectors" like UEXT (olimex) or Grove (Seeed).
-Majenko How's the IDE/Compiler(s) of microchip nowadays? And what actually makes the difference with AVR's SAM3X and others?

@Paul The IDE is the same as Arduino. You can install the chipKIT core into the Arduino IDE. You also have UECIDE, of course. The benefit of using PIC32 over the others is you get much better support from me :) Seriously, though, the PIC32 uses MIPS whereas most others bow down to the might of ARM. MIPS, MHz-for-MHz is actually slightly more efficient. Or it certainly has been historically. That's why 90% of home wireless routers use it. And now with 200MHz PIC32MZ chips with FPUs they really do fly along.

@Majenko, Hmm, I've worked with a PIC18F and IDE+compiler from Microchip. But for large objects I had to change memory banks in the linker file or something. And if you had a "non-paid" version of the compiler, they said it would be "less optimized". But the PIC32 series seems promising. I've also looked at ARM based boards, (teensy3.2) which I think are very nice as well. Not sure how they compare, but I'm looking something that's easy to learn (lot's of resources online and less struggle with oddities).

@Paul Software-wise the Teensy is probably the easiest. PJRC has put in a lot of work making it work really well and have good compatible libraries for it. The PIC32 boards (chipKIT) though have better hardware support - standard Arduino footprints, lots and lots of IO, built in Ethernet or WiFi on some models, etc. The Teensy is one product done very well, but doesn't always fit everyone's needs. chipKIT has far more to choose from, but the software is sometimes a little lacking, though it is improving all the time. Also I am available for hire to create new chipKIT boards ;)

The PIC32 chipKIT compiler is the open-source portions (i.e., GCC) of XC32. Freely available. Full C++, etc. The main difference is it uses newlib instead of Microchip's own C library.  Whoop-de-doo ;)

@Majenko Built-in ethernet is something that'll come in very handy ;). And indeed seems that it's much better "supported" as the PIC18F's. I was thinking of the difference between ARM and PIC32, but I guess it doesn't really matter that much per se. Ideally, I should get into both :x
It's good to work with something more "professional" as Arduino, but prototyping/building with DIP package (328P) is just so much easier/cheaper :) (But we shouldn't be chatting in this comment section (though it's more interesting as the original question xD)

@Paul There are PIC32s in DIP format believe it or not - the PIC32MX1xx/2xx chips are available in 28 pin DIP ideal for breadboard use.

It's not a review, it's an opinion. The entire question is about opinion. That is why the question is closed. My opinion is that the Sam3x chips are vile.

@Majenko could you please elaborate? I know it's old but I'd be genuinely interested why you say that. It seems like it'd be better than say a Mega2560 in every way (except arguably voltage).


text:
RC Car Hack Issue
I am trying to hack a cheap RC car as to be able to control it using my Arduino. I took apart the cars remote controller and found the pins that make it go forwards, backwards, left, and right. So I soldered 4 jumper wires to these pins and connected them to the Arduino as follows:
Pin 8 - Left
Pin 9 - Right
Pin 10 - Forwards
Pin 11 - Backwards
I found the remote controller is controlled by a chip called TX-2E, I checked the data sheet online and found that if any of the pins that control the pins motion are ground, the car will move in that corresponding direction. So if the forwards pin is grounded the car is supposed to move forwards.
To test this, I connected each jumper wire to ground on the Arduino individually and found that it worked as described on the datasheet.
Then I decided to create a sketch that makes the car move forwards for 1 second and backwards for 1 second, it worked as expected.
Then I wrote a sketch that makes the wheels turn left for 1 second and then turn right for 1 second. But it didn't work as expected instead the wheel turned left for 1 second, went to neutral for a second.
I wasn't sure what was wrong, but I decided to run a sketch that should move the car forwards for 1 second, move it backwards for 1 second, turn the wheels left for 1 second, and then turn right for 1 second. But all it actually did was just turn left for 1 second every couple of seconds. I removed the jumper wire connected to pin 8 that is supposed to control the wheels turning left, while the sketch was running and everything worked as expected except the turning left part. it moved forwards for 1 second, moved back for a second, waited at neutral for a second, and then turned right for a second.
When I connected back the jumper wire that controls the car moving left everything stops working again. I am not sure whats wrong, I even connected a multimeter to each pin and found they were pulsing between 0V and 5V as expected but for some reason they weren't moving the car, it was only moving left, in this case at least.
Any help to get this working, ideas to why its not working, or any troubleshooting tips would be greatly appreciated.
Below you can find the code for the sketch, that is supposed to move the car      forwards, backwards, left and right.
const int LEFT = 8;
const int RIGHT = 9;
const int FWD = 10;
const int BWD = 11;

void reset () {
  //Sets all pins to HIGH as the car moves when the pins are grounded.
  //And we want the car to start out by not moving.

  digitalWrite(LEFT, HIGH); //For some reason everything works when I remove this
  digitalWrite(RIGHT, HIGH);
  digitalWrite(FWD, HIGH);
  digitalWrite(BWD, HIGH);
}

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

  pinMode(RIGHT, OUTPUT);
  pinMode(FWD, OUTPUT);
  pinMode(BWD, OUTPUT);
  pinMode(LEFT, OUTPUT);
  reset();
}

void Forward(){

  digitalWrite(FWD, LOW);
  delay(1000);
  digitalWrite(FWD,HIGH);
  delay(1000);
}

void Backward(){
  digitalWrite(BWD, LOW);
  delay(1000);
  digitalWrite(BWD, HIGH);
  delay(1000);
}

void Left(){
  digitalWrite(LEFT, LOW);
  delay(1000);
  digitalWrite(LEFT, HIGH);
  delay(1000);
}

void Right(){
  digitalWrite(RIGHT, LOW);
  delay(1000);
  digitalWrite(RIGHT, HIGH);
  delay(1000);
}

void loop() {

  Forward();
  Backward();
  Left();
  Right();

}

Did you connect the arduino ground to the remote's ground?

What is the voltage across the switches when they are not depressed?  Perhaps your Arduino is getting reset periodically rather than running the entire program.  It could be useful to add some serial output to your program which you could capture to monitor its operation, though connecting to both the computer and the RC transmitter could perhaps cause electrical issues.  Perhaps you could add an LED and resistor (anode to 5v, cathode to signal) to your setup and visually monitor it that way?

Without details of the car's circuitry one can't say with certainty what the problem is.  However, from the description given, one thing sticks out:  The TX-2E spec sheet says to ground a control pin to select a motion.  But besides grounding pins at times, you are also taking them high.
Instead, try leaving pins open when not active, and pulled down for active.  Eg, try code like:
void motion(const int pin) {
  pinMode(FWD, OUTPUT);
  digitalWrite(pin, LOW);
  delay(1000);
  pinMode(pin, INPUT);
  delay(1000);
}
void Forward() {
  motion(FWD);
}
void Backward() {
  motion(BWD);
}
void Left() {
  motion(LEFT);
}
void Right() {
  motion(RIGHT);
}

But is there a reason, this works as opposed to applying a high voltage to the pin when not active?
Some extra info:
The pin when not active and not connected to the Arduino is at around 3.5 V. But when I connect the pin to the Arduino and apply a high voltage to it, the voltage across the pin is about 5 V.
Could this somehow have led to my issue? If so, in what way?
And could it have led to more long term issues if I kept applying 5V to a pin that was used to taking about 3.5 V.
The confusing thing is that it worked properly for all movement except for leftward movement.

I don't really know and haven't thought of a circuit that would work precisely that way, but can  imagine there's some matrix or multiplex circuitry that works when certain combinations are used -- eg, forward and left, or forward and right -- and depends on the left or right contact point being open to let signals flow through.


text:
Driver shield providing 24+ pins at 100mA (for Mega 2560)
Do any shields (or similar boards) exist to let the Mega 2560 (or Due) output a full 100mA per pin on at least 24 pins, in a digital on/off fashion? I know there is a motor shield, but it looks to have only a handful of outputs. It seems very common that people need to output higher current than the MCU can provide safely (if at all), but there do not appear to be any shields for this. Of course individual transistors are fine for a few outputs, and some chips can do up to 8, but what about the rest of us who want to use all those nice pins on the Mega, Due, or similar but who need more power?

You can:

use a driver chip, e.g. ULN2803 which gives you 8 outputs of up to somewhat 500mA from 8 digital pins
use a serially addressible power+logic chip, such as TPIC6A595NE which gives you 8 outputs, each can drive 350mA, and has a built-in short circuit protection. You can cascade these, 3 chips give 24 outputs, and need only three pins to drive all 24 (or more if you use more chips) outputs.
There are 24 output devices, however not in this current range. 24 output devices are usually i2c or spi based led controllers - some of them gives you goodies like rock solid hardware PWM on all 24 ports - but none of them gives you 100mA output.

You'll likely have to use an https://www.arduino.cc/en/Main/ArduinoProtoShield with 3+ of those chips you like that do up to 8.

I was considering that. I see that the board has only one place dedicated for such a chip though. Hence, I would think this would require putting jumpers on all the pins of the 2nd and 3rd chip.


text:
Share battery pack with Arduino and DC motors
I used 6 rechargable AA batteries (total 7.2V) to power my Arduino (UNO R3) Car's two DC Motors (using L293D IC as motor driver). I used separate 9V battery to power arduino itself. But I want to share same 6 battery pack to power my arduino via barrel jack. Please suggest me how can I do this? What precautions Should I take? Like decoupling capacitors or any other?

If you want to operate the uC reliably, then take a switching step down regulator (I usually use the LM2596 modules from ebay, 1€/each, but a lot of them are fine), then push the 5V voltage in the board directly (through the USB connector if you want some protection - e.g. fuse - or directly in the 5V pin if you don't want it)

I have LM317 and LM7805 can I use any of this? @frarugi87

The LM7805 has a 2V dropout, so as soon as the voltage drops under 7V you won't have 5V again. The LM317 has a 3V dropout, so it will not work. Moreover they are linear regulators (they will waste much power, and you don't want this to happen with a battery powered system). Just use a switching regulator (the modules you find on ebay are perfect for your needs)

You may have read that the UNO can accept 7-12 volts as input power. Your AA battery pack (7.2 volts) is very near the low limit of 7 volts. After just a little discharge of the battery (and also voltage drop from motors running), your batteries are likely to deliver less than 7 volts.
As your AA battery goes below 7 volts, then the 5 volts (regulated) will also begin to go lower.  A reasonable scenario would be if AA battery was 6.5 volts (1/2 volt low), then the 5 volts regulated would be about 4.5 volts. The UNO is likely to operate ok at this voltage, but as voltage goes lower operation could become a problem depending upon your program used.
Since you are experimenting with a toy car, I would say to go ahead and run both the motors and UNO from the same battery pack.  Not a lot to lose on trying.
The UNO already has decoupling capacitors in it's 5 volt regulator circuit.
Just for fun,  you could use an Analog input to measure your 5 volts and if the voltage drops to 4.5 volts, you could dis-allow motor operation and flash an LED (or other action). Just a low battery indicator.
If you decide to measure the 5 volts with an analog input,  read up on using resistor dividers and the Analog reference (A-ref). Because 5 volts dropping to 4.5 volts could effect your analog reading, depending upon what you use for Analog reference.

When the motors are running the battery voltage can drop quite a bit too. If the motors allow it, I'd use 8 batteries (9.6 volt) instead.

I like your analog input read up idea. To do so, should I connect arduino 5V pin to any one analog pin directly? Could you tell me more? I also like frarugi87 comments on main quesion. Could you comment on this that which one is the best approach? @marla

@palash he is saying that if you want to measure the battery voltage, you have to use a stable analog reference instead of Vcc, because if the 5V voltage drops to 4.5V your analog reading will raise. So if you want to measure the battery voltage, you can use the internal analog reference (1.1V), then use a voltage divider to lower the 7.2V to around 1V (for instance 82k and 13k). I suggest you to use a PMOS to disconnect this from the battery (otherwise it will consume power)


text:
Both red and blue led of ESP8266 stays on
I've connected ESP8266 to Arduino UNO. After a getting a huge trouble I successfully managed to run some AT commands. I have also tested AP mode.
Then I got some trouble with software serial communication with Arduino and decided to change baud-rate to 9600 (previously it was 115200).
I used AT+IPR=9600 command to change it.
After that blue led of esp stays on and not taking AT commands any more, but output some gibberish to serial monitor with few ascii text like below:
ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x40100000, len 1396, room 16
tail 4
chksum 0x89
load 0x3ffe8000, len 776, room 4
tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4
tail 8
chksum 0xc0
csum 0xc0

2nd boot version : 1.4(b1)
SPI Speed      : 40MHz
SPI Mode       : DIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

Note: I know it consumes a lot power tried external 3.3V power supply and voltage divider for rx pin.
Any help would be appreciated.

I have exactly the same after running that command "AT+IPR=9600".
Any update on how you fixed this?

I fixed this by updating its firmware @rabs

Here I posted what I did to solve this error. I hope somebody finds it helpful: http://bbs.espressif.com/viewtopic.php?t=4597#p15844

If you have too, you can find the firmware for the ESP8266 here and re-flash it.
There's some good info here about the instruction set.
With respect to your issue of the blue (traffic) light staying on, I can't imagine that the baud command would have caused an issue. Perhaps you need to double check your circuit and make sure that the Rx pin of the ESP8266 is not being held high.
What happens with only 3.3V and GND connected to the ESP8266?
Also the output you're getting is similar to the output from “AT+GMR”. Are you sending it that in a loop by chance?

If I only connect 3.3V and GND then only red led stays on (as usual). But if I pull CH_PD to high (connect to 3.3V using a 10K resistor) then blue led stays on. @James


text:
Can you connect ACS712 sensor to digital input of Arduino?
I have a home automation project and am looking to use multiple current sensors (ACS712) for multiple appliances. I just need to know whether current is present or not instead of the current value. Is it possible, that I connect the ACS712 sensor to the digital input of Arduino, and get HIGH or LOW via digitalRead() function. If not, please suggest an alternative to detect ac current is present or not with digital input i.e. HIGH or LOW that can be read via the digitalRead() function.

This has already been asked on EE.SE. You will end up being asked the same questions here; if you don't help us then we cannot help you.

The answers over at EE also suggest that this is not the most appropriate sensor for this purpose.  Given you are detecting AC, note that the ACS712 returns values representing the sine-wave, crossing over at "0", which is 2.5v output from the sensor.  So you could take samples via the Arduino over a short period and detect the peaks in software to determine the total current, but from the answers below and at EE it seems an alternative sensor component, or additional circuit between the ACS and the Arduino would make the most sense if you need to use this particular sensor.

Please do not cross-post the same question on different Stack Exchange sites. See Is cross-posting a question on multiple Stack Exchange sites permitted if the question is on-topic for each site?

I'm voting to close this question as off-topic because posting a question to multiple sites is explicitly prohibited.

Considering an ATMEGA with a 5V VCC we have:
LOW  = < 0.3*VCC = 0,3*5V = 1.5 V
HIGH = > 0.5*VCC = 0,5*5V = 2.5 V

You can connect directly to the Arduino if the output of your sensor is higher than 2.5 volts whether current is present or below 1.5 volts if not. This would translate to HIGH or LOW output from digitalRead() function respectively.
You need to recalculate this values for the 3 volt version of Arduino, probably in this case is better the comparator solution to ensure up to 3 volts max logic level.
Example circuit as follow, just need to set voltage divider to desired threshold (note this is for 5v case),

You should instead use the Peak Detector example from the datasheet; it's designed for AC use and is much more appropriate for a current/no-current output.

The Arduino/AVR (for instance ATmega328p, chap. 22) has an analog comparator (D6/AIN0, D7/AIN1 or any analog pin). This could be used with the correct reference voltage.
Cheers!

It seems like you could do this with a transistor (if "faking" a digital signal from the ACS712 doesn't work). A simple circuit where the VIOUT of the ACS712 drives the base of a switching transistor connected to a digital pin on the Arduino with an internal pull up might do the trick (assuming that the ACS712 give you a voltage on VIOUT that is proportional to the current).

Use a comparator for an adjustable threshold and feed the output into the arduino digital pin.

Can you please expand your answer to include how to do this? What components would the OP need? Thanks!

Your answer would be even more useful if you could include more detail. For example, can you suggest a comparator that would be suitable, or a link to a tutorial that does something similar.

Depending on which Arduino, it already has an analog comparator.


text:
Measuring the distance covered by a car
I am currently working on developing an RC car that is controlled by an Arduino .
I would like to add a function that can calculate the distance covered by the car without using a GPS !
what are the available alternatives ?

The cheap and easy way. Doesn't work all the time though. This method uses an ultrasonic sensor (such as the HC-SR04). You mount it on the car's front bumper and calculate the distance from the car and the wall. Then from the start point, calculate how much distance has been covered. This method is flawed in the way that you cannot do this unless there is a wall in front of the car.
Rotary encoder, put this on the wheel of your robot, then calculate the circonference of the wheels. Then calculate, with the number of rotation made and the circonference of the wheel, the distances that has been made. Some cars use this to calculate the cars speed. It is quite effective.


text:
Attiny85 DigiSpark: Drive 128X64 OLED screen, no picture problem
Devices used
It's about these devices:

Quick scheme (how I connected those)

Got the wiring info from the TinyWire library

Program I use (also many different examples tried but no luck):
#include <Wire.h>

//~ DEFINES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Some defines for the SSD1306 controller driving a 128x64 resolution OLED display
// PART     - http://www.simplelabs.co.in/content/96-blue-i2c-oled-module
// DATASHEET  - https://www.adafruit.com/datasheets/SSD1306.pdf

// The Slave Address (SLA) of the OLED controller - SSD1306 - is 0x3C
// The LSB is supposed to be the mode. Since we are only going to WRITE to the OLED, the LSB is going to be 0
// SLA (0x3C) + WRITE_MODE (0x00) =  0x78 (0b01111000)
#define OLED_I2C_ADDRESS   0x3C

// The SSD1306 datasheet (pg.20) says that a control byte has to be sent before sending a command
// Control byte consists of
// bit 7    : Co   : Continuation bit - If 0, then it assumes all the next bytes are data (no more control bytes).
//        :    You can send a stream of data, ie: gRAM dump - if Co=0
//        :        For Command, you'd prolly wanna set this - one at a time. Hence, Co=1 for commands
//        :    For Data stream, Co=0 :)
// bit 6      : D/C# : Data/Command Selection bit, Data=1/Command=0
// bit [5-0]  : lower 6 bits have to be 0
#define OLED_CONTROL_BYTE_CMD_SINGLE  0x80
#define OLED_CONTROL_BYTE_CMD_STREAM  0x00
#define OLED_CONTROL_BYTE_DATA_STREAM 0x40

// Fundamental commands (pg.28)
#define OLED_CMD_SET_CONTRAST     0x81  // follow with 0x7F
#define OLED_CMD_DISPLAY_RAM      0xA4
#define OLED_CMD_DISPLAY_ALLON      0xA5
#define OLED_CMD_DISPLAY_NORMAL     0xA6
#define OLED_CMD_DISPLAY_INVERTED     0xA7
#define OLED_CMD_DISPLAY_OFF      0xAE
#define OLED_CMD_DISPLAY_ON       0xAF

// Addressing Command Table (pg.30)
#define OLED_CMD_SET_MEMORY_ADDR_MODE 0x20  // follow with 0x00 = HORZ mode = Behave like a KS108 graphic LCD
#define OLED_CMD_SET_COLUMN_RANGE   0x21  // can be used only in HORZ/VERT mode - follow with 0x00 + 0x7F = COL127
#define OLED_CMD_SET_PAGE_RANGE     0x22  // can be used only in HORZ/VERT mode - follow with 0x00 + 0x07 = PAGE7

// Hardware Config (pg.31)
#define OLED_CMD_SET_DISPLAY_START_LINE 0x40
#define OLED_CMD_SET_SEGMENT_REMAP    0xA1
#define OLED_CMD_SET_MUX_RATIO      0xA8  // follow with 0x3F = 64 MUX
#define OLED_CMD_SET_COM_SCAN_MODE    0xC8
#define OLED_CMD_SET_DISPLAY_OFFSET   0xD3  // follow with 0x00
#define OLED_CMD_SET_COM_PIN_MAP    0xDA  // follow with 0x12

// Timing and Driving Scheme (pg.32)
#define OLED_CMD_SET_DISPLAY_CLK_DIV  0xD5  // follow with 0x80
#define OLED_CMD_SET_PRECHARGE      0xD9  // follow with 0x22
#define OLED_CMD_SET_VCOMH_DESELCT    0xDB  // follow with 0x30

// Charge Pump (pg.62)
#define OLED_CMD_SET_CHARGE_PUMP    0x8D  // follow with 0x14

// NOP
#define OLED_CMD_NOP          0xE3

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Box pattern
uint8_t pattern1[] = {
  0x00,0x7E,0x42,0x42,0x42,0x42,0x7E,0x00,
  0x00,0x7E,0x42,0x42,0x42,0x42,0x7E,0x00
  };

// Cross weave pattern
uint8_t pattern2[] = {
  0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81,
  0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81
  };

void setup()   {
  // Init the OLED controller
  OLED_init();
}

void loop() {
  // I2C
  Wire.beginTransmission(OLED_I2C_ADDRESS);
  Wire.write(OLED_CONTROL_BYTE_CMD_STREAM);
  Wire.write(OLED_CMD_SET_COLUMN_RANGE);
  Wire.write(0x00);
  Wire.write(0x7F);
  Wire.write(OLED_CMD_SET_PAGE_RANGE);
  Wire.write(0);
  Wire.write(0x07);
  Wire.endTransmission();

  for(uint16_t i=0;i<1024;i++){
    Wire.beginTransmission(OLED_I2C_ADDRESS);
    Wire.write(OLED_CONTROL_BYTE_DATA_STREAM);
      for (uint8_t x=0; x<16; x++) {
      // Wire.write(0b11000001);
      // Wire.write(0x81);
      // Wire.write(0x02);
      Wire.write(pattern1[x]);
      // Wire.write(pattern2[x]);
      i++;
      }
      i--;
      Wire.endTransmission();
  }

    delay(5000);

}

void OLED_init() {
  // Init the I2C interface (pins A4 and A5 on the Arduino Uno board) in Master Mode.
  Wire.begin();
  // keywords:
  // SEG = COL = segment = column byte data on a page
  // Page = 8 pixel tall row. Has 128 SEGs and 8 COMs
  // COM = row

  // Begin the I2C comm with SSD1306's address (SLA+Write)
  Wire.beginTransmission(OLED_I2C_ADDRESS);

  // Tell the SSD1306 that a command stream is incoming
  Wire.write(OLED_CONTROL_BYTE_CMD_STREAM);

  // Follow instructions on pg.64 of the dataSheet for software configuration of the SSD1306
  // Turn the Display OFF
  Wire.write(OLED_CMD_DISPLAY_OFF);
  // Set mux ration tp select max number of rows - 64
  Wire.write(OLED_CMD_SET_MUX_RATIO);
  Wire.write(0x3F);
  // Set the display offset to 0
  Wire.write(OLED_CMD_SET_DISPLAY_OFFSET);
  Wire.write(0x00);
  // Display start line to 0
  Wire.write(OLED_CMD_SET_DISPLAY_START_LINE);

  // Mirror the x-axis. In case you set it up such that the pins are north.
  // Wire.write(0xA0); - in case pins are south - default
  Wire.write(OLED_CMD_SET_SEGMENT_REMAP);

  // Mirror the y-axis. In case you set it up such that the pins are north.
  // Wire.write(0xC0); - in case pins are south - default
  Wire.write(OLED_CMD_SET_COM_SCAN_MODE);

  // Default - alternate COM pin map
  Wire.write(OLED_CMD_SET_COM_PIN_MAP);
  Wire.write(0x12);
  // set contrast
  Wire.write(OLED_CMD_SET_CONTRAST);
  Wire.write(0x7F);
  // Set display to enable rendering from GDDRAM (Graphic Display Data RAM)
  Wire.write(OLED_CMD_DISPLAY_RAM);
  // Normal mode!
  Wire.write(OLED_CMD_DISPLAY_NORMAL);
  // Default oscillator clock
  Wire.write(OLED_CMD_SET_DISPLAY_CLK_DIV);
  Wire.write(0x80);
  // Enable the charge pump
  Wire.write(OLED_CMD_SET_CHARGE_PUMP);
  Wire.write(0x14);
  // Set precharge cycles to high cap type
  Wire.write(OLED_CMD_SET_PRECHARGE);
  Wire.write(0x22);
  // Set the V_COMH deselect volatage to max
  Wire.write(OLED_CMD_SET_VCOMH_DESELCT);
  Wire.write(0x30);
  // Horizonatal addressing mode - same as the KS108 GLCD
  Wire.write(OLED_CMD_SET_MEMORY_ADDR_MODE);
  Wire.write(0x00);
  // Turn the Display ON
  Wire.write(OLED_CMD_DISPLAY_ON);

  // End the I2C comm with the SSD1306
  Wire.endTransmission();
}

Source: https://github.com/SonalPinto/Arduino_SSD1306_OLED/blob/master/oled_test/oled_test.ino

Other examples I have been tried:

http://www.14core.com/wiring-digispark-attiny85-with-096-oled-screen-display/
http://www.instructables.com/id/ATTiny85-connects-to-I2C-OLED-display-Great-Things/

Question
What could be wrong, do I miss something inhere? Wires seems to be OK, do I use the correct pins (sometimes a little confusing on Attiny85, digital versus analog)? Tried also another OLED_I2C_ADDRESS, 0x3D instead of 0x3C but no luck at all. Tried both screen and both remain black.

Got scope pictures?

Nope, got no scope :-(

With I2C you always need pull up resistors on the data lines, otherwise nothing works.  Normally ones around 4.7K for a Uno, not sure what they should be for a Tiny.
If you are unsure about the I2C address get "I2CScanner" (An Arduino program) and that will tell you.

Ah, this is useful info, thanks! Got no 4,7K resistors but desoldered two from a spare board and guess what..... It works like a charm! Thank you very much for the execellent info. I'm happy, thumbs up!

Hmm not strictly true I've currently got mine working without resistors, and the screens I get often do work without them, for example the Arduino Nano and ESP8266/NodeMCU I have used without resistors.
I had a bit of a pain with this board, the drivers for Windows originaly not working or detecting the board correctly and then the board not seeing the OLED mine is the 128x32 version. I edited the code to reflect the screen size in the DigiSparkOLED.cpp
0xA8, 0x1F,      // Set multiplex ratio(1 to 64)

And change:
0xDA, 0x12,      // Set com pins hardware configuration

To:
0xDA, 0x02,      // Set com pins hardware configuration

Also on several sites it does say to use PINS SCL on P5 and SDA on P2 so if its not working maybe try that pinout. I used the one mentioned above and the I2C scanner is now seeing it on address 0x3C (I wouldn't try changing the address in my experience the pinout will be wrong)
Do your usual checks to see if the screen is drawing power on all lines with a multimeter, also run I2C Scanner program to see if it sees anything and if not then try the alternative pinout.

ESP8266/NodeMCU is another puppy comparing to the Attiny85, Attiny is very basic and limited. However it might work now, it can change when connecting more i2c peripherals or using longer wires. Also the pin versus GPIO naming isn't the same, see also: https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h#L37-L59 . About the display, used a 128x64 oled and it feels very buggy, especially at boot, sometimes it works, sometimes it don't. The ESP8266 is very picky on timing. See my topic on this on stackoveflow when it is using the wire library:

https://stackoverflow.com/questions/48350250/i2c-communication-between-atmega328p-and-esp8266ex-can-only-send-8-bytes-bug