Many programmers have a disjoint between a pointer and an array. Here's an explanation.

Here is a variable of type char, initialised with the value 'A':

char c = 'A';

'A' has the ASCII value of 65, so that means that there's a byte in memory that holds the value 65. Let's say that byte in memory is at address 0x2000. If you were to add 1 to that byte, it would become 66, and if you were to print it as a character, it would print B (ASCII 66).

Here is a pointer to a char, initialised with the address in memory of c:

char *p_c = &c; // Get the address of c into p_c

  [Note that char *p_c = c; would be invalid: you can't initialise a pointer with a char! That'd give p_c the value 65 - not what you want!]

In Arduino, p_c represents two successive bytes of memory that together store the address of a char: in this case the value 0x2000. Where those two bytes are doesn't matter for this explanation - but trust that they too have an address...

If you were to change c into a 'Z', that would change c's contents, but not p_c's (it would still be 0x2000). But if you were to use p_c to look at the byte it was pointing to (c), then you'd see the 'Z'.

If you were to do a printf("%c", c); you'd get a 'Z'.

  %c means "I've got a character as the next variable in the printf() list".

If you were to do a printf("%c", *p_c); you'd also get a 'Z'.
If you were to do a printf("%c", p_c); you'd get horrible results.

  You lied to printf() - you didn't give it a one-byte character, you gave it a two-byte pointer!

Now let's move on to arrays.

Here is a variable of type char [], initialised with the value "John".

char s[] = "John";

'J' has the ASCII value 74, 'o' 112, 'h' 104, and 'n' 111. That means that in memory there are four sequential bytes with the values 74, 112, 104, 111. Let's say that those bytes are at addresses 0x3000 through 0x3003.

And here is another pointer to char, this time initialised with the address in memory of s.

char *p_s = s; // Point to s with p_s

  I hate that the C language allows the above. It is one of the roots of the whole array/pointer confusion. It kind-of implies that p_s somehow gets all of "John" assigned to it. Nope!

A better statement would have been:

char *p_s = &s; // Initialise p_s with the address of s // ILLEGAL!

That gives a MUCH better idea of what's happening - alas, it's not how it's done...

But also note that neither of the above could possibly store 0x3000-0x3003 (the addresses for all of s), so they have to be satisfied with only storing the start of the string: p_s will get the value 0x3000.

