text:
Interrupt not firing on motion
I'm trying to get MMA8452Q to trigger an interrupt when motion is detected and wonder if I'm missing something very obvious here.
So I setup CTRL_REG4 to 0x0B with
void MMA8452Q::setupISR()
{
    writeRegister(CTRL_REG4, 0x0B);
}

then I setup FF_MT with
void MMA8452Q::setupFF_MT()
{
    writeRegister(FF_MT_CFG, 0xF8);
    writeRegister(FF_MT_THS, 0x0F);
    writeRegister(FF_MT_COUNT, 0x00);
}

and I read ISR with
#define SRC_PULSE 2
#define SRC_FF_MT 1

byte MMA8452Q::readISR()
{
    byte intStat = readRegister(INT_SOURCE);

    if (intStat & 0x0B)
    {
        readRegister(FF_MT_SRC);
        return intStat & 0x0B;
    }
    else
        return 0;
}

void printISR()
{
  byte isr = (accel.readISR() >> 2);
  if (isr & SRC_PULSE)
    Serial.print("(ISR) Tap");
  else
    Serial.print("(ISR) No Tap");

  Serial.print("\t");

  if (isr & SRC_FF_MT)
    Serial.print("(ISR) Motion");
  else
    Serial.print("(ISR) No Motion");

  Serial.print("\t");
}

AFAIK, that should already have FF/MT interrupt enabled. Even when I'm getting readings in FF_MT_SRC, I'm not picking up an interrupt in INT_SOURCE.
Interrupts are fired on (most) taps, but not on motion at all.
Am I missing something here?
Thanks

Please post all your code. Do not do serial prints inside an ISR. Read: Interrupts

@NickGammon I've updated my post with the full code now. Re. serial prints, am I doing serial prints inside an ISR? I read the ISR first and then print. The ISR would have finished processing - right?

Kar, I may have missed something, but in what you've posted I don't see any setup() or loop() routines as often found in Arduino sketches.  Without that code it isn't clear what routines are being called when.  Also, you haven't shown how the MMA8452Q is connected to your Uno.  Is an interrupt wire from the 8452 connected to the Uno?  Absent other info, it looks like MMA8452Q::readISR() is not an interrupt processing routine, but instead a routine that polls an interrupt-source register to find out what source would have triggered an interrupt if correctly wired and initialized

Kar, re setup() & loop(),  I'd overlooked a block of code.

Here's an extract from page 39 of MMA8452Q-rev8.1.pdf, the MMA8452 spec sheet:

Rather than saying writeRegister(CTRL_REG4, 0x0B); in MMA8452Q::setupISR(), try writeRegister(CTRL_REG4, 0xD);.
0xB is 1011 in binary, while 0xD is 1101, which turns on INT_EN_FF_MT to enable freefall/motion interrupts.
The above should answer your question as asked.  The following expands on my earlier comment which said

Absent other info, it looks like MMA8452Q::readISR() is not an interrupt processing routine, but instead a routine that polls an interrupt-source register to find out what source would have triggered an interrupt if correctly wired and initialized.

"Interrupt" as used in your question (and code) refers to when the MMA8452 signals (via an I1 or I2 output line) that an interrupt-worthy condition has occurred.
"Interrupt" as in the question does not refer to an interrupt from the Uno's point of view, because (per diagram) neither of I1 or I2 connects to the Uno.
If speed of response becomes important, you may wish to hook I1 or I2 to one of the Uno's Digital Pins With Interrupts, ie pin 2 or 3, as noted in the AttachInterrupt page at arduino.cc.  Then you'd replace the polling loop that now periodically reads the MMA8452's ISR (interrupt status register) to check for set bits, with an interrupt service routine which would set a flag to cause loop() to use Wire.read to get ISR data.

Ah yes, I was about to say something to this effect. Your code does not actually use interrupts, so I am not surprised it is missing things. Your terminology of "reading the ISR" was confusing. The chip appears to actually generate interrupts, which you should connect to a pin as jwpat7 suggested.

Kar -- note that if your Uno's V+ is 5V, use a Logic Level Converter between it and the MMA8452.  Sparkfun's BOB-12009 is bidirectional if the i/o's it connects are implemented with  open-collector/open drain.


text:
Why doesn't the LED turn on in this circuit?
I'm experimenting with buttons and LEDs and I would like my code to change a LED's brightness once a button is pressed. I connect the LED to the PWD digital pin.
My circuit looks like this one:

This is the code I'm using:
int switchPin = 8;
int ledPin = 11;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;

void setup() {
    pinMode(switchPin, INPUT);
    pinMode(ledPin, OUTPUT);
}

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

void loop() {
    currentButton = debounce(lastButton);
    if (lastButton == LOW && currentButton == HIGH) {
        ledLevel = ledLevel + 51;
    }
    lastButton = currentButton;

    if (ledLevel > 255) ledLevel = 0;
    analogWrite(ledPin, ledLevel);
}

Though, the LED never turns on, but the light on the Arduino is on. I made sure the leads of the LED were in the right spot. Why doesn't the LED turn on?

Because you don't actually have a circuit?  One side of the LED doesn't connect to anything.

Thanks a lot for your answer, Majenko. Do I have to use a wire to connect things. Could you please propose a fix for this? Thanks. As you figured out, I'm very new to this.

One leg of the LED connects to the strip with a red line painted next to it.  That then doesn't connect to anything unless you connect it to something.  You should connect it to either +5V or GND depending on which way round your LED is.  I can never tell which way the LEDs are in those awful fritzing drawings.

Those breadboards do not automatically connect the top red line to the bottom red line (nor the blue ones). You have to do that yourself, if that is what you want.

source: Stack Exchange

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

sort: votes


text:
Why char 0x80 == 0xFFFFFF80?
As far as I know a char is an 8 bit variable

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

void loop() {
  char x = 0x80;
  if(x != 0x80){
    Serial.println(x, HEX);
  }

  delay(1000);
}

To illustrate the reasons better let's look at the actual content of the data.
0x80 is 0b10000000 in binary. A char is a signed variable, which means that the most significant bit is the sign bit, with two's complement representation
So in 8-bit signed representation the value 0b10000000 is a sign bit and zero value - which is -128 in decimal notation, which is "-128 + the 7 least significant bits", or -128 + 0 in this case.
When you print a signed value on the Arduino as HEX there is no 8-bit specific function for it. Neither is there a 16 bit function. However there is a 32-bit signed function, which is the closest match available. So the compiler performs type promotion to 32-bit signed, then represent it as hexadecimal.
Now -128 in signed 32-bit is calculated in the same way - take the value of the most significant bit, negate it, and add the value of all the other bits to it.  With 32-bits the value of the most significant bit, in decimal, is 2147483648, so negate that into -2147483648. Now we need to make that into -128, so we need the difference between the two to add to it. That's 2147483520.
So you get the MSB + 2147483520, which in hexadecimal, is 0xFFFFFF80.
Of course, the compiler doesn't go through that whole routine - instead it uses something called sign extension. This method basically means copying the sign bit from the original smaller (char) type into every bit to the left of it in the larger type:
                           10000000 8 bit signed
                  11111111 10000000 16 bit signed
11111111 11111111 11111111 10000000 32 bit signed

All those are -128 in two's complement, just stored in different size variables. So when you come to print it, that is just what you get - the two's complement representation of -128 in the variable size that has been accepted by the print function.
You might find this site useful for experimentation and furthering your understanding of variable data storage.

char is signed so 0x80 is really -0x80 (==-128). When promoted to a higher width the sign gets copied into the new bits 0xffffff80 (still ==-128).
if you put unsigned in front of char you won't get that issue (though may encounter others).
void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned char x = 0x80;
  if(x != 0x80){
    Serial.println(x, HEX);
  }

  delay(1000);
}

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


text:
Hardware network-infrastructure for a fully-arduino-based home-automation project
As already mentioned in another question, I'm spending LOT of time planning the home-automation system for my new house (currently still in the "still building" phase).
Even if started only as a "lights/switch management project", things started getting bigger and bigger and, at the moment, in addition to original requirements, I already have:

A reed switch including cut-detection wires (for a total of 4 wires)  installed on every single window (one switch for single-windows; two switches for dual-door windows);
planned the location of a DHT22 sensor in each room.

In addition to the above, I'm currently evaluating the opportunity to add a single RGB led to have visual-feedback for each push-button (something like: GREEN=>LIGHT/OFF; RED=>LIGHT/ON). More specifically, I'm evaluating the opportunity to replace common/simple pushbuttons with these:

Obviously, such a change will heavily impact the cabling, as:

