text:
problem in integrating the slave code in attiny 84
I tried the whole process by using two arduino unos.It worked perfectly.
Though when i tried to replace the slave uno with attiny 84 uC it showed following errors in compiling.
Arduino: 1.6.7 (Windows 7), Board: "ATtiny24/44/84, ATtiny84 @ 1 MHz  (internal oscillator; BOD disabled)"

WARNING: Category '' in library ArduinoJson is not valid. Setting to 'Uncategorized'
C:\Users\LEGEND\AppData\Local\Temp\arduino_8a75bcb6a2713182a57eb1014198ceb3\sketch_may12c.ino: In function 'void setup()':

sketch_may12c:12: error: 'SPCR' was not declared in this scope

   SPCR |= bit (SPE);

   ^

In file included from C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/WProgram.h:12:0,

                 from C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/Arduino.h:4,

                 from sketch\sketch_may12c.ino.cpp:1:

sketch_may12c:12: error: 'SPE' was not declared in this scope

   SPCR |= bit (SPE);

                ^

C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/wiring.h:158:25: note: in definition of macro 'bit'

 #define bit(b) (1UL << (b))

                         ^

sketch_may12c:15: error: 'MISO' was not declared in this scope

   pinMode (MISO, OUTPUT);

            ^

sketch_may12c:22: error: expected unqualified-id before '.' token

   tinySPI.attachInterrupt();

          ^

C:\Users\LEGEND\AppData\Local\Temp\arduino_8a75bcb6a2713182a57eb1014198ceb3\sketch_may12c.ino: In function 'void SPI_STC_vect()':

sketch_may12c:30: error: 'SPDR' was not declared in this scope

 byte c = SPDR;  // grab byte from SPI Data Register

          ^

exit status 1
'SPCR' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Sounds like a bug in the core.

It has to do with SPI.

Could you post the content of sketch_may2c.ino as it seems this is where the erroneous code is.

#include <SPI.h>
char buf [100];
volatile byte pos;
volatile bool process_it;
void setup (void)
{
Serial.begin (115200);   // debugging
// turn on SPI in slave mode
SPCR |= bit (SPE);
// have to send on master in, slave out
pinMode (MISO, OUTPUT);
// get ready for an interrupt
pos = 0;   // buffer empty
process_it = false;

continued.....................
// now turn on interrupts
SPI.attachInterrupt();
}  // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR;  // grab byte from SPI Data Register
// add to buffer if room
if (pos < sizeof buf)
{
buf [pos++] = c;
// example: newline means time to process buffer
if (c == '\n')
  process_it = true;

}  // end of room available

}  // end of interrupt routine SPI_STC_vect

continued..................
// main loop - wait for flag set in interrupt routine
void loop (void)
{
if (process_it)
{
buf [pos] = 0;
Serial.println (buf);
pos = 0;
process_it = false;
}  // end of flag set
}  // end of loop

You are trying to compile the wrong program for the wrong chip.
The nice thing about the Arduino core library is that it enables you to
write code that is portable across various Arduino boards. However, this
library provides very limited access to the capabilities of the
underlying hardware. Then, it is quite common for users to mix Arduino
code with C statements that directly access the hardware registers.
Doing this provides full control over the hardware, at the cost of
reduced portability.
Just an example from your code:
SPCR |= bit (SPE);

This line is accessing the control register of the SPI port (SPCR means
“SPI Control Register”) in order to set to 1 the bit named SPE (for “SPI
Enable”). This is the “bare metal” way of turning on the SPI port.
Now, your problem is that, unlike the ATmega328P powering your Unos, the
ATtiny84 does not have a hardware SPI port. Thus the line above just
makes no sense.
The solution: you have to figure out some other means for your chip to
talk SPI. You could emulate it purely in software, but it would
certainly be more efficient to use the USI port. The USI (“Universal
Serial Interface”) is a multipurpose serial port found in many ATtinies.
It can be configured to do SPI, I2C or simplex/half-duplex UART.
Recommended readings:

AVR319: Using the USI module for SPI
communication, an
application note by ATmel
Using an ATtiny2313/4313 as SPI
master on the Arduino
Playground

You may be able to find ready-made libraries for doing this.


text:
Arduino LED matrix and 2D array, data seems to be corrupting
Duplicate of this question
I'm trying to drive an 8x8 LED matrix with an arduino nano, but I can't get the LEDs to display what I tell it to.
I'm using this LED Matrix
Here's my code:
int row1 = 2;
int row2 = 3;
int row3 = 4;
int row4 = 5;
int row5 = 6;
int row6 = 7;
int row7 = 8;
int row8 = 9;

int col1 = 10;
int col2 = 11;
int col3 = 12;
int col4 = 18;
int col5 = 14;
int col6 = 15;
int col7 = 16;
int col8 = 17;

void setup() {
  int i;
  for(i = 2; i <= 18; i++) {
    pinMode(i,OUTPUT);
  }
  for(i = 2; i <= 9; i++) {
    digitalWrite(i, HIGH);
  }
}

void loop() {

  int display [8][8] = {
  {1,0,0,0,0,0,0,0},
  {0,1,0,0,0,0,0,0},
  {0,0,1,0,0,0,0,0},
  {0,0,0,1,0,0,0,0},
  {0,0,0,0,1,0,0,0},
  {0,0,0,0,0,1,0,0},
  {0,0,0,0,0,0,1,0},
  {0,0,0,0,0,0,0,1}
  };

  updateScreen(display);
}

void updateScreen(int screen[8][8]) {

  Serial.begin(9600);
  int i;
  for (i = row1; i <= row8; i++) {
    Serial.println(i-1);
    digitalWrite(i, LOW);
      digitalWrite(col8, screen[i-2][0]);
      Serial.print(screen[i-2][0]); Serial.print("|");
      digitalWrite(col7, screen[i-2][1]);
      Serial.print(screen[i-2][1]); Serial.print("|");
      digitalWrite(col6, screen[i-2][2]);
      Serial.print(screen[i-2][2]); Serial.print("|");
      digitalWrite(col5, screen[i-2][3]);
      Serial.print(screen[i-2][3]); Serial.print("|");
      digitalWrite(col4, screen[i-2][4]);
      Serial.print(screen[i-2][4]); Serial.print("|");
      digitalWrite(col3, screen[i-2][5]);
      Serial.print(screen[i-2][5]); Serial.print("|");
      digitalWrite(col2, screen[i-2][6]);
      Serial.print(screen[i-2][6]); Serial.print("|");
      digitalWrite(col1, screen[i-2][7]);
      Serial.println(screen[i-2][7]);
      delay(1);
      blank();
    digitalWrite(i, HIGH);
  }

}

void blank() {
  digitalWrite(col1, LOW);
  digitalWrite(col2, LOW);
  digitalWrite(col3, LOW);
  digitalWrite(col4, LOW);
  digitalWrite(col5, LOW);
  digitalWrite(col6, LOW);
  digitalWrite(col7, LOW);
  digitalWrite(col8, LOW);
}

And here is the output:
1
1|0|0|0|0|0|0|0
2
0|1|0|0|0|0|0|0
3
0|0|1|0|0|0|0|0
4
0|0|0|1|0|0|0|0
5
0|0|0|0|1|0|0¾j
6
0|0|0|0|0|1|0|0
7
0|0|0|0|0|0|1|0
8
0|0|0|0|0|0|0|1

So I can tell that the error (probably) isn't my wiring, because those array values are clearly wrong, I have no idea where the ¾j is coming from.

What do they display/what do you expect them to display?

Did you try a longer delay?

With that code as it is works fine, but if I try to display an alternating pattern of LEDs (i.e. like a chess board) like this:
{1,0.1,0,1,0,1,0},
{0.1,0,1,0,1,0,1},
{1,0.1,0,1,0,1,0},
{0.1,0,1,0,1,0,1},
{1,0.1,0,1,0,1,0},
{0.1,0,1,0,1,0,1},
{1,0.1,0,1,0,1,0},
{0.1,0,1,0,1,0,1}

@user168057 If you mean an alternating on-off pattern, then its displaying fine for me. Do you mean on the actual LEDs or only serial monitor?

Nevermind found the issue, I used a few . instead of , in my array declaration. Thanks anyways :)

Because of my psychic abilities*, I am able to tell that you actually used . in a few places you should have used , in your array initialization. Replacing the ,s with .s should fix the problem.
*Okay, okay, not really.

Your initial problem can be sorted out by using a longer delay.
void updateScreen(int screen[8][8]) {

  Serial.begin(9600);
  int i;
  ........
      delay(100); //Longer time duration
      blank();
    digitalWrite(i, HIGH);
  }

}

As far as the chess pattern is concerned, it displays correctly for me.
void loop() {

  int display [8][8] = {
  {1,0,1,0,1,0,1,0},
  {0,1,0,1,0,1,0,1},
  {1,0,1,0,1,0,1,0},
  {0,1,0,1,0,1,0,1},
  {1,0,1,0,1,0,1,0},
  {0,1,0,1,0,1,0,1},
  {1,0,1,0,1,0,1,0},
  {0,1,0,1,0,1,0,1}
  };

  updateScreen(display);
}

Check your array declarations for errors.

source: Stack Exchange

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

sort: votes


text:
16 bit PWM on a mega
I have two Arduinos, a nano and a mega. I want to output 16 bit PWM, but can seem to only get it working on the nano. I'm adapting the code from this website: http://www.ofrecordings.com/2014/03/16/how-to-set-up-16-bit-pwm-with-an-arduino-uno-atmega328/
void setup() {
  // Set PB1/2 as outputs.
  DDRB |= (1 << DDB1) | (1 << DDB2);

  TCCR1A =
      (1 << COM1A1) | (1 << COM1B1) |
      // Fast PWM mode.
      (1 << WGM11);
  TCCR1B =
      // Fast PWM mode.
      (1 << WGM12) | (1 << WGM13) |
      // No clock prescaling (fastest possible
      // freq).
      (1 << CS10);
  OCR1A = 0;
  // Set the counter value that corresponds to
  // full duty cycle. For 15-bit PWM use
  // 0x7fff, etc. A lower value for ICR1 will
  // allow a faster PWM frequency.
  ICR1 = 0xffff;
}

void loop() {
  // Use OCR1A and OCR1B to control the PWM
  // duty cycle. Duty cycle = OCR1A / ICR1.
  // OCR1A controls PWM on pin 9 (PORTB1).
  // OCR1B controls PWM on pin 10 (PORTB2).
  OCR1A = 0x0000;
  delay(500);
  OCR1A = 0x8000;
  delay(500);
  OCR1A = 0xffff;
  delay(500);
}

