Expanding on my comment, after checking experimentally that this was
indeed the issue.

Short answer

You should do

TIFR1 = _BV(OCF1A);  // clear interrutp flag

right before

TIMSK1 |= _BV(OCIE1A);  // enable match interrupt

Explanation

Whenever the timer reaches the value stored in one of its “compare
match” registers, this triggers a “compare match” event, which has the
effect of raising the corresponding interrupt flag (OCF1A in your
case). If the associated interrupt is enabled, that fires an interrupt
request, and the flag is automatically cleared when the CPU starts
executing the interrupt vector.

However, if the interrupt is not enabled, the flag just stays set. If
you later enable the interrupt when the flag is already set, the
interrupt request is sent immediately. This is not what you want, you
want the interrupt to fire only on the next match. For this to happen,
you have to clear the interrupt flag prior to enabling the interrupt.

The interrupt flags have a very non-intuitive behavior: you clear the
flag by writing a logic one to it. Thus the line:

TIFR1 = _BV(OCF1A);  // clear interrutp flag

For completeness, I would also clear ICF1 before enabling ICIE1,
although this seems to not be critical for the working of your program.

Also, as a side note, be aware that the timer can increment while the
CPU is in the middle of executing TCNT1 = TCNT1 - ICR1;. If you want
the cleanest possible timings, leave the timer free-running and just set
OCR1A to the appropriate values: ICR1+pulse_delay, then
ICR1+(pulse_delay+pulse_length).


How to send unmodulated IR-Signal via cable?

There are two major components to an infra-red signal.  One is the high frequency carrier wave signal that pulses the LED on and off.  This frequency has to match that of the receiver and is used with either a high-pass or band-pass filter to filter out ambient IR light and allow it to only react to a real signal.

The second component, and it sounds like this is the one you are interested in, is the on-off pulsing of that carrier wave in different combinations and with different timings to denote binary 0 and 1.

Without knowing what your cable actually is, and we'd need to see a datasheet to get all the proper information, all this is just surmising.

I would imagine that you provide power and ground to the emitter cable, and the third pin is a logical "on/off" signal that enables and disables the carrier frequency to the LED.  That would allow you to send any codes you like as long as you know the timing of the signal.

In the library you link to is all the timing you need in the ir_NEC.cpp file.  The times are defined as:

#define NEC_BITS          32
#define NEC_HDR_MARK    9000
#define NEC_HDR_SPACE   4500
#define NEC_BIT_MARK     560
#define NEC_ONE_SPACE   1690
#define NEC_ZERO_SPACE   560
#define NEC_RPT_SPACE   2250

The actual data format is defined in the sendNEC function:

void  IRsend::sendNEC (unsigned long data,  int nbits)
{
    // Set IR carrier frequency
    enableIROut(38);

    // Header
    mark(NEC_HDR_MARK);
    space(NEC_HDR_SPACE);

    // Data
    for (unsigned long  mask = 1UL << (nbits - 1);  mask;  mask >>= 1) {
        if (data & mask) {
            mark(NEC_BIT_MARK);
            space(NEC_ONE_SPACE);
        } else {
            mark(NEC_BIT_MARK);
            space(NEC_ZERO_SPACE);
        }
    }

    // Footer
    mark(NEC_BIT_MARK);
    space(0);  // Always end with the LED off
}

The mark and space functions take a number of microseconds to perform either an ON or OFF of the PWM signal.  That is somewhat simpler for you, since it is just an ON or OFF of a digital IO pin to control the output of the emitter cable.  So where you have a MARK you turn on the output, then delay for the specified time. For a space you turn off the output and again delay for the specified time.

So you can just replicate the operation of that sendNEC function but with your own output control and timing in it instead of using the functions in that library.

Edit: It seems the cable doesn't need power - just provide the ground connection and the signal connection.  Of course, this is assuming that it isn't just an LED on a wire.  If it is just an LED on a wire then you would need to just use the library you link to as it is.


If you don't want to use the Terminal and the command line, the Arduino IDE is your best option. Get yourself an AVR programmer (or an Arduino Uno to serve as programmer, with the ArduinoISP sketch uploaded), and code on it.

Then connect your Arduino to your module via SPI. Select the correct processor and port.

You can now upload the sketch:


Best way to determine if a 5 gallon water jug is getting empty

Using a Force Sensor to Measure a Quantity of Water

To satisfy your requirement of having the sensor on the exterior of the water container, I would recommend using a force sensor to weigh the bottle at set intervals. A force sensor, such as the FlexiForce A401, is a type of resistor that changes resistance in response to the amount of force applied. While not as accurate as a scale, it should provide enough accuracy (+-3% according to the datasheet) for the application described.

The basic procedure would be to hook up the force sensor to the Arduino and first measure the resistance with an empty bottle, then measure again with a full bottle. This will give you an idea of the force that your specific platform is actually applying to the sensor, and you can then fine tune the voltage (as per the datasheet) for your installation.

A basic tutorial using a similar force sensor with an Arduino can be found here.

Other Possibilities

Optical Liquid Level Sensors
Ultrasonic Level Monitoring
Thermistors and Heating Coils at various levels to Measure the Thermal Mass (i.e. water) near the Sensor


What is the difference using library of SoftwareSerial.h and ESP8266WiFi.h?

The SoftwareSerial is used to communicate with the esp8266 from other MCU. The ESP8266WiFi library is for Arduino sketch running in esp8266.

The esp8266 can be used with firmware as 'network adapter' for your sketch running for example in Arduino Uno. MCU in Uno has only one hardware Serial which is used to communicate with the computer over USB (to upload and use Serial Monitor). To communicate with the esp8266 usually a second Serial interface is created with SoftwareSerial.

But esp8266 can be used as Arduino board with "esp8266 Arduino core". This 'core' contains Arduino libraries to access the WiFi functions of the esp8266 from a sketch running in esp8266.


How to detect which wire is live and which is neutral with Arduino?

There is no "correct" way with european plugs. Live and neutral are interchangeable. If you want to be sure you switch the live pin you will need to switch both pins together.

A DPDT or DPST relay (Double Pole, Single/Double Throw) is the simplest option.

There is no way of knowing which pin is which since they both have exactly the same current flowing through them (if they didn't your RCD would trip...)


Need help converting a processing sketch for a robot arm with servo shield

I use a generic servo shield, and the servo PWM outputs (3 pin inline connector) on the shield are labeled accordingly (0 - 15). Your Adafruit servo shield should be the same, see below.

The link that you provide also has the Arduino version, see below. You should use that, instead of the Processing version.
The Arduino library Servo.h, handles all of the "Servo PWM to Arduino pin conversions" that you ask for. So, looking at the Fixbot code, it would seem that all you would need to do is change the five pins (servo PWM outputs) to which the servos are attached in setup(), according to which servo PWM outputs you attach each servo to.
#include <Servo.h>

String command;

Servo seg0;
Servo seg1;
Servo seg2;
Servo seg3;
Servo seg4;

void setup() {
  Serial.begin(115200);
  seg0.attach(8);            /* <--- Change Me !!! */
  seg1.attach(9);            /* <--- Change Me !!! */
  seg2.attach(10);           /* <--- Change Me !!! */
  seg3.attach(11);           /* <--- Change Me !!! */
  seg4.attach(12);           /* <--- Change Me !!! */
}

void loop() {
  if(Serial.available() > 0) {
    char inChar = Serial.read();
    command += inChar;
    if(inChar == '\n') {
      // clear command
      performCmd(command);
      command = "";
    }
    Serial.flush();
  }
}

void performCmd(String cmd) {
  int comma1 = cmd.indexOf(',');
  int comma2 = cmd.indexOf(',', comma1+1);
  int comma3 = cmd.indexOf(',', comma2+1);
  int comma4 = cmd.indexOf(',', comma3+1);

  int cmd0 = stringToInt(cmd.substring(0, comma1));
  int cmd1 = stringToInt(cmd.substring(comma1+1, comma2));
  int cmd2 = stringToInt(cmd.substring(comma2+1, comma3));
  int cmd3 = stringToInt(cmd.substring(comma3+1, comma4));
  int cmd4 = stringToInt(cmd.substring(comma4+1, cmd.length()));

  seg0.write(cmd0);
  seg1.write(cmd1);
  seg2.write(cmd2);
  seg3.write(cmd3);
  seg4.write(cmd4);

}

int stringToInt(String str) {
  String tmp = String(str);
  return str.toInt();
}

Regarding your question about the maximum and minimums, again, these will be handled by the Servo.h library.

TL;DR
Change the five servo attach lines in the setup() routine, to reflect which servo ports your servos are connected to.

Power Requirements
As an aside, remember that you will need to supply external power (+5V) to the Adafruit Servo board, via the blue screw terminal block, in order to have sufficient power (current) to actuate the servos. In the photo above the screw terminal block is not shown, but would be mounted half way up on the left hand side of the PCB (where it says 5-6V Servo). It can be seen in this photo, at the top:

If you do not supply external power, then the Arduino board, by itself will not be able to supply enough power. Even though the code may be running, the lack of power may make it appear that there is no output, as the servos remain immobile, due to the lack of current.


You wrote:

  DateTime now = rtc.now();

  Thus, with every iteration of loop() "now" gets defined anew (on the
  heap?!), right?

No. Local variables like this are usually allocated on the stack,
although the compiler may keep them in CPU registers if that helps
optimization.

  static DateTime now;    // static declaration, executed only once

  In this case "new" should be allocated on the stack like a global
  variable, right?

No. It is allocated statically, in the .bss section, like uninitialized
global variables.

  I want to use "static" to increase overall performance by reducing
  work for the processor

Not sure it will make much difference. Static allocation may save you a
few CPU instructions compared to stack allocation (the instructions that
move the stack pointer). On the other hand, it will cost you a few
instructions compared to register allocation (the instructions to access
the RAM).

  avoiding heap fragmentation

Stack allocation does not use the heap, and the stack never fragments.

  Does this make sense or will it cause more problems than it solves?

If you really care about sub-microsecond differences in the execution
time, you should either look and the disassembly of the program, or do
some benchmarking. Otherwise just write whatever makes more sense from
the point of view of the program's logic: does the variable need to keep
its value across calls to loop()? If the answer is “no”, do not use
static.


No you don't have to change any time delay in order to get it rotating by 90 degrees, delay would just change the speed of rotation of the servo. The simulator you are using is at fault here as the sketch with 180 changed to 90 works flawlessly.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

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

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

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

MAKE SURE THAT YOU CHANGE BOTH OF THE 180'S TO 90.


Is there a way to traverse a filesystem and read files with an arduino?

The Arduino has no access to the file system on a PC.  All it has is a serial connection with which it can communicate with some program running on the PC. The code that is handling the PC's file system would have to run on the PC itself.


ESP8266 print DNS address (obtained via DHCP)

Serial.println(WiFi.dnsIP());

If you have more than one DNS server you can specify the index:

Serial.println(WiFi.dnsIP(1));


From the wiki.
Above is a schematic of a Groove shield. You can see that each of the connectors has two digital pins connected to it and then V (5V) and G (GND). The last two you can connect normally to an Arduino. The first two you connect to the pins that are used in your sketch.
Say it says to connect the connector to the top left DIGITAL pin on the board (D6/D7). You'll 7want to connect the pins as followed: Black → GND, Red → 5V, White → D7, and Yellow → D6.

Notes:

The shield overlaps the pins (i.e. 3-4, 4-5), so that might make things confusing. I think that is a design flaw. If it needs two pins, it should have two connectors. In the current state, you can connect two things together. I don't really know how to figure out if it uses all of the ports attached or not. If you don't have to, I would try not to overlap any two grooves. You would do this by using two digital ports for every groove "module."
You'll also need to have a adapter cable (Link from TheDoctor's Answer.)
For analog connections, it applies the same way as digital. G is ground, V is 5v, and A# is an analog pin.