original simple/pushbutton required only two wires for each pushbutton, with one wire potentially shareable among adiacent pushbuttons (I'll be using "internal pullups", so one wire will be GND)
RGB pushbuttons require six wires (GND and SIGNAL for pushbutton; R, G and B plus COMMON for LED), with only two wires potentially shareable among adjacent pushbuttons (GND and COMMON).

Adding to this that it will be easy to have wall-boxes hosting two, three or even four pushbuttons, and you easily understand that LOTS of cables are required!
Here below I'm attaching a rough schema of what I'm planning to build, in terms of hardware:

where you can see:

ROOM 1, with:

2 x reed switch (up to 8 wires);
1 x DHT22 (3 wires);
a wall box with two pushbuttons/wLED (up to 12 wires);
a wall box with one pushbutton/wLED (up to 6 wires)

ROOM 2, with:

1 x reed switch (4 wires);
1 x DHT22 (3 wires)
a wall box with two pushbuttons/wLED (up to 12 wires)

Also, as for "controlling" the whole system:

two POWER-BOXES, located externally to rooms, where I originally planned to host the "controller" (a MEGA2560) together with needed Relay-modules, and interconnected via an RS-485 bus.

(BTW: actually, I'll have three POWER-BOXES, and not only TWO. But this is a detail, as for the spirit of this question).
Please note that POWER-BOXES (PB1 and PB2) will be located (...as for the original plan) quite FAR from some rooms: up to 10/15 meters, in the worst case scenario. Also, please note that each power-boxes are far up to 10/15 meters from each-others.
Before the real question, let me add another couple of important points:

Even tough I know that some kind of wireless system and/or wireless segment could simplify my overall architecture, I'm a strongly believer that a "wired" system is more reliable than a "wireless" one, expecially in the long-term. As such, as I'm lucky enough to put down lots of "pipes" (to properly distribute cables all around the house), I really prefer a wholly wired system;
As for this question, I'm not interested in the "software" side of the system. This is really an accessory (again, as for this very question). My really_big_problem relates to the "hardware" infrastructure to put in place. That's why I'm posting this question here.

After the all of this, here is the question:
As for your experience and knowledge:

should I stick to original plan, having an RS-485 multidrop-bus interconnecting only the MEGAs, with "signal" cables going directly from room-hardware (pushbuttons, reeds, DHT22, etc.) to the MEGA PINs ....

or

should I add some other Arduinos (a Micro seems a really good candidates) in each room, terminating all the signal-room-cables coming from room-hardware, and speaking with MEGAs via the same RS-485 bus?

In the first case, I'll have a real simple RS-485 bus with a mess of cables; In the second case I'll have a _longer_and_more_complex_ RS-485 bus, with a much manageable network cabling/infrastructure.
Am I right? What are the PROs and the CONSs of above two scenarios? Should I investigate other approaches?
Are there some documentation that can help me picking the right solution?
Thanks in advance to all of those who will spend some (precious) time helping me in this really difficult decision to take!

BTW: if you need further details, please don't hesitate to ask.

I'd put Ethernet shields and Arduinos in each room. Then when you need a more powerful Arduino (or even a Raspberry Pi) you simply connect it to the existing network. It's easier to maintain and expand when some years passes. And, of course, it's very likely you are already wiring the rooms with network wires.

IMHO wiring each button to the central unit (mega) is a real waste of cables, pins and money. Not to mention that that solution is not flexible at all: if you want to add something in some place you will need to pull another wire. IMHO the ideal setup (but I'm just a beginner, so I can be wrong) is having one microcontroller per box: you can use an arduino micro or a simple attiny if the box is really small. Then all these uC are connected through a fieldbus (can be the same RS485 which goes through all the house, can be a "room-wide" rs485, CAN, I2C, Serial, daisy-chain network, ...).

This way you can serially communicate with each box, each box can communicate with the main mega, and most important you will just need to pass a few cables, so extending the network is really easy.Personally I'd use RS485, since it's easier to use than CAN but it's strong enough (in fact, you can use the serial protocol over RS485 transceivers). I'd avoid a global ethernet connection, for both security and performance reasons (security because someone connecting to your net will also be able to see every message, performance because you can't connect an attiny to the ethernet without efforts)

@frarugi87 : thanks for commenting. As for "ethernet security", this should not be a big issue as in such a scenario I will surely rely on a dedicated VLAN. Anyway, the idea of having a fully distributed network, with Arduinos in every box, sounds interesting. I have to check how many nodes can be handled by the framework I'm planning to use.

@DamianoVerzulli well, in any case you will have unencrypted messages going back and forth your network, but yeah, it's just a minor issue. The most important part is that you will need ethernet shields or transceivers (e.g. ENC29J60) for each node, and they will need to handle heavy processing just for the communication, while with simpler field bus (e.g. rs485) you will still need the transceiver (which is cheaper and smaller), but you will need very little computing for the communication (usually it is serial-based, so the peripheral will handle it on its own)

@fabrosell : thanks for commenting. I spent some time, before beginning, investigating ethernet involvement. As the network, initially, looked much like a bus and considering that RS485 was both more cheap and more reliable (not needing an external switch) I'm currently oriented towards RS485. Obviously I'll have ethernet, around the home, but it will be used up to the main "gateway" (one, or probably two of the MEGAs), so to have the whole infrastructure easily accessible by a Raspberry/OrangePI, acting has a web-server/data-collector/etc. Anyway, I'll re-evaluate the ethernet option. Thanks.

I'd go for more, and thus simpler nodes on a single bus. I'd probably add another wire for power too. Because of the long wires, I'd use a slightly higher value for the voltage, and use the regulator on the arduino to get a stable 5v.

@Gerben:  Do you think I'll be able to fit everything (1 x Nano 3.0; 1 x MAX485; up to 3 push-buttons; cabling) inside this wallbox? Should I start planning to design/buy an ad-hoc PCB to reduce/optimize the space?   (BTW: thanks for your time)

@DamianoVerzulli Sure. You can probably even fit in a half-sized breadboard. You can add even more stuff by layering.

short wires are generally better than long ones
I agree, that wired is better in your situation
Maybe you distinguish between two different areas: sensor/actor to controller and controller to controller communication
In many cases you can not chose the sensor/actor to controller communication, because it is given by the device (DHT-22, reed, led push button etc.). Therefore, keep these lines short
RS-485 is good, but is it necessary? It adds drivers to each device. Maybe, I2C could do it,to. You can still use twisted pair cables.

Thanks for commenting. The very first problem I faced was the decide "how" and "with which protocol" interconnect my Arduinos. As: 1) the distance between them was quite large (20 meters or even more); 2) I need to handle "noise", during transmission, as best as possible; 3) the bandwidth required by the whole system is relatively low; I ended up with RS-485 in multidrop configuration (like the one described here. Have you been able to test I2C under similar conditions?

As for RS-485, Nick Gammon in his excellent answer made several really useful tests about cable lenghts, communication speeds and collision/detection/avoidance approaches. Based to them, I ended up deciding that RS-485 was really suited to my needs. Don't you?

As for "short wires are generally better than long ones", such an approach would take me in having an ad-hoc Arduino in every wall-box (this wall-box). I wonder if I'll be able to fit everything inside such boxes (1 x Nano 3.0; 1 x MAX485; up to 3 push-buttons; cabling) and/or if I'll need to design a proper PCB to optimize everything. What's your opinion?

As for two different kinds of networks: "sensor/actor <=> controller" and "controller <=> controller" this is absolutely reasonable and I'm actually investigating this as I've 3 serials on each MEGA so I can definitely have a "secondary network branch" from each MEGA towards the "local" boxes. Also, the software-framework I'm currently evaluating/experiencing, souliss, should play nicely with such an architecture.

Here my additional thoughts in short:

20 meters is, compared with the distance to the moon, quite short ;-). Maximum length of RS-485 is reported to be kilometers with small transmission rates (google: rs485 cable length).
Noise can either be avoided (hardware) or corrected by software (fault tolerant codes, checksums etc.) Generally, software is cheaper.
Short wires does not mean no wires at all. Short wires would e.g. result if you have a controller per room and connect the sensors to it.
There are also small packages of Arduino compatible chips available (ATTiny84/85). And without RS485 you save the space of the controllers...
I2C bus length should work inside a house, if yous is not bigger than the one of Bill Gates...
http://www.esacademy.com/en/library/technical-articles-and-documents/miscellaneous/i2c-bus/frequently-asked-questions/i2c-faq.html
I would not use serial for communication. It is not extensible. Serial is ok for debugging.


text:
RS485: is "Y" multidrop allowed?
I imagine that the proper way to implement an RS485 multidrop bus is the following:

What happens if, in order to save cables, I connect the same 5 nodes above using this other topology?

Will it works?
If no, why?
If "maybe", under which circumstances will it work?

P.S.: yes! I know that MEGA has three Serials and, as such, I could implement two different BUSses (1: Mega<->Mega<->Mega; 2: Mega<->Nano<->Nano), but this will increase the complexity of the software I'm running, as it needs some hacking in order to play nicely with two distinct RS-485 busses;
P.P.S.: This is the bus discussed in this other question

At low speeds and short distances that won't be a problem.
At high speeds (megabits per second) and long distances (hundreds of meters) you may get reflections unless you get the termination just right.

Can you please tell values you think is reasonable to call "short distance" and "low speed" in this context?

@Bacco tens of meters and 115200 baud, I'd call short distance and low speed.

Thanks for your feedback!

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


text:
"tamper" circuit of a reed switch: can I connect the two wires to an INPUT and an OUTPUT pin?
While working for the automation side of my new house, I'm currently in the process of installing several reed switches on top of external doors and windows.
Even if this could be used as a "security" infrastructure, I'm more interested, at the moment, at the "automation" side (checking the status of door and windows without the need to physically watch them) and as such, I'm going to extend the arduino-based infrastructure I've already planned and prototyped [more details here].
This is the reed-switch I've installed (1€ coin added for size reference):

and this is the related circuits:

As you can see, it comes with two circuits: one related to the "switch" funcionality; another one as a safety-measure to catch some "cuts" along the wires.
To check its status, currently, I've configured:

"contact circuit":

one end to an Arduino GROUND_PIN;
the other end to Digital PIN 52 (REED1_SW_Pin);

"tamper circuit":

one end to an Arduino GROUND_PIN (same GND pin as above);
the other end to Digital PIN 50 (REED1_AT_Pin);

Arduino setup:

pinMode(REED1_SW_Pin, INPUT_PULLUP)
pinMode(REED1_AT_Pin, INPUT_PULLUP)

Arduino code:

the main code-block handling REED events is reported below

Even tough everything is working fine, I wonder if there are better approaches, expecially inchecking the status of door and windows without the need to physically watch them terms of POWER-CONSUMPTION. So, here are my questions:

TAMPER-Circuit: due to its nature, it will always be a "closed" circuit, with current flowing inside, from REED1_AT_Pin to GND. Currently I'm checking its state every 1 second (#define REED_AT_CHECKDELAY   1000) but a frequency of once every 5 seconds, or even 10 seconds would be acceptable (for me). So I would like to have the current flowing ONLY during the "checking-timeframe". Something like:

every 5 seconds...
power-up something, getting the current flowing along the circuit;
check if the current flows;
if yes => OK
if no => set/keep the ALARM state
power-down the "something"

Is it feasible? If yes, how? Also: is it worth the effort?

REED-switch circuit: same as above. Polling approach is still acceptable (for me) but frequency need to be relatively high (5 seconds max), in order to keep of sort of "near-real-time feedback" when opening/closing windows. Best would be 2 secs polling-interval.
With such a timing, does the polling-approach make sense?
from an "electronic" point of view, what is the "to-be-preferred-scenario" for the Arduino board:

having a small, fixed, steady current, flowing out from a PIN, for YEARS on a 24/7/365 basis or...
having a continuosly transition from LOW->HIGH->LOW for a Digital PIN, say once every 5 seconds, again, for YEARS?

Every comment, sidenotes, hints, critics, whatever... is REALLY welcomed/appreciated.

Arduino code-block handling REED events
BTW: the full-code, where the REED switch is handled togheter with pushbuttons and relays, it's available on GitHub

    [...]
    if (reed_sw1_state != reed_sw1_previous_state) {
        // a change occurred. Are we in a "boucing" window?
        if (millis() - last_reed_sw1_debounce > REED_DEBOUNCE) {
          // no. So it's a real change
          // Let's handle the event...
          Serial.print(millis());
          Serial.print("[REED] - SW1 state CHANGED from [");
          Serial.print(reed_sw1_previous_state);
          Serial.print("] to [");
          Serial.print(reed_sw1_state);
          Serial.println("]");
          reed_sw1_previous_state = reed_sw1_state;
          last_reed_sw1_debounce = millis();
        } else {
          // yes. Let's ignore it
        }
      }

      // Let's check REED Switches anti-tamper state
      if (millis()-reed_at1_lastcheck > REED_AT_CHECKDELAY) {
         reed_at1_state = ! digitalRead(REED1_AT_Pin);
         if (reed_at1_state == HIGH ) {
            Serial.print(millis());
            Serial.print("[REED] - AT1 state OK [");
            Serial.print(reed_at1_state);
            Serial.println("]");
         } else {
            Serial.print(millis());
            Serial.print("[REED] - AT1 state ALARM - OnGoing TAMPER!!! [");
            Serial.print(reed_at1_state);
            Serial.println("]");
         }
         reed_at1_lastcheck = millis();
      }
      [...]

So I would like to have the current flowing ONLY during the "checking-timeframe".

Turn off the pull-up until just before checking. Allow a few milliseconds for the pull-up to raise the voltage.

With such a timing, does the polling-approach make sense?

Certainly, if you are trying to save battery power.

Bear in mind the voltage drops over long cable runs (and also possibly induced spikes). You might want a more powerful pull-up (eg. 10k) rather than the inbuilt 50k. You can still organize that by having an output pin turn on the voltage to the pull-up. Or, have the pull-up wired in permanently but instead of running the other side to ground, set the "ground" wire to OUTPUT and write LOW to it - and then set it to INPUT when you want it to be inactive.
See my post about Power saving - you could use a watchdog timer to wake the device at (say) every 4 seconds, to check things.
You may want to add in input-circuit protection (eg. a couple of diodes) to dampen down any incoming spikes. Even something simple like this:


text:
Uploading Arduino code, OTA, via connected ESP8266-12E running Esp-Link
1. A short preliminary introduction
I'm deploying a small network of three MEGAs connected trough an RS-485 bus.
Each MEGA is connected to up to 16 push-buttons (wall-mounted) and two relay-module (2 x 8-SSR; located close to the MEGA). The objective is to manage the lighting of the whole house (aka: "switching 'ON' the relay 'R1' when the push-button 'PB1' is pressed").
At the moment, everything runs fine: MEGAs are able to 'broadcast' events along the BUS and each node is able to properly react to both locally-generated events, as well as events coming from the BUS.
Above system is running from a couple of weeks and... I'm starting struggling about "updating" the code: having around 40 push-buttons and 35 relay distributed on the three nodes, chances are "high" that some "tuning" (aka: "trial-and-error") is required.
Things get even worse when... you start enjoying the powerfullness of the system (aka: "Hai! What about turning-OFF ALL the lights of the main-floor by long-clicking PB1?"). This, obviously, requires a "patch" to the code and a related "upload" the the MEGAs. And so on: LOTS of uploads :-(
Having some ESP8266-12E modules sitting around, I decided to investigate the possibility to use them, as a sort of "WiFi gateway": reaching them via WiFi; sending them the new code; asking them to kindly "upload" the code to its own MEGA that is phisically connected via USART.
As mentioned in lots of places (including a comment on this other question) I decided to test the ESP-Link firmware.
As I'm having problems interconneting the MEGA with the ESP, here I'm, asking this community :-)
2. Hardware involved
As for the Arduino side, I'm using a common MEGA (a Chinese one, BTW), so I don't get into details, here, 'cause there is nothing special.
As for the ESP8266, strictly speaking I'm NOT using a straight ESP8266-12E, but a Development Board. Actually, I'm using a Lolin NodeMCU v3, this, that you can see here below:

My plan is to connect DIRECTLY the USART of the ESP to the USART of the MEGA. This raises some problems, described below.
3. GPIO voltage issues
One of the very first issues that I addressed relates to GPIO voltage.
While it's crystal clear that:

GPIO PINs, on MEGA, are 5V based and, as such:

the TX on the MEGA side will send out a 5V current;
the RX on the MEGA side expect to receive a 5V current;

GPIO PINs, on ESP8266-12E, are 3.3V based and, as such:

the TX on the ESP side will send out a 3.3V current;
the RX on the ESP side expect to receive a 3.3V current;

I still am NOT able to understand if this is --in my case-- a real problem. I'm saying this, 'cause:
1 - Transmission from ESP to MEGA should NOT be an issue, as the HIGH/3.3V signal coming in into MEGA should still be recognized as HIGH, from the MEGA, as it's higher than 2.5V;
2 - Transmission from MEGA to ESP COULD be a problem, if PINs on the ESP are NOT 5V tolerant
As for point 2) I deeply searched all-around and found plenty of contradictory assertions. In the end, I would like to "trust" the Hackaday article: "Ask Hackaday: Is The ESP8266 5V Tolerant?" as, in several comments, reports various semi-official statements (like a message from Expressif CTO sent from a Facebook account or a message from an "internal" of Espressif) asserting that: "Yes! GPIO PINs on the ESP8266-12E are 5V tolerant").
So, again, I decided: "Ok! Let me go! Let's connect the two, straight, without a level-shifter". And yes: I know that with such a decision, I'm taking some risks and... can "burn" something, especially on the ESP side.
So, here's my:

Question 1: How much I'm "brave" in connecting straight-away the TX/RX of the ESP8266 to the RX/TX of the MEGA? Would you suggest it? And why?

4. Ground issues
While working on my RS-485 bus, I learnt that it's critically important to have a "common ground" among my MEGAs. That sounds understandable... as otherwise there is NOT a common reference to evaluate the same signal among different devices.
So, now that I've TWO equipment and I'm giving them POWER via two distinct sources (MEGA directly connected to my PC; ESP connected to another PC), I'm wondering if:

Question 2: Do I need to connect a GND PIN on the MEGA to a GND PIN on the ESP? Do the two boards, to properly operate, need a shared/common GND?

5. RESET line on the MEGA
In order to trigger the flashing of the new sketch on the Arduino side, the ESP need to RESET it. To do this, the ESP need to be connected to the RESET line of the MEGA. The RESET PIN is clearly shown on the MEGA so the connection is really easy.
Nevertheless, after some preliminary test... it looks to me that the ESP is UNABLE to reset the MEGA.
This lead to:

Question 3: Is, an ESP8266-12E OUTPUT PIN (operating at 3.3V), able to properly handle the RESET PIN of the Arduino?

I'm asking also 'cause based on the official documentation of the MEGA I read:
Reset PIN: Bring this line LOW to reset the microcontroller.
Typically used to add a reset button to shields which block
the one on the board.

6. Physical connections
In the official documentation of ESP-Link I read about potential problems generated (to Arduino) by the ESP as, right after a reboot of the ESP, it send out on TX some debug messages. Due to the USART connections, such characters transmitted by the ESP to the MEGA are received by the MEGA. It's not clear, to me, WHY this could be a problem. Anyway, the same documenation say: "...If you need to avoid this, you can configure esp-link to swap the uart pins..."
So, in the end, I connected the two devices following the official doc, with USART PINs swapped:

GPIO13: connect to TX of microcontroller
GPIO15: connect to RX of microcontroller and use a pull-down to ensure proper booting
GPIO12: connect to RESET of microcontroller
GPIO14: connect to ISP of LPC/ARM microcontroller (not used with Arduino/AVR)
GPIO0: either a 1k-10k pull-up resistor to 3.3v or a green "conn" LED via a 1k-2.2k resistor to 3.3V (indicates wifi status)
GPIO2: either a 1k-10k pull-up resistor to 3.3v or a yellow "ser" LED via a 1k-2.2k resistor to 3.3V (indicates serial activity)

As I don't need (currently) any LED feedback, I haven't used GPIO0 and GPIO2. Also, as I don't have an ARM, I haven't used GPIO14.
With help of this mapping I ended with following connection:

7. Results (...and problems)
To test what's going on, I've uploaded to Arduino a simple sketch that turn ON/OFF the internal LED every second and dump an increasing counter on the console. Here it is:
unsigned long counter;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  counter = 0;
}

void loop() {
  Serial.print("[");Serial.print(counter);Serial.print("] ");
  Serial.println("on");
  digitalWrite(13, HIGH);
  delay(1000);
  Serial.print("[");Serial.print(counter);Serial.print("] ");
  Serial.println("off");
  digitalWrite(13, LOW);
  delay(1000);
  counter++;
}

so, from the console output, I can see if Arduino is correctly operating and if it's restart.
On the ESP-Link side, I've configured the PIN as shown below:

With all the above in place, up to know, I've been experimenting the following:

If I connect ONLY the RESET line and the TX/MEGA to the D7/GPIO13/ESP, I can succesfully reset the Arduino from the ESP-Link web interface and I can see the "console" of the MEGA (I can be sure of succesfully reset, as the counter in the Arduino console, restart);
Above apply:

when the MEGA is powered via a full-USB connection from a PC;
when the MEGA is connected via a power-only USB cable from the PC;
when the MEGA is powered via a USB-power-bank, but in this case ONLY if thereis a shared-GND between ESP and MEGA

