text:
Can you connect an output pin from one Arduino to the input pin of another?
I have a system that uses two Arduino boards.  One is used to control several different functions, and the other is dedicated to driving a 45 second countdown display (comprised of two large 7 segment displays.)  All this second Arduino needs is a single signal to tell it when to start.  I would like to simply connect an output pin (on #1) to an input pin (on #2) and and send a single pulse to get the clock started.  Fo something this simple, I wanted to avoid using I2C.  Can I do this?  If so, is there anything else I need to be aware of (like connecting ground to ground?)

Yes, you can. That is indeed the most easy way of communication.
And like you said, you have to connect the grounds of both arduino's.
Optionally you could add a pull-up of pull-down resistor, so the countdown doesn't accidentally start if the first arduino is still starting up, or is disconnected.

Doe the pull-up (or pull-down) ensure that the base state for the input is high (or low)?

Yes. That's what it's for.


text:
For the digital output pins, how is LOW different than no connection?
I am working with relays and I noticed that connecting the trigger pin to ground (or a digital pin set to LOW) is not the same as having the trigger connected to anything.  For the digital output pins, how is LOW different than no connection?  Is there actually a current flowing into the LOW pin, or is there a tiny current flowing into the relay?
Is Ground and LOW the same voltage?

Connecting a relay directly to an output pin is not a good idea: you should use a transistor to provide enough current to the relay. You also need a diode to protect against reverse emf voltage.

I'm not sure exactly what you're asking but try giving this a read: http://arduino.cc/en/Tutorial/DigitalPins. What are you declaring the pin in question as?

(Edit for clarification: I've assumed in this answer that you're asking about the difference between connecting the relay to ground/LOW vs. connecting the relay to nothing at all. I've also assumed by the word "trigger" that your relay has some kind of digital actuation built-in, such as a transistor, or that it's simply a Solid State Relay.)
If something is unconnected, it is described as 'floating'. This means there could be random voltage spikes in it caused by nearby electromagnetic fields, making it appear to be switching on/off.
Connecting something to ground or LOW can stop this from happening by drawing away any induced currents.

What you describe is true for inputs, not outputs. The op is about outputs.

No. The electromagnetic environment does not create any currents on the floating pin. It creates voltage fluctuations.

@EdgarBonet Oops, sorry. I wrote this post late at night. :)

@jfpoilpret - I think we've understood the question in different ways. I've edited my answer to clarify my assumptions.

Ground and LOW are very, very close in voltage. They are the same when no current is being sunk into the output (LOW sinks current from higher voltages, HIGH sources current to lower voltages), but the voltage rises as the current does (the output has a resistance of about 25ohm).

source: Stack Exchange

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

sort: votes


text:
Fog machine Arduino integration
I want to control my fog machine with an Arduino.  Has a simple button that is used to activate the machine.  I want to press this button using an Arduino digital output pin, but the fog machine is operating on its own electrical circuit.  How do I use the Arduino to activate this machine?
I a few other machines with buttons that I want to wire into an Arduino, so is there a generic solution?

As krol says - a relay is liable to be what you want. Relays like these ones cost between $US1 and $US1.70 per relay and use 5V power supplies to operate them PLUS wil accept Arduino output signals top control them. I have found that specific seller reliable and the products good. Shipping is usually free and delivery to me (in NZ) takes typically 2 to 3 weeks. [I have no relationship with them except as a satisfied customer].

You can interface with the fog machine's button by:

Use a Relay (this will isolate the fog machine's circuit from your Arduino's)
Use a Servo to physically press the button on the fog machine

I believe those would be the simplest and most generic.

Krol - see my "answer" - you may add this material to yours if you wish.

@RussellMcMahon good expansion.

Please do not upvote this answer.
This is an expansion of @Krol's answer.
Krol may incorporate this material in his answer if he wishes.
The image below shows a typical relay module which is able to be driven by logic level / GPIO signals from typical microcontrollers.
The relays have 5V coils and there are optocouplers and drive transistors between the input and the relay.
Inputs are active LOW - ground to turn on.
These are available by mail from China for under $2/relay (under $1/relay if you buy 10 modules with several relays in).
They are NOTIONALLY opto-isolated as well as having relay isolation between input and contacts. BUT the PCB layout and relay design is such that mains to input clearances are poor. They will PROBABLY NOT kill you or your controller but they may - as is the case with much other items manufactured afar off at ludicrously low prices.
I have found the seller/manufacturer whose logo appears on that photo to be a reliable supplier of well made products. (Being well made does not overcome "dangerous design" as above.
Note that the above warning applies to most buffered relays you can buy on the hobbyist market and also top consumer products that have not been put through formal testing (UL etc). This relay board would fail UL testing - as would most others.

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


text:
How can I calculate approximate cycles per second from pulsed pin on Arduino MKR Zero?
The relevant tech specs for a MKR Zero are:
    32.768 kHz (RTC*), 48 MHz
*Real-Time Clock
What I'm curious about is how I might do an approximate calculation of cycles per second from operations.
I'm running the following (extremely simplified) code :
int pin3 = 3;
void setup() {
  //set digital pin pin3 as output

  pinMode(pin3,OUTPUT);
}

void loop(){
  digitalWrite(pin3,HIGH);//set pin pin3 to +5V
  delay(100);//wait 100ms
  digitalWrite(pin3,LOW);//set pin pin3 to 0V
  delay(100);//wait 100ms
}

Now I'm curious how many cycles per second (approximately) that might account for.
The Equation?
What would the equation be to calculate that?
Not Processor Op Codes
Is this even possible to approximate?  I understand it will be difficult because those lines of code do not equal the actual op codes and don't exactly break down to specific cpu cycles or whatever.
Would it be something like:
48,000,000 (48MHz) / 200 (millisecond pause) = 240KHz?

Or would I use the real-time clock speed?
32768 / 200 = @163Hz

Or something completely different?
I'm trying to better understand how I might create a very simple frequency generator and I know that depending upon the chip speed the code will vary.

Do you know the library for the internal rtc of a arduino mkr zero? https://www.arduino.cc/en/Reference/RTC You could increment a counter in the loop and measure it against the real time. For example during an hour, then you can calculate the actual cycles per second. It might be 4.999 Hz per second. You can also use millis to set the output exactly to a certain number of cycles per second. Perhaps even the tone function can be used.

It is unclear exactly what you are trying to do, however the frequency generated by the code would be ~5Hz - corresponding to a period of 200mS

Thanks, what is the equation that you applied to come to that answer?  Oh, (forehead slap) it is generating a pulse every 200mS so 1000mS (1S) / 200mS = 5Hz.  So it would actually be ~5Hz (not kHZ), right?  Thanks for answering.  If you change it to Hz I will mark it as the answer.  You helped me get to the right point.  I had been thinking something else.  Thanks.

The dependency on the clock speed is hidden in the implementation of the delay() function. It works with 'human readable' milliseconds.
Hertz is count of repeating in one second. One second has 1000 ms. So with 200 ms delay, 5 repeating happen in a second. Then the frequency is 5 Hz.

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


text:
Powering an Arduino Mega with external USB Power Bank?
I am making a robot with arduino mega r3. I want to power the arduino with a usb power bank. How should I do that?

Did you try plugging it in?

Plug USB power bank output into Arduino USB port. Done. [BUT see madanon's comment re the need to dra a minimum current level in some cases to keep powerbank output alive].

I know that I am not supposed to post this, but @IgnacioVazquez-Abrams, thank you sir. I love your sense of humor :D

I have a "USB power bank" with two USB ports, which I use to power some projects.
I have discovered that my bank (i.e. your mileage may vary!) shuts off unless my project draws at least 50mA. If your project does draw at least that at ALL times, you should just be able to plug a USB cable directly from the powerbank to the project.
For some other projects, I have bought a USB cable (USB A to USB A) which I cut in half, stripped the wires, then used a multimeter set to "Volts" to work out which wire was +5V and which was GND; I connect these straight to the 5V/GND on my project. To make sure at least 50mA was drawn at all times, I put a 100 Ohm resistor from +5V to GND (at LEAST 1/4 watt!!). This obviously wastes a lot of power (turning it into 1/4 watt of heat), but it keeps the power bank "awake". By using a USB A to USB A, I now have two cables.
My power bank also has a "torch" (led) integrated; if the torch is on, it also stays awake.

+1 Quantification if minimum current requirement is useful.

Thanks! This solved my problem. I tried powering an arduino with a power bank and it kept shutting down every X seconds, unless I turned on the LED on the power bank. In that case it continued working until the led went out. Now I know why :)

@RussellMcMahon, the 50mA figure is probably not useful, as it will vary from model to model. Gives an idea though :)

Powerbank is a term for those external batteries that output USB. Usually used to recharge a phone when you don't have access to wall outlet and USB charger.
Inside powerbank:
Battery (3.7v) --- Some Circuit --- USB female
How to:
You have a bank
You have USB cable
ugh! ...
Plug USB to Arduino and you are (pretty much) done.
For those who use ProMini and/or want to skip the USB port
Cut the USB cable and take the red (+) and black (-).
Put it directly to Vin and Gnd and you are good to go.
*
Unfortunately for us (fortunately for most) most Powerbank has auto-shutoff where it will shut off the power if there's no load (usually ~50mA, vary with every brand). Since Arduino may not draw that much, the battery thinks it is not connected to anything.. thus it will auto-shutoff after a while
I found this trick helps (a lot!! thank you!):
https://www.dorkbotpdx.org/blog/paul/battery_pack_load

