text:
One workspace, two IDEs - Possible?
How can I create a workspace & projects so that either the Arduino IDE or the EclipseArduino IDE may be used to develop the project, interchangeably?
I have both IDEs installed and working but in separate workspaces.
I need:

One workspace that either IDE can understand and work in;
Either to IDE build with the physically same set of library sources;
Whichever IDE I open to see my sources as I last left them, regardless of which IDE I last used.

I want:

The source files to have conventional names - .C or .C++, not .pde or .ino;
Either IDE to build with the physically same set of library object modules;

My use-case is that I work in/with Eclipse, and I teach Arduino skills to people starting out with the Arduino IDE. I'd like to be able to prepare class work at home with Eclipse but open and project it in class with the Arduino IDE. It would be nice if I could demonstrate the two IDEs using the same code. Clearly, I could hack up a demonstration, but I'd rather do it honestly and without sync issues like having to apply twice any changes we made in class.
Update 20 Apr '16:
At @Jantje's suggestion (in the comments below his answer), I created a github issue, "Importing an ArduinoIDE project with the New Sketch Wizard and using same sketch-name, failed." The new sketch would over-write the .ino file with a new, empty sketch.
That issue got fixed in the April 14, 2016 nightly and now works as his answer to this question says it does.

I came across to this issue, but I found out that it is very tricky to use eclipse with some libraries as they dont compile for "not understand it" or "not c standard". One way would be to code with Eclipse and coimpile with Arduino IDE which sounds stupid but... it works

I'm not sure why you want the source files to be named with conventional names (I mean I know exactly why I would want that, but…) – won't that break the compatibility with the Arduino IDE? It occurred to me that if Eclipse uses something like a standard Makefile that you could probably create a rule that would allow you to work with .ino files.

Help me please. I made changes - warnings appear, after I canceled the changes, warnings remain. https://www.youtube.com/watch?v=Y9doeAvnN70

You might find this useful, so I'm sharing here too: I use Eclipse and Sublime Text for editing Arduino code, and I build in the Arduino IDE with it set to "external editor" mode, or using the Arduino Command Line tools. Eclipse has a fantastic indexer and makes understanding the Arduino core much easier. I've written a detailed PDF about using and setting up Eclipse for professional software development, incl for Arduino, here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/eclipse/Eclipse%20setup%20instructions%20on%20a%20new%20Linux%20(or%20other%20OS)%20computer.pdf.

Your requirements for not having .ino files and wanting to be able to work with the Arduino IDE are conflicting. Assume we drop that requirement it is very much possible to do what you want.
The Arduino Eclipse plugin has been supporting .ino files for a long time now. You can simply compile Arduino IDE-made sketches. You do not have to make links and so make the folder where your Arduino IDE makes its sketches the workspace in Eclipse.
In Eclipse, for each sketch you want to edit, start the new sketch wizard and use a project name that is the same as the sketch name in the Arduino IDE.
Now you can work in the Arduino Eclipse plugin and the Arduino IDE on the same files.
Important: In Windows, if you use a version of the plugin from before March 3, 2016, you need to delete the .ino.cpp file before starting the Arduino IDE. In Linux, the Arduino IDE ignores this file, but in 1.6.7 on Windows (just tested it) the file gets picked up by the Arduino IDE. You need to restart the Arduino IDE to tell it the file is gone.
From March 3, 2016 onwards, the code in the .ino.cpp file is inside a #ifdef that is not defined in Arduino IDE.

Thanks, @jantje! Is the the .ino.cpp file an artifact of the Eclipse plugin?

the .ino.cpp is indeed an artifact of the arduino eclipse plugin.

I found that the .ino.cpp is ignored by the arduino ide in linux but not on windows. Making the file hidden in windows (that is what the. stands for in linux) didn't help to hide the file for arduino ide in windows.

"start the new sketch wizard and use a project name that is the same as the sketchname in arduino ide." This fails for me - opeing the ino file in Eclipse, I see an empty sketch template, even though the file on disk has my actual code in it.

If the code is there pressing F5 should make it visible. I may have had a auto refresh workspace when I tested it.

@JRobert. Did you get it to work?

Bottom line: It does, and in fact I just opened ArduinoSE to update this. F5 did not cause any action so I put aside my testing until the next day - and magically, it worked! I don't know why, but I'm glad to have it!

cool, Always nice to hear that it works somewhere else than on your own system:-)

I updated my answer because I provided a fix for windows.Now it works regardless wether Arduino IDE ignores the .ino.cpp file or not.

On Mar 3, I wrote "magically, it worked!". Unfortunately the magic was short lived. I just tried to import an Arduino sketch into Eclipse by wizarding a new sketch over the existing sketch. Eclipse over-wrote the sketch that was there.

I think it is better to make a github issue from this. https://github.com/jantje/arduino-eclipse-plugin/issues

Are you willing / able to work with Xcode? There is a package called embedXcode that enables Arduino development on Macs – I'm just getting up to speed with it, but it does appear to allow you to work either in Xcode or with the Arduino IDE (the .ino file is present and is what you edit in Xcode). In my testing so far it appears that the easiest thing to do is to create a project using Xcode and then you can point the Arduino IDE at the project pretty easily, getting Xcode to pick up a sketch started in the Arduino IDE is currently beyond me.
From the point of view of your students I would think that you'd want to keep the .ino file rather than make them learn about the conventions of C or C++. It would also save you the hassle of somehow managing file names – although you could probably get make to do this for you.
I haven't looked into it at all, but I think you could do something similar with Atom (a quick Google found a blog post called Arduino Development in Atom Editor and an Atom package called nino that is described as a "Toolbelt for Arduino") or Emacs, or for that matter Vim is also like to have some Arduino support.

I want to use Eclipse both to remain platform-agnostic, and because I'm familiar with it. I get the point about using ,INO files, and that alone may make my request unrealistic, or at least require that I change file extensions when I go back and forth. I don't mind that the class see and use the magic that the Arduino IDE otherwise does behind the scenes. Just having the projects accessible by both IDEs would be a huge help.

That makes total sense. Does Eclipse use something like a Makefile, seems like if it did there would be a way to teach it how to handle the .ino file. Or maybe it would be enough to create a symbolic link between the .ino and the matching .cc/.c++.

Symlink is the first thing I though of, too. Or Eclipse can be told to recognize .ino extensions. Makefiles: I'm sure it uses them but it auto-generates them. That's some magic that I'd rather not let out of its box! :)

Wise, very wise.

On further reflection on the IDE's behind-the-scenes processing, I personally prefer the stricter language processing (i.e. no invisible fix-ups). More than "not minding" the class seeing the fixups, I prefer it. They should know what gets done on their behalf and be able to do it for themselves in the real-world. To that end, a switch would be welcome in Eclipse for sure, if not in the IDE as well, to turn off that hand-holding. Most people that stay nvolved will eventually outgrow the basic IDE and will need to know how to write the real language for themselves.


text:
ESP-01 not responding to serial data while programming with esptool.py
I have a Arduino uno board, ESP-01 board and a logic level shifter (bidirectional) and to program the esp module i wired my Arduino and esp like this

Arduino uno(atmega328p removed)  --> level shifter --> ESP-01
5v --> highvolt
3v3 --> lowvolt
TX --> ch1 --> TX
RX --> ch2 --> RX
proper ground connections

but when i click upload the RX pin lights up indicating its receiving data but esp doesn't respond to that when i reset the module while its uploading the compiler throws this
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "C:\Users\TRAJU\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "C:/Users/TRAJU/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 2890, in main
    esp.connect(args.before)
  File "C:/Users/TRAJU/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
the selected serial port _
 does not exist or your board is not connected

It as working fine yesterday and it stopped today :(
Please help and thanks in advance.

I found my problem.
esptool.py uploads the firmware at 115200 baud rate, which my logic level converter couldn't handle.  I found this out after writing this question. I thought of connecting RX and RX directly to the ESP module's RX and TX and it uploaded the program. Maybe I am wrong.  Please, if any one know why this happened I am curios to know.  Thanks in advance. ;)

Please accept this as the soulution, because the question is answered now.

It will take a day or two before you can do that.

Re: "if any one know why this happened", I would put a scope on it an look at the signals, particularly the rising edges because you may have something based roughly on this design.  Questions about that belong more squarely on ASE, though you can probably work it out if my suspicions about the relevance of the appnote happen to be correct.  You should be doing something to address 5V -> 3.3V, rather than nothing in any case.

@timemage if i had a scope i wouldn't post this question at all, i could debug it myself (i wish i had a scope) and ya it says it takes around two days to accept my answer

source: Stack Exchange

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

sort: votes


text:
How to avoid delays in the loop() function?
vI have this functions in my loop() and it publishes temperature reading to Ubidots(an IoT cloud service) using the #include  library but it seems it returns a boolean and so the loop is delayed until a true or false value is return and this takes a while there by slowing  down my loop() function and other functions in it.
Is there a way I can call this function without it having to slow the loop?
#include <math.h>
#include <Wire.h>
#include <Servo.h>
#include <WiFi.h>
#include <Ubidots.h>
#include "rgb_lcd.h"
#include "Timer.h"
//#include <SoftwareSerial.h>

//SoftwareSerial mySerial(11, 10); // RX, TX

char ssid[] = "ROSTALECOM_6916";                                                 //your network SSID (name)
char pass[] = "6PTDFYJD";                                                         //your network password (use for WPA, or use as key for WEP)
String api = "875c4a17d995ce4977bdfc1ace55233fd0591c7ce";                             //your API Key number
String idvari = "567d623a762542205cbc517f";                                          //the number of the Ubidots variable
String ctext = "{\"color\":\"blue\",\"status\":\"active\"}";
Ubidots ubiclient(api);                                                             //with that you call the api with the prefix ubiclient

byte p5[8] = {
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F,
  0x1F
  };

int a;
int temperature;
int B=3975;                  //B value of the thermistor
float resistance;

String readString;
int val;
int hum = 70.35;
unsigned char base = 10;

//Temperature Limits
int maxTemp = 29;
int minTemp = 28.5;

//Declarations
rgb_lcd lcd;
Servo winServo;

//Ubidots timer
Timer t;

void setup()
{
    //Loading character
    lcd.createChar(0, p5);

Serial1.begin(9600);
Serial.begin(9600);
winServo.attach(3);
lcd.begin(16, 2);
//mySerial.begin(9600);

//Start Screen
lcd.print("--SmartGarden--");
for (int i = 0; i < 16; i++)
{
        // scroll one position left:
        lcd.setCursor(i, 1);
        lcd.write((uint8_t)0);
        delay(400);
 }
lcd.clear();
lcd.print("Connecting...");
//connect to  wifi network
boolean response;
int status = WL_IDLE_STATUS;
response = ubiclient.WifiCon(ssid, pass, status, api);
Serial.println(response);

//
t.every(1000, sendToUbi);

}