As soon as I connect the D8/GPIO15/ESP to the RX/MEGA, everything still work, but up to next reset. If I "reset" the Arduino via the ESP-Link web-interface, it reset but.... never boot (I'm sure, as the "blinking" never start).

So, the last question:

Question 4: What's wrong with above testbed? Why the D8/GPIO15/ESP disrupt the boot process on the MEGA? I've swapped the UART PINs exactly to avoid this... as far as I understood...

Sorry to be so long but... I think that details matter :-)

do you have a common ground between the boards? The ESP's GPIO 4+5 are the only pins that are low during reset+default on boot; you might want to use those two to avoid issues with "boot noise". You can use a relay/mosfet to reset the mega w/o shared electrical connections.

@dandavis: As for "common ground" the boot-problem (Arduino NOT booting properly after a "reset", when the ESP/TX is connected to Arduino/RX) persist even with shared ground. As for "relay/mosfet" to restart Arduino, please note that it's not needed: I've tested that ESP is surely able to reset Arduino. Problem is that after a reset, Arduino "hang" in the boot-process, and never launch the sketch. As soon as I plug-away Arduino/RX and reset it again (via ESP), boot process complete regularly - Currently I'm investigating problems related to the bootloader, even evalutating to "upgrade" it.

I have successfully used ESP-link firmware with esp-01 and Arduino Pro Mini.
For the ESP-01 and Pro Mini, you can find out more on my blog post. I have connected GPIO 0 of ESP-01 to reset pin of Pro Mini and the Pro Mini can be reset using ESP-Link the web interface. I try to use the same voltage level for both micro-controllers and a single power source. For my example, the Pro Mini is driving the ESP-01 and of-course sharing the common ground.
To answer your questions.

I try not do that as ESP has stated that all the GPIO pins are only 3.3v compatible.
Yes, both controller must share a ground.
My understanding is RESET is an output pin. If connected to ESP8266, there is a possibility that the ESP will be damaged.
Not sure if your wiring is correct. You may reference my diagram on how the ESP and Arduino Pro Mini is wired up. For your case, I will recommend a level shifter to prevent damaged to your ESP.


text:
Compile `.hex` files on Linux
I build .hex files for Arduino. How can I do this in Linux? I use the Linux distro  Mint 17.2.
I need a program to make [.hex files] (in Linux).
Can anyone help me?

With the Arduino IDE of course.

What are you asking for? How to build .hex files on Linux? Or how to upload .hex files on Linux? Please clarify your question, because as it stands it is rather unclear and is likely to be closed.

@Majenko - I may be wrong, but looking at your edit, I would have said (as a non-native Brazilian Portugese speaker) that Necessito de um programa para fazer. should be translated as I need a program to make [.hex files], rather than I need to make a program.This may be the reason why the question seems a little unclear... :-)

@Greenonline Don't complain to me - complain to Google Translate ;)

@Majenko - ah, ok :-) Anyways, I've changed the meaning of the question, and it all makes a bit more sense now. I've voted to reopen.

How are you creating your .hex files? Where are they coming from? Are you cross compiling the .hex files on some other machine and then transferring them to the Linux box? What is your Arduino connected to, the Linux box, or some other machine? Why are you even bothering with the .hex files? Your question is a little unclear. As Mikael states in his comment, you do not need to compile the .hex files, they are already compiled, you merely need to upload them, which the Arduino IDE would do for you anyway...
As ARK points out in his answer, you may find the answers to the question Where are the hex files compiled by Arduino? useful, although it seems like you know where they are but you don't know how to upload them.
Why can you not just use the Arduino IDE, to write your sketch, and then allow it to automatically compile the sketch and upload the .hex file for you? That way you do not need to manually play with the .hex file. Maybe I am missing something.
Is the Arduino IDE bombing out and not uploading the sketch on to the Arduino board?

However, if you are merely asking, how can I upload a .hex file to an Arduino, in Linux without using the Arduino IDE, then you would use avrdude. Taking the answer from How do I upload a hex file firmware to a target board without using the arduino IDE?
avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build8135728863211847829.tmp/sketch_may21b.cpp.hex:i

or alternatively, taking the answer from Uploading Arduino hex file using avrdude
avrdude -U flash:w:[put-hex-file-path-here]:i -C avrdude.conf -v -p atmega328 -b 115200 -c stk500v2 -P [put-device-path-here]

You can download the Arduino IDE for Linux from the Arduino site.
As mentioned in Where are the hex files compiled by Arduino?, in the Arduino program: go to Arduino -> Preferences and then select Show verbose output during -> compilation.

Finally, when you are compiling, the program will show you lots of
  data. At the last lines, you will find the path to the .hex file
  (Every time the path changes!).

If you want to upload this .hex file to your ATmega328P (the micro controller inside Arduino Uno), avrdude can do that for you.
Here, are few useful links:

Setup Avrdude on Linux
Programming your chip
Choosing a Programmer
Uploading your .hex file

ok. But it not is my problem.
I have an .hex file and I need compiler this file to the arduino.

Upload? Compile seems strange. Please elaborate.

from what i understand of your question is that you have a .hex file and you want to upload it to your Arduino Board. Well, First you need to know which microcontroller is being used in your Arduino Board you can use AVRDUDE, as shown in this tutorial, you can upload that .hex file to your micro controller. (Arduino UNO have a ATMega328P)

Unfortunately, your answer and the link only shows how to install avrdude, but not how to use it to upload a .hex file.

Unfortunately, you did paid attention while visiting the given link. There was menu in which different section were listed. Anyways, I have edited my answer.

No problem... It turns out that you were correct anyway, as the true meaning of the question had got lost in translation. I have clarified the question.


text:
Need to buy a new breadboard?
I'm new to Arduino and haven't done any education in electrical engineering before, so this might be a very dumb question.
I'm busy with a project to control two servo motors with Arduino. Now yesterday I connected the wires incorrectly to the breadboard, so the wires started smoldering. I didn't connect the resistor correctly, so I guess that might have been the problem.
Now I replaced the wiring, but it's not working and I don't know if the software might be the problem or the breadboard need to be replaced as well. I cannot see anything wrong with the breadboard, but it was warm so I don't know if it might be burned from the inside? The wiring of the servomotors seems to be okay, so I guess that I don't need to replace those I hope.
Any tips about how to check everything is still working?
Or might it be a good idea to buy an LED and add it to the breadboard to ensure it's okay?
EDIT:
I guess I found some code to check that the servomotors are still okay. Just add them directly to the Arduino and run some code: Sweep
One other question: one of the servomotors doesn't have a black, red and yellow cable but a red, brown and orange. How can I know which ones the same as yellow, red and black?

I didn't know you could buy just one LED...

I didn't connect the resistor right - Resistor? With servos? Can you share your schematic please? It sounds like you are doing something wrong.

How did you understand that it was the breadboard? usually a breadboard is a plastic cover and metal contacts; if something is broken, then probably it's the arduino or the servo,..

@Majenko http://cdn.instructables.com/FJJ/4RJK/HI3TRXOL/FJJ4RJKHI3TRXOL.MEDIUM.jpg

Ah right - just a base/gate resistor. That's OK then.

@frarugi87 Well the arduino is still functioning. I can upload and run software so that seems ok. I don't know OR the breadboard could be fried, that's my question, it's like you said a plastic cover so I cannot directly see or it's fried or not. So my question how can I determine or there's something wrong with the breadboard or not.

@ErikvandeVen usually if you can't understand if it is fried then it is not fried. When a breadboard "blows" the white plastic becomes black (and even then most of times it still works). To be sure, assemble your circuit, then check with a multimeter the resistance between each pin and the servo. I mean, touch the GND pin on the arduino and the GND pin on the servo and check that the resistance is low. Then do the same for the +5V and the signal..

Sorry to check your English, but when you say I don't know OR the breadboard and I cannot directly see or it's fried, do you mean if and not or, so that they should read as I don't know IF the breadboard and  I cannot directly see if it's fried - I only ask as I reviewed an edit to your question and swapped or for if as otherwise it didn't sound idiomatically correct.

haha I'm sorry. yes I meant if, my bad.

To answer your last question (for 99%):
red = +
brown = gnd
orange = pwm (speed)

To test: try measure resistance with multimeter, gnd and + should have the lowest resistance.
And to be save: buy a new breadboard, a bad partly melted breadboard, or pieces of solder spoiled, is a nightmare.
Otherwise you can test with a multimeter the resistance of your breadboard for columns (close to 0) and rows 1.

And if you want to be more sure, 99.99% of times the pinout is always the same, so if your cables are black-red-yellow and the other is brown-red-orange, then brown GND, red + and yellow PWM

You could check the connections of the breadboard, using a multimeter (set to continuity check) and wires in the breadboard holes, with the + and - leads, from the meter, at either end of each row/column of connections, following the diagram below:

It might be a bit tedious, but it should only take thirty minutes maximum, and would give you peace of mind as well as saving you four Euros...
If you say that it was working before and now is not, then maybe the breadboard is damaged. However, it is unlikely that the whole breadboard is... try moving your components to a different part of the breadboard.
The breadboard could possibly get warm, as servos can use a fair bit of current, and breadboards aren't really designed for power circuitry. You may be better off using an Arduino Servo shield and connecting the servos directly to that, rather than using the breadboard. Why are you using a breadboard - can you, as Majenko states, provide a schematic diagram?
Answering the last part of your question - Taking the graphics from my answer to Code to control servo with shield, to show the different colours for the four different connector types:
Futaba and Airtronics connectors

Hitec and JR Radio connectors have the same pin out:
.
This means that the red, brown and orange leads go to a JR Radios connector.

@ErikvandeVen - I have updated my answer a little, w.r.t. using the breadboard (component placement and heating)

Not all servo motors have the same color cables, that's the manufacturers choice, although they should be standardized. You can test them with a multi-meter, low resistance is usually ground, slightly higher one is usually is usually the power, the other will be the signal. Breadboards are generally cheap and if you suspect yours is not functioning properly, buy a new one. I have two of these and they work very well for $10. MPJA powered breadboard
Additionally, if you have a motor driver shield, they usually have a three pronged port for your servo cable to connect to. Try that as well.