Not clear what a usb power bank is. I assume you actually have a battery, perhaps with a regulator. The data sheet
http://www.arduino.cc/en/Main/arduinoBoardMega at says: Microcontroller ATmega1280 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 54 (of which 15 provide PWM output) Analog Input Pins 16 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA
also
The Arduino Mega can be powered via the USB connection or with an external power supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.
If you use the usb connector, use the correct pins an make sure you have it regulated to 5 volts.
I think this answers the question, if not please comment.


text:
RFID library issue
I am having some strange issue. I am using Linkit One board, which is a based on Arduino.
I am using rfid reader RC522 which is cheapest and most common.
I cant get its official library get it work. I tried to search for problem or differences but nothing help. I am looking for some to take a fresh look because its been 4 days and i am stuck.
Not Working https://github.com/miguelbalboa/rfid
Working (this is full ino in single file) http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt


text:
Connect the output of an Arduino to the input from another Arduino
I'm making a project and i'm trying to send bits from an Arduino to another Arduino with the digital pins. So my setup are 2 Arduino's connected with a jumper.
I connected the grounds and they have both a different power supply.
Now I tried this set-up and as soon as I connect the output pin to the input pin from the other Arduino the voltage lowers from 5V to 2.6V so we can't detect our bits.
Anybody an idea how to solve this problem?
Thanks in advance!
Kind regards,
Manu

Schematic and code?

Well, it could be the bad case of two NOT floating PSs with different ground levels.

Or a simple case of two outputs connected together, driving different levels.

How did you measure the 2.6v you're talking about? (Also, you probably should add a resistor in between, just in case the voltages between the 2 arduino's are not exactly the same).

We measured it with an oscilloscoop. The strange this is we tried everything that is commented below. We will try an optocoupler, maybe this will work. We are pretty sure it ahs nothing to do with the code because we stripped everything to the basics because we thought the code wasn't working. We wrote a new code just to detect if the input was 1 or not and even that is not working. We are thinking it has something to do witch the reference voltage (ground).

Schematic will help. Also, tell us if the 2.5V is on the data line connecting the two arduinos, or did the power of any of the arduinos dropped to 2.5V?

As you are trying to communicate with two arduinos I will suggest you to use some sort of standard communication protocol such as Two wire interface or I2c. There is the Wire.h library you can use and it has also a reference on the main Arduino site. If you have different necessity and want to carry on with you're methods you need to specify in more depth the connections you have made. As for now I can guess that the output is being connected to ground or some sort of load and that might be the reason you are seeing a drop out of voltage. But it might be also the case that you're output pin is changing so fast that the multimeter is not capable of reading the high state correctly

As Harry mentioned better to use some communication lines like UART or I2C or SPI.
If you dont have them available then use digital i/os but make sure their pull up and pull down resistors are correctly configured. If it is input just set as pull up and for output set as output pin.
Regards,
Pathik

Please do not repeat what others have already said as it leads to clutter on the site.

First of all, I cannot say if your protocol will work or not since I don't have the details. However, switching protocols will give you the same result. Also, you do not need a transistor for this usage.
The solution is to connect the grounds of the different power sources. Since voltage is relative, having the grounds disconnected will lead one device to think that the voltage is higher/lower than the other one thinks (they have different reference point).

Are you sure one pins is configured as input? If one would be output high and the other output low you basically get a short circuit: from Vcc through the top FET of the high output, through the wire to the other Arduino, and into the lower FET of the low output, and back to ground.
If the short circuit were perfect the voltage would drop to zero, but both FETs have a non-zero resistance, which makes them a voltage divider.
One way to protect your Arduino against this (such a short circuit does damage the I/O circuits!) is to place a 1 kΩ series resistor between the pins. Since an input pin won't draw any current there won't be a voltage drop across the resistor either.
I wouldn't use Harry's I2C, because it's probably too complicated for your needs. (I don't know what data you want to exchange). A simple connection is the UART: one transmit line and one receive line. It's true that the UART is used for the USB communication, but that connection goes via a set of resistors, so that another controller using the bus should be able to override the USB's signals.
If you have a long distance between the Arduino's you'll want RS232 level shifters.

I would suggest sticking a transistor in between - use a layout like http://en.wikipedia.org/wiki/Transistor#/media/File:Transistor_Simple_Circuit_Diagram_with_NPN_Labels.svg (from the wiki page on transistor).
Note that Vout should be connected to the input pin on one arduino, and Vin should connect, via a resistor, to the output pin on the other arduino.
Just to confirm, the labels are reversed from what you will expect them to be.
The 2 resistors can be anything > 1kOhm.
This still depends on the common ground.
Note that common ground may not be a good idea if they are generated from the same power source - I've found ground from two USB ports on the same laptop to be at different levels, so current will flow out from one port, and in the other, probably damaging the laptop, if the two grounds are connected.


text:
How can I execute a shell command?
This page says to run a shell command I need a "proxy code" running on my computer (Linux Ubuntu). What do they mean by this, and how should I make one?

I'm not familiar with the term proxy code, but I'm assuming that it's a piece of code on your computer that acts as a man in the middle.
You cannot directly use Arduino to run a shell command, so you'll need to create a program on your computer that listens to serial and then executes a command.
For the "proxy code" Python would be a good choice because of the pySerial library that plays nicely with Arduino. It seems fairly easy to execute a shell command with Python.
As per the Arduino code, something like this would work good:
setup() {
  Serial.begin(9600);
}

loop() {
  if(state == true) {
    Serial.print('A');
  }
}

Some should direct the Pythonic Side Too


text:
Question regarding powering Arduino through the USB Port
If powering the Arduino (Mega) through the USB port, is a voltage of 5.19VDC acceptable?

Yes, the ATMEGA328 processor will work without any problem, in fact if you go in the power informations section on the datasheet, you will find that the processor can run from a little less of 3V to a maximum of 5.5V.
Just be careful, because the processor works at that power, but the board will need from 5 to 5.5V.

The 5.19V you see, I guess you expect 5.00V, is a combination of power supply tolerance and the tolerance of your voltmeter.
Your voltmeter also has some error, we tend to forget that sometimes.

That's the approximate expected voltage. The Arduino devices are typically powered at 5V, but the chips themselves are rated to work at values lower and higher than 5V.


text:
How to transfer data from Arduino to some software in computer?
My arduino gets some data from sensors and save it into EEPROM. Now, I want that when I connect my arduino to PC there should be a software(like sketch) which can fetch data from arduino's EEPROM processes it and saves it into a file in PC. I am willing to create such a software but how will I then communicate with arduino like Sketch does?

Which part of the EEPROM library and Serial are you having trouble with?

Just use serial communication. Make sure you know which port your Arduino is recognized in your system, make a sketch to send data through Arduino's serial communication and try making a simple Node.js application using serialport package which will receive your data. There is a code sample where you can start from. Just set the port and start receiving data. And that's good, using Node.js you are really close to web tools, so it's easy to migrate your application to web.
It's really simple and you can get it done in a few minutes, even if you have not been introduced to node.
These kind of embedded applications have been accepted by Node.js and there are plenty of robotics projects which use node on the web.
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyACM0", {
  baudrate: 57600
});

Usually Arduino is recognized as ttyACM0 on Unix-based systems.
With this line of code you establish a serial communication with your board.
Going further you can register events like data, which is fired when data comes from Arduino:
// it opens the connection and register an event 'data'
serialPort.on("open", function () {
  console.log('Communication is on!');

  // when your app receives data, this event is fired
  // so you can capture the data and do what you need
  serialPort.on('data', function(data) {
    console.log('data received: ' + data);
  });
});

In this example your app just receives data and log it to your terminal.

You should specify what programming language/compiler/IDE you want to use for the part on your pc.
I would suggest using "Processing" - https://processing.org/ it's a similiar IDE as the arduino IDE and the coding is also a bit similiar. You can use a serial library to receive data from USB/COM port.
Processing has the ability to create a window with graphics. You could read the position of something with your arduino, then send it to 'processing' and it will draw the object on the screen (after a bit of coding).
Guide: https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing

The options that I see:

Via serial - this can either be done wirelessly via Bluetooth serial adapter, or via the standard USB connector. Your program will have to have a way of sending the data - some way to indicate that you want to download the data.
Transfer via ICSP - these are the 2x3 grid of pins on your Arduino. You can download the data, without having to write any code. You will need something like a USBASP - they're cheap. You can download the entire EEPROM, and dissect it once you have it on your computer.

I have a vague recollection that EEPROM may be overwritten when you upload a sketch, so if you want to use serial (the first option), make sure your sketch already knows how to transfer the data before you collect it. This is not a limitation for ICSP.

Or you can set the EESAVE fuse via ISP in order to preserve EEPROM contents when flashing. But really, your sketch should know how to handle the data. A primitive serial interface is easy to write into almost anything.