Inferencing it:
There's no real cookie cutter way to connect to them. However, the wiki seems to be a decent resource once you figure out how to navigate it. The dust sensor you mentioned seems to ONLY use digital pin 8. It was connected to the D7/D8 connector on the Groove shield, so the yellow wire could be ignored since it was never used in the sketch.
It's hard to do much with this system: it's poorly documented and not uniform at all. Plus, some boards could cause problems that could even lead to damaging components. I would say look at something else.

This dust sensor seems pretty good, minus the documentation. On this blog, they say to do this:

Sharp pin 1 (V-LED)   => 5V (connected to 150ohm resister) Sharp pin 2
(LED-GND) => Arduino GND pin Sharp pin 3 (LED)     => Arduino pin 2
Sharp pin 4 (S-GND)   => Arduino GND pin Sharp pin 5 (Vo)      =>
Arduino A0 pin Sharp pin 6 (Vcc)     => 5V

I can't seem to find the cord for it, but I'm sure there are many others like this online. (It lists the cable needed: a 6-pin, 1.5mm pitch connector. That doesn't seem too hard to find).

Here is a 4x7 segment display for much cheaper. It does use a lot of pins and need resistors, but multiplexing and resistors aren't that hard to figure out. That's outside of the scope of this question. There might be some other board with a built in IC for controlling a display like that, but I can't seem to find one now.


How to change the default name of ESP8266-12E module

This line of code should hopefully do a difference.

wifi_station_set_hostname(myHostname);

For more information :

https://www.reddit.com/r/esp8266/comments/3zl3pi/change_esp8266_network_name/


ATtiny85 MIDI IN using SoftwareSerial - Is it possible?

I have done tests with a normal Arduino with software serial and missed quite a bit of messages, so I would advice to use hardware serial's instead.

For MIDI Out probably it works, but for MIDI In I have bad experiences. Especially when it comes to many messages, like aftertouch/pitch bend etc.

Also, I tried some optocouplers which didn't work well (like 6N137). I now use H11L1 optocouplers (they are white compared to most black ICs) and work perfectly.

You already checked the clean note on/note off ... are you sure it doesn't send active messages?

Below the schematic as I use it.. It does not matter if an STM32 or Arduino is used. Actually I haven't checked if H11L1 are 3.3V or 5V but they seem to work on both.

simulate this circuit – Schematic created using CircuitLab


If your computer/tablet/phone can act as a WiFi hotspot, you could use that to avoid the router. Many smartphones have that capability, as do many notebooks (as geometrikal mentioned, it's usually referred to as an 'ad-hoc' network on PCs). Create the network (or turn on hotspot capability), and connect to the network you created from your Arduino.


Suggest me a power source for my Arduino UNO project

Unfortunately, the perfect power supply system doesn't exist yet. However, powering an Arduino is simple.  You have to main options 9V for standard "full size" Arduinos (such as the UNO that you mention), although you could go for the low voltage 3.3V options.
Covering just the 9V option, from the Power section of Arduino Uno:

Power
The Arduino Uno can be powered via the USB connection or with an
external power supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter
(wall-wart) or battery. The adapter can be connected by plugging a
2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER
connector.
The board can operate on an external supply of 6 to 20 volts. If
supplied with less than 7V, however, the 5V pin may supply less than
five volts and the board may be unstable. If using more than 12V, the
voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.

You should probably also take a look at Power Supplies, in particular the section on Batteries and cells, also from the following section Voltage conversion and regulation, it states:

In a very simple scenario, you connect a disposable 9v battery
(probably one of the (approx) 4cm x 2.5cm x 1.5cm units with two snap
connectors on one end) to your Arduino, and the Arduino's built in
voltage regulator takes care of reducing the voltage to a consistent
5v or 3.3v, depending on the sort of Arduino you have.

So you have a couple of choices regarding 9V, either the P9 cell

or a pack that holds six 1.5V AA or AAA batteries.
You may find this link, How to run an Arduino (clone) on (AA) batteries for over a year – part 2, an interesting read. Here the chap uses four AA batteries, which only gives 6V, to power an UNO:

I have just highlighted some information, you should take the time to read the links fully, and google for more information.

Regarding the servo motors, more current may be required. You can use the same four AA battery pack, thusly:

but the capacity of the batteries may leave something to be desired, especially if you use rechargeable batteries (which in today's eco-concious world, you should), so you may require something more hefty. A quick google will show you the options available.
Addendum
The video Flite Test : RC Planes for Beginners: Batteries and Safety - Beginner Series - Ep. 7 is an extremely useful video tutorial about LiPO batteries for RC projects.


How to create delays in AVR assembly language

AVR LibC already has macros that do this, provided F_CPU is set correctly.

// Note: The Arduino IDE gets the value for F_CPU from boards.txt
#define F_CPU xxxxxxxxxx

#include <util/delay.h>

 ...

_delay_ms(1);
_delay_us(100);
_delay_us(1);


Zigbee Relay board communication with Arduino

Take a look at this library : https://code.google.com/p/xbee-arduino/

This is the XBee Library for Arduino, you will find simple sketch that are perfect bases for the application you're trying to do.


Breaking out of while loop using IR remote input

Replace delay with millis in Flash().

You do this by making every delay it's own state and give each state a number. Then inside flash you check which state you are in to set the LEDs and how long you have been in it to trigger the next state.

boolean flashing = false;
int flashingState = -1;
long nextFlashingState = 0;

void Flash() {    // flashing function
  if(!flashing ){
    flashingState =-1;
    return;
  }

  long ms = millis();
  switch(flashingState ){
  case -1:
    flashingState =0;
    nextflashingState = ms+75; //init "timer"
    //fallthrough
  case 0:
    digitalWrite(rLED, LOW);
    digitalWrite(gLED, LOW);
    digitalWrite(bLED, LOW);
    digitalWrite(rLED, HIGH);
    if(nextflashingState < ms){
        flashingState =1;
        nextflashingState +=75;
    }
    break;
 case 1:
    digitalWrite(gLED, HIGH);
    if(nextflashingState < ms){
        flashingState = 2;
        nextflashingState +=75;
    }
    break;
 case 2:
    digitalWrite(bLED, HIGH);
    if(nextflashingState < ms){
        flashingState = 3;
        nextflashingState +=75;
    }
    break;
  case 3:
    digitalWrite(rLED, LOW);
    if(nextflashingState < ms){
        flashingState = 4;
        nextflashingState +=75;
    }
    break;
  case 4:
    digitalWrite(gLED, LOW);
    if(nextflashingState < ms){
        flashingState = 5;
        nextflashingState +=75;
    }
    break;
  case 5:
    digitalWrite(bLED, LOW);
    if(nextflashingState < ms){
        flashingState = 0;
        nextflashingState +=75;
    }
    break;
  }
}

I used state -1 as the init state to start the timer, the case block will fall through to the next case. The millis() function returns the number of milliseconds since the arduino booted up (it overflows every ~1.5 months). So when I start a timer I set the the nextFlashingState to the time when it should start the next state.

Then in loop you call it every time.

void loop() {
  if (irrecv.decode(&results))
  {
    if (results.value == BUTTON_ON)
    {
      digitalWrite(rLED, HIGH);
      digitalWrite(gLED, HIGH);
      digitalWrite(bLED, HIGH);
      stR = HIGH;
      stG = HIGH;
      stB = HIGH;
    }
    if (results.value == BUTTON_OFF)
    {
        flashing =false;
      digitalWrite(rLED, LOW);
      digitalWrite(gLED, LOW);
      digitalWrite(bLED, LOW);
      stR = LOW;
      stG = LOW;
      stB = LOW;
    }
    if (results.value == BUTTON_R)
    {
      digitalWrite(rLED, !stR);
      stR = !stR;
    }
    if (results.value == BUTTON_G)
    {
      digitalWrite(gLED, !stG);
      stG = !stG;
    }
    if (results.value == BUTTON_B)
    {
      digitalWrite(bLED, !stB);
      stB = !stB;
    }
    if (results.value == BUTTON_FLASH)
    {
        flashing =true;
    }
    irrecv.resume();
  }

  Flash();
}


Is it possible to run emulator from IC? and how?

Not a chance, I am afraid.  The Arduino cannot do what you think it does.

Yes, you could program the Arduino to act like some of the simple old video games, but there is no way it can run a pre-existing emulator program like your computer can.

You need something more like a Raspberry Pi - in fact there is an interesting project that might be just what you want: RetroPie


For others who reach here by search results

Before this applying AT+CSTT command check if the modem is attached to GPRS using the AT+CGATT=? command. If the result is +CGATT: 0 this means the modem is not attached so attach the modem using AT+CGATT=1 command.

This will solve the issue as it was in my case. Even applying AT+CIPCLOSE=0 and AT+CIPSHUT didn't help until I checked that that the result of AT+CGATT=? was returning +CGATT: 0 and applied AT+CGATT=1.


Your incoming string, as Gerben has mentioned, will actually be more like:

GET /STA/ID=HelloWorld/Pass=Testin123 HTTP/1.1

My personal preferred method is to use strtok() to split the string up.  I'd use a two-pass method for this.

First split the string up into three parts - one GET, one the request, and the third the request type (though you don't need to use that for anything).  Assume the string is in C string incoming:

char *get = strtok(incoming, " ");
char *request = strtok(NULL, " ");
char *rtype = strtok(NULL, " ");

The request is now pointed to by the *request pointer and the string has been sliced up in-place.  So now you can do something similar with the request, this time splitting on / instead of space:

String SSID;
String Pass;

if (request != NULL) {
    char *part = strtok(request, "/");

    bool seenSTA = false;
    while (part) { // While there is a section to process...

        if (seenSTA) {
            if (!strncmp(part, "ID=", 3)) { // We have the ID
                SSID = String(part + 3);
            } else if (!strncmp(part, "Pass=", 5)) { // We have the password
                Pass = String(part + 5);
            }
        } else if (!strcmp(part, "STA")) {
            seenSTA = true;
        }

        part = strtok(NULL, "/");
    }
}


Your function, getCurrentTimestamp() saves the date string in an automatic variable - it is on the function's stack frame which gets freed as soon as that function returns. Either Serial.println() or savelog() is overwriting it.

The proper way to do what you're trying to do is to make the buffer live for the duration of both function calls. One way is to use a global buffer. Another is to declare the buffer in loop() and pass it to both functions.


What bootloader does the Arduino Micro come with?

Try looking at https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/caterina/Descriptors.c

Inside that is:

/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
 *  device characteristics, including the supported USB version, control endpoint size and the
 *  number of device configurations. The descriptor is read out by the USB host when the enumeration
 *  process begins.
 */
const USB_Descriptor_Device_t DeviceDescriptor =
{
    .Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},

    .USBSpecification       = VERSION_BCD(01.10),
    .Class                  = CDC_CSCP_CDCClass,
    .SubClass               = CDC_CSCP_NoSpecificSubclass,
    .Protocol               = CDC_CSCP_NoSpecificProtocol,

    .Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,

    .VendorID               = DEVICE_VID,
    .ProductID              = DEVICE_PID,
    .ReleaseNumber          = VERSION_BCD(00.01),

    .ManufacturerStrIndex   = 0x02,
    .ProductStrIndex        = 0x01,
    .SerialNumStrIndex      = NO_DESCRIPTOR,

    .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};

...

/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
 *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
 *  Descriptor.
 */
const USB_Descriptor_String_t ProductString =
{
    .Header                 = {.Size = USB_STRING_LEN(16), .Type = DTYPE_String},

    #if DEVICE_PID == 0x0036
    .UnicodeString          = L"Arduino Leonardo"
    #elif DEVICE_PID == 0x0037
    .UnicodeString          = L"Arduino Micro   "
    #elif DEVICE_PID == 0x003C
    .UnicodeString          = L"Arduino Esplora "
    #else
    .UnicodeString          = L"USB IO board    "
    #endif
};

  and how would I go about building and uploading a modified bootloader?

You would run the Makefile which is in the same directory as the above file. Then send the resulting .hex file to your device.


How do I find names of components I don't know?

The Arduino webpage has a section about their Starter Kits, including pictures (and technical specs if you scroll down the page). Particularly, if you go to the Arduino store, there is a sub-menu for components - for example, for actuators (there are more categories to the left of the image).

There is a blog by Aaron Eiche, Arduino Starter Rundown, that if you scroll down, there is a chart that labels the main components.

There are several websites that have pages that identify components by image - an example is the uCHobby webpage Identifying Electronic Components, with pictorial menus of the main types of components.

In Google images, searching "arduino starter kit components" yields a considerable amount of labelled component charts.


Serial Port fails with speeds greater than 19200

Answer is simple. You assign 38400 to a variable of type int. The signed range of integer values that can be stored in 16 bits is −32,768 through 32,767;


If you are finding Cheapest and working module you can you SIM800L less then 4$.

aliexpress.com/item/Free-Shipping-Smallest-SIM800L-GPRS-GSM-Module-MicroSIM-Card-Core-BOard-Quad-band-TTL-Serial-Port/32708504554.html

You can find many other cheap alternative but they does not work properly.

Sim800 have good support and you can find many examples to use this with arduino.

Many other model also available in market as per your requirements.


Thanks to @PeterPaulKiefer here is the answer.
External power for SIM800L module GND pin needs to be connected to both SIM800L module GND pin and Arduino nano GND pin. (e.g between RST and R2 pin on Arduino nano)
In order for the calling function to work, you also need to use a capacitor on SIM800L VCC and GND pins. I used 35V, 3300µF.
Schema:
                  Antena
                   \_/
                    |
Arduino    SIM800L  |  External 4.0V
             NET ---/
             VCC ----- +4.0V
 D2 --------- RST   |
 D3 ---------  RX  === Capacitor (35V, 3300µF)
 D4 ---------  TX   |
GND --------- GND ----- GND


The important thing to know for PROGMEM is that the AVR chip you’re using does not have a single flat address space. I.e., it does not use a von Neumann architecture; instead, it uses a specific version of what is known as a Harvard architecture: it has separate address spaces for RAM, program memory, and EEPROM. All of them start at 0. Which means that while dereferencing a nullptr is technically still undefined behavior in C++, it can be (and often is) perfectly valid in Arduino code.

The short version is: If you have a PROGMEM pointer, whatever function you pass it to must work on PROGMEM pointers. lcd.print does not, and afaict there is no way the function could possibly detect this is not a RAM pointer. You have to call a different function, assuming there is one in the first place.

See http://arduino.cc/en/Reference/PROGMEM for examples on how to use PROGMEM data.


How to upload code without closing puTTY

There is an open source project that will do what you want.
http://com0com.sourceforge.net/
The com0com will create virtual com ports for the programs to connect to.
The hub4com will allow you to route data between the physical port and multiple virtual com ports.
http://com0com.sourceforge.net/hub4com/ReadMe.txt


Solution found here:
http://www.dfrobot.com/wiki/index.php/LCD_KeyPad_Shield_For_Arduino_SKU:_DFR0009

  This example will test the LCD panel and the buttons.When you push the
  button on the shield，the screen will show the corresponding one.
  Connection: Plug the LCD Keypad to the UNO(or other controllers)

/*************************************************************************************

  Mark Bramwell, July 2010

  This program will test the LCD panel and the buttons.When you push the button on the shield，
  the screen will show the corresponding one.

  **Connection: Plug the LCD Keypad to the UNO(or other controllers)**

**************************************************************************************/

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);           // select the pins used on the LCD panel

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){               // read the buttons
    adc_key_in = analogRead(0);       // read the value from the sensor

    // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
    // we add approx 50 to those values and check to see if we are close
    // We make this the 1st option for speed reasons since it will be the most likely result

    if (adc_key_in > 1000) return btnNONE;

    // For V1.1 us this threshold
    if (adc_key_in < 50)   return btnRIGHT;
    if (adc_key_in < 250)  return btnUP;
    if (adc_key_in < 450)  return btnDOWN;
    if (adc_key_in < 650)  return btnLEFT;
    if (adc_key_in < 850)  return btnSELECT;

   // For V1.0 comment the other threshold and use the one below:
   /*
     if (adc_key_in < 50)   return btnRIGHT;
     if (adc_key_in < 195)  return btnUP;
     if (adc_key_in < 380)  return btnDOWN;
     if (adc_key_in < 555)  return btnLEFT;
     if (adc_key_in < 790)  return btnSELECT;
   */

    return btnNONE;                // when all others fail, return this.
}

void setup(){
   lcd.begin(16, 2);               // start the library
   lcd.setCursor(0,0);             // set the LCD cursor   position
   lcd.print("Push the buttons");  // print a simple message on the LCD
}

void loop(){
   lcd.setCursor(9,1);             // move cursor to second line "1" and 9 spaces over
   lcd.print(millis()/1000);       // display seconds elapsed since power-up

   lcd.setCursor(0,1);             // move to the begining of the second line
   lcd_key = read_LCD_buttons();   // read the buttons

   switch (lcd_key){               // depending on which button was pushed, we perform an action

       case btnRIGHT:{             //  push button "RIGHT" and show the word on the screen
            lcd.print("RIGHT ");
            break;
       }
       case btnLEFT:{
             lcd.print("LEFT   "); //  push button "LEFT" and show the word on the screen
             break;
       }
       case btnUP:{
             lcd.print("UP    ");  //  push button "UP" and show the word on the screen
             break;
       }
       case btnDOWN:{
             lcd.print("DOWN  ");  //  push button "DOWN" and show the word on the screen
             break;
       }
       case btnSELECT:{
             lcd.print("SELECT");  //  push button "SELECT" and show the word on the screen
             break;
       }
       case btnNONE:{
             lcd.print("NONE  ");  //  No action  will show "None" on the screen
             break;
       }
   }
}


Trouble trying to turn a stepper while a button is pressed down

You don't set the pin itself:

Change

if (buttonPinBlue == HIGH) {

to

if (digitalRead(buttonPinBlue) == HIGH) {

Also you don't have to set the pin every time, only one time is enough: in function setup should be the following line (and it can be removed from the function stepp:

pinMode(buttonPinBlue, INPUT);

Note that if you want to use a 'click' to move to the next item, you have to debounce the button; on the Arduino site check for button debouncing: https://www.arduino.cc/en/Tutorial/Debounce


avrdude: stk500_recv(): programmer is not responding: lilypad arduino

Last time I bought one of the Lilypads, it did not have a bootloader. I had to buy a SMD programmer adapter that presses down over the 328P chip to bootload it as the board did not break out the ICSP pins to any pads.

I think I got mine here https://hobbyking.com/en_us/atmel-atmega-socket-firmware-flashing-tool.html but I haven't seen them in stock for a while.  Very handy tool tho. Another option is to tack wires to the appropriate uC pins and, connected to a 2x3 header that your Programmer can connect to. Remove the wires when done.


Two flow sensors, one ESP32, LCD and/or Arduino

A Hall Effect Sensor like that just gives you a pulse every rotation (or two pulses per rotation, etc) of the internal vanes.

If you use interrupts to count the pulses then two pulses arriving at the same time will be handled sequentially. The interrupt flag indicating a pulse has arrived is set in hardware the moment the pulse arrives, and the CPU checks all the interrupt flags between instructions. Each flag is handled sequentially, the order determined by interrupt priority settings and a "natural" order determined by the internal wiring of the CPU.

However there is a better way on the ESP32, and that is the Pulse Counter peripheral.  This is designed to count pulses like the signals from Hall Effect sensors.

You can just leave the Pulse Counter counting your pulses, then periodically read and reset the pulse count to see how much water has flowed in that period. It looks from the documentation that you can have two inputs both making the same counter increment, so it will do the aggregating for you.


There are some good applications for visualizing the serial data, including:

MegunoLink ($29.95; Lite free) - plotting, logging, programming, reporting and more.

MakerPlot ($39) - digital & analog plotting, monitoring, custom interfaces and more.

ArduinoPlot (free) - simple plotting.

arduino-plotter (free) - easy, light-weight plotting with support for all primitive types

Bridge Control Panel (free) - logging, plotting, and more.

RealtimePlotter (free) - 6 channels data plotting.

Real Time Serial Data Plotter (free) - CSV data plotting, logging and more.
SimPlot (free) - 4 channel plotting.

Arduino Serial Plotter (free) - built in Arduino Editor under Tools > Serial Plotter.

(This is a community wiki, you can expand the list.)


/dev/cu port resource always busy on OS X 10.10

Finally figured it out. I need to call Serial.flush().

  Waits for the transmission of outgoing serial data to complete.


Frequency measuring using Arduino (AC analog input)

This project includes a frequency counter.

https://www.instructables.com/id/Oscilloscope-in-a-Matchbox-Arduino/

From the project page:
This oscilloscope costs the price of an Arduino Nano (£2 and a display (£3) plus a few pence for resistors, etc. It's specification is:

max 1M samples/second, min 1000sps
8-bits per sample
DC 0-5V; AC +/- 550mV, AC +/- 117mV, AC +/- 25mV
USB "PC scope" or built-in display
could be battery-powered
optional logic display
optional frequency meter
optional voltmeter
optional signal generator

My comment: I build it, it's a nice little project and the author is an expert programmer.


Can I change Arduino program on-the-fly?

Replacing or modifying the existing code during run-time will require some form of uploading and over-writing the old code. This is deliberately not made straightforward or easy for these kinds of micro-controllers.

But you can change the program's strategy on the fly, if you anticipate the potential changes and include the code for each of the possibilities.

For example, write a set of functions that each embody one of the various ways of operating, and, at run-time, select which function the program should use. You can change the selection by setting a value from the keyboard or the program could sense some external trigger such as a button-press, or a temperature reading and respond by changing the selection - the value of an int, perhaps. A switch statement can use that value to call the appropriate function at the appropriate time:

uint8_t strategy = 0;           // init to the default strategy

switch( selector ){
case(1):                // has event 1 happened?
   func1();
   break;

case(2):                // has event 2 happened?
   func2();
   break;

case(3):                // has event 3 happened?
   func3();
   break;

default:                // none of the above or undefined selector value
   funcDefault();
   break;
}

This does mean that all of the code for the possible operating strategies must be included at upload-time and share the program-memory space, but unless your job is very complex, even an Uno should be capable enough.

Update:

  I need to be able to update the device with some new functionality.

There is another approach which may or may not fit in an Uno but would be doable with a Mega 2560 or other larger-RAMmed machine: interpreted code.

Define a set of operations that includes whatever you'll need to operate your external device(s): the necessary I/O operations to read your sensors and control your hardware; to make logical and/or arithmetic tests and conditionally branch or call a function based on the test result; to listen for a user-signal from the terminal (for example) and return to the arduino program. This will be the "language" in which you write your control program.
Define a concise coding scheme to specify each operation and whatever data it needs, such as reading a temperature sensor and storing the result in a named place. If your control programs won't be too complex, you can get away with pre-defining A, B, ..., Z to be data registers of some appropriate type.
In C++, write an interpreter for this new language. It's program will consist of the codes you just defined. But this code will be seen as data by the interpreter. This is the key - this pseudo-code will live in RAM, where your interpreter - a collection of C++ functions - can read and execute it, and the Arduino program can download a new one, over-write the old one, and run the interpreter again.

Caveat: Like the Greek mythological Hydra, this is a job that can grow new challenges as you address the current ones, but it is doable if you keep it simple as possible and include only what you must have to make it work.

Run-time-interpreted code can take 10 - 50 times as long to execute as a natively coded application, so anything that can be pre-coded in C++ should be. The finer and more flexible your interpreted instructions, the more expressive you can be when writing the control program, but the interpreter will be more complex to write, slower to execute, and harder to debug. Design your language to be only as flexible as it must be to allow you to write new control algorithms.

If you try to invent an entire pseudo-computer, completely flexible and capable of being programmed for any and all purposes, you'll drive yourself crazy. Whole businesses have folded after sinking money and time into inventing a new and better computer and got so bogged down they couldn't recover. Don't go that route.

Start with the grossest, least flexible operations you can live with and get that much working. Discover its limitations and address those, and only those, one at a time, until you have a sufficiently flexible system in which to control your device.


Using two digits to display a number using TM1637 and a 4-digit display

Using tm1637.display(digit#, value); calls, you can display a two-digit number using division to isolate the tens digit and mod to isolate the units digit.  For example, if hour and mins have hour and minute values, respectively, consider code like:

tm1637.display(0, hour/10);
tm1637.display(1, hour%10);
tm1637.display(2, mins/10);
tm1637.display(3, mins%10);

Code like the above is suitable in cases where values don't exceed 99, and where displaying a leading zero is ok.

If you don't want to display the leading zero when hour is less than 10, add an if test and blank the first digit in that case.


How do I scroll through the LCD vertically with joystick?

The LCD library provides easy functions that activate commands in the LCD itself.  The LCD doesn't have functions that do what you want, so there is no simple vertical scrolling like you're suggesting.

If you need to have it, you'll need to re-write the screen with the content you want to display when the user scrolls around. I can't make any specific suggestions as I don't know the reason you need to scroll around the display this way, but one comprehensive method would be to create a buffer of data the LCD should be displaying, then scroll it using software (move the bytes around the way you want) and then send that buffer to the LCD when it changes.

There may be other more applicable or easier tricks, but that would largely depend on your specific use case and user interface design.


Each pin has its own, separate, pullup resistor.

I don't believe you can damage it by drawing current from the port, because the pullup resistor is only active when the port is in high impedance (hi-Z, input) mode.

The pullup resistor can be damaged by overvoltage, static discharge, and the like.

The Uno has 20 kOhm pullup resistors according to this tutorial. If you feed it a 0V signal while the Atmega is running at 5V, the current will be a quarter of a milliamp, which is miniscule.


You are never closing the file.  The SD library (owing to how SD cards work) operates around a 512 byte buffer. Only when that buffer is full, or the library is manually instructed, will that buffer ever get written to the SD card.

The two ways of forcing the buffer to be written to the card are:

Close the file with myFile.close() or
Flush the file with myFile.flush()

Unless you do one of those after storing your data, since you are writing less than 512 bytes, the data will be lost when you power off (or reset) or remove the SD card.


Fast switching of high load using an IGBT

One of the key requirements for IGBT driver circuits is
that enough current be supplied to charge and discharge
the input capacitance of the IGBT and thus to switch the
IGBT on and off at very high Switching rates.


Have you tried resetting the board after sending the program? Or after having opened the terminal?

A few days ago I didn't have any results using SerialUSB, and today I have. The program has been sent trough the programming port, and SerialUSB is with native port. Uploading my program trough native port, it didn't worked until I reset!


Arduino Mega with two Arduino Unos as slaves via I2C?

Welcome to the wonderful world of microcontrollers!  Looks like an exciting project, and you will definitely learn a lot!

As for wiring with I2C, you have a few things to connect:

SDA (the "data" line)
SCK (the "clock" line)
GND (ground)

For I2C (which is also called TWI for two-wire interface), you connect all like lines together.  This means connect all the SDA pins (analog pin 4 [A4] on Unos, digital pin 20 on the Mega) and all the SCK pins (analog pin 5 [A5] on the Unos, digital pin 21 on the Megas).  I think the schematic is different than this.  I can't read the actual lettering on the boards because the image resolution is not high enough.  You also want to connect all the ground pins together, which you've done in your drawing.

If you want a quick way to get up and running with I2C, use the example sketches in the Arduino programming environment.  Open up Arduino, then go to File > Examples > Wire.  In your case, I would pick one master and use the other two as slaves.  I would try using the master_writer on the Mega and slave_receiver on the 2 Unos.  A good idea would be to leave all of the accelerometers, potentiometers, etc. off to start.  Just have the master send a command to the two slaves, and when they receive it they can light up their on-board LED:

digitalWrite(13, HIGH)

Another note: the Fritzing sketch shows a 3.7V battery powering the Arduinos, but they need 6-20V and it's best to use 7-12V.  This may just be a filler battery you threw in for the drawing, I understand.  Just in case, I thought I'd mention it.

As suggested by Nick Gammon above, you will probably get the best response by breaking up the rest of your post into individual questions.  Good luck with your project!  Sounds like a fun one!


The MPU6050 has an accelerometer and a rate gyro (which tells you how fast it is rotating). The accelerometer will tell you which direction is down and in a motionless situation, that is all the information you have.

You'll probably want something like the MPU9150, it has a compass, which will give you the directional information you're asking for.


Is Arduino stable enough to use it for a door lock?

I'm not sure if the platform is stable enough to use it for something like this.

Absolutely it is. As I describe in my post about an RFID door lock I use a Uno (and some additional parts) to unlock my door.

Since writing that I improved the software as described here so you can reprogram the valid list of cards "on the fly" (without uploading new code) as the valid cards are stored in EEPROM.

My system has been operating for over 5 years without any problems, except once when there was a brownout in the area and I had to power cycle the system (possibly the RFID reader failed and not the Arduino).

My system "fails shut" so it keeps the door locked in the event of a power failure. However I have alternate ways of leaving the building in the event of a power failure combined with a fire.

You are talking about a servo rather than an electric strike. That is likely to be the weak point, and not the Arduino as such. You would need to ensure it was powerful enough to do whatever-it-is you are planning to do, and that it had suitable drivers (eg. MOSFET or driver board).

My system gets used dozens of times each day. We never have a problem with it.


Any semi-reputable authentication mechanism would be performed over HTTPS, which is an encrypted connection - this would require an SSL library to be installed for use along with the normal Ethernet and HTTP libraries, and I don't believe the arduino really has the processing capability to make connections like this feasible.
Unfortunately this is one of those cases where a more sophisticated device may be more appropriate.... (like a Beaglebone Black, or a Raspberry Pi.)

It is possible that you could add headers into the HTTP connection packet to either bypass proxy authentication, or include a cookie that has already undergone authentication and is cached by the proxy. How you do this is almost entirely down to how your proxy works. You may also find this doesn't work unless you spoof the MAC address of your device to match that of the machine used to fulfill the authentication.

It is entirely possible to set up a system to share the internet connection (act as a router) between two adapters - so you end up making connection requests to webpages, but the authenticated proxy only sees requests coming from your system (this is kind of how mobile phone tethering works, when you access the internet on a laptop or tablet through your smartphone's internet connection).

If the proxy supports unencrypted authentication, it may be possible to pass through username/password details in plaintext (or Base64 encoded) in Basic access authentication, which is what HTTP (and HTTPS) often uses - but this is unsafe on HTTP and is VERY unsafe when any part of the connection is publicly transmitted - like when using wifi, for example. (Doesn't matter if the wifi is encrypted - as on a university network, everyone who can connect to the wifi can see your wifi traffic (typically).)

If you're going to be using your own personal university login credentials to do this, make sure you always use ethernet to do it, not wifi, and if possible, obtain a second username/password explicitly for connecting this way - you don't want to have to hard-code your own personal username and password into source code that you have to give to anyone.

Here's a few links to get you started:

HTTP Spec: Proxy-Authorization and Authorization headers
How to use authentication in an HTTP Proxy?
Wikipedia: X-Forwarded-For


Arduino MIDI Program Change to Voodoo Labs GCX Converter

To solve this problem I used an Arduino UNO and a Olimex MIDI shield. I also want to use MIDI PC messages and Bank Selects.

For reference:

A Channel 16 PC 77 with Bank select 0 converts to binary 0x4D => Binary 01001101
A Channel 16 PC 77 with Bank Select 1 converts to binary 0xCD => Binary 11001101

Just to point out, the Bank Select value basically controls bit 8 and the PC value represents bits 6 down to 0

Based on the binary output, I scroll through bits 0 to 7 and send messages on CC 80 to CC 87. If a bit is a 1, I turn the loop on by setting the corresponding CC value to 127 and if it is a zero, I set the CC value to 0.

The Helix can generate a Bank Select and PC as one message, so for the price of one message, this project will make me 8 CC#'s effectively. ;)

It should allow other messages through, with the Arduino's SW loop latency. There maybe some other side effects to, but those should be limited to channel 16 only.

I have tested this on a Arduino UNO board with an Olimex MIDI Shield.

// GCX Editor
// By Rich Maes
// Converts MIDI PC's on channel 16 to GCX CC's starting at 0x80
// Allows everything else to pass.

#define MIDI_PC_CH16 0xCF
#define MIDI_CC_CH16 0xBF
#define MIDI_SYSEX 0xF0
#define MIDI_SYSRT_CLK 0xF8

boolean byteReady;
boolean sendCCMessage;
int ccMsgsToSend;
unsigned char midiByte;
unsigned char capturePCByte;
unsigned char captureCCByte;

// Queue Logic for storing messages
int headQ = 0;
int tailQ = 0;
unsigned char tx_queue[128];

int getQDepth();
void addQueue(unsigned char myByte);
void addCCQueue(unsigned char captureCCByte, unsigned char capturePCByte);
unsigned char deQueue();

static enum {
    STATE_UNKNOWN,
    STATE_1PARAM,
    STATE_1PARAM_CONTINUE,
    STATE_2PARAM_1,
    STATE_2PARAM_2,
    STATE_2PARAM_1_CONTINUE,
    STATE_PASSTHRU
  } state = STATE_UNKNOWN;

void setup() {
  // put your setup code here, to run once:
  //  Set MIDI baud rate:
  Serial.begin(31250);
  sendCCMessage = false;
  byteReady = false;
  midiByte = 0x00;
  state = STATE_UNKNOWN;
  captureCCByte = 0;
  capturePCByte = 0;
  ccMsgsToSend = 0;
}

int getQDepth() {
int depth = 0;
    if (headQ < tailQ) {
        depth = 128 - (tailQ - headQ);
    } else {
        depth = headQ - tailQ;
    }
    return depth;
}

void addQueue (unsigned char myByte) {
    int depth = 0;
    depth = getQDepth();

    if (depth < 126) {
        tx_queue[headQ] = myByte;
        headQ++;
        headQ = headQ % 128; // Always keep the headQ limited between 0 and 127
    }
}

void addCCQueue(unsigned char myCaptureCCByte, unsigned char myCapturePCByte) {
    int i;
    if (getQDepth() < 80) {
        // There is enough space to add our CC messages
        for (i = 0; i < 8; i++) {
            addQueue(0xBF);
            addQueue(80 + i);
            addQueue(127 * ((((myCaptureCCByte * 128) + myCapturePCByte) >> i) % 2));
        }
    } else {
        // This is an error condition.  So reset the queue and pointers
        headQ = 0;
        tailQ = 0;
        byteReady = false;
        for (i = 0; i < 128; i++) {
            tx_queue[i] = 0;
        }
    }
}

unsigned char deQueue() {
    unsigned char myByte;
    myByte = tx_queue[tailQ];
    tailQ++;
    tailQ = tailQ % 128;  // Keep this tailQ contained within a limit
    // Now that we dequeed the byte, it must be sent.
    return myByte;
}

void loop() {
    if (byteReady) {
        if (midiByte >= 0xF0) {
            // This automatically passes all clocks and System Realtime Messages
            state = STATE_PASSTHRU;
        } else if (midiByte >= 0x80) {
            switch (midiByte) {
            case MIDI_PC_CH16:
                state = STATE_1PARAM;
                break;
            case MIDI_CC_CH16:
                state = STATE_2PARAM_1;
                break;
            default:
                state = STATE_PASSTHRU;
                break;
            }
        }  else {
            switch (state) {
            case  STATE_1PARAM:
                capturePCByte = midiByte;
                state = STATE_1PARAM_CONTINUE;
                addCCQueue(captureCCByte, capturePCByte);
                break;
            case STATE_2PARAM_1:
                if (midiByte == 32) state = STATE_2PARAM_2;
                else state = STATE_2PARAM_1_CONTINUE;
                break;
            case STATE_2PARAM_2:
                state = STATE_2PARAM_1_CONTINUE;
                captureCCByte = midiByte;
                break;
            default:
                state = STATE_PASSTHRU;
                break;
            }
        }
    }

    if ((state == STATE_PASSTHRU) && byteReady) {
        // Just pass messages unaltered.  Also don't let any of our modified message through if
        // we are passing though.  Our burst of modified CC# can wait.
        // Serial.write(midiByte);
        addQueue(midiByte);
        // state = STATE_UNKNOWN;
    }
    byteReady = false;

    if (getQDepth() > 0) {
        // We have a byte to send, dequeu and send it
        Serial.write(deQueue());
    }
}

// The little function that gets called each time loop is called.
// This is automated somwhere in the Arduino code.
void serialEvent() {
  if (Serial.available()) {
    // get the new byte:
    midiByte = (unsigned char)Serial.read();
    byteReady = true;
  }
}


If I put a shield on an Arduino, can I use the Arduino for anything else?

Normally, yes, you may plug other components to your setup after you plug your shield, but it depends on the shield exposing the unused Arduino pins through additional female headers.

Some shields even provide a little protoboard or perfboard to make it convenient for plugging or soldering additional components. Below are some examples:

Arduino shields are normally designed to be stackable, so you can plug one on top of the other. See more on Arduino shields from this WikiPedia article. See below one example of stacked shields, shamefully stolen from this great answer by RedGrittyBrick.

Photo by John Boxall

But note that you need to study carefully what pins each of the shields use to avoid conflicts between the boards. Such conflicts may lead to damages.


Controlling flexinol with an arduino board?

First thing's first, this just seems to be a wire that has special characteristics. If so, we just need to find out the resistance and use Ohm's law.

From the product page, I found this image:

I can tell from that that it has a resistance of 20 ohms and a recommended current of 1 amp. First, let's see how much current it would draw with a 5V supply. I prefer using a Ohm's law triangle, just because I'm a very visual person. So with this math:

  5 / 20 = 0.25

That's 250 mA, but an Arduino can only provide 40 mA! Furthermore, it is only 1/4 of the recommended current that the manufacturer specifies.

To get the full current the OEM specifies you'll need a 20 V power supply capable of at least 1A. Even then, you might want to put in a power resistor to limit the current.

Driving this with Arduino: So, we have a few problems here:

It is 20W, which is quite a bit in the Arduino world
We need to control the current/voltage dynamically
You need 16 of them, so we don't want something too costly
You probably can't find something to fit your needs that is one shield.

What comes to mind is a transistor. I'm not skilled with picking them out, but there are a lot of guides online. You'd then want to add a capacitor and a resistor to make some sort of filter and connect it to a PWM pin to send a varied voltage to the transistor, which will vary the amount of power going through it.

Alternatively, you could use a relay. However, that only does ON or OFF. A solid state relay (SSR) would allow you to use PWM on the relay and then you could add a capacitor/resistor combo on the other end of it, but you'd need a pretty large capacitor or a pretty large frequency for the PWM (which you can modify).


Measuring high frequencies (300kHz) with arduino

To sample a 300kHz signal you need to sample at at least 600,000 samples per second (see Nyquist-Shannon Theorem).

The Arduino can sample at an absolute maximum of 125,000 samples per second.

A normal Arduino will not be able to sample the analog input fast enough to even remotely have a clue what the frequency is - let alone what shape the signal is (for that you would have to be sampling in the millions of samples per second).

You will need a much more powerful board than an Arduino to do it.

The other option is to feed the signal through a comparator (an op-amp with infinite gain) to convert the signal into a square wave. You can then use simple frequency counting to get the frequency (count the pulses within a given time frame - maybe 1 second).

As for the rest of your questions, you would be better off asking those on Electrical Engineering.


Error to make a request using Arduino Uno and ESP8266

A HTTP requests is comprised of more than just GET /webservice/. Take a look at what curl (console-line HTTP client) does.

C:\>curl -v "http://ternary.com.br/webservice/"
*   Trying 187.84.237.200...
* Connected to ternary.com.br (187.84.237.200) port 80 (#0)
> GET /webservice/ HTTP/1.1
> Host: ternary.com.br
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 11 May 2018 15:04:16 GMT
< Server: Apache
< X-Powered-By: PHP/5.6.30
< Vary: Accept-Encoding
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Expires: Wed, 11 Jan 1984 05:00:00 GMT
< X-UA-Compatible: IE=Edge,chrome=1
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<

Hello Versa
* Connection #0 to host ternary.com.br left intact

You will have to at least transfer the minimal correct HTTP Headers of the form

GET /webservice/ HTTP/1.1
Host: ternary.com.br
Connection: Close

To get an answer. Also mind the ending \r\n\r\n. Refer to this website for more headers.

When I only send GET /webservice/ I also get 404 page.

C:\>cat test
GET /webservice/

C:\>cat test | ncat ternary.com.br 80
[...]
        <title data-i18n="[html]404_page.title">404 ÔÇô P├ígina n├úo encontrada</title>


Measure revolutions per second with reed switch

It sounds like occasional "misses". Possible causes include:

the magnet passing far enough from the reed switch to "only just" trigger it [narrow the gap.];
the magnet's passage being too short for the reed switch/capacitor to respond [use a wider magnet or move closer to the center of rotation];
Too much capacitance [reduce it or debounce in software];

Update:

  Would it be better to debounce in software and what would be the best way to do it.

If you have an oscilloscope available, you could look at the raw switch signal (no capacitor) to find out how long it bounces. I'm guessing that it will be around 10ms for such a small switch. If the entire [make/break/make/break....] sequence takes less than 50% (being conservative) of the wheel rotation time (1/max_RPS), you can probably count the first pulse and ignore the switch for (0.5/max_RPS), or 1/2 of the fastest rotation. You appear to be doing something like this already. If you want to be a little bit more rigorous, you might do:

see a HIGH;
ignore switch for debounce_time;
if still HIGH,
   count++;

Also, don't forget that variables shared between your Interrupt function and the main-line code need to be:

declared as volatile, to tell the compiler not to expect that this variable has the value it had last time the mainline code read it; and
Turn interrupts off briefly while reading or writing such a variable (if it is multi-byte) in your mainline, to prevent it being changed by the interrupt function between byte-reads/writes by the mainline.


You might want to look into how LORAN works, as I believe you can do something similar.

First premise: You want to look for the initial transient caused by the impact propagating to sensors in various places on the periphery.  The signal in the material will end up bouncing around quite a bit before it dies out, but the leading edge of the initial transient should be unambiguous, so use that.

Second premise: You have no idea when the ball actually hits - you can also measure the difference in timing between when various sensors first detect it.

So take any two sensors, measure the time lag between when they detect the ball, and convert that via the speed of sound in your material.  This yields the difference in the distance of the impact point from the two sensors.  If you know the position of the two sensors, and plot the curves of points which satisfy the equation of the measured difference in distance from each of them you can a class of conic section called a hyperbola.

But so far you do not have an answer, but only a pair of curves along which the impact must lie.  So now take at least one new sensor, and repeate the exercise generation a new equation.

Combine the equations and solve to find the intersection of the curves - this is your point of impact.  It is possible to have more than one mathematical solution, but I think you will find that only one possible solution lies in the area between the sensors.

(Unfortunately, the ATmega328p A/D converter probably isn't fast enough to do a good job of this - at 10KSPS each sample is around 34mm in air, and around half a meter in typical solids - so you either need a much faster A/D, or else tune a comparator circuit to detect pulses and measure them with ATmega timer channels.)


What sensor would I use to get the speed or velocity of my Arduino based nav system?

On small recreational sailboats there is a small propeller on the bottom, when it turns it dials a speedometer, the faster it turns the faster the ship goes, a similar setup should be possible. With a small propeller and 2 ball bearings and an optocoupler, (same principle you got in the scroll button on your mouse, you should be able to pull it off with minimal resistance since there is no physical parts.


Simultanous read and read/write on two serial connections

Adafruit_GPS.h (line 132-), which is included in Adafruit_GPS.cpp (line 13) refers in turn to the SoftwareSerial library on AVR platform and Arduino IDE version > 100.

#ifdef __AVR__
#if ARDUINO >= 100
    SoftwareSerial *gpsSwSerial;
#else
    NewSoftSerial *gpsSwSerial;
#endif
#endif

This means it uses software serial on an Uno. It also means if your problem is indeed with Software Serial, that is the library to check for bugs / updates or commit a patch to.


You should create your library as a separate project: File->New->Project and select C or C++ static library:

Add your library modules in this project. When building, this will create lib{your_project_name}.a file (in Debug or Release folder) - your library object file you can use in your other projects.

Usually I include in the same solution both the library project and target project (just library project file, sure the library and it's files resides in single place):

ORDO is the library name.

Some check list:

Include the library file in Libraries folder (shown above)
Specify the path to the library *.a file for linker (Toolchain->AVR/GNU Linker->Libraries). Note that there should be different paths for Debug and Release configurations.
Specify the path for library include files (Toolchain->AVR/GNU C or C++ Compiler->Directories)
In some cases, F_CPU definition might be needed for library project too (same as in your project, under Symbols).
When changes are made in your library files, use Build solution (F7) when building, if not - you can use Build project (which will be faster).

Setting project dependencies shall also lead to rebuilding the library automatically when needed (not tested, I usually just hit F7 :).


Wake up ESP8266 from deepSleep with a button

Use some other pin to hold RESET HIGH or to disconnect the button from RESET while the esp8266 is not running.

simulate this circuit – Schematic created using CircuitLab

I asked on EE SE for the missing part of the circuit.


I've had some progress in my researches towards this problem.

In fact, Arduino gets the correct gateway address from my DHCP server, but displays the wrong one. There must be a bug somewhere in WiFiEsp library somewhere.

To debug this, I made a few changes to the following files:

WiFiEsp-Master/src/WiFiEsp.h

void config(IPAddress local_ip, IPAddress gateway);
void config(IPAddress local_ip, IPAddress gateway, IPAddress subnetMask);

WiFiEsp-Master/src/WiFiEsp.c

void WiFiEspClass::config(IPAddress ip, IPAddress gateway)
{
  EspDrv::config(ip, gateway);
}
void WiFiEspClass::config(IPAddress ip, IPAddress gateway, IPAddress subnetMask)
{
  EspDrv::config(ip, gateway, subnetMask);
}

WiFiEsp-Master/src/utility/EspDrv.h

static void config(IPAddress local_ip, IPAddress gateway);
static void config(IPAddress local_ip, IPAddress gateway, IPAddress subnetMask);

WiFiEsp-Master/src/utility/EspDrv.cpp

void EspDrv::config(IPAddress ip, IPAddress gateway) {
  LOGDEBUG(F("> config"));

  // disable station DHCP
  sendCmd(F("AT+CWDHCP_CUR=1,0"));

  // it seems we need to wait here...
  delay(500);

  char buf_ip[16];
  sprintf_P(buf_ip, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);

  char buf_gateway[16];
  sprintf_P(buf_gateway, PSTR("%d.%d.%d.%d"), gateway[0], gateway[1], gateway[2], gateway[3]);

  int ret = sendCmd(F("AT+CIPSTA_CUR=\"%s\",\"%s\""), 2000, buf_ip, buf_gateway);
  delay(500);

  if (ret==TAG_OK)
  {
    LOGINFO1(F("IP and gateway addresses set"), buf_ip);
  }
}

void EspDrv::config(IPAddress ip, IPAddress gateway, IPAddress subnet)
{

  LOGDEBUG(F("> config"));

  // disable station DHCP
  sendCmd(F("AT+CWDHCP_CUR=1,0"));

  // it seems we need to wait here...
  delay(500);

  char buf_ip[16];
  sprintf_P(buf_ip, PSTR("%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);

  char buf_gateway[16];
  sprintf_P(buf_gateway, PSTR("%d.%d.%d.%d"), gateway[0], gateway[1], gateway[2], gateway[3]);

  char buf_subnet[16];
  sprintf_P(buf_subnet, PSTR("%d.%d.%d.%d"), subnet[0], subnet[1], subnet[2], subnet[3]);

  int ret = sendCmd(F("AT+CIPSTA_CUR=\"%s\",\"%s\",\"%s\""), 4000, buf_ip, buf_gateway, buf_subnet);
  delay(500);

  if (ret==TAG_OK)
  {
    LOGINFO1(F("IP, gateway and subnet mask addresses set"), buf_ip);
  }
}

These few changes should be enough to implement fix IP address and specify manual address for gateway and subnet mask (please feel free to correct me if I'm wrong).

But after doing this, I realized the gateway continued to be "192.168.1.0". Then I added this piece o code to the function EspDrv::readUntil, inside EspDrv.cpp:"

        ringBuf.push(c); // this line was already there
        Serial.print(c);

This way, I could see exactly all responses for the AT commands sent by WiFiEsp library. When asked, the results were:

+CIPSTA:ip:"192.168.1.60"
+CIPSTA:gateway:"192.168.1.36"
+CIPSTA:netmask:"255.255.255.0"

Then I realized the problem wasn't the gateway, but the DNS. If the library sends command "AT+CIPSTART=3,"TCP","www.google.com",80", the result was:

Not connected

busy p...

And, if increased the timeout value to 15000 instead of 5000, the result was:

DNS ERROR

Now my problem is partially solved. I can connect to an external server if I use an IP address, but I can't set a domain name because it won't be resolved by the DNS.

Apparently the firmware version of my ESP-01 won't accept "AT+CDNSCFG=?" required to set/retrive DNS address. I tried to set 8.8.8.8 as the DNS, but the result was "NOT OK".

I will stick to this "solution" for now, but would be glad to hear any comment about what I described here and a more final solution.

Thanks.


I2C code working on Mega 2560 but not on Uno and nano

I added pull-up resistors to the board and it started working. Turns out that the boards weren't well designed and the I2C lines were pulled up to 1.8V instead of Vin. By removing the pull-ups and adding pull-ups to Vin, the circuit started functioning. The circuit worked with Mega because it has in-built Pull-up Resistors.


If you put:
    #define DO_NOTHING(s) (s)

    DO_NOTHING(R"xyz(Hello
    World)xyz")

you can see g++ choke on preprocessing the raw string literal in the macro invocation with the latest esp8266 board package as of writing (version 2.7.4).  This comes with g++ 4.8.2 for xtensa.
    ~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++ -E  donothing.h

You may need to adjust the command-line for your system.  donothing.h is just the macro and invocation described above.
Result:
# 1 "donothing.h"
# 1 "<command-line>"
# 1 "donothing.h"

donothing.h:3:13: warning: missing terminating " character [enabled by default]
 DO_NOTHING(R"xyz(Hello
             ^
(R"xyz(Hello World)
donothing.h:4:10: warning: missing terminating " character [enabled by default]
 World)xyz")
          ^
      xyz")

This does not happen with g++ 9.3.0 on an amd64 Linux target.
As a workaround you can reconstruct (more or less) what the F() macro does with the following:
    void setup() {
      Serial.begin(9600);
    }

    void loop() {
      static const char pgm_str[] PROGMEM = (R"xyz(Hello
    World)xyz");

      Serial.println(FPSTR(pgm_str));
      delay(4000);
    }


Using Leonardo as keyboard: add wake and sleep functions

It turns out there is a library that can be added to compile the media and system functions for USB keyboard connection into the Leonardo, as well as other Arduino modules. It is available through 'tools','library manager'; it is HID-project by NicoHood. There is an example program called "system example" at github to test it for for wake and sleep. It works perfectly.
I expect it'll work for the other functions too.


Say you have a string of 1000 characters in Flash, and you want to print it to Serial.  Yes, you need to load it into RAM in order to pass that data around the place for printing. But, do you need to put all of it in RAM at once?  No.  You only need one character at a time.  So instead of taking 1000 characters and allocating 1000 bytes of RAM and copying the whole shebang into RAM then printing it, you just need to allocate 1 byte of RAM* and copy each character in turn and print it.

Since you can only read one character at a time from flash there's no advantage in reading the whole lot anyway.

*Actually, because of compiler optimizations, this probably never even touches RAM and just stays in a CPU register.


Thank you Harry i managed to fix it by downloading CH341SER_MAC.zip just in case someone has the same problem wch.cn/downfile/178


Assign an interrupt to any pin of the atmega328 microcontroller

Here is a link to a good tutorial on how to enable, respond to, and clear interrupts on the ATMega328P device:
Arduino Pin Change Interrupts
I'll repeat the overall steps here in case this URL disappears in the future:
First, you must enable pin change interrupts:

Note the use of 3 bits in the PCICR register [0:2].  These enable pin change interrupts on ports B, C, or D in general.  You can choose any combination of these ports or all of the ports as you desire.
Next, you select which pin or pins on the enabled ports that you want to receive interrupts from.  You have control here over each individual port bit:

Then you must write an ISR (Interrupt Service Routine) to handle the interrupt once it occurs.  You have the option of up to THREE ISRs, one to handle each port or you can have a single ISR to handle any pin change interrupt.  The way this works is that when an interrupt happens on an enabled port and pin, the AVR chip calls the ISR that you have configured for that event:

So when an interrupt happens, how do you know which pin(s) caused the ISR?  Let's assume you used a single ISR to handle all 3 ports.  At this point you know only that an interrupt happened somewhere.  That's the purpose of the PCIFR register bits.  From the AVR datasheet we see this:

By checking the status of these bits you can now tell which pin or pins caused the interrupt.  Note that there CAN BE MORE THAN ONE, so it's up to you to decide the priority of each one and handle them accordingly.  Note that you only get ONE chance to read these during any ISR function call since they get cleared when the ISR executes.
One last note.  You MUST call the sei(); function to enable any interrupt to the CPU before any interrupt will happen.
In your example, however, you seem to be attempting to generate a pin change interrupt on an output. This is probably NOT what you want.  Try simply using the existing LED output pin as an indicator and choose a different pin, setup as INPUT, to be your pin change interrupt source.


datalogging sampling frequency bottleneck

First, based on my experience with similar hardware, something about the sd card I/O stinks: it should be plenty fast enough. Using a class 4 (cheapo) sd card I've seen a 16mhz AVR do a FAT filesystem open for appending, write a new record of maybe 70 characters and close the file, all a few hundred times per second. This was with the Arduino "SD" library apparently written by Sparkfun in 2010 and improved by Adafruit sometime later.

Maybe the I/O library you're using is dog slow? Another possibility is that your SD card has a lot of files on it and something about directory (folder) traversal during an open is the bottleneck? (my experience is with just a few files on a given sd card)

But you could try buffering N samples so each sd card write records N samples.

If you do this, don't forget to "flush" any remaining samples when you go from "sampling" to "not sampling" modes, if that's possible. That is, if something is telling the thing 'start', then 'stop', part of the response to 'stop' is to get the N-m buffered samples written out to the sd card.


Arduino due dying after connection, gets hot

The "504L" is a 500mA polyfuse.  If more than 500mA is attempted to be drawn through the USB port it will get hot which causes the fuse to "trip".  When it cools down again it will "reset".

Why is too much current being drawn through the USB port?  Well, that's what needs answering to know just why your board is misbehaving:

Do you have lots of things plugged into the board - like LED strips, motors, etc?
Is the board sat on something metal causing a short circuit? (I did that by having some loose change on my desk once).
Have you physically damaged the board and caused some pins of one of the chips to short together?
Has the Magic Smoke™ escaped from one of the chips rendering your board broken?


Water level Detection using Ultrasonic Sensor and arduino

A friend of mine worked on a liquid level monitoring project, and after many iterations finally abandoned the kinds of sensors you're talking about. Ultimately he just pointed a cheap USB webcam at the thing and used OpenCV and the edge detection algorithm to find the level of the water.  Then it's just a matter of doing some math using the dimensions of the container, to figure out how full it is.

If you are using a clear container and if you have the option of using a Raspberry Pi (or a PC, whatever) that can run OpenCV, you might find that option worth exploring.


Arduino force feedback vibration gamepad

That library has no support for vibration.

The HID report descriptor has to include the correct OUTPUT items for the PC to send the vibration instructions to the Arduino - and of course the library has to be able to handle that incoming data - none of which is implemented.

So you can't unless you massively expand that library. And that takes intimate knowledge of USB and HID protocols.


Can I power a Wemos D1 R2 via the VIN and GND pins?

Wemos D1 R2 has on-board regulator with input from power jack and Vin pin. The regulator is for 9 to 24 V.


Why does this button have a connection to ground?

That resistor is called a pull-down resistor. It's there to make sure pin 2 read low when the button isn't pressed. If you don't put it there pin 2 is left 'floating', and it could erroneously read a high value. Google it for more info.

If you want to simplify you circuit you could instead use a pull-up resistor, and connect the button to ground instead of 5v. The ATMega chip on the arduino has these pull-up resistors build into the chip itself, so you don't need to add one to the breadboard. Just not that the input values will be reversed. So pin2 will read LOW when the button is pressed, and HIGH when not. To activate the internal pull-up use pinMode(2, INPUT_PULLUP)


Trying to flash ATTiny85 bootloader using FT232R in the Arduino IDE

A bootloader is a program that gets loaded into the bare microcontroller to handle a number of low level tasks. One of those tasks is the ability to load a program over UART (serial).

As such, the bootloader can be loaded into the microcontroller using a AVR programmer. Once this has occurred, you can then easily load in programs with the FT232R.

It is possible to use the bitbang mode on the FT232R to load the bootloader into an Arduino board, hence replacing the AVR programmer. So, it can work but it isn't easy.

As suggested by per1234, there is some instructions on how to do this to an Arduino Diecimila on the Adafruit website: Programming the Arduino Bootloader
In general the full page has a lot of useful information: Full page


Linker error when trying to use functions in separate header and source files

This is talked about here.  Evidently, the C++ compiler changes names of *.c files when compiling.  Try changing the names of your files from *.c to *.cpp so that the C++ compiler does not change the names. Then recompile.


Problem with 2 decimal places/2 significant figures

You're talking about the output from this line?

Serial.println( (String) "DATA,DATE,TIME," +flat+ "");

drop the use of the String class and make that two separate print statements.  Then you can use the second argument to print to define the precision.

Serial.print("DATA,DATE,TIME,");
Serial.println(flat, 6);

That gets the same end result output going out the serial line, but lets you specify the precision and avoids the nasty String class.


Do I use 3,3V or 5V, when device supports both?

Using the MAX3232 data sheet , which is what the TTL Converter has on it's board :

The main difference between using 3.3v or 5v is on the receiver data line "R" (or Rout as it is called on the MAX3232).

Simply put, you want to power the TTL converter from the same voltage as your Arduino is using (3.3v or 5v). Meaning the voltage that your I/O pins will put out and accept.

The received data line R will go between 0 volts and Vcc.

You would NOT want to power the TTL converter at 5 volts if you are using the converter for a 3.3v Arduino, as the received data line would go to 5 volts when high. Actually Vcc - 0.1 volts (typ.)  (5 - .1 = 4.9)  as per this specification :

If you power the TTL converter from 3.3 volts, the received data line (Rout) switches between 0v and 3.3v   as shown here :


Sending a string from RPi to Arduino - Working Code

onReceive is intended for use by slaves. master must request data from slave and wait for answer. look at MasterReader example from the Wire library


What is the best serial protocol for bidirectional communication with NodeMCU?

So you are asking how to use an Arduino Pro Mini as a smart peripheral connected to a NodeMCU master, without making use of the hardware serial port on the latter.

In general, this is either going to operate slowly enough that you can guarantee reception, or you will need to use some kind of flow control or acknowledgement.

One question is whether the APM can always receive at any time, or whether it has to do things which would cause it to not respond for some while and possibly lose data.

Hardware I2c or SPI, with a software flow control protocol using additional pins, are probably your best bets if you cannot use async serial.  For example the APM sets OK2SEND high when it's ready to receive (this is an APM output pin connected to a NodeMCU input pin).  When NodeMCU detects this high, it writes to I2C and then sets HAVESENT high.  When the APM detects & processes incoming data as I2C slave, it sets OK2SEND low.  NodeMCU sees OK2SEND low (ack'ing the byte) and sets HAVESENT low.  APM detects HAVESENT low which completes the handshake.  When APM is ready for another byte, it sets OK2SEND high again.  etc.  Variants could send more than one byte per handshake, if performance needs that; APM asserting OK2SEND would be contracting to handle that number of bytes.

If you can guarantee that the APM will respond quickly enough to interrupts, you could use an interrupt driven I2C slave system on it, and simplify the above.  The APM could be like a dedicated I2C peripheral, albeit a slow one.


digitalPin giving lower voltage than Vcc

You should connect the AVCC pin to VCC. From the datasheet (emphasis
mine):

  AVCC is the supply voltage pin for the A/D converter and
  a selection of I/O pins. This pin should be externally connected to
  VCC even if the ADC is not used. [...]

  The following pins receive their supply voltage from AVCC:
  PC7, PC[5:0] and (in 32-lead pack- ages) PA[1:0]. All other I/O
  pins take their supply voltage from VCC.


Simple network protocol to communicate between N slave arduino and 1 central arduino?

You have quite a few options available to you as your requirements are filled by quite a few protocols, I am not going to list all. You can use things such as I2C, CAN, RS-485, RS-232.

You can find a few good examples from this EE.SE post from a search.

The CAN option is quite a good one for your application and is easy to set up and there are quite a few libraries available for the common chip MCP2525 and MCP2551. Yo can also get a 'shield' with this functionality from sparkfun.

The other options are discussed in the linked EE.SE post with regards to RS-485.

I2C can be implemented with the Wire library of arduinos and other libraries.

You can use RS-232, but I don't think it will be immune to noise at the distance you want, but you can still try. What you can do is use a multiplexer, such as this one CD74HC4067, and use it to multiplex the TX line from each node to the RX of the master.

From SFE's site:

  For example, you could use it to connect the TX pins of 16 devices to one RX pin on your microcontroller. You can then select any one of those 16 devices to listen to. If you want two-way communications, you can add a second board to route your microcontroller’s TX line to 16 device’s RX lines. By using multiple boards, you can create similar arrangements for I2C, SPI, etc.

You will probably want to add some sort of checksum/CRC to the data you send over the network too.


Store TinyGPS++ latitude value into a variable of type string or float

it returns me Tiny lat:33.55 on serial monitor. But i want 33.546600. How do I do that?

The issue is simply the number of decimal places. That can be added to the Serial.println().

double Tiny_latitude = (gps.location.lat());
Serial.print("Tiny lat:");
Serial.println(Tiny_latitude, 6);

  Now if i want to make a String "your location is \nlat:33.546600 \nlong: 75.456912" , i.e. my String variable are stored in Tiny_latitude and Tiny_longitude and want to make a string my_Location. How do i do that?

I would use sprintf() for that but as that requires some additional build parameters the easiest way is to use String. Some special care is needed to increase the number of decimal places.

void loop()
{
  ...
  float latitude = 33.546600;
  float longitude = 75.456912;
  String buf;
  buf += F("your location is \nlat:");
  buf += String(latitude, 6);
  buf += F("\nlong:");
  buf += String(longitude, 6);
  Serial.println(buf);
  ...
}

Cheers!


Help with my DHT22 sensor and using GET request

The Adafruit DHT library causes a shortcut on the signal line. That can be a problem for Arduino boards, but it is a big problem for the ESP8266.
Issue: DHT init sequence wrong #48
I don't know what is a bigger problem, the shortcut in the code or Adafruit not fixing it.

Why do you mention the Arduino Uno with a label ?
For the "GET" you should find a good working example.

The DHT22 is not very good. There are better sensors with a normal I2C interface, for example the HTU21D-F or the BME-280. This is about a great test: Hackaday: Humidity Sensor Shootout. The BME-280 is the undisputed winner.


How do I change the I2C address on the LCD backpack?

As mentioned in the page you linked, jumper together one of the address jumpers. For example, above A0 are two pads. Solder a wire across them (vertically - between the two pads above A0). I am guessing the address is pulled high by a resistor, so that will probably make the new address 0x3E, but you could run the I2C scanner to check that.


AVRdude + Arduino leonardo: can't flash over bootloader, not in sync: resp=0x3f

You're specifying the wrong bootloader protocol via -carduino. The Arduino bootloader is for boards using the Diecimila bootloader. The Leonardo uses the "AVR109" bootloader - named after the Atmel Application Note which describes its protocol.

Try this command on for size:

avrdude -cavr109 -P COM5 -n -p m32u4 -b57600 -v

Don't forget to press the reset button (or open and close COM5 at 1200 baud) first to run the bootloader.


How to read AC Voltage in arduino uno with 12V adaptor and usb cable.?

If your battery voltage is lower than 12 but sufficiently high to power the arduino (let's say 9V), you could put a white LED on the 12V line and a red LED on the battery line, like this:

         WHITE       RED
  _______|>|_________|<|________
 |             |                |
_|_          Arduino           _|_
 - 12V         |                -   Battery
 |_____________|________________|

This should work, as long as the LEDs can withstand the reverse voltage.
And you do not need to drive them from the Arduino.
If you still want to know the status fro mthe Arduino (mains or battery) you can sample the voltage level across the Arduino.


Sending multi-byte data over I2C between different processors

There seems to be multiple questions in what you are asking. Here I try
to answer specifically this one:

  if I shift a uint16_t (or any non-trivial datatype) right by 8 bits,
  and mask out the bottom 8 with &0xFF, do I always get the
  second-least-significant (in this particular case, high) byte, or can
  the compiler produce alternate outputs based on byte order?

Short answer: yes, you get the second-least-significant byte,
irrespective of the platform's native endianness.

Now, I'll expand on this answer by showing the different ways you
can convert an uint16_t to a sequence of bytes, and the implications
on the byte order.

If you want to control the endianness, and you want your code to work
independently of the native endianness of the platform, then bit
shifting is the way to go. Let's assume you want to convert this:

uint16_t data;

into this:

uint8_t bytes[2];

You can do it this way in order to get the least significant byte first:

bytes[0] = data >> 0;  // least significant byte
bytes[1] = data >> 8;  // most significant byte

Or you can instead do the assignments the other way around
(data >> 8 goes to bytes[0]...) if you want MSB first. Note that
there is no point in masking, as the assignment does it implicitly.

In contrast, if you wanted to put the bytes in native endianness (the
endianness of the platform), the traditional way to do it is to cast the
address of the number to a pointer to bytes, then read from this
pointer:

bytes[0] = ((uint8_t *) &data)[0];  // first byte
bytes[1] = ((uint8_t *) &data)[1];  // last byte

You can swap the indices on one side of the assignments if you want to
instead reverse the byte order. But note that this kind of casting is
now frowned upon, as it violates aliasing rules. A common alternative is
to have the number and the byte array share the memory within an
union:

union {
    uint16_t data;
    uint8_t bytes[2];
} x = { .data = some_16_bit_value };
do_something_with(x.bytes[0]);  // use first byte
do_something_with(x.bytes[1]);  // use second byte

These are the main byte-splitting idioms you may come across. If your
purpose is to have an endianness that you control and is independent of
the platform, then stick with the first option: the old good bit
shifting.


That library should work with pretty much anything that has the M10 module on it.

I only have experience with the SIM900 modules. Found the cheapest one on EBay.

While interfacing with these things can be a challenge at first, you really just need to read the manual for all the AT commands and execute them. I've written a couple of functions that may help:

Note: you may safely replace all instances of DEBUG_PRINT and DEBUG_PRINTLN with Serial.print and Serial.println.

SoftwareSerial SIM900(7, 8);

/*
    Sends AT commands to SIM900 module.

    Parameter   Description
    command     String containing the AT command to send to the module
    timeout     A timeout, in milliseconds, to wait for the response

    Returns a string containing the response. Returns NULL on timeout.

*/
String SIMCommunication::sendCommand(String command, int timeout) {
    SIM900.listen();
    // Clear read buffer before sending new command
    while(SIM900.available()) { SIM900.read(); }

    SIM900.println(command);

    if (responseTimedOut(timeout)) {
        DEBUG_PRINT(F("sendCommand Timed Out: "));DEBUG_PRINTLN(command);
        return NULL;
    }

    String response = "";

    while(SIM900.available()) {
        response.concat((char)SIM900.read());
        delayMicroseconds(500);
    }

    return response;
}

/*
    Waits for a response from SIM900 for <ms> milliseconds

    Returns true if timed out without response. False otherwise.
*/
bool SIMCommunication::responseTimedOut(int ms) {
    SIM900.listen();

    int counter = 0;
    while(!SIM900.available() && counter < ms) {
        counter++;
        delay(1);
    }

    // Timed out, return null
    if (counter >= ms) {
        return true;
    }
    counter = 0;
    return false;
}


how to send large strings (> 100 characters) from arduino serial monitor

I saw that arduino cannot read more than 63 characters at a time.

Not strictly true. The Arduino core HardwareSerial library has a 64 byte buffer, so it can only buffer up to 64 characters. If your sketch is reading the characters from the buffer whilst you are sending the characters from your PC then that limit is irrelevant. As long as you are reading the characters as fast as they are coming in.

Serial is actually quite slow (on the scale of things) and unless you're doing silly things like using delay() or long blocking loops, then reading the data fast enough is not that big a problem.  If you do need more time the simplest way is just to slow down the serial data somewhat - i.e., use a lower baud rate. The slower you send the data the longer you get between each character arrives to do things.

For strings the size you are on about you are probably best off processing the data on the fly rather than storing it all then post-processing it - simply because the Arduino doesn't have much RAM, so storing large strings isn't always an option.


Is it necessary to reduce the size of libraries?

Normally a library supports various kinds of components; because mostly those components share a lot functionality, so it prevents to make very many different libraries.

Note that all functions that you do not call within your program (and are not called from within the library), will NOT end up in your sketch, thus also will not affect your flash memory usage.

If the library is full of if statements to make a difference between models, that code is in (if a function is called, the entire function is stored in flash). (Unless the if statement can be evaluated compile time, see remark of Edgar Bonet below about link time optimization).

So if you want to remove that 'unnecessary' code (for you at least), than copy the library into your project and remove the unnecessary code yourself.

However, I would not do that until you run out of flash memory.

You can do an easy test:

Include a library, and compile your sketch. You will see (possibly) some difference.
Now call a function from the library. Compile the sketch again, you will see the flash memory usage has increased. This means, before that, that function was not part of your compiled sketch.

A thing I would worry more about, is SRAM memory usage, but mostly buffers are created depending on the model, and SRAM is not wasted (since the Arduino Uno has only 2 KB for example).


Would it be feasible to build an arduino that takes 12v on/off signals from a vehicle diagnostic port (1984 pre-OBD)?

Yes, it is possible. The 12v signals would have to be conditioned for the Arduino to receive them (0 - 12v or maybe 0 - 12-14.5v?). Then the Bluetooth side would be the same as any other Bluetooth data transmission.

So your question comes down to: Is this a fun project that's worth the effort you put into it for the learning experience? Or is this meant to answer a need, and the most practical means to that end is the best means?

Ex: I wanted to know how long / what kind of driving would it take to get my car's oil to full temp (~100C), starting from dead-cold in the winter? I had a thermo-logger I'd built for another experiment, so I taped a sensor to my oil filter (yeah, not the greatest, but quick and dirty) and lead a cable outside the hood, through the driver's window, to the experimental PC board on my dash-board. It wasn't a miserable failure but nothing to be proud of, either.

The solution I settled on was a USD$12.00 OBD port sender and an iPhone app. The results were much better, and while I didn't have the built-it-myself experience, I got the data and the answers I needed.


You can't simply concatenate C strings like that. Instead you have to build them up into a new string.  For formatting like that the simplest way is with sprintf:

char outMessage[strlen(outTopic) + strlen(msg) + 3]; // Room for topic, message, [ and ] and terminating \0
sprintf(outMessage, "[%s]%s", outTopic, msg);
client.publish(outTopic, outMessage);

Another method is with strcpy and strcat:

char outMessage[strlen(outTopic) + strlen(msg) + 3]; // Room for topic, message, [ and ] and terminating \0
strcpy(outMessage, "[");
strcat(outMessage, outTopic);
strcat(outMessage, "]");
strcat(outMessage, msg);
client.publish(outTopic, outMessage);

You have to ensure that your "holding" string outMessage is big enough to hold everything you want to send, plus a terminating NULL character, otherwise your program will crash.

Another way of creating the "holding" variable is with alloca(). That allocates bytes on the stack for a variable - just like malloc() does on the heap, but doesn't require free()ing because it's on the stack and is reclaimed when the function exits:

char *outMessage = (char *)alloca(strlen(outTopic) + strlen(msg) + 3);


How can one reset Arduino Nano from NodeMCU?

Yes, you can reset a 5 V Arduino with esp8266. I did it many times. The esp8266 doesn't have a problem with pull-up level current at 5 V.

On my picture io 0 of the esp-12F is wired to reset pin of Nano. The esp-12F runs WiFiLink firmware which can OTA upload sketch to ATmega328p and of course before flashing it must reset the ATmega.


serial communication between arduino to 89c51 with gsm

The Arduino Uno only has one (hardware) serial port. Since you need two, you have in principle two solutions:

Use a software serial, this will work only for low speed transmissions. You can download this as a library.
Use an Arduino (or other microcontroller) which has more than one hardware serial port, like the Arduino Mega which has 4.