void readTemp()
{
   a=analogRead(0);
   resistance=(float)(1023-a)*10000/a;
   temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;

   //Send temperature via Bluetooth
   Serial.print(temperature);

   //print temperature to LCD
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("Tmp:");
   lcd.print(temperature);
   //print humidity to LCD
   lcd.setCursor(8,0);
   lcd.print("Hm:");
   lcd.print("50");

   delay(1000);

}
void writeServo()
 {
  if (val != 0)
  {
  //val = map(val, 0, 1023, 0, 180);
  winServo.write(val);
  delay(100);
  }
 }

 void sendToUbi()
 {
 ubiclient.save_value(idvari, String(temperature));                                                  //this function is to post to ubidots and return True or False depending on the connection status
 Serial.println("The sensor value " + String(temperature) + " was sent to Ubidots");                //print the sensor value
 }

void timerMax()
{
  for (int i = 0; i < 60; i++)
  {

   }
   winServo.write(180);
 }

void loop()
{
  //read temperature
  readTemp();

  //Update ubidots timer
   t.update();

  while (Serial1.available()) {
    delay(3);
    char c = Serial1.read();
    readString += c;
  }
  if (readString.length() >0)
    {
      Serial.println(readString);
      delay(15);

       val = readString.toInt();
       if (val != 0)
       {
       //val = map(val, 0, 1023, 0, 180);
        winServo.write(val);
       delay(100);
       readString = "";
       }
       //writeServo();

    if (readString == "1")
       {
        digitalWrite(13, HIGH);
       }
     if (readString == "0")
       {
        digitalWrite(13, LOW);
       }
     readString = "";
  }

  if (temperature >= maxTemp)
  {
    timerMax();

  }

}

Please edit your post and format the code using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you.

Please edit your post and add links to the libraries you are using. Without these libraries it is very hard for anyone else to understand your code.

Please edit your post and remove confidential API tokens. :D

The tokens were all edited and invalid

See How to do multiple things at once

Also related "How and Why to avoid delay()" (see: http://playground.arduino.cc/Code/AvoidDelay)

How to avoid delays in the loop() function?

The question is why all the delays? Is there some logic missing? What are you trying to design?
Using delays is often a sign of an attempt to synchronize with external events. Wait for additional input, etc.
Let us walk through some of them:
void readTemp()
{
   ...
  delay(1000);
}

What is this about? The function does read an analog input BUT then there is a lot of output to Serial and LCD and last this delay. Why?
void writeServo()
{
  ...
 delay(100);
}

Again the same pattern. Now for your question "delays in the loop()".
void loop()
{
   readTemp(); // hidden 1000 ms delay

  while (Serial1.available()) {
    delay(3);
    ...
  }
  if (readString.length() >0)
  {
     ...
     delay(15);
     ...
     if (val != 0)
     {
       winServo.write(val);  // Possible hidden 100 ms delay
       delay(100);
       ...
     }
     ...
}

Consider using some logic instead of the delays. There seem to be a common pattern you are using.

As short reply and a general note, there is the millis() function that will be faster than a delay(). It returns the number of milliseconds since the Arduino board began running the current program. You use maths to check if you've waited long enough.
Like this:
  // check to see if it's time to do something; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // do something after the waiting interval here

   }

Edit: One should also be aware of Interrupts, but be warned they must be used correctly.

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


text:
Use MOSFET to Change Voltage With PWM
Ok so forgive me for being an amateur but I'm having a situation that's driving me nuts.
I have a sensor that I have to cycle between +5VDC and +1.4VDC every 60 seconds. I'm using an ATTiny85 with the 8Mhz internal clock fuse set.
What I was hoping was to use a 2N7000 N-Channel MOSFET to control the cycling of the voltage. So my thought is to have +5VDC on the Drain and a PWM signal on the Gate with the + side of the sensor connected to the Source. I am thinking that using PWM and adjusting the duty cycle on the Gate will allow me to adjust the voltage that is seen at the Source but what I'm seeing is a variation of +1.4VDC @28% duty cycle and +3.6VDC at 100% duty cycle.
I can't figure out why +3.6VDC is the best I can do. The PWM is coming from PB1 on the ATTiny85 and the +5VDC is coming from the main voltage source that also feeds the ATTiny85. The current draw of the sensor is 140mA max.

Ok so I haven't had any luck using a BJT or a single component to perform this voltage change so I started on a different approach using two 1N7000, with one being in an inverter configuration.  My though is the pin from the MCU will go high, which will turn on both FET's, with one supplying 5V and the other sinking to ground.  When the MCU pin goes low, both FET's turn off, which stops the 5V flow and the sink to ground, which then will allow the path through a voltage divider into my sensor at 1.4V.  The issue I am having is the second FET is smoking, and by that I mean the sucker heats up like crazy and one even let the smoke out!  I cannot for the life of me figure out WTF I am missing in this configuration.  Here is the new schematic and Q1 is the FET that is smokin.

Please post a schematic.

Using a N-type transistor as a high-side switch is inefficient unless you have some way of driving the gate above the positive rail. The most you can reasonably expect at the source is the gate voltage minus the gate threshold voltage, VGS(th). The typical threshold voltage of the 2N7000 as given in the datasheet is 2.1V, which means that it is a bit remarkable that you are able to get a voltage as high as you have (5V - 2.1V = 2.9V).
The way to fix this is to switch to a P-type transistor (and flip it around) since its threshold voltage is negative.

Not sure about how the P-Type BJT would fit in there but definitely open to it.  I'm mobile at the moment so don't have access to the schematic but as soon as I can I will upload it.

I added a rough schematic. The heating element is a 33 ohm resistive element in the sensor that needs to cycle between 5V and 1.4V.

@JW52761: Add it to the question, not an answer.

Sorry about that, the mobile client is not very intuitive.  Anyway, it's attached and I'm wondering if I should use an opamp in non-inverting mode with a gain of x3 to enable driving the gate above the +5VDC rail voltage to allow the source to have a full +5VDC on it.
Forgive me if that sounds silly, I am still learning as I go.

@JW52761: You can't drive an op amp above its positive supply. Change the resistor.

The resistor is representative of the sensor's heater and is out of my control.  It's data sheet states the heater's resistance is 31 ohm +/- 3 ohm, so I used R1 in the schematic just for representation.
What needs to happen is the heater needs to run at 5V for 60 seconds, then at 1.4V for 90 seconds, then repeat.  So, I guess the solution would be to increase the supply voltage to +9VDC, which means I have to mess with voltage regulation and such which I haven't messed with yet.

Did I say resistor? I meant transistor, sorry.

I did try a 2N3904 but couldn't get it to change the voltage based on PWM duty cycle.  I looked at a 2N3906 but couldn't figure out how to get it into the circuit.

Ok, so did a slight change on paper that uses a LM7805 for the ATTiny85 and the sensor's +5VDC input.  The input voltage I've moved to +9VDC which will input into the LM7805 and into the positive rail of a LM358 op-amp.  I'm thinking 2.2 ohms for both the Rf and Rg resistors, which should give me a gain of 2x if I'm thinking right.
So by fiddling with the PWM of the ATTiny85 through the non-inverting input of the LM358 I should be able to get the 2N7000 to swing between 1.4VDC and 5VDC, and since the Vgs(th) is between .8 and 2.1 VDC I should have no problem with 1.4VDC.

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


text:
Arduino CAN SPI Configuration problem
I am using an Arduino UNO along with a Cooking Hacks CAN Bus Module and Multiprotocol Radio Shield. The CAN module is connected to the radio shield which is plugged into the Arduino. I got this radio shield keeping future applications in mind where I can combine multiple protocols, for eg. CAN and Bluetooth.
I connected them through an OBD2-DB9 cable to the car's OBD port but noticed that I was not really getting any messages. Well I am getting messages but just:
   -- Constructor Can(uint16_t speed) --
   SPI configured
   The MCP2515 has been successfully reset, configuration mode activated
   Speed=500kps
   -- End Constructor Can(uint16_t speed) --

   Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0
   id: 7FF  rtr: FFFFFFFF => Data in buffer 0

After analysing the connections, I realised that the hardware is probably fine since the continuity between the pins of the cables is fine and the CAN module(MCP2515 + MCP2551) is receiving power and I also checked the voltages at the pins and think they're mostly fine apart from a few pins which I'm not sure about. Which brings me to the software issue. I can see that the SPI is not getting configured properly and the MCP2515 controller doesn't enter configuration mode which means the bit times defined are not being used and hence the controller is not initialising like it should. I even tried manually changing to configuration mode by changing the values of the REQOP bits of the CANCTRL register as opposed to doing a software reset which was how I was doing it initially. Even then, no luck. To verify the SPI connection, I chose a random read/write control register like BFPCTRL and wrote a value to it and then read it back to verify that it matched the values I wrote. However, the value read back is not the same as the value I wrote. Also, the controller only has trouble going into configuration mode. It seems to change to normal and listen only mode without problem since the CANSTAT register displays the correct values for the REQOP bits. I don't understand why the controller has problem entering configuration mode but no problem changing to the other modes. Can anybody help me?
SPI Code:
    bool CAN::begin(uint16_t speed)
    {
    #if (DEBUGMODE ==1 )
    Serial.println("-- Constructor Can(uint16_t speed) --");
    #endif

    //Initialization SPI
    SPI.begin();
    SPI.detachInterrupt();
    SPI.setBitOrder(MSBFIRST);
    // both mode 0 & 3 should work
    SPI.setDataMode(SPI_MODE0);

    //Set the SPI frequency
    SPI.setClockDivider(SPI_CLOCK_DIV4);

    #if (DEBUGMODE==1)
    Serial.println("SPI configured");
    #endif

    //Configure MCP2515 pins
    pinMode(CAN_CS,OUTPUT);
    pinMode(CAN_INT,INPUT);
    digitalWrite(CAN_CS,HIGH);

    writeRegister(BFPCTRL, (1<<B0BFM) | (1<<B1BFM));
    int dat = readRegister(BFPCTRL<<2);
    Serial.println(dat);

    //Software resets MCP2515
    reset();
    delay(100);
    //After the reset, controller enters configuration mode
    dispMode();

When I read back the values of B0BFM and B1BFM bits, they should be 1 but the display says that their values are 0.
   void CAN::writeRegister( char direction, char data )
   {
   //CS low to select the MCP2515
   digitalWrite(CAN_CS,LOW);

  SPI.transfer(SPI_WRITE);
  SPI.transfer(direction);
  SPI.transfer(data);

  //CS line again to release
  digitalWrite(CAN_CS,HIGH);
   }

  char CAN::readRegister(char direction)
  {
  char data;
  //CS low to select the MCP2515
  digitalWrite(CAN_CS,LOW);

  SPI.transfer(SPI_READ);
  SPI.transfer(direction);
  //Read data SPI
  data = SPI.transfer(0xff);

  //CS line again to release
  digitalWrite(CAN_CS,HIGH);
  return data;
  }

Please fix the format and remove extra characters "myCAN.begin(500);  ]"

In SPI protocol you'll need to read the SPI buffer twice because the data you wrote will be read by the IC and the IC will respond to it in the next communication and that's when you know.
Also, by looking at the message, I see that your IC is working fine, but is your CAN bus initialised properly? I'm a FSAE team member and I've faced this issue with the CAN Bus termination resistances and the ODB-II configuration on the Sparkfun CAN Bus shield.
Also, have you tried any other libraries for the CAN Shield? For me the seeedstudio library of their CAN shield worked very well.


text:
error parsing data from server using arduino uno and cc3000 shield
I'm using arduino uno with cc3000 shield and I'm trying to get some sort of data from my server but I only get some of it and the remaining part is delivered after so long, when I send the request I get this:
HTTP/1.1 200 OK.
Date: Sun, 14 Feb 2016 14:00:46 GMT.
Server: Apache.
Last-Modified: Sun, 14 Feb 2016 11:58:31 GMT.
Accept-Ranges: bytes.
Content-Length: 16.
Keep-Alive: timeout=2, max=100.
Connection: Keep-Alive.
Content-Type: application/json.

and the full data should look like this:
HTTP/1.1 200 OK.
Date: Sun, 14 Feb 2016 13:59:26 GMT.
Server: Apache.
Last-Modified: Sun, 14 Feb 2016 11:58:31 GMT.
Accept-Ranges: bytes.
Content-Length: 16.
Keep-Alive: timeout=2, max=100.
Connection: Keep-Alive.
Content-Type: application/json.
{"light": "off"}

the {"light": "off"} part takes too long to get parsed to my code.
I'm using this code:
#include <SPI.h>
#include <SFE_CC3000.h>
#include <SFE_CC3000_Client.h>
#include <ArduinoJson.h>

// Pins
#define CC3000_INT      3   // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN       5   // Can be any digital pin
#define CC3000_CS       10  // Preferred is pin 10 on Uno

// Connection info data lengths
#define IP_ADDR_LEN     4   // Length of IP address in bytes

// Constants
char ap_ssid[] = "xxxxx";                  // SSID of network
char ap_password[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX};          // Password of network
unsigned int ap_security = WLAN_SEC_WEP; // Security of network
unsigned int timeout = 30000;             // Milliseconds

#define SERVER "XXXXX"
#define DIRECTORY      "/esp8266pir/light.json"

const int pin        = 2;
#define IDLE_TIMEOUT_MS  5000

// Global Variables
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
SFE_CC3000_Client client = SFE_CC3000_Client(wifi);

void setup() {

  pinMode(pin, OUTPUT);
  pinMode(pin, HIGH);

  ConnectionInfo connection_info;
  int i;

  // Initialize Serial port
  Serial.begin(115200);
  Serial.println();
  Serial.println("---------------------------");
  Serial.println("SparkFun CC3000 - WebClient");
  Serial.println("---------------------------");

  // Initialize CC3000 (configure SPI communications)
  if ( wifi.init() ) {
    Serial.println("CC3000 initialization complete");
  } else {
    Serial.println("Something went wrong during CC3000 init!");
  }

  // Connect using DHCP
  Serial.print("Connecting to SSID: ");
  Serial.println(ap_ssid);
  if(!wifi.connect(ap_ssid, ap_security, ap_password, timeout)) {
    Serial.println("Error: Could not connect to AP");
  }

  // Gather connection details and print IP address
  if ( !wifi.getConnectionInfo(connection_info) ) {
    Serial.println("Error: Could not obtain connection details");
  } else {
    Serial.print("IP Address: ");
    for (i = 0; i < IP_ADDR_LEN; i++) {
      Serial.print(connection_info.ip_address[i]);
      if ( i < IP_ADDR_LEN - 1 ) {
        Serial.print(".");
      }
    }
    Serial.println();
  }
}

void loop() {
  send_request();
}

void send_request () {

  client.connect(SERVER, 80);
  if (client.connected())
  {
    client.print(F("GET "));
    client.print(DIRECTORY);
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Host: ")); client.print(SERVER); client.print(F("\r\n"));
    client.print(F("Connection: keep-alive\r\n\r\n"));
    client.println();
  }
  else
  {
    Serial.print(F("failed to connect"));
    return;
  }
  // read response
  String section="header";
  unsigned long lastRead = millis();
  while (client.connected()&& (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
    // we’ll parse the HTML body here
    if (section=="header") { // headers..
      Serial.print(".");
      if (line=="\n") { // skips the empty space at the beginning
        section="json";
      }
    }
    else if (section=="json") {  // print the good stuff
      section="ignore";
      String result = line.substring(1);

      // Parse JSON
      int size = result.length() + 1;
      char json[size];
      result.toCharArray(json, size);
      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& json_parsed = jsonBuffer.parseObject(json);
      if (!json_parsed.success())
      {
        Serial.println("parseObject() failed");
        return;
      }

      // Make the decision to turn off or on the LED
      if (strcmp(json_parsed["light"], "on") == 0) {
        digitalWrite(pin, HIGH);
        Serial.println("LED ON");
      }
      else {
        digitalWrite(pin, LOW);
        Serial.println("led off");
      }
    }
  lastRead = millis();
  }
  }
}

and here is my light.json code:
<?php
$light = $_GET['light'];
if($light == "on") {
  $file = fopen("light.json", "w") or die("can't open file");
  fwrite($file, '{"light": "on"}');
  fclose($file);
}
else if ($light == "off") {
  $file = fopen("light.json", "w") or die("can't open file");
  fwrite($file, '{"light": "off"}');
  fclose($file);
}
?>

Turn On
Turn Off

  <?php
    if($light=="on") {
      echo("Turn LED on.");
    }
    else if ($light=="off") {
      echo("Turn LED off.");
    }
    else {
      echo ("Do something.");
    }
  ?>

thanks in advance.
Edit
memory statistics:
Global variables use 1,187 bytes (57%) of dynamic memory, leaving 861 bytes for local variables. Maximum is 2,048 bytes.

Edit
I did some enhancement to my arduino code and used adafruit library but still the server response takes too long to get it (up to 10 seconds).
this is my new code:
/***************************************************
  This is an example for the Adafruit CC3000 Wifi Breakout & Shield

  Designed specifically to work with the Adafruit WiFi products:
  ----> https://www.adafruit.com/products/1469

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Kevin Townsend & Limor Fried & Rick Lesniak for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

/*

This example does a test of the SNTP (Simple Network Time Protocol) client:
* Initialization
* SSID Scan
* AP connection
* DHCP printout
* SNTP time synchronization
* Extract and print current time and date information

*/

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
//#include "utility/NetTime.h"
#include <string.h>
#include "utility/debug.h"

#include <ArduinoJson.h>
#include <TextFinder.h>

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed but DI
Adafruit_CC3000_Client client;
TextFinder finder(client);

#define WLAN_SSID       "XXXXX"   // cannot be longer than 32 characters!
const char WLAN_PASS[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0x00};
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WEP

#define SERVER "XXXXX"
String DIRECTORY   =   "XXXXX";

uint32_t ip;

const int pin        = 2;

/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/
void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(pin, HIGH);
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);

  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }

  /* Optional: Update the Mac Address to a known value */