Note that s does NOT have the value 0x3000 in it. That is its address, like 0x2000 was c's address (it too doesn't have 0x2000 in it). But p_s does have 0x3000 in it - and don’t forget that p_s also has its own address (I won't bother with that here).

And this is where the "equivalency" (they're not) between a pointer and an array starts to get people confused:

s[2] = 'h'; and p_s[2] = 'h'; do the same thing - but in different ways!

The first accesses 0x3002 directly.
The second needs to find out that p_s is 0x3000 and add 2 to it before it can access 0x3002.

*(p_s + 2) = 'h'; is yet a third way to do the same thing.

So now let's printf() these new variables:

printf("%c", *s); wouldn’t compile.

  s is not a pointer, so you can’t dereference it with *.

printf("%c", *p_s); would print the character at where p_s was pointing.

  This would print out J.

printf("%c", s[0]); would print the character at s[0].

  This would print out J.

printf("%c", s); would give horrible results.

  Again, you lied to printf()!

printf("%s", s); would work (but see below).

  %s means "I've got a sequence of characters that I'd like you to print. I've provided the address of the first character."

printf("%s", p_s); would be identical to the previous one.

  After all, the same address value was passed!

printf("%s", *p_s); would give horrible results.

  Again, you lied to printf()!

But note something: you've given printf() the beginning of the string, so it can start printing. How does printf() know where the end of the string is? You didn't provide the number 4; it's not stored anywhere; how can it know when to stop?

That's where a C convention for strings steps in. By convention, when the compiler sees a string "between quotes", it stores the ASCII values of the characters, and then follows them with a 0. Not an ASCII '0' (with value 48), but an ASCII NUL (with value 0). Thus if you looked at address 0x3004 (the byte directly after John), you'd see a 0 in that memory byte. That's how printf() knows to stop printing - and yes, many a bug has resulted from forgetting to maintain a NUL at the end of a sequence of chars!

That then leads me to the sizeof() function

sizeof() always returns a constant at compile time using information that the compiler then knows about:

sizeof(c) would return 1.
sizeof(p_c) would return 2.
sizeof(p_s) would also return 2.

  It is after all merely a pointer too.

sizeof(*p_c) would return 1.
sizeof(*p_s) would also return 1.

  It's only pointing to a single char...

sizeof(s) would return 5.

  The compiler knows what s is: an array of 5 bytes (including the final NUL).

Given a pointer, there is no (native) way to find out how large the buffer it is pointing to can be.

OK: so if you've got a char [] you can find out its size. Note that that is its maximum size - the string inside it could be a lot shorter! If you did the following:

s[3] = 0; // Overwrite the fourth character (arrays start at 0)
printf("%s", s);

  [Note a better version of the first line would be s[3] = '\0'; which means "store the ASCII character 0 (NOT '0')" instead of "store the number 0".]

you'd get Joh printed out. Note:

sizeof(s) remains 5;
You can't get the length with sizeof(*p_s);
The string inside it is only 3 characters long.

So... if you've got a string buffer, or a pointer to one, how do you know how long it is? Count the number of characters until you reach a NUL - and there's already a function to do that for you: strlen().

Which now leads to the final point about pointers: dynamic allocation of memory.

The array s above was sized by the compiler at compile time: it could count the characters, add one for the NUL, and reserve the right number of bytes. You could also have written:

char s[10] = "John";

which would have reserved 10 bytes and only initialised the first 5 of them. The following would be an error:

char s[3] = "John"; // Buffer too small!

  Scarily, char s[4] = "John"; works... (The compiler says to itself "No room for the NUL?! Ah well...”) Better never pass that string to strlen() or printf() then!

What if you don't know at compile time how big a string is going to be? If you know at runtime, you can ask the system for a lump of memory from the heap - a reserved area that can have chunks taken from it and returned as required. There are two ways to do this:

char *p_b = (char *)malloc(size); // Where size is a variable
char *buffer = new char[size];    // Grab 'size' new chars

The first calls malloc(), passing in the number of desired bytes. If malloc() can give those bytes it will reserve them and return a pointer to them. If it can't it will return 0. You should always test the return value! If not, you'll corrupt things horribly...

The second uses the more sophisticated new[] syntax, which is more object oriented. Notice how malloc()'s return value needed to be turned into a (char *)? That's because it doesn't know what type of pointer it's returning, so it just picks void *. new does know, so it returns the correct type - but it still may return 0 if there's no room!

Once you've got either pointer, you use them just like p_s before. There is nothing stopping you from accessing outside the boundaries of the buffer - just like there isn't for p_s! Be careful!

Oh, and once you've finished with the lump of memory, you need to return it to the heap:

free(p_b);
delete [] buffer;

If you used malloc(), return it with free(). If you used new[], return it with delete[].

And all of the above is why they invented the String object.

It manages the memory; keeps track of the string's length; lets you access and modify individual characters; lets you resize the string as needed; and gets rid of the used memory once you're finished with it. No wonder people start to use String syntax when they see string pointers...

But Strings are only useful for chars. Arrays and pointers can be of and to anything - including Strings and (GASP!) pointers! Uh oh - here we go again...


Basically you're sending a command that gives a response, then waiting 2 seconds for that response to arrive (which is completely the wrong thing to do to start with).

You have to ask yourself: where does that response go when it does arrive, while it's waiting for you to finally get around to reading it?

The answer is: into a small internal buffer that is considerably smaller than the response.

Thus most of the response just gets thrown away because there isn't room for it.

Instead you should most definitely NOT delay for 2 seconds waiting for the response, and instead keep looking to see if there are any characters to read up until you reach the end of the line.

It's all explained here: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/


There is no 5 or 10 second sleep. You can't just arbitrarily choose how long to sleep for. The watchdog timer only has specific periods (defined by dividing the clock by a set amount) that it can sleep for:

enum period_t
{
    SLEEP_15MS,
    SLEEP_30MS,
    SLEEP_60MS,
    SLEEP_120MS,
    SLEEP_250MS,
    SLEEP_500MS,
    SLEEP_1S,
    SLEEP_2S,
    SLEEP_4S,
    SLEEP_8S,
    SLEEP_FOREVER
};

To sleep for 5 seconds you would need to sleep first for 4 seconds, then wake up, and then sleep for a further 1 second after that. For 10 seconds sleep for 8 seconds followed by 2 seconds.

Note that they aren't exact values, however, since the watchdog oscillator is very crude and varies wildly in frequency with both temperature and power supply voltage.


How to send IR data from Arduino to USB-TTL

You are transmitting data by encoding it using one of probably many Sony Consumer Remote Control formats and expecting to decode it using one of many possible RS232 like formats.  You will likely get something between nothing and random values.

Instead, consider sending data using only the RS232 protocols.  This is what is done in this tutorial.  It is recommended you replicate the tutorial before moving on to using a TTL to USB dongle and a computer.  This should validate the transmitter is working.  Note in the tutorial transmitter code example no IR  remote control library is used.  Only the common serial libraries.

A word regarding the tutorial.  Consider using the second of the two examples in the tutorial.  The first does not modulate the IR transmitter and will not work with commonly available IR receivers.  The second does modulate the IR transmitter and discusses how to alter the modulation to accommodate different IR receivers.


I found a better picture that shows the jumper from above. I can see now that there is a jumper to toggle between 5V and 3.3V

http://buyhere22.com/components/usb-ttl-ft232rl-pinout.png


Sending value from Arduino to MySQL using ESP8266

You're sending commands blindly without checking if they actually succeeded. If you're not ready to correctly handle the responses, you're better off using a library like this. The 'HTTP GET' example should help.


Are you sure your laptop doesn't detect any device? It is possible that you need to install right driver for your arduino. The problem could be with:

Cable: Try to replace it with a working cable
Drivers Issue: You need to install driver for your Arduino. Generally, your laptop will issue warnings if it didn't find any appropriate driver for it.
USB-To-UART Bridge: This is an IC in arduino board. It needs to be working for laptop to detect your board.
Microcontroller: Since, you told us that your board is blinking, then microcontroller will be working for sure.

Can you see any part getting hotter? Have you tried with other laptop and cable?


Just program it like you would program a normal ESP8266.

The documentation is here:

https://github.com/SmartArduino/SZDOITWiKi/wiki/ESP8266---TTLtoWiFi

The datasheet provides the schematic of the module

So SW2 is the reset button and "SW1" is the "FLASH" button. To enter the bootloader mode in which the ESP8266 can be programmed, you first have to hold down the "FLASH" button then press "RESET" once.

For programming you would ideally get a 5V USB-UART adapter make the connections

VCC to 5V (it has a regulator to generate the actually needed 3.3V)
GND to GND
EN to 5V (e.g. via a pullup)
TXD to RX of UART adapter
RXD to TX of UART adapter

After the ESP is in the bootloader mode as described above, you can just program it normally through the Arduino IDE. Follow the instructions at https://github.com/esp8266/Arduino to install the ESP8266-Arduino core in the board manager.

Refer to the similiar procedure:

https://www.hackster.io/harshmangukiya/program-esp8266-esp-12e-with-arduino-using-ftdi-cable-2310c9


How to detect Arduino serial port programmatically on different platforms?

Here is a solution:

On Windows, Arduino IDE comes with a tool named listComPorts.exe, which will list all COM ports and their USB info like VID & PID. There is also a file named arduino.inf in drivers folder contains all known device types and their VID&PID etc, and we can look for the connected device.

On *nix, the IDE take advantage of libusb and no such a tool, and it's easy to find a tool to list usb info on these platforms.

This go package mentioned in the question is a good choice, which also uses libusb and could build on all platforms. (On windows, you have to install mingw to build the C code, cygwin & msys don't work, I tried TDM-GCC and it works. You also have to add LDFLAGS: -lsetupapi (in serial.go) to successfully link the code.) After list all serial ports, you can search for 'Arduino' to determine the port. 'CH340' is also a keyword to search as many modified boards use this chipset.

New version of the IDE don't have listComPorts.exe, they all uses libusb. I find this tool from version 1.6.5.


Arduino PWM output cannot drive MOSFET 0-12V

Assuming you have a suitable FET You should have a circuit in line the following.
http://elinux.org/RPi_GPIO_Interface_Circuits#Using_a_FET

You should have some kind of load (a multimeter will have too high an impedance). Use a resistor 4.7k or smaller. You should also have a resistor on the gate


Can not print an element in an specific position in an arduino list

How about you completely delete

int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

and instead do:

if (attempt != FINGERPRINT_OK)
    return -1;

Serial.println ("Belongs to: ");
Serial.print(users[data.fingerID - 1]);


Is there an Arduino Simulator or Emulator that runs on OS X?

I am using the Wokwi Arduino simulator for a long time. It runs on all three platforms. Mobile, Windows OS, and macOS.
I have checked the working of the simulator in both Android and iPhone. Both give a good performance as well.


Controlling 4 motors using the Arduino Uno

Can I control the 4 motors using 2 H-bridges (L293D)?

Yes. Two per chip.

  Are ESC's necessary if I use the PWM pins?

There is one thing you must understand first: there are two kinds of DC motor - Brushed and Brushless.

The Brushed motor is the "normal" kind - you apply power to it and it spins.  These you control with the likes of an L293D and use PWM to control the speed.

Brushless motors are the kind you have in hard drives and the like. They consist of a number of coils that get turned on and off at the right time to pull a magnet around in a circle (to put it crudely). These require special timing and control to get the coils energised at the right time and in the right way. This is what an ESC is for.

Brushless motors are smaller and lighter for the same power than brushed ones. They also have a longer life. Because of this they are generally preferred to brushed motors on quadcopters.

Brushed motors have a very high starting torque, don't require complex control logic and use less energy when not running full speed.

If you use brushless motors, which ideally you should (though I can't tell what kind of motors those are in that kit) then you must either use an ESC or build your own ESC using an Arduino and multiple motor driver circuits. Simplest to use an ESC.

If you don't use brushless motors then an ESC is not what you want to use - just the L293D chips and PWM.


With the press of a button, I need to play an intro sound file, then one of 50 other sounds in order, each time a button is pressed

You will find all the code and thelibrary you need on the Adafruit learn center.
For such a project I would use a DF-robot (clone) MP3 player (~4$), an Uno, a speaker and an SD card. The library for the player includes examples to get you started and the sound project you plan is possible even with low programming skills. Look at the example codes provided and start to program.


There are multiple versions and "clones" of the Arduino, and each one will probably use different components. The time you refer, in this case "millis()" I believe, is maintained from a timer interrupt, which is derived from the main clock (normally 16Mhz).

The main clock on your board might be generated by a ceramic resonator, which is not very accurate: around 0.5%-1% error. It also might be from good quartz crystal, with up to 0.001% accuracy. Those variations on the frequency source will produce some drift over time... Like your watch needs to be readjusted from time to time.

Another factor that affects accuracy, including for RTCs using a 32.768KHz crystal, is the temperature. Here an Application Note on this: http://www.st.com/content/ccc/resource/technical/document/application_note/55/e2/3d/2a/87/ab/4d/e1/CD00232494.pdf/files/CD00232494.pdf/jcr:content/translations/en.CD00232494.pdf

Your application might not require too much precision, and you could simply write a sketch to print the time every second on the serial... let it run from one hour, one day, and check how much drift you're getting. After that will be easy to estimate how much drift you'll have a after a month.


How to know the external interrupt origin from the ISR

Is there any memory record which store the external interrupt
  activation?

There is, but I do not think it will be easy to exploit.

At low level, each interrupt is handled by a different ISR. So you will
have INT0_vect handling external interrupt 0 and INT1_vect
handling interrupt 1. These ISRs are all defined by the Arduino
core library. In your case, they will both call the same handler that
you defined. Thus, the information about which ISR fired is now on the
stack: it is the return address of your function.

The reason this information will not be easy to use is that you do not
know how far it is from the stack pointer. It depends on how much stuff
your own handler pushed onto the stack. You could disassemble it and
count, but then your code will be fragile, as the smallest change in the
handler (or compiler version) may change this count.

An easier approach may be to define your own INT0_vect and
INT1_vect, overriding those from the Arduino core. These new ISRs
will both call your handler, but they will pass it an argument to tell
which interrupt fired.

Or you can register a different handler for each interrupt, each calling
a common function. But this adds an extra level of function calls.


Arduino Uno power input - is 5 V at 1 A enough?

I dont see why not - YES you can!

I regularly use usb powerbanks to power projects for testing. so long as you dont ask for too much current (unlikely but project specific) you will be fine!


DigitalWrite Cannot Power HC-06 Bluetooth

A digital IO pin is only capable of powering an LED or an incredibly low powered device. It is not suitable for powering meaty RF modules.

Instead you need to control the power to your module using a P-channel MOSFET as a High-Side switch.

For instance, assuming a 5V module with built in 3.3V LDO:

simulate this circuit – Schematic created using CircuitLab

Note that /RFEN is active low - set the pin OUTPUT and LOW to turn the module on. M1 should have a threshold of no lower than -4V, better -2V or higher.

Also be sure to set RX and TX to be INPUT when you power down the module or back-powering through the TX/RX pins may occur.

R2/R3 is a simple logic level shifter for the 3.3V logic signal the RX pin expects.


You can't. The factory firmware of Uno Wifi is discontinued.

Uno WiFi and WiFi Link doc


Why do only specific arduinos support the keyboard and mouse libraries?

Those chips have hardware support built into them to handle the rather strict timing requirements for interpreting (and responding to) USB sequences. You will notice, for example, that on the Arduino Uno there is a second chip (the Atmega16U2) which also can handle USB. In fact the chips with a "U" in the name generally can do this.

  I have Nanos, Unos and Duemilanoves. I am out of luck aren't I?

You have a couple of options. Some people reflash the USB chip on their Uno (for example), although personally I think that is a bit fiddly.

Alternatively, there is a library called VUSB (virtual USB) which lets you do some USB on the non USB chips. Google vusb arduino.

You need three resistors and two zener diodes to make up the hardware that lets this library do its stuff.


You are on a tough road. I hope someone can give you specifics.  Normally you would able to identify the capacitor from its parts designation, but that board does not have any. So you will have to match the schematic (assuming spark fun provides one) to the board layout to figure out what it is.  The cost of the part is probably over a penny, maybe even 2 cents. In other words, not an issue.

It will require hot air to desolder one from another board and to solder this one on. Someone might be able to do it with a fine tip solder  pencil, but not likely.

Bottom line; find someone who has experience repairing boards, or order another one. Amazon has breakout boards for the 6050 for $6. But I see this one has Serial, and a magnetometer, so it is not quite the same. But depending on what you plan to do with it, it could work.


Arduino Uno R3 not working after shorting 5V to GND

Have you tried restarting the computer? The computer will shut down the USB port to protect it from a malfunction like this (over-current).

You can also try the ports on the other side of the computer (or front/back) as they're usually on different controllers.


Can a video game potentially detect arduino leonardo?

Yes.

First you'll need to define how you plan to inject the new input signal, into the data "packets" as a spoof of controller signals, or just jumping the switches?

In the context of any modern gaming console, it could be detected. Easily. Consoles and controllers use any number of proprietary protocols which sync.commands to improve response and reduce controller lag. If you're just jumping the switches, then no, you could simulate hadouken and probably get away with it just fine.

If you're referencing PC gaming, then that would be hard if not impossible with the variance of input control available.  The best deterrent would be the security of the game software itself and the genre of the gaming. Some games actively encourage Hotkeys.


Arduino tool to enumerate where RAM is being used?

I use this code for Heap memory of AVR (UNO, Mega, etc.):

int freeRam()
{
     extern int __heap_start, *__brkval;
     int v;
     return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int)__brkval);
}

To show heap memory just use Serial.print("Write here a name of the function from which you print it"); Serial.println(freeRam()); anywhere in the code.

Compiler shows stack memory but not the heap, so this code helps me to find exact place where my program uses too much of heap memory. I just print it in every suspicious place in my code.

I hope this will help.


Programming Servo How To Get -90 Degrees

Normal servos only have a range of 180°. You can give yourself an "offset", so you have -90° to 90°, but you only ever get 180° range. You can't go -90° to 180°.

Using mechanics (outside the scope of this site) you can multiply your movement (think gears) so that your range is bigger.


The Arduino IDE has a compiler, and will in the end compile the library with whatever .ino script you'll write. But you don't need any compiler to write a library. All you need is a text editor, and produce .cpp and .h files.

However when you test the library, you'll have to use the Arduino IDE to compile it.


Customize FTDI driver for custom PID and VID

On Windows

You can refer to FTDI's documentation here for details on how to create your own custom device driver. The FTDI website has a lot of resources for this, however they seem to be a little outdated. Microsoft details how drivers work in it's Hardware Dev Center.

On Linux

On Linux it may be as easy as registering the device with modprobe. For example, for a device with a VID of 0102 and a PID of 1234, execute the following from the shell:

modprobe ftdi_sio
echo "0102 1234" | sudo tee /sys/module/ftdi_sio/drivers/usb-serial\:ftdi_sio/new_id > /dev/null


Using MULTIPLE shields on Arduino Uno R3

You will have to consult a source like this one: http://shieldlist.org
There are no simple rules for which pin conflicts are OK and which ones are not, it all depends on the concrete protocol (i.e. I2C is designed for all bus participants to share lines, while in SPI, each participant needs their own select line, while the other lines are shared).

In your concrete case, both shields you want to use are addressed by SPI, which means D13 (SCK) and D12 (MISO) are shared between the shields by design, while they MUST have different slave select pins. In your case, the SS pin for the microSD shield is fixed as D8, while the one for the KTA shield seems to be selectable, so either D9 or D10 should be OK.

Peripherals generally don't have facilities to become an SPI master, so all data has to be transferred through the Arduino.


How can I use stepper for specific degree?

stepper.step(num)is used to rotate your motor 'num'-step. i.e. num=25, then calling stepper.step will cause your motor do 25-step.

STEPS is number of steps per revolution for your motor. It will be depending on the motor you used. For more information, you can check here.

You have to check for your motor stepper resolution. Most common motor stepper has 200 steps per revolution, which means 1 step is 360/200 = 1.8 degree. If you try Stepper.step(1), your motor will rotate 1.8 degree.

So in your case, if you already found out the resolution of your motor stepper, just do a simple conversion task:

const float resolution  = xx.xx; // put your step resolution here
int step_degree(float desired_degree){
    return (desired_degree/resolution);}

This can be use by calling

stepper.step(step_degree(40)); //rotate 40 degree.

--EDIT--
You can check this link, since it (perhaps) using same motor stepper (24BYJ48)

Based on 24BYJ48 datasheet, it has 5.625 degree resolution / 64 steps per revolution.


HTTPClient http;
http.begin("http://google.com?on=false");
http.addHeader("Content-Type", "application/json");
int httpCode = http.sendRequest("PUT", "");
String payload = http.getString();

try with this code, if server .php,
get data by $_REQUEST


Arduino : distance measurement between fixed points

Seems to me you are looking for some kinda of SLAM thing. Depending on your knowledge in control theory and your precision goals you can go from simple rotary encoders on wheels to multiple sensor fusion like Extended Kalman filters (example videos). Probably the most precise thing you can have is sensor fusion with LIDAR (can be achieved precisions like 1cm), however the price range is way to far from described.

I would start with a small approach and go from there depending on the results I'd get:

rotary encoders (easy to calibrate and can be precise enough as a starting point)
9DOF IMU (use a Extended Kalman filter or similar to make an AHRS correction). And in this part I have many advices. You have suggested MPU-9150. I'm not familiar with it but looking at datasheet it seems very good, specially because gyro comes factory calibrated. In past I've used razor IMU / GY-85 (adlx345 + ITG3200 + HMC5883L) and gyro was very precise and low noise. Hope Invesense used the same sensor in MPU . First in hardware: Acc are easy to calibrate just use gravity. Gyros are easy to calibrate but hard to do. Why, because it may be hard to get something that spins at constant RPM and know that value. But as I've said, according to datasheet, MPU comes factory calibrated. Magnetometers calibration can be a bit tricky. Bottom line is you get readings from various points of your robot  in 3D space. you plot all and you will get an ellipsoid. Then you find a transformation equation that maps the ellipsoid into a perfect sphere take a look this article. Your concerns about Angle random walk can be minimized with kalman filter and similar. This page provides much great information and examples in how to make a good AHRS. Mr. Madgwick wrote a really nice algorithm that implements the IMU  filter and have it also written in C (nice for Arduino).

After integrate all things with Kalman and see the results, if things are not good enough, you can add more sensor and provide a better estimation for example: sonars, rangefinders, landmarks with image processing and as suggested also, RSSI and triangulation.

These links might help you in finding your way:

Introduction to Kalman Filters and SLAM
Indoor Location Tracking using Received Signal Strength Indicator


Where can I find a better pinout diagram for "Arduino Ethernet" board?

The formal Arduino.cc website mentions, somewhat obscurely, that the Arduino Ethernet is pin compatible with Arduino Uno:

  The Revision 3 of the board introduces the standardized 1.0 pinout

Except for pins 10-13:

  Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet
  module and should not be used otherwise. This reduces the number of
  available pins to 9, with 4 available as PWM outputs.

The other difference is the onboard LED is connected to pin 9 rather than the Uno's pin 13:

  On most other arduino boards, this LED is found on pin 13. It is on pin 9 on the Ethernet board because pin 13 is used as part of the SPI connection.

You can use any Arduino Uno pinout diagram as a reference, the one you have found seems to be pretty elaborated.


How to re-solder the resistor in order to reprogram the Atmega8U2

Looks like you ripped a pad off. To prevent that in the future, try using more flux and dropping the temp (Max around 320*C/610*F). The iron shouldn't be in contact with the board for more than about 3 seconds. No force should be necessary to remove components.

Not to worry though. Common beginner's mistake and not too hard to fix.

To prep this for repair:

Gently clean the area up with 91% isopropyl alcohol and cotton swabs.
Carefully scrape away the solder mask (blue paint) on what's left of the copper trace all the way back to the via (little hole). Try to remove all the solder mask from the via. Straighten and flatten the pulled up trace.
Clean, flux, and tin (apply as thin layer of solder) to the trace and remaining pad. Filling in the via is OK as it will give better surface area to attach the repair.
Flux and solder the resistor to the remaining pad to keep it in place and properly aligned for the repair.

To repair the damage:

We need to bridge the gap created by the damaged pad. A globby solder bridge may work, but wire is much better.
Find a piece of thin gauge solid core wire (30-22AWG. Some 24AWG from an ethernet cable would do fine).
Orient the wire so that it's directly over the remaining trace and also making contact with that end of the resistor.
You can trim it to size now or after soldering. It may be easier to keep in place if you trim it after soldering as long as you have some fine flush cut pliers. Either way, leave enough that it covers the entire cleaned and tinned portion of the trace.
Flux and solder the wire to both the resistor and trace. This will complete the circuit.
Clean again with alcohol. Let dry. Test the board.

Give this Adafruit article a read. I've got extensive professional soldering training and endorse it fully as the best beginners soldering guide I've found.


Yes you are going in the right direction.

Comparators
You haven't as yet detailed how you plan to connect the 2 comparators to the Arduino, but I imagine it would be something similar to this:

simulate this circuit – Schematic created using CircuitLab

In the circuit above, X and Y are either high or low based on the analog voltages of A, B, C & D. I have created a truth table below with some arbitrary voltages to output. The value column corresponds to the value needed for the analogWrite() function.

Note: If you need your analog output to be able to source some current you can add an Op-Amp in a unity gain configuration at the output of the RC filter.

Examples To Read
To output the analog value, the 4 best suited inbuilt examples/tutorials to look at are:

Dimmer: Send serial values to change the brightness of an LED.
Fading: Use an analog output (PWM pin) to fade an LED.
Analog In Out Serial: Read an analog input pin, map the result, and then use that data to dim or brighten an LED.
Read ASCII String: Parse a comma-separated string of integers to fade an LED.

What all of these examples have in common is the analogWrite() function:

// writes the analog value (range from 0 to 255):
analogWrite(pin, value);

Dimmer is a simple example where a serial value is read and then output on one of the PWM pins.
Fading is probably the most basic example of using the analogWrite() function (PWM output).
I included Analog In Out Serial as it uses the map() command.
I included Read ASCII String as it shows how to parse multiple values on the serial string.

PWM Pins
You can use pins 3, 5, 6, 9, 10, 11, and 13 on the Arduino Leonardo to output the PWM using the analogWrite() function.

Control
I recommend the following tutorials for your control. You could either use the if-else command or the switch-case command.


Combining code for two sensors in one programming

This example combines both codes but uses a single delay. If you want readings at two different times you should use two unsigned long global variables to store the millis() of the last time the functions were called. Then you use an if statement to only call readTH02() or readDHT11() when the last millis is less than the <= current-interval.

It is better to use millis interval checking instead of delays but I have not made significant changes to your code to implement that. Take a look at the Arduino IDE example called BlinkWithoutDelay to understand how to use intervals instead of delay()

void setup()
{
  setupTH02();
  setupDHT11();
}

void loop()
{
  readTH02();
  readDHT11();

  delay(1000);
}

void setupTH02()
{
Serial.begin(9600);        // start serial for output

Serial.println("****TH02_dev demo by seeed studio****\n");
/* Power up,delay 150ms,until voltage is stable */
delay(150);
/* Reset HP20x_dev */
TH02.begin();
delay(100);

/* Determine TH02_dev is available or not */
Serial.println("TH02_dev is available.\n");
}

void readTH02()
{
float temper = TH02.ReadTemperature();
Serial.println("Temperature: ");
Serial.print(temper);
Serial.println("C\r\n");

float humidity = TH02.ReadHumidity();
Serial.println("Humidity: ");
Serial.print(humidity);
Serial.println("%\r\n");
//delay(1000);
}

byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++){

    while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
    delayMicroseconds(30);

    if(PINC & _BV(DHT11_PIN))
    result |=(1<<(7-i));
    while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
}
return result;
}

void setupDHT11()
{
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);

Serial.begin(9600);
Serial.println("Ready");
}