That code works on the nano, but not on the mega. I expect that it output PWM on pins 11 and 12, but no luck. Care to explain how I can get it working? It's an entirely different microprocessor, and I'm not sure which parts of the code to change.

Change first line:
    // Set PB1/2 as outputs.
    DDRB |= (1 << DDB1) | (1 << DDB2);`

to the
     // Set PB5/6 as outputs. [**Digital pin 11,12 on Arduino Mega!**]
    DDRB |= (1 << DDB5) | (1 << DDB6);

Now your PWM should work, but on digital pins 11 & 12 [Arduino Mega].

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


text:
Problem with piezo readings and Arduino Due
I'm using 1mOhm resistor in parallel to a piezo that is connected to analog1 pin on the Due,

and the following code to observe the readings in the serial monitor:
int piezo = A0;
int threshold = 200;//anything over 200 means I've hit the piezo

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

//this part checks if the threshold has been reached and then writes the strenght of the signal

void loop(){
    int piezoVal = analogRead(piezo);

    if (piezoVal>threshold){
        Serial.println(piezoVal);

        delay(10); //delay is used to prevent from getting multiple values one after another, usually 3-4
    }
}

The things that bother me are:

if I do not use threshold, then I am constantly getting readings from the piezo, even if the threshold is slightly below 200.
if I do not use delay, then I'm getting getting multiple values one after another
and the strangest thing is while I hit the mouse pad that covers the piezo, the readings in the serial monitor are not matching the force being used to trigger the piezo. Sometimes they stay the same, sometimes they reach 6-700 after I directly touch the piezo, sometimes I hit really hard and I only get some slight increase (for ex. from 225 to 229).

This doesn't make sense to me. I think the stronger the vibration, the higher the values should be. Cause I've tried with two different piezos and different resistors (1mOhm, 1.2 mOhm and 1.5 mOhm) and I'm still getting the same result. I bought the Due few days ago in order to build a drum kit, and I have no problem with sending midi notes to a DAW, but this piezo sensitivity thing is driving me crazy. Any suggestions?

The problem is timing.  When you tap or hit the sensor it produces an impulse response: a signal that increases to a peak, then decays back to zero.  You are expecting the code to capture the peak value.  Your code is spinning in loop() as quickly as possible, but captures just the first point above the threshold. The signal can still be increasing when you capture and print.
So imagine this stream of signal values
time  signal   analogRead()
      at pin   occurs
----  ------   --------
 1     190      190
 2     190
 3     199
 4     210
 5     220      220 - trips threshold, prints and then waits
 6     230
 7     260
 8     280
 9     320      (this point occurs during delay())
 10    280
 11    260

The same exact signal, but at a slightly different time could be read different by the code:
time  signal   analogRead()
      at pin   occurs
----  ------   --------
 1     190
 2     190
 3     199      199
 4     210
 5     220
 6     230
 7     260      260
 8     280
 9     320      (closer, but still did not read the peak)
 10    280
 11    260

So the strategy of catching the first point above the threshold makes it unlikely you can capture the peak value.  There are two ways forward: hardware or software.
You could use electronics that latches the maximum value.  If you search "peak hold circuit" you will find many circuits that would capture and hold the peak.  That frees the Arduino to somewhat lazily spin in the loop and still be able to accurately capture the peak.  Once it sees the value is no long increasing, it resets the peak hold and goes back to waiting.
You could use code to capture the peak. Something along the lines of this psuedo code:
lastreading = analogread()
if(lastreading > threshold) {
  peakreading = lastreading
  keeplooking = true
  while(keeplooking) {
    nextreading = analogRead()
    if(nextreading > lastreading) {
      // the signal is increasing, save this and see if next point is even higher
      peakreading = nextreading
      lastreading = nextreading
    }
    else {
      //signal is decreasing, the peak is over
      keeplooking = false
    }
  }

This software approach could still miss a sharp peak that occurs between analogRead()'s, but may be good enough for your use.

I very much appreciate your help. Since I'm a total beginner, I expect things to run smoothly :). I'll definitely dive into this peak filtering and share the results.


text:
Arduino Nano and a 3.3v Ethernet shield
I plan on purchasing a Nano clone, an Ethernet shield (ENC28J60), an LCD and a DHT22 humidity + temperature sensor. This will be used in a wine cellar to monitor relative humidity and temperature.
The DHT sensor, LCD and Nano all operate on 5V logic. The Ethernet shield does not operate at 5V, but rather at 3.3V.
Does the Nano have a way to connect the two, will they work anyway (probably not), or should I use a CD4050 that is recommended on adafruit?
Any guidance is appreciated; I'm still amazed in what $10 in parts can do.
Also, in regards to the DHT22 sensor, what do I need in terms of a resistor? I've seen some people say you absolutely need a 4.7K resistor on the data pin for "pull up", and  others who say it's unnecessary. Can someone give a definite answer, either way?
Edit, wrong link on my nano clone.

Could you provide links to something else than ebay? FYI, the second link is blocked in some countries, making it impossible to see what you're talking about.

Also is that a shield or a breakout board?

I believe it's a shield. Sorry, didn't know ebay was blocked for anyone.

@Ethan those eBay links are dead - they don't last long.

Just get one with a 3.3v regulator on it. PS logic levels are allowed to be 5v.
DHT22 and LCD will also work fine on 3.3v so, alternatively, you could also get a 3.3v Nano.
The resistor value for the DHT22 depends on the length of wire between the DHT and Nano. Just buy them to be sure, or get a breakout board that already has them on the board (along with a capacitor, which is nice).

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


text:
Bluetooth Master and Slave to track device's locations
I'm trying to create an app for my science fair that uses bluetooth to track people in a determined place.
I was thinking about one Arduino system to receive all the information and transmit through a network and some Arduino slaves to duplicate the signal and cover the hole place.
Resuming...
I'll have:

Arduino slaves placed all over the place to track people
One Arduino connected to the network to receive all the information from the slaves and pass it through the network.
Some kind of web app inside the main Arduino with an API to manage the data and make it friendly for third-party apps

I was wondering of what kind of equipment should I buy to make this happen. Thanks!

Each cellphone with it's bluetooth enabled will work as a person (sending signal) - my Arduino slaves will receive the signal (find bluetooth around it) and send the device name and signal strength to the arduino master - The arduino master (connected to the network) will interpenetrate the responses and send the results to the built-in web server - Apps will make requests to the web app to get this data and show in a plant where're these people.
Basically it will work like these bluetooth stickers that you can plug in to your keys, phone e etc... and with the app you can search for them in your house via bluetooth from your cellphone.
Here's a better explanation:
Link

Google "sensepost snoopy".  Also note that most phones are not discoverable unless they are put into pairing mode so you won't be able to detect them unless you already know their bluetooth ids in which case you can poll for them.

Classic bluetooth is not a solution for this.  BLE could be crudely, though signal-strength based positioning as commonly used there is only crudely accurate.  Time of flight measurement would require substantially better hardware than you have available.

Bluetooth generally support only one to one connection. Atmost 6 bluetooth can be connected to single module in latest bluetooth version(the basic model probably used by you connects only 1 device). Hence it is not a good idea to use bluetooth. Also if you need a web based platform you should switch to some more powerful platform like raspberry pi, beagle bone etc.


text:
Arduino Nano not responding with yellow led blinking fast
Update: I started playing with a genuine Deumilanove and exactly same problem happened to it - d13 led blinking, but avrdude says stk500_recv(): programmer is not responding
I uploaded a largish sketch ~15kb to Arduino Nano v3.0 (clone) and that left the board in an unusable state. When connected to USB, a power LED goes on immediately and 1-2 seconds later the yellow "L" starts blinking really fast.
Here's the board I use, it's a cheap clone, but it worked really well before today.
Now, when I try to upload a new sketch I get an error:
avrdude: stk500_recv(): programmer is not responding

I tried making and ISP programmer out of genuine Duemilanove, using nano's ISP pins and tried following official instructions (didn't use any capacitors/resistors).
Either way when I click "Burn Bootloader" result is the same error:
avrdude: stk500_getsync(): not in sync: resp=0x15

I have connected "debug" leds to D7,8,9 and heartbeat fades in and out in idle, others stay dark.
When I click "Burn Bootloader" all leds go dark then it does few quick blinks on 7, then similar pattern for 8, and then heartbeat resumes. Sometimes this sequence is repeated twice.
I also tried editing preferences.txt to bypass bootloader, but that didn't help.
How do I restore this board or do a low level reset?
It seems to be in some failure mode, with pin 13 oscillating, but I don't know what that means.

Ahh I kinda remember something about holding the reset button while uploading might unbrick the Arduino enough to upload it, but I can't remember when to release the button (or if I'm just imagining this)... are you sure you have the right COM port set and all in the IDE?

Yes, pretty sure the ports are right, because the programmer board blinks the leds differently when software tries talking to nano.

The official instructions don't mention any capacitors (unless you use a bare chip). Could you show a picture of how you wired it?

It suggests a 10uF capacitor when using Uno. Anyway, I managed to restore the boards using a Reset button, see my answer below. I disassembled the wires afterwards so no pictures this time. Wiring was really straightforward, I might attempt it again, once I find a newer bootloader

im have the same problem, Chinese Arduino 3.0 with CH340 USB controller, i was thinking the problem is CH340 failure, in my time this arduino is so cheap, i solve that by replacing the entire board, but in order to know whats cause the failure i will be testing changing the CH340 chip in this board.

I successfully restored both boards using the reset button:

Power off the board (I disconnected the USB cable from computer)
Press and hold the reset button
Connect USB cable (keep holding the reset button)
Click "Upload Sketch"
Wait a second or two until Arduino software says "Uploading..." in the status bar
Release the reset button

Use these steps to upload any small sketch, Blink example is a good choice.

I've been blocked on this for 2 days, you just saved my board!

There is bug related to watchdog in original old Arduino bootloader. You can switch to different bootloader, e.g. "Optiboot".
Explanation of issue from ATmega48A/PA/88A/PA/168A/PA/328/P datasheet, section 10.10.5 Watchdog Timer, page 48:

If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the
  device will be reset and the Watchdog Timer will stay enabled. If the code is not set up to handle the Watchdog,
  this might lead to an eternal loop of time-out resets. To avoid this situation, the application software should
  always clear the Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialization routine,
  even if the Watchdog is not in use.

Reset from button is not helping, only power off/on reset give device change to boot again (and flash new software). Explanation of this, from 11.9.1 MCUSR – MCU Status Register, page 54:

Bit 3 – WDRF: Watchdog System Reset Flag
  This bit is set if a Watchdog System Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic
  zero to the flag.

Use "upload.verbose=true" in the preferences.txt of the Arduino IDE (File->preferences-> Click on the file), this helps you to find the right moment to release the reset button (Step 5 of Paul's method).
avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
.
.
         Using Port                    : COM19
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
release here ^^^^

Try changing processor type to ATmega328(old bootloader) in Tools->Processor. My Nano board blinked led like it had bootloader but I couldn't upload sketch and that helped.


text:
PWM generation using Registers
I'm using the Registers of the Arduino micro to get a signal for Electronic Speed Controllers (ESC) for brushless motors.
As far as I read, ESCs interpret everything they can, while just ignoring too fast update rates. If somebody knows better, this would be a great time to yell.
The goal is to get a digital signal, where a timespan between 1 and 2 ms is HIGH and the rest low. Ideally I want this at 50-400Hz, since 488Hz is the fastest possible frequency, and 50 Hz the standard Servo frequency.
I try to use Phase Correct Mode to count up and down continuously. As the value in the counter reaches my set OCRnx on the way up, it sets the output pin LOW, as it reaches the same value on the way down, after reaching TOP(value), it sets the output HIGH. In ATmega documentation terms, this is NON-inverted Phase-Correct-PWM.
So I set the Registers DDR (to set the pin as output), TCCR1A and TCCR1B and ICR1 (TOPvalue = between 20000 and 2500).
Now using OCR1A = 1000 should give me a pulse width of 1000ms. This is the expected or target behaviour.
My testing code is:
// using a 16-bit timer to generate PWM signals for ESCs

// Phase Correct Mode counts from Bottom to Top and back to Bottom
// with a prescaler of 8
// motor signal (OCRnx) uses values of 1000 (idle) - 2000 (max)
// which directly corresponds to microseconds HIGH-time
// setting the range to (BOTTOM) 0 - TOPvalue sets the frequency

// two important formulas are:
// frequency(PWM) = F_CPU / (2*Prescalar*TOPvalue)
//
// PulseWidth [s] = High-tick-count / (F_CPU/Prescalar)
// High-tick-count = 2 * OCR-value

// n = number of timer (1,3)
// x = A,B,C

#include "Arduino.h"
// #include <Arduino.h>
// #define DEBUG
// #include <Moto.h>

#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

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

  // TIMER 1
  // TIMSK1 = 0; // disable Interrupts for timer1
  DDRB |= (1<<DDB5); // D9 Output
  DDRC |= (1<<DDC6); // D5 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;
  OCR3A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively
  // bits 1,0 WGM_1,0: phase correction mode
  // TCCR1A |= B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  TCCR1A |= (1<<COM1A1)|(1<<WGM11);
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  // TCCR1B |= B00010010; // in hex: 0x12; B 0001 0010
  TCCR1B |= (1<<WGM13)|(1<<CS11);
  ICR1 = TOP_VALUE;

  // TIMER 3
  // TIMSK3 = 0; // disable Interrupts for timer3
  // bit 7 PWM Output on pin A
  // bits 1,0 WGM_1,0: phase correction mode
  TCCR3A |= B10000010; // in hex: 0x82; // B 1000 0010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR3B |= B00010010; // in hex: 0x12; B 0001 0010
  ICR3 = TOP_VALUE; // TOPvalue = 2048

}//setup

void loop(void) {

  // Serial.println(TOP_VALUE);
  // delay(500);
  while (dutytime < 2000) {
    dutytime += 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }
  while (dutytime > 1000) {
    dutytime -= 150;
    OCR1A = dutytime;
    OCR3A = dutytime;
    Serial.println(dutytime);
    delay(1500);
  }

}//loop

I repeated the settings for timer3 to get something to compare to. Both do give the same: if i delete the loop and just write loop{} nothing happens. The pins are high and seem to stay so. With the while loops activated, my multimeter gives me 1Hz (which are the changes of course) and between 99.9% duty cycle and 96%.
An led, which i connected to it blinks every second a very short time.
What am I doing wrong?

I don't understand what you want to achieve. Pulse width of 1000ms at a sample rate of 488.28Hz that seems contradictory, as the maximum pulse width can only be 2ms at 488Hz.

2048 to be exact for this case. Why is that contradictory, if I want to have pulses between 1 and 2 ms (something around 48% and 97% duty cycle)?

That doesn't really make it any clearer. Seems I can't help you then.

I'm not 100% familiar with Arduino timers, but here is how I did PWM on an MSP430 with timers: http://imgur.com/2aOnW2g Essentially, you count up, and reset. When the timer hits the set value, it does the rising edge pulse, and when it hits the max count, it resets both the pulse and the timer. The alternative of this is to do the opposite: set the pulse high until the timer hits the threshold value, etc.

Thanks. What you suggest is in Atmels Documentation called fast PWM, where the counters just count until overflow. I however use phase-corrected PWM, where it counts up and down. This gives a more symmetrical output (and according to them) is prefered over fast PWM.

What I did wrong was using |= instead of = . Apparently Arduino set some of these Bits on start, which didn't change.
Now it works like a charm and I added a frequency choice, which works for at least 50,200,400,488 Hz. Everything in between should work aswell!
Working testcode for timer1 with serial input of HIGH-time:
#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

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

  // TIMER 1
  DDRB |= (1<<DDB5); // D9 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively (COMnx1)
  // bits 1,0 WGM1(1,0): phase correction mode
  TCCR1A = B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR1B = B00010010; // in hex: 0x12; B 0001 0010
  ICR1 = TOP_VALUE;
}//setup

void loop(void) {
  // Serial.println(TOP_VALUE);
  dutytime = serial_input();
  if (dutytime) {
    OCR1A = dutytime;
  }
  delay(500);
}//loop

float serial_input() {
  double num = 0;
  while(Serial.available()) {
    delay(2);
    char ser = Serial.read();
    if(isDigit(ser)) {
      num = (num*10)+(ser-48);
    }else{ break; }
  }
  if (num) {Serial.println(num);}
  return num;
}


text:
Electret microphone amplification
I've got an electret microphone and I understand that I need quite some amplification to get it to be read by an Arduino (0-5V input). So I seeked the web, but answers are as different as people on the street. Some use Op-Amps, some only a transistor cicruit or the like. This guy is using 2 amps before and after his filters Video, LM386 and this guy claims, that exactly this amp isn't good for the job: recommends NOT using LM386.
I really only want to have a threshold switch, so I need no filters whatsoever and not a super duper amplification. What is the simplest solution, with which I can read a voltage with the arduino? With a transistor alone (seems easiest to me so far) - how can I know how much it amplifies (or as I understand it modifies the "other voltage" to look the same)?
I found many different schematics using various op-amps, but regarding them I don't really need another tutorial, but rather a rule of thumb for a "readable" amplification. Is 100 times enough? I found circuits with 1000 times amplification, so I'm really wondering which one works fine.
However the really simple thing would be this: video at 17sec. At second 17 and 50 or so, they show an extremly basic circuit, which would be exactly what would work best for me... However the question is, if this is enough amplification for the ADC in an arduino.
If I can't get a satisfying answer I think I'll build both and see how they compare/work for me.

I've built

This circuit without C4 and everything after R4 (no rectifier, not a single diode used). R4 has to be switched for 100kOhms, since this gives a 100x amplification. I guess this is simple enough for most people.
Thanks for the hints.
The following code can be used to detect claps/noises. It is restricted to a double-clap with silence in between. Parameters can be easily tuned. This works quite well for me, even when I play noise/TV/music to the speaker directly it triggers rarely, or not at all!
// CLAP switch using an electret microphone
// switches ie. a relais or led with a certain
// clap-melody

// sound parameters
const int THRESHOLD = 20;
const int VAL_MEAN = 507;

// trigger characteristics
const int CLAPS_TO_TRIGGER = 2; // number of claps
const int DEBOUNCE_TIME = 150; // ms to ignore double-clapping
const int SILENCE_T = 40; // ms between claps, otherwise reset
const int MELODY_INTERVAL = 800; // ms max time for the claps
const int PAUSE_TIME = 2000; // wait after switch, or noise

// pin-layout
const int analogPin = 0;
const int OUTPUT_PIN = 13;

int output_state = LOW;
uint32_t pause_t = 0;
uint32_t debounce_t = 0;
uint32_t start_time = 0; // timestamp of first clap-start
uint8_t claps = 0;
int sensorVal = 0;
int amp = 0;

void setup() {
  Serial.begin(115200);
  pinMode(OUTPUT_PIN,OUTPUT);
}

void loop() {
  sensorVal = analogRead(analogPin);
  amp = abs(sensorVal-VAL_MEAN);

  // Serial.print(F("sensed: ")); Serial.println(sensorVal);
  // Serial.print(F("amp: ")); Serial.println(amp);

  // at the end of an interval check the number of claps
  if (millis()-start_time > MELODY_INTERVAL & claps != 0) {
    if (claps == CLAPS_TO_TRIGGER & millis()-pause_t > PAUSE_TIME) {
      output_state = !output_state;
      pause_t = millis();
      digitalWrite(OUTPUT_PIN,output_state);
      Serial.print(F("Triggered "));
      Serial.println(output_state);
    }
    if (claps>CLAPS_TO_TRIGGER) { Serial.print(F("- too many")); }
    reset();
  }

  // noise/clap detected
  if (amp > THRESHOLD &\
      millis()-debounce_t > DEBOUNCE_TIME &\
      millis()-pause_t > PAUSE_TIME) {
    // there has to be silence between claps
    if (millis()-debounce_t < SILENCE_T+DEBOUNCE_TIME) {
      claps = 0;
      debounce_t = millis();
      Serial.print(F("reset - silence interrupted"));
      Serial.print(F(" amp "));Serial.println(amp);
    } else {
      claps++;
      debounce_t = millis();
      Serial.print(F("claps "));Serial.print(claps);
      Serial.print(F(" amp "));Serial.println(amp);
      if (claps == 1) { start_time = debounce_t; }
    }
  }
  delay(1);
}

void reset() {
  // time has expired
  start_time = 0;
  claps = 0;
  debounce_t = 0;
  Serial.println(F("reset"));
}

You can use Maxim MAX4466 op-amp which works very well with Arduino. There is a breakout available for the same for arduino at Adafruit here. The chip has a select-able gain from 25x-125x. This amplifies works very well to get a nice waveform for audible noise. There are a couple of libraries available for the waveform that you record and can translate it to frequencies. You can also use it to distort or change the voice. Here is a schematic of the circuit if you want to make one yourself.

For the most basic circuit you must bias your microphone since it is electret with a 10k pull up resitor. If you do not want to build a complex circuit you could use a breakout board such as this one.  To build your own see here. It is used as a VU meter which is basically the same idea.  Also, make sure you observe polarity(pin with traces touching metal packaging is negative).


text:
Comparing a char with the symbols '.-'
I'm using the Arduino software to create a Morse code decoder using the  serial monitor.
I enter a Morse code such as .- as a text string and it's displayed in the LCD as a alphanumeric text. So if I enter .- into the serial Monitor, A is displayed on the LCD. But it only works for single symbols, not the dot and dash together.
Is there a way to make the if statement as seen below accept both the dots and dashes together?
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);

 Serial.begin(9600);
}

void loop()
{
  char schar;

  if (Serial.available())
  {
    schar = Serial.read();

    Serial.write(schar);

    if (schar== '.-' ){
      Serial.write('A');
      lcd.print('a');
    }
  }
}

Your first problem is that there is no way for schar to contain two characters in the first place; Since schar is declared as a char, it can only contain one character.
You need to make a String out of the serial input. Serial.read() only returns one character at a time, so you will need to make sure you iterate over all the input. Then you can compare the whole String with another, and see if both characters match at once. Just look at this code to see different ways of manipulating Strings: http://arduino.cc/en/Tutorial/StringComparisonOperators
Notice that string literals use double quotes, not single quotes like characters.
Also, be aware of the fact that string and String are different things. lowercase 's' is an array of characters, capitol 'S' is the class that has those useful string comparison member functions. The class is more resource intensive, but I think in your case the readability and convenience are worth it.

i'm still new but should i use char schar[2];

That would be equivalent to a string (lowercase) on arduino, sometimes called a "c style string". It can work, but using the functions built in to arduino's String class might be easier. that would be String schar;

A string seems like overkill here. The lowercase one would use much less memory (if(data[0] == '.' && data[1] == '-') would be more efficient)

You could use C strings, (type char*) or C++ String objects (type String). Both would work.
If you use C strings, you'll need to use functions like strcmp() from the C library to see if your input string matches a particular morse sequence.
If you use C++ String objects, you'll need to use the methods of that class. I'm less familiar with that class.
If you have single Morse characters, matching them up is pretty easy. If you have a continuous stream of dots and dashes, though, it's a much thornier problem. You need a way to figure out the boundary between characters. Morse characters can be sequences of between 1 and 5 dots and dashes.
Unless there are extra delays between the dots/dashes for a character, I'm not sure how you figure out where the boundaries are. There are already computer Morse code readers, though, so this must be a "solved problem". I'd do some googling.

morse code does in fact require a delay or a break character to be uniquely decipherable, see Is Morse code without spaces uniquely decipherable?

schar is a char variable of size 1. It makes no sense to compare it with '.-', which is supposed to be a string. Declare a char[3] array, fill it as string and use the strcmp function. It's elementary C knowledge.


text:
Should I use an Arduino or not?
I am building an electronic gadget eventually to sell.
I think the Atmega IC is used in the arduino and could this be programmed as easily as the arduino?
I'm wondering if I can use the chip and buy just what I need for my circuit, which would be cheaper as there would be no licensing obligations to the Arduino company
Cheers
Eamonn

What "licensing obligations" are you worrying about? The Arduino is open source hardware, which has been cloned by many other companies. Also, you will probably find that a cheap clone costs less than you would pay for the parts.

@DaveP. I had a look on the Arduino site and they mentioned a fee for producing a product for sale. Maybe its just if you want to have the product promoted on their site and you would have the arduino logo on the product. I will do a bit more rescearch so thanks for the info.

Short answer: Yes. After all, Arduinos are made by starting with an ATMega (or other AVR) IC.
Longer answer: People - including myself - routinely build with a bare ATMega328p (or other MCU), programming them off-board on another system, or providing connections to allow programming them in place. Beyond that you only need the soldering skills for the chip you choose (if you're building the boards yourself). I use DIP ICs and off the shelf through-hole PCBs and hand-build one or a couple at a time. Quad Flat-Package or Surface-Mount chips are another step up in complexity for the hand-builder.

I'd like to second the other posts - if you are familiar with Arduino, going to a stand-alone chip is very easy.
You miss out on the following things: programming via USB, 7-12volts through the power jack, and/or power through USB, reset button, led on pin 13, and the clock. Depending on where you get your Atmel chip, you may also need to set the fuses.
The code is exactly the same, even if you go down to a smaller chip (or larger - whatever suits your project best!).
Programming: I use a FreeTronics ICSP (ISP) to program the chips, and have the 6-pin ICSP header on all my projects for easy reprogramming. This particular programmer has a "slow clock" jumper, because when you get the chip from the Atmel factory, their internal clock runs at 1mhz, too slow to program with the Arduino IDE default settings. You can leave it at 1mhz, if your project doesn't need any more, or change the fuses. You will need an ICSP to set the fuses (see further down). By using an ISP rather than usb, you also save a little memory - you don't need a bootloader (which is pre-programmed on Arduinos, but not when you buy the chips from the factory).
You will need to sort out your own power - this depends on what you need, and what you have. You can use a 5-volt AC-DC power supply ("Wall wart") and plug it into mains. Or, you can power it off USB - if you only use USB for power, you can solder the socket directly on your board. You can use a regulator (which is what the Arduino uses for the 7-12v power socket), or, if running it off a 12v power supply, it might be easier/cheaper to buy a car phone charger from the dollar store, and a lot of the work will be done for you. Also, the power supply doesn't have to be 5v - depending on your application, you might run it from 5.5v to as little as 1.8v, depending on your clock speed. Find the data sheet for the chip you use.
A reset button is very easy to add, if you need it - all it takes is a resistor and a pushbutton. Weather you need it or not, depends on your project.
The same applies to the led on pin 13 - it depends on your project.
Finally, the clock. The Arduino has a 16mhz quartz clock. You can do the same, it only takes 3 components (you will have to set the fuses, see further down). You can use a clock up to 20mhz, giving you a 25% speed boost if you need it (you may need to change some settings, because timing functions like delay depend on the clock speed - your delays will be 25% shorter). Or, you can use the internal 8mhz clock (either at full speed, or as from factory, at 1/8 speed, so you get 1mhz). At 4mhz or less, you can run the Atmega at 1.8 volt, or 0.7 volt for the "pico power" chips.
As I have mentioned, you may need to set the fuses to the correct value. The best idea is to go to http://www.engbedded.com/fusecalc/ to work out what fuse settings you want. Specific things to look for: the clock source (internal or external? what speed?), divide clock by 8 internally, and brown-out detection (Arduino chips turn themselves off when the power goes below 4.3v). Warning: setting wrong fuses may set your chip so it is very difficult to fix. You can set the fuses using an ISP; if the clock speed is very slow (I think < 4mhz? which it is when it comes from the factory), then you will have to "slow program" - some ISPs have a "slow program" jumper, but you can use an option to avrdude to do the same - I think it's -B e.g. -B10).

^ for a comprehensive answer.

That's what I do all the time. You might want to buy an ISP programmer to program the chips (e.g. USBASP or usbtinyisp). If you just want to try things out first, you can use your arduino board as an programmer by uploading the ArduinoISP sketch.
The Arduino Uno uses an ATMega328, but you could use other AVR chips too. E.g. the ATMega8, which is slightly cheaper. Or an ATTiny85, which only has a few pins, and is therefor a lot smaller (also cheaper). So you can choose a chip that best fits your needs.

Thanks for all the replys. I have a lot to learn as I only heard of arduino a month ago.
Didn't have a reason before.
My arduino hasn't arrived yet so I made my basic circuit with components on a breadboard.
I think I will need the arduino as I need some monitoring in the circuit.
Thanks again much appreciated.
Eamonn

Arduino of course started as a prototyping platform. Build this first, get it working, then move to a circuit board of your own design with the same chip and go from there. However, as the cost of all the components and really the boards themselves drops, I frequently find my self thinking, why not just use the board. Obviously if you are going to market something, having a full arduino in there might be a bit much, but if its just for your own application, I don't see any reason why you wouldn't just buy boards and use them as necessary.

Since you are already using Arduino, I think you not should use atmega, but must! To prevent future headaches, since you look new to electronics, I HIGHLY recommend to check for app notes by Atmel. Just type it "Atmel app notes" at google and you will find a lot of useful tips. Some of them are start to routing by crystal resonator, them GND and Vcc. Use, if possible, on each IC a 100nF ceramic SMT capacitor nearest as possible and another one of 10uF (can be electrolytic) on most robust ones (like microcontroler). Always route opposite signals (like Vcc and GND) tied together with the same size to low its impedance... If you are doing with high inductance loads you should use another sorce (and maybe also a diode as rectifier or an optocoupler).
There's a lot of good practices and if you want to sell your work, you really have to study them.
Good luck! Also look for the electronics SE


text:
Problem with fading LEDs
I got a breadboard with 10 LEDs, 4 of them fade, to be specific:
3, 5, 6 and 9 are working. 0, 1, 2, 4, 7, 8 are not working.
I'm using LEDs and resistors on all spots, they're all the same. Tried changing things around but the problem doesn't seem to be the resistors or the LEDs.
I'm using the following code (I'll highlight the parts for the fading, by marking it between //** comments).
Does anyone know a way to fix this? Or see any problem?
const int inButton = 13;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
int delayTime = 100;
int brightness = 0;
int fadeAmount = 5;

void setup() {
  //**
  pinMode(inButton, INPUT);
  for (int out = 0; out < 10; out++){
    pinMode(out, OUTPUT);
  }
  //**

  pinMode(testLed, OUTPUT);
}

void loop() {
  buttonState = digitalRead(inButton);
  if (buttonState != lastButtonState){
    if (buttonState == 1){
      buttonPushCounter++;
    }
  }

  lastButtonState = buttonState;

  if (buttonPushCounter % 5 == 0){
    for (int i = 0; i < 10; i++){
      digitalWrite(i, 1);
      delay(delayTime / 2);
      digitalWrite(i, 0);
    }
  }
  else if (buttonPushCounter % 5 == 1){
    for (int i = 0, j = 9; i < 10, j >= 0; i++, j--){
      digitalWrite (i, 1);
      digitalWrite (j, 1);
      delay(delayTime / 2);
      digitalWrite (i, 0);
      digitalWrite (j, 0);
    }
  }
  else if (buttonPushCounter % 5 == 2){
    for (int i = 0; i < 10; i+=2){
      digitalWrite(i, 1);
    }
    delay(delayTime);
    for (int i = 0; i < 10; i+=2){
      digitalWrite(i, 0);
    }
    delay(delayTime);
    for (int i = 1; i < 10; i+=2){
      digitalWrite(i, 1);
    }
    delay(delayTime);
    for (int i = 1; i < 10; i+=2){
      digitalWrite(i, 0);
    }
  }
  else if (buttonPushCounter % 5 == 3){
    for (int i = 0 ; i < 10 ; i++){
      analogWrite(i, brightness);
    }
    brightness = brightness + fadeAmount;
    if (brightness == 0 || brightness == 255){
      fadeAmount = -fadeAmount;
    }
    delay(25);
  }
  else {
    int R1 = random(10);
    int R2 = random(10);
    int R3 = random(10);
    int R4 = random(10);
    digitalWrite(R1, 1);
    digitalWrite(R2, 1);
    digitalWrite(R3, 1);
    digitalWrite(R4, 1);
    delay(delayTime);
    digitalWrite(R1, 0);
    digitalWrite(R2, 0);
    digitalWrite(R3, 0);
    digitalWrite(R4, 0);
  }
}

Only pins that support PWM support analogWrite() fully. 3, 5, 6, 9, 10, and 11 do. The rest do not.

Ahh, that explains a lot! Is there any way around this, to get them working anyway?

You need to either implement software PWM or use a chip with more PWM channels such as the TLC5940.

Alright, thanks for the help, I'll start looking into that!

To add to @ignacio-vazquez-abrams answer, the pins that support analogWrite() have ~ sign next to their number (on my Uno board they are 9~, 10~, 11~ e.g.);

It's worth noting that this doesn't necessarily apply to 3rd-party clones/derivatives of Arduino boards.


text:
Take an Arduino or Teensy prototype to Mass production - Loading software onto microcontroller
I am developing an educational product that I would like to mass produce. I am not sure of the quantity yet, but I imagine we will make a few hundred PCBs at least to begin
I spoke with an electrical engineering about how to take an Arduino prototype to mass production, and he warned me that the code written in the Arduino IDE cannot be fused onto the processor. (He used the term "fuse", although I don't see this elsewhere in the forum. is this the right term?)
He said that I would probably have to take each product, and load the Arduino code on manually, plugging in each one to a computer and upload like one would when prototyping. Also, he said the other option would be to recode my Arduino sketch from scratch using an AVR code.
Can someone shed some light on this for me? How can I take Arduino prototyping code and use it in mass production?

For easier programming, you might use a programmer with pogo-pins, and draw some connection pads on the PCB. Also, some programmers can program from stored memory, so you're not re-uploading it from PC everytime, but from the memory of the programmer.

I spoke with an electrical engineering about how to take an Arduino prototype to mass production, and he warned me that the code written in the Arduino IDE cannot be fused onto the processor.

That's nonsense. The output from the IDE compiler is a .hex file which is then sent via avrdude to program the board. If the output cannot be "fused" onto the processor how does he imagine we ever get anything done?
Possibly he is referring to changing the fuses to make it impossible to read the code back from the chip. This can be easily accomplished.

He said that I would probably have to take each product, and load the Arduino code on manually, plugging in each one to a computer and upload like one would when prototyping.

You have obviously spoken to someone with no experience in Arduinos, possibly one of those engineers with an active dislike of it.
I have written code to run on an Arduino to upload sketches to another board.
You can read about it at Atmega chip stand-alone programmer to upload .hex files. The idea is you take your .hex file, put it onto an SD card and then program your target board in a few seconds.
User "Crossroads" from the Arduino forum has taken that idea and made a stand-alone board, looking like this:

You put up to 255 hex files onto the SD card. You dial-up which one you want with the rotary dial. You plug in the ICSP cable into your target board, and hit the "program" button. The whole thing takes a few seconds.
It is designed to be used "in the field". All you have to do is plug in a power-pack to supply power to it.
If you needed to protect the target boards with a fuse setting after uploading, you would modify the code in the programmer slightly to do that for you.
It would be helpful to have an ICSP header on your target boards, both for programming before deployment, and in case you find a bug and have to change it.
Failing that you might put the chips into a suitable board first (eg. with a ZIF socket), program them off-board, and then solder them on. There are lots of options for you.

Also, he said the other option would be to recode my Arduino sketch from scratch using an AVR code.

I don't see why that would be necessary, in any way.

Thanks for the response. That is just what I was looking for.

Arduino code and AVR code is essentially the same, at least once compiled it is. The only real difference is the existence of the bootloader, and that is not essential.
For quantities of a hundred or so it is probably most cost effective to manually program them via an ISP connector to the board. For larger quantities Atmel provide a mass programming service to pre-program the chips, but that costs money so the more you have done at once the cheaper it is per chip. I am not sure on Atmel's procedure off hand but others I have used just take either a .elf or .hex file which the Arduino IDE is perfectly capable of producing.
Either way you should design in an ISP connector on your board so the firmware can be upgraded in the future if needed.

Great to know that Atmel provides this service. Thanks for the tip

Actually, the difference between Arduino code vs. plain AVR code is the use of the Arduino libraries - the bootloader is, as you say, entirely optional.  The best "connector" to use may be a single row of unpopulated plated through holes, as a mass production setup can hit those with pogo pins, while in the lab you can hold in a set of pin headers at an angle, or solder in a set if you are going to be reprogramming it a lot - but it's best to consult the factory on the specifics.

That is the difference in source code. I am on about when compiled. There is no difference when compiled. And the libraries are just AVR code. There is nothing special about them.

Arduino code is AVR code. There's no real difference. The only thing is that Arduino's tend to use bootloaders, which might cause a problem. But in your case I'd advice to not use a bootloader anyways.
Since you plan to build a lot of them, you probably want to use bare ATMega chips, and not arduino boards. Bare chips don't have a bootloader to begin with.
You'd program the boards using ISP.


text:
In what situation would the Vin pin be attached to any of the I/O pins?
In what situation would the Vin pin be attached to any of the I/O pins?
Also, in what situation would the Vin pin be attached to an external circuit?

Vin is exactly the same as using the barrel jack (DC in) on the Arduino.  You can use it when you want to power your Arduino from an external source and you don't want to have the bulk of a big power plug.  It can also be used as a power output when you are using the barrel jack, for instance for powering relays or motors.  It just saves on having to splice wires into the cable of a wall wart, for example.
The voltage you feed in to the Vin pin should be of the same specification as the barrel jack - that is, between 7 and 12V.  From there, just like the barrel jack, it goes to the 5V regulator to provide the 5V for the board, and then on to the 3.3V regulator for low powered peripherals.
If, at any time, you power the board from the USB and have something connected to the Vin pin that consumes power you risk damaging the 5V regulator on the Arduino since power will flow backwards through it form 5V to Vin, which it really isn't meant to do.  In these situations it is good to connect a diode between 5V and Vin such that the anode is on 5V and the cathode on Vin - so that if the 5V is higher than the Vin voltage then the current will bypass the regulator safely.

Thanks, also when do you think it would be acceptable to attach the positive or negative end of a power supply to an I/O pin?

@abc12333333 You have asked that as a separate question - see my answer there.

@Majenko Vin is exactly the same as using the barrel jack. The barrel jack has a polarity protection diode, while Vin hasn't (at least on the UNO). Other than that, they are indeed the same.

Vin connected to an IO pin: If you want to damage your Arduino.
Hypothetically, I could imagine a misguided attempt to detect if it's being powered from a barrel jack or from USB, but the higher voltage (and it will ALWAYS be a higher voltage if powered from that rail) is likely to damage the chip
To do that safely/correctly, you would need a voltage divider, to reduce both the voltage to a level below the +5v level.
Vin to an external circuit is very reasonable. If you have, for example, a motor that needs +12v, and your Vin is 12v, then you can provide the power for the motor from Vin, and still control it from the Arduino - you would use a transistor to turn the +5v from one of the digital pins (set to output) to 12v from Vin. This is typically what happens on a "motor driver" - for example, see http://www.hobbytronics.co.uk/image/data/tutorial/bipolar-stepper-drive.jpg - on the left-hand side, you will see "motor supply" - this runs at a higher voltage (and is isolated from +5v and Arduino pins), and if your motor needs what the barrel jack supplies (and is no more than 12v), then Vin is perfect.
The other situation is that you can put +7v to +12v INTO the Vin, instead of using the barrel jack - this will power your Arduino.

Thanks, also when do you think it would be acceptable to attach the positive or negative end of a power supply to an I/O pin?

Directly connected, there's no point, though it's not unusual to connect it via a resistor as a part of a voltage divider.


text:
About arduino serial communication
I've used the arduino uno with the python serial library months ago and some packets got lost in the way. I've been searching about serial communication for arduino and I've been thinking that I could use some parity systems and other things to guarantee that my packets will arrive. First of all, if I use the parity system of the arduino's serial library, how good it will be? I need to send packets like "this button was touched", but ALL packets must arrive, so if some packet fails, I need to send it again.
How to make it possible? I'm thinking about using the parity system of the arduino's library, but I don't think if it's gonna work well.
Can somebody point me some good text about it?

You seem to be freely intermixing three extremely distinct concepts - Arduino "serial" which tends to mean UART-style asynchronous, "packets" a concept for which the previous serial has no inherent support, and then a rather random i2c tag, which is something else entirely (a shared synchronous signalling scheme).  Step one is going to be to sort out what specifically and exactly you are asking about.

Also note that on direct connections such as you likely have, failure is extremely infrequent - if you are seeing it, then likely you either have software which does not service the channel frequently enough to avoid missing data, or else extreme electrical noise.  While protocol-level integrity can be useful (especially where misoperation has real consequences), in a scheme that shouldn't be failing you should spend some time trying to understand why it is.

What baud rate are you using?

There is no way to guarantee that all packets will arrive. The best you can do is to have the receiving system acknowledge receipt of all packets, with enough data within to verify the correctness of the packets.
UART parity is not a good method to verify correctness since it can only detect single-bit errors within a byte; two bit errors will verify correctly, and of course the entire byte may get dropped before it can even get to the receiver.
RFC 916, "RELIABLE ASYNCHRONOUS TRANSFER PROTOCOL (RATP)", describes a TCP/IP-like method of sending data reliably over an asynchronous medium. It's more wordy than just sending a byte containing status changes, but if you need reliability then you need more than that.


text:
Monster moto shield + Arduino +Pololu 12V, 29:1 Gear Motor Encoder hardware problem
Overflow enthusiasts!
I am trying to build a balancing robot with two wheels, using the polulu gear motor as mentioned above. In order to have a strong motor driver,the monster moto shield is used in this project. Here is the components and datasheets which is used.

Components
Li-poly RC Battery 2800mah 11.1V 35C.
Arduino saint smart
2x Pololu 12V, 29:1 Gear Motor w/Encoder
Monster moto shield
Now, back to the issue.. Well, the first problem I encountered was my motor driver. It keeps getting hot after a while, whenever I use it ( I run 2 motors through 1 driver). And the most frustrating part is that the motors can stop for a while, and then restart again ( suspect a hardware reset here). Is there any way this can be solved?, I have checked the datasheet for the monster moto driver but can't understand whether the components are already on the PCB boad or I manually have to add new components like resistors, capacitors and etc. Would be glad if you guys directed me on this issue.
Secondly, The other problem I have is that the motors are going fast CW and slow CCW whenever I reverse direction. I have also seen other ppl getting the same problem as I do and wonder why this happen. Could it be that the cables are to small for the current flow ?
Should I add external components ? Then which components should I use in order to subdue this problem?
Here are some pictures in order to clarify the problem. Mostly using cables to connect inputs and etc. I would be glad if you wonder something and want me to post more information.

pictures:

Code
/*  MonsterMoto Shield Example Sketch
  date: 5/24/11
  code by: Jim Lindblom
  hardware by: Nate Bernstein[![enter image description here][1]][1]
  SparkFun Electronics
 This is really simple example code to get you some basic
 functionality with the MonsterMoto Shield. The MonsterMote uses
 two VNH2SP30 high-current full-bridge motor drivers.

 Use the motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
 function to get motors going in either CW, CCW, BRAKE[![enter image description here][1]][1]VCC, or
 BRAKEGND. Use motorOff(int motor) to turn a specific motor off.

 The motor variable in each function should be either a 0 or a 1.
 pwm in the motorGo function should be a value between 0 and 255.

This code is beerware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.
 */
#define BRAKEVCC 0
#define CW   1
#define CCW  2
#define BRAKEGND 3
#define CS_THRESHOLD 100

/*  VNH2SP30 pin definitions
 xxx[0] controls '1' outputs
 xxx[1] controls '2' outputs */
int inApin[2] = {7, 4};  // INA: Clockwise input
int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {5, 6}; // PWM input
int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)

int statpin = 13;

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

  pinMode(statpin, OUTPUT);

  // Initialize digital pins as outputs
  for (int i=0; i<2; i++)
  {
    pinMode(inApin[i], OUTPUT);
    pinMode(inBpin[i], OUTPUT);
    pinMode(pwmpin[i], OUTPUT);
  }
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  // motorGo(0, CW, 1022e3);
  // motorGo(1, CCW, 1023);
}

void loop()
{
  motorGo(0, CW, 1023);
  motorGo(1, CW, 1023);
  delay(500);
  motorGo(0, CCW, 1023);
  motorGo(1, CCW, 1023);
  delay(50);
  if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) < CS_THRESHOLD))
    digitalWrite(statpin, HIGH);
}

void motorOff(int motor)
{
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  analogWrite(pwmpin[motor], 0);
}

/* motorGo() will set a motor going in a specific direction
 the motor will continue going in that direction, at that speed
 until told to do otherwise.

 motor: this should be either 0 or 1, will selet which of the two
 motors to be controlled

 direct: Should be between 0 and 3, with the following result
 0: Brake to VCC
 1: Clockwise
 2: CounterClockwise
 3: Brake to GND

 pwm: should be a value between ? and 1023, higher the number, the faster
 it'll go
 */
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
  if (motor <= 1)
  {
    if (direct <=4)
    {
      // Set inA[motor]
      if (direct <=1)
        digitalWrite(inApin[motor], HIGH);
      else
        digitalWrite(inApin[motor], LOW);

      // Set inB[motor]
      if ((direct==0)||(direct==2))
        digitalWrite(inBpin[motor], HIGH);
      else
        digitalWrite(inBpin[motor], LOW);

      analogWrite(pwmpin[motor], pwm);
    }
  }
}

regards, Volkan

How are the orange and while wires connected?

I dont have high rep , so I cant post more than 2 pictures, I have edited my post, Now you can clearly see my battery and its connector above. I have no componenets between the battery and the motor driver its just cables

I use JST connectors from battery to the blue screw terminals


text:
Buttons and LED
I am creating a program that turns on and off an led. When two buttons are considered "high". But there is a twist, The first button needs to stay "high" until the second button is pressed and the led turns on. Here is my code so far.
// Boolean logic for Button Switch
boolean currentState = LOW;    //stroage for current button state
boolean lastState = LOW;      //storage for last button state
boolean ifcondState = LOW;    //storage for the current state of the ifturn  (off/on)

// set pin numbers:
const int buttonPinA = 3;     // the number of the pushbutton pin
const int buttonPin1 = 4;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int ifcond =  12;      // the number of the ifcond pin
const int ifturn =  11;      // the number of the ifturn pin

// variables will change:
int buttonStateA = 0;         // variable for reading the pushbutton status
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonStateIf = 0;         // variable for reading the If Condition status

void setup() {
//initialize Serial connection
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinA, INPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
// If Condictional Pin
pinMode(ifcond, OUTPUT);
// If Turnon Pin
pinMode(ifturn, INPUT);

}

void loop() {
  // read the state of the pushbutton values:
  currentState = digitalRead(buttonPinA);
  buttonState1 = digitalRead(buttonPin1);
  buttonStateIf = digitalRead(ifturn);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (currentState == HIGH && lastState == LOW){    //  if button has just been pressed
    Serial.println("pressed");
    //delay(1);

    //toggle the state of the ifcond
    if (ifcondState == HIGH){
      digitalWrite(ifcond, LOW);
      ifcondState = LOW;
    }
    else {
      digitalWrite(ifcond, HIGH);
      ifcondState = HIGH;
    }
  }
  lastState = currentState;

  if (ifturn == HIGH && buttonState1 == HIGH) {
    digitalWrite(ledPin, HIGH);
  }
  else ();
  digitalWrite(ledPin, LOW);
}

I have Pin 12 (ifcond) And pin 11(ifturn) Jumped together. Pin 12 acts like a button to pin 11, When it goes high pin 11 reads the change.
The code works like this, When ButtonpinA goes high  pin 12 goes high and stays high until the next button push. This is the part that doesn't work Pin 11 should read if pin 12 if high or not. If it reads high and Button1 is also high it should turn on ledpin which it does not.
I am sorry for any confusion Thanks

I can't understand what you want it to do. Also; else (); is rather odd. You also might want to look into debouncing the buttons.

I want to be able to press and release Button A and then be able to press button one whenever i want to turn the led on

if (ifturn == HIGH && buttonState1 == HIGH) {
  digitalWrite(ledPin, HIGH);
}
else ();
digitalWrite(ledPin, LOW);

I think you have made a small mistake here.
What you are saying there is "If both these inputs are high then turn on the LED - otherwise don't do anything", and immediately after that "Turn off the LED".
So the LED is turned on when they are both high, and immediately turned off again, so fast you never see the LED lighting up at all.
I think what you meant to have was:
if (ifturn == HIGH && buttonState1 == HIGH) {
  digitalWrite(ledPin, HIGH);
} else {
  digitalWrite(ledPin, LOW);
}

That way it will turn the LED on if both are HIGH, otherwise it will turn the LED off only if the test for both being high fails.


text:
Unable to send data from Processing to Arduino through ports
I'm just beginning to use Processing along side with Arduino and need help linking the two. Just to get started, I just wanted to send a single character (eventually strings) to the Arduino and have the Arduino light up a matrix if the Arduino receives the data.
Here's my code for the Arduino (I'm using an Arduino Uno):
#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

// Set up the matrix
#define CLK 8
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

int incomingByte = 0;   // for incoming serial data

void setup() {

  Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  matrix.begin();
}

void loop() {
    if(Serial.available() > 0) {
    incomingByte = Serial.read();

    // Print a white "Done!" to the matrix
    matrix.setCursor(1, 0);
    matrix.setTextSize(0);
    matrix.setTextColor(matrix.Color333(7, 7, 7));
    matrix.print("Done!");

  }
}

And here's the code for Processing:
// Example by Tom Igoe

import processing.serial.*;

// The serial port:
Serial myPort;

// List all the available serial ports:
println(Serial.list());

// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[1], 9600);

// Send a capital "A" out the serial port
myPort.write(65);

I run the processing sketch and then upload the code to the Arduino, but get nothing. The Arduino is using COM3 and I believe the Processing sketch is too, but that may be where I'm messing up.
If I open up the serial monitor and send some data to the Arduino that way, then the LED lights up fine, but only when I do it through that.
Any help would be appreciated. Thanks!

Please specify what Arduino board you are using. Boards like the Uno reset when you open the serial connection and won't respond till the bootloader has exited. I believe it takes 1-2 seconds.

Just edited the post to specify, sorry about that. I'm using an Arduino Uno.

Your code seems to be assuming that the Arduino is on the first port of the list you fetch, which doesn't sound like it is the case.  Anyway, you should first make sure you can trigger your code with the serial monitor in the IDE.

I can easily trigger the code with the serial monitor. I've tried it with Processing going to Serial.list()[0] and Serial.list()[1] but have gotten no results either way.

What's the output of println(Serial.list());?

When you open a serial connection to Arduino Uno the atmega328 microcontroller is usually reset(this depends if the OS is configured to toggle the DTR serial control signal on/off when a port is opened). Just after a reset the bootloader (optiboot) runs to see if you are trying to upload a new sketch. If the bootloader doesn't receive any meaningful communication it will start your sketch after ~1 sec. All communication sent to the serial port while the bootloader is running is lost.
When you use the serial monitor you are too slow to notice the 1 second where the board won't respond to your commands. But the processing sketch is another story.
The easiest fix will be to insert a delay after you open the serial port and before you send any data.
// Wait 1.2 sec
int start = millis();
while (millis() - start < 1200);

If you would rather use a hardware fix you can connect a 10uF capacitor between RESET and GND pins that will prevent the board from being reset by the usb to serial converter.

The resest-on-open behavior is often a configurable property of the host operating system's serial device, but even if configured not to happen it easily could if the board is moved to a different install.

I updated the answer to be more speific


text:
Is it bad coding practice to design a buffer using pointers?
I coded a ring buffer for my Arduino to buffer data from either the SPI or TWI ports. In the .h file I used a pointer for the buffer:
typedef uint8_t *ring_buffer_t;
typedef uint8_t ring_count_t;
typedef uint8_t ring_index_t;
typedef uint8_t ring_size_t;

typedef struct ring_t
{
    ring_buffer_t buffer;
    ring_count_t  count;
    ring_index_t  head;
    ring_index_t  tail;
    ring_size_t   size;
}rint_t;

int ring_init(ring_t *r, ring_buffer_t buffer, ring_size_t size);

// other function prototypes to add and remove from the ring buffer

There is more code to handle adding and removing from the buffer, but I am simplifying here. Then in my .c file I have:
#include<string.h>

void ring_init(ring_t *r, ring_buffer_t buffer, ring_size_t size)
{
    r->buffer = buffer;
    r->size   = size;
    r->head   = 0;
    r->tail   = 0;
    r->count  = 0;

    // clear out the buffer memset cheaper by 12 bytes rather than for loop
    memset((void *)r->buffer, 0, r->size);
}

Then somewhere in code where the ring buffer is going to be used:
In SPI.h ...
#define MAX_BUFFER_SIZE 32
ring_t  rx_ring;
uint8_t spi_rx_buffer[MAX_BUFFER_SIZE];

#define MAX_BUFFER_SIZE 32
ring_t  tx_ring;
uint8_t spi_tx_buffer[MAX_BUFFER_SIZE];

In SPI.c ...
void spi_init( ... )
{
    ring_init(&rx_ring, spi_rx_buffer, MAX_BUFFER_SIZE);
    ring_init(&tx_ring, spi_tx_buffer, MAX_BUFFER_SIZE);

    // initialize other spi parameters
}

Are there any issues with my code that are obvious that I am not seeing? I ask because I ran the code and it works, but I feel I am doing something wrong. I can code in C and remember something about malloc() for dynamic memory allocation, just not sure if what I am doing qualifies. Or should this work creating a buffer of some defined size?
Thanks for any help or ideas.
EDIT: 07/27/2014 Added code to try and make what I am trying to do clear. Let me know, thanks.

Don't bother with malloc unless you need to. If you explicitly define your buffer before hand then you can use avr-size to check your SRAM usage.
Also the C compiler automatically adds code to initialise global variables to 0, so you don't need ring_init if your define the array explicitly. See https://stackoverflow.com/questions/2218254/variable-initialization-in-c for initialisation comments. Even if buffer was filled with non-zeros it wouldn't matter because it should be written to before being read from.
If you change the ring buffer from chars to ints, etc. you will have to change memset, as it assumes chars.
Will MAX_BUFFER_SIZE change? If not, you could put the buffer in ring_t.

Simple answer: No, it isn't bad practice at all. I write with pointers all the time. Pointer referencing usually compiles to more efficient code than does array referencing.
But:
It looks like you've confused a pointer with the thing it is supposed to point to. The member you call 'buffer' is declared as pointer to unsigned byte. It doesn't appear to get initialized anywhere; it should be initialized with the address of an array of unsigned bytes (at least) as large as your ring buffer needs to be. I don't see this in anywhere in your code.
As others have described, the buffer could be allocated at run time with malloc() (but it's best not to save malloc() & free() for things you have to create and destroy on the fly; or direct the compiler to allocate it before your program gets control, with something like:
#define RINGBUFSIZE 32

uint8_t ring_buffer_memory[RINGBUFSIZE];

and initialize your pointer to it with:
r->buffer = ring_buffer_memory;

This will initialize your pointer to the first of (in this case) 32 bytes of zeroed memory reserved for the ring buffer. In your code, it's quite likely the pointer contains 0, thus pointing to memory location zero and is definitely not what you mean to do.
A word on variable names - adopt a convention for naming your variables that help a future reader (probably you!) understand/remember what that variable is for. In this case I'd probably use ringBuf for the array, and pRingBuf for its pointer. As a new reader of this code, I'd find it pretty inconvenient to have to have to remember that buffer is really a pointer (and what the heck was the buffer called!?).

Not enough info. You have a struct ring_t that has a pointer to an array of uint8_t's. In your ring_init method, your code assumes that the pointer points to valid memory. If you have not explicitly pointed the pointer to a block of memory, either stack memory or heap memory, then yes, there is a problem.
You COULD malloc the ring buffer, or you could create it as a global variable. If you've only got one ring buffer it's probably just as well to make the buffer a global and set the pointer in your setup method.

In my function ring_init the second argument "ring_buffer_t buffer" I expect an array to be referenced. So the first argument would be a ring_t struct, the second argument an uint8_t array, and the last argument would be the size of that array. Does that help?

Your description still isn't clear. Post the code that defines your ring_t struct, the array, and the code that calls the method.

I adjusted the code above to try and make it clear what I am trying to do. If you need it I can post all the code I have but we are talking  5 files and over 450 lines of code, though I could take out the comments and whitespace. Still would be looking at around 250 lines of code.


text:
Program ATtiny13 - 20PU
I'm trying to program my ATtiny 13 - 20PU. An it seems to work, but there is no action upon the "delay" command. If on the sketch below I comment out the "High" line, my led is off all the time and whenever I have a Pin 4 High, it's on all the time! Basically this seems to be a frequency/fuse/bootloader problem and made me think the upload was broken.
I added a led between the tiny's pin 3 (digital pin 4) and ground with a 1k current limiting resistor. This one is for testing with the attached sketch.
I also tried this breadboard circuit, which gives exactly the same results.
Upon upload to the tiny I get this:
Sketch uses 380 bytes (37%) of program storage space. Maximum is 1,024 bytes.
Global variables use 8 bytes of dynamic memory.

(Everybody warns about 2 errors occuring upon a proper upload - I don't get those).
My boards.txt look like this:
menu.cpu=Processor
menu.clock=Clock

attiny.name=ATtiny
attiny.bootloader.tool=arduino:avrdude
attiny.bootloader.unlock_bits=0xff
attiny.bootloader.lock_bits=0xff
attiny.build.core=arduino:arduino
attiny.build.board=attiny
attiny.upload.tool=arduino:avrdude

attiny.menu.cpu.attiny45=ATtiny45
attiny.menu.cpu.attiny45.upload.maximum_size=4096
attiny.menu.cpu.attiny45.build.mcu=attiny45
attiny.menu.cpu.attiny45.build.variant=tiny8

attiny.menu.cpu.attiny85=ATtiny85
attiny.menu.cpu.attiny85.upload.maximum_size=8192
attiny.menu.cpu.attiny85.build.mcu=attiny85
attiny.menu.cpu.attiny85.build.variant=tiny8

attiny.menu.cpu.attiny44=ATtiny44
attiny.menu.cpu.attiny44.upload.maximum_size=4096
attiny.menu.cpu.attiny44.build.mcu=attiny44
attiny.menu.cpu.attiny44.build.variant=tiny14

attiny.menu.cpu.attiny84=ATtiny84
attiny.menu.cpu.attiny84.upload.maximum_size=8192
attiny.menu.cpu.attiny84.build.mcu=attiny84
attiny.menu.cpu.attiny84.build.variant=tiny14

attiny.menu.clock.internal1=1 MHz (internal)
attiny.menu.clock.internal1.bootloader.low_fuses=0x62
attiny.menu.clock.internal1.bootloader.high_fuses=0xdf
attiny.menu.clock.internal1.bootloader.extended_fuses=0xff
attiny.menu.clock.internal1.build.f_cpu=1000000L

attiny.menu.clock.internal8=8 MHz (internal)
attiny.menu.clock.internal8.bootloader.low_fuses=0xe2
attiny.menu.clock.internal8.bootloader.high_fuses=0xdf
attiny.menu.clock.internal8.bootloader.extended_fuses=0xff
attiny.menu.clock.internal8.build.f_cpu=8000000L

attiny.menu.clock.external8=8 MHz (external)
attiny.menu.clock.external8.bootloader.low_fuses=0xfe
attiny.menu.clock.external8.bootloader.high_fuses=0xdf
attiny.menu.clock.external8.bootloader.extended_fuses=0xff
attiny.menu.clock.external8.build.f_cpu=8000000L

attiny.menu.clock.external16=16 MHz (external)
attiny.menu.clock.external16.bootloader.low_fuses=0xfe
attiny.menu.clock.external16.bootloader.high_fuses=0xdf
attiny.menu.clock.external16.bootloader.extended_fuses=0xff
attiny.menu.clock.external16.build.f_cpu=16000000L

attiny.menu.clock.external20=20 MHz (external)
attiny.menu.clock.external20.bootloader.low_fuses=0xfe
attiny.menu.clock.external20.bootloader.high_fuses=0xdf
attiny.menu.clock.external20.bootloader.extended_fuses=0xff
attiny.menu.clock.external20.build.f_cpu=20000000L

#################################################
attiny.menu.cpu.attiny13=ATtiny13
attiny.menu.cpu.attiny13.upload.maximum_size=1024
attiny.menu.cpu.attiny13.build.mcu=attiny13
attiny.menu.cpu.attiny13.build.variant=core13

attiny.menu.clock.internal96=9.6MHz (internal)
attiny.menu.clock.internal96.bootloader.low_fuses=0x7A
attiny.menu.clock.internal96.bootloader.high_fuses=0xff
attiny.menu.clock.internal96.build.f_cpu=9600000L
################################################

attiny.menu.clock.internal48=4.8MHz (internal)
attiny.menu.clock.internal48.bootloader.low_fuses=0x79
attiny.menu.clock.internal48.bootloader.high_fuses=0xff
attiny.menu.clock.internal48.build.f_cpu=4800000L
################################################

And I choose the settings: Board ATtiny, Processor ATtiny13, Clock 9.6 MHz (internal), Port Arduino Uno (same as when I upload the ISP sketch), Programmer Arduino as ISP. I upload by clicking "Upload using Programmer".
Arduino Software is 1.6.4, the programmer Arduino is an Uno SMD edition.
I used this programmer and this tutorial for smeezkitty core13.
I'm trying to upload this sketch:
// Blink sketch to test ATtiny Chips

//       ATMEL ATTINY13 / ARDUINO
//
//                 +-\/-+
// ADC0 (D 5) PB5 1|*   |8 Vcc
// ADC3 (D 3) PB3 2|    |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3|    |6 PB1 (D 1) PWM1
//            GND 4|    |5 PB0 (D 0) PWM0
//                 +----+

const int LED_PIN = 4; // digital pin
const int DELAY_TIME = 1000; // time between blinks [ms]

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, LOW);
  delay(DELAY_TIME);
  digitalWrite(LED_PIN, HIGH);
  delay(DELAY_TIME);
}

Trying to burn a bootloader with the same settings as uploading to the tiny and then tools -> burn bootloader, get's me the error:
"efuse" memory type not defined for part "ATtiny13"
Error while burning bootloader.

Skimming through the data sheet I noticed that the tiny13 - 20PU (the 20) stand for 20 MHz,... theoretically one should be able to downclock them to the ordinary 10 MHz, but maybe this is my problem?

Most likely a mistake in the construction of your ISP stripboard shield. I'd check for dry joints, uncut cuts, etc.

I checked the connections many times now. And since nothing happens, when I try to upload using a breadboard-version, I guess there is some software issue, or I do something wrong.

The last time I programmed an ATtiny (an 85 in my case) using the ArduinoISP sketch, I had to set the IDE to use the right programmer: Tools -> Board -> ATtiny85 (w/ Arduino as ISP) and
Tools -> Programmer -> Arduino as ISP - the messages you are seeing suggest the IDE is targetting an STK500 programmer. This may be right as several programmers emulate an STK500 - but it might be worth checking/experimenting with this.

Yeah, as mentioned above, I've used ATtiny13 and Programmer Arduino as ISP. I have no clue, what is going wrong there. Or even how I can debug it further.

Arduino_ISP emulates the avrisp tool. You may try to add something like attiny.upload.protocol = avrisp to your boards.txt.

Thanks for the hints, I found out, that everything was uploading correctly, but only the delay command doesn't work!

There was some mistakes in the boards.txt it seems. After finding a very detailed and extensive boards file here, I modified it to have neat and tidy categories and is easier to use to become a working boards.txt. I had to burn the bootloader once to set the fuses right. After that everything works like a charm for 3 ATtiny13! No warnings or errors. This is used with Arduino 1.6.4. The folder tree is ~Arduino/hardware/attiny/avr/cores/core13 and ~Arduino/hardware/attiny/avr/boards.txt
# boards.txt for Arduino 1.6.4

menu.flag=GCC Flags
menu.cpu=Processor
menu.clock=Clock

attiny13.name=ATtiny13
attiny13.upload.tool=arduino:avrdude
attiny13.upload.using=arduino:usbtiny

attiny13.bootloader.tool=arduino:avrdude

attiny13.menu.cpu.attiny13=ATtiny13
attiny13.menu.cpu.attiny13.upload.maximum_size=1024
attiny13.menu.cpu.attiny13.upload.maximum_data_size=64
attiny13.menu.cpu.attiny13.build.mcu=attiny13
attiny13.menu.cpu.attiny13.build.core=core13
# attiny13.menu.cpu.attiny13.build.variant=core13

#################################################
############## clock speeds #####################
#################################################

#### 9.6 MHz
############
attiny13.menu.clock.t13_9M6=9.6MHz (internal clock, Preserve EEPROM, BOD disable)
attiny13.menu.clock.t13_9M6.bootloader.low_fuses=0x3A
attiny13.menu.clock.t13_9M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_9M6.upload.speed=57600L
attiny13.menu.clock.t13_9M6.build.f_cpu=9600000L

#### 9.6 MHz - 2.7V
attiny13.menu.clock.t13_9M6_bod=9.6MHz (internal clock, Preserve EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_9M6_bod.bootloader.low_fuses=0x32
attiny13.menu.clock.t13_9M6_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_9M6_bod.upload.speed=57600L
attiny13.menu.clock.t13_9M6_bod.build.f_cpu=9600000L

#### 4.8 MHz - 2.7V
attiny13.menu.clock.t13_4M8_bod=4.8 MHz (int 4.8 MHz clock, Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_4M8_bod.bootloader.low_fuses=0x31
attiny13.menu.clock.t13_4M8_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_4M8_bod.upload.speed=57600L
attiny13.menu.clock.t13_4M8_bod.build.f_cpu=4800000L

#### 1.2 MHz
attiny13.menu.clock.t13_1M2=1.2 MHz (int 9.6 MHz divided by 8,Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_1M2.bootloader.low_fuses=0x2A
attiny13.menu.clock.t13_1M2.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_1M2.upload.speed=9600L
attiny13.menu.clock.t13_1M2.build.f_cpu=1200000L

#### 600 kHz
attiny13.menu.clock.t13_0M6=600 kHz (int 4.8 MHz divided by 8, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_0M6.bootloader.low_fuses=0x29
attiny13.menu.clock.t13_0M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_0M6.upload.speed=9600L
attiny13.menu.clock.t13_0M6.build.f_cpu=600000L

## 128 kHz
attiny13.menu.clock.t13_128k=128 KHz (internal watchdog oscillator)
attiny13.menu.clock.t13_128k.bootloader.low_fuses=0x7B
attiny13.menu.clock.t13_128k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_128k.upload.speed=250
attiny13.menu.clock.t13_128k.build.f_cpu=128000L

## 16 kHz
attiny13.menu.clock.t13_16k=16 KHz (internal watchdog oscillator, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_16k.bootloader.low_fuses=0x2B
attiny13.menu.clock.t13_16k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_16k.upload.speed=250
attiny13.menu.clock.t13_16k.build.f_cpu=16000L

##-----------------------------------
##--------- compiler flags ----------
##-----------------------------------

attiny13.menu.flag.Os=Default
attiny13.menu.flag.Os.compiler.c.extra_flags=
attiny13.menu.flag.Os.compiler.c.elf.extra_flags=
attiny13.menu.flag.Os.compiler.cpp.extra_flags=

attiny13.menu.flag.Os_flto=Default -flto
attiny13.menu.flag.Os_flto.compiler.c.extra_flags=-Wextra -flto
attiny13.menu.flag.Os_flto.compiler.c.elf.extra_flags=-w -flto
attiny13.menu.flag.Os_flto.compiler.cpp.extra_flags=-Wextra -flto

attiny13.menu.flag.O1=-O1
attiny13.menu.flag.O1.compiler.c.extra_flags=-O1
attiny13.menu.flag.O1.compiler.c.elf.extra_flags=-O1
attiny13.menu.flag.O1.compiler.cpp.extra_flags=-O1

attiny13.menu.flag.O1_flto=-O1 -flto
attiny13.menu.flag.O1_flto.compiler.c.extra_flags=-O1 -Wextra -flto
attiny13.menu.flag.O1_flto.compiler.c.elf.extra_flags=-O1 -w -flto
attiny13.menu.flag.O1_flto.compiler.cpp.extra_flags=-O1 -Wextra -flto

attiny13.menu.flag.O3=-O3
attiny13.menu.flag.O3.compiler.c.extra_flags=-O3
attiny13.menu.flag.O3.compiler.c.elf.extra_flags=-O3
attiny13.menu.flag.O3.compiler.cpp.extra_flags=-O3

attiny13.menu.flag.O3_flto=-O3 -flto
attiny13.menu.flag.O3_flto.compiler.c.extra_flags=-O3 -Wextra -flto
attiny13.menu.flag.O3_flto.compiler.c.elf.extra_flags=-O3 -w -flto
attiny13.menu.flag.O3_flto.compiler.cpp.extra_flags=-O3 -Wextra -flto

Please somebody publish it with easy-to-install json config https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.6.x-package_index.json-format-specification

The "efuse error"  on burning the bootloader is described in the article you refer to and a solution is given there as well.
It occurs when the attiny13 is defined in the same group as the attiny25/45/85 as the former has no efuse and the latter do.
Giving the attiny13 its own menu entry in the IDE -as described in that article- should solve that.

Welcome to Arduino SE! Can you please edit your answer to explain how this is done? Thanks!


text:
Gui Scale on Linux HD display
I use Fedora 24/25 and now Ubuntu 17.04 Gnome on my Lenovo Yoga 900, which has an extremely high pixel density display. For these situations on Mac and Windows, I find a gui.scaling option in the Arduino settings. However, on Linux there is no such option, and entering it in ~/.arduino15/settings.txt does not have any effect.
The version I use is Arduino 1.6.4 (now 2.1.0.5) from the Fedora (Ubuntu) repos. Is the scaling gui option not implemented on linux? Or is there some fix for this?
On the physical display the following screenshot has an approximate width of 4cm -> the green buttons are not usable at all!

Maybe related to this issue.

Not really, as the user there asks for buttons to customize the UI. I am missing the buttons, which should already be there! Or similarly, I've tried modifying the uiscale via the preferences file, also with no result.


text:
Can I apply a Kalman filter to DHT11 data?
I want to apply a Kalman Filter to the humidity data which I retrieve of the DHT11.
How can I do that?

Learn about the kalman filter and what it does. It requires a certain understanding of what it is, what it is good for and why you would eventually use it. It seems to me, that at the moment this isn't your strongest topic.
Thereafter, figure out which !multiple! sensor values you have, since only with a "model" and an "observation" a filter of this kind makes sense in the first place.
To specifically adress your question: you can apply any filter to any data. The hidden question, if it makes sense in this case is not trivial to answer, since you didn't exactly provide the vast information. My guess is, you only have this one sensor, and it would be (at this state of knowledge) a reasonable idea to use a bandpass filter of sorts instead.

Hi, thanks for your reply. I have some knowledge about Kalman filter in theory. But i didnt yet apply anwhere and  I have some data in my figures. The humidty is acting +-%5 and I want filter this data. As i see on internet, some people use Kalman filter to temperature and humidity data for best results. I can research about applications of Kalman filter. May be someone help me for earn time.

As I said before, you didn't give enough information for anything. Please state a specific question. If you know, what a kalman filter is, you need to think about what your observation is, and what your model is. Then you need to state the covariances of both of these and then you implement the filter.
However, it seems to me, a lowpass is a better fit for a one-sensor problem.

Thanks, may be I should basicaly implement a smoothing filter for DHT data.

That's what I suggested. I think a kalman filter is a very nice tool, but it has it's place and it's nowadays used, where it really has no place at all. Just because it became famous, doesn't mean it does wonders for each problem. But still, all of this is guessing, since you didn't specify, what resources you have, or what your goal is. If you have many sensors and a lot of time, a kalman filter might just be the thing!

Btw: If you calculate a discrete time kalman filter for a linear system with only one measurement, the formulae automatically yield a simple lowpass filter (the steady state KF). This means, in the sense of the least quadratic error, it is best to just use a lowpass.

Hi, I applied a smoothing filter with samples of 100 from DHT data. This filter is already work as recursive and the results are very good for me. Anymore humidity data is coming without noise and peak. This is enough  for now. May be i can try discrete time kalman filter for my filter in the coming days.