/*
  uint8_t macAddress[6] = { 0x08, 0x00, 0x28, 0x01, 0x79, 0xB7 };
   if (!cc3000.setMacAddress(macAddress))
   {
     Serial.println(F("Failed trying to update the MAC address"));
     while(1);
   }
*/

  uint16_t firmware = checkFirmwareVersion();
  if (firmware < 0x113) {
    Serial.println(F("Wrong firmware version!"));
    for(;;);
  }

  /* Delete any old connection data on the module */
  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while(1);
  }

  /* Attempt to connect to an access point */
  char *ssid = WLAN_SSID;             /* Max 32 chars */
  Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);

  /* NOTE: Secure connections are not available in 'Tiny' mode! */
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  ip = 0;
  // Try looking up the website's IP address
  Serial.print(SERVER); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(SERVER, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }

  cc3000.printIPdotsRev(ip);

  client = cc3000.connectTCP(ip, 80);
}

void loop()
{
  if(!cc3000.checkConnected())
  {
    cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
    Serial.println("connection was lost but succefully retrieved");
  }
  if(!client.connected())
  {
    client = cc3000.connectTCP(ip, 80);
    Serial.println("client lost connection but succefully retrieved it");
  }

  String request = "GET " + DIRECTORY + " HTTP/1.1\r\n" +
               "Host: " + SERVER + "\r\n" +
               "Connection: keep-alive\r\n\r\n";
  send_request(request);
}

/**************************************************************************/
/*!
    @brief  Tries to read the CC3000's internal firmware patch ID
*/
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;

#ifndef CC3000_TINY_DRIVER
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); Serial.print(F(".")); Serial.println(minor);
    version = major; version <<= 8; version |= minor;
  }
#endif
  return version;
}

void send_request (String request) {
  String req = request;
  if (client.connected())
    {
      client.print(req);
      delay(5);
      client.println();
      delay(5);
    }
    else
    {
      Serial.print(F("failed to connect from loop"));
      return;
    }

  // read response
  while (client.connected()) {
    while (client.available()) {
      if(finder.find("\n\r")){
    int line = finder.getValue();
    Serial.print(line);
      if (line == 1) {
        digitalWrite(pin, HIGH);
        Serial.println("LED ON");
      }
      else {
        digitalWrite(pin, LOW);
        Serial.println("led off");
      }
    }
    }
  }
  client.close();
}

can somene tell me how to reduce this delay time?

Do you have some build statistics? How much memory is available?


text:
arduino mega overheat when connected to TFT 7" and TFT shield
I have bought a 7" LCD (TFT01-7) and a shield to make it work with arduino mega (http://www.elecfreaks.com/store/lcd-tft01-mega-shield-v10-p-214.html), but when I upload my code to the arduino and plug my LCD to the shield the arduino get overheated and the LCD lose power and I don't know why even when I power my arduino with external 9V 2A adapter, I even tried uploading an example from the library but it does the same, I used to work with the same code and the same shield but with 5" LCD ITDB50 and I didn't have this problem before, how can I fix this?

What is powering the mega?

an external adapter (9V,2A)

7" LCDs need a lot of current. They need it for the back light.
That current comes from the 5V pin.  That 5V pin is supplied by a linear regulator that has limited current capacity.  As you draw more current it gets hotter and hotter and eventually shuts down.
You will need to power your LCD screen with another external 5V source. The best solution may be a powerful (2A) phone charger (USB) which you then plug direct into the USB port of the board thus bypassing the weak regulator.

So can I connect my lcd to the shield and connect the 5V pin to external power source and then connect the ground pin to the external source ground and make it common with the arduino ground?

Yep. That's right. As long as it is a regulated 5V power source.