void readDHT11()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);

DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);

dht11_in = PINC & _BV(DHT11_PIN);

if(dht11_in){
    Serial.println("dht11 start condition 1 not met");
    return;
}
delayMicroseconds(80);

dht11_in = PINC & _BV(DHT11_PIN);

if(!dht11_in){
    Serial.println("dht11 start condition 2 not met");
    return;
}
delayMicroseconds(80);
// now ready for data reception
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();

DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);

byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
    Serial.println("DHT11 checksum error");
}

Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("%  ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C  ");

//delay(2000);
}


after writing a value to EEPROM, and terminating the I2C connection with a STOP, the EEPROM enters a self writing mode to write what you have sent to it, to it's internal memory. (you don't actually write the values to the memory section; you write them to a buffer, and then the internal controller writes them to its memory section).

this "self writing mode" takes about 5ms, and you cant do nothing about it. but you can use "page writing" instead of byte writing. that 32K model, has a 32 bytes page buffer. you have to send all the bytes (as long as they are under 32 bytes) at once in one I2C transaction. this time, the chip fills its page buffer and then after a STOP, writes it all at once on its memory. in your code, you just write one byte in your buffer each time in a single transaction. like sending a bus with just one passenger at a time.

remember in this mode, you only set the address of the first byte. the next bytes automatically settle in the next addresses.