text:
What do these operators do?
Going through the "timeouts" example of the elapsedMillis library (https://github.com/pfeerick/elapsedMillis) I found the following statement:
digitalWrite(LEDPIN, flashPattern[ledIndex++] ? ledBrightness : !ledBrightness);

flashpattern is an array of boolean variables  (boolean flashPattern[] = { 1,1,1,1,1,1,1,0,1,1,0 };)
ledBrightness is a boolean as well.

What does the "?" and the ":" do there? are these boolean operators?

A ? B : C;

is shorthand for
if(A) {
    B;
} else {
    C;
}

It is not. B and C are not allowed to be statements or blocks, and if is not a valid RHS.

They are the conditional operator. If the expression before the ? is true then the result is the expression before the :, otherwise it is the expression after.

Also known as Ternary Operators http://www.cprogramming.com/reference/operators/ternary-operator.html


text:
Arduino Uno: Pullup Resistor
I have been reading a bit about the internal pullup resistor. I know from past projects in school that resistor themselves are fragile (burnt one by accident due to higher current than was made for).
I have two different Arduino models. One by Intel and rest are standard Arduino Uno.
So I was wondering about safely using the internal pullup resistor on the Arduino Uno. Hence my question is about the internal pullup resistor pinmode; How many pin can you connect to it safely and not overload it?

Each pin has its own, separate, pullup resistor.
I don't believe you can damage it by drawing current from the port, because the pullup resistor is only active when the port is in high impedance (hi-Z, input) mode.
The pullup resistor can be damaged by overvoltage, static discharge, and the like.
The Uno has 20 kOhm pullup resistors according to this tutorial. If you feed it a 0V signal while the Atmega is running at 5V, the current will be a quarter of a milliamp, which is miniscule.

The question was pretty much are there only one internal pullup resistor for all pin? If so is there any dangerous of overlord with so many connections. But apparently not if each pin has it's own resistor.

Yes, to clarify: They are separate resistors, with approximately the same value (~20 kOhm on the Atmega328/Arduino Uno).


text:
How to reduce current from a AC TO DC power supply for arduino use
I have a AC to DC converter that was originally used for recharging the PSP, I stripped the 2 wires of the output and was wanting to use it for my arduino instead of using a 9V battery, it's output is 5V 2000MA, is there a way to reduce the current in order to use it for the arduino and im guessing the 5V is enough to power it...right? Im kinda new to electronics and the arduino so any help is much appreciated :D.
Thanks,
Liam.

See this question on EE.SE, it should clear up some of your confusion.

You don't need to reduce the current.
2000MA (2 amps) means the power supply is CAPABLE of supplying this (without overheating). Anything less than this, and your device will work perfectly.
Your Arduino will DRAW a certain number of milliamps (amps), this is the amount of current that will ACTUALLY run through your circuit.


text:
Accelerometer readings on a moving object
I hope this stack is the right place for this question.
I have an accelerometer mounted securely on a swaying object -lets say a stick or pole-
this object is swinging back and forth in small angles (+- 20) with a frequency of about 2-3 times a second.
Im using the accelerometer output to calculate the tilt of the object, however since the frequency of the swings is relatively high the accelerometer readings are very high as well, and not reliable for calculating the tilt.
from my research i have seen that accelerometers work best in a stable environment.
Is there any way to improve the reliability of my accelerometer output in this setup?

Is the pole tilt the value, which you want to measure? Or could be the accelerometer placed on some base, where the pole is attached, measure the tilt of the base and have another sensor (like potentiometer) set to measure the tilt between the base and the pole?

You will probably need to model the physics of the system, establish what can be known (for example, length of the stick) and characterize the cause of the oscillation, (restoring force, stiffness, etc).  Then you need to consider the time-domain performance of the accelerometer.  From that you can probably get enough information about what is actually happening to fit your model in real time, and from that deduce the angle.  Or you could measure it externally.  At any rate, this is not an Arduino question - first it is an issue of definition, then physics, finally more general engineering.

Use a faster output accelerometer? I'm regularly using ones with 2 kHz or faster output rates.

@andrew That actually did help improve accuracy

I'm voting to close this old abandoned question as off-topic because it is about physics, not Arduino

A few things to consider.
First. An accelerometer isn't that great here. Low output frequency is one issue. Noise is another. A pot or an optical encoder would be better.
Secondly. Even if output frequency isn't an issue. You will need some sophisticated math to reconstruct the instantaneous tilt, as the measurements are essentially a sine function, but with an acceleration away from the center of the rotation.  Getting to the max tilt is easier mathematically.
Just for starters.


text:
String to float on Arduino
I'm trying to convert a String to a float but I'm running into issues with precision, even with the Arduino's own String example I'm getting bad results.
Example 0:
Input string: 1.234567  After conversion to float: 1.2345669
Example 1:
Input string: 60.123456 After conversion to float: 60.1234512
Example 2:
Input string: 9.876543  After conversion to float:9.8765430
Why is this happening and how do I get rid of this?

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes.
In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits).
Only for e.g. Arduino Due: You can use doubles instead, see https://www.arduino.cc/reference/en/language/variables/data-types/double/
You might check for the strtod function, but I'm not sure if it is handled by the Arduino:
https://www.techonthenet.com/c_language/standard_library_functions/stdlib_h/strtod.php
If this doesn't work, you can use a function to split the '.' and process the left/right part to convert to an unsigned long and combine it together. But if there are exponential and minus signs involved it might get more difficult.

A float is 32 bits. On AVR boards, double is just a synonym of float.

@EdgarBonet Thanks for that remark, I updated my answer (Only for Arduino Due).

There are two issues at play here:
1 – Limited precision of the float data type
A float has a precision of roughly 10−7, and any number that
is not an exact float is supposed to be rounded to the nearest float.
For example, the two floats closest to 1.234567 are
10356298 × 2−23 = 1.2345669269561767578125 and
10356299 × 2−23 = 1.23456704616546630859375.
The latter is the closest.
2 – Naive string to float implementation in the Arduino core
The Arduino core aims at being small and consume few resources.
Sometimes it cuts corners, at the cost of accuracy. In this case,
although a correct implementation is supposed to round 1.234567 up,
because the nearest float is above that number, the actual
implementation ends up rounding down. Thus you end up with roughly
1.234566927, which is off by 0.61 ULPs (units of the last place), instead
of the expected error of 0.39 ULPs.

It seems that I must convert to string first then use atof.

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


text:
'crash' when using pin change interrupts
I'm noticing a crash when testing out some interrupt code for a project I'm working on.
I've returned to the example provided with the library PciManager and I'm still experiencing the same issue. There doesn't appear to be any patten to when the crash appears, and on occasion I've been playing for several minutes and not seen a crash. NOTE I had to add a file (Task.h) from the developers other project (SoftTimer) to get it to compile.
here is the code:
#include <PciManager.h>
#include <PciListenerImp.h>

#define INPUT_PIN 3

PciListenerImp listener(INPUT_PIN, onPinChange);

int i = 0;

void setup() {
  Serial.begin(9600);
  PciManager.registerListener(INPUT_PIN, &listener);
  Serial.println("Ready.");

}

void onPinChange(byte changeKind) {
  i++;
  Serial.print("pci : ");
  Serial.print(i);
  Serial.print(" : ");
  Serial.println(changeKind);
}

void loop() { }

I have a wire connected to pin 3 and 3.3v which I'm pulling out and then connecting again. Some times when disconnected it continually interrupts, I was expecting this. Sometimes it doesn't which I found strange, the crash appears to happen more in the latter case.
Here is a trace from the serial monitor
Ready.
pci : 1 : 0
pci : 2 : 1
pci : 3 : 0
pci : 4 : 1
pci : 5 : 0
pci : 6 : 1
pci : 7 : 0
pci : 8 : 1
pci : 9 : 0
pci : 10 : 1
pci : 11 : 0
pci : 12 : 1
pci : 13 : 0
pci : 14 : 1
pci : 15 : 0
pci : 16 : 1
pci : 17 : 0
pci : 18 : 1
pci : 19 : 0
pci : 20 : 1
pci :

I've run this on a shrimp and on a freeduino diecimila compatible board both resulting in the same effect.
Anyway down to question; is the issue the way I'm interrupting? i.e. not stopping the floating pin? or is it a problem with the library, or is it a fundamental problem with pin change interrupts.

Your onPinChange() function is called with interrupts disabled.
For you what it means is this function should:

last as short as possible (because NO interrupts are handled during its execution, that includes timers that are used by several Arduino core libraries)
not use Serial functions as these functions are slow and sometimes wait on interrupts (that could thus mean wait forever)

You can read further advice about these so-called Interrupt Service Routines (ISR) here and there.
If you want to trace all calls to onPinChange() then you will have to use some kind of circular buffer as a global volatile variable, which will be written into by onPinChange() and read from by loop().
Accessing that buffer from loop() should be protected against concurrent write by ISR.
Here is sample code I have just written (disclaimer, I have not checked that it compiles but I think it should work correctly) that uses such a circular buffer as described above, and ensures all shared variables accesses are protected against concurrent write by ISR:
#include <PciManager.h>
#include <PciListenerImp.h>

// Structures and function to manage circular buffer of changes
struct Change {
    int i;
    byte kind;
};

// We allow max SIZE changes in the buffer; if onPinChange() is called more often
// than loop(), then at one time the buffer will be overwritten.
const int SIZE = 100;
volatile Change changes[SIZE];
volatile int start = 0;
volatile int end = 0;

// Get the next change recorded by onPinChange()
Change* nextChange() {
    static Change change;
    Change* result = 0;
    // Disable interrupts as we are accessing variables modified by onPinChange
    cli();
    if (start != end) {
        change = changes[start];
        start = (start + 1) % SIZE;
        result = &change;
    }
    // Re-enable interrupts before leaving the function
    sei();
    return result;
}