Sorry for the late reply (I was buying some components), I did try what you said, I connected my LCD to the shield and connected it to arduino through jumpers, except for the (3.3V, 5V, ground, Vin) pins wich happen to be the power pins on the shield, I connected them to external (5V 1.5A) usb adapter, I think that the LCD is stable now but I only get the backlight on...I can't see my code, it doesn't draw anything.

Is the ground connected to both the Arduino and the external power supply?

I'm connecting Vin on the arduino board to 5V and whenever I take it off the LCD starts blinking, and I do connect the corresponding pin to Vin on the shield to 5v, I'm also connecting both the ground pins on the arduino and the corresponding pins to the on the shield to the ground of the 5V power source, the 3.3V corresponding pin on the shield is connected through a level shifter that I made of 10k and 20k resistors and connected them to the 5V adapter and finally the RST pin is connected to it's corresponding on the shield

the 3.3V corresponding pin on the shield is connected through a level shifter that I made of 10k and 20k resistors - that is doomed to failure. You cannot translate power that way, only very very tiny signals.

Ok, I moved it back to the arduino 3.3V pin but still nothing happens.

Please provide a picture or drawing of how you have it wired up at the moment. It is not clear from your description.

please check the edit that I did to my question


text:
Arduino digital output pin controling relay problem
I try my code to change the state of a relay on pushing a push button buy checking the state of a digital pin.
My code :
const int led1 = 6;
const int enable1 = 7;
boolean led1_OnOff;
long now;
int minSecsBetweenUpdates = 1; // 1 seconds
long lastSend = -minSecsBetweenUpdates * 1000l;

void setup() {
  led1_OnOff = false;
  pinMode(enable1, INPUT);
  pinMode(led1, OUTPUT);
}

void loop() {
  now = millis();
  if (now > (lastSend + minSecsBetweenUpdates * 1000l))
  {
    if(digitalRead(enable1) == HIGH)
    {
      lastSend = now;
      if(led1_OnOff == true)
      {
        led1_OnOff = false;
        //+digitalWrite(led1, LOW);
      }
      else
      {
        led1_OnOff = true;
        //digitalWrite(led1, HIGH);
      }
    }
  }

  if(led1_OnOff == true)
    digitalWrite(led1, HIGH);
  else
    digitalWrite(led1, LOW);
}

But the code keeps on looping and the relay keep changing it's state as if pin 7 is always high, I'm sure of my schematic but I don't know what's wrong with my code.
for those who want my schematic:

Did you wired pin 7? If it was floating, it will read as HIGH (mostly) and LOW sometimes. BTW your interval checking is incorrect, it doesn't work when value is expected to overflow (somewhere at 49th day). Checking the elapsed time (subtracted difference) with period value will work OK.

Perhaps you should post your wiring diagram for bigger chance to get a proper answer

Possible duplicate of Error while trying to drive relay through the state of a digital input pin in Arduino

Did the code I gave you for your practically identical question yesterday help?

no it didn't, my code was working but suddenly it has gone crazy, I even tried your code but it keeps on looping like enable1 is always high

What makes you sure your wiring is correct?

Your problem is that you are basically saying "while the pin is HIGH toggle the relay" rather than "When, and only when, the pin transitions from LOW to HIGH do I toggle the relay".
To do that you must remember what state the pin was in during the last iteration:
const uint8_t led1 = 6;
const uint8_t enable1 = 7;

void setup() {
    pinMode(enable1, INPUT);
    pinMode(led1, OUTPUT);
}

void loop() {
    static bool led1_OnOff = false;
    static bool lastValue = digitalRead(enable1);

    bool currentValue = digitalRead(enable1);

    if (currentValue != lastValue) {
        lastValue = currentValue;
        if (currentValue == HIGH) {
            led1_OnOff = !led1_OnOff;
            digitalWrite(led1, led1_OnOff);
        }
    }
}

I tried that but I have the same problem, always keeps looping like crazy and only stops looping when I hit the push button

How have you wired up the pushbutton?

It's not a small push button for arduino, it's a normal lighting AC push button, I user one side for pin 7 and the other for 5V

So no pulldown resistor? No wonder it's spazzing out - the pin is floating until you press the button and connect it to a signal of some form. Read the basic Arduino button tutorial: https://www.arduino.cc/en/Tutorial/Button

that was the problem, thanks for pointing it out...I didn't know I had to use a resistor for the AC standard push button like the arduino small push button.

A button is just a button - two metal contacts that get pressed together. Regardless of if it's for AC, DC, high voltage, low voltage, momentary, toggle, rocker, whatever. That is all they are - just two metal contacts that press together.

It now works but if I keep pushing the push button it keeps changing the relay state every one second (my pre-defined time interval), I want it to keep it's state if I keep pushing the push button and only change it if I take my hands of it and pushed it again, can you help?

Which code are you using - your original code, or my code I posted above?

my original code, I tried yours but it's not working, the delay that I add keeps it steadier but if I keep pushing the pushing button it keeps looping and changing the state of the relay every second

In what way does my code not work?

please check this link

You say your switch is between pin 7 and +5v.  Therefore you will need a pull-down resistor on pin 7.
You say that setting pin 7 to an output works.  However you are very likely to burn out the output like this.  A pull-down resistor is the way to go.

no it's connected to 5V and pin 7...I think I solved it by setting enable1 pin to OUTPUT in the setup() loop and forcing it to start at low state by calling digitalWrite(enable1, LOW);

In that case, you will need a pull DOWN resistor.

no that's only what I did, when I set enable1 to output it goes crazy but when I set it to input it's fine.

`void setup() {
led1_OnOff = false;
pinMode(enable1, OUTPUT);
digitalWrite(enable1, LOW);
pinMode(led1, OUTPUT);
}
void loop() {
now = millis();
if (now > (lastSend + 1000))
{
if(digitalRead(enable1) == HIGH)
{
lastSend = now;
if(led1_OnOff == true)
led1_OnOff = false;
else
led1_OnOff = true;
}
}
if(led1_OnOff == true)
digitalWrite(led1, HIGH);
else
digitalWrite(led1, LOW);
}`

OK, I understand what's happening now. Answer updated. You'll blow up your Arduino if you do it like that.

It now works but if I keep pushing the push button it keeps changing the relay state every one second (my pre-defined time interval), I want it to keep it's state if I keep pushing the push button and only change it if I take my hands of it and pushed it again, can you help?

Are you using either my, or @Majenko's, method for detecting when you release the button?

I used both but they both don't work so I'm using mine which is steadier if I push the push button and let go, but if I keep pushing it keeps looping.

Then I think you have another, as yet undiscovered, problem. Both methods should work.

I haven't added anything else except that I added a pull down transistor between pin 7 and ground.

My point stands.  Your solution may be sufficient for you, which is fine, but there is an undiscovered problem, otherwise it would work perfectly.  Perhaps it's interference on that cable - you could try moving the switch right next to the Arduino.

please check this link

What you have there is a cludge to avoid addressing the real problem. If you're happy with that, OK, but know that's what it is.  Also, if you want to encourage people to help you further, consider at least up-voting, or better accepting, helpful answers.

I did up-vote your answer but they said it will be considered as I don't have enough reputation to up-vote you directly...beside, what is wrong with my code?, it's the one that I tried actually and did work for me, It's not a competition here, and I didn't ask this question to have more reputation, I did ask this question to have help and you did help but your code doesn't work for me, that doesn't mean that I'm better, it just means that I found a code that is more suitable for me...thanks for your help and thanks for your understanding.


text:
How to get Type name of a variable on Arduino
I found this post and implemented the code in a separate classed and then passed different variables to it in an attempt to get the type name printed to serial.
The code compiled and worked fine but i get the following strange output:
For type int I get Fn on the serial monitor
For String I get ;y on the serial monitor

If I don't make a type using MAKE_TYPE_INFO(type) then try TYPE_NAME() I don't get unknown printed on the serial monitor. I get fÝ.
All this weirdness is consistent and I could use it to make decisions based on type but why do that if their is a solution.

Can you show us your full code? The example you link to works fine for me.

Also, are you sure you don't just have the wrong baud rate selected?

I could use it to make decisions based on type - why do you even need to?


text:
Atmega32 push button library problem
I have two files, the first file is a library that I use to handle push buttons and initialize it and the second is where I handle my code and change LED state when push button is pressed, but my code doesn't work, I'm using Atmega32A micro-controller.
my library code:
#ifndef ButtonLibrary
#define ButtonLibrary

#ifndef numberOfButtons
#define numberOfButtons 2
#endif

#ifndef bit_is_clear
#define bit_is_clear(sfr, bit)   (!(_SFR_BYTE(sfr) & _BV(bit)))
#endif

#include <avr/io.h>

char ButtonPressed(int buttonnumber, unsigned char pinofbutton, unsigned char portbit, int confidencelevel);
void initialize_button(int pinofbutton, unsigned char port, unsigned char datadirection);
void initialize_led(int pinofled, unsigned char port, unsigned char datadirection);
void change_led_state(int pinofled, unsigned char port);

char pressed[numberOfButtons];
int pressed_confidence_level[numberOfButtons];
int released_confidence_level[numberOfButtons];

void initialize_button(int pinofbutton, unsigned char port, unsigned char datadirection)
{
    datadirection &= ~(1 << pinofbutton);
    port |= 1 << pinofbutton;
}

void initialize_led(int pinofled, unsigned char port, unsigned char datadirection)
{
    datadirection |= 1 << pinofled;
    port &= ~(1 << pinofled);
}

void change_led_state(int pinofled, unsigned char port)
{
    port ^= (1 << pinofled);
}

char ButtonPressed(int buttonnumber, unsigned char pinofbutton, unsigned char portbit, int confidencelevel)
{
    if(bit_is_clear(pinofbutton, portbit))
    {
        pressed_confidence_level[buttonnumber] ++;
        released_confidence_level[buttonnumber] = 0;
        if(pressed_confidence_level[buttonnumber] > confidencelevel)
        {
            if(pressed[buttonnumber] ==0)
            {
                pressed[buttonnumber] = 1;
                return 1;
            }
            pressed_confidence_level[buttonnumber] = 0;
        }
    }
    //button isn't pressed
    else
    {
        released_confidence_level[buttonnumber] ++;
        pressed_confidence_level[buttonnumber] = 0;

        if(released_confidence_level[buttonnumber] > confidencelevel)
        {
            pressed[buttonnumber] = 0;
            released_confidence_level[buttonnumber] = 0;
        }
    }
    return 0;
}
#endif

my main code:
#define F_CPU 1000000UL

#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include "ButtonLibrary.h"

int main(void)
{
    initialize_button(PIND4, PORTD, DDRD);
    initialize_button(PIND3, PORTD, DDRD);
    initialize_led(PINC7, PORTC, DDRC);
    initialize_led(PINC6, PORTC, DDRC);

    while(1)
    {
        if(ButtonPressed(0, PIND, 3, 500) == 1)
        {
            change_led_state(PINC6, PORTC);
        }
        if(ButtonPressed(1, PIND, 4, 500) == 1)
        {
            change_led_state(PINC7, PORTC);
        }
    }
}

