text:
Can ESP8266 replace Arduino?
I’m a hobbyist and have used Arduino so far for simple projects. Now I want to build a project involving addressable LEDs, I want to write several programs on the Arduino for the LEDs and on my phone I select which ones to run.
I found ESP8266 as a good and cheap solution to talk to my Arduino. Searching on the web to learn getting it to work I found that It has its own mcu on it and I can write and upload my code in Arduino IDE! 20kB of RAM, 80MHz CPU and 4MB of flash for 3 USD (However I’m not sure of these numbers but even one fourth of it is great)!! If I just need a few GPIOs why should use an Arduino UNO? Is this module reliable?

No, I'm not going to look up what a ESP8266 is to answer a question here.  Besides, from the title this is clearly a opinion-based question, and it seems is about the use of electronic device rather than their design.  Not only that, but to erase any doubt, you mention "arduino".

The internal ESP8266 processor is able to run user programs. The language used depends on what you have access to. LOA is commonly used.

@OlinLathrop If people use terms such as "LM324", "BC337", 1N4148 it is generally accepted that they are well enough known that inclusion of opamp, bipolar low power NPN transistor and silicon small signal diode, respectively is not required for understanding. | The ESP8266 family is a range of modules with WiFi + processor in a single IC and a companion memory for program. These are very very well known and something extremely worth knowing about if you have not met them. While not (yet) quite as ubiquitous as eg an LM324 they are quite possibly the most common "IOT" WiFi interface overall.

I really do not think this question deserves a negative

@RussellMcMahon It's "LUA" not "LOA".

@linhartr22 LOL

@linhartr22
Quoting from www.lua.org/about.html:
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

Well, the answer of the question "Can it replace Arduino" - yes, in many cases it can.
Whether it would be "the Arduino killer" - I doubt it.
There are multiple arduinos and ESPs in my home and 1 ESP in my office running 24/7 as a part of my self-made (and constantly under development) smart home solution, together with 1-2 PCs. On top of that I have several experiments / unfinished projects involving the ESP.
So, from my not-so-limited experience, here are the pros and cons of ESP compared to Arduino:

++++ Internet connectivity built in!
++ Faster clock and more memory.
+ Runs on 3V3 (most, but not all Arduinos are 5V) so it can interface 3v3 devices (like most of the display modules) directly, without level shifters.
+ The "basic" ESP-12E costs about as much as an Arduino nano or pro micro.

- The "basic" ESP-12E is 2.0mm pitch, not 2.54mm, making it a pain in the ass to work with.
- There are breakouts that make it easier for prototyping, but they increase the cost and take too much space on a breadboard / protoboard.
- The most common breakout - NodeMCU - is more expensive and has pins remapped, major annoyance, unless you program it in Lua, which is only ok for very simple projects. IMO, it should be used for prototyping only.
- They run on 3v3, making it hard to interface 5V modules, fully turn on most MOSFETs, etc.
- They are extremely picky on their power supply.
- They draw significantly more power than the Arduino when not transmitting and much more when transmitting.
- They are almost always worse for battery operated projects - you need 3v3 regulator (which has quiescent current), you need to sleep a lot (and you need GPIO16 broken out for that) and at the end of the day an arduino + a low-power radio will do the same job while lasting significantly longer on battery.
- They have less GPIO pins and some of them must have set voltages at startup (GPIO0 - high, GPIO2 - high or floating, GPIO15 - low), also they "wiggle" some of their IO pins on startup, often making them unusable for many devices.
- They only have one ADC, and to my knowledge it is slower than the already slow Arduino ADCs, plus you can only use it with 0-1.1V (internal reference).
- Many of the Arduino libraries work out of the box or are already ported, but many don't. You either have to port them yourself or wait for someone to do it. In general, the Arduino community is much bigger and more mature, so most "noob-friendly" tutorials, libraries, etc. are provided for the Arduino.

Having that said, the ESP8266 is still great and extremely useful. Even Lua is useful for quick small projects. In most cases where internet connectivity is required, they seem to be the best solution. In many other cases, whether you will use ESP or Arduino actually doesn't matter. And sometimes the Arduino (or the little ATTiny85) is the better choice.
As always, "the right tool for the job" is the way to go.
Or combination of tools.

Strongly disagree that it is "just wrong" to use an ESP as a secondary device to an Arduino with a UART interface. You point out reasons for this yourself - if you want to use libraries that aren't yet ported to the ESP, why not have the Arduino as the primary device and use the ESP to do one job well? Or if you are more familiar with 8-bit AVR devices and can afford $5 for a very capable WiFi addon, why not do that? In engineering, excluding stupidity, there is no right or wrong way, provided it works - only more or less appropriate to a particular challenge.

There is nothing wrong with having an arduino (or attiny) connected with ESP via UART. What feels "wrong" is using AT commands and having the Arduino parse HTML requests and responses, etc. It sure works (I've done it), but sounds wrong - the "logical" way would be for the more powerful chip (the ESP) to act as a master and offload specific tasks to the less powerful chip, not the other way around. Most of the time, it is also the easier way - fiddling with AT commands parsing on the Arduino is neither fun nor efficient. Yes, you have to program both chips this way, which is inconvenient.

Might be worth editing your answer to include this clarification.

This was just a remark at the end of my answer, finished with a smilie, and it clearly mentions AT commands already. And, it is already a bit offtopic, I dont know why you picked that up.

Because the rest of the answer is good, but that last sentence is unclear and misleading imho. Clarifying for those seeking answers would help those who do not understand why this might be a bad idea - and get them away from the idea that there is such a thing as "just wrong" without clear reasoning. But the answer is yours - obviously you are free to do as you see fit.

There you go :)

@Mishony Thank you for your detailed answer. Excuse me for my ignorance, but if I want to use an Ardunio and not use AT commands, how should I talk to the Arduino? I'm new to this module and know very little. I would appreciate it if you could give me some keywords to start with.

If you really need to use an Arduino AND an ESP (instead of just the ESP) then you can still use Serial communication, but on a higher level - for example Arduino sends "temp=26.5" to the ESP, your code on the ESP recognizes that and sends an HTTP request to thingspeak.com or whatever. For this to work, you must program both the Arduino and the ESP, which is a bit inconvenient, but not really harder than fiddling with AT commands. In many situations you can simply ditch the Arduino and only use the ESP.

If you can program it, then of course it is viable to directly control your lights.  It doesn't have a large number of I/O pins like the Arduino does, but as long as you have enough to do the job, it certainly drops the cost, the size, and the power requirements.

@Dow you can find even better price on ebay/aliexpress.

For my application one IO is enough, however ESP-12 provides  several IOs, 10 bit ADC and much more.
Actually I bought one ESP-01 for 1.78 USD (From Aliexpress)! Check https://github.com/esp8266/Arduino for using your ESP in Arduino IDE. you just need a USB to serial converter. Or google  NodeMCU to get it all in one board.

Yes there are a few I/O pins, so in theory you could drive one or a few leds or use an I/O port expander (I2C) for example.
And yes you can develop software and download it into even the low cost modules.  The Arduino-like angle is just one way to do this.  It is not an ARM as one might be lead to believe.  But there is a gnu toolchain for the esp8266, etc.  Yes 80 or 160MHz, 32 bit RISC, some flash, some ram.

The Arduino Uno board and the ESP module are not the same, but as long as the GPIO of the ESP8266 provides the hardware that you need for your application it will work.
One of my concerns is certification.  The product has received several certifications, you'ld need to check if your version is also certified.
You can lookup the manufacturer's certifications (and some documentation) from the FCC Search Page by entering 2AC7Z as the grantee code.
The board you use may depend on those or require their own certification.
As you noticed, it can be added as a board type to the Arduino tool which makes it a lot easier for hobiests to play with it.
I just checked the grants and all three of them require that the WiFi antenna is kept at least 20 cm of all persons.


text:
Good Arduino motor drivers
I need some motor drivers that can control a DC motor with 10-15 A and 25 V. I can't find any shield that can do the job. I need to control 4 motors with these.
Can you suggest some models that are good with this?
And one more question: if a driver can control a DC motor in 2 directions, can it control 2 DC motors in one direction each?

The "shield" form factor isn't really a good fit for these power levels.  Likely a suitable driver will be its own unit, which you will have to connect to the arduino with wires.

We don't really answer "shopping questions".
You could contact several suppliers like Adafruit, sparkfun or maybe even Digikey, Farnell etc (ebay?).
If you search for: "15A dual h-bridge" you will find some motor drivers which should work for you.
If a driver can control a dc motor in 2 directions can it control 2 dc motors in one direction each?
Where are you going to use them for?
If you're only going in one direction, you won't need a motor driver.
An MOSFET (per motor) is good enough if you only drive one direction.
If you want both motors to be able to turn each direction, a dual h-bridge will do.

I need to control the speed

You can use analogWrite(pin, value) instead of digitalWrite. The value will be the "on time", so a lower value will make the motor go slower.

Nice but can I output around 25 V?

If you use a MOSFET that's rated for over 25V, yes. You'll also need a 25V power supply.

Think of the MOSFET as an on/off switch controlled by Arduino. But when you use analogWrite() it's more like a dimmer, for different speeds.

I think that the current you need is high and you are not likely to get a shield that does that. Look at a H-bridge with the desired current and voltage rating, it will probable be largish with a heat sink. If the motors are going one way then you may just need a simple mosfet style driver. You should probably look for a module with the correct rating as it will have the correct heat sink, track sizes, connections for your motor power and will probably have a diode to protect stuff from the induction spikes.
The H bridge will probably be fine with the Arduino output and it may have a voltage reg for its logic that you could use to power the Arduino.

source: Stack Exchange

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

sort: votes


text:
Arduino's digitalWrite, precautions for direct port manipulation?
I stumbled upon this piece in digitalWrite.
I'm unsure why clearing interrupts and setting/resetting SREG is neccesary here.
Can anyone shed a light on this?
uint8_t oldSREG = SREG;
cli();

if (val == LOW) {
    *out &= ~bit;
} else {
    *out |= bit;
}

SREG = oldSREG;

I figure they don't want an interrupt to possibly change any of the bits in the output register while it executes *out = *out & ~bit?
And what would the SREG have to do with it? Could the code affect SREG and why would that matter?
When speed matters, I often use the direct port manipulation, I'd like to get an idea if it's neccesary for me to include these "precautions".

If you want to do this kind of interrupt protection yourself, look at simply using ATOMIC_BLOCK from #include <util/atomic.h> http://www.nongnu.org/avr-libc/user-manual/group__util__atomic.html