#define INPUT_PIN 3

PciListenerImp listener(INPUT_PIN, onPinChange);

// No change necessary in setup()
void setup() {
    Serial.begin(9600);
    PciManager.registerListener(INPUT_PIN, &listener);
    Serial.println(Ready.);
}

void loop() {
    // Get the next change recorded by onPinChange (if any)
    Change* change = nextChange();
    if (change != 0) {
        // One change occurred since last time, trace it to Serial
        Serial.print("pci : ");
        Serial.print(change->i);
        Serial.print(" : ");
        Serial.println(change->kind);
    }
}

void onPinChange(byte changeKind) {
    // i does not have to be visible outside this function
    static int i = 0;
    i++;
    // Write information to the end of the circular buffer
    Change& change = changes[end];
    change.i = i;
    change.kind = changeKind;
    // Prepare for the next call (write to the next item of the buffer)
    end = (end + 1) % SIZE;
}

Using Serial.print inside the ISR did cause crashes on my latest project too. By setting the baudrate to a higher value (Serial.begin(115200)), the number of crashes was reduced to almost zero.

@Gerben, yes increasing baud rate will make crashes appear less often, but they still can appear, as 115200 bps means that one character will need ~0.1ms to be transmitted, that's 1600 clock cycles on an UNO, just for one character! Really, I always stay away from Serial in ISR, whatever baud rate I use!

Just so o understand properly it's calling onPinChange while it's executing the code in onpinchange

I'm going to include this answer even though I think there's a very little chance that it is the problem because I just wasted ten hours on a project before finding it and it's an easy check so it won't take much time either way.
On AVR chips, if you have enabled interrupts and one occurs and you don't have an ISR for it, it will call the default ISR which resets the board. You can test if this is happening by redefining the default ISR by creating a function ISR(BADISR_vect){};  I would put a serial print in there and run it again and see if it's happening. If you don't want to do serial (for obvious reasons) just toggle an LED.
I also agree it's probably a bad idea to be doing this on a floating pin. I'd use the internal pull-up resister to keep it high then connect a wire between that pin and ground to simulate a button.

I just spent the last 8 hours trying to figure this out.  Thanks for preventing me from turning that into 16 hours.

Note that disconnecting a wire on an input pin is also not going to give you the results you expect. A disconnected input pin's value will float, and you'll get a semi-random mixture of 1s and 0s. You should either connect an external pull-up/pull-down resistor, or activate the internal pull-up resistor when you configure the pin (by setting the pin to INPUT_PULLUP).
I prefer using INPUT_PULLUP, since that saves wiring an external resistor. Use INPUT_PULLUP, then wire the pin through a pushbutton switch to ground.
Then look for a high-to-low transition on the pin to signify a button press.

Right, floating inputs have undeterministic values that can change all the time; in addition, they draw more energy due to these fast changes.

As I said in the question when it bounced round all over the place it didn't crash as much; recording thousands of interrupts when it didn't bounce it was more likely to crash like after 20 in the listing provided. I know I need pull it up or down I'm just confused by the crash.

Just realised I added extra debugging in after a crash so probably made my problem worse

Don't use Serial commands in an interrupt service routine, even for debugging. It will hang your device.

authors: Филипп Цветков


text:
Arduino Wifi Shield with monitor mode ( promiscuous mode )
Is there a WiFi Shield or driver that supports monitor mode and receiving raw packets ?

What is it that you're specifically that you want to achieve and what research have you done on this already?

I want to capture probe requests packets essentially.

I'd like to do something similar and have yet to arrive at an Arduino-based solution. Here's some resources I've found useful in learning about this topic. http://security.stackexchange.com/questions/54062/how-to-detect-the-hello-packets-sent-by-a-wifi-enabled-smartphone
http://www.engr.uic.edu/pub/Bits/Musa/musa-eriksson-sensys12.pdf

Does it have to be a shield?
I would consider buying a cheap Wi-Fi router instead with good open-source support and a way to interface it to the Arduino. Their price is near to the price of Wi-Fi shields.

They consume little power, can be powered by 5V and have built in Wi-Fi.
Some have a built-in USB port, most have a serial port, which can be used to talk to the Arduino.
You would have to put custom firmware on it, plus the program which receives the raw packets for you.

Specifically, I would get a TP-Link TL-WR703ND for this task.

It can be fed 5 Volts, or 3.3 Volts with a little hacking
It has USB
It also has serial, and you can even hack an I2C port onto it
It can run OpenWRT

More info on this particular router

You actually gave me a nice idea. Could I plug a 3G modem in the usb port and send the packets over the air?

Most certainly. On the OpenWRT website you can find instructions on getting the USB modem to work. You can use a hub to plug both the Arduino and the USB modem into the router. But beware that most USB modems communicate using serial-over-USB, so it's easy to mix up the two devices (because Arduinos also do and you will only see two serial ports, numbered by the order they were detected by the system). Also you may have to install the kernel module(s) for the USB/serial chip of the Arduino.

If this question is still open, I can also suggest using an ESP8266 board. It's a small board with a WiFi-enabled CPU, flash memory and an antenna - so it can be programmed and it can run without the Arduino. It supports promiscuous mode, so I think probe packets can also be captured. Also, it costs less than $4. (It came out in late 2014, about the time you asked the question)


text:
What is this component? (range finder)
I've taken apart an old range finder (see photo here). It uses a circular, seemingly gold-plated, two-wire sensor that I'd like to re-use in an Arduino project.
I'm looking for a datasheet of the sensor and/or a circuit-diagram. Any help is welcome.

The big circular parts likely is ultrasonic transducer as used in instant camera.
http://www.uoxray.uoregon.edu/polamod/
https://www.google.com/?gws_rd=ssl#q=polaroid+ultrasonic+ranging+module&revid=399558007&safe=off
Working principle is same as modern unit, easily available at a few US dollars. The transducer does NOT work by itself, needs the associate PCB to work.

Thanks! This got me going. The first link provided shows pictures of the exact same component.


text:
Does not name a type error when using makeTime
I am getting a "does not name a type" error when trying to use makeTime() from the Time.h library, code snippet as follows:
#include<Time.h>

tmElements_t tmet;
tmet.Year = 2013-1970;
tmet.Month = 8;
tmet.Day = 28;
tmet.Hour = 18;
tmet.Minute = 30;
tmet.Second = 0;

time_t dateMet = makeTime(tmet);

Alternatively I've also tried time_t dateMet = maketime(&tmet); with the same result. I am no expert so go easy on me but am I missing something small here?
Thanks

You're trying to access the 'properties' (i.e. the members) of the tmet variable in a scope where they aren't accessible (outside of a code block). In this global scope of the program the compiler expects a type name on the left side of a statement (i.e. a variable or type declaration), but tmet's members like tmet.Year aren't types in and of themselves.
There are two solutions. You can move the access to the members of tmet into a code block like the setup function:
#include <Time.h>

tmElements_t tmet;
time_t dateMet;