Each time the watchdog interrupt triggers, WDIE is reset. You will need to set it again in the loop if you want to continue capturing the interrupt rather than resetting the system.

Also, consider using <avr/wdt.h> and <avr/sleep.h> to handle (most of) the watchdog and sleep functionality.

EMPTY_INTERRUPT(WDT_vect);

void main ()
{
    watchdog_init();
    set_sleep_mode(SLEEP_MODE_STANDBY);
    //and initialize all the other hardware and power supply

    while (true) //no need to step out of this loop
    {
        wdt_reset()

        //
        //main program
        //

        if(go_to_sleep=1)  //command received through serial
        {
            sleep_enable();
            sleep_cpu();
            sleep_disable();
            WDTCSR |= _BV(WDIE);
        }
    }
}


Arduino IDE menu doesn't display properly (missing letters)

I've never had this problem, but here are some things you might want to look at.

Did you install it from an administrator account and use "run as administrator"?  If not, uninstall and reinstall.
Its possible that you are missing a font, god knows which one.  Go and look at the Arduino source on GitHub(?) and find any TTF files and install them.
Does this version support Windows 7?
What version did you have previously? Did you uninstall it before installing this?
If you didn't have a version before this one, uninstall this version go and get 1.5 or 1.6 and install that, then install 1.7 over the top.

Good luck, and keep monitoring the Arduino.org forums because if it is a problem with the app then they will start screaming quite quickly.


How do I change the Console colour of Arduino IDE?

It turns out that the theme.txt configuration file is not located alongside the preferences.txt file, but alongside/under the Arduino application's .jar files. Thus, for the current version (1.6.3):

on OS X, .../Arduino-1.6.3.app/Contents/Java/lib/theme/theme.txt
on Win7, C:\Program Files\Arduino\lib\theme\theme.txt
on Linux, .../arduino-1.6.3/lib/theme/theme.txt
on Windows 10, when installed as an App, C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\lib\theme\theme.txt, however it does not seem possible to edit it - it can be opened in notepad++ but a save fails.

See an associated Github issue, IDE Background and print color options needed, for a little more discussion.


How to connect MPU9250 with NodeMCU using SPI or I2C Slave?

If you want to use SPI-
The homepage of the library you mentioned, clearly explains the circuit connections.-
The MPU-9250 pins should be connected as:

VDD: this should be a 2.4V to 3.6V power source.
GND: ground.
VDDI: digital I/O supply voltage. This should be between 1.71V and
VDD.
FSYNC: not used, should be grounded.
INT: (optional) used for the interrupt output setup in
enableDataReadyInterrupt and enableWakeOnMotion. Connect to
interruptable pin on microcontroller.
SDA / SDI: connect to MOSI.
SCL / SCLK: connect to SCK.
AD0 / SDO: connect to MISO.
nCS: connect to chip select pin. Pin 10 was used in the code snippets
in this document  and the included examples, but any digital I/O pin
can be used.
AUXDA: not used.
AUXCL: not used.

Each sensor's nCS (chip select pin) needs to be connected to a slave select pin (any digital pin) on the NodeMCU. This allows the NodeMCU toselect which sensor it wants to talk to.
Another easy way of connecting multiple sensors with the same I2C address is by using an I2C multiplexer like the Adafruit TCA9548A

This would allow you to connect up to 8 sensors having the same I2C address. Here's a youtube video explaining how to do so.
However, if you just want connect two MPU9250s, you dont need to do any of this, as the board offers two unique addresses via the AD0 pin-

0x68 if AD0 is grounded
0x69 if AD0 is pulled high


Serial Communication Between Two arduinos (Asking and Receiving)

it is not really easy to follow your code but here is a "hello world" procedure to do an on demand data send between two arduinos:

upload this code to arduino uno before you make any connection on pins 0 and 1 of the board:

/**
 * Code for server side (arduino uno)
 */

uint8_t data2send = 'A'; //data to send on a received request
uint8_t incomingByte;

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

void loop() {
        // send data only when you receive data:
        if (Serial.available() > 0) {

                // read the incoming byte:
                incomingByte = Serial.read();

                if(incomingByte=='Q'){  //if incoming data is the expected request (request code = 'Q' in this example)
                        Serial.write(data2send);
                }
        }
}

connect:

UNO  | MEGA
------------
pin0 | pin18
pin1 | pin19
GND  | GND

upload to arduino mega this code:

 /**
 *  code for arduino mega.
 *
 *  proxy between Serial0 and Serial1
 *
 *  send data to Serial0 to forward it to Serial1.
 *  when data is received from Serial1 it will be forwarded to Serial0.
 */

void setup() {
        // initialize both serial ports:
        Serial.begin(9600);
        Serial1.begin(9600);
}

void loop() {
        // read from port 1, send to port 0:
        if (Serial1.available()) {
                int inByte = Serial1.read();
                Serial.write(inByte);
        }

        // read from port 0, send to port 1:
        if (Serial.available()) {
                int inByte = Serial.read();
                Serial1.write(inByte);
        }
}

open the mega's serial monitor and send some characters. Check that you receive back data only when you send a 'Q' character.


need to compare if a byte is less than 80 hex

The rules of integer arithmetics are tricky in C++. There are rules that
give the type of integer literals:

256 and 200 are of type int, which is the default type for
integer literals. On the Nano, this type is 16-bits, and covers the
range from −32,768 to +32,767.
65536 being too large for the int type, it is implicitly
considered a long int. This type is 32-bits on the Nano, and covers
roughly ±2.15×109.

Then there are rules for the types used in arithmetic operations. No
computation is ever done on a type smaller than int: anything smaller
is promoted to int. Then, if you combine two operands of different
types, the larger type “wins” and the compiler implicitly converts the
other operand to the larger type. Note that if two types have the same
bit size, the unsigned one is considered “larger”.

Let's go now through your formula, and see the types of the different
terms:

data[3]       = uint8_t
data[4]*256   = uint8_t * int → int
data[5]*65536 = uint8_t * (long int) → long int

Now you may see the problem. Your calculation will eventually overflow,
but the overflow is not in data[5]*65536, as one may naively expect.
What happens is than when the temperature reaches 163.84 °C (≈ 327 °F),
data[4] becomes 128, and data[4]*256 is 32,768, just too large for
an int. The result overflows to −128, hence the negative values you
see.

The simplest solution is to force 256 to be a long int, by appending
the L suffix to the number. Then the multiplication will be performed
with the long int type, and there will be no overflow:

TA = (data[3] + data[4]*256L + data[5]*65536) / 200;