text:
Do I need a full Arduino board hardwired to a sensor to send data via Wi-Fi?
Basically I want to wire a Wheatstone bridge style load-cell into a moving trolley and transmit the data to a remote workstation so I can get real-time feedback about the loading conditions.
Do I need to have a full board riding on the trolley that is wired in between the Wi-Fi transmitter and the bridge amplifier or is there a way that the current variations from the bridge can be read directly by the Wi-Fi transmitter and relayed to the remote in some translatable format?
The trolley design is extremely streamlined and it would be a bummer to have to add more than minimal electronics to make this happen...

the ESP8266 has the same kind of IO as an UNO, more or less, it's all you need.

There are small packages out there with built in WiFi.  Node MCU is one of them, however its analog to digital conversion isn't up to the task of measuring bridges.  If you go that route you'll need to add a ADC to the Node MCU which will increase the total package size.

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


text:
ESP8266-01 WifiScan not working
I have a ESP8266-01 and am trying to get it to work. I am using the example WiFiScan code shown below.
#include "ESP8266WiFi.h"

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

  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

I have a voltage regulator producing 3.3 V connected to CH_PD and the Arduino powers the ESP's VCC via the 3.3 V pin. TX is connected to TX and RX is connected to RX. GPIO0 is connected to ground. I can upload, but it cannot find any networks. It always states no networks found. Now I'm not even sure how to proceed... Any help would be appreciated.

Try Wifi access point example and connect green wire to 2 and white one to 3. And give it a try

ch_pd is an enable signal, VCC draws current that the Uno 3.3 pin can't supply

Actually, I'm not too sure how to control the current being produced. Some things I have tried include using the 5V but adding a 100ohm resistor, and powering the esp through the mains via a phone charger. Do you have any suggestions? Thanks!

and the voltage regulator? how many amperes can it supply?

Try connecting the ESP's Vcc to your 3.3v regulator. You didn't say which regulator you are using but most will be able to supply more than enough current for your ESP. I power my ESP-01s with LM-1117 regulators which can supply up to 800mA.

I have connected a multimeter in series to the circuit to read the current produced by the voltage regulator. I connected the positive probe to the positive output of the voltage regulator and the negative probe to the VCC of the esp. The circuit still lights up but the multimeter shows 0A. Am I connecting it wrong. I am using a 2A fast charger for the source and a LM2596 DC-DC regulator.

You should provide a good power source for the VCC. One that can supply 170 mA for WiFi operations of esp8266. You should use the power regulator to supply 3.3 V to VCC and there is no reason to use other power source for the CH_PD pin. CH_PD pin is "enable" pin, it doesn't need a strong power supply.
IO 0 should be connected to ground only for upload, not for normal operation.


text:
Send HEX number over serial
I have a RS232 device that I am able to communicate with using RealTerm on a windows PC.
The device is expecting a hex string like AA BB 03 01 03 EE