when I press the push button nothing happens, I think there is something wrong in my initialize functions or change_led_state function but I don't know it.

Have you tried adding trace (serial prints for example) to see where it is going wrong?

I'm not using serial in my project, I'm sort of still learning.

Try adding some sort of trace - anything which lets you know what's going on. It could be serial prints, or lighting an LED, or anything which is convenient. You will hit a problem sooner or later which you can't solve by looking at the code.


text:
I just fried my Arduino on a breadboard. Can I still use the breadboard?
So, I just fried my arduino nano on a breadboard. Can I still use the breadboard and usb cable?

If the breadboard failed from over current, there's a good chance you will see visible heat damage to the encapsulating plastic.

"Is this broken."
Well, does it still work?
It's hard for us to tell if something is working or not, we can't see the situation. If you want a definitive answer, you should try it out.
If plugging in the USB cable doesn't pop-up a "over current" message on your PC, you can safely plug it into a new Arduino.
If you can program the Arduino, it's still working.
For the breadboard, you'll have to check if there are no "shorts" where they shouldn't be.

Did you friend it or fry it?

It really depends on the circumstances around its demise. If it went out in smoke and flames, maybe not. Assuming the chip quietly overheated and died, the breadboard and the cable are almost certainly ok. Either of them will stand more abuse than the chip will. What was the cause of failure?

I think I short circuited it. The nano went up in smoke and I quickly turned off the power. I'm new to arduinos, so I was also wondering if 2$ breadboards from online will work just as well? Thank you :)

@Ethan get a continuity tester and test the pins that you use that burnt out the Arduino. If you are certain some don't work, then yea get a new breadboard or live without using some of the breadboard pins.

The differences I've found between breadboards is the quality of the internal connector system. If the maker didn't hold the tolerances closely enough, it can be difficult to push wires into them the first few times (and conversely, I suppose - some could be too loose). I had one that wasn't quite flat on the bottom. These are really simple devices; it's hard to screw them up, even though a few knock-off makers try. :)

you can test the breadboard if you have a multimeter. Even if you don't, you can place an LED, a resistor and a power source across the suspect portions of the breadboard. If you locate a trace or two that appear unreliable, you should be able to mark them appropriately and continue to use the board.

What about the usb cable?

If you're asking about the health of the USB cable, you can also test it with a multimeter or simply by connecting to your computer something that uses USB. The amount of current that passed into your breadboard to destroy the chip is likely of short enough duration to not have damaged the USB cable. I expect also that the breadboard is undamaged.


text:
Error compiling to ESP32 using Arduino: Operand 2 of 'l32r' has out of range value
I was trying to follow this tutorial and ran into a problem compiling on the Arduino IDE with an ESP32 board. https://eloquentarduino.github.io/2019/12/how-to-do-gesture-identification-on-arduino/
I end up getting multiple lines of error from Arduino saying:
Error: operand 2 of 'l32r' has out of range value '4294704916'

The code that its struggling to compile is the converted SVM model generated from SciPy. The file is very long, but here is a snippet of what it looks like:
#include "model.h"
#include <cstdarg>