void setup() {
  // put your setup code here, to run once:
    tmet.Year = 2013-1970;
    tmet.Month = 8;
    tmet.Day = 28;
    tmet.Hour = 18;
    tmet.Minute = 30;
    tmet.Second = 0;

    dateMet = makeTime(tmet);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Or you could declare and define tmet in one statement, which has a different syntax (since you have to provide the content of a tmElements_t in a single line:
#include <Time.h>

tmElements_t tmet2 = { 2013-1970, 8, 28, 18, 30, 0 };

time_t dateMet2 = makeTime(tmet2);

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:

}

Both versions work right away from within the Arduino IDE (i.e. I tested them).


text:
How does Arduino IDE for OSX work without drivers?
My Arduino IDE works right out of the box without me having to install any USB to UART drivers. I know the Atmega16U2 on the UNO is acting as UART bridge, but this means that OSX recognizes it on a hardware level, which doesn't make sense since no drivers were installed - unless there is some sort of standard here that the Atmega16U2 implements?
The reason why I ask this is that I have a project where I want to connect an ATMega328p to a client mac which may not have access to 3rd party drivers, so having serial work natively with screen would be ideal. If the Arduino IDE can implement serial monitor without any additional drivers then it means I can too.
Does anyone know how this is implemented?
Thanks!

Sounds luke you want a CDC/ACM implementation.  Maybe you can meet your goal with just a 32u4, leonardo style?  There are lots of Arm parts with built in USB too.  Or you can do it the same way an Uno does.

Windows 8.1 is the last version of any common desktop system that requires CDC/ACM (that is what the Arduino's USB port is) drivers.
OS X is based on BSD which, like Linux, has had CDC/ACM drivers built in since (pretty much) the dawn of time. It is only really Windows that has had the concept of drivers for anything that isn't vendor specific and/or complex (such as video cards, or devices that don't adhere to published standards).
Even Windows 10 now has the drivers for CDC/ACM built in (it's only taken Microsoft 20 years or so to catch up with the rest of the OS world).


text:
How do I convert a float into char*?
Asked this question on Electrical Engineering Stack Exchange and was directed here:
Pretty self explanatory; how would I go about converting a float into a char*? I have code in which the float 'resistance' is constantly being updated. I would like to be able to update the variable 'result' to take the value of 'resistance'. Here is some of the code, in case it helps:
const char * result = "";
float resistance = 2.5;

result = resistance; //This bit (obviously) doesn't work

Thanks for your help!

There is a function in the standard Arduino library called dtostrf(). I think of it as "Decimal to String Float". You pass in the float, how wide you want the whole number to be (if it will fit), the number of decimals of precision - and the buffer you want it to fill.
Note that! You need to provide the buffer, and you need to be careful to provide more than enough! Don't forget to add 1, too (to store the NUL character at the end):
char result[8]; // Buffer big enough for 7-character float
dtostrf(resistance, 6, 2, result); // Leave room for too large numbers!

This will give result values like "  1.23" and " -1.23" and "123456789" (without the quotes). Note the last example - it won't truncate the number if it's too large, and that 10- character result (don't forget the final NUL) just overflowed your buffer...
Incidentally, if you specify a negative width, it won't right-justify the answer, it'll left-justify it (put any spaces on the end instead of the beginning).

Did the trick nicely! Thank you very much kind sir :)


text:
Arduino as a custom I2C slave device
I'm trying to interface with a master I2C device that doesn't exactly follow the normal I2C protocol.
The only difference really is in the read request. A "normal" I2C read operation looks like this ([M]aster, [S]lave):
S | SLA+R | ACK | Data | Ack | Data ...some number of bytes... Nack | P
^M  ^M      ^S    ^S     ^M    ^S                              ^M     ^M

But this device expects to do a read like this:
S | SLA+R | ACK | Data | Ack | Data | Ack | Data | Ack | P
^M  ^M      ^S    ^M     ^S    ^S     ^M    ^S     ^M    ^M

Essentially a read request goes to the slave device, and then the master sends an 8-bit register address, and then the master expects 2 data bytes back from the slave with the Master responding with an ACK on both.
I've been able to set up a master device to do this style of protocol pretty easily by just manipulating the I2C registers directly. But I can't seem to find a way to get the slave device to accept that it is going to receive a data byte after it has been selected by a SLA+R, which leads to a bus contention problem and the slave not giving the master an ACK.
Is this possible to do with the built in I2C hardware on the Atmel chips? Is there any alternative if it can't (bit-banging)?

with a master I2C device - what device?

Are you writing the code for both ends? Master and slave?

I'm missing something on the bus operation. Pretty much whenever I get NAK'd I know I need to redo the operation. On the i2c bus it should be an ACK'd or NAK'd on every byte.
Usually you send the address of the device then the command. So the master initially sends the address, which is ACK'd and then the master sends the command that it wants executed. Your diagram has the slave answering when it's the master that's required to give it an operation?
Here's a good document on it... :)
Philips I2C Document


text:
Arduino Serial library (Synchronous or Asynchronous?)
On an Arduino 101, I have this code running:
void setup()
{
 pinMode(2, INPUT);
 Serial.begin(9600);
}

int counter = 0;

void loop()
{
 Serial.print(millis()/1000);
 Serial.print("\t");
 Serial.print(counter);
 Serial.print("\t");
 Serial.println(digitalRead(2));
 counter++;
}

A wire can be used to jump Pin2 between 3.3V and GND.
When running with the Serial Monitor on, I see the values increment at a rate where counter increases by the hundreds very quickly and steadily ticks through the thousands over time.
If I close Serial Monitor momentarily and re-open it, I notice that this counter value has increased dramatically (by the tens-of-thousands).  Another sign of this is when starting the program and waiting a moment to start the Serial Monitor.  As the Arduino 101 does not restart when the Serial Monitor is opened, I see a large initial value in the tens of thousands despite having just started the program.
My question is this: is the Serial library operating synchronously or asynchronously? I was led to believe that it was asynchronous; however, if that was the case, why should the Arduino execute any slower when the serial monitor is on?
While I understand that increasing baud rate will increase the speed at which counter increases, I still see the same dramatic increase in this code when the monitor is closed and then re-opened.
Another possibility I thought of was that maybe counter was being stored in a buffer and what I was seeing was not an up-to-date time or count.  To check this, the program prints the digitalRead value of pin2 as I swap the jumper between 3.3v and GND. This change in value was reflected instantaneously on the Serial Monitor, and I believe this means I am not seeing past data slowly being printed out to the monitor.
One last attempt at understanding what was going on was executing this code:
void setup()
{
 pinMode(2, INPUT);
 Serial.begin(9600);
}

int counter = 0;

void loop()
{
counter++;
if (counter%1000==0)
 {
  Serial.println(counter);
 }

In this example, counter can be seen ticking through quite fast, by the hundreds of thousands, which indicates that the program is capable of running very quickly until a print statement is made. The effect is notably less when baud rate is increased to something like 115200 but is that saying that baud rate is literally slowing the processing speed of the controller?
Any kind of explanation as to what exactly is going on would be very appreciated.
Thank You for your Time.
Source of Arduino being supposedly Asynchronous:
https://itp.nyu.edu/physcomp/lessons/serial-communication/serial-communication-the-basics/

The Arduno 101 doesn't communicate to the PC using a UART. It uses CDC/ACM over USB, which looks like a UART to the PC.  But it isn't.

USB sends packets of data, not individual characters
It only sends if there is something to receive it at the other end
There is no such thing as baud rate with USB.

Basically, when the CDC/ACM port has been opened by an application (e.g., the serial monitor) the Arduino 101 starts to send the data down the line. When the port is closed all data to be sent gets silently dropped by the Arduino since there is nowhere to send it to.
Hence when the port is closed it runs much faster since the data that would normally have to be packed into packets and sent down USB isn't. It's just thrown away.

To address your confusion:
You are misunderstanding the concept of synchronous and asynchronous with regards to serial. There are basically two types of serial communication: Asynchronous, where both ends have to (pretty precisely) agree on the speed of communication (baud rate), and synchronous, where one end tells the other end what the speed is by providing a discrete clock signal. UART (RS-232, RS-485, etc) is asynchronous. It sends at a specific rate and has to rigidly stick to that rate for the other end to be able to receive it properly.  SPI and I2C are synchronous - they both (as master) provide a clock signal to the receiving end (slave) and the receiver synchronises its reading and writing of data with that clock signal (hence synchronous).
You are confusing those concepts with another meaning of synchronous and asynchronous - terms that could better be used would be parallel and sequential processing. If something happens in parallel then two (or more) things happen at once. This is the case of the hardware UART where you submit characters to be sent to the buffer and they get transmitted out by the hardware separately to the sketch - in parallel. Sequential would mean that one thing has to happen after the other. If the UART behaved like that your program would stall every time you wanted to send a single character.
So UART processing happens in the background, in parallel to your sketch. So does USB data processing for CDC/ACM. These things are generally coupled with interrupts to allow the CPU to handle tasks such as placing more data in the buffer or storing data that has arrived somewhere that you can get to it.  Interrupts aren't strictly parallel, in that they do stall your program while they run, but they are kind of in a different thread, or context. So they appear to be parallel.

Your explanation of the CDC/ACM being the cause makes alot of sense but from what I'm seeing, adjusting the baud rate in the program makes quite a difference in the rate at which information is displayed.  Do you have any explanation as to why this has an effect? Are the packets simply being filled with more information before they're sent at some other rate?

Maybe the 101 is doing some artificial throttling to make it seem like the baud rate is real. Who knows? Baud rate is meaningless (normally) though since the USB runs at a constant rate. The baud rate setting is only (normally) used to configure whatever device is at the end of the USB connection - e.g., if the data is being forwarded on to a real UART output it would configure that UART output for the requested baud rate.

The Universal asynchronous receiver/transmitter (UART) is a chip that control the actual wires for serial communication. The UART operates independently and asynchronously.
As far as I know the UART (or USART) has a buffer, and the serial.print* functions will write to this buffer, and if it is full will block until the buffer has room. The UART will consume the buffer and transmit it over the wire. So your code will run full speed until the buffer is full then it will have to wait for the UART to make space.

... but is that saying that baud rate is literally slowing the processing speed of the controller?

When the UART's buffer becomes full, the Serial API has no choice but to wait for the buffer to empty so it can fill it again. This makes it appear as if the code is running synchronously; waiting on the buffer is essentially acting as a synchronization device. So yes a slow baud rate can slow the micro-controller down since the code is forced to wait for the UART even though it is asynchronous!
You may not notice any of the above effects, since even 9600, a relatively slow rate, is much faster than humans can read. 300 baud is approximately the rate at which humans can read comfortlably. If you repeat your experiments with a higher baud rate you should see the text fly past on the serial monitor much faster than at 9600; if you lower the speed to 300 (the lowest supported by the library) you should be able to read along, and see that things do go slower. The buffer on the UART is rather small, and even when slowing down to 300 baud, it might be difficult to see the buffering behavior.
When the serial monitor is closed the serial communications are still happening, the UART on the receiving side is receiving the data, but it gets dropped on the floor since no one is reading it. If you were to disconnect the serial wires at some point this should stall the sending UART which should cause the serial.print* functions to block (alternatively the UART could be configured to drop the data if it can't physically transmit it over the wire.)

I went ahead and tried setting baud rate to 300 as you suggested.  It is more than easily legible; however, I still find that moving between 3.3V and GND, the change is instantaneous. With that being said, I do agree that baud rate does seem to affect the rate at which the microcontroller runs as counter's increase is dramatically slowed. So in short, I don't think there's a buffer being filled and drained but instead maybe the baud rate effects the timing for how long the Arduino waits while in the Serial.print() statement.


text:
How do I use an AtTiny85 (or other AtTiny) with Arduino?
Please mind that this is an "example" question.
How to make a "tiny arduino"?
I've ordered a bunch of ATtiny85's off E-bay, they're like tiny Arduino's.
I've set up the latest Arduino IDE and would like to run the blink example.
My process so far:
Wiring

Code
(The blink example)
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

1. The Tiny
The ATtiny differs a little from the Arduino, don't expect it to be "fully compatible". It's a microcontroller which is just a part of an Arduino and not a full Arduino itself.
It's more of a device for "advanced users" and gives some more flexibility (at cost of usability). You can easily add this microcontroller on a breadboard, since putting a full Arduino on a breadboard makes little sense.
1.1 USB?
Since the ATtiny is a microcontroller (like the ATmega on an Arduino) and not a development board (as an Arduino), it does not have an USB connector.
The ATtiny series also does not have hardwareUART (Rx/Tx). The
You'll have to take care for a steady power-supply to your Microcontroller and the programming will be a little more tricky (details further below).
It is however possible to use SoftwareSerial and a customized bootloader. My ATtiny85 runs software serial with 115200 fine, though I have found a post which states that the internal oscillator should be tuned for a reliable connection.
1.2 RAM/program memory
The ATtiny has less RAM and program memory. This essentially means your program can't be as 'big' as on a normal Arduino. It also means that you can't use as much variables. A program for the tiny should be "small" or very efficient.
1.3 "Speed"
My ATtiny came with 1Mhz internal clock set, but if you change the fuse bits you can make it run at 8Mhz. An standard Arduino has a 16Mhz clock on the board. So your code would run 16x slower on default and 2x slower on "max". You could use an external clock for the ATtiny, but that eats up 2 pins.
The cool thing is, when you set it to 1Mhz it can run on about 2.7V (check datasheet first).
Arduino                   16Mhz
ATtiny (standard)         1Mhz
ATtiny (set fuses)        8Mhz
ATtiny (external crystal) up to 20Mhz

Higher Mhz is faster. Keep in mind that 1Mhz is roughly 1000000 instructions per second, which is still blazingly fast and good enough for most occasions, especially on such a tiny device.
2. Programming the Tiny
Most of the ATtiny's don't come with a customized (software serial) Arduino bootloader. This essentially means that you have to burn a custom bootloader by yourself or use another type of programmer. You should really watch the video from Ben Heck. He explains that Arduino boards have an USB converter on board and have custom code that is able to "bootload" your Arduino. But that ICSP/ISP programmers are used to upload programs without a bootloader/uart connection.
2.1 The programmer
You've got a load of options, check the "Programmer" item in the "tools" tab in your Arduino IDE. I'm using an USBasp which can be bought on ebay for as little as 3€. You should get one that has a selectable voltage (3.3V and 5V).
(If your ATtiny85 already has the bootloader, which is unlikely, you can use the software rx/tx pins for uploading)
2.2 Preparation
Check your microcontroller if it really is a ATtiny85 my E-bay reseller actually had one ATtiny45 included, which lead to an "error" when trying to upload.
The Arduino IDE does not know the "ATtiny board" so you can't select it easily. You'll have to let the IDE know that the ATtiny can also be programmed.
I found a very nice tutorial that describes how to do this.

Open the preferences dialog in the Arduino software. Find the
  “Additional Boards Manager URLs” field near the bottom of the dialog.
Paste the following URL into the field (use a comma to separate it from any URLs you’ve already added):
  https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
Click the OK button to save your updated preferences.
Open the boards manager in the “Tools > Board” menu.
Scroll to the bottom of the list; you should see an entry for “ATtiny”.
Click on the ATtiny entry. An install button should appear.
Click the install button. The word “installed” should now appear next to the title of the ATtiny entry.
Close the boards manager. You should now see an entry for ATtiny in the “Tools > Board” menu.

2.3 Changing the internal clock
Some interesting post I found told me that you can change the internal clock/oscillator to 8Mhz by selecting 8Mhz (internal) as the clock and pressing the "Burn bootloader" button. This won't flash a bootloader (since that makes little sense on a Tiny85) but does change the fuse-bits.
2.4 Code
You'll not get away with the standard blink tutorial. It uses digital pin 13 (the tiny only has 8 pins).
Mind that you might have to upload using Ctrl+Shift+U (or sketch->Upload with programmer).
I used the diagram below to check the pins (from highlowtech.org)

3. Hardware
Your "schematic" isn't complete, I don't see a way to program or power the microcontroller. And you might want to take some precautions.
I personally think a well-drawn schematic looks better as a "breadboard view".

The 10Kohm pull-up resistor on the reset pin is not 100% neccesary according to the datasheet. But the Uno has one in it's reference design (which I use as a reference).
There are two capacitors, one "big" capacitor as a reservoir. If one device suddenly pulls a lot of current, this capacitor will handle that. The smaller decoupling capacitor will damp the noise of other IC's or switching supplies. It may work withouth these, but your circuit will be more reliable with them.
Mind that the decoupling capacitor should be (physically) close to the IC.
You can power the board through the programming header, but mind that you'll need a smooth voltage between (most likely) 3.3V and 5V. If you want to power it with a bigger voltage (9V battery) then you'll need a voltage regulator.

Many of your "you can't" claims with regard to serial and USB are incorrect - there is no hardware support, but both regularly done with software implementations, including for bootloader use.  It's not clear that an incomplete presentation in the necessarily limited form of an answer here is doing people a favor when there are much more developed presentations elsewhere that could be pointed to instead.  Stackexchange does not exist to duplicate the web over again...

@ChrisStratton I've updated the statements, I must agree that they were atleast half-true, since uploading the "custom bootloader" also takes an other type of programmer. I've combined (and referred to) multiple sources which can be of great ease. Another point is that someone who is relatively new can easily find all the important info on one page, and more details if they look a little further.

@ChrisStratton I've made the post "community wiki" so that everyone can contribute (I won't get points for upvotes). I believe it would be better if everyone (who wants to research ATtiny's) can contribute to an open "reference" or "starter guide". Which would work better as everyone creating their own blog ;)


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

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

SREG = oldSREG;

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

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

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

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

Correct. That is known as a critical section.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
RGB Led - mixing colors using analogWrite
Currently I'm controlling an RGB LED with my Arduino Nano.
I'm mixing the colors using analogWrite
Though, the LED's don't light up at all for low analogwrite values and the difference between the levels is not visible (to me).
I'm using 100 Ohms resistors between the LED's, using a 680Ohms didn't seem to make a difference.
Analogwrite is working by toggling the LED's fast (PWM)? So not by lowering voltage? This is why I think it's weird that they don't light up at all, on low write values.
My sketch below:
#include <SoftwareSerial.h>

int r, g, b = 0;
String command = "";
const byte rxPin = 11;
const byte txPin = 10;

SoftwareSerial blueTooth (rxPin, txPin);

void handleCommand() {
  r = rgbFromCommand("r=",";");
  g = rgbFromCommand("g=",";");
  b = rgbFromCommand("b=",";");

  if(r != -1){
    analogWrite(A2,r);
  }
  if(g != -1){
    analogWrite(A1,g);
  }
  if(b != -1){
    analogWrite(A0,b);
  }
}

int rgbFromCommand(String prefix, String postfix) {
  int idx = command.indexOf(prefix);
  int endIdx = command.indexOf(postfix,idx);
  if(idx>=0 && endIdx>=0){
    idx+=2;
    return command.substring(idx,endIdx).toInt();
  }
  return -1;
}

void setup() {
  pinMode(rxPin,INPUT);
  pinMode(txPin,OUTPUT);
  Serial.begin(9600);
  blueTooth.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    char incomingByte = Serial.read();

    if(incomingByte == '\n'){
      handleCommand();
      command = "";
    }else{
      command += incomingByte;
    }
  }
  if(blueTooth.available() > 0){
        // read the incoming byte:
    char incomingByte = blueTooth.read();

    if(incomingByte == '\n'){
      handleCommand();
      command = "";
    }else{
      command += incomingByte;
    }
  }
}

Analog pins aren't PWM pins. Instead you have to use the pins marked with a ~
Pins that aren't PWM pins will be off with a value of 0-127 and on with a value between 128 and 255.

Ah, analogWrite and analog pin caused the confusion!
Also, I find it rather weird that it doesn't cause (atleast) a warning.
I'm using an Arduino Nano, and the silkscreen on it is also rather unreadable. I thought it could be the resolution of the analogWrite, as it did work in native C++ (because I did use the hardware PWM and pins (as at that point it made sense to read the datasheet ;) ))

Yup, found the right pins, now works like a charm (https://www.youtube.com/watch?v=iJPvMaQH3D4) many thanks!


text:
Running a function in the background continuously
I have a keypad which is connected to arduino (with one analog pin).In the arduino code, I have created a circular queue which stores the inputs by pressing on keypad. Now when a key is pressed on keypad, it is stored as the first element in the queue. If an another key is pressed, it is stored as second element in the queue until is queue is full.(The keypad pins are connected using a voltage divider for each pin, so each and every key pressed on keypad will be recognized by arduino based on voltage for the key. The keys and voltages are stored in an array, as follows):
int keyboardPin = 0;    // analog pin to which keypad is connected
int keyboardValue = 0;  // Initial reading of analog pin 0 (A0) (it is zero as no key is pressed initially)
char keypad[16] = {'1','2','3','4','5','6','7','8','9'};
int treshold[16] = {590,568,548,426,415,404,334,326,320}; // Volatge values corresponding to each pin
int front=0,rear=0,size=6; // implementing circular queue using array
char cQueue[6];
int speed = 6,timer=0;
void setup(){
  cQueue[0] = '1'; // the first element of queue is '1' by default at the start
}
void loop(){
  keyboardValue = analogRead(keyboardPin); // Reading the value from A0 when key is pressed
  while(keyboardValue > 5) {  // Runs when a key is pressed
    for(int i=0;i<8;i++){
      if((treshold[i] - keyboardValue) == 0){
        Serial.println(keypad[i]); // Printing the key pressed
        enQueue(keypad[i]); // Storing the key pressed in the queue
        break;
      }
    break;
    } // end of for
  keyboardValue = 0;
  liftStops(cQueue[front+1]);// function to be run in background (front + 1) because  the key pressed by the user should be the argument of function
  break;
  } // end of while
}        // end of loop
int isFull(){  // to check if queue is full
  if( (f1 == r1 + 1) || (f1 == 0 && r1 == stops1-1)) {
  return 1;
}
  return 0;
}
void enQueue(char element){  // adding key pressed to queue
  if(isFull()){
    Serial.println("Lift full");
  }else{
    r1 = (r1 + 1) % stops1;
    qlift1[r1] = element;
  }
}
int deQueue(){  // removing the front element of queue
  char element;
  element = qlift1[f1];
  f1 = (f1 + 1) % stops1;
  return(element);
}

At the start of program, 1st element of queue is loaded with '1' (in setup function). When key is pressed, it is added as 2nd element of the queue.
There is a function which should run in the background as soon as a key is pressed. The function is:
void liftStops(char keyPress){  // defined after the loop() function
  while(timer<100){
    distance = (speed*timer);
    motorClockwise();
    Serial.println(distance);
    if(keyPress == '1' && distance == 0){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '2' && distance == 30){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '3' && distance == 60){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '4' && distance == 90){
      motorStop();
      deQueue();
      return;
    }
    timer = timer+0.167;
    delay(200);
  }
}

The element hold indicated by front variable in the queue is passed as a parameter to the liftStops() function. There is a motor in the circuit and the motorClockwise() rotates motor clockwise,motorStop() will stop the motor.
When the program is run for first time , if I press '2', it is stored as second element in the queue. The function liftStops() starts with '2' as its argument. Now the liftStops() function runs till distance == 30 and motor stops. Now deQueue() function is called and the element indicated by front gets eliminated('1' gets eliminated in the above case). After this,if I press '3', liftStops() runs till distance == 60 and the element indicated by front gets eliminated('2' in this case).
If I press a key when the liftStops() execution didn't finish, nothing is added to queue. I want the liftStops() function to run in background so that each and every key I press at any point of time gets stored in queue and the liftStops() function runs for every element in queue one after another.
Thanks.

If you use millis() instead of delay() (see the Blink Without Delay Arduino tutorial), then you won't need to run anything in the background.

Thanks for the reply. I have tried a lot using millis(), but I couldn't achieve the desired output.

I wrote in a comment to your question:

If you use millis() instead of delay() [...], then you won't need
  to run anything in the background.

and you answered:

I have tried a lot using millis(), but I couldn't achieve the
  desired output.

From this, I assume the real problem is that you haven't tried hard
enough. The general approach is quite simple:

Is there any work that has to be performed right now?

if yes, then just do it
if no, then don't do it

It works as long as you do not have any blocking code in your program.
Especially no calls to delay().
In your particular case, it would seem that liftStops() has work only
when:

timer is less than 100
and it hasn't done useful work during the past 200 ms (that's
the delay(200) in your code, and it's not useful work).

You may try the following:
void liftStops(char keyPress) {

    // Manage the execution timing.
    static uint32_t last_time;
    uint32_t now = millis();
    if (timer >= 100 || now - last_time < 200)
        return;  // nothing to do this time
    last_time = now;

    // Do the actual work.
    distance = (speed*timer);
    motorClockwise();
    Serial.println(distance);
    if(keyPress == '1' && distance == 0){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '2' && distance == 30){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '3' && distance == 60){
      motorStop();
      deQueue();
      return;
    }else if(keyPress == '4' && distance == 90){
      motorStop();
      deQueue();
      return;
    }
    timer = timer+0.167;
}

Just make sure it is called often. I.e. you call it in loop() and you
make sure there is no blocking code elsewhere in your program.

I have solved my problem using attachInterrupt() function.The loop() runs liftStops() continuously and if there is a keyPress, it is recorded by the interrupt.
void setup(){
  attachInterrupt(digitalPinToInterrupt(3), floor1, CHANGE);
}
loop(){
  liftStops();
}
void liftStops(){
  if(qlift1[f1+1] != NULL){
    while(timer<100){
      distance = (speed*timer);
      motorClockwise();
      Serial.println(distance);
      if(qlift1[f1+1] == '1' && distance == 0){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }else if(qlift1[f1+1] == '2' && distance == 30){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }else if(qlift1[f1+1] == '3' && distance == 60){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }else if(qlift1[f1+1] == '4' && distance == 90){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }else if(qlift1[f1+1] == '5' && distance == 120){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }else if(qlift1[f1+1] == '6' && distance == 150){
        motorStop();
        deQueue();
        delay(5000);
        return;
      }
      timer = timer+0.167;
      delay(200);
    }
  }
}
void floor1(){
  keyboardValue = analogRead(keyboardPin);
  while(keyboardValue > 5) {  // Runs when a key is pressed
    for(int i=0;i<8;i++){
      if((treshold[i] - keyboardValue) == 0){
        Serial.println(keypad[i]); // Printing the key pressed
        enQueue(keypad[i]); // Storing the key pressed in the queue
        break;
      }
    break;
    } // end of for
  keyboardValue = 0;
  break;
  } // end of while
}

If any key is pressed during delay(5000) even that gets recorded.

Typically this is done via an interrupt.
The use of an analog keyboard makes that more difficult or less convintional as the detection of a press in the analog sense is more difficult. One way to go is likely to scan the keyboard on a constant rate. But then detecting releases needs to be done creatively.

Thanks for the reply. I think it's easy the other way. The arduino runs the liftStops() function in the background and always checks if any key is pressed,stores it in queue and run the liftStops() for every function in queue.

You probably want to think through it more. The term "background" can be confusing. It generally means a high priority short task that can interrupt other low priority tasks.

Your code has a serial print in it and then delay. That's the sort of things that you should not put in the interrupt.

Obviously the whole thing is moot if you have a different distribution of "background".

Use loop function already provided for repetitive tasks
 void loop() {
 //this itself should be the function which you want keep running
 //check for keystrokes here and handle characters as they are
 //received. For handling characters, you can write a function outside
 //of the main loop which should return control to loop when task is
 //finished
 delay(200);
 }


text:
How do I measure speed and manipulate the speed based on distance covered?
I'm doing a project on arduino. I'm using a online simulator to design the circuit. I have a dc motor. How do we measure the rpm,speed at that rpm,distance covered by the motor in a given time. For example,
When motor starts, it starts rotating slowly and gradually increases it's RPM. When it covered a distance of 50 meters, the motor slows down and stops. After 10 seconds, the motor starts again at that 50 meter point and goes to 100 meters point and stops. Like this it stops for every 50m. For this we need to keep track of the distance travelled by motor and control it's speed.
How do I achieve the above working. I have tried alot and verified many tutorials but couldn't understand what to do. Please help me out.
(The online simulator I'm using has a L293D motor driver, IR sensor and a ultrasonic distance sensor in it's component list.)

Put an encoder on the shaft; this way you will be able to "read" the rotational speed. Whis is linked to the vehicle by a constant. And integrating the speed (summing up) will give you the distance travelled.

Rather than computing and integrating the speed (which amount to computing the integral of a derivative), you just have to count the pulses from the encoder.

@EdgarBonet yes, in fact summing up the "frequencies" that you read is equivalent to counting the pulses... I tend to overcomplicate things ;)

They key point here is to know the distance. The simplest way of finding that distance is to know how many times the wheel has completed an entire revolution. Multiply that number of revolutions by the circumference of your wheel and you have the distance the wheel has covered.
Depending on how precisely you want to measure that distance you may get away with a simple magnet and hall effect sensor. Place the magnet on the wheel, and locate the hall effect sensor so the magnet passes it close enough to trigger. Each pulse from the sensor is one rotation of the wheel.
You could increase the resolution by adding more magnets - 4 magnets set at 90° points around the wheel will give you a pulse for each quarter of a revolution (so multiply pulses by a quarter of your circumference).
If you want better resolution and accuracy you could attach a rotary encoder to the axle of the wheel. This, depending on the encoder, can give you far better resolution than simple magnets. Some will also give you the angle the wheel is at (not that such information would be of interest in this project).


text:
Measuring distance based on time
I have written a arduino sketch which is used to measure the distance travelled. Since distance = speed * time , I have initiated speed = 6. I have initiated time = millis() variable and it calculates the time in millis().
So, distance is calculated as (speed*time) /1000 and we get distance for every second.
Now, as soon as the distance==20, I want to print distance and then delay for 5 seconds. So, as soon as distance==20 implies time = 4000 . If I delay for 5 seconds, time becomes 9000. But I want time to start from 4000 itself. So I have initiated another variable called curTime = time - prevTime.At the start, prevTime = 0. Code:
int prevTime = 0;
void loop(){
  unsigned long time = millis();
  unsigned long curTime = time - prevTime;
  int speed = 6;
  unsigned long distance = (speed * curTime)/1000;
  Serial.println(distance); // displays values of distance
  if(distance == 20){
    Serial.println(distance);
    delay(5000);
    prevTime = time;
  }
}

So prevTime = 4000 if distance == 20.
After this, time will be equal to 9000 and curTime will be 9000-4000 which equal 5000. So the distance will be 30 skipping all the values between 20 and 30. I don't want the distance to skip the values between 20 and 30. I have tried a lot but couldn't achieve it. Please help me fix this.
Thanks.
Link for code:
https://circuits.io/circuits/5260912-the-unnamed-circuit/edit

@JohnnyMopp, Thanks for the reply. Please see the link on how code works.When distance == 20==> prevTime=time ==> prevTime=4000(After delay). Now when curTime is calculated, it's coming as 5000 (since time=9000 and prevTime=4000). But when I keep prevTime = millis(), curTime is started from 0 again. For my output , as soon as distance==20, after the delay, again the distance should get calculated from 21, but in the above code, the distance is skipped to 30.

Thanks for the reply. I tried it earlier, but it didn't work.

This program is not measuring anything. As it stands, it is completely useless, and unlikely to be what you want. Could you please explain clearly what you actually want to do?

When distance == 20 you pause for 5 secs. So all calculations after that will be off by 5 secs. So, prevTime should equal 5000.
unsigned long time = millis();
unsigned long curTime = time - prevTime;    // 0 or 5000
int speed = 6;
unsigned long distance = (speed * curTime) / 1000; // calculating distance in meters for every milli second
Serial.println(distance);
// Only pause once
if (distance == 20 && prevTime == 0) {
  delay(5000);
  prevTime = 5000;  // Adjust for the delay
}


text:
Arduino Mega 2560 not showing up in Serial Port in IDE
I recently purchased an Arduino Mega 2560. As soon as I connected it for the first time with my macbook pro the led was blinking (default blink program). To stop the blinking, I uploaded an empty sketch to Arduino. Now the arduino is not showing up in serial port in any operating system. The LED is constantly on and not blinking. Please help

Are you using the same cable as before?

Yes, using the same cable. Have also tried it with a different cable.

What does the Arduino IDE show for Ports? None?

Did you try:-

Unplugging and reconnecting the board?

or

Holding down the reset button (on the board) during compile and then letting go when the Ide says "Uploading to ..."? (Make sure the sketch has a setup(){} and loop(){} so is not entirely empty)

If that doesn't work then ...

The pin13 on all the time with an empty sketch might indicate a hardware problem. Is anything connected to the board apart from the usb cable? Green LED simply means the board has power unless you are talking about the tx/rx Led's?

for windows users ...

Look in "Control Panel>Device Manager" to see if there is an exclamation mark against any devices, or "Unknown/Other" devices? If you can see the board but it has an error against it look at the properties to see if you can see what the error is. Re-installing the arduino ide will attempt to install the usb drivers again but they can also be found in the \drivers sub folder below the Arduino Ide.
If you can see an entry in control panel but it is not showing in the Arduino Ide try changing the port to a different COM number (right click>properties)
If you can't see anything in Control Panel try a different usb port on your computer.
Is the board connected directly to the pc via usb or via a usb hub? Make sure direct connect. If power externally make sure enough power.

I have tried unplugging and reconnecting the board and also pressing the reset button. As of now, the Green LED is ON and the ORANGE LED at pin 13 is constantly ON.

I've added some more suggestions and questions


text:
What features of the Arduino framework will fail if I use my own infinite loop in favor of the standard loop()?
I have a strong urge to replace the framework-provided loop() function with my own like so:
__attribute__((always_inline)) inline void fastLoop()
{
}

void setup()
{
   // Performing setup here...
   Serial.begin(115200);

   // Now looping
   for(;;)
      fastLoop();
}

This way, my loop is inlined and I'm saving quite a few cycles - avoiding not only Arduino housekeeping costs, but also the function call cost which even for a void function has to be at least 6 cycles on AVR (>=2 for RCALL and 4 for RET).
This is the framework code for calling loop() from main():
for (;;) {
    loop();
    if (serialEventRun) serialEventRun();
}

My question is: what does this serialEvent stuff do? What features of the framework will stop working properly with my own loop?
Assuming my loop has observable side effects as required by the C++ standard, of course (otherwise it can be optimized out).

It depends on which "Arduino" you are running it on.
On an Arduino Uno, for example, then the only thing that won't work is the SerialEvent system. Everything else that matters is interrupts.
Here is main() on the Arduino AVR core:
int main(void)
{
    init();

    initVariant();

#if defined(USBCON)
    USBDevice.attach();
#endif

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}

As you can see, loop() is run just the same way as your fastLoop(), just not inline, and adding in a call to serialEventRun() if it has been defined.
If no serial event handlers have been defined, then it won't do anything there anyway.
To save clock cycles you would get more benefit (as long as you don't want to use millis(), delay(), serial communication, etc) from disabling interrupts.
However, on an ESP32 or ESP8266 you will find that your watchdog times out and resets the unit. This is because it relies on code being run regularly to manage the WiFi connection that keeps "kicking the dog". Without that being run (which can be called by calling the yield() function) the watchdog times out.

I don't see an edit on the question. but your answer looks like you didn't read it to end

@Juraj I had to go eat.


text:
Can burn bootloader but not sketches... thoroughly mystified!
I have a custom board designed to be essentially identical to the Arduino Micro (Atmega32u4). I can burn the bootloader (Caterina) and it burns just fine, including the fade-then-slow LED signal that indicates a successful bootloader burn. However, it does not turn up under USB. What am I doing wrong?

Explain better what you mean with "it does not turn up under USB". Add the details of how you burn the bootloader. Do you compile it yourself? How are you sure that it is flashed correctly? There is too little information in your question.

The bootloader has been burned straight from the Arduino IDE using a USBasp and a Diamex AVR (effectively the same as the MkII programmer). It completes the burn, completes the verification successfully, and uploads the blink sketch. At first run, the first 12 (I think) blinks are slow-fade.
When I then connect the board with a USB cable, it is not listed as under /dev as a tty device and it does not turn up in the Arduino IDE, either.

Oh, and to add to the weirdness: the board powers just fine from USB. It's also not a power issue as I get the same result with a reliable powered hub.

"Custom board essentially the same as" what is the difference?

What does dmesg tell you?

@Paul It has some components directly on its I2C bus. It is no different from an Arduino Micro with two I2C devices wired up to it. The power consumption is at least theoretically ok.

dmesg does nothing.


text:
Negative voltage output Or Controling negative voltage
I've got an RGB led strip I'm trying to control. It's a 12v, 4 pin strip.
Pin layout seems rather odd to me as 1 pin takes 12v of power and 3 pins (that go to ground) control the colors. In other words, the LED colors are controlled by limiting outgoing voltage.

White- +12v
Green- Green in negative voltage
Red - Red in negative voltage
Blue - Blue in negative voltage

I've already made a similar setup that uses n-channel MOSFETS (or at least I think that's what they are) between the colored cables and the ground and Arduino power the MOSFET gates as necessary.
So my question is: is it possible to hook these LEDs up directly to arduino and control the negative voltage without aditional electronics?
As a slightly off topic question: Is there a specific name for elements that are controlled with negative voltages.

By the way, I'm using Arduino nano, although I don't think it is relevant at this point and I've got Mega and Uno aswell if needed.

It seemed weird to me too, at first. But you'll find out it actually makes it a lot easier to connect. Switching the cathode side only requires an n-channel transistor/mosfet, which you can drive directly from 5v arduino pins. Switching the anode side would require additional components since the transistor/mosfets would require 12v signals.

No, it's not possible, since the voltages and currents involved (12V) are too high.  It will damage your board.
Your arrangement with N-channel MOSFETs is the correct arrangement.
By the way, you are not working with "negative" voltages at all - it's all positive - you just happen to be between the "load" and ground.
This is called a Low Side Switch since it is on the "low" (i.e., between the load and ground) side of the circuit.
The LEDs you have are in an arrangement called Common Anode in that the anodes (+ pins) of the LEDs are all tied together (common) and you control the cathode (- pins) of the LEDs.  It means you can use cheap N-channel MOSFETs that are (as you have seen) easy to control with a microcontroller.  The other arrangement, Common Cathode, where all the cathodes (- pins) are tied together and you switch the power to the anodes (+ pins) requires P-channel MOSFETs and N-channel MOSFETs to switch the P-channel MOSFETs, which increases costs.

Just for the reference If I used 5v LEDs would it be possible then?

If you used 5V LEDs and the total current for all the LEDs on one colour channel was below around 20mA then yes it would be possible.

I'm still far from understanding the limits of arduino, but. I just checked the leds. They are just under 4mA/channel.
Wouldn't that work with VIN pin powered arduino?

Then if they are 5V LEDs you can run around 5 channels in parallel without any extra hardware. Any more than that and you will need the MOSFETs regardless to handle the extra current.

It doesn't have to be MOSFETs, a bog-standard cheap NPN BC547 or similar would be fine.