@BrettAM yup, figured that one out as well (see latest comment on Majenko's answer). Though it looks fancier (and more logical) it won't make a difference runtime?

I figure they don't want an interrupt to possibly change any of the bits in the output register while it executes *out = *out & ~bit?

Correct. That is known as a critical section.

And what would the SREG have to do with it? Could the code affect SREG and why would that matter?

SREG is where the flag that says if interrupts are enable or not is stored.  Basically that is storing the current state, disabling interrupts, then restoring the current state.
The upshot is:

If interrupts are enabled to begin with, they are disabled, then re-enabled.
If interrupts are disabled to begin with, they are again disabled, and they remain disabled.

It's a way of restoring the previous state without actually having to check what the state was and set or clear accordingly.

Ah! At first it didn't make sense, I thought they could've used 'cli()' and 'sei()'. Since I was thinking of an "interrupts always on scenario". The fun thing is, when interrupts is off, you want them to be off after that piece of code as well. And on when it was on (:

What happend when one doesn't use interrupt disabling on that critical part? It may cause the wrong output state when this pin is also changed within an interrupt?

It may be that the pin you want to change in your ISR (sometimes) doesn't get changed. Or it could be that the pin you want to change outside the ISR may (sometimes) not get changed. They don't need to be the same pin - just in the same register.

Anything that does a read-modify-write that can also happen in a different context (i.e., in an interrupt) should be protected so that one RMW doesn't happen mid-way through the other RMW.

Ah, got it, the interrupt may editie a pin in the same register, just after reading and before writing. After that it writes, so the interrupt's effect is cancelled

Yep. Spot on. The only times you don't need a critical section are for atomic operations - i.e., things that cannot be interrupted since they are only one machine "op code". Note I don't use "assembly instruction" there, since some assemblers use macro instructions that get assembled into multiple op-codes and thus aren't atomic.

I've indeed heard about atomic blick http://www.nongnu.org/avr-libc/user-manual/group__util__atomic.html and read-modify-write cycles. Coudn't directly spot that it was applied in this situation (:

Answering only the last question, as the rest has been addressed by
Majenko.

I often use the direct port manipulation, I'd like to get an idea if
   it's neccesary for me to include these "precautions".

If you use constant values, like PORTB |= _BV(2); or the like, there
is no need, since this compiles into a single CPU instruction. Even if
you write things that take multiple instructions,
like PORTB |= _BV(2) | _BV(3);, you probably know whether you are
modifying the same register inside an interrupt handler or not. If not,
no need for critical section either. The authors of the Arduino core
cannot make any assumptions.

Good one. I should check how many instructions some of these take. Instead of PORTB |= _BV(2) | _BV(3); you could use PORTB |= 0b00000110 so it's one instruction again?. But well, it will depend on compiler and settings if that does anything different.

No, that's not one instruction - that's a read-modify-write.  It compiles to in r24, 0x05; ori r24 0x06; out 0x05, r24; - i,.e, read the port into register 24, OR the new value with it, then write the new combined value back out to the port. The only reason the other method for a single bit is a single instruction is because of the SBI instruction, (set bit in I/O register), such as sbi 0x05, 1; for PORTB |= 0b0000010;

Using two separate |= would be two atomic instructions that would be fine: PORTB |= 0b00000010; PORTB |= 0b00000100; = sbi 0x05,1; sbi 0x05, 2; - it's less efficient though - each sbi is 2 clocks, but in, out and ori are one clock each, so 4 clocks vs 3 clocks.

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


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:
How to connect Wi-Fi shield ESP-12E-ESP8266-UART-WIFI-Wireless-Shield with Arduino
I have bought this shield from ebay and now I don't know how to use it, ESP 12E ESP8266 UART WIFI Wireless Shield for Arduino UNO R3 Bouclier Sans filfr:

There are no instructions in the box or anywhere on internet for this board. The only description I found everywhere is this:

Description:

Standard pin interface to achieve full compatibility with the pitch Arduino Uno, Mega and so on. (Unless the standard size Arduino, such
  as Nano, Mini)
3.3V power supply using advanced chip (with the official expansion board power chip CC3000 same), so 3.3V Arduino board provided more
  accurate, so ESP8266 as official CC3000 chip work as normal, there is
  no gap.
It leads to a WiFi module power supply / service interface to facilitate developers to extend the power supply and maintenance.
Onboard ESP8266-12 stable industrial grade serial WiFi module, using an enhanced PCB antenna, signal better.
You can quickly switch DIP switch ESP8266-12 industrial grade WiFi stable operation mode (such as operating mode and upgrade mode)
  module, integrated serial chip, quickly flashing the firmware.
Built-in 5V to 3.3V TTL level converter to prevent high-pressure Arduino TTL level of the WiFi module damage.
Onboard ESP8266-12 stable industrial grade WiFi module with a metal shield, immunity to interference.
Onboard ESP8266-12 standard pitch leads to a stable industrial grade WiFi module all interfaces, enabling developers to easily
  develop deep.
Use stackable design, it can continue to accumulate above the other modules, easy to use.
Onboard four LED displays the status of ESP8266, namely PWR, DFU, AP, STA

What should be the board settings for this?
I am new to electronics please help me how can I connect this with Arduino.

I presume you plug it into the Arduino, as it is a shield. Are you asking how to code for it?

yes I need some generic library so I can run simple code for that device, I have code

Very often the seller list example code and libraries, did you try those?

thry didnt list anything and I didn't found anything anywhere, I searched lot, I search same device on ebay and other sites but nothing found in description

Nice board, but I'm also puzzled why you bought it if you don't know what to do with it. Did you have something in mind when you got it? More background is required. If you have code, post it. Describe what it does, what it doesn't do and what you're trying to but can't achieve. The possibilities with this board are really endless

I just want to create server on this device which I can achive by running any simple code but I am not able to upload code on the device code is not matter just want to run any code on that device but I am getting error while uploading and not sure what should be setup because seller didnt gave more information about device, I am still working on that trying to flash firmware and trying other things, i'll post here if I found something,

I have exactly that very board you mentioned into your article. It is a fake board. You said one has to disconnect the 2 transistors which lead to the pins 0 and 1. Okay. This makes sense, because they apparently are blocking the upload process from the IDE's serial COM Port.

From @Peter: What do you mean by the changing of the switches? Please could you explain it perhaps with a little drawing again? Thank you in advance you will be doing myself and others a favour. Have a good time. Peter

Hello, I've got the same shield, as in exactly the version on your picture. with the 'Shia1d' and the 'KXK' above 3 & 4 from DIP switch.
Did any of the below answers help you out? I was following claus' blog post and another post from claus

Changing baud rate and flashing firmware through debug ports seemed easy. But when connecting to Arduino, it only acts as access point and can't seem to be able to talk to the shield from Arduino.

There are some fake Modules on eBay! Only after changing the wiring can you use them. The fake modules have the wrong text printed on it.

Moer info $ tech

instead of

More info & tech

But when you change the wiring you can use the shield!
The two transistors which are connected to Arduino board pin 0 and 1 have to disconnected. Also the connection to the switches 1 and 2 have to change. Then you can stack ESP-12 shield on the Arduino. You can now flash the Arduino Uno when you switch off (switch 1 and 2) With the old wiring you can't use it because the transistors are wrong connected.
The voltage divider is need for 3,3 V ESP-12 RX pin

The two transistors which are connected to Arduino board pin 0 and 1 have to disconnected. Also the connection to the switches 1 and 2 have to change. Than can you stack ESP-12 shield on arduino. You can now flash the Arduino Uno when you switch off (switch 1 and 2) With the old wiring you can't use it because the transistors are wrong connected. https://lh3.googleusercontent.com/-1jOVVFXLXgQ/WIImhPhDVTI/AAAAAAAAAV8/VNd8nN_h7MMx8o-MWcf8ozXq8BSljZ_8ACJoC/w530-h707-p-rw/ESP-12%2Bfake.jpg

The voltage divider is need for 3,3 V  ESP-12 RX pin.https://plus.google.com/photos/photo/105750023979112812523/6378417390811089410?icm=true

Just to add to Andreas' answer, this is what the shield's circuit looks like at the board level:

For connecting to a 3.3v Arduino I found the neatest solution was:

Remove all the components from the area above
add 2 small bits of wire to short the areas shown in green above
Switch the DIP switch so 1&2 are towards 'ON' (to connect serial to D0/D1) and 3&4 are 'OFF' (to disable the bootloader)
Use with your Arduino on D0/D1 at 115200 baud

(You may have to flash you own ESP8266 command firmware using the debug port and a USB-TTL converter, in which case setting 3&4 to 'ON' and resetting the ESP8266 will stick it into bootloader mode. If you're doing this you can also send AT+UART_DEF=9600,8,1,0,0 to put the ESP8266 into 9600 baud mode permanently if you're using an Arduino that can't handle the higher baud rates)

Same Shield here, the most useful guide I've found is https://www.espruino.com/arduino-esp8266
The DIP switches are:
Switch  Function
SW1 Connect ESP8266 TX to pin D0
SW2 Connect ESP8266 RX to pin D1
SW3 Enable bootloader mode
SW4 Use DFU LED to show serial activity (?)

For connection to the Arduino, just stack the shield over the Arduino board.

(source: robotshop.com)

A search on the designer's name turned up a few posts by people working with this board. This post was the most useful one I found. I don't have this shield and haven't tested this poster's instructions, but it seems worth trying:

Hi! Finally back here, more enlightened! :D I have finally done some
  stuff with the 8266 shield. I just wanted to share it with you all.
  Since I know I wanted all this before I started. I write all this a
  little bit as a "for dummies" just to make sure every step is
  included. So to be more precise, I use a Arduino uno with a (se
  below).
1: (identifying) The shield is a "ESP8266 ESP-12E UART WIFI Wireless
  Shield for Arduino UNO R3" (from Ebay). Since there seems to be none
  documentation about this board, hopfully this will help you. I think
  there was some pictures before on this thread. On my board it states:
"Arduino ESP8266 Wifi shield. Version 0.9 by WangTongze." (and 1.0..
  I've got two)
Here is a good link to identify which ESP8266 module you got if you
  want to know exacly what you got (if it is a different wifi board) :
  wiki/doku.php?id=esp8266-module-family
There a 4 DIP switches on this board are numbered from 1-4. To be
  honest I really don't know what 1 and 2 is. But my guess is that you
  can use TTL levels on TX & RX opposed to 3.3 which the 8266 module
  uses directly. These two are always set to DOWN for me. Second though,
  if so, I might set them to UP when using Arduino. I usually play
  around with the board with a USB to 232 converter when testing. The
  other two, 3-4, are connected to GPIO 0 and something else xD. I
  really doesn't matter really. All I know, that I set these to UP to
  start a firmware update. Here is a good link that might be somewhat
  equal to what the shield has implemented.
http://blog.falafel.com/how-to-wire-the ... ogramming/
2: (using Arduino with the shield) So everywhere, including this
  thread states that Arduino UNO doesn't handle the software emulated
  serial very good at high speeds. That is true :D So I got it to work
  perfectly with a baud rate 9600. What I did was to find a firmware
  that has default baud rate 9600 from AI thinker. I never really got
  the baud change to work. AT+CIOBAUD=9600 never got stuck after a reset
  (rst button och a AT+RST). And the other AT+IPR=9600 broke the
  firmware. If someone got this to work, please write here in this
  thread!!
Here is a link: http://wiki.aprbrother.com/wiki/Firmware_For_ESP8266
The only wiring I did to make it work, is to connect the tx and rx to
  Arduino's pins. (rx->tx and tx->rx). According to this example:
  http://allaboutee.com/2014/12/27/esp826 ... d-circuit/ connect to pins
  2 and 3. The tx and rx from the 8266 shield are located on the left
  down side. There are other pins you can use also.
3: (flashing a firwmware) To set the board on flash mode, put the DIP
  switches to 3-4 to UP, press the 'ESP-RST' button. When flashing is
  done, set these to DOWN and press the 'ESP-RST'. Maybe there is a way
  to flash a firmware with the Arduino, but I finally bought a "FT232RL
  3.3V 5.5V FTDI USB to TTL Serial Adapter Module for Arduino Mini Port T". There is a picture here: http://blog.falafel.com/how-to-wire-the
  ... ogramming/. I use this flash software:
https://github.com/Stadslab/ESP8266_exa ... te%20Ready
Because you can't really do any setting with it and it has worked 100%
  of all time for me and my use.
So to connect the FT232RL to the 8266 board:
(pins down) from left to right you have: dtr, rx, tx, vcc,cts and gnd
  and on the wifi shield from left to right: txd, rxd, 5v, gnd, 3v3.
  rx->txd, tx->rxd, gnd->gnd, vcc-> 3v3. Remeber that the FT232RL board
  has a jumper to change the voltage. You should use 3.3v. But for me I
  had some problems flashing, so I actually the the voltage to 5v and
  then connect the vcc to 5v connector on the wifi board. Never had any
  problems after that.

I just managed to get mine working and wrote a blog article about it.
Long story short:

Set all DIP switches "off"
configure the ESP8266 to use 9600 baud using the AT command "AT+UART_DEF=9600,8,1,0,0"
connect debug ports RX/TX to Arduino pins of your choice (not being pin 0 and 1)
Use the WiFiEsp Lib and tell it to use "your" pins and 9600 baud

In addition to Andreas' answer, I believe he is correct about the general wiring of the 2 pins #0, #1 for some cheap clones.
I got mine to talk to the serial monitor (Arduino) by jumpering over the shield pins directly to the header pins next to the ESP-12E module.
This is at 115200 baud and Both NL and CR on the serial monitor.

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


text:
Safe changes in the Arduino Libraries and use them
I changed 2 Arduino Libraries because i have a 9 bit data protocol, now i want use the amended Libraries on my Arduino mega2560.
At first i have set a 9 bit data mode that can i do when i set the UCSZ12 bit on 1(original code under the following link: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp#L103 ):
void HardwareSerial::begin(unsigned long baud, byte config)
  ...
  sbi(*_ucsrb, RXCIE0);
  sbi(*_ucsrb, UCSZ12);  // chance: set 9-bit data mode on 1
  cbi(*_ucsrb, UDRIE0);
  ...

At second i want throw an interrupt when the 9th bit is an 1 that can i do when i change the code like the follow (original code under the following link : https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial_private.h#L101 ):
void HardwareSerial::_rx_complete_irq(void)
  if (bit_is_clear(*_ucsra, UPE0)) {
    bool is_address = UCSR0B & _BV(RXB80);
    unsigned char c = *_udr;
    if (is_address) {
      do_something_with_address(c);
      return;
    }
  rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
...

What must i do with the two file´s?
How can i use the changed Libraries?

If you edited them in your local IDE installation then there's nothing to do. I don't quite understand your question - you edited the files, now you want to know what to do with them? They have been edited. If you saved the files after editing them (which you would have done) then what is it you are now hoping to do with them?

I write a new file because i did´t find them in the local IDE. It will be nice when you have a path than i know what i have to do.

Oh sorry i find it, in the link from Github is the path i didn´t see it the whole weekend sry that was my fail.

I'd rename them to something new, and add them to the libraries folder.

In Linux, after building the data base, "locate HardwareSerial.cpp" results in: /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.cpp and several other hits.  This works for Mac as well.  If you are on a Windows machine, the search feature varies from version to version of Windows.   And some implementations are very slow.  If you can not find the file ... consider upgrading to the latest version of the Arduino IDE.

How can i close that question when i have the answer but no community answer?

I found the path to the files i want change in the github link so i can change the files(C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino).
I enable the uart for 9 bit, i add sbi(*_ucsrb, UCSZ12);  in HardwareSerial::begin
I decided that i only send a Flag to my PC when the 9th bit is set. For that i change the _rx_buffer to a 2 byte matrix (short _rx_buffer). Now i send the databyte in the low-byte and flags for 9 bit, framing error and overrun error in the high-byte. That i can do that i change the void HardwareSerial::_rx_complete_irq(void) code like the follow:
void HardwareSerial::_rx_complete_irq(void)
{
  if (bit_is_clear(*_ucsra, UPE0))
  {
    bool is_address = UCSR0B & _BV(RXB80);
    bool is_framError = UCSR0A & _BV(FE0);
    bool is_overError = UCSR0A & _BV(DOR0);
    unsigned char c = *_udr;
    rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;

    if (i != _rx_buffer_tail)
    {
     _rx_buffer[_rx_buffer_head] = c;
     _rx_buffer[_rx_buffer_head] |= is_address << 8;
     _rx_buffer[_rx_buffer_head] |= is_framError << 9;
     _rx_buffer[_rx_buffer_head] |= is_overError << 10;
     _rx_buffer_head = i;
    }
  }
  else {    *_udr;  };
}

I hope this will work and i can evaluate the data right at the PC.
Frindly wishes sniffi


text:
Storing integer into character buffer
I have my Arduino code as below.I am trying to send Serial request and get response for it. I can able to send request mentioned in Setup function and also able to switch cases. Problem i am facing Print character buffer after storing the  values. can someone suggest me how to store integer value into charcter buffer and print result later.
#include "glob.h"
const int BUFFER_SZ = 32;
char sendBuffer[60]={'0'};

void Take_Reading() {

  for (int row = 0; row < 8; row++)
  {
    //   // get rid of me:
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    delay(50);
    analog_1_pv[row] = ANALOG_SCALING * analogRead(A0);
    analog_2_pv[row] = ANALOG_SCALING * analogRead(A1);
    analog_3_pv[row] = ANALOG_SCALING * analogRead(A2);
    if ( (analog_1_pv[row] <= MINV_RANGE || (analog_1_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value1[row] =  0.0;
    }
    else
    {
      Current_Value1[row] =  (analog_1_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_2_pv[row] <= MINV_RANGE || (analog_2_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value2[row] =  0.0;
    }
    else
    {
      Current_Value2[row] =  (analog_2_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_3_pv[row] <= MINV_RANGE || (analog_3_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value3[row] =  0.0;
    }
    else
    {
      Current_Value3[row] =  (analog_3_pv[row] * 12.5) - 31.25;

    }

    Mod_current[row] = (uint16_t)(Mul_Factor * Current_Value1[row]);
    Mod_current[row + 8] = (uint16_t)(Mul_Factor * Current_Value2[row]);
    Mod_current[row + 16] = (uint16_t)(Mul_Factor * Current_Value3[row]);

  }

}

int ID_Check() {

  int ID_value;
  for (int row = 0; row < 8; row++)
  {
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    Status_Out[row] = digitalRead(Output_Read);

  }

  ID_value = 1 * Status_Out[7] + 2 * Status_Out[6] + 4 * Status_Out[5] + 8 * Status_Out[4] + 16 * Status_Out[3] + 32 * Status_Out[2] + 64 * Status_Out[1] + 128 * Status_Out[0];
  return (ID_value);

}

int  Take_Temp_Reading()
{

  Temp_Total = Temp_Total - Temp_readings[Temp_index];
  Temp_readings[Temp_index] = analogRead(A5);
  Temp_Total = Temp_Total + Temp_readings[Temp_index];
  Temp_index = Temp_index + 1;

  if (Temp_index >= numReadings)
  {
    Temp_index = 0;
    Temp_Average = Temp_Total / numReadings;
  }
  temp = (Temp_Average * 5.0) / 1023.0;

  //  temp = float(analogRead(A5)) * 5.0 / 1024.0;
  temp_int = (int)(temp * 100.0);
  return (temp_int);
  // Serial.print("Temp"); Serial.println(temp);
}

int SPD_Check()
{

  SPD_STATUS = digitalRead(SPD_STATUS_PIN);
  return (SPD_STATUS);
}

int  DC_Status()
{

  DC_STATUS = digitalRead(DC_STATUS_PIN);
  return (DC_STATUS);

}

int   Take_HV_Reading()
{

  //int analog_int= analogRead(A4);

  total = total - readings[index];
  // read from the sensor:
  readings[index] = analogRead(A4);
  // add the reading to the total:
  total = total + readings[index];
  // advance to the next position in the array:
  index = index + 1;

  // if we're at the end of the array...
  if (index >= numReadings1)
  {
    index = 0;
    average = total / numReadings1;

  }
  else
  {

    HV_voltage = (average * 5.0) / 1023.0;
  }
  if (HV_voltage <= 0.25)
  {

    Conv_HV_voltage = 0.0;
  }
  else
  {
    Conv_HV_voltage = 197.837837838 * HV_voltage + 10.8108108108;
  }

  HV_Reading = (uint16_t)(Conv_HV_voltage * 10);

  //  HV_Reading = (uint16_t)(Conv_HV_voltage * 10);

  return(HV_Reading);
}

void  Serial_Command1()

{
   Take_Reading();
  int Temp_read=Take_Temp_Reading();
  int HV_Read=Take_HV_Reading();
  SPD=SPD_Check();
  DISCONNECTOR=DC_Status();
  Serial.println("Command1 executed ");

  sendBuffer[1]=char(Mod_current[1]) ;
  sendBuffer[2]= ',';
  sendBuffer[2]= Mod_current[1];
  sendBuffer[3]= ',';

  sendBuffer[4]= Mod_current[2];
  sendBuffer[5]= ',';
  sendBuffer[6]= Mod_current[3];
  sendBuffer[7]= ',';

  sendBuffer[8]= Mod_current[4];
  sendBuffer[9]= ',';
  sendBuffer[10]= Mod_current[5];
  sendBuffer[11]= ',';

  sendBuffer[12]= Mod_current[6];
  sendBuffer[13]= ',';
  sendBuffer[14]= Mod_current[7];
  sendBuffer[15]= ',';

  sendBuffer[16]= Mod_current[8];
  sendBuffer[17]= ',';
  sendBuffer[18]= Mod_current[9];
  sendBuffer[19]= ',';

  sendBuffer[20]= Mod_current[10];
  sendBuffer[21]= ',';
  sendBuffer[22]= Mod_current[11];
  sendBuffer[23]= ',';

  sendBuffer[24]= Mod_current[12];
  sendBuffer[25]= ',';
  sendBuffer[26]= Mod_current[13];
  sendBuffer[27]= ',';

  sendBuffer[28]= Mod_current[23];
  sendBuffer[29]= ',';
  sendBuffer[30]= Mod_current[22];
  sendBuffer[31]= ',';

  sendBuffer[32]= Mod_current[21];
  sendBuffer[33]= ',';
  sendBuffer[34]= Mod_current[20];
  sendBuffer[35]= ',';

  sendBuffer[36]= Mod_current[19];
  sendBuffer[37]= ',';
  sendBuffer[38]= Mod_current[18];
  sendBuffer[39]= ',';

  sendBuffer[40]= Mod_current[17];
  sendBuffer[41]= ',';
  sendBuffer[42]= Mod_current[16];
  sendBuffer[43]= ',';

  sendBuffer[44]= Mod_current[15];
  sendBuffer[45]= ',';
  sendBuffer[46]= Mod_current[14];
  sendBuffer[47]= ',';
  sendBuffer[48]= Temp_read;
  sendBuffer[49]= ',';
  sendBuffer[50]= HV_Read;
  sendBuffer[51]= ',';
  sendBuffer[52]= SPD;
  sendBuffer[53]= ',';
  sendBuffer[54]= DISCONNECTOR;

  Serial.println(sendBuffer[1]);

}

void Serial_Command2(int a)
{

  Serial.print("Command2 executed: ");
  Serial.println(a);
}

void setup()
{
  Serial.begin(57600);
  Serial.println("Format 1: <SMCB1,1>");
  Serial.println("Format 2: <SMCB1,1,Length>");

}

// Parse the request, WITHOUT the '<' and '>' delimiters.
void parseRequest(char *request)
{
  // Check the request starts with the prefix "SMCB1,1".
  if (strncmp(request, "SMCB1,1", 7) != 0) {
    Serial.println(F("Error: bad request prefix"));
    return;
  }

  // Remove that known prefix.
  // Now we have either "", ",Length" or ",Timer,On_OFF"
  request += 7;

  // Format 1: ""
  if (request[0] == '\0') {
    //Serial.println(F("Received format 1"));
    Serial_Command1();
    return;
  }

  // Remove the leading comma.
  // Now we have either "Length" or "Timer,On_OFF"
  if (request[0] != ',') {
    Serial.println(F("Error: ',' expected"));
    return;
  }
  request++;

  // Format 2: "Length", no comma.
  char * comma = strchr(request, ',');
  if (!comma) {

    int length = atoi(request);
    Serial_Command2(length);
    //Serial.print(F("Received format 2, length = "));
    // Serial.println(length);
    return;
  }

}

void loop()
{
  static char buffer[BUFFER_SZ];  // received chars
  static size_t pos;              // current position in buffer
  static bool insideRequest;      // are we between '<' and '>'?

  if (Serial.available()) {
    char c = Serial.read();
    if (insideRequest) {
      if (c == '>') {  // end of request received
        buffer[pos] = '\0';  // terminate the string
        parseRequest(buffer);
        pos = 0;             // get ready for the next request
        insideRequest = false;
      }
      else if (pos < BUFFER_SZ-1) {  // add char to buffer
        buffer[pos++] = c;
      }
    }
    else if (c == '<') {  // start of request
      insideRequest = true;
    }
  }
}

Golb.h header file contains
#ifndef GLOB_H
#define GLOB_H
int counter=0;
int Mod_current[24];
const int numReadings = 10;
const int numReadings1 = 10;
int Temp_Total = 0;
int Temp_readings[numReadings];
int Temp_index = 0;
int Temp_Average = 0;
float  reading[10];
float Total = 0.0;
static int i;

int readings[numReadings];
int index = 0;
int total = 0;
int average = 0;

// These PinS are use to enable and disable analog MUX
int SO_enable = 5;
int S1_enable = 4;
int S2_enable = 3;

// temprature sensor permeter
int TempPin = 5;
float temp;
static int temp_int;

// digital mux setting
int Output_Read = 2;

float Vref = 2.5;
// Used for sensor conversion
float ANALOG_SCALING = 0.004887585532746823;
//tempfloat ANALOG_SCALING=0.0049560117;

int Sensor_Value0 = 0;
int Sensor_Value1 = 0;
int Sensor_Value2 = 0;
float analog_1_pv[8];
float analog_2_pv[8];
float analog_3_pv[8];
int Status_Out[8];

//SPD & DC STATUS PIN
static int SPD_STATUS_PIN = 6;
static int DC_STATUS_PIN = 7;

int row;

int Mul_Factor = 10;

float Current_Value1[8] = {
  0.0
};
float Current_Value2[8] = {
  0.0
};
float Current_Value3[8] = {
  0.0
};

//HV perameter setting are defined here
int HV_SensorValue;
int HV_Reading;
float HV_voltage;
float Conv_HV_voltage;
unsigned  int DC_STATUS = 0;
unsigned int SPD_STATUS = 0;
float MINV_RANGE = 2.52;
//float MIDV_RANGE1=1.875;
float MAXV_RANGE = 4.5;

int SPD;
int DISCONNECTOR;

int Serial_Status=0;

int array[8][3] = {
  {
    0, 0, 0
  }
  , {
    0, 0, 1
  }
  , {
    0, 1, 0
  }
  , {
    0, 1, 1
  }
  , {
    1, 0, 0
  }
  , {
    1, 0, 1
  }
  , {
    1, 1, 0
  }
  , {
    1, 1, 1
  }
};

#endif

The simple answer is: don't.
At the moment you are trying to assign integers to chars, and that just won't fit. It's like a round peg in a square hole. Or more like trying to force a bowling pin through a hose pipe. It just isn't going to fit.
So you either need to "print" the values into your final string (say with sprintf()) or just don't build up a string at all and print the values directly. And while you're at it, use some loops to make your code simpler:
for (int i = 0; i < 14; i++) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
}

for (int i = 23; i > 13; i--) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
}

Serial.print(Temp_read);
Serial.print(",");
Serial.print(HV_Read);
Serial.print(",");
Serial.print(SPD);
Serial.print(",");
Serial.println(DISCONNECTOR);

If you really need to create a string the easiest way is probably with sprintf (or snprintf to prevent buffer overflows):
char sendBuffer[200]; // Enough room for 28 integers of 1-5 characters, plus commas.

snprintf(sendBuffer, 200, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
    Mod_current[0], Mod_current[1], Mod_current[2], Mod_current[3],
    Mod_current[4], Mod_current[5], Mod_current[6], Mod_current[7],
    Mod_current[8], Mod_current[9], Mod_current[10], Mod_current[11],
    Mod_current[12], Mod_current[13], Mod_current[14], Mod_current[23],
    Mod_current[22], Mod_current[21], Mod_current[20], Mod_current[19],
    Mod_current[18], Mod_current[17], Mod_current[16], Mod_current[15],
    Mod_current[14], Temp_read, HV_Read, SPD, DISCONNECTOR);

int len = strlen(sendBuffer);
Serial.println(sendBuffer);
Serial.print(len);
Serial.println(" bytes");

(note: I think I got the right number of parameters there)

Yes i know that. For my second case , I would like to print Serial statement based on length. It wont work above case. How can i print of specified length.thats reason i tried with String intially but memory is exceeding and controller gets restarts frequently

In that case you will need to use something like sprintf to print your values into the string. I will add an example.

@ in second command i am mentioning length of buffer . I am passing length int as argument So i can print Specified length of character


text:
Button Relay Control
How can I fix this sketch to make it so that once the button is pressed, it performs some action for a certain amount of time and then returns back to a low state until it is pressed again. For example, I need to run a pump for 5 seconds when the button is pressed and then turn off automatically. And then, when I press the button again it will repeat, etc. I am not trying to use a relay module if it is not necessary. Here is my current sketch and a Lab View of the components:

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

int switchPin = 8;
int ledPin = 13;
int buttonPresses = 0;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  pinMode(switchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  lcd.begin(16, 2);
}

boolean debounce(boolean last) //just a debounce function
{
  boolean current = digitalRead(switchPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(switchPin);
  }
  return current;
}

void loop()
{
  {currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;

    buttonPresses++;
    lcd.clear();
    lcd.print("Number of Button ");
    lcd.setCursor(0,1);
    lcd.print("Presses = ");
    lcd.print(buttonPresses);
  }
   lastButton = currentButton;
   digitalWrite(ledPin, ledOn);
  }
}

THANK YOU!

This code should work. You will need to declare the following variables:

lastPress   // The last time the button was pressed
outputState  // The state of the timed output
outputPin  // The pin number for the timed output
PERIOD  // The amount of time that the outptu remains on

The code:
void loop()
{
    currentButton = debounce(lastButton);
    if (lastButton == LOW && currentButton == HIGH)
    {
        ledOn = !ledOn;

        buttonPresses++;
        lcd.clear();
        lcd.print("Number of Button ");
        lcd.setCursor(0,1);
        lcd.print("Presses = ");
        lcd.print(buttonPresses);

        outputState = HIGH;
        lastPress = millis();
    }

    if (outputState && ((millis() - lastPress) > PERIOD))
    {
        outputState = LOW;
    }

    digitalWrite(outputPin, outputState);

    lastButton = currentButton;
    digitalWrite(ledPin, ledOn);
}

A relay should be used to drive a pump etc.. The Arduino Uno can only drive 5V at maximum 20mA.

okay so I have tried what you mentioned and have been unable to get it to run? The variable lastPress would be akin to my variable lastButton, outputState to ledOn, and outputPin, to ledPin. I am unsure how I can declare the variable PERIOD to have a time dependent value.

PERIOD can be defined in two ways:
const int period = 3000;  // 3 seconds
or
#define PERIOD 3000  //3 seconds

The if statement I have added in my answer measures the time elapsed and compares if it is larger than the period variable. If it is it will turn the output off. More info: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay and here: https://www.arduino.cc/en/Reference/Millis

Appreciate all the help


text:
Can an ATtiny print results to a console?
I'm trying to port some Arduino code that I wrote for the Arduino Mega to an ATtiny and I'm having trouble figuring out how to do output. Here is what I have:
char foo;
#include <SoftwareSerial.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial(rx,tx);

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

void loop() {
 if (mySerial.available()) {
   char data = mySerial.read();
   mySerial.write(data);
 }

 mySerial.println("hello");
}

To my understanding this should print "hello" to the console over and over again but for some reason it uploads successfully but then it doesn't do anything.
Here is the programmer that I am using to connect my ATtiny to my computer: https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/programming-in-arduino

One of the available tags for this forum is Arduino and the other it ATtiny. I don't see how it's not, but I'll copy it to the Arduino exchange if no one here knows the answer.

You need to open the serial monitor, the Arduino IDE's console only display message concerning the build and the upload status

@FortunaIwasaki check my other comment.

@MathieuL I won't be able to post another question for at least 40 minutes. Also I know about the little magnifying glass at the top right. I opened it and there was nothing there.

Which pins are you connecting the serial adapter to?

I'm using the ATtiny programmer to connect the ATtiny to my computer and to program it. I provided a link to the programmer I'm talking about at the bottom of my question.

You don't have any output because you don't have a serial adapter connected to the device. The programmer you have is only for programming and does not support a UART serial connection.

Right on point, that programmer don't have the usual ucontroller which manage the Virtual UART connection.

So in other words there is no way to deliver the output to my computer. Do you by any chance know what kind of serial adapter I can get to connect the ATtiny to my computer?

Any FTDI/PL2303/CH340G-based serial adapter should work. You should consider disconnecting the chip from the programmer before connecting it though.

@FortunaIwasaki You can transfer information to your PC with a UART to USB adapter.

Most ATtiny's do not have UART at all. So, probably, even with UART to USB adapter you would need to use some software UART.

This is writing serial data to digital pin 4. If you have a serial to USB converter attached to pins 3,4 and you have a terminal attached to said serial to USB converter, it will print to that terminal.
Also, on an ATtiny, you have to check which pins are pins 3,4. They are probably not the physical pins 3,4, and it is dependent on which pin mappings you are using (dependent on ATtiny libraries).

I'm using the ATtiny Programmer to connect my ATtiny to my computer and according to the diagram pins 3 & 4 are both analog input pins. However, I'm confused as to why the pins matter at all when all I want is for the word "hello" to be displayed in the console.

Please add a link to the ATtiny Programmer, and I will add to my answer.


text:
Fan control circuit with Arduino
I have a fan control circuit with Arduino (PWM). I did all things and it worked. My question is why we did not directly connect the fan to Arduino. Why should we have a driver circuit?

Because physics will destroy your device.

I found an answer for that since we are applying a linear control on the fan,if we we connect directly to the arduino,we would not be able to any voltage rather than 0 and 5 volts(it will act like a switch).With driver circuit,we made our fan operate between 0-12 volts using feedback. However,this answer is not enough for me ,i did not understand the exact reason.

This question is on-topic and should remain open. Programming is included but not exclusively. Boards, clones, IDEs, libraries, and more, related to Arduino, are included.

This is an electronics question, and it should be forwarded to the electronics stackexchange.
The fan needs to have a proper amount of current to spin, and because the microcontroller that controls the fan draw very little current on its output pins (check the datasheet for the exact value, but it should be a few milliamps), unless you have a miniature fan, wiring it directly on the microcontroller will not be able to move the fan.
And this is by design that microcontrollers cannot provide much current. Because to provide larger amount of current than what they do, they'd need to have bigger copper tracks between the transistor to avoid having they internal circuits building too much heat, and they would be much much bigger.
So as a work around, we use an transistor, which receives on the "Base" pin a voltage, drawing almost no current, which will "connect" the collector and emitter pins where you can have a much bigger current flowing (though be careful to respect the datasheet's nominal values for current! Or use either a MOSFET, a Triac or a Relay for bigger currents).

Arduino is a low voltage and low current device. Arduino max current output delivery capecity is 200ma, you can read about diffrent arduino's limitations here,
http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations
Fan or anything that has a coil inside it, needs a huge amount of current during their start up. The current draw decreases as it gains its motion to some limit. The initial huge current is called surge current. There is a high chance that it will blow you pins dead.
Let's say we are using really small fan. And it managed to start and rotating, that dosen't meant there is no problem at all. When a coil is rotated inside a magnetic field an opposite voltage is induced called Back Emf . This is another huge potential concern. This is why we are always suggested to use a diode which will block the opposite flow of current.
Transistor, being a low voltage device and as it can deliver tremendous large amount of output current, It is very widely used to drive high current devices

The
Vin pin = 5V or 3.3V

You cannot use the 5V from the USB to power up the FAN and the LOAD because the USB port usually delivers only 100mA, and this is not enough to switch the relay and the LOAD.
That is why you must use an external power supply (Vcc) that is between 7 to 12 volts to power up the Arduino board and the transistor + relay. The load uses its own power supply, for instance if you use a light bulb then you might connect it to the 110/220V mains or any other power source.
or
you can also use a fan that has one of the pins of the fan is a PWM input. The fan has an internal transistor to switch the 12V power when given a 0-5V input. That is the pin you want to connect to the actuator pin.
please get back to me if it was helpful

Actually the Arduino Uno dc current per I/O pin is 40mA. When fan is connected directly to Arduino Uno, it cannot withstand, because the fan draws more-than 20mA current.
The driver circuit provides sufficient current to rotate the fan. The TIP 121 can withstand up to 3A current.

I know this is an old link but MAXIM has a tutorial on using PWM to drive "normal" DC fans.  The link is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/1784
It was helpful.
Personally, I am designing a simple 5-step temperature-driven device that uses an ATtiny13A to drive a 5 volt fan and a thermistor mounted to a heatsink.  I was originally trying to use a PWM frequency of 4687Hz (CPUclk / 256) but it was way to high.  The MAXIM article states that frequencies in the range of 20Hz to 160Hz are useful.  Obviously, the 4687Hz was TOO HIGH.  I dropped it down to 18Hz and everything works now.  The problem was that the pulse width at 4687Hz was too short to give the DC fan enough electrical "momentum" to spin the fan.  Using a lower PWM frequency gives more electrical energy to the fan to get it to spin.  An analogy would be trying to push a toy car with short and rapid "pushes" as opposed to using longer and slower "pushes".
Hope this helps.
Peace and blessings.


text:
Add string inputs into an array
I have been working on this a while and I cannot seem to figure it out. Essentially, I am using the app/server Blynk and their Terminal Widget to sent String inputs to my Arduino board. My code is below:

  String INFO;
  String fromTerminal = param.asStr();
  int indexstart = fromTerminal.indexOf(",");
  int indexend = fromTerminal.lastIndexOf(",");
  int counter = indexstart - indexend;
  INFO[counter] = fromTerminal;
My thoughts on the code was, based on the number of "," I enter in the string then that will assign my input to an index within the INFO array. However as I have tried several different things, I constantly get errors such as:
cannot convert 'String' to 'char' in assignment.
Oddly enough if I set: INFO[counter] = fromTerminal.toInt();
I dont get an error but I dont think that will allow me to print out my actual input. Any help is much appreciated, thanks!

INFO isn't an array - it's a String.

Yeah so I was looking into it further, dumb oversight on my part but I guess you cant dynamically create an array. So I am just going to over initialize the array ie. INFO[20}; even when I only ever input between 5-10 strings, and then just call the index up to how many I input

I think you should better read about the String Object and don't mix this up with string as char array.

That is not an answer!


text:
Change timeout of `Serial.parseInt()`?
Serial.parseInt() reads from the serial buffer until it sees a non-numeric character or it's timeout is reached. When I use it, I put a space after the last number to make it return faster. Can I change the timeout so if I forget the number it doesn't take as long?

You can, just call
Serial.setTimeout(millisecondValue);

https://www.arduino.cc/en/Serial/SetTimeout
It defaults to one second, and controls the timeouts for readBytes, readBytesUntil, parseInt and parseFloat.

Don't use Serial.parseInt(). It is very very wrong. The whole idea behind how it operates is completely wrong and teaches bad practices and methods.
Part of your way of speeding it up is half-way to doing it properly.
You require a delimiter to say "this is the end of the number". Relying on time in a system that is inherently asynchronous is just plain daft. You have chosen to add a space. A better choice is to use a proper line ending "\n".
Then you should either read the serial character-by-character and parse it as it arrives until you find the EOL character, or read it character by character into a string (NOT a String, a "string" - a C string - a character array terminated by a NULL character), and then use atoi() etc to convert it to the numerical format you want.
Many of the methods that Arduino provide are not suitable for professional use and should be avoided at all cost lest they teach you the completely wrong way of doing things.

Isn't that just what the Serial.parseInt() function does minus the timeout?

It does one of those methods, yes, plus the timeout. It's the timeout that is evil, and the fact that you have no control over what happens. Better to read the data manually so you a) know what is happening, and b) have control over the entire situation. I have never, and will never, use things like .parseInt().

Fair enough. What if EOL get garbled in transmission somehow? You wait forever?

You wait for the next EOL. But then, if you write your code properly, you won't be "waiting", you'll be "expecting". Written properly serial reading code is non-blocking and your sketch can continue doing other things until the serial data has arrived.

Good point. I will try that.

IIRC the Serial.* methods that have timeouts are based on an assumption that while asyncronous each transmission or 'message' will be contiguous in time, i.e. its written out all at once. This obviously won't work if one wanted to use the serial port like a terminal, ex. a person typing on the other end. AFAIK embedded stuff like this often uses 'bad' practices, but justified by their environment, in that it works under these assumptions. One should be aware of this embedded 'culture' of 'bad' 'code'!


text:
Arduino wire question
I am a complete newbie to Arduino and I just received an ARDX arduino starter kit (the one that comes in the transparent green case)
I have been following the instructions for Circ-01 for the blinking led light but I am curious about the wires. In the breadboard instructional picture it shows a purple wire that is supposed to connect to pin 13 on the arduino. But the kit did not come with a purple wire, it only came with black, red, white, yellow, and green wires.
I also tried following a tutorial on YouTube and the guy in the video used a purple wire that he said was the led "cathode"
Can i substitute another wire for the purple and? Or did I receive an incomplete kit? I am very confused and the breadboard instruction picture is not very clear.
Thanks for any help!

Go buy some Quality Street. Eat one of the nice purple ones. Flatten out the wrapper. Look through it at a white wire. It now looks purple. The colour of wires makes absolutely no difference to a circuit - it is purely for humans to keep track of what is what.

Personally I like to try to use red wires for +5V, black or blue for ground, and yellow for data. However as Majenko said in a comment, the colour is irrelevant to the operation.
The usefulness of colour is just that if you stick to a system (like red for +5V and black for ground) then there is a visual check you make when connecting up a circuit, so you don't accidentally put things in backwards, like you might if every wire is yellow.
Also, if you run half-a-dozen wires from one place to another, using different colours is another way of making it easier to see you have connected the correct things together.
Having said all that, the colour does not otherwise affect things.


text:
Can't play melody and FastLED lights at same time
I'm trying to make an OO state machine based program to play music and lights at the same time. It uses the FastLED library and a 13 pixel neopixel strip.  I've confirmed that with the currently wired setup that I can separately play music and also separately run the FastLED Cylon example code. However when I upload the code below it just kinda hangs out and doesn't do anything and doesn't even print the statements in the setup statement.  The weird thing is that if I comment out the Lights lightstrip1() instantiation line and the lightstrip.Update() line, it does play the melody part ok.
#include "pitches.h"
#include "FastLED.h"

class Melody{

// notes in the melody Minuet in G.
int melody[126] = {
  NOTE_D4, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4,
  NOTE_D4, NOTE_G3, NOTE_G3,
  NOTE_E4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_FS4,
  NOTE_G4, NOTE_G3, NOTE_G3,

  NOTE_C4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_A3,
  NOTE_B3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_G3,
  NOTE_FS3,NOTE_G3, NOTE_A3, NOTE_B3, NOTE_G3,
  NOTE_A3,

  NOTE_D4, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4,
  NOTE_D4, NOTE_G3, NOTE_G3,
  NOTE_E4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_FS4,
  NOTE_G4, NOTE_G3, NOTE_G3,

  NOTE_C4, NOTE_D4, NOTE_C4, NOTE_B3, NOTE_A3,
  NOTE_B3, NOTE_C4, NOTE_B3, NOTE_A3, NOTE_G3,
  NOTE_A3, NOTE_B3, NOTE_A3, NOTE_G3, NOTE_FS3,
  NOTE_G3,

 // Second part
  NOTE_B4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_G4,
  NOTE_A4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_D4,
  NOTE_G4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_D4,
  NOTE_CS4, NOTE_B3, NOTE_CS4, NOTE_A3,
  NOTE_A3, NOTE_B3, NOTE_CS4, NOTE_D4, NOTE_E4, NOTE_FS4,
  NOTE_G4, NOTE_FS4, NOTE_E4,
  NOTE_FS4, NOTE_A3, NOTE_CS4,
  NOTE_D4,

  // BACK TO G MAJOR!!!!
  NOTE_D4, NOTE_G3, NOTE_FS3, NOTE_G3,
  NOTE_E4, NOTE_G3, NOTE_FS3, NOTE_G3,
  NOTE_D4, NOTE_C4, NOTE_B3,
  NOTE_A3, NOTE_G3, NOTE_FS3, NOTE_G3, NOTE_A3,
  NOTE_D3, NOTE_E3, NOTE_FS3, NOTE_G3, NOTE_A3, NOTE_B3,
  NOTE_C4, NOTE_B3, NOTE_A3,
  NOTE_B3, NOTE_D4, NOTE_G3, NOTE_FS3,
  NOTE_G3

  };

// note durations: 4 = quarter note, 8 = eighth note, etc.:
float noteDurations[126] = {
  4, 8,8,8,8,
  4, 4, 4,
  4, 8,8,8,8,
  4, 4, 4,
  4, 8,8,8,8,
  4, 8,8,8,8,
  4, 8,8,8,8,
  1.5,

  4, 8,8,8,8,
  4, 4, 4,
  4, 8,8,8,8,
  4, 4, 4,
  4, 8,8,8,8,
  4, 8,8,8,8,
  4, 8,8,8,8,
  1.5,

  // Second part

  4, 8,8,8,8,
  4, 8,8,8,8,
  4, 8,8,8,8,
  4, 8,8, 4,
  8,8,8,8,8,8,
  4, 4, 4,
  4, 4, 4,
  1.5,
  4, 8,8, 4,
  4, 8,8, 4,
  4, 4, 4,
  8,8,8,8, 4,
  8,8,8,8,8,8,
  4,4,4,
  8,8,4,4,
  1.5
  };

  unsigned long OnTime;  // This will be the time in millis to turn on a note.
  unsigned long OffTime; // This will be the time in millis to turn off a note.

  int ToneState;
  unsigned long previousMillis;

  int speakerPin;
  int noteNumber;
  int maxNoteNumber;

  public:
  Melody(int pin) {
     speakerPin = pin;
     pinMode(speakerPin, OUTPUT);
     previousMillis = 0;
     OnTime = previousMillis;
     ToneState = 0; // Off
     noteNumber = 0; // Start at the first note.
//     maxNoteNumber = sizeof(noteDurations); // This turns out to 504 for some reason.
     maxNoteNumber = 125;

  }

  void Update() {
     unsigned long currentMillis = millis();

     if (ToneState == 0 && currentMillis >= OnTime) {
       tone(speakerPin, melody[noteNumber]);
       OffTime = currentMillis + (1000 / noteDurations[noteNumber]);
       ToneState = 1;
       Serial.print(noteNumber);
       Serial.print("/");
       Serial.println(maxNoteNumber);

     } else if (ToneState == 1 && currentMillis >= OffTime) {
       noTone(speakerPin);
       OnTime = currentMillis + ((1000 / noteDurations[noteNumber]) * 0.30);
       ToneState = 0;
       if (noteNumber < maxNoteNumber) {
         noteNumber += 1;
       } else {
         Serial.println("RESET");
         noteNumber = 0; // Reset to the begining of the song.
       }
     }
  }
};

class Lights {
    int ledPin;
        int ledCount;
    unsigned long NextOn;
        int led_R;
        int led_G;
        int led_B;

        CRGB leds[12];

    int ledOn;
        int lightdelay;

    public:
    Lights(int pin, int ledcount, int led_r, int led_g, int led_b) {
      ledPin = pin;
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, LOW);
      ledCount = ledcount;
      led_R = led_r;
      led_G = led_g;
      led_B = led_b;
      ledOn = 0;
      lightdelay = 100;
      NextOn = 0;
      FastLED.addLeds<NEOPIXEL, 7>(leds, ledCount); // It complains if I try to use a variable for the 7. It has to be a constant.
      for (int i = 0; i < ledCount; i++) {
        leds[i] = CRGB::White;
      }
      FastLED.show();
    }

    void Update() {
      unsigned long currentMillis2 = millis();

      if (currentMillis2 > NextOn) {
         if (ledOn >= ledCount) {
           leds[ledOn] = CRGB::Black;
           ledOn = 0;
           leds[ledOn] = CRGB::Red;
         } else if (ledOn == 0) {
           leds[ledCount - 1] = CRGB::Black;
           leds[ledOn] = CRGB::Red; // Need to put RGB to HSV converter in later.
         } else {
           leds[ledOn - 1] = CRGB::Black;
           leds[ledOn] = CRGB::Red; // Need to put RGB to HSV converter in later.
         }
         Serial.print("LED: ");
         Serial.println(ledOn);
         Serial.println(NextOn);
         FastLED.show();
         NextOn = currentMillis2 + lightdelay;
         ledOn++;
      }
    }

};

Melody melody1(2);

Lights lightstrip1(7, 12, 250, 0, 0);

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

void loop() {
   melody1.Update();
   lightstrip1.Update();
}

Any ideas?

Are you sure the program is uploading properly and you haven't run out of memory or something daft like that?  (Of course that wouldn't explain why it runs when you comment things out, unless the compiler is optimising things away).

Well, I'm not 100% sure, but its not erroring out and it says the program is only using about 5K (out of 32K) of memory. This is on an Arduino Uno by the way.

Can you comment out JUST the "lightstrip1.Update();" line and see if it works. Then, put that line back in and comment out JUST the "melody1.Update();" line.  That way you can see if the problem is in the constructors or the Update functions.

You could try your luck with Adafruits' NeoPixel library. I also highly advise to use const unsigned char as the type of noteDurations (and simply multiply by 2. This will save you quite some room and avoids floating point math. And depending on the type of a single note int melody[126] could better be const unsigned char or const unsigned int.

What type of Arduino do you have? 32K SRAM is pretty nice? You're probably confusing SRAM and PROGRAM/Flash memory. An Arduino Uno only has 2kbyte of SRAM (so you can save only 2.000 bytes of variables).

sizeof(noteDurations); // This turns out to 504 for some reason.
Yes. sizeof gives you the length, in bytes. So only the note durations already use 0,5KB of your precious 2KB RAM. An float is 4 bytes.

Thanks for all the comments, suggestions and cool tricks to bring memory consumption down. I can also reduce the pitches array size to be a char array by taking it down 2 octaves and then multiplying by 4 on the fly.

I asked on the FastLED library github page and they provided me with the correct instantiation for the object:
Lights *lightstrip1;

void setup() {
  lightstrip1 = new Lights(7,13, 250, 0, 0);
}

void loop() {
  lightstrip1->Update();
}

It now works fine and plays the music and the lights simultaneously without issue.

The WS2812 device requires precise timing down to +/- 150 x 10-9 seconds.  For details look at this chip specification.  As such, it is likely the FastLED library uses processor resources that can not be shared.  Look through the FastLED library's code to verify this.
It appears your sketch plays a note, changes the LED pattern then repeats this cycle.  Assuming the resources for FastLED are initialized in the constructor of the library, you might consider destroying and re-instantiating the FastLED class for each of these cycles.
added later...
Comments about memory space and large amounts of static data in the sketch have merit.  Consider moving your static (unchanging) data from limited RAM to FLASH memory.  This resource explains how this is accomplished.

Hmmm, understand what you are saying but I would think if this were the problem that commenting out the melody1.Update line would still allow the lights to update, but it doesnt. It's almost like the object instantiation of the lights object is crashing the Arduino. I say this because it doesn't print the lines on serial in the setup statement if I have the lights enabled.

I think to understand what is happening and how to fix it, you would have to analyze the FastLED library, the built in millis() function and the Atmel chip specification. Although the comments about limited RAM space has merit.  You said you can control the LEDs if you remove all other code.  But what happens when you put back (only) the large arrays?  Will the LEDs still work?

You have a good idea. When I have time, I think I will build a version that doesn't have the melody part in it at all to see if the FastLED library can handle being updated from an object.  I'm beginning to think this is the problem.


text:
Serial Request error
I am working on arduino Uno board.I am trying to send request Serially from out Side using docklight.I am sending COmmand  is request send every 5S to 10S and get response.When i tested this code with arduino Uno board its working fine. When i tested same code with Customised board whos schematic as below
. For this i got response like this. I am suspecting it might be issue with crystal. I have replace KDS16 with SCTF16.00crystals . It behave same.Can someone suggest what might be wrong

My code
#include "glob.h"
const int BUFFER_SZ = 32;
char sendBuffer[200];
static int OverRide=0;

void Take_Reading() {

  for (int row = 0; row < 8; row++)
  {
    //   // get rid of me:
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    delay(50);
    analog_1_pv[row] = ANALOG_SCALING * analogRead(A0);
    analog_2_pv[row] = ANALOG_SCALING * analogRead(A1);
    analog_3_pv[row] = ANALOG_SCALING * analogRead(A2);
    if ( (analog_1_pv[row] <= MINV_RANGE || (analog_1_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value1[row] =  0.0;
    }
    else
    {
      Current_Value1[row] =  (analog_1_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_2_pv[row] <= MINV_RANGE || (analog_2_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value2[row] =  0.0;
    }
    else
    {
      Current_Value2[row] =  (analog_2_pv[row] * 12.5) - 31.25;

    }

    if (  (analog_3_pv[row] <= MINV_RANGE || (analog_3_pv[row] >= MAXV_RANGE) ))
    {
      Current_Value3[row] =  0.0;
    }
    else
    {
      Current_Value3[row] =  (analog_3_pv[row] * 12.5) - 31.25;

    }

    Mod_current[row] = (uint16_t)(Mul_Factor * Current_Value1[row]);
    Mod_current[row + 8] = (uint16_t)(Mul_Factor * Current_Value2[row]);
    Mod_current[row + 16] = (uint16_t)(Mul_Factor * Current_Value3[row]);

  }

}

int ID_Check() {

  int ID_value;
  for (int row = 0; row < 8; row++)
  {
    digitalWrite(SO_enable, array[row][0]);
    digitalWrite(S1_enable, array[row][1]);
    digitalWrite(S2_enable, array[row][2]);
    Status_Out[row] = digitalRead(Output_Read);

  }

  ID_value = 1 * Status_Out[7] + 2 * Status_Out[6] + 4 * Status_Out[5] + 8 * Status_Out[4] + 16 * Status_Out[3] + 32 * Status_Out[2] + 64 * Status_Out[1] + 128 * Status_Out[0];
  return (ID_value);

}

int  Take_Temp_Reading()
{

  Temp_Total = Temp_Total - Temp_readings[Temp_index];
  Temp_readings[Temp_index] = analogRead(A5);
  Temp_Total = Temp_Total + Temp_readings[Temp_index];
  Temp_index = Temp_index + 1;

  if (Temp_index >= numReadings)
  {
    Temp_index = 0;
    Temp_Average = Temp_Total / numReadings;
  }
  temp = (Temp_Average * 5.0) / 1023.0;

  //  temp = float(analogRead(A5)) * 5.0 / 1024.0;
  temp_int = (int)(temp * 100.0);
  return (temp_int);
  // Serial.print("Temp"); Serial.println(temp);
}

int SPD_Check()
{

  SPD_STATUS = digitalRead(SPD_STATUS_PIN);
  return (SPD_STATUS);
}

int  DC_Status()
{

  DC_STATUS = digitalRead(DC_STATUS_PIN);
  return (DC_STATUS);

}

int   Take_HV_Reading()
{

  //int analog_int= analogRead(A4);

  total = total - readings[index];
  // read from the sensor:
  readings[index] = analogRead(A4);
  // add the reading to the total:
  total = total + readings[index];
  // advance to the next position in the array:
  index = index + 1;

  // if we're at the end of the array...
  if (index >= numReadings1)
  {
    index = 0;
    average = total / numReadings1;

  }
  else
  {

    HV_voltage = (average * 5.0) / 1023.0;
  }
  if (HV_voltage <= 0.25)
  {

    Conv_HV_voltage = 0.0;
  }
  else
  {
    Conv_HV_voltage = 197.837837838 * HV_voltage + 10.8108108108;
  }

  HV_Reading = (uint16_t)(Conv_HV_voltage * 10);

  //  HV_Reading = (uint16_t)(Conv_HV_voltage * 10);

  return(HV_Reading);
}

void  Serial_Command1()

{
  Take_Reading();
  int Temp_read=Take_Temp_Reading();
  int HV_Read=Take_HV_Reading();
  SPD=SPD_Check();
  DISCONNECTOR=DC_Status();
  // Device_ID=ID_Check();
  Device_ID=1;
  Serial.print("SMCB1");
  Serial.print(",");
  Serial.print(Device_ID);
  Serial.print(",");
  for (int i = 0; i < 14; i++) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
  }

  for (int i = 23; i > 13; i--) {
    Serial.print(Mod_current[i]);
    Serial.print(",");
  }

  Serial.print(Temp_read);
  Serial.print(",");
  Serial.print(HV_Read);
  Serial.print(",");
  Serial.print(SPD);
  Serial.print(",");
  Serial.print(DISCONNECTOR);
  Serial.print(",");
  Serial.print(DISCONNECTOR);
  Serial.print(",");
  Serial.println("END");
}

void Serial_Command2(int a)
{
  Take_Reading();
  int Temp_read=Take_Temp_Reading();
  int HV_Read=Take_HV_Reading();
  SPD=SPD_Check();
  DISCONNECTOR=DC_Status();
  Device_ID=1;
  // Serial.print("Command2 executed: ");
  snprintf(sendBuffer, a, "SMCB1,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ,END",Device_ID,
  Mod_current[0], Mod_current[1], Mod_current[2], Mod_current[3],
  Mod_current[4], Mod_current[5], Mod_current[6], Mod_current[7],
  Mod_current[8], Mod_current[9], Mod_current[10], Mod_current[11],
  Mod_current[12], Mod_current[13], Mod_current[14], Mod_current[23],
  Mod_current[22], Mod_current[21], Mod_current[20], Mod_current[19],
  Mod_current[18], Mod_current[17], Mod_current[16], Mod_current[15],
  Mod_current[14], Temp_read, HV_Read, SPD, DISCONNECTOR);
  Serial.println(sendBuffer);
  //Serial.println(a);
}

void setup()
{
  Serial.begin(57600);
  Serial.println("Format 1: <SMCB1,1>");
  Serial.println("Format 2: <SMCB1,1,Length>");
  Serial.println("Format 2: <SMCB1,1,Length,ON> ON- turn on timer ,off to turn off timer");
}

// Parse the request, WITHOUT the '<' and '>' delimiters.
void parseRequest(char *request)
{
  // Check the request starts with the prefix "SMCB1,1".
  if (strncmp(request, "SMCB1,1", 7) != 0) {
    Serial.println(F("Error: bad request prefix"));
   //  Serial_Command1();
    return;
  }

  // Remove that known prefix.
  // Now we have either "", ",Length" or ",Timer,On_OFF"
  request += 7;

  // Format 1: ""
  if (request[0] == '\0') {
    //Serial.println(F("Received format 1"));
    Serial_Command1();
    return;
  }

  // Remove the leading comma.
  // Now we have either "Length" or "Timer,On_OFF"
  if (request[0] != ',') {
    Serial.println(F("Error: ',' expected"));
    return;
  }
  request++;

  // Format 2: "Length", no comma.
  char * comma = strchr(request, ',');
  if (!comma) {

    int length = atoi(request);
    Serial_Command2(length);
    //Serial.print(F("Received format 2, length = "));
    // Serial.println(length);
    return;
  }

  // format 3
  int timer = atoi(request);
  char * on_off = comma + 1;
  char * Compare="ON";
  bool on = strcmp(on_off, "ON") == 0;
  if (!on && strcmp(on_off, "OFF") != 0) {  // sanity check
    Serial.println(F("Error: expected either ON or OFF"));
    return;
  }
  /*  Serial.print(F("Received format 3, timer = "));
   Serial.print(timer);
   Serial.print(F(", on_off = "));
   Serial.println(on ? "ON" : "OFF");
   Serial.println(on_off);
   Serial.println(Compare);*/
  int v = strcmp(on_off, Compare);
  if(v==0)
  {
    Serial.println("Timer is on");
    OverRide=1;

  }
  else
  {
    Serial.println("Timer is OFF");
    OverRide=0;
  }

}

void loop()
{
  static char buffer[BUFFER_SZ];  // received chars
  static size_t pos;              // current position in buffer
  static bool insideRequest;      // are we between '<' and '>'?

  if (Serial.available()) {
    char c = Serial.read();
    if (insideRequest) {
      if (c == '>') {  // end of request received
        buffer[pos] = '\0';  // terminate the string
        parseRequest(buffer);
        pos = 0;             // get ready for the next request
        insideRequest = false;
      }
      else if (pos < BUFFER_SZ-1) {  // add char to buffer
        buffer[pos++] = c;
      }
    }
    else if (c == '<') {  // start of request
      insideRequest = true;
    }

  }

}

Test your custom board with a much simpler sketch, for example one that just gives a simple serial output or maybe counts, and edit exactly what you receive compared to what is expected into your question.  It is worrisome that there does not seem to be a ground connection on the serial header on this custom board - you must have a common ground with the other end of the serial link.

i dont have problem in receving data. I tested already. I am printing Serial statement for Every 1S-10S code seem wok fine.

I tested code with Simple [print statement . Where i can able to receive data without any garbage value or miss of data.Yes i have connected Common Ground connection.I am worried code working fine over Arduino not over customised board.Whenever change crystal ,For some crystal more response coming normally.i.e out of 10 request i am getting error for 2

Could you post a photo of the board? The traces to the crystal might be too long e.g.. Could you use a lower speed, than 57600 baud.

@Gerben This baudrate required to communicate with Wifi device. WIth same board out of 10 board 3 boards are working as i expected. But remaining boards have same Serial print issue. Either it wont print data or Taking request with Data missed.

Could you post a photo of the board?


text:
Converting an array of uint8_t to a char array
I'm trying to convert this array uint8_t data[] in the code below to a character array to be printed in the serial monitor. However, when I run this code I see a blank screen. What am I doing wrong?
Serial.begin(115200);
uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x01,0x02,0x03,0x04,0x05};
Serial.println((char*)data);

In what way do you want to "print" it? Converting it to char * just makes the compiler think it's a string, which it isn't. Those aren't the ASCII values of printable characters.

When you cast as char *, println thinks you are passing it a string. It will try to print it as a string and stop on the first 0x00.
You can use Serial.write to send the array as integers (no conversion):
Serial.write(data, sizeof(data));

If you want to send the ASCII representation of these numbers, use a loop. Serial.print will convert:
int count = sizeof(data) / sizeof(data[0]);
for (int i = 0; i < count; i++) {
    Serial.print(data[i]);
}
Serial.println();

A quick Q: Why are you dividing sizeof(data) by sizeof(data[0])? Wont just sizeof(data) suffice?

sizeof(data) gives you the size of the array in bytes. What I did gives the number of items in the array.

To print numbers, integers have to be converted to ASCII code.  To accomplish this add 0x30 to each value.  Note, this (only) works for numbers between 0 and 9 as the ASCII value for zero is 0x30.  Good code will check to make sure only the values 0 through 9 are being processed.
When creating a character string you need to identify the end using the NULL character.  Before using an array of characters, set the array position after the last desired character equal to NULL or 0x00. Terminating the string is explained further in this article.


text:
How to handle multiple simultaneous Arduino development environments?
I am developing for several different target microcontrollers (on OS X 10.11), which requires some unique combinations of (Arduino) IDE version, library versions, USB drivers, support software, etc.
What are the pros and cons of using separate logged-in users for each environment as opposed to using Virtual Machines? Are there other methods commonly in use to separate environments, and also keep the environments archived for any legacy needs?
Update: I also have a desire to keep these environments as standard as possible: installing released components (e.g., IDE, drivers) and customizing IDE app settings, but trying to avoid source-level forks. This is for my own sanity, and to give best chance of replicating the environment in the future.

That sounds horrible. What about 1.6.x doesn't let you handle all the boards?

Even within 1.6.x there is a lot of variability between versions which can make things simply not work, especially for many alternate-hardware plugins.  The "ordinary" Arduino installation organization for extensions and libraries is pretty seriously broken for any serious software development, being able to specify a custom library path would be a big help.  Not needlessly complaining about .git folders would be a help, too.

You might be able to get custom per-version libraries/ and hardware/ folders by changing the sketchbook directory, the problem is that all versions from 1.5 on seem to want to store such configuration in the same place such as ~/.arduino15/preferences.txt - and it's not clear how you could change that without modifying the source or binary or playing some game like process-unique mounts (which are generally inheritable by children)

You can run multiple versions of the IDE just fine. Just rename Arduino.app to e.g. Arduino-1.5.app. For the different libraries, you can just put the libraries into the app-package /Applications/Arduino.app/Contents/Java/libraries , instead of the regular libraries folder ~/Documents/Arduino/libraries.

@ignacio-vazquez-abrams, the other issue is wanting to avoid regression testing each working environment when updating IDE, libraries, etc. for just one. I'd like to pre-test updates in a non-production clone.

I'm yet to see evidence that there is a sound or comprehensive way to do this, so would be pleased to read better suggestions.  As for why you would want to, there are a number of board support plugins/extensions that are moderately functional on some recent Arduino versions, but partially or entirely incompatible with others.
You can achieve a very limited partial version segregation by creating a new sketchbook folder for each version, which would host your libraries and hardware folders.
To get the IDE to pick this up, you could have a custom preferences file (rather than preferences.txt) with that sketchbook location set.  You can specify the file to use on the command line, for example:
/opt/arduino-1.6.8/arduino --preferences-file ~/.arduino15/alternate.txt

However, there is still quite a bit related to extra board support and similar stored in the settings folder, and at present that is hard coded to the same "Arduino15" or ".arduino15" path for all recent versions.
This hard-coding of the settings folder is implemented in the version of Platform.java applicable to the operating system you are running under, so it is not clear how you could change this except at the source level, by modifying the jar, or by playing file-system level tricks with the operating system (process-unique mounts, etc).

Thanks for your helpful comments and answer. I'll wait to see if someone chimes in specifically about VMs vs. users, etc. (I haven't tried yet, so I'm not even positive if VMs will have issues of their own, but I'm hopeful). I'll also edit my question to include my desire to keep each environment as standard an install as possible (so I don't go insane keeping track of meta-customizations).

Either distinct user ID's (with the whole installation in a user-specific directory) or VMs would probably work pretty well... sorry I skipped over that, I just don't really consider it a reasonable thing to have to resort to for everyday development.

I ended up running arduino-buider, available in Arduino IDE 1.6.6 and newer.
When laying out your project, put a libraries/ and hardware/ folder along side your sketch directory, like so:
YourHipProject/
    Makefile
    hardware/
        Vendor/arch/{boards.txt,platform.txt}
    libraries/
        SomethingUseful/
        NoIdeaHowThisWorks/
    ProjectSketch/
        ProjectSketch.ino
        othersource.cpp

The hardware/ directory is only needed if you need support for 3rd party boards. Then, in the Makefile:
ARDUINO_DIR ?= /opt/arduino-1.6.13 # need to set this for your environment

.PHONY: ProjectSketch

ProjectSketch:
    arduino-builder -compile -verbose \
        -hardware $(ARDUINO_DIR)/hardware \
        -tools $(ARDUINO_DIR)/tools-builder \
        -tools $(ARDUINO_DIR)/hardware/tools/avr \
        -built-in-libraries $(ARDUINO_DIR)/libraries \
        -hardware ./hardware \
        -libraries ./libraries \
        -fqbn=Vendor:arch:board \
        ./ProjectSketch/ProjectSketch.ino

ARDUINO_DIR needs to point to where your Arduino is installed, be sure to set -fqbn= correctly too.
Running make should compile the firmware from ProjectSketch/ with the accompanying libraries and hardware definitions. Also, with verbose compile output enabled, the Arduino IDE will show you how it runs arduino-builder.


text:
Is it possible to run 2 functions, that communicate with 2 different serial devices, in parallel using FreeRtos library?
This might seem like a very broad question but that's what i want it to be for multiple ways of implementation.
I've an Arduino UNO communicating with 2 Serial devices interfaced using SoftwareSerial flawlessly. I've used [SS_Object].listen() function to switch between the two. Right now, the entire code works sequentially meaning that, once it's work with the 1st Serial device is done, only then it will switch to the 2nd Serial device and work with it. Can i communicate with the 2 in parallel (Multitasking) using FreeRtos? I've heard that the scheduler switches between tasks when it encounters a delay. So may be a small useless delay is required, only for the scheduler, to switch between the two. May be! or May be things will be better if i use more advanced Arduino like Mega or Due.
Thanks for taking your time to read this. Please answer the question the way you've understood it as i am sure different people with different experiences will interpret this differently.
Thanks in advance!

You really should pick a chip with multiple hardware UARTs for that.

Yep. that's what i thought. Thanks! @Stratton

It is unlikely that FreeRTOS will allow you to do that. SoftwareSerial uses busy loops with interrupts disabled, which means it cannot be interrupted or preempted by the RTOS (or by anything for that matter).
If you want two serial connections in parallel, at least one of them should be done in hardware.


text:
wifi failled connection with yun and after upgrading openwrt
I recently bought an arduino yun. When trying to connect to the router following the procedure in https://www.arduino.cc/en/Guide/ArduinoYun#toc14. After the Configure & Restart, the Arduino network shut down after a few moments but it wasn´t linked to my router.
After reading a bit about it in the internet, i upgraded it following https://www.arduino.cc/en/Tutorial/YunSysupgrade. As i found that the firmware version 1.5.3 was from 2014 https://github.com/arduino/openwrt-yun/blob/master/ChangeLog, and as Reflashing the OpenWrt-Yun image on the Yún would void warranty, i proceeded by http://nootrix.com/software/upgrade-arduino-yun-openwrt/. Everything occured as detailled there.
However now, when i turn on the yún, none network appear and the WLAN LED doesn't blink.
Thanks

Find out if the Linux system is running. Maybe you mistyped your WiFi password.
Try the Following:

connect via Ethernet check your router to see if the Yun request an IP via DHCP
If unsuccessful connect via USB and install this sketch to see if you get a command prompt maybe your network settings are messed up

Still no success?

Press the WiFi reset button for at least 30 seconds to do a reset to
factory defaults.


text:
Printing Time to Serial Port
I am reading sensory data that comes from the digital inputs(two DHT11 Humidity sensors using adafruit library.) and I would like to add a hh:mm:ss real time counts next to them. I try to use the time.h library but could not understand how to worked it in that way.
My code is;
#include "DHT.h"

#define DHT1PIN 4
#define DHT2PIN 7

#define DHT1TYPE DHT11
#define DHT2TYPE DHT11

DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("Humidity sensors DHT11 tests!");

  dht1.begin();
  dht2.begin();
}

void loop() {

  delay(2000);

  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature();

  if (isnan(t1) || isnan(h1)) {
    Serial.println("Failed to read from DHT #1");
  } else {
    Serial.print(h1); Serial.print(" \t");
  }

  if (isnan(t2) || isnan(h2)) {
    Serial.println("Failed to read from DHT #2");
  } else {
    Serial.print(h2);
    Serial.print(" \t");
  }
  Serial.println();
}

and my serial port out is;

and I want it to be like that;

Any help will appreciated.

Did you add a RTC to the circuit?

No I want it to read the clock from compter.

Then there's no way the Arduino can know the time. Write a custom host-side program.

Isn't there a way to know the time of data that printed on a serial?

Sure. The host will know. But that means a host-side program.

So no way to print it to serial window, thanks.

Like he said, there is a way to print it but it would require a program running on your PC; the Arduino is not omniscient, your PC keeps track of the current time whereas the Arduino only knows about time as it relates to executing instructions, therefore your PC has to either inform the Arduino of the time when the sketch first begins to run, and let the Arduino regularly update the time on its own or, even better, your PC program should listen to the serial port and print the current time in addition to whatever DHT sensor data it receives from the Arduino.

http://unix.stackexchange.com/questions/104834/how-to-log-serial-data-with-time-stamp

I solved the problem by using millis() function. And now I ca get results like these;

My code is;
#include <Sensirion.h>
#include "DHT.h"
unsigned long time;

#define DHT1PIN 4
#define DHT2PIN 7

#define DHT1TYPE DHT11
#define DHT2TYPE DHT11

DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);

const uint8_t dataPin =  9;              // SHT serial data
const uint8_t sclkPin =  8;              // SHT serial clock
const uint8_t ledPin  = 13;              // Arduino built-in LED
const uint32_t TRHSTEP   = 1000UL;       // Sensor query period
const uint32_t BLINKSTEP =  250UL;       // LED blink period

Sensirion sht = Sensirion(dataPin, sclkPin);

uint16_t rawData;
float temperature;
float humidity;
float dewpoint;

byte ledState = 0;
byte measActive = false;
byte measType = TEMP;

unsigned long trhMillis = 0;             // Time interval tracking
unsigned long blinkMillis = 0;

void setup() {
  dht1.begin();
  dht2.begin();
  Serial.begin(9600);
  Serial.println("In.(%) In.Tem(*C) Out.(%) Time");
  pinMode(ledPin, OUTPUT);
  delay(15);                           // Wait >= 11 ms before first cmd
  // Demonstrate blocking calls
  sht.measTemp(&rawData);              // sht.meas(TEMP, &rawData, BLOCK)
  temperature = sht.calcTemp(rawData);
  sht.measHumi(&rawData);              // sht.meas(HUMI, &rawData, BLOCK)
  humidity = sht.calcHumi(rawData, temperature);
  dewpoint = sht.calcDewpoint(humidity, temperature);
  logData();
}

void loop() {

  unsigned long curMillis = millis();          // Get current time

  // Rapidly blink LED.  Blocking calls take too long to allow this.
  if (curMillis - blinkMillis >= BLINKSTEP) {  // Time to toggle the LED state?
    ledState ^= 1;
    digitalWrite(ledPin, ledState);
    blinkMillis = curMillis;
  }

  // Demonstrate non-blocking calls
  if (curMillis - trhMillis >= TRHSTEP) {      // Time for new measurements?
    measActive = true;
    measType = TEMP;
    sht.meas(TEMP, &rawData, NONBLOCK);      // Start temp measurement
    trhMillis = curMillis;
  }
  if (measActive && sht.measRdy()) {           // Note: no error checking
    if (measType == TEMP) {                  // Process temp or humi?
      measType = HUMI;
      temperature = sht.calcTemp(rawData); // Convert raw sensor data
      sht.meas(HUMI, &rawData, NONBLOCK);  // Start humidity measurement

      float h2 = dht2.readHumidity();
      float t2 = dht2.readTemperature();

      Serial.print(humidity);
      Serial.print(" \t");
      Serial.print(temperature);
      Serial.print(" \t");

      if (isnan(t2) || isnan(h2)) {
        Serial.println("Failed to read from DHT #1");
      } else {
        Serial.print(h2);
        Serial.print(" \t");

        //time = millis();
        //prints time since program started
        Serial.println(curMillis);
      }
      Serial.println();
    }
    else {
      measActive = false;
      humidity = sht.calcHumi(rawData, temperature); // Convert raw sensor data
      dewpoint = sht.calcDewpoint(humidity, temperature);
      logData();
    }
  }
}

void logData() {
}

But the difference is that I am using SHT75 instead of another DHT11 so I am simultaneously acquiring data from the both of them. Thanks for everyone!


text:
Router with arduino
Is it possible to send and receive data from a normal router using arduino? I need to create a little device that uses a router to communicate with a remote. It's a close circuit.

Please read How do I ask a good question?

If you have a network interface (wired or wireless), yes, of course it is.
Look into the ESP8266, and ESP-12E-based boards such as the Adafruit Huzzah; they can be programmed in an Arduino environment, and have built-in wifi.

I need a normal router. Like the one you would you at home but a lot more powerful.

How powerful your router is is irrelevant. The problem is connecting to the Arduino. The standard boards don't have a network interface; you need an ethernet or wireless shield for that, but there are arduino-compatible boards, usually based on the ESP8266, that have built-in wifi.

So I can do it, directly or not!

Yes ,You CAN.
Use ESP 8266-07.Its a very good Wi-Fi module.You juts need to install ESP8266 board file in Arduno IDE.
For board file installation and some basic tutorial , just
Click here
Its helpful I think.