int SVM::predict(float *x) {
    float kernels[92] = { 0 };
    float decisions[21] = { 0 };
    int votes[7] = { 0 };
    kernels[0] = compute_kernel(x,   1.2  , -1.79  , -1.1  , 1.22  , -1.36  , 0.26  , 1.0  , -1.57  , -0.81  , 1.08  , -1.45  , -0.18  , 1.18  , -1.77  , -0.31  , 1.59  , -1.69  , 0.55  , 6.74  , 0.71  , -13.06  , 6.31  , 12.0  , -4.34  , 1.55  , -0.16  , 0.0  , 1.38  , 1.91  , 1.02  , 0.96  , -2.28  , -0.45  , 1.3  , -2.12  , -0.49  , 0.83  , -0.18  , -0.79  , 0.92  , -0.73  , 1.34  , 2.59  , -4.15  , -3.4  , 2.22  , -0.2  , 1.41  , 0.61  , -3.91  , -1.39  , 9.29  , 1.85  , -16.0  , 2.4  , -1.02  , -0.75  , 1.87  , 0.18  , 0.47  , 1.38  , -2.06  , 0.06  , 1.32  , -2.16  , 0.1  , 1.63  , -2.2  , -0.16  , 1.47  , -1.49  , -0.08  , 0.98  , -1.51  , -0.55  , 1.3  , -1.53  , -0.12  , 1.32  , -1.61  , -0.47  , 1.18  , -1.26  , -0.2  , 1.43  , -1.06  , 0.06  , 1.3  , -1.18  , -0.59  , 0.94  , -0.1  , 1.04  , 1.28  , -1.41  , -0.55  , 1.26  , -1.3  , -0.18  , 1.28  , -1.65  , -0.39  , 1.26  , -1.36  , 0.63  , 1.45  , -1.45  , -0.57  , 1.65  , -1.32  , -0.63  , 1.3  , -1.28  , -0.35  , 1.22  , -1.3  , -0.31  , 1.22  , -1.02  , 0.16  , 1.12  , -1.43  , -0.39  , 1.1  , -0.96  , 0.43  , 0.92  , -1.12  , -0.37  , 1.24  , -0.86  , 0.0  , 1.1  , -1.12  , -0.24  , 1.12  , -1.34  , -0.2  , 1.16  , -1.14  , -0.1  , 1.14  , -1.12  , -0.24  , 1.24  , -1.1  , -0.26  , 1.16  , -1.39  , -0.24 );
    kernels[1] = compute_kernel(x,   1.1  , 0.24  , 9.49  , -11.73  , -9.12  , 9.63  , -2.5  , -5.48  , 1.87  , 1.53  , -1.14  , 0.96  , 0.79  , -1.96  , -0.75  , 0.55  , -1.61  , -1.39  , 1.41  , -1.91  , -0.57  , 0.88  , -2.1  , 0.2  , 0.29  , -2.22  , 0.73  , 1.69  , 0.45  , -0.14  , 2.08  , -1.89  , 1.0  , 1.16  , 0.84  , 1.59  , 1.45  , -2.36  , -0.83  , 2.36  , -0.71  , 0.61  , -9.51  , -16.0  , 6.13  , 2.61  , 1.18  , 0.77  , 0.69  , 0.63  , -0.96  , 1.0  , -0.67  , -0.02  , 1.57  , -1.08  , 0.2  , 1.14  , -1.47  , -0.08  , 1.57  , -1.93  , -0.22  , 1.18  , -1.36  , -0.57  , 1.57  , -1.39  , 0.71  , 1.16  , -1.55  , -0.65  , 1.04  , -1.12  , -0.77  , 1.55  , -2.12  , 0.67  , 1.57  , -0.86  , -0.75  , 1.41  , -1.2  , 0.53  , 1.55  , -1.39  , -0.83  , 1.32  , -0.75  , 0.59  , 1.67  , -1.49  , -0.55  , 1.65  , -1.51  , -0.49  , 1.36  , -1.16  , -0.02  , 1.63  , -1.22  , -0.35  , 1.49  , -1.2  , -0.26  , 1.38  , -1.32  , -0.02  , 1.39  , -1.22  , -0.12  , 1.41  , -1.0  , -0.1  , 1.43  , -1.18  , -0.14  , 1.41  , -1.22  , -0.02  , 1.55  , -1.3  , -0.33  , 1.45  , -1.2  , -0.24  , 1.38  , -1.3  , -0.26  , 1.38  , -1.28  , -0.12  , 1.3  , -1.06  , -0.12  , 1.39  , -1.32  , -0.2  , 1.39  , -1.22  , -0.18  , 1.43  , -1.1  , -0.24  , 1.43  , -1.32  , -0.33  , 1.45  , -1.08  , -0.37 );
    kernels[2] = compute_kernel(x,   1.55  , -1.67  , -2.16  , 1.59  , -0.04  , 1.16  , 1.38  , -2.71  , -1.06  , 2.04  , 1.41  , 1.49  , 1.16  , -0.67  , 6.66  , 0.79  , -7.94  , 8.51  , 2.4  , -0.41  , 2.32  , 1.45  , -0.37  , 0.0  , 1.61  , -1.67  , -0.28  , 2.04  , -0.96  , -0.57  , 1.04  , -0.83  , 0.61  , 1.38  , -1.08  , -0.33  , 1.65  , -0.24  , -1.96  , 2.06  , -2.99  , -0.92  , 8.31  , 4.83  , 2.3  , 4.79  , -3.89  , -5.38  , 0.67  , -2.67  , 1.2  , 3.03  , 1.41  , -0.86  , 2.36  , -1.85  , -1.32  , 2.32  , -1.32  , 0.75  , 1.69  , -1.2  , -0.35  , 1.28  , -1.04  , 0.22  , 1.28  , -1.12  , -0.37  , 1.87  , -1.14  , 0.33  , 1.83  , -1.24  , -0.26  , 1.77  , -0.94  , -0.51  , 1.63  , -0.79  , 0.22  , 1.47
//and so on
decisions[0] = 1.245222806707
    + kernels[1] * 0.00090445776
    + kernels[2] * 0.000488112628
    + kernels[8] * 0.000123322494
//and so on

I have the following flags enabled on the compiler:
compiler.c.extra_flags=-mlongcalls -mtext-section-literals

It just won't compile for some reason and gives me the same l32r message. Can someone please help? Much is appreciated.

May be related: https://github.com/espressif/esp-idf/issues/3258

do you have the flags on cpp and S too?

@Juraj yes the flags are enabled on both

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


text:
Does an Arduino get worn out by too much command execution?
Excuse me if it is a silly question, but I couldn't find an answer.
I've been wondering for a while whether an Arduino (or generally any other micro-controller) gets happy if the code is light and it does not have to execute too much operations. Does a code that has too many ifs, too many loops and all sort of complicated calculations wear out an Arduino sooner than a code that just blinks an LED?

Also see linked questions ....

No, the code doesn't "wear out" the MCU. In general no matter what you are doing roughly the same level of activity is being performed. Even delay() does lots of work while it's "idling".
There are commands to make the CPU do less - place it in an IDLE or SLEEP mode - but these are used to save power rather than to reduce "wear" on the MCU.
Of course there are specific things that do have a limited lifetime and you can only use them a limited amount of times - things like writing to EEPROM and writing to the Flash memory - so you don't want to be doing those all the time. Other than that, no, no matter what you are doing it doesn't wear the MCU out.

But all semiconductos age, don't they? hot carrier injection and bias temperature instability are the mechanisms I remember. Of course it would take many many years.

@MV. Yes, but what you run on the microcontroller doesn't really affect it. Whatever you are doing you are running the CPU at (roughly) the same level. You're using all of it (pretty much) all of the time.

Won't code indirectly influence generated heat? Hot components could wear down faster.

Only a very tiny tiny amount. Even when doing 'nothing' it is working hard and processing.

Thank you for your reply. Now I can lean back and write codes as complex as I want and do not worry about life span of my Arduino! But is it also the case for constantly interacting with external components? Reading sensors, SPI communication and so on?

You can very quickly ruin your EEPROM if you write to it aggressively. To make life a little easier, AVRC provides dedicated update commands which only perform the write if the value has changed, which has many use-cases (e.g. a regularly written but rarely changed status code), but is no silver bullet. I believe EEPROM fails on a byte or word level, so you can work around this to some extent if you must.

@Mast It only makes a difference when parts of the system are actually powered-off when not in use - that's actually quite a complex thing to do, especially while taking latency into account (it takes a while to power things on - e.g. Intel Skylake takes about 70 clock cycles to enable the whole AVX). Checking what helps is easy enough - just measure how much power is being consumed; that's pretty much how much heat is being generated. Also, consider total energy use, not just power - e.g. slower code taking more time while saving power might be less efficient that faster code for a task.

It's not. Well, it might slowly wear out if you run it like 20 years....(like most other physical products)? At least it does not rely on code complexity but how many writing operation done in the same memory section. Moreover, when it wear out it will just get bricked and it won't become a simpler code like blinking the LED.
An Arduino (Uno) has three memory parts. SRAM, FLASH, and EEPROM. SRAM is more like a logical transistor gate. It won't wear out by storing variables. FLASH and EEPROM consist of floating gates. They slowly wear out when you write new data. From the datasheet of Ateml microcontroller, it states:

The Flash memory has an endurance of at least 10,000 write/erase cycles.  (From Chapter 8.2)
The EEPROM has an endurance of at least 100,000 write/erase cycles.  (From Chapter 8.4)

However, FLASH memory is a space for code execution. Writing operation is not be done while Arduino is running. You only write FLASH memory when you upload a new code. So it will wear out when you upload code at least 10,000 times.
If you really want you can make a special code to self-reprogram FLASH memory usually for the purpose of keeping variable data when Arduino is turned off. When you write this kind of program it will wear out slowly because FLASH memory doesn't have much writing endurance. That's why you will be suggested to use EEPROM which has much more life expectancy, if you want to keep data even when Arduino is turned off.
To sum up, it will wear out by re-writing FLASH or EEPROM memory, not by code execution.

For a hobbyist:
About the only life limiting software related issue might be writing to the FLASH memory as fast as you can from inside a program.  But few programs make use of variables that need to survive events like changing batteries.
About the only life limiting hardware related issue is over loading the outputs with low resistance loads (incandescent light bulbs), inductive loads (like directly driving mechanical relays) to name just two.  But the question is only about software.

... (or generally any other micro-controller) ...

The other answers are great, but there is one small exception.
Ferroelectric RAM (FRAM) is a form of memory that combines the non-volatility of flash and EEPROM, the writability of SRAM, and the density of DRAM.
However, read operations on FRAM are destructive to the data stored in the FRAM, and write operations are destructive to the FRAM construction itself (and since the data is destroyed by reading it, it must be written back each time). If your code is located in FRAM then running it will wear down the MCU in time. But given that FRAM has a write endurance in the millions of billions it is unlikely that the MCU will become inoperable due to FRAM in the lifetime of the device.
Examples of MCUs that use FRAM include TI's MSP430FRxx line.

In general if there is FRAM there is no other memory. Not even flash.

Probably not ... The Atmel chip might get warmer over time (even a delay does not prevent this), however if it has a possibility to release its heat I don't see a problem. But mostly only overclocking can cause really serious problems, or using the Arduino in a fully closed box or in a hot environment.
In comparison: many computers are running for years without switching off, the Atmel (chip) is in that sense no difference, as long as generated heat can be relieved.
You can read more about a heat sensor in Atmels here: Internal Temperature Sensor

The way Arduino implements delay, is by constantly checking if enough time has passed. So running a program, or having a delay uses the same amount of processing power.

I will update (remove) that part ... thanks!

There is a difference - most computers today have tons of power saving features; a lot of things power off when not needed, and this happens pretty much automatically. The Arduino also has ways to reduce power use, but you need to use them explicitly. If you need something that is powered-down most of the time, https://learn.sparkfun.com/tutorials/reducing-arduino-power-consumption is a great way to start. In particular, the lowpower sleep drops power consumption about a thousandfold - unlike delay, which just spins the CPU. This has its cost, of course :)

authors: Никита Сммрнов


text:
How can you reduce the clock frequency of an Arduino Mega?
I'm trying to debug a problem and need to reduce the speed of the clock on my Arduino Mega from 16MHz to 8MHz.
I can't find any simple way of doing so, so I wanted to know if there were any gurus here who knew if this was possible, as well as how to do it.
WITHOUT PRESCALER:
long int runTime;

void setup()
{
  Serial.begin(9600);     //Setting the data transfer rate
}

void loop()
{
  delay(1000);
  runTime = millis();
  Serial.print("Runetime: ");
  Serial.println(runTime);
  delay(100);
  exit(0);
}

OUTPUT: 999

WITH PRESCALER:
long int runTime;

void setup()
{
  Serial.begin(19200);   //Setting the data transfer rate for when CLK Freq. is Halfed

  CLKPR = _BV(CLKPCE);  // enable change of the clock prescaler
  CLKPR = _BV(CLKPS0);  // divide frequency by 2
}

void loop()
{
  delay(1000);
  runTime = millis();
  Serial.print("Runetime: ");
  Serial.println(runTime);
  delay(100);
  exit(0);
}

OUTPUT: 999

In your test code, you should put the changing of the clock prescaler between noInterrupts() and interrupts(). Otherwise there is a small possibility of this failing. Also, your test only proves the clocks of delay() and millis() have changed consistently. Which is to be expected since it's the very same clock.

So how can I test if the clock is in fact running at 8MHz instead of 16MHz?

The only way to test a clock is to compare it with another clock. This other clock could be your own sense of time (that's how the test in my answer works), or the UART at the other end of the serial connection (that's how you own program, with 19200 bps nominal and 9600 bps actual baud rate, is actually a valid test). High end solution: hook a GPS with a 1PPS output to your Arduino. Low end solution: program the watchdog, which has its own independent clock, to generate periodic interrupts.

You can set the clock prescaler for that:
void setup() {
    noInterrupts();
    CLKPR = _BV(CLKPCE);  // enable change of the clock prescaler
    CLKPR = _BV(CLKPS0);  // divide frequency by 2
    interrupts();
}

This is explained in section 10.12 and 10.13 of the
ATmega2560
datasheet.
Of course, changing the clock frequency will mess with the time-related
function (millis(), delay() and co.) and the baud rate of the serial
port.
Edit: Here is a small program to demonstrate the slowing of the
clock:
//#define SLOW_CLOCK

void setup()
{
#ifdef SLOW_CLOCK
    noInterrupts();
    CLKPR = _BV(CLKPCE);  // enable change of the clock prescaler
    CLKPR = _BV(CLKPS0);  // divide frequency by 2
    interrupts();
#endif
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
}

This makes the LED flash at 1 Hz. If you uncomment the line
#define SLOW_CLOCK, it instead flashes at 0.5 Hz.

So when I added that I got a bunch of random symbols (i.e. †fæ†žf) and I'm not sure why. Are the setting different for an Arduino Mega?

Note that delay(1000); will now take 2 seconds, instead of 1.

You should also half the baud rate of your serial console, or double the baudrate in Serial.begin().

I wrote some test code and there didn't seem to be any change. Is this what @EdgarBonet  was talking about? Am I not supposed to see a difference in the output of millis()? is so then is there another way for me to test if it's working.

@IsabelAlphonse: What test did you do? The wacky symbols on the serial port kind of prove that the baud rate was unintentionally changed.

@EdgarBonet I added the test code to the console. I'm not getting wacky symbols anymore. I just get the same value for runtime which confuses me because I thought this would make one of them smaller.


text:
Best way to protect a digital output?
I am looking for a way to protect my Arduino's digital outputs from unwanted, outside voltages. My project uses about 20 different outputs, each connected to a wire (run) that can range from 20 to 100 feet (I used cat5 cable, with each inner wire (randomly chosen) dedicated to a single digital in, out, +5, +9 or ground.)  There is a good change that outside voltages could impact these digital outs (or any other pin or power wire.)
I have a good resource on protecting digital in's but I ma not sure how to protect the digital outs.  Each needs to be able to both pull a connect component to ground, and push it up to 5 volts (am I saying this correctly?)
This should be able to protect the digital outs from shorts or 12v spikes.
How can I build this circuit?
Edit: it is difficult for me to describe this problem without mentioning the danger to all components.
Note that ways of protecting digital inputs is HERE.

Some good results you can get with optocouplers.

It's electrically disconnects one part of your circuit from another.
For example, here is my IoT-ish device, which is detects water leaks in my bathroom:

I use the transformer (T1), which have two separate output windings, so, that windings does not connected electrically, only magnetically. The block in border "Sensing unit" doesn't have any wires with other scheme - only magnetic field, which is gives it power, and infrared light in the optocoupler (u2, PC817), which informs ESP01 about leak presence.
How does it work? Very simple! When the water shorts JP1 (long naked wires on the floor), Q1 opens and lights-up the IR diode in PC817. Light from this diode opens another transistor - and pulls the RxD PIN of ESP01 down.
Small sketch, written on Arduino for ESP8266 periodically sends pin state by HTTPS on my web server, where monitor software, Nagios, checks the information age and the pin state, and send to me notifications, when something goes wrong.

Can you add a bit more detail please? This is basically a link-only answer that says the link will solve your problems.

@NickGammon - Done!

Check with your favorite automotive semiconductor supplier such as ST. In there automotive listings you will find drivers that will do exactly what you want and if shorted to long will shut down and come back when the short is removed.  I am not going to make a recommendation as there are literally hundreds of possibilities. These come from 1 driver per unit to 8 that would be easy to purchase. They have parallel and serial interfaces depending on what you want. If you want to be nasty get a 50 amp driver and put a huge power supply behind it, then enjoy the looks and smoke when shorted and you get the last laugh your Arduino will be OK.  Have Fun!

Add a resistor in the circuit to limit the current in case of a short.
Add clamping diode to prevent voltages higher than 5v (combined with the resistor from before). The AVR has internal clamping diodes, but those can only handle very little current. Since you are running such long wires, you probably need to add the lowest value resistor, to limit noise.
PS The possibility of have a external voltage applied to an output sound pretty troubling to me.

The possibility of have a external voltage trouble me too.  My circuits are accessible to other 'technicians' who disconnect / reconnect them without powering down everything.  There is a very real chance that a 12 volt wire will touch a digital in, digital out, a 5 volt supply wire or the Arduino's ground.  I have discussed this with them and the boss, and the response is to build a circuit that will not be damage by such things.

Just add a 220v wire. That way they are required to power everything down. That will protect the rest of the circuit from idiots messing with a powered circuit. q-:

Would love to, but the Arduino is a part of a drama stage, so the techs have to be really fast and really safe.

Related to: best way to protect a digital or analog input from 12volts by @Hoytman

Should the same configuration be used for both inputs and outputs?

@Hoytman - you asked the same question in the other thread. This is kind-of confusing, asking in one thread about inputs, and in the other about outputs, and then in both threads asking about the alternate (output/input). This is spreading the answers over multiple threads which is confusing.

Your right, I'll ask that answers are specific to the thread title.

The configuration mentioned in the other thread, which has a 1 k resistor in series with the signal, won't work so well for an output. For a start, due to Ohm's Law, it would limit the amount of current it could source, or sink, to 5 mA. If the output is just something like a serial port, that may not matter. If you are trying to turn on a relay or LED, you may find it a limitation.

Would it be a good idea to use the same configuration, but play with the values till I find something that works?

@Hoytman Could you not use a transistor to switch it on and off and also add a pull-down resistor to pull down the wire to ground after turning it off and a diode to protect the transistor?

See 10 Ways to Destroy An Arduino
One of the suggestions there for output pins was:

Put a 30mA resettable fuse (PTC) in series with every I/O pin. Not only is the current safely limited to 30mA under all conditions (more on this below), but the built-in 220 ohm resistance of the fuse naturally limits the current to 5V/220 = 23mA right off the bat.

You may also want to look at some of the suggestions on the question about protecting input pins which could help with keeping spikes out of the output circuits.


text:
best way to protect a digital or analog input from 12volts
At work, I have connected an Arduino to a security key (which has a 12v power supply) in order to give us a more versatile door lock.  Unfortunately, people keep removing the key pad, disconnecting the wires and re-connecting them (defective keypad I guess.)  In the process, I am afraid that they will accidentally send 12v into the Vcc, ground, digital in, and/or analog in pins.  What is the best way to protect my Arduino from the 12 volts?  I really need a component or two that I can to my pins.
Edit: it is difficult for me to describe this problem without mentioning the danger to all components.  Please describe ways to protect digital outputs HERE

There are some suggestions at Protecting Inputs in Digital Electronics .
Amended answer
Testing of my earlier answer involving clamping diodes gave unsatisfactory results. Due to the small current flow the diodes allowed a considerable voltage to reach the input pin (like, 9 V).
The amended circuit below, tested with 12V input, satisfactorily keeps the Arduino input pin to 4.9 V, even with 12 V from the device. The current through R1 is around 7 mA which is what you would expect:
I = V / R
I = 7 / 1000
I = 7 mA

The 1N4733A is a 5.1 V, 1 W zener diode which can therefore handle dropping 5 V at 7 mA.
In case you are wondering where the number 7 comes from in the calculations above:

The input voltage is 12 volts
The desired output is 5 volts
Therefore we need to drop (12 - 5) volts over the resistor
Thus 7 volts are dropped over the resistor

Further reference material:

10 Ways to Destroy An Arduino
Protection
Microcontroller Input Protection Techniques

Is D2 and C1 connected to +5v or ground?  I don't see a lable

As per Electrical Symbols & Electronic Symbols the downwards pointing triangles are common ground. So yes, D2 and C1 are connected to ground.

Thanks, great link for someone that is not a trained electrical engineer (me.)

Can this same circuit protect Digital outputs too, or should a different circuit be used?

A 10 ohm resistor, will mean around 0.7 A will go through the diodes if +12 volt is connected. That's 5Watts being dissipated by R1. Fine for 12v spikes, but not for continues 12v being applied.

That's true - probably R1 should be at least 100 Ω instead of 10 Ω . That means it will have 70 mA through it, which would be 0.49 W. The circuit was really for spikes rather than connecting a high-current supply. And since that wasn't really the question asked, I have amended the answer to have a higher value for R1. Since we had a 1 k resistor there anyway, I changed R1 to 1 k. Assuming the security key is just sending serial data that should still work.

@Hoytman - that isn't really required for an output circuit. I suggest you browse some of the references in my answer to see if they help.

Note: circuit changed again as testing of the clamping diodes solution revealed that with the low current through the resistor (due to the high impedance of the Arduino input) they were not effectively protecting the input pin. The zener diode solution, however, does.


text:
ESP8266 Arduino 2.2inch ILI9341 TFT library
I recently got one TFT LCD from aliexpress which supports SPI and uses ILI9341.
This is the one.TFT LCD
I have the ESP8266 EspressoLite 1 board, and I am using ESP8266 Arduino.
(https://github.com/esp8266/Arduino)
I made the following connection :
SCK #14, MOSI #13, MISO #12 and CS #4, DC #5,RESET #0
and used the example graphicTest (which is available in the Adafruit_ILI9341-master folder) . I was able to make the display work for a few seconds.
In the graphic test, once the line test starts my ESP8266 gets restarted. This was getting repeated .
In my existing project, I used the following code to just show some messages :
Adafruit_ILI9341 tft = Adafruit_ILI9341(4, 5, 13, 14, 0, 12);
  tft.begin()
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_GREEN);  tft.setTextSize(4);
  tft.println(message);

The message is shown once a response is sent back from ESP. This works for a couple of times and then it again gets stuck and reboots.
I am not sure whether I am using the optimised library for ESP8266 for this LCD or whether there is any as such.
I read in forums and could see that there were some adafruit libraries in the ESP8266 Arduino but now that it is not available and only some TFT_Touch_Shield_V2 are present.
Has anyone faced the same issue or can tell me a better way to make this display work with ESP8266 Arduino.
Thanks in advance. !!!

You did not include any output from the esp8266, but I'm pretty sure what is happening is that the watchdog timer is expiring and resetting your board. This is because the SPI transactions to transfer data to the display are taking too long.
Put the following line in both setup() and loop() before any display operations happen:
wdt_disable();
Needless to say, if you actually do need the WDT in your application, you can reenable it after the display operations complete (of course, if you are doing something that depends on the wdt, you already know this!)
Look at the source for the Adafruit library, make sure there are #ifdef ESP8266 statements there; older versions did not support the 8266.
You may also want to increase the default speed at which the library drives the SPI bus from 8000000. I've gotten it to work at up to 40MHz, with the board flashed at 160MHz of course, and it's a lot faster (unsurprisingly), but if you have long wires or a marginal-quality display, that may fail.
Post pictures :)

Thanks a lot for the suggestions .Its too early in the morning here to check what you have mentioned .I will check the following once later today and will post the results :) I hope with your help I can sort it out and too much thankful for such lengthy explanation and details about the whole issue. I expect you to help me further in case it doesn't sort out the issue .