How would I send the equivalent string from an arduino? (I feel confident the arduino is wired correctly since I can see incoming uart data)
Things I have tried
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
      Serial.println('AA BB 03 01 01 EE', "OCT");
      delay(3000);
      Serial.println('0xAA 0xBB 0x03 0x01 0x01 0xEE', "DEC");
      delay(3000);
      Serial.println('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.println('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.println('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.print('0xAA 0xBB 0x03 0x01 0x01 0xEE', "DEC");
      delay(3000);
      Serial.print('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.print('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.print('AA BB 03 01 01 EE', "DEC");
      delay(3000);
      Serial.println('AA BB 03 01 01 EE', HEX);
      delay(3000);
      Serial.println('0xAA 0xBB 0x03 0x01 0x01 0xEE', HEX);
      delay(3000);
      Serial.println('0xAA 0xBB 0x03 0x01 0x01 0xEE');
      delay(3000);
      Serial.println('0xAA 0xBB 0x03 0x01 0x01 0xEE', HEX);
      delay(3000);
      Serial.write('AA BB 03 01 01 EE');
      delay(3000);
      Serial.write('0xAA 0xBB 0x03 0x01 0x01 0xEE');
      delay(3000);
}

I've also tried using double quotes as mentioned in the comments
     Serial.write("AA BB 03 01 01 EE");
     delay(3000);

     Serial.write("0xAA 0xBB 0x03 0x01 0x01 0xEE");
     delay(3000);

     Serial.write("101010101011101100000011000000010000000111101110");
     delay(2000);

Additionally I've tried writing the serial one line at a time
  Serial.write(0xaa); // AA
  Serial.write(0xbb); // BB
  Serial.write(0x03); // 03
  Serial.write(0x01); // 01
  Serial.write(0x01); // 01
  Serial.write(0xee); // EE
  Serial.write(0x0d); // \r
  Serial.write(0x0a); // \n
  delay(3000);

Additional Information

controlling projector using arduino
Adding \r\n to hex sent over arduino

'AA BB 03 01 01 EE'  This is a multi-character literal (a different thing from a string literal) and won't play a role in your answer. I don't know whether or not it's relevant to the question. If not, you probably intended to have double quotes here.

The device is expecting a hex string ... the first screenshot shows that binary values are being sent, not strings ... hexadecimal numbers are human readable representation of binary values

what problem are you seeing?

There are 2 problems. 1 is how to write out with Serial.write(). 2. Is how to understand what RealTerm is doing that arduino isn't doing. I'll capture that in another question (This question here is very similar to the second problem https://superuser.com/questions/245926/how-does-realterm-send-numbers)

Futhermore, I'm finding that the expected values I'm sending over serial aren't matching the received results. Almost exactly identical to this form https://forum.arduino.cc/t/how-to-send-hexadecimal-value-to-serial-devices/138834/15

The problem was that I wasn't using a RS232 to TTL adapter. Once I added that in between the arduino and the device the correct values were received.

As noticed by jsotola in a comment, your device doesn't seem to be
expecting HEX at all, but rather plain binary. Serial.print() is not
appropriate, as it is designed for sending ASCII text. For binary data,
you should prefer Serial.write(). More specifically, for sending
arbitrary binary data, the proper method is
size_t Print::write(const uint8_t *buffer, size_t size)

Applying this to your example gives:
const size_t packet_length = 6;
uint8_t packet[packet_length] = {0xaa, 0xbb, 0x03, 0x01, 0x03, 0xee};
Serial.write(packet, packet_length);

Thank you! This gets me closer, unfortunately the device still isn't responding. When I spy on the uart cable I see what is being transmitted is "~ (which converted from ascii is 7E 22

@spuder: There is something wrong either with your setup or your serial sniffer. I just tested my code with hd /dev/ttyACM0, and it does send the intended sequence.

I've created a simulator here: https://wokwi.com/projects/337371635280511572
When casting to a char the output is ª»î which matches hex AABB030103EE. So your code does appear to be logically correct, but there is something I'm not understanding in my situation.

@spuder: Your simulation prints “170 187 3 1 3 238” (without the spaces), which does match 0xaa, 0xbb, 0x03, 0x01, 0x03, 0xee.

I now understand ª»î is unicode, 170 187 3 1 3 238 is binary decimal, AABB030103EE is hexadecimal. I was confused because different terminals default to different display formats (even though it is all the same value under the hood).

I setup a loopback debugging cable to see the output. When using RealTerm I get AA BB 03 01 03 EE, but when using the arduino I get  95 91 7E 7F 7E 04 00

Once I used a proper RS232 to TTL adapter between the arduino and the device, the serial values started transmitting properly. Thank you https://www.amazon.com/dp/B07BJJ1T5G?ref=ppx_yo2ov_dt_b_product_details&th=1

if device expects actual numbers, then it does not receive them in hex format or decimal, but in binary. in which case you would need an array of numbers and then go with them using for loop (or purpouse made function.
byte sequence[]={0xAA, 0xBB, 0x03, 0x01, 0x01, 0xEE};
for(byte i=0; i<sizeof(sequence);i++) Serial.write(sequence[i]);

if you have to send it as a HEX, then its most likely a case of hex representation and you can use printf for that
Serial.printf("0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X", 0xAA, 0xBB, 0x03, 0x01, 0x01, 0xEE);

Another  think is that you should be careful using println when communicating with other devices.
println ads extra character (number) for new line, after the data you wish to send. if you only want to send data you wish to send, then use print instead
Edit:
Thanks for the note from Edgar Bonet, I was warned that printf is still not a standard instruction outside of the ESP core.
Its well worth adding it up by yourself. Look for a guide on arduino playground.

Your Serial.printf() call can be simplified as Serial.print("0xAA 0xBB 0x03 0x01 0x01 0xEE");.

yes, that is correct, but I have wanted to stress the 0x%02X formatting so that it always outputs two digit hex numbers and let the person latter change his variables after format string.

Good point! You may want to add a note, though, warning that Serial.printf() is not a standard Arduino method. It is available on ESP, but not on standard Arduino cores.

To quote you: Good Point!
I have got too used to esp core, that I have assumed that core-Arduino coughed-up with its hobby core in those years.

Alas, it would seem the core Arduino devs do not want the official cores to support printf().

I would suggest you view a tutorial or two on HEX numbers and how they are represented.

@Gil What do you mean? if you see something incorrect state it.  I take Feedback, but be specific so that I and the others can learn from it. I Personaly use HEX numbers in programming more then decimal. Mine communication library has all the instructions in HEX. So if you have some specific improvement of mine approach in mind, state it and I will edit mine answer quoting you in edit, like I did with the Edgar Bonet s  useful point.


text:
Trigger event onRelease of button
I am using the EasyButton library to detect button presses on an arduino.
I want do execute a function when the user

Presses a button
Presses and holds a button
Releases a button

Detecting when a user presses or holds a button is straight forward
#include <Arduino.h>
#include <EasyButton.h>
# define BUTTON_PIN 2;
EasyButton button(BUTTON_PIN);

void onPressedCallback() {
  Serial.println("Button was pressed and released");
}

void onHoldCallback() {
  Serial.println("Button was pressed and held");
}

void setup() {
  button.begin();
  button.onPressed(onPressedCallback);
  button.onPressedFor(buttonHoldDuration, onHoldCallback);
}

The easyButton library has the following events

onPressed
onPressedFor
onSequence

It has the following states

isPressed
isReleased
wasPressed
wasReleased
pressedFor
releasedFor

How would you trigger an event when a button is 'released'?
Full Documentation
https://easybtn.earias.me/docs/on-single-press-api
What I've tried

Check the state from inside an event

void onHoldCallback() {
  while (button.isPressed() {
     Serial.println("you are still holding the button");
  }
  Serial.println("Button was released");
}

This unfortunately creates an infinite loop since the button state is never refreshed (button.begin();)
Additional Resources

https://github.com/evert-arias/EasyButton/tree/main/examples
Source code for the system interupt https://github.com/evert-arias/EasyButton/blob/4e818410252e9518564fc55f8d4a976fac70a9b2/src/EasyButton.cpp#L55-L82

I have 3 states I want to perform different actions on. 1: Press 2: Press & Hold 3: Release. The hold and release action is the problem I haven't been able to solve

The onPressed() event Triggers a callback function when the button has been pressed and released.
Here's a test sketch to show what I mean. I've also added a function you could use to detect the moment the button is first pressed.
#include <EasyButton.h>

// EasyButton(uint8_t pin,
//            uint32_t debounce_time = 35,
//            bool pullup_enable = true,
//            bool active_low = true)
EasyButton button(2);

void onReleased(){
  Serial.println("Button Releast");
}

void firstPressed(){
  Serial.println("First Pressed");
}

void setup(){

  // Test output to serial monitor.
  Serial.begin(9600);

  // Initialize the button.
  button.begin();

  // Add the callback function to be called
  // when the button is pressed then released.
  // NOTE: This function is only called AFTER
  // the button has been released.
  button.onPressed(onReleased);

}

void loop(){

  // Continuously read the status of the button.
  button.read();

  // Call a function the moment the button is pressed.
  if(button.wasPressed()){
    firstPressed();
  }

}

Just check the easyButton state in your loop code and run your functions as required. The library already has the events you need, no point rolling your own. It's best just to set a variable or flag in event code so it returns quickly, then deal with the results in the main loop. The easyButton library has done most of that work for you.

Origionally I started with the EasyButton library, but when I wasn't able to get it working I switched to the madleech/Button@^1.0.0 library and got the following working.
Note that this depends on polling which could definitly be improved.
While this deviates from the original question, I feel it is worth sharing for anyone else who wants a working but (less than ideal) solution.
#include <Arduino.h>

#include <Button.h>

Button button1(2);

unsigned long buttonCheckMillis;

void setup()
{
  buttonCheckMillis = millis();
  button1.begin();
}

void loop()
{
  if (button1.toggled()) {
    // User pressed the button
    if (button1.read() == Button::PRESSED) {
      Serial.println("Button Pressed");
    }
    // User released the button
    else {
      Serial.println("Button Released");
    }
  }
  // Poll every 100 milliseconds to see if user is still holding button
  if (millis() - buttonCheckMillis > 100) {
    buttonCheckMillis = millis();
    if (button1.read() == Button::PRESSED) {
      Serial.println("Button Held");
    }
  }

}


text:
ESP8266 - CIPSEND & external power supply Hangs program
Updated:
I connected my esp to external power, the blue light stays on, I start getting garbage data.
I used voltage regulator which was giving 3.4v, power supply tested with 1A &  2A.
Old problem :
I have been trying to make ESP8266 since my last semester exams & now 2nd semester exams are going on. So i've been trying to make ESP8266 work for very long time.
Earlier it was firmware problem, i updated it.
After a lot it worked. I tried many libraries - but none worked, either some are using specific port or some want specific firmware version which is really hard to find & then flash.
I am using telnet to check.
When i disable code to send data - i can send data madly, it works & never hangs up. But as i use AT+CPISEND after 1-2 read/write - it stops responding.
I am powering using arduino with/out voltage divider. Its firmware - 0020000903, AT Firmware v1.5, 4mb flash size, I changed baudrate to 9600.
Below is code i worte :
( I intentionally didn't remove comments)
#include <SoftwareSerial.
#define DEBUG true

SoftwareSerial esp8266(9,10); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{

  pinMode(11,OUTPUT);
  digitalWrite(11,LOW);

  pinMode(12,OUTPUT);
  digitalWrite(12,LOW);

  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);

  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different

Serial.print("Sending at..");
  sendData("AT",2000,DEBUG);
  //sendData("AT+RST",2000,DEBUG); // reset module
  sendData("AT+CWMODE=1",1000,DEBUG);
 // sendData("AT+CWLAP",1000,DEBUG);
 //sendData("AT+CIOBAUD=9600",1000,DEBUG);
 //sendData("AT+UART=9600,8,1,0,0",1000,DEBUG);
 //sendData("AT+IPR=9600",1000,DEBUG);
 // sendData("AT+CWJAP_DEF=\"mad\",\"agentis47?orBond?\"",15000,DEBUG);
 //sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
  sendData("AT+CIFSR",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80",1000,DEBUG); // turn on server on port 80
}

void loop()
{

  if(esp8266.available()) // check if the esp is sending a message
  {

    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }

    //Serial.println("IPD Search "+(len));
    if(esp8266.find("+IPD,"))
    {

     delay(20); // wait for the serial buffer to fill up (read all the serial data)
     // get the connection id so that we can then disconnect
     int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48

     esp8266.read(); //skip the comma ','
     //(CIPMUX=0): + IPD, <len>:
     //(CIPMUX=1): + IPD, <id>, <len>: <data>
     int len = (readUntil(":")).toInt();
     if(len>500) len = 500; //prevent extra data we won't be sending more than 500bytes in one go.
     char data[len];

     esp8266.readBytes(data, len);
     //data[len-2]='\0';

      int pinNumber = (data[0]-48)*10; // get first number i.e. if the pin 13 then the 1st number is 1, then multiply to get 10
     pinNumber += ((data[1])-48); // get second number, i.e. if the pin number is 13 then the 2nd number is 3, then add to the first number

       digitalWrite(pinNumber, !digitalRead(pinNumber));
    Serial.println(String(len));

     /*Serial.println("===");

     Serial.println("--");
*/
    //cleanBuffer();
    //delay(10);
     //Serial.println("Sendddiddding data");
     //sendData(connectionId,String("OK"));
     //Serial.println("Sent");
     //closeConnection(connectionId);

     //digitalWrite(pinNumber, !digitalRead(pinNumber)); // toggle pin

     // make close command
     //String closeCommand = "AT+CIPCLOSE=";
     //closeCommand+=connectionId; // append connection id
     //closeCommand+="\r\n";

     //sendData(closeCommand,1000,DEBUG); // close connection
    }
  }
}

void cleanBuffer(){
  while(esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }
}

String sendData(int connectionId, String data){
  //Serial.println("AT+CIPSEND="+String(connectionId)+ ","+String(data.length()));
  //sendData("AT+CIPSEND="+String(connectionId)+ ","+String(data.length()),1000,DEBUG);
  //sendData(data,100,DEBUG);
  //closeConnection(connectionId);
  String webpage = "
Hello
&lth2>World!
<button>LED1</button>";

     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";

     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);

     webpage="<button>LED2</button>";

     cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();

     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);

     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId; // append connection id

     sendData(closeCommand,3000,DEBUG);

 /*
  Serial.println("finding prompt");
  if(esp8266.find(">"))    //prompt offered by esp8266
  {
    Serial.println("Sending data");
   // Serial.println("found > prompt - issuing GET request");  //a debug message
    esp8266.println(data);  //this is our http GET request
  }
  else
  {
    closeConnection(connectionId);
    Serial.println("No '>' prompt received after AT+CPISEND");
  }
*/
}

String closeConnection(int connectionId){
    sendData("AT+CIPCLOSE="+String(connectionId),100,DEBUG);
}

String readUntil(String delimiter){
  String response = "";
  char c;
  unsigned int dLen = delimiter.length(),n=0;

    while(esp8266.available()&&(c= esp8266.read())){
      n= (c==delimiter[n])?n+1:0;
      if(n==dLen) break;
      response+=c;
    }
   return response;
}

void sendRaw(String data){
esp8266.print(data);
}

String sendCommand(String command){
  esp8266.print(command); // send the read character to the esp8266
  esp8266.print("\r\n");
  esp8266.flush();
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    esp8266.print(command); // send the read character to the esp8266
    esp8266.print("\r\n");
    esp8266.flush();
    long int time = millis();

    do
    {
      while(esp8266.available())
      {

        // The esp has data so display its output to the serial window
        char c = esp8266.read(); // read the next character.
        response+=c;
      }
    }while( (time+timeout) > millis());
    if(debug)
    {
      Serial.print(response);
    }
    return response;
}

Please help, I am stuck, Is there any other cheaper & better solution ? I am only looking for Wifi.

If you are powering it using Arduino 3.3V pin it is no wonder it does not work.
ESP8266 uses more power than Arduino can provide. Power pin on arduino is about 50ma. ESP8266 in receive or send mode uses much more and either halts or restarts.
A table of ESP8266 power consumption can be found here

can you suggest power regulator which is easily available ?

any Buck Step Down Converter. There is literally gazillion of them on ebay and on... Use it to step down 5V that you get from any phone charger to 3.3V. You could also use something like this for use with breadboard

@m11404 you can easily buy a cheap 3.3V linear regulator LM1117T and use it with the Arduino 5V pin, which can supply up to 500mA; a separate 1A supply would be even better.

I already had that... I used 5v,1A adapter... &  connected esp without voltage divider... The led in esp was dim... &  not responding

I am getting yyyyyyyyy.... Similar as response if I connect external power.

make sure that your terminal baud speed is set correct. go from 9600 and up. See if that fixes it. And put the capacitor between vcc and ground.

Wait ? You connected the ESP to 5V without the voltage divider? ESP is 3.3V. You fried your ESP module.

@NccWarp9 Hey, No...Its not fried, i used voltage regulator. I also tried using 3A DC-DC Converter Step Down buck http://www.ebay.in/itm/Supper-mini-3A-DC-DC-Converter-Step-Down-buck-Power-Supply-Module-3V-5V-16V-/331854215553?hash=item4d440d7981:g:1ywAAOSwt7pXNFQz
ESP echoes back whatever i type. No error.
& it works fine if i correct directly to uno.
Baud rate is 9600 as i changed it using AT, Should i reflash & use 115200 with external power ?

I will try a 100uf capacitor.
I also monitored current  - while connected to uno it was fluctuating from 70mA to 30mA..i  don't remember exactly but there was lot of fluctuations but when i connect to external no fluctuation  , blue blinks once, red light is OK.   this is result when i connect to external power & directly to serial.
The source is rated to 2A, 5V.

If i use arduino promini with esp, it keeps resetting i believe because of less power.  & once it worked but there was lots of garbage text. & then it started resetting.
I am really thankful to you.  Thank you for replying. I didn't get notification for your comment so this was late reply.

older modules come with only 9600 and to get it to work with higher baud rates you will need to flash it with newer firmware. did you flash it with 0.9v of the firmware that has baud watchdog? http://www.xess.com/blog/esp8266-reflash/

Yes I used 0.9 of expressif. The latest one.  Initally it was 115200.. I changed it to 9600.

@NccWarp9 hey Yes I used 0.9 of expressif. The latest one. Initally it was 115200.. I changed it to 9600

Im sorry but there is nothing else. I do wonder why you use AT commands  from code.

@NccWarp9 i wonder is there any other way to communicate ?

Sure there are, Many. Currently Im testing out MQTT for ESP and it works perfectly. Also you have WebSockets and so on. You can put your own telnet on it, webserver, or program another arduino over the wifi.

@NccWarp9 I checked for mqtt, etc earlier but i thought its just build upon at library, i will try flashing it again. Really thankyou.
the mqtt firmware didn't work well in past. I will try again.
I just want to communicate arduino with ESP8266, any how.

If you wish only to communicate they I would suggest looking at ESP-Link. I find it one of the most impressive and useful pieces of code out there for ESP

@NccWarp9 I will give it a try & update you, really thankyou.


text:
Serial communication with Python
I am trying to send integer from my Python program to Arduino MEGA.
If I send 1, the LED should turn on and If  I send 0 the LED should turn off.
I was able to write Python code correctly as I think. I have configure the port and made serialWrite(val) function for send data to Arduino only if data is changed.
This not a full program. It has while loop. So, it writes data to Arduino rapidly. I used serialWrite(val) function to prevent that.
But, the LED never turns off, if I send 0. It turns on only. What are the problems in my code?
import serial as ser

prt = ser.Serial(
port='COM3',
baudrate=9600,
parity=ser.PARITY_NONE,
stopbits=ser.STOPBITS_ONE,
bytesize=ser.EIGHTBITS
)

preSerVal=0
#function for send data..data will send only val is changed
def serialWrite(val):
    global preSerVal
    if(not preSerVal == val):
        prt.write(str(val)+'\r\n')
        preSerVal=val

This is my Arduino program.
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}
byte incomingByte;

void loop()
{
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
      if (incomingByte == '1') {
        digitalWrite(13, HIGH);
    } else if (incomingByte == '0') {
        digitalWrite(13, LOW);
    }
  }
}

UPDATE 1
I write testing program like this.
Python code:
import serial as ser
import time

preSerVal=0
prt = ser.Serial(
port='COM3',
baudrate=9600,
parity=ser.PARITY_NONE,
stopbits=ser.STOPBITS_ONE,
bytesize=ser.EIGHTBITS
)
def serialWrite(val):
    global preSerVal
    if(not preSerVal == val):
         prt.write(str(val)+'\r\n')
         preSerVal=val

while 1:
   for i in range(0,10):
        serialWrite(0)
   time.sleep(1)
   for i in range(0,10):
        serialWrite(1)

Arduino code:
void setup() {
 Serial.begin(9600);
 pinMode(13, OUTPUT);
 digitalWrite(13, LOW);
}
byte incomingByte;

void loop()
{
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
  if (incomingByte == '1') {
    digitalWrite(13, HIGH);
  } else if (incomingByte == '0') {
    digitalWrite(13, LOW);
  }
 }
}