On a final note, it is worth noting that the numbers 256, 65536 and
16777216 used in the formula are all powers of two. Even powers of 256.
You may notice that, save for the division by 200, what this formula
describes is the coding of an integer as a 24-bit, little-endian, two's
complement number. This format (two's complement little-endian) is
exactly what the Arduino uses internally for representing numbers. You
could then avoid all those calculations and get your result by just
telling the compiler that what those memory cells are actually holding
is a 24-bit integer:

float TA = *(__int24*)&data[3] / 200.0;

This works for both positive and negative temperatures, but it has the
drawback of breaking some C++ rules (aliasing rules), and using the
non-standard type __int24. A safest way to achieve the same is to
build a 32-bit integer by putting the bits in place using bitwise
operations. But note that then a sign-extension byte is needed to
convert the 24-bit number to 32 bits:

uint8_t sign_extension = data[5] & 0x80 ? 0xff : 0x00;
int32_t reading = (uint32_t) data[3] <<  0
                | (uint32_t) data[4] <<  8
                | (uint32_t) data[5] << 16
                | (uint32_t) sign_extension << 24;
float TA = reading / 200.0;


You did not say which library you are using, but based on the #includes, I am assuming http://maniacbug.github.io/RF24

This line in your receiver code:

  while (!radio.available(true));

does not make sense. You are passing true to the radio.available() function, but the function does not care about a parameter.

You probably mean something like:

while (!radio.available());

When you pass in a variable, you are calling a variant of the function that expects a pipe number to be given, and true is defined as 1. Your transmitter, however, is not sending on pipe number 1.


Arduino Uno R3 Bluetooth Shield is not discovering in any of the device

As per this site: http://www.rjanick.com/2012/11/26/seeed-studio-bluetooth-shield/

Try switching the #define rxd and #define txd pin numbers in the code, inversely corresponding to the ones that the jumpers are connected to on the board.

For instance: my pins are jumped from the BT_TX line to digital 6 (and BT_RX to pin 7), so in the code I write #define TxD 7, and RxD 6. This made the board's LEDs blink differently (red blinks on D2 until connection).


How to program and arduino UNO via NodeMCU ESP8266?

The UNO's USB connection is little more than a USB to UART converter.  The NodeMCU's USB connection is also little more than a USB to UART converter.
With a little jiggery pokery (yes, that's a technical term) you can replace one with the other.
By keeping the NodeMCU in RESET mode (tie the EN pin low, or hold the RESET button) you can use the TX and RX pins as the output to the onboard USB to UART converter to connect to the TX and RX pins of the Arduino.
The tricky part is getting the Arduino to reset at the right time: you have to press the Arduino's RESET button at just the right time. Normally this is done by a small capacitor between the DTR signal of the USB to UART converter and the RESET pin, but you don't have access to the DTR signal, so you will have to do it manually. Timing here is everything. Press upload, and just as AVRDude starts to execute you press RESET. Having verbose compilation turned on in the IDE can help.
It may take a few attempts to get it right.


The best thing you can do is to simply add a DC offset to your signal.  Instead of having it be 0V ±80mV, have it 1.65V ±80mv.  All you need is a capacitor and two resistors:

simulate this circuit – Schematic created using CircuitLab

However, 80mV is not going to have much resolution unless you reduce your reference voltage considerably, and in that case you'd need to reduce the 3.3 down to the same (or around) the reference voltage you use.

But, just feeding your signal directly into the ADC will give you the positive 80mV signal which you can use a smaller reference voltage with directly with no problem - after all, the datasheet shows:

  Voltage on Input Pins
  with Respect to Ground (except VBUS)...............-0.3V to +4.0V

So you can provide down to -300mV on an analog input before it potentially becomes a problem.

This is because all the IO pins have ESD protection diodes, which look like this:

simulate this circuit

Those diodes have a forward voltage of about 300mV, and so anything below -300mV will cause the lower diode to start conducting. When that happens too much current can flow and the diode risks burning out.  But you can add further protection by simply adding a small resistor (1kΩ is good) in series with the IO pin to limit the current in the case that the voltage goes below -300mV and protect the internal circuitry.


I think http://stackoverflow.com is the correct forum for your question. Your problem is how to serialize/deserialize correctly an object in C++.

An easy way to do it is simply send the values (not the object) and recreate the object at the other side. So, now your problem is reduced to send and receive a bunch of int's, float's, string's, whatever.

Why you want/need to do that?


Will a simple RC filter work with my mechanical rotary encoder, or do I need a Schmitt trigger?

Having just chased a problem using a software based debounce for several days, what I'll add is that for the encoders I was using (green no-name Chinese ones), if you put 10mA though the contacts then the signal is a LOT better.   So change the 10k to 470 Ohms.

Or if using 3.3V use 330 Ohms.  Solved all my problems.


Does the Arduino pro-micro 3.3v use an 8MHz crystal or a 16MHz crystal with a clock divisor of 2?

On the schematic of the Sparkfun Pro Micro 3.3V/8 Mhz (here) a resonator of 16 MHz is drawn. But also is stated there: "Board is marked with combination of resonator frequency and regulator voltage". From this you can deduct that the 3.3V/8MHz and the 5V/16MHz versions don't have the same resonator and that the 3.3V/8MHz version most probably has a 8MHz resonator.


Better than that: Zero wires.

The Arduino has EEPROM built in.


You can't do anything else with the RF calibration then to clean the flash area where it is stored. There are two reason for doing it:
First is reason to delete the RF calibration area is, if it was written by different version of Espressif SDK, including changing between AT firmware and Arduino. Then it is almost always wrong. I think they changed the data structure so some values are swapped.
Second reason is if the SDK did the calibration in wrong conditions like without antenna.
There is not much information about RF calibration. The FAQ has "Please erase the RF parameters to trigger overall calibration."
The AT firmware reference has (addresses for 4MB-C1):

blank.bin 0x3FB000 Initializes RF_CAL parameter area.
esp_init_data_default.bin 0x3FC000 Stores default RF parameter values, has to be downloaded into flash at least once. If the RF_CAL parameter area is initialized, this bin has to be downloaded too

The esp8266 Arduino core writes the data of esp_init_data_default.bin as part of the sketch's binary.
EDIT: the SDK does the 'digital calibration' at boot. it takes some microseconds. it is not done at every boot, but after some count of resets. this can be configured in the init section


Teensy 4.1 serial communication with 7N2 (7 databits no parity 2 stopbits)

There is no difference between 7N2 and 8N1. You just have the most significant bit of your data value being the first of the two stop bits.
To transmit just set the most significant bit to 1.
To receive just ignore the most significant bit.
For example:
Serial.write(val | 0x80);

And:
uint8_t val = Serial.read() & 0x7F;


Does ATMega 328/2560 chips support JTAG-type programmer and hardware debugger?

The ATmegaXX8 does not support JTAG, but the ATmegaXX0, 'XX1, and 'XX4 do. The 'XX8 (as well as other AVR families) supports debugWIRE, which allows debugging over ISP. You will need one of Atmel's debuggers such as the AVR ONE! or the Atmel-ICE as well as Atmel Studio in order to use it.


Sets of Ultrasonic frequencies using arduino uno

There are three parts to this project, one of which you asked:

I need to generate a frequency greater than 40 khz using arduino uno?

This one is easy: Yes. You can use the tone() library call. You can specify a frequency up to 8mhz. You can call this in the void setup{} part of your code, and (if you don't want to do anything else), leave the void loop() {} empty. You might want to generate an audible tone for a short period first, to show that it is working.

You need something to actually make the sound.

Depending on the frequency, most speakers won't do the trick, or will do it at a very low volume. Speakers are made to work with audible frequencies. Even then, some speakers (larger ones) are better at low frequencies; others (smaller ones) are better at higher audible frequencies. I think piezoelectric buzzers would give you a better response at higher frequencies. In any case, whatever you buy find out the frequency response for the specific part, find the frequency you intend to use along the bottom, then see what the volume (db) is for that frequency - this will give you an indication of how loud it will be. Remember that you won't be able to hear it.

The circuit is pretty trivial. Google piezo arduino

Efficacy:

From https://en.wikipedia.org/wiki/Electronic_pest_control#Effects_on_rodents

  Rodents adjust to the ultrasound (or any new sound) and eventually ignore it. At best, ultrasonic waves have only a partial or temporary effect on rodents. Numerous studies have rejected ultrasonic sound as a practical means of rodent control.Tests of commercial ultrasonic devices have indicated that rodents may be repelled from the immediate area of the ultrasound device for a few minutes to a few days, but they will nearly always return and resume normal activities. Other tests have shown that the degree of repellance depends on the frequency, intensity, and pre-existing condition of the rodent infestation. The intensity of such sounds must be so great that damage to humans or domestic animals would also be likely; commercial ultrasonic pest control devices do not produce sounds of such intensity.


If you used the 9 V battery as described in the diagram, but with a 3 V rated motor, then the motor starts smoking and you might damage it. Use e.g. 2 AA batteries with 1.5 V instead of the 9 V battery, then it should work without smoke and your motor will survive much longer.


There seem to be two issues:

Getting the IDE to fully function when launched from the command
line, and;
Getting the IDE to fully function (i.e. compile) when launched from
the Fedora GUI menu.

I have found a solution if I run the Arduino IDE from the command line, by adding the path to  one of the cc1plus binaries to the PATH environment variable:

[piebody@berrybody ~]$ PATH=${PATH}:/usr/libexec/gcc/avr/4.9.2
[piebody@berrybody ~]$ export PATH
[piebody@berrybody ~]$ arduino&

However, if I launch the Arduino IDE from the Fedora application menu, and then try to compile a sketch, it still can't locate cc1plus. Maybe the PATH needs to be added in my .profile, or some other mechanism, to get an application launched from the Fedora menu to see the path?1

Yet, even with the command line launch, it still does not finish compiling.  I now get the following error when the IDE attempts to compile:

In file included from Blink.ino:18:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:23:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.

In verbose mode

Arduino: 1.0.6 (Linux), Board: "Arduino Uno"
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /tmp/build1210300884764677972.tmp/Blink.cpp -o /tmp/build1210300884764677972.tmp/Blink.cpp.o
In file included from Blink.ino:18:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:23:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.

I assume that this is another PATH issue. One that relates to the path to the Arduino libraries, or libc libraries.

After reading can't locate avr libraries2, I can't see why avr-g++ is not picking up the avr directory in the /usr directory.

The actual path to stdlib.h is /usr/avr/include/stdlib.h

The output of avr-gcc (and avr-g++) shows --prefix=/usr

The Arduino IDE preference file (~/.arduino/preference.txt) shows the line

last.ide.1.0.6.hardwarepath=/usr/share/arduino/hardware

Linking the includes

If I manually link some header files to where the compiler actually is looking, then it works (until avr-gcc needs a header that I have not linked to):

cd /usr/share/arduino/hardware/arduino/cores/arduino
sudo ln -s /usr/avr/include/stdlib.h stdlib.h
sudo ln -s /usr/avr/include/string.h string.h
sudo ln -s /usr/avr/include/math.h math.h

but I can not do this for every header file, it is ridiculous. There must be a way of linking to /usr/avr from /usr/share/arduino/hardware/arduino/cores/arduino. I have tried linking the parent directories /usr/avr and /usr/avr/include, at various points along the directory hierarchy of /usr/share/arduino/hardware/arduino/cores/arduino, but none of those seem to work.

Copying the include directory

After reading default include file path?, and running avr-cpp -v I saw that the default #include search path was

#include <...> search starts here:
 /bin/../lib/gcc/avr/4.9.2/include
 /bin/../lib/gcc/avr/4.9.2/include-fixed
End of search list.

From this, I could see that avr-cpp was searching in /lib/gcc/avr/4.9.2/include. I examined, and compared, the contents of /lib/gcc/avr/4.9.2/include with /usr/avr/include and they held similar (the same) files, except /lib/gcc/avr/4.9.2/include was a subset, that is to say that it was missing the required files.

I ended up copying the /usr/avr/include directory, which contains the required header files (stdlid.h etc., to which I had linked previously), and replacing the original include directory, in the directory where avr-gcc seemed to be looking, which was in its own directory location /lib/gcc/avr/4.9.2/.

cd /lib/gcc/avr/4.9.2/
mv include include.old
cp -r /usr/avr/include .

Then the Arduino compiler seemed to work, until it then gave an assembler error:

Assembler messages
Error: unrecognized option -mmcu=avr5

This is an issue with avr-as.

I will update as I resolve these issues.

1 I eventually resolved this by creating a script in /usr/bin (where the arduino binary was located) called arduino.launch which contains the PATH settings and a call to arduino:

#!/bin/sh
PATH=${PATH}:/usr/libexec/gcc/avr/4.9.2
export PATH
arduino

setting it to be executable with chmod +x arduino.launch. Then I edited the properties of the Fedora Arduino launch icon, by right-clicking on the icon and selecting Properties, and changed the Command entry from arduino to arduino.launch.

However, there must be a better way of doing this, as this seems to be a bit of a hack.

2 Other posts 1, 2 and 3) that I have read, apart from providing useful paths to investigate, merely suggest reinstalling. However, as bone headed as I may seem, there must be a way of linking up what is already on the file system (everything is there - just in the "wrong" place), such that compiles work as they should.


Possible to create IP-to-USB HID (keyboard) device using Arduino?

Yes, it is perfectly possible.

You ideally need an Arduino with a direct USB interface, such as the Leonardo. Then you can just access the Keyboard object to send the keystrokes to the PC.  How your receive the data through Ethernet is entirely up to you. A simple TCP interface may be easiest - open the connection with whatever telnet-like client and whatever you type gets sent through.  The trick will be getting it into character-at-a-time mode.


How to fade an LED in response to a sensor?

Do analogRead(sensor) and check what range of values you are getting. Arduino has 10 bit adc which means you can get 0-1023 in readings. However the sensor might not go complete LOW (0) or complete HIGH (1023). So just measure what's the range you are getting. Assume the range is 125 - 980.

PWM on arduino - This one is 8 bit, which means you can write 0-255. 0 means LED is OFF and 255 means LED is fully ON. Now you need to map 125-980 to 0-255 (as far as I can understand from your comments about synchronizing it with the sensor).

Here is what your code will look like:

/* Map an analog value (125-980) to 8 bits (0 to 255) */

    void loop()
    {
      int val = analogRead(0); //sensor attached to A0
      val = map(val, 125, 980, 0, 255);
      analogWrite(9, val); //LED attached to D9
    }


Is it possible to save different values on address 0 and 1 in EEPROM?

EEPROM.put() and EEPROM.get() write or read the object you pass them. An int is 2 bytes so that is what they write or read. It sounds like you intended for the functions to only handle 1 byte. In that case, make the your variable's data type something that is 1 byte, such as int8_t; otherwise allocate 2 bytes of EEPROM to each.

Update:
It works because you had only allocated 1 byte in EEPROM for each variable but you store 2-byte variables. Now you're storing 1-byte variables, which matches your EEPROM allocation.


Building projects on the command line using the Bare-Arduino-Project template

You  probably look at the wrong boards.txt:

# Trinket 5V Configuration
trinket5.name=Adafruit Trinket (ATtiny85 @ 16MHz)

this can be found in the boards.txt in the main directory

C:\Users\YOUR_USER_NAME\AppData\Local\Arduino15\packages\arduino\hardware

in the sub directory

\adafruit\avr

in the same main directory should  also be a folder named 1.8.2 (for ArduinioIDE 1.8.12) for the core files

if added via board-manager using this line in preferences/additional bord manager urls

https://adafruit.github.io/arduino-board-index/package_adafruit_index.json

If you did a manual installation check with this guide for pit traps.Details on using trinket with the avrdude command line can be found here


What does display.setSegments(&segto, 1, 1); do?

Let's take the hardest line first.  We'll start from the "inside" outwards.
segto = 0x80 | display.encodeDigit((value/100)%10);

The innermost bit is:
value/100

That gives you 12 from 1244.
Then there's modulus 10.
12%10

That gives you 2 (divide by 10 and return the remainder - 12/10 = 1.2, or 1 remainder 2)
That is then passed through a function that calculates what segments need to be turned on to represent the digit 2. Let's say that's 00110111 in binary, where each bit represents a segment to display.
To that you want to add the colon, which is in the most significant bit's place.  So you set that bit. That's done with the OR operator, which in C is |. 0x80 is 10000000 in binary.
OR the two values together:
00110111
10000000
========
10110111

That value is then assigned to the segto variable.
I am not familiar with that library, but I would assume that the setSegments function is expecting an array of segment settings, a number of digits to apply it to, and maybe a digit offset in the display (at a guess).
In C there is no real difference between using a 1 element array and using a variable and taking its address.
You could just as well have used:
uint8_t segto[1];
int value = 1244;
segto[0] = 0x80 | display.encodeDigit((value/100)%10);
display.setSegments(segto, 1, 1);

If you were doing more than one digit you'd be wanting to use an array anyway.


How to interface arduino nano with sim900A?

The bottom of your board shows a chip that gives every hint of being a charge-pump logic-level to RS232 inverting level shifter, to translate from the SIM900A's levels to the RS232 D-Sub connector.

It would appear that the 3 pin header just inside the D-sub would allow you to communicate at these levels.

However, a quick look at the SIM900A docs I could find suggests that these logic levels may be 2.8v, NOT 3.3v, and 3.3v is actually outside absolute maximum rating!

Essentially, you have two problems:

You need to drive and read signals with 2.8v logic, either by modifying your arduino to run at that voltage, or by using a level shifter.  It's possible that a resistor would protect the SIM900A, but that is going to be the most expensive component and so short of finding solid evidence of input protection diodes I'd be more hesitant to do that here than I would in other cases.
You need to make the level shifter not drive a signal into the SIM900A, so you don't fight with it.  You could do this by looking in the documenation (if any) for your board and seeing what accommodations they made for this, looking up the level shifter's  data sheet and finding the enable pin, or merely desoldering it.

Another option would be to make your Arduino talk at RS232 levels using its own shifter board.

Finally, there's a sort of hackish option:  Connect the transmit data from the SIM900A to a 3.3v Arduino, but connect the transmit from the Arduino through a simple inverter (tinylogic, whatever) to the RS232 receive pin.


Transient buttons control non-transient behaviour of LEDs

Don't react to the button by changing the LED; change a state-variable in memory, instead. That saves the information of which button was most recently pressed. Then, each time through your loop, set your LED's according to the contents of that persistent variable. Remember that it will have to be a static variable (global or static local), as an automatic one will disappear and reappear after each exit and re-entry to loop(), and you cannot count on its contents when that happens.

Update:

  How do I prevent overwriting the state variable with different input ?

You don't prevent it - you must over-write it. The purpose of the state variable is to remember which button was last pressed. I had in mind something like the following, where lastButton saves the number of the most recent button:

void setup(){
   pinmode(LED1PIN, OUTPUT);
   pinmode(LED2PIN, OUTPUT);
   pinmode(BUTN1PIN, INPUT_PULLUP);  // you might not want the pullup
   pinmode(BUTN2PIN, INPUT_PULLUP);  //  depending on your wiring.
}

void loop(){
   static uint8_t lastButton = 0;

   // Save the number of the last button pressed.
   if (digitalRead(button1) == HIGH)
      lastButton = 1;
   else if (digitalRead(button2) == HIGH)
      lastButton = 2;

   // Set the LEDs according to most recent button
   // Note that at program-start, when no button has
   // been pressed yet, this code leaves both LED's off.
   if (lastButton == 1)
   {
      digitalWrite(LED1PIN, HIGH);
      digitalWrite(LED2PIN, LOW);
   }
   else if(lastButton == 2)
      digitalWrite(LED1PIN, LOW);
      digitalWrite(LED2PIN, HIGH);
   }
}


do i need an I/O shield for quadcopter motors

If the ESC accepts a signal that the Arduino can generate (i.e., 5V PWM) then no interfacing is required.

If the ESC is running from 3.7V (or similar) then some level shifting may be required to reduce the 5V signal to 3.7V, depending on the ESC. That may be built on a shield of some form or just with discrete resistors wired in manually to the leads.


What is the sampling-rate of the `analogRead()`?

The ADC in default configuration will take 104 µs to make a sample (which agrees with Edgar Bonet's comment of roughly 9600 per second).

You can speed that up somewhat by changing the ADC prescaler from the default of 128. See ADC conversion on the Arduino (analogRead). A prescaler of 32 will reduce that to 26 µs and still give quite acceptable results.

You can also run the ADC asynchronously (in the background) so you can transmit the previous result while obtaining the next one. A higher baud rate than 9600 baud would be highly recommended in this case.

People have been doing FFT analysis using the Arduino Uno and similar. I suggest you Google for relevant posts about that.


Connecting an arduino uno to an arduino due

if(Serial.available())
{
 if (b == Serial.available())
{
 while(Serial.available())
 {

I think you may be getting your knickers in a twist there.

... Is serial available? Yes. Is serial available? Still yes! But yes doesn't equal '$'!!!... WHAT?!

You really really need to rethink your understanding of serial communication.

Read this: http://hacking.majenko.co.uk/reading-serial-on-the-arduino


A normale servo will stay in position when:

It's powered up (with enough current)
You are feeding the control signal into it.

And

It's rated for the amount of force applied.

Based on your comments, it seems that it's not a regular servo or could be faulty.
I couldn't find the datasheet for your servo, so I can't tell if it's normal behavior, though it seems unlikely. (Servo's aren't made to bounce around)

Edit:
It doesn't really make sense that it could be easily rotated by touching it, that would also mean that it can't lift anything? I would suggest trying another servo.


Arduino IDE / Specified folder/zip file does not contain a valid library

You don't install that repository as a Arduino library.

Read the README file in that repo. It explains how to install it using the Arduino IDE Board manager. That's the correct way to install it.


What is the difference between Arduino board and Genuino Board?

The name Genuino grew out of the split between Massimo and Gianluca (aided in part by Microsoft of course, and a trademark wrangle that went wrong). Each side wanted to appear to be more "genuine" than the other. That lead to the "Genuino" name (a genuine Arduino), and a version number war with the IDE.

Both sides started making their own variants of boards, with some only available from the USA (Arduino) and others only outside the USA (Genuino).

Since they have patched up their differences now the two boards are one and the same. A Genuino Uno and an Arduino Uno are the exact same board. They always have been, there has just been arguments over the name.


Wifi.status() always returns WL_NO_SHIELD

The problem is solved now.

I imported the Adafruit_CC3000 library which can be downloaded here: https://github.com/adafruit/Adafruit_CC3000_Library
I run the example but the output was chinese nonsense
Instead of

Serial.begin(115200);

I used

Serial.begin(9600);

then the examples run without any problem

Thanks @Majenko. His question was very helpful.


I'd consider using Bosch BME280 digital sensor. Although it's a bit expensive, it has very good sensitivity, precision and amazingly fast response for humidity changes (for ex. in my project it detects dry human hand lying in 2" away within a 1-2 seconds).

So its features make possible to put it into an enclosure to avoid direct water contact with water spays and it'll still be very responsive for greenhouse needs, I suppose.
Datasheet warns:

  Liquids shall not come into direct contact with the device.

Also, I'd use electronic-friendly protective acrylic lacquer (Plasticote 70 for instance) and put two layers to sensor's PCB, avoiding small black tiny vent hole on the chip itself:

UPD: Here's DHT11 with cover removed:

It might be the easiest and cheapest solution to cover all internal contacts and IC (avoiding humidity sensor's stripes) of DHT11 with Plasticote 70.


Make something happen on a continous input just once and for a specific amount of time

you want something along the lines:

bool continuing;
#define trigger 't'
void loop(){
  if( Serial.avaiable()) {
    char c;
    c=Serial.read();
    if (continuing) {
       if (c==trigger) { //do nothing, ignore it
       } else {
       continuing=False; }
   } else {
     continuing=True;
     motors.start();
     the_time=milis();
   }
 };
 if (the_time+timespan>milis()) {motors.stop();};
}


How to get the MAC address of an Ethernet shield, if it is not printed on it?

If you do not have a MAC address then you have to make one up.  There are a couple of rules and regulations about what a MAC address can be, but most of the time you can just make one up:

It must be unique on your network
There are a set of prefixes that are reserved for special purposes:

The lowest bit of the first byte must be 0
The second bit of the first byte must be 1

You can read more about it here: https://en.wikipedia.org/wiki/MAC_address

Once you have provided a MAC address and physically connected it to the network then you need an IP address and netmask.  There are two ways you can get the IP address and netmask:

Through DHCP - For example your home internet router would provide the IP address for you.
By allocating your own. This must be within the range of your network's IP addresses, typically something like 192.168.0.x where x is between 1 and 255.  The IP address must be unique on your network.

The netmask, again, can be given by DHCP, otherwise you will have to enter the netmask of your network, typically 255.255.255.0

Then to access the internet itself you need to provide (or be provided with through DHCP) the address of the internet gateway and possibly a DNS server address. On a home network they are typically the address of the router, which may well be 192.168.0.1 or something similar.


How to call an interrupt when any one of the 12 defined digital inputs go high?

You are kind of unlucky. The ATmega2560 MCU has 32 pins capable of
generating interrupts (counting the INTn and PCINTn, not sure all of
them are routed to board headers), but none of the pins you have chosen
is interrupt-capable.

I suggest you combine your 12 signals, using external logic, into a
single interrupt signal. You would then, in the ISR, sort out which
individual signal triggered the interrupt. A pair of 74HC4075 chips
should be enough to OR together the 12 inputs.


It means that it is a unsigned value. Because the compiler checks for signed and unsigned in the same operation this is used (amongst others) to avoid warnings.

This is explained on stackoverflow here https://stackoverflow.com/questions/14844119/define-foo-1u-2u-4u-what-does-1u-and-2u-mean


unresolved overloaded function type for Wire.onReceive

void pi::sendPI(){

That is a class function (method) which has an implicit this pointer. You can't use it as a static ISR.

In general, classes cannot implement ISRs for this reason. There are a few workarounds, one being to make it a static class function. However then it will affect the entire class, not just one instance.


Is there an ICRn CTC mode interrupt vector?

No, there isn't. But you do have a simple alternative: use WGM 14
(fast PWM with TOP = ICR1). Then the TOV1 flag will be set after
the timer reaches TOP:

TIMSK1 |= (1 << TOIE1);  // enable Timer 1 overflow interrupt

ISR(TIMER1_OVF_vect) {}  // Timer 1 overflow vector

Note that this waveform generation mode behaves very much like the CTC
mode. If you do not set any of the COM1 bits in TCCR1A, then there will
be no PWM output.

Edit: My bad. As noted by Gerben and confirmed by you, the
TIMER1_CAPT_vect can be used, and it is specified in the datasheet,
although maybe not very prominently:

In section 17.9.2 “Clear Timer on Compare Match (CTC) Mode”:

  An interrupt can be generated at each time the counter value reaches
  the TOP value by either using the OCFnA or ICFn Flag according to the
  register used to define the TOP value.

In section 17.11.40 “TIFR5 – Timer/Counter5 Interrupt Flag Register”, in
the description of bit 5 (Input Capture Flag):

  When the Input Capture Register (ICRn) is set by the WGMn3:0 to be
  used as the TOP value, the ICFn Flag is set when the counter reaches
  the TOP value.


What type of hardware could make a ball tilt or roll?

The ball moves are made by a simple physics principle called Conservation of Angular Momentum. The angular momentum is a property that has any object that rotates and is proportional to its mass and velocity.
To make a ball move you should play with this momentum, using its simplest application, the mechanical gyroscope.
The mechanical gyro is made of a heavy disc rotating at high speed, modulating its velocity you can change the momentum and create a force that will move your sphere.


Why can't my bluetooth receive serial data from my android phone, but can send serial data from my bluetooth to my android phone?

Your erroneous level shifting attempt from Bluetooth TX to Arduino RX is the root of your problem.

Pins 0 and 1 are also connected to the on-board USB interface chip via a pair of 1kΩ resistors. These resistors serve two purposes:

To "weaken" the drive of the USB chip's UART interface (actually only needed on the USB chip's TX -> Arduino RX connection), and
To protect both the USB chip and the main MCU from damage should two connected pins be set to opposing levels, which would cause high currents to flow through both output drivers.

The TX pin of the USB chip is actively driven HIGH all the time when idle (stupid design by Arduino, it should be Hi-Z when the port is not open), and the RX pin is pulled up by the internal pullup resistor in the USB chip.  Further, when the Arduino's Serial is in use the TX pin of the Arduino is actively driven HIGH when idle (or LOW when transmitting a "1" bit).

The actual circuit you have looks more like this:

simulate this circuit – Schematic created using CircuitLab

Transmitting from the Arduino to the BT module is straight forward enough - the "high" point of the circuit is the Arduno's TX pin at 5V when idle.  Current flows through R2 to the USB RX pin, and through R5 to the BT RX pin, with a portion split off to ground, which is what you want for your level shifting.

Communication in the other direction, however, is different, because you have two balanced "high" points in your circuit - one at the USB TX and one at the Bluetooth TX - and the fact you have 1kΩ resistors in both branches means that neither transmitter is "stronger" than the other. This means that when the BT TX is LOW (0V) you have around 2.5V at the Arduino RX pin (5V over two 1kΩ resistors = 2.5V in the center tap - see here).

Since 2.5V is neither within the Arduino's HIGH nor LOW voltage ranges (which are more than 3.5V for HIGH and less than 1.5V for LOW when running from 5V) the input is completely ignored.

The 3.3V transmitted by the Bluetooth module is a little under the official threshold for a HIGH signal on an Arduino, but in practice, it usually is detected fine. So remove the resistor network from the Bluetooth's TX pin and connect it directly to the Arduino. Since the input threshold voltage is a function of the supply voltage (0.7 * Vcc) it depends very much on your power supply as to whether it will work reliably or not. If you find it doesn't, you should use some upward level shifting.  There are simple MOSFET based bi-directional level shifters available cheaply that are a better solution than resistors, and will allow proper operation in both directions, shifting a high voltage to a low one and a low voltage to a high one. These are good for lower frequency communications such as UART. If you should need higher frequency, or you find a simple MOSFET based shifter isn't working for you then a 74HCT08 or similar chip (be sure to use the HCT range not the HC range) or a dedicated level shifting chip may be in order.


How to get the angle from vertical window blinds

A hall-effect sensor, plus a small magnet attached (glue?) to the outside edge of one slat ought to be able to tell you the strength of the magnetic field, and thus the distance of the magnet from the sensor. From that, given that the rotation is with a fixed radius, you can deduce the angle while introducing zero additional friction.

Edit:
I had imagined something like:

However, looking again, this introduces difficulty in detecting the 90deg position, where the magnetic flux lines are exactly parallel to the hall-effect sensor plane.

If you experiment with this enough, you may be able to get repeatable values from the sensor to know the angle of the blind slats.

Edit 2:

The timing measure you noted in your question could also be a possibility. If you could use a microswitch or photo-interrupt sensor on the extreme ends of travel (0deg and 180deg), so that any time those extreme ends are detected, you can eliminate drift.


Try sending a command that sets the GPS baud rate to something a little lower:

altss.write( F("$PMTK251,38400*27\r\n") );
altss.end();
altss.begin( 38400 ); // change to match above command

Are you sure you're having trouble reading, because there are many other things you may be doing in your sketch that cause input buffer overflow.  Please post your code and some sample output for us to examine.  It may be failing for a different reason.

For example, you may just be losing data because you're trying to do too many things in loop().  Please take a look here.

To solve this kind of problem, I have posted a modified version of AltSoftSerial on github, here, that let you process GPS data in the background (i.e., during interrupts).  When coupled with NeoGPS, it can save you quite a bit of program space, RAM and execution time.  There is an interrupt-driven example here.  Just change which include is uncommented on lines 30-31:

#else
  // Only one serial port is available, uncomment one of the following:
  #include <NeoICSerial.h>
  //#include <NeoSWSerial.h>
#endif
#include "GPSport.h"

...and the baud rate below, on line 140:

  // Start the UART for the GPS device
  gps_port.attachInterrupt( GPSisr );
  gps_port.begin( 115200 );
}


You send from Serial Monitor a character followed by a new line character. This two characters are available. Nothing more to enter the if (Serial.available()) { block.


How to attach interrupts to Arduino UNO timers?

For the UNO, use Timer1.

An example of the way you can use it is as follows:

Download the TimerOne library: https://code.google.com/p/arduino-timerone/downloads/list

/*
 *  Timer1 library example
 */

#include "TimerOne.h"

void setup()
{
  pinMode(10, OUTPUT);
  Timer1.initialize(500000);         // initialize timer1, and set a 1/2 second period
  Timer1.pwm(9, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
}

void callback()
{
  digitalWrite(10, digitalRead(10) ^ 1);
}

void loop()
{
  // your program here...
}


The problem is with sizeof(com) in your loops. sizeof() is for C arrays, not string objects. If you print it, it will report 6, which is not the length of the array. For string objects you should use com.length() instead. Then the output becomes

Saved
Testing~Network123......

P.S. The EEPROM can store 1024 bytes on ATmega328P-based boards (I believe that's what most Arduino Nanos use (clones included).


Is the supply voltage made available anywhere on the Arduino Uno Board?

The Vin pin is available (next to Gnd) pins.


EBay "Development Programmer Board for ATtiny"

If you don't have experience working with AVRs at a low level then stay away from that. It doesn't provide any connection for a programmer and relies on the Micronucleus bootloader already being in place.

If you really want to experiment with ATtiny development then go with either an Adafruit Trinket or a Digistump Digispark (both of which already have Micronucleus loaded), or get an AVR programmer and (optionally) a ATtiny13/25/45/85 development board that includes a 6- or 10-pin programming header


The read() method works character-wise, not element-wise. Then you
have to rethink your algorithm to loop over characters:

store each character in a buffer
send the whole buffer (i.e. a single element) when you see a delimiter

Example:

const size_t BUFFER_SZ = ...;
char buffer[BUFFER_SZ];
size_t pos = 0;    // current write position in buffer
int c;

// While we can read a character:
while ((c = <file>.read()) != -1) {

    // If we get a delimiter, then we have a complete element.
    if (c == ',' || c == '\n') {
        buffer[pos] = '\0';         // terminate the string
        raspberry.println(buffer);  // send to the RPi
        pos = 0;                    // ready for next element
    }

    // Otherwise, store the character in the buffer.
    else if (pos < BUFFER_SZ-1) {
        buffer[pos++] = c;
    }
}

Here the buffer is sent as a string. If you want to parse it into a
number, you can use sscanf.

This code assumes Unix text-file conventions, i.e. each line of the file
(including the last one) being terminated by an LF character. You may
have to adapt if your file is different.


There can be power/connection problem or somehow the bootloader has been damaged.
So

Check power
Check Connection

If there no problem found, then by using usbasp, avrisp, usbtinyisp, etc reflash the bootloader. I hope your problem will be solved.


The Ultrasonic sensor just detects the same distance

First of all you need to make cm, inches and duration float to be more precise. Second, you need to make the delay 2 and 10 microseconds between triggers. Overall, if I'm not wrong you can use the code below without changing your circuit.

int tPin = 11;
int ePin = 12;
float duration, inches, cm; //floating numbers to make the result more precise

void setup()
{
    Serial.begin(9600);
    pinMode(tPin, OUTPUT);
    pinMode(ePin, INPUT);
    pinMode(2, OUTPUT);
}

void loop()
{
    digitalWrite(tPin, LOW);
    delayMicroseconds(2);         //Delay 2 microseconds
    digitalWrite(tPin, HIGH);
    delayMicroseconds(10);        //Delay 10 microseconds
    digitalWrite(tPin, LOW);
    duration = pulseIn(ePin, HIGH);
    cm = duration / 58.2;          //Instead of duration/2/28.1
    inches = cm / 2.54;            //You can use cm that was created before for conversion
    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(100);

    if (inches <= 10) {
        digitalWrite(2, HIGH);
        delay(50);
        digitalWrite(2, LOW);
        delay(50);
    }
    else {
        digitalWrite(2, HIGH);
        delay(500);
        digitalWrite(2, LOW);
        delay(500);
    }
}


Dust sensor for Arduino in open and windy environment

A popular option is the Shinyei PPD42 sensor. There are a few well-documented blogs that describe how to connect it to an Arduino. Some of the users determined that the sensors are more accurate when a fan is placed on the unit to blow air through it, but this might not be necessary in an outdoors and windy environment.

I have two of these sensors hooked up to an Arduino, one monitoring indoors and one outdoors. I found that the indoors unit needed a fan on it to help it detect particles better (otherwise I was getting too many zeros). But the outdoors unit seems fine without the fan.

I mainly followed this blog's instructions for the code:
http://www.howmuchsnow.com/arduino/airquality/grovedust/

I think I read a few months ago that the next best sensors are in the $200 range.

I have a Dylos DC1100 dust monitor (considered very accurate) and it usually correlates with my Shinyei readings. But I'm pretty sure I introduced some "magic numbers" into my code to make the Shinyei readings match more closely with the Dylos. The entire process wasn't easy for me, and it took me weeks to get everything to behave the way I wanted.


What's the newest way to use C++ stdlibs in Arduino 1.8.2?

Most Arduino Core don't include the Standard C++ Library, that's why headers like <vector> and <string> are missing.
This decision makes a lot of sense because the STL relies heavily on heap allocation, which would ruin the little RAM of the microcontroller.

If you're looking for an alternative to the STL, you might check out the ETL, the Embedded Template Library.. However, the code will not be the same because all the containers of the ETL have a fixed capacity. Here is a string for example:

etl::string<32> s = "hello world";

In practice, I never saw a project using the ETL. Most projects use the standard Arduino classes (String, Stream, Print...) and learn to live with their flaws. Since there are no generic container classes in the Arduino core, the common usage is to use plain old C arrays.


How to run 5 wires hibrid stepper motor with arduino uno?

1) it is probably something like A1, A2, Common, B1, B2.  You could confirm this with an ohmmeter. Common to any of the others would be a certain resistance X, while between any of the others (A1-A2, B1-B2, A1-B1, A1-B2, B1 A2) would be 2X.

2) You can't.  It is a unipolar stepper.

The EasyDriver faq number 5.1 at http://www.schmalzhaus.com/EasyDriver/ says:  "... The only kind you can't use is 5-wire stepper motors. (They need uni-polar drivers.)"

The difficulty with the 5-wire steppers is that they short the middle of the two coils together, which makes it hard to drive the coils independently.

Since you have the motor open, you might be able to do some surgery and disconnect the centers of the coils from each other, but you'll probably be better off getting a 4, 6 or 8 wire stepper instead.


Adafruit OLED 7 Pin Display - Abbreviations

DC selects between Data and Commands.
CS is the Chip Select
SDA is the Serial DAta.
SCL is the Serial CLock.

These four together form what the documentation calls the "4-wire serial interface". It's not quite like SPI, owing to the presence of the DC pin (which is why it doesn't use SPI terminology), but close enough that SPI can be used to communicate with it.
In SPI the pin that sends data from the Arduino to the slave is known as the MOSI - Master Out Slave In.  Some microcontrollers also call this SDO - Serial Data Out, where it's "out from the master's perspective".


According to this page on Arduino for Linux there ought to be some devices at /dev/ttyACM*

That is not the case. On a "traditional" Arduino board, like the Uno, you have two chips: the main MCU which you program, and a USB interface chip, which is pre-programmed with code to present a CDC/ACM interface to the computer (which it then creates a /dev/ttyACMx device for).

With the feather you don't have that. You have one single chip. That chip is both the USB interface and the chip that you program - and most importantly, it is your program that provides the CDC/ACM device if you choose. If your program doesn't provide a CDC/ACM device then the computer will never see one, so it will never create /dev/ttyACMx.

In general the Arduino core always adds a CDC/ACM device whether or not you ask for it, since it is often used to initiate a reset into the bootloader. However if your sketch stops working for whatever reason then the CDC/ACM port is no longer there.

The M0 on the feather has a neat trick though - if you reset the board with the reset button twice the startup code recognises that fact and forces it to run the bootloader. That bootloader then presents the needed CDC/ACM device to the computer allowing you to upload new code.

Of course, if your program that you upload then doesn't initialise its own CDC/ACM device, or crashes, the CDC/ACM device will not be presented until you do the double-reset trick again.


Check these things first:

Is your power supply give a constant 3.3V and a minimum of 0.5A(500mA)?
Does your code work for others?
Are you on the right serial baud rate?
Is the path from the radio to the Arduino as short as possible?
Are your MISO and MOSI wires twined into each other?

If none of these things help then, please tell me what library you are using. I had a lot of issues with the RF24 library so maybe try using the NRFLite library.


The SoftwareSerial example code
https://www.arduino.cc/en/Reference/SoftwareSerialAvailable
shows that the pins used as tx and rx for SoftwareSerial need to be defined using pinMode() as digital input and output.

  Example

// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>

#define rxPin 10
#define txPin 11

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  // define pin modes for tx, rx:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available()>0){
    mySerial.read();
  }
}


In the end, stimulated by Majenko's advice to desolder the LED,  I instead carefully studied the PCB layout online, checked that it corresponded to my PCB, checked the location of nearby traces I didn't want to cut and then used multiple magnifying glasses and a fresh blade in my smallest utility knife and carefully cut the track leading from the LED to the IC. All was well.


How can the sensitivity of capacitive touch sensors be limited?

digitalRead(pin) is the wrong way to read capacitive touch inputs.

In the file from the example you linked in your answer, the reading is made by calling CircuitPlayground.readCap(pin, num_samples) and then the returning value is compared to a threshold.

const uint16_t TOUCH_THRESHOLD = 300;

...

if (CircuitPlayground.readCap(Fire) >= TOUCH_THRESHOLD) {
   Keyboard.write(KEY_SPACE);
   Serial.println('F');
}
...

You can change the sensitivity by changing TOUCH_THRESHOLD. You could also add and fiddle with the second argument to change the number of samples.


Handle reading timing in Python using pySerial

The answer is that it depends on what you are actually trying to accomplish. If there is nothing else to be done on the Arduino then it is fine to have it sit and wait; on the other hand if there is nothing else for the python script to do then it is fine for it to sit and wait, but there is no reason for both of them wait.

Arduino delays

You don't need to deal with the timing delay in python if the Arduino is delaying. According to the documentation readline will wait until it has received a value or until the timeout is reached. That said, I would make the timeout slightly longer than the delay on the Arduino side of things.

Note that readline will block your program from doing anything else while it waits. As such, It is pretty useful to explore python threading when you are writing a program which collects data over a serial stream unless the program is only collecting data.

Python sleeps

If there is other stuff to be done on the Arduino (perhaps if you are doing some filtering of the temperature data using the Arduino so as to reduce noise) then it might make more sense for it to push data to the serial stream at the end of each loop, and for the python script to only read the data every 5 seconds. In this case you could have python sleep and use no delay (or a shorter delay) on the Arduino. You can achieve this behavior without resorting to using sleep by using a timer object to periodically call a function that opens the serial stream (possibly flush it), reads the data, processes it, and closes the serial stream.


The execution time of your loop() will be slightly longer when the CPU
runs at 8 MHz v.s. 16 MHz, but I don't expect the difference
to be significant. CPU-bound functions, such as digitalWrite(), will
run at half the speed. These functions, however, are quite fast. In
contrast, analogRead() is slow, as it takes roughly 110 µs to
execute, so this is likely where your loop() spends most of its time.
The execution time of analogRead() does not depend significantly on
the CPU speed. This function spends most of its time waiting from the
analog-to-digital converter to do its conversion. When the CPU is
clocked at either 1, 2, 4, 8 or 16 MHz, the Arduino core sets the
ADC prescaler so that the ADC is clocked at 125 kHz.
This means the conversion time will be the same irrespective of the CPU
frequency.
Note: You may just use your Arduino Pro Mini 5V 16MHz. This board is
based on the ATmega328P microcontroller, which is rated for frequencies
up to 20 MHz when the supply voltage is between 4.5 and 5.5 V.
According to the datasheet (see freq-Vcc graph), it should safely
run at 16 MHz for any supply voltage between 3.78 and 5.5 V.