Thanks for the detailed explanation .I tried putting the wdt_disable() void showmessage(String message) {   wdt_disable();   tft.fillScreen(ILI9341_BLACK);   tft.setCursor(0, 0);   tft.setTextColor(ILI9341_GREEN);  tft.setTextSize(4);   tft.println(message); }  but it doesn't work .it still continues to reset

What do you see on the serial port output? (If you are not using the serial port in your code, just put Serial.begin(115200) or some such, as the debugging output defaults to 74300bps or some weird number like that which most terminal emulators, including the arduino ide serial monitor, do not support.

I made it work as you mentioned .disabled the watchdog timer before writing to LCD and then once that is done called the enable with a time value of 10 and now it works without any exception . But still I feel the speed is bit slow for esp8266 .You said about 40Mhz . Is that done using the spin set frequency method and then flashing at 160 ? anyway thanks for fixing my issue :)

I'm glad you got it to work. The 40MHz is the SPI bus speed, which you set in the spi settings, for example here: https://github.com/adafruit/Adafruit_ILI9341/blob/master/Adafruit_ILI9341.cpp#L39
You also appear to be using the software (bit-banged) SPI code; use the constructor that does not specify the miso/mosi/sclk pins, and use the hardware spi pins on the 8266 (mosi: 13, sclk: 14, cs: 16, miso: 12 (unused for the display, but if you have the card that also has a touch screen, you need that. With a different chip select, of course!)

Thanks again and the hardware SPI is fast now. But I would like to know one more thing from you whether the adafruit library for the esp8266 supports any kind of scrolling by default or there is any other library which supports that ?


text:
Why doesn't my object's method return back to my caller method?
I am creating a miniature computer using an Arduino, and I am creating a full-scale interpreter for it. Everything works, and the code begins to run after calling the runCode method, but once the run is finished it doesn't return to the calling function. I have Serial outputs to tell me where the code reaches.
My code contains an "Function" object with a name and a function pointer, an object to run the code (with a working Lexer object that splits the inputted code by spaces), and an in-computer editor (which completely works except the one function) to input programs to be run.
The function that calls the runCode method for my code-running object (called Joker) is in the editor. The problem is, once the runCode finishes, it does not return. The system halts. I will post the Function class, runCode Method, and calling method.
P.S. There are Serial prints to determine where the code reaches. It outputs "Function End!", but not "Failed!"/"Succeeded".
P.P.S. It uses a parallax 4x20 Back-lit Single-pin Serial LCD which completely 100% works.
P.P.P.S It uses the QueueList library which is basically a dynamic list that works like a stack.
One more note: The code heavliy uses dynamic lists, function pointers, and lambda expressions, so.... be prepared....

Code for Function class (no it does not have any actual functions):
class Function {
public:
  String f_name;
  bool (*f_run) (QueueList<float> &stack, SoftwareSerial &lcd);
};

Code for runCode method:
bool Joker::runCode(QueueList<String> lineTable, SoftwareSerial &lcd) {
  // Set up lexer
  Lexer lexer;
  // Get all lexer words
  lexer.getWords(lineTable);

  String cur_word = "";
  float num_val = 0.0f;
  bool quit = false;

  while(!quit) {
    cur_word = lexer.nextWord();
    if(cur_word == "")
      quit = true;
    else {
      // Get word in uppercase
      cur_word.toUpperCase();

      Serial.println(cur_word);

      // Parse the first number from it
      num_val = cur_word.toFloat();

      // Check if we have a function
      if(queueListContains(cur_word, dictionary)) {
        Function theFunc = getDictionaryFunction(cur_word, dictionary);
        if(!theFunc.f_run(stack, lcd)) {
          error(F("Unable to process word!!"), lcd);
          return false;
        }
      } else if(num_val != 0) {         // check if the parse was good
        stack.push(num_val);            // if it was: push num to the stack
      } else if(num_val == 0) {         // if zero it could be parsing a zero or it could have failed
        if(cur_word.indexOf("0") != -1) // if it didn't fail:
          stack.push(num_val);          // push to the stack
        else {                          // otherwise:
          error(F("Unknown word!!"), lcd);   // Unknown word error
          return false;
        }
      } else {
        error(F("Unknown word!!"), lcd);
        return false;
      }
    }
  }

  // Test printing the stack
  /*while(!stack.isEmpty()) {
    lcd.print(stack.pop());
    lcd.print(' ');
  }*/

  Serial.print(F("Function end!"));
  return true;
}

And the caller method:
void line_editor::RunProgram(SoftwareSerial &lcd) {
  Serial.println("Running program!!");
  // Move to top line
  currentLine = 0;
  while(!lineTableB.isEmpty()) {
    lineTableA.push(lineTableB.pop());
    // Serial.print(lineTableB.peek());
  }

  // Clear the string
  lcd.write(12);
  delay(5);
  lcd.write(128);

  // Joker language object
  Joker joker;

  QueueList<Function> PrintingWords;

  // Create the printing functions
  Function printWord;
  printWord.f_name = "BC"; // print "Beginning Card"
  printWord.f_run = [] (QueueList<float> &stack, SoftwareSerial &lcd) {
    if(stack.isEmpty()) {
      return false;
    }

    float num = stack.pop();
    lcd.print(num);
    lcd.write(13);

    return true;
  };
  PrintingWords.push(printWord);

  // Print the whole stack
  Function printStack;
  printStack.f_name = "AC"; // print "All Cards"
  printStack.f_run = [] (QueueList<float> &stack, SoftwareSerial &lcd) {
    while(!stack.isEmpty()) {
      lcd.print(stack.pop());
      lcd.print(' ');
    }

    lcd.write(13);

    return true;
  };
  PrintingWords.push(printStack);

  // Add all the functions
  joker.addWords(PrintingWords);

  // Run Program here...
  if(joker.runCode(lineTableA, lcd))
    Serial.println("Success!!");
  else
    Serial.println("Failed!!");

  // lineTableA.push(lineTableB.pop());

  Serial.println("Here!!");

  return;
}

Sorry if I confused anyone. If there are any questions, then leave a comment, and I'll try to clear up the confusion. Any help would be appreciated.
EDIT::ADDING FULL CODE:
Here is a LINK to the rest of the code on github.
Also, here is the rest of the Joker.cpp:
void Joker::addWords(QueueList<Function> new_dict) {
  while(!new_dict.isEmpty()) {
    dictionary.push(new_dict.pop());
  }
}

bool Joker::queueListContains(String theWord, QueueList<Function> &list) {
  Serial.println("Finding word:");

  QueueList<Function> temp;

  while(!list.isEmpty()) {
    Function r = list.pop();
    temp.push(r);

    Serial.print(">> ");
    Serial.println(theWord);
    Serial.print(">> equals? ");
    Serial.println(r.f_name);
    delay(5);

    if(r.f_name.equals(theWord)) {
      while(!temp.isEmpty())
        list.push(temp.pop());
      return true;
    }
  }

  while(!temp.isEmpty())
    list.push(temp.pop());

  return false;
}

Function Joker::getDictionaryFunction(String theWord, QueueList<Function> &list) {
  QueueList<Function> temp;

  while(!list.isEmpty()) {
    Function theFunction = list.pop();
    temp.push(theFunction);

    if(theFunction.f_name.equals(theWord)) {
      while(!temp.isEmpty()) {
        list.push(temp.pop());
      }
      return theFunction;
    }
  }
}

void Joker::error(String message, SoftwareSerial &lcd) {
  lcd.write(12);
  delay(5);
  lcd.write(128);

  lcd.print(message);

  delay(2000);
}

And the header:
#pragma once

class Joker {
private:
  bool queueListContains(String theWord, QueueList<Function> &list);
  Function getDictionaryFunction(String theWord, QueueList<Function> &list);

public:
  QueueList<float> stack;
  QueueList<Function> dictionary;

  void error(String message, SoftwareSerial &lcd);
  void addWords(QueueList<Function> new_dict);
  bool runCode(QueueList<String> lineTable, SoftwareSerial &lcd);
};

Please post a Minimal, Complete, and Verifiable example.

What Arduino board and IDE version are you using? Most boards have very limited amount of memory.

He tagged it Mega.

In principle, I would avoid the String class, because that could fragment memory. However in this particular case, it is probably something more sinister.

The full code link was a very very very bad way to upload code.

@MikaelPatel Don't mind me asking, why was it a bad way?

The short answer here is - It does not return because you have corrupted the stack.
The return address is pushed onto the stack as part of the function call.  If you overwrite (corrupt) that address the program cannot jump back to where it was (return).
So where is the cause of the problem?
Does getDictionaryFunction(cur_word, dictionary) ever return NULL or an invalid pointer?  The code tries to execute it anyway.  EDIT: What happens below when theWord is not matched or list is empty?  Actually I'm surprised this compiles, since there's a few paths where no value is returned.  (I'm no expert on the GCC AVR compiler, but what happens if we don't assign a return value at all?)
Function Joker::getDictionaryFunction(String theWord, QueueList < Function > &list)
{
    QueueList < Function > temp;

    while (!list.isEmpty())
    {
        Function theFunction = list.pop();
        temp.push(theFunction);

        if (theFunction.f_name.equals(theWord))
        {
            while (!temp.isEmpty())
            {
                list.push(temp.pop());
            }
            return theFunction;
        }
    }
    // BAD-JUJU HAPPENS IF WE GET HERE
    assert(false);
}

Coding style tip: except in trivial cases, it's good to only return from the bottom of your function.  Then the above never happens, and supposedly it's easier for the compiler to optimise.  NOTE: I'm unsure if assert() will even do anything on Arduino.  It's left as a marker to mean Handle Error Here.
Function Joker::getDictionaryFunction(String theWord, QueueList < Function > &list)
{
    Function dict_func = NULL;
    QueueList < Function > temp;

    while (!list.isEmpty())
    {
        Function theFunction = list.pop();
        temp.push(theFunction);

        if (theFunction.f_name.equals(theWord))
        {
            while (!temp.isEmpty())
                list.push(temp.pop());
            dict_func = theFunction;
            break;
        }
    }
    assert(dict_func != NULL);  // This should never happen
    return dict_func;
}

Coding style tip: WoRd CasE ~ lower_case, mixedCase, CapitalCase, UPPER_CASE.  I use lower case for all_variable_names, mixed case for functionNames(), capital case for ClassNames and StructureNames, and upper case for MACROS and CONSTANT_DEFINITIONS.  Pick a system, and stick to it absolutely.
Have you run out of memory - the stack could have hit the heap.
What sort of Arduino are you using?
On an Uno, with only 2k of RAM, you might need to make some scope-cuts.
Even on an Arduino Mega, you still only have 8k.
Maybe you can make use of a freeMemory() function.  This will give you an indication of the free space between the stack and the heap.  The AdaFruit version is below, but there are others too.
int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

It may be worthwhile reading their page on Arduino memory usage.
So after having a browse through your code, I can't see any obvious problems.  Fix the getDictionaryFunction() so you know if it's failing.  Check to see if you're running out of RAM - you are making heavy use of it copying strings around, especially with that template class.
Maybe consider re-compiling the code on a workstation in GCC - it wouldn't take much, just change your serial outputs to printf(), and hard-code your input data (or read from a file).  That will enable easier debugging.

He has a Mega, from the tags. However I agree in principle that the stack is probably corrupted. Why, it is hard to say from that snippet.

@NickGammon I will add the rest of the code.

I was hoping for a minimal example that demonstrates the issue.

Agreed - dude is clobbering the stack. Not surprising, considering what he is trying to make his arduino do.


text:
Hacking old car dvd monitors with arduino
I got this old junk LCD from my car. The DVD function stopped and the LCD holder on the top of the car broke, so I took it.
Is there any documentation or advice I could use to get this working with an Arduino mega or clone of similar power? I couldn't find anything after looking through Google.
I.e. I'm looking for a way to get a pinout or idea of what those wires on the jack are so that I might be able to get text and/or basic graphics on the screen. Maybe to make an Arduino PC or something idk.
Any advice on either figuring out the connections by hand and how to get a simple connection to the Arduino to get bsic stuff working or a place I can find pinout and such or where someone else has done something similar would be helpful.

Update 2
A quick Google search reveals that it's made by sharp I believe. I'm looking into it.
Update
Here's is the back. It's got quite a few numbers on it. Maybe one of those can help?
Top Numbers:
D 09399847
LQ070T5CRQ2 46009355
And the one on the bottom:
K4013TP

Most bare monitors use an LVDS interface (some use a TTL like digital interface).  Such an interface requires very high data rates.  An Arduino is usually based on a low power Atmel processor.  There is no way an Arduino Uno, for example, can support the necessary data rates.  LCDs designed for under powered processors such as an Arduino Uno actually contain a much more powerful processor to go between the slow Arduino Uno and the LCD screen.

@st2000 What about a teensy 3.6? It has a 32 bit CPU running at 180MHz, 1M Flash Memory, 256K RAM, 4K EEPROM, and can be programmed in "real" C or Arduino. It's also very small in case you didn't get that from its name :)