This code gives this result.
see the video bellow:
https://www.youtube.com/watch?v=utC4vo8YDVU&list=PLM5AA5oFchgC25da44Q2X900pz0eojSQJ&index=1
UPDATE 2
This is a piece of code..it sends 0..i checked it.
try:
    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        houghCenter=(i[0],i[1])
        cv2.circle(src,houghCenter,i[2],(0,255,0),2)
        cv2.circle(src,houghCenter,2,(0,255,255),1)
        cv2.circle(drawing,houghCenter,i[2],(0,255,0),2)
        cv2.circle(drawing,houghCenter,2,(0,255,255),1)
        #print (houghCenter,"   ",contourCenter)
        dx=math.fabs(houghCenter[0]-contourCenter[0])
        dy =math.fabs(houghCenter[1]-contourCenter[1])
        if (dx>diff and dy>diff):
            serialWrite(0)
        else:
            serialWrite(1)
except Exception:
    serialWrite(0)

You need to post the Python while loop to get a more specific answer. But I'll bet you just aren't sending enough 0s between 1s, for you to notice the LED going off. You did say the while loop is fast. Perhaps you should try slowing it down with time.sleep(1) and see if anything changes.

@TisteAndii .. Thanks... I cant slow down while loop..I have checkered,0 is sent by while loop. That's OK.

please post the Python while loop. Is the Arduino code working with IDE console ?

Its huge code with some image processing code...I have update my post..plz see it..

add print("0/1") to see how fast 0 and 1 are sent on PC side. Is the code executed once or in a loop ? What is the expected behaviour and the real bahaviour ?

I previously added a print command to same place that I call serialWrite(val) function..It was very speed..that's why I used serialWrite(val) function.

I understand the serialWrite() avoids sending twice same data. Then add the print after prt.write if the 1 and 0 are wery fast you will not have time to see anything blink. If you do not describe the expected and observed behaviour I cannot help you

Let us continue this discussion in chat.

You are missing a second time.sleep(1). That is why the first loop executes correctly and the the LED flashed faster. Without any time.sleep() at all, the LED is going OFF/ON so fast that you cannot see it happen (may be it's just not so bright as usually).
while 1:
   for i in range(0,10):
        serialWrite(0)
   time.sleep(1)
   for i in range(0,10):
        serialWrite(1)
   time.sleep(1)

Its worked now...Thanks..But,How can I apply to my image processing code?

I have update my post again with piece of image processing code.what is the wrong of that?

@NSiri Try adding a delay each time you send a 0 or 1. If your algorithm can afford it.


text:
Connect Arduino via TX RX Pins to Computer's USB Port
I want to avoid using the big USB B connector to program my Arduino Mega. Since there are those RX TX Pins I thought, it would be possible, to connect my USB - Wires from my PC directly to those RX TX Pins. D+ -> TX and D- RX. This Post on Arduino Stackexchange says, those wires are just connected, while this post says the exact opposite.
I'm confused. Is it possible or would I damage my board when connecting USB wireq to RX / TX pins on my Arduino?

The first answer that you cite that you say says it is possible is in fact not talking about  what you are referring to  - it is discussing the use of the RX & TX pins directly when they are not being used for USB connection.
The second answer you cite is technically incorrect but "correct enough" in the context.
The answer to your question  is "It can be done but it requires a different boot loader, its slower, its technically inferior, it's less standard, it requires a degree of understanding (on someone's part) to get it going, and it can be done
It IS possible to access USB directly from digital I/O pins. As TX & RX are also standard digital I/O pins they could be used for this purpose BUT you need dedicated bootloader code to do this and it has inferior performance if a USB to serial converter is available. The eg ADAFruit Arduino Trinket uses this system.

Here is how the (or a)  ADAFRUIT Trinket Bootloader works. (The Trinket is not mentioned here but I'm told that this is what it uses. If not, it works in functionally the same manner).
This is in turn based on the USBaspLoader
A (very) simple "more or less Arduino compatible" development board which can use this system is Metaboard. It's circuit diagram is shown below. As can be seen - it uses an ATMega168 and the USB connection is made to two standard digital I/O pins.

"Metaboard" using ATMega168

note USB connection to pins PD2 & PD4 - NOT via RXD on PD0 and TXD on PD1 via a serial to USB converter, as is more usual.

AND another version:  AVRUSBBOOT

And again
BootloadHID   They say  -

BootloadHID is a USB boot loader for AVR microcontrollers. The uploader tool requires no kernel level driver on Windows and can therefore be run without installing any DLLs.
BootloadHID is a USB boot loader for AVR microcontrollers. It can be used on all AVRs with at least 2 kB of boot loader section, e.g. the popular ATMega8. The firmware is flashed into the upper 2 kB of the flash memory and takes control immediately after reset. If a certain hardware condition is met (this condition can be configured, e.g. a jumper), the boot loader waits for data on the USB interface and loads it into the remaining part of the flash memory. If the condition is not met, control is passed to the loaded firmware.
This boot loader is similar to Thomas Fischl’s avrusbboot, except that it is built on top of the HID device class. This implementation is more user friendly on Windows, since no kernel level drivers need to be installed.

I thought about the 'EDIT' Part of the Answer where it is from jfpoilpret: EDIT: Serial data over USB goes through copper traces connected to the rx and tx pins, connecting them to the USB to serial converter chip. This got me thinking about this post.

@Joel Telling me that it got you thinking is nice - but telling me WHAT you were thinking is liable to be more useful. Maybe you were thinking what I said was wrong. It's not. A problem is that you are reading what somebody has written and adding words and thoughts that are not actually there. This is easily done (ask me how I know :-) ) and needs to be watched for, always. He says that you can use the TX and RX pins as standard digital I/O if TX and RX are not being used to connect to a serial to USB connection. This is not saying anything remotely like that you can connect to USB directly...

@Joel Somebody else notes that the pins connect directly on board to the onboard converter. That also does not in any way say that the pins can connect to USB. Read what they say, draw a picture - DO NOT ADD ANYTHING they do not say. DO NOT remove anything they do say. See what the picture tells you. | NOTE that I have told you that you CAN do what you are trying to do BUT it is harder slower and less capable. And you will need to know special magic or know somebody who does to do it. | QUESTION: WHY do you want to do this?

first: thanks for your tips, i will keep them in mind.
I want to put my Arduino in a case and i will need a bigger case if the big USB Plug is plugged in. I wanted to connect the wires from the USB cable going to my PC with the RXTX Pins on my Board, to save space. But this is not possible, since i need a lot more utilities to achive that, which need more room, than an USB Plug.

@Joel For a "one off" it would be far easier to add a custom socket (maybe a micro USB or mini USB) or even use a short wire tail to an off-board socket which can be more conveniently located.

Strictly Serial interfaces use ±15V, although this is uncommon these days (but then so are PCs with serial ports). ±12V, ±5V or even 0/+5V also exist. Connecting a ±15V interface to the Pi would destroy it. There are RS232 adapters to ensure safety.
If you are talking about connecting USB data lines to serial forget it. The voltages are the least of your worries, the USB serial encapsulates the data in a protocol.

I Thought since USB is the Universal Serial Bus, I could connect it. There is no way in connecting the Arduino to my PC in order to upload programs to it, without additional hardware?

See my answer - he's talking about an Arduino, not a RasPi. It is possible to use std digital I/O pins to implement low speed USB functionality and bootloaders to do this are available. See links in my answer. Not a path most would want to follow. This is what the ADAFruit Trinket Arduino look alike does.


text:
Arduino - Button to start / stop loop
So basically I'm trying to create a device where when I push a button it starts a loop. When I push this button again, it stops the loop. Right now I have it logged to serial. It starts up correctly with no output. When I press the button the loop begins and it spits out "toggled on" continuously. When I press the button again... nothing happens. What should happen ideally is that it should stop spitting out "toggled on" and just go back to doing nothing.
#include <Bounce2.h>

Bounce bouncer = Bounce();
const int W = 10;
bool wOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(W, INPUT_PULLUP);
  bouncer.attach(W);
  bouncer.interval(5);
}

void loop() {
  bouncer.update();
  if (bouncer.read() == LOW) {
    wOn = !wOn;
  }

  if (wOn > 0) {
    Serial.println("toggled on");
  }
}

If you change your sketch to this one, you'll see the issue:
const int W = 10;
bool wOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(W, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(W) == LOW) {
    wOn = !wOn;
  }

  if (wOn) {
    //Serial.println("toggled on");
  }
  Serial.println(wOn);
}

The button's contacts "bounce" (Google "contact bounce"), sending multiple low to high signals. There are several software solutions that will eliminate this issue. Have a look at: arduino.cc/en/Tutorial/Debounce. There are a couple of libraries that simplify de-bouncing buttons: playground.arduino.cc/Code/Debounce and playground.arduino.cc/Code/Bounce

I've added Bounce2 (I believe correctly) and it still has the same result. I added that bit to see the wOn value and it changes correctly between 0 and 1. Still the same end result. I've updated my code snippet to reflect my changes.

It seems that it only changes wOn back to false when I click it then instantly goes back to 1. The problem seems to be that it's infinitely changing the wOn back. Maybe I need to account for state changes?

Fixed. The solution I used was to add state change checking using .fell() which you'll see reflected below. I added state change verification using Bounce2.fell(), like so:
  if (bouncer.read() == LOW && bouncer.fell()) {

Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review

What I'm suggesting @C Steph is to edit your question and put the original, non-functioning code back. Then you could edit your answer and use your complete, functional sketch with the Bounce2 library. Your current answer is only 7 words long, so it's incomplete. In approximately 24 hours, you will be able to accept your own answer and I encourage you to do so. This will give you addition reputation on the Arduino.SE network.

If you edit your question with the fix, then the answers (and your question) will not make any sense. @VE7JRO - I've have done it for the OP.

I was looking for, Question = broken code, Answer = completely fixed and working code. There were 2 edits by the OP to their original Question. I was hoping the OP would have changed the Question back to the sketch they first posted (it did not use the Bounce2 library and was identical to the sketch in my answer, minus the code comment and extra Serial.println I added). Is there any way to go back through the question editing process to restore the first post by the OP?

I just tried to edit the question and was not able to go back to the OP's first post. More than likely, my reputation level is not high enough to access the information or only a site moderator can make these types of changes.


text:
Problem with programming an ATtiny85: Error - avrdude: Yikes! Invalid device signature
I'm trying to program an Attiny85 chip using an Arduino Uno as an ISP following this two tutorials: Instructables: Program an ATtiny With Arduino and Programming an ATtiny w/ Arduino 1.6 (or 1.0) but every time I try to upload the sketch I get this error message:
     avrdude: Yikes!  Invalid device signature.
     Double check connections and try again, or use -F to override
     this check.

I have tried different Arduino boards/changing port and different ATtiny chips but the results are all the same. I have also checked the wiring multiple times and it seems to be correct.
This is the full error message (on verbose mode):
     avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

     Using Port                    : COM7
     Using Programmer              : stk500v1
     Overriding Baud Rate          : 19200
     AVR Part                      : ATtiny85
     Chip Erase delay              : 400000 us
     PAGEL                         : P00
     BS2                           : P00
     RESET disposition             : possible i/o
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
       flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
       lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

     Programmer Type : STK500
     Description     : Atmel STK500 Version 1.x firmware
     Hardware Version: 2
     Firmware Version: 1.18
     Topcard         : Unknown
     Vtarget         : 0.0 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

     avrdude: AVR device initialized and ready to accept instructions

     Reading | ################################################## | 100% 0.05s

     avrdude: Device signature = 0x000000 (retrying)

     Reading | ################################################## | 100% 0.05s

     avrdude: Device signature = 0x000000 (retrying)

     Reading | ################################################## | 100% 0.05s

     avrdude: Device signature = 0x000000
     avrdude: Yikes!  Invalid device signature.
     Double check connections and try again, or use -F to override
     this check.

     avrdude done.  Thank you.

Downvoted because you stopped answering the questions of the person trying to help you, making this question impossible to answer.

Hint: Start by verifying "Arduino Uno as an ISP". This question assumes that the ISP is working correctly.

@MikaelPatel - I have found that if the ISP is set incorrectly then the error isn't the Yikes!, but is instead either Could not find USBtiny device error or avrdude: stk500_recv(): programmer is not responding

Try connecting the RESET pin of the Attiny85 to GND the second before you hit "program".
In my experience, the Arduino does not always send the RESET signal when it should (or on the pin that you think it would send it).
In these cases, manually resetting the Attiny by connecting the RESET pin to ground makes it programmable.
You can keep RESET low during the whole programming process, but if you keep it low for many minutes before programming the chip, it might not always work. In those cases, set RESET high for a moment before setting it back low, and the Attiny should be good for another round of programming.
And of course, when you want the Attiny to start doing what you have programmed it to do, you have to pull RESET high again.

I tried that and got :
avrdude: stk500_recv(): programmer is not responding
any suggestions?

Have you added the capacitor or pull-up resistor to prevent the Arduino from resetting itself when it tries to reset the Attiny?

Yes I have, a 10uf connected between the GND and RES

The only recurring problem that I've had, that has defied my double and triple checking of ... * the connections, * and remembering to upload the "Arduino as ISP" sketch to the Arduino, * and selecting board, * port, and * "ArduinoISP" in the Arduino IDE, ... has been having to do the reset manually. If none of that helps, then I'm sorry to say I'm out of ideas. Remembering to switch the programmer between AVRISP mkII and ArduinoISP at the appropriate time has tricked me a couple of times, though.

@Voly: Are you trying to program the Attiny in circuit? In other words, are there other components connected to the pins of the Attiny, or is it just the Arduino Uno?

@Voly, another question: Have you "burned the bootloader" to the Attiny85? This doesn't actually burn a bootloader, but it sets the fuses. Does this operation succeed, or does it also fail?

I solved a similar issue with my ATtiny13, I set a clock too slow (128 Khz) and Arduino ISP with its default params was unable to talk with ATtiny; I changed the clock in the Arduino ISP sketch and my ATtiny went back from the death.

This error (in particular the 0x000000) usually, but not always, means that the ATtiny has the fuses set for an external oscillation, but there is no functioning oscillator:
avrdude: Device signature = 0x000000

You probably need to add an external oscillator, i.e. a 16 MHz crystal, and a couple of 22 pF ceramic capacitors:

However, as this Engbedded Atmel AVR® Fuse Calculator shows, there are a number of permutations that could be set:

So, instead of using a crystal, you may need to provide an external clock:

These schematics come from What's the schematic to share one crystal with two micros?


text:
Troubleshoot Arduino LCD 16 x 2 shield
I tried to assemble Adafruit's Arduino LCD 16 x 2 using the instructions RGB LCD Shield: Control a 16x2 Character LCD using 2 pins - Assembly  without any success.
After assembly, I uploaded the HelloWorld example sketch on to the Arduino. The shield doesn't seem to be working. The LCD didn't turn on.
If I push back/press the LCD it turn on. Any idea on how to troubleshoot this?

Please upload the picture of your completed board.

Where have the photos disappeared to? Where they lost when the answer  that you posted was deleted? If so, could you edit your question and add the photos there? It may help other people who are having the same issue as you did.

By visually assessing the pictures, the issue seems to be due to poor soldering job.
You should try re-heating the soldering joints and make sure they are clean. There could be dry joints that may not be conducting signals.
Also you should upload pictures to your question post, not as an answer.

Thanks Chetan. I reheated some of the soldering joints and its started working. Thanks again! Feeling like a champ!

@user1261620 I'm glad that my post helped you in fixing the board. Before investing in expensive kits, you can practice soldering on some cheap scrap boards.