These are opinions.  So I'll keep them in the comments.  The only recent "bare bones" attempt widely done was to interface a RaspberryPi GPIO port to a TTL level bare color LCD screen.  Even then, the color depth suffered.  LVDS would add the complexity of balanced pair HW.  Maybe, if you worked hard at it, you could get an ARM core Arduino to work.  But it may be much easier to take @Tri 's advice and find the OEM of the LCD and work backwards from there.

I realize this is an ancient question, but just in case someone else has one of these things, I'll share what I know. I have one of these Sharp LCDs that I typically use as a monitor for a Commodore 64. I believe mine was originally from a rear seat DVD player in a Ford Explorer.
Looking at the rear of the unit, with the two connectors on the bottom, the leftmost connector is CN2 and the rightmost is CN1. I know nothing of CN2, but here's what I know about CN1:
Pins 1 through 15, from left to right:

NTSC composite video in
ground
ground
?
+12VDC in
?
?
?
?
?
?
+12VDC in
+12VDC in
ground
ground

I'm sure the other pins have additional functionality, but I'm not aware of it. Hopefully this helps someone.
EDIT: I found the datasheet in my files: https://byteshiftmusic.com/media/Sharp_LQ070T5CRQ2.pdf

I don't even remember asking this question haha.
Might still have it somewhere though, so thanks!

Your best bet is to try to take the casing off until you find a company name so that you can get a lead on where to look for documentation. Because until you find out more about how that screen works, it's a black box to you and you don't know what to put in it. No one else will be able to help you until you provide more information to this extent because no one else can hold it in their hands, and the photo of the socket that you showed us doesn't look like a common display format either.
Also, you're very unlikely to make a PC-type thing out of this. That depends on the power of the computer behind the display and an arduino isn't that powerful. You want a Pi. Or maybe I'm misunderstanding what you want. You could easily get a scrolling text type thing going or maybe even a game (if you figure out how to make it work).
Edit: I just looked up a sample LCD screen and it has 6 signal pins and power and ground. Yours looks like it has a lot more. So you definitely have some digging to do.