text:
Problems with L293D

The motor are not rotating in the above circuit . Or rather the Voltage between the two Motor Terminal is zero. I have checked the Pin 10 & 11 and Pin 12 & 13. They are fine and produces desired Voltage.
When I have earlier connected the circuit only to one motor then it worked[ there were no motor right, Pin 12 and Pin 13]. But now, it's not.
What's the problem? The code in the arduino is as follows:
const int echo = 7;// connected to ultrasonic sensor's echo
const int trig = 8;// connected to ultrasonic sensor's trig
const int Right1 = 10;
const int Right2 = 11;
const int Left1 = 12;
const int Left2 = 13;
void setup() {
  pinMode(echo, INPUT_PULLUP);
  pinMode(trig, OUTPUT);
  pinMode(Right1, OUTPUT);
  pinMode(Right2, OUTPUT);
  pinMode(Left1, OUTPUT);
  pinMode(Left2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(5);
  digitalWrite(trig, LOW);
  int duration = pulseIn(echo, HIGH);
  int cm = microsecondsToCentimeters(duration);
  if (cm > 4)
  {
    digitalWrite(Right1, HIGH);
    digitalWrite(Right2, LOW);
    digitalWrite(Left1, HIGH);
    digitalWrite(Left2, LOW);
  }
  else
  {
    digitalWrite(Right2, HIGH);
    digitalWrite(Right1, LOW);
    digitalWrite(Left1, LOW);
    digitalWrite(Left2, HIGH);
  }
  delay(50);
  Serial.println(cm);
}
long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}

Try these steps

Increase the delay of 50ms to a longer time.

If that fails to work try,
2.Running the motor by just directly connecting the terminal to the 9V battery which you are using.
If the motor runs then most probably the motor requires more current than what the L293D can output which as per the data sheet is 600mA. A solution to this would be using a higher current motor driver like L298N.
If the motor doesn't run directly by the battery then well change the battery to one which can supply enough current.


text:
General Question about fast Serial Communication and Arduino
I'm looking for a fast (and safe, in terms of stability) way to send sensor data from an Arduino UnoR3 in real time to a Computer (in my case a MacBook Pro) with a sample rate of at least 1kHz.
I tried following:

Sending sensor values with the related timestamp (in microseconds):
I use 7 bytes for each sample [1 Header byte, 2 bytes for the sensor value (10/(16)bit-Int), and 4 bytes for a 32-bit unsigned long (time in microseconds)] and send them right away.
On the receiving end i mainly use Processing (Im relatively new to Processing though): Reading the bytes in, converting them in integers and safe them in a file or plot them.

For sampling rates of 1sample/10ms my code runs smooth and i even can plot the data in "real-time".
For higher frequencies i ran into following problems:

If i want to plot things, my peripherals freeze and program stops after some time. I have no clue why... maybe serial buffer overflow??
If i just save the data in a text file (without plotting) it works but with a delay of around 20-30seconds on total sampling times of 10seconds (10000 samples).
Meaning that somewhere seems to be a bottleneck and i cant keep up with the sent samples from the Arduino.
Is it possible that the serial bus is the bottleneck here? How can i speed things up? (I'm working with a baudrate 115200bits/s and also 230400bits/s)

How can i improve this while still be able to process data in almost real-time (e.g plotting). Is this even possible or do you recommend logging the data in a text file first and then plot?
Will it helps to send the data in packages (10samles = 70bytes)?
I added a timestamp on each sample, since i observed some delay between the actual sensor measurement and the input on the receiving end. I thought that would allow me to plot and postprocess accurately in "real"-time (with a little delay). Any other ideas?
I would appreciate some input and advice!
Thanks in advance!

You might be interested in the Telemetry library in combination with the command line interface for plotting the data (among other things). It is exactly designed for this sort of things ; also, it is well tested and reliable (I can send without issues data at maximum serial port rate). Arduino library is here Full disclaimer: I am the author of both

You are sending data at ~70kbps. Provided you use serial rate greater than this (115.2 kbps or faster on the Arduino) there should be no problem, assuming you samples are processed quickly enough. This seems to be the case.
Your problem seems to be on the Mac. With a quad core CPU on a fast multitasking machine this should not be an issue. If you are having problems this would be in how you are processing the data. I am not familiar with Processing but you could do this in any language. You need to separate the data logging from the processing and display task. This could be as simple as running a logger and piping the data into a display program.
This is not an Arduino issue (or even a Mac issue), you should ask on https://stackoverflow.com/. NOTE if you want help there you will need to give more detail of the code you are running in the Mac.

So i guess i'm more or less on the right track. Thanks for clearing things up a bit!

source: Stack Exchange

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

sort: votes


text:
How to send the MFRC522 RFID module into sleep mode?
I'm trying to get the power consumption of a MFRC522 RFID module down, currently while running it consumes about 4mA. There should be a way to put it into sleep mode, I just can't find any documentation on it. I'm using the module with a arduino currently if that helps; and this is the module itself : MFRC522

http://www.nxp.com/documents/data_sheet/MFRC522.pdf
Look at section 8.6.2   Soft power-down mode.

I still don't get how to implement this in my arduino code.

First, that wasn't your question. Secondly, you didn't say how you connected it. Are you using SPI or UART? What library are you using?

I didn't know there was anything other than an SPI library for it; but currently using SPI.

Two questions, one answer. I'm done helping you.

Sam, it sounds like you're asking two different questions: "How do I put the MFRC522 into sleep mode?" and "How do I send commands, such as the soft power-down command, from an Arduino to the MFRC522?". I suggest you open a separate, independent question to ask that second question, as recommended by http://meta.stackexchange.com/questions/39223/one-post-with-multiple-questions-or-multiple-posts .

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


text:
Infra Red Send Hex Code
I am using an arduino nano with the standard arduino IR remote library. For now I am using the Irrecord sketch. However, I want to have some pre - programed codes for remotes I don't have. I found this site which apparently has the hex of an endless number of remotes. When I use the regular IR decode, the hex of any remote I use, is only a couple of characters.  However at this site the typical amount is at least 100.
This is the hex for a Toshiba model's sleep command:
0000 006c 0022 0002 0157 00ab 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0016 0016 0040 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 05f0 0157 0055 0016 0e52
So, finally after all that if you are still with me my question is, how would I send that command with the IRRemote library.

That seems to be pronto hex format for codes. A quick google showed this explanation: http://www.remotecentral.com/features/irdisp2.htm and this sample code: https://gist.github.com/probonopd/5793692

Is there some converter I could use to convert it into regular or do I have to deal with it directly.

I don't know what you mean by regular. The pronto codes are just durations of on and off. So you don't need to know which code is used exactly. The code that I linked has an example sketch (https://gist.github.com/probonopd/5793692#file-sendprontohex-ino) which takes codes from serial and sends them. This could be easily adjusted to send the codes from an array. The function that does the sending is ir_start in loop

I mean, is there a way I could integrate that into the example in the irremote library?

It can be made into its own lib or probably added to that library, but this is beyond the scope of this answer. If you make it work as a regular sketch then can read about creating libraries and make one. That would be the simplest way instead of integrating with the existing one.


text:
Arduino PWM LED blinking on four pins, each pin's intensity and time period based on the previous pin
I am trying to make four LEDs glow using my Arduino, based on some relationship between them in terms of brightness and the time for which LEDs glow.
For example, the relationships are:
pin_3_value = 250  // LED 1 intensity
pin_5_value = 1.2 * pin_3_value // LED 2 intensity
pin_7_value = 1.1 * pin_5_value  // LED 3 intensity
pin_13_value = 0.59 * pin_7_value  // LED 4 intensity

time_till_led_1_on = 100
time_till_led_2_on = time_till_led_1_on * 1.2
time_till_led_3_on = time_till_led_2_on * 2.4
time_till_led_4_on = time_till_led_3_on * 1.2

I understand that only a fixed set of values are permitted as input to the analogWrite(). Is there some way to implement this relationship on the Arduino? I cannot use a digitalWrite(), as the output of PWM pins are used for something else; making the LED glow is just for testing purposes.
The code I have written so far:
// Brightness level for the four pins

int Brightness_1 = 255;
int Brightness_2 =  Brightness_1 * 2;
int Brightness_3 = Brightness_2 * 3;
int Brightness_4 = Brightness_3 * 4;

// Delay or time between  LED turn off and next LED turn ON

int Delay_1 = 500;
int Delay_2 =  Delay_1 * 1.1;
int Delay_3 = Delay_2 * 1.2;
int Delay_4 = Delay_3 * 1.3;

int pins[] = { 2, 4, 5, 7 }; // An array of pin numbers

void setup()
{
    int i;
    for (i = 0; i < 4; i++) // The array elements are numbered from 0  to num pins - 1
        pinMode(pins[i], OUTPUT); // Set each pin as an output
}

void loop()
{
    // Loop through each pin...
    analogWrite(pins[0], Brightness_1 ); // Turning it on,
    delay(Delay_1);                      // pausing,
    analogWrite(pins[0], 0);             // and turning it off.

    analogWrite(pins[1], Brightness_2); // Turning it on,
    delay(Delay_2);                     // pausing,
    analogWrite(pins[1], 0);            // and turning it off.

    analogWrite(pins[2], Brightness_3); // Turning it on,
    delay(Delay_3);                     // pausing,
    analogWrite(pins[2], 0);            // and turning it off.

    analogWrite(pins[3], Brightness_4); // Turning it on,
    delay(Delay_4);                     // pausing,
    analogWrite(pins[3], 0);            // and turning it off.
}

How can I make this work?

I see this is an old question, and before going into it, I was going to see how you went with coming to a solution. There are several things about this. 1) you're setting the values to a fixed previous value, you'll need to use functions or at the least pointers to retrieve each value dynamically, and 2) ditch the delays unless you're after a fixed rate each loop (again each one is indefinitely a fixed value). Also some indication of what you're expecting it to look like would help. Is it a Knight Rider forward and backward swipe you're after, or one direction only?


text:
How to learn enough C++ to program Arduino?
I am an experienced web developer, but my C++ skills are very basic. I struggle with the concepts because it is so different from something like Javascript (which I already know). I do not have a lot of time to learn C++, and I only need to know enough to play with Arduinos.
Are there any good resources out there for learning C++ that is specifically geared towards Arduino programming, and is there anything interactive like Codecademy?

Bad news: Arduino uses C++. And C++ is harder than C.

My bad. Like I said I have done a little Arduino programing but clearly I know very little.

@IgnacioVazquez-Abrams - Good news:  ANSI C will still compile with the Arduino IDE.

Well I would like to learn whatever the Arduino IDE uses as default and whatever else most people use.

@Comintern: And yet most of the Arduino libraries use C++.

Perhaps this question would be better if you explained what concepts confuse you. After you get down the basic C++ syntax, it's only a matter of learning the Arduino libraries. And for Codecademy: it's generally a good idea to get an Arduino book since they cover basic C++, electronics, and the usage of the Arduino libraries and how they all relate to each other.

If I were you I'd take the high road.
I was in your shoes a while ago and I didn't know how to approach Arduino. I was very lucky that I came across a book written by the famous Jack Purdum, "Learn C programming for the Arduino". It is written by a retired Purdue University professor who is well known for his extremely easy to learn teaching method. He has another
I only knew MATLAB and Simulink before starting this book. This book is amazing. It was extremely easy to follow. I now have no difficulty programming Arduino in the correct way. This book trains you to optimize everything which is very crucial with the limited resources on Arduino boards.
I suggest C instead of C++. It is the language of choice for programming embedded system. It is said to be low level, but as a MATLAB user I should tell you that syntaxes are extremely easy and intuitive. I didn't find anything hard about them.
Remember:

There isn't any problem to use C in Arduino IDE.
You don't need to worry about libraries. You only need to load them in the beginning of the code. You do not need to know how was the code written in the library.
Check the comments about the book on Amazon if you are not convinced.

Good Luck

It's worth noting that a little C++ knowledge is quite important for using many of the common Arduino libraries.

I must admit that I am not familiar with C++. On the other hand, to this day I haven't had any problem with any libraries. I just load them. But I don't know if I will need to use C++ in the simple projects. I'd be thankful if you could elaborate on this. Make a few examples where knowledge of C++ is crucial for using already written libraries. Thank you in advance.

In many cases, the library interface is a class. You have to instantiate it and call member functions on it in your code (e.g. see SoftwareSerial). It's certainly possible to just copy and adapt example code. However, I'd always recommend that at least a little knowledge of object orientation is important in understanding how to use it effectively.

Some newer C features won't work in the IDE, which is a shame since __flash is so very handy.

A very good book: Beginning C for Arduino:Learn C Programming for the Arduino, by Ph.D. , Jack Purdum

Beginning C for Arduino:Learn C Programming for the Arduino, by Ph.D. , Jack Purdum

This is not an answer.  Perhaps a comment.  Be sure to take the tour at https://arduino.stackexchange.com/Tour to see ow this works.

Since you have programming experience and you say you only want to learn enough to play with Arduinos, I think a resource worth mentioning is the built-in example programs. I've seen Arduino itself used as a learning tool for C/C++; their examples are very basic and intended for complete novices. If you keep hacking on progressively more complicated examples and googling specific things you don't understand, you will probably be able to get a good handle on things IMHO.
That isn't to say it's necessarily a good tool for learning C++ in general, since the limited memory resources and 8-bit CPU make some capabilities of the language commonly used on desktops (and the whole standard library) rarely used or unavailable on Arduino.

I have played with the examples and the most complicated thing I built used shift registers. What confuses me the most is all the variable types. Javascript is so simple but C++ is so fussy.

@ChristianJuth The reason there are so many types, is to make efficiënt use of your memory. But you can actually use Int (for integer values), float for decimal and strings for text. The other types or sub-types are to make them a little longer or smaller :) or to define wethether they can be negative (signed or unsigned) ontop of that you have boolean for true or false.

Another way to approach the problem is to come up with a project that you want to do with an Arduino and look for code samples.  Since you already have some programming experience you should be able to pick up what's going on pretty quickly and you will have a vested interest in what the code is doing.
For Example: Read temperature from a sensor and display to an LCD.
Arduinos are really good for reading from a sensor and there's a huge arduino community.  So, if you start with just reading from different types of sensors you'll find a lot of examples and learn a lot about Arduinos at the same time.


text:
Capturing images from OV7670 (w/o FIFO) using Arduino Uno?
I want to capture images from my OV7670 (w/o FIFO) and send it to my PC via Wi-Fi (ESP8266) (which I know how to use) using an Arduino Uno. I have read so many blogs and threads on the internet but couldn't find a simple and exact solution for the problem. I am a newbie in this and all I want is the simple wiring schema, code that can be used with Arduino IDE and the direction on how to proceed.
I found this random code. Please see if I can use it.
    #include <Wire.h>
    #include <Ethernet.h>
    #include <SPI.h>
    uint8_t sensor_addr = 0x42;

    //************ REGISTRADORES **********************//

    #define REG_COM1    0x04    /* Control 1 */

    #define REG_COM7    0x12    /* Control 7 */

    #define   COM7_RESET      0x80    /* Register reset */

    #define   COM7_FMT_MASK   0x38

    #define   COM7_FMT_VGA    0x00

    #define   COM7_FMT_CIF    0x20    /* CIF format */

    #define   COM7_FMT_QVGA   0x10    /* QVGA format */

    #define   COM7_FMT_QCIF   0x08    /* QCIF format */

    #define   COM7_RGB    0x04    /* bits 0 and 2 - RGB format */

    #define   COM7_YUV    0x00    /* YUV */

    #define   COM7_BAYER      0x01    /* Bayer format */

    #define   COM7_PBAYER     0x05    /* "Processed bayer" */

    #define REG_RGB444  0x8c    /* RGB 444 control */

    #define   R444_ENABLE     0x02    /* Turn on RGB444, overrides 5x5 */

    #define   R444_RGBX   0x01    /* Empty nibble at end */

    #define REG_COM9    0x14    /* Control 9  - gain ceiling */

    #define REG_COM10   0x15    /* Control 10 */

    #define REG_COM13   0x3d    /* Control 13 */

    #define   COM13_GAMMA     0x80    /* Gamma enable */

    #define   COM13_UVSAT     0x40    /* UV saturation auto adjustment */

    #define   COM13_UVSWAP    0x01    /* V before U - w/TSLB */

    #define REG_COM15   0x40    /* Control 15 */

    #define   COM15_R10F0     0x00    /* Data range 10 to F0 */

    #define   COM15_R01FE     0x80    /*            01 to FE */

    #define   COM15_R00FF     0xc0    /*            00 to FF */

    #define   COM15_RGB565    0x10    /* RGB565 output */

    #define   COM15_RGB555    0x30    /* RGB555 output */

    #define REG_COM11   0x3b    /* Control 11 */

    #define   COM11_NIGHT     0x80    /* NIght mode enable */

    #define   COM11_NMFR      0x60    /* Two bit NM frame rate */

    #define   COM11_HZAUTO    0x10    /* Auto detect 50/60 Hz */

    #define   COM11_50HZ      0x08    /* Manual 50Hz select */

    #define   COM11_EXP   0x02

    #define REG_COM16   0x41    /* Control 16 */

    #define   COM16_AWBGAIN   0x08    /* AWB gain enable */

    #define REG_COM17       0x42    /* Control 17 */

    #define COM17_AECWIN    0xc0    /* AEC window - must match COM4 */

    #define COM17_CBAR      0x08    /* DSP Color bar */

    #define REG_TSLB    0x3a    /* lots of stuff */

    #define   TSLB_YLAST      0x04    /* UYVY or VYUY - see com13 */

    #define MTX1            0x4f    /* Matrix Coefficient 1 */

    #define MTX2            0x50    /* Matrix Coefficient 2 */

    #define MTX3            0x51    /* Matrix Coefficient 3 */

    #define MTX4            0x52    /* Matrix Coefficient 4 */

    #define MTX5            0x53    /* Matrix Coefficient 5 */

    #define MTX6            0x54    /* Matrix Coefficient 6 */

    #define REG_CONTRAS     0x56    /* Contrast control */

    #define MTXS            0x58    /* Matrix Coefficient Sign */

    #define AWBC7           0x59    /* AWB Control 7 */

    #define AWBC8           0x5a    /* AWB Control 8 */

    #define AWBC9           0x5b    /* AWB Control 9 */

    #define AWBC10          0x5c    /* AWB Control 10 */

    #define AWBC11          0x5d    /* AWB Control 11 */

    #define AWBC12          0x5e    /* AWB Control 12 */

    #define REG_GFIX        0x69    /* Fix gain control */

    #define GGAIN           0x6a    /* G Channel AWB Gain */

    #define DBLV            0x6b

    #define AWBCTR3         0x6c    /* AWB (Automatic White Balance) Control 3 */

    #define AWBCTR2         0x6d    /* AWB Control 2 */

    #define AWBCTR1         0x6e    /* AWB Control 1 */

    #define AWBCTR0         0x6f    /* AWB Control 0 */

    #define REG_COM8    0x13    /* Control 8 */

    #define   COM8_FASTAEC    0x80    /* Enable fast AGC/AEC (Automatic Gain Control - Automatic Exposure Control)*/

    #define   COM8_AECSTEP    0x40    /* Unlimited AEC step size */

    #define   COM8_BFILT      0x20    /* Band filter enable */

    #define   COM8_AGC    0x04    /* Auto gain enable */

    #define   COM8_AWB    0x02    /* White balance enable */

    #define   COM8_AEC    0x01    /* Auto exposure enable */

    #define REG_COM3        0x0c    /* Control 3 */

    #define COM3_SWAP       0x40    /* Byte swap */

    #define COM3_SCALEEN    0x08    /* Enable scaling */

    #define COM3_DCWEN      0x04    /* Enable downsamp/crop/window */

    #define REG_BRIGHT      0x55    /* Brightness */

    #define REG_COM14      0x3E

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

    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC do arduino
    IPAddress ip(192,168,0,120); // IP do arduino
    byte server[] = {
      192,168,0,105}; //Endereço do servidor

    void setup (){

      DDRC&=~15;//low d0-d3 camera  PORTC (pino A0 ao pino A5) (11110000) A0 a A3 como entrada e A4 (SDA) e A5 (SCL) como saídas - essa linha tem a mesma função de pinMode que declara quem
      //é pino de saída e de entrada. Se for 0 é entrada e se for 1 é saída. O valor é não 15 (acima).
      DDRD&=~255;//d7-d4 and interupt pins PORTD (pino 0 ao pino 7) (0000 d7 ao d4           0=d3=vsync 0=d2=pclock               0=d1=href   1=d0=button)

      DDRB&=~1;

      Serial.begin(57600);
      Wire.begin();

      UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter (habilita bit 4 e bit 3)

      UCSR0C=6;// B (00000110) async (b7 e b6 = 00); (b3 = 0) 1 stop bit; (b2 e b1 = 1)  8bit char; no parity bits (b5 e b4 = 00); (b0 = 0)clock polaridade

      //set up twi for 100khz
      TWSR&=~3;//disable prescaler for TWI
      TWBR=72;//set to 100khz

      //SET UP CAMERA
      wrReg(0x15,32);//pclk does not toggle on HBLANK COM10 vsync falling
      //wrReg(0x15,0);//pclk does not toggle on HBLANK COM10 vsync falling
      wrReg(REG_RGB444, 0x00);             // Disable RGB444
      wrReg(REG_COM11,226);//enable nigh mode 1/8 frame rate COM11*/
      wrReg(REG_TSLB,0x04);                // 0D = UYVY  04 = YUYV
      wrReg(REG_COM13,0x88);               // connect to REG_TSLB
      //definição para o RGB 565
      wrReg(REG_COM7, 0x04);           // RGB + color bar disable
      wrReg(REG_COM15, 0xD0);          // Set rgb565 with Full range    0xD0

        wrReg(REG_COM3,0);    // REG_COM3

      wrReg(0x32,0xb6);        // HREF
      wrReg(0x17,0x13);        // HSTART
      wrReg(0x18,0x01);        // HSTOP
      wrReg(0x19,0x02);        // VSTART
      wrReg(0x1a,0x7a);        // VSTOP
      wrReg(0x03,0x0a);        // VREF

      wrReg(REG_COM1, 0x00);

      //COLOR SETTING
      wrReg(REG_COM8,0x8F);        // AGC AWB AEC Unlimited step size
      wrReg(0xAA,0x14);            // Average-based AEC algorithm
      wrReg(REG_BRIGHT,0x00);      // 0x00(Brightness 0) - 0x18(Brightness +1) - 0x98(Brightness -1)
      wrReg(REG_CONTRAS,0x40);     // 0x40(Contrast 0) - 0x50(Contrast +1) - 0x38(Contrast -1)
      // wrReg(0xB1,0xB1);            // Automatic Black level Calibration
      wrReg(0xB1,4);//really enable auto black level calibration
      wrReg(MTX1,0x80);
      wrReg(MTX2,0x80);
      wrReg(MTX3,0x00);
      wrReg(MTX4,0x22);
      wrReg(MTX5,0x5e);
      wrReg(MTX6,0x80);
      wrReg(MTXS,0x9e);
      wrReg(AWBC7,0x88);
      wrReg(AWBC8,0x88);
      wrReg(AWBC9,0x44);
      wrReg(AWBC10,0x67);
      wrReg(AWBC11,0x49);
      wrReg(AWBC12,0x0e);
      wrReg(REG_GFIX,0x00);
      //wrReg(GGAIN,0x40);
      wrReg(AWBCTR3,0x0a);
      wrReg(AWBCTR2,0x55);
      wrReg(AWBCTR1,0x11);
      wrReg(AWBCTR0,0x9f);

      wrReg(0xb0,0x84);//not sure what this does
      wrReg(REG_COM16,COM16_AWBGAIN);//disable auto denoise and edge enhancment
      //wrReg(REG_COM16,0);
      wrReg(0x4C,0);//disable denoise
      wrReg(0x76,0);//disable denoise
      wrReg(0x77,0);//disable denoise
      wrReg(0x7B,4);//brighten up shadows a bit end point 4
      wrReg(0x7C,8);//brighten up shadows a bit end point 8
      //wrReg(0x88,238);//darken highligts end point 176
      //wrReg(0x89,211);//try to get more highlight detail
      //wrReg(0x7A,60);//slope
      //wrReg(0x26,0xB4);//lower maxium stable operating range for AEC
      //hueSatMatrix(0,100);
      //ov7670_store_cmatrix();
      //wrReg(0x20,12);//set ADC range to 1.5x
      wrReg(REG_COM9,0x6A);//max gain to 128x
      wrReg(0x11,9);//using scaler for divider
      delay(100);//i2c uses interupts to write data wait for all bytes to be written

      //            #ifdef qqvga || ifdef qvga

      wrReg(REG_COM3,4);    // REG_COM3

      //    #ifdef qqvga

      wrReg(REG_COM14, 0x1a);          // divide by 4

      wrReg(0x72, 0x22);               // downsample by 4

      wrReg(0x73, 0xf2);               // divide by 4

      wrReg(0x17,0x16);

      wrReg(0x1A,0x04);

      wrReg(0x32,0xa4);

      wrReg(0x19,0x02);

      wrReg(0x18,0x7a);

      wrReg(0x03,0x0a);

      wrReg(REG_COM1, 0x00);

      // COLOR SETTING

      wrReg(REG_COM8,0x8F);        // AGC AWB AEC Unlimited step size

      wrReg(0xAA,0x14);            // Average-based AEC algorithm

      wrReg(REG_BRIGHT,0x00);      // 0x00(Brightness 0) - 0x18(Brightness +1) - 0x98(Brightness -1)

      wrReg(REG_CONTRAS,0x40);     // 0x40(Contrast 0) - 0x50(Contrast +1) - 0x38(Contrast -1)

      // wrReg(0xB1,0xB1);            // Automatic Black level Calibration

      wrReg(0xB1,4);//really enable auto black level calibration

      wrReg(MTX1,0x80);

      wrReg(MTX2,0x80);

      wrReg(MTX3,0x00);

      wrReg(MTX4,0x22);

      wrReg(MTX5,0x5e);

      wrReg(MTX6,0x80);

      wrReg(MTXS,0x9e);

      wrReg(AWBC7,0x88);

      wrReg(AWBC8,0x88);

      wrReg(AWBC9,0x44);

      wrReg(AWBC10,0x67);

      wrReg(AWBC11,0x49);

      wrReg(AWBC12,0x0e);

      wrReg(REG_GFIX,0x00);

      //wrReg(GGAIN,0x40);

      wrReg(AWBCTR3,0x0a);

      wrReg(AWBCTR2,0x55);

      wrReg(AWBCTR1,0x11);

      wrReg(AWBCTR0,0x9f);

      wrReg(0xb0,0x84);//not sure what this does

      wrReg(REG_COM16,COM16_AWBGAIN);//disable auto denoise and edge enhancment

      //wrReg(REG_COM16,0);

      wrReg(0x4C,0);//disable denoise

      wrReg(0x76,0);//disable denoise

      wrReg(0x77,0);//disable denoise

      wrReg(0x7B,4);//brighten up shadows a bit end point 4

        wrReg(0x7C,8);//brighten up shadows a bit end point 8

        //wrReg(0x88,238);//darken highligts end point 176

      //wrReg(0x89,211);//try to get more highlight detail

      //wrReg(0x7A,60);//slope

      //wrReg(0x26,0xB4);//lower maxium stable operating range for AEC

      //hueSatMatrix(0,100);

      //ov7670_store_cmatrix();

      //wrReg(0x20,12);//set ADC range to 1.5x

      wrReg(REG_COM9,0x6A);//max gain to 128x

      //    #ifdef qvga

      wrReg(0x11,4);//using scaler for divider

      pinMode(4,OUTPUT);
      digitalWrite(4,HIGH);
      Serial.println("Iniciando conexao");
      Ethernet.begin(mac, ip);
      Serial.println("Por favor, espere.");
      delay(1000);

    }

    EthernetClient client;
    void loop (){

    connectWeb(7000,server);
    foto(480,640);

    }

    byte wrReg(int regID, int regDat )

    {

      Wire.beginTransmission(sensor_addr >> 1);
      Wire.write(regID & 0x00FF);
      Wire.write(regDat & 0x00FF);
      if(Wire.endTransmission())
      {
        return 0;
        PORTB|=32;
        while (1) {
        }
      }
      delay(1);
      return(1);
    }

    uint16_t d;

    void foto(uint16_t linha, uint16_t coluna)
    {
      while (!(PIND&8)) {
      }//wait for high
      while ((PIND&8)) {
      }//wait for low
      //uint16_t a =millis(); //teste de tempo
      if (linha != 0)
      {
        //while (!(PINB&1)) {}//wait for high
        //while ((PINB&1)) {}//wait for low
        //while (!(PINB&1)) {}//wait for high

        while (linha--)
        {

          while (!(PIND&4)) {
          }//wait for high
          while ((PIND&4)) {
          }//wait for low
          //      int a = millis(); //teste de tempo

          uint16_t byte1, byte2;
          uint8_t buf[512];

          uint16_t  coluna_temp=coluna;
          while (coluna--){

            for(int i=0; i<2;i++){
              while (!(PIND&4)) {
              }//wait for high
              if(i==0){
                byte1= (uint8_t)(PINC&15)|(PIND&240); //B 00001111 (A0 a A3) ou 11110000 (d7 ao d4)
              }
              else{
                byte2= (uint8_t)(PINC&15)|(PIND&240);

                //((byte1<<8)|byte2);
               /* for(int x=0;x<512;x++){
                  buf[x]= (((byte1<<8)|byte2),BIN);
                  d+=buf[x];
                }*/
            sendMsg(client, ((byte1<<8)|byte2));
                //Serial.println(d);

                // Serial.println(((byte1<<8)|byte2),BIN); //B 00001111 (A0 a A3) ou 11110000 (d7 ao d4)
                //teste++;
              }
              while ((PIND&4)) {
              }//wait for low
            }

          }
          //                                        int b = millis(); //teste de tempo
          //  Serial.println((b-a)); //teste de tempo
          coluna=coluna_temp;
        }

        //while ((PIND&1)) {}//wait for low

      }
      //uint16_t b =millis(); //teste de tempo
      //Serial.println((b-a)); //teste de tempo
     // return teste;

    }

    void connectWeb(int port, byte ipServer[]){

      if (client.connect(ipServer,port)){
        Serial.println("Conectado");
        //essa e a parte que da erro. Perceba que estou enviando a mensagem
        //aqui, mas a intençao e enviar na funcao de tirar a foto.Aqui e teste
       // sendMsg(client, 800);

      }else{
        Serial.println("Conexao falhou");
      }

       if (!client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();

        // do nothing forevermore:
        while(true);
      }

    }

    //void sendMsg(EthernetClient client, uint8_t msg){
    //      client.println("valor "+String(msg));
    //}

    void sendMsg(EthernetClient client, uint32_t msg){
          client.println(msg,DEC);
    }

An Arduino is probably the wrong choice for this job - even if you can get it working at all, it will be limited to a small fraction of that camera's capability.

@ChrisStratton If the Arduino acts as a bridge between the ESP and camera then there would be no functionality loss except longer transfer rates. But Arpit it's a better idea to remove the Arduino, use the ESP instead to read the data from the camera and send it via wifi.

You should start from connecting Arduino UNO to PC. For this purpose use the following article: Arduino Uno и камера ov7670 — пример использования. You can disregard the longer text in Russian on top, it discusses why choose exactly this camera.
As listed in that source, the main problems you will find are:

The camera input current is not 100% compatible with the Arduino current. You will need to use resistors. The linked blog includes a schematic how to connect both.

You will need to write code for connecting both. There are examples on the Internet. You can also see the code used in the link. The main gotcha here is that the camera works in YUV mode. Each pixel in that format is coded with two bytes. The first byte codes the grey gradient, the second carries the chroma information. For a simple test, it is sufficient to get a greyscale image, so discard the second byte.

The oscillograms in the linked site show the signal we are expecting, followed by the code needed to read the image information.

The actual program for getting the image can be very simple. The author of the linked article wrote one. It reads from COM9, uses Java communication API and saves in bmp. You can download it here.

This simple test connection has following disadvantages:

Without buffering, the picture smears
There are synchronisation artefacts in the image
You cannot change the focus, the subject has to be kept at the camera's focused distance.

Transferring data via Wi-Fi will be the next step. But it will be hard because Uno and Wi-Fi module are connected via UART interface and maximum speed is limited to 230.4Kbps.
Here is example how to transmit image via bluetooth, Передача картинки с OV7670 через Arduino Uno на Android телефон. It maybe useful to you.
It assumes that you have connected the Arduino and the camera as described above, as step 1.
In step 2, you have to solve the problem of speed mismatch. The HC-06 UART interface and the Arduino Uno have following speeds:

HC-06: 1200 / 2400 / 4800 / 9600 / 19200 / 38400 / 57600 / 115200 / 230400 / 460800 / 921600 / 1382400
Arduino Uno: 2400 / 4800 / 9600 / 14400 / 19200 / 28800 / 38400 / 57600 / 76800 / 115200 / 230400 / 250000 / 500000 / 1000000 / 2000000

The maximum speed common to both is 230400, so you have to use that. You then need to reduce the internal processing speed with wrReg(0x11, 31);. You still cannot send at 230400, because the picture is sent in two steps, first the even rows, then the odd ones. You have to write the Arduino application to capture the image.
Finally, you can write the phone software. It only has to read the picture and show it on the page, nothing more. On a Bluetooth 2.1, the blog author measured more than 1 minute per frame, and the result was highly distorted. On Bluetooth 4.0, the picture quality was acceptable, and sending took less than 15 sec per frame.

Unfortunately, the links that you provide are to blogs written in Russian, and this is an english speaking Q&A site. Could you edit your answer to also provide links to pages written in English?

This is basically a link-only answer which will become useless if the target site goes down. Plus the linked site is in Russian, and this is an English-language site. It would be helpful to post or summarize the information there, in English, in your answer.

unfortunately he didn't read your post and said 'connect to uno' when you clearly stated you are using an esp8266

translation from page: http://privateblog.info/arduino-uno-i-kamera-ov7670-primer-ispolzovaniya/ (consult links in the original link as I couldn't post them because I need at least 10 reputation blah blah blah)
Arduino Uno and camera ov7670 - an example of use
(December 15, 2015)
Currently, the ov7670 is the most affordable image acquisition module for Arduino fans. Once it cost about $ 12, now its price dropped to less than $ 5.
ov7670 ( datasheet ) has good opportunities for its price:

different resolution VGA (640 x 480); - QVGA (320 x 240); - CIF (352 x 240); - QCIF (176 × 144);
transmission speed up to 30 fps,
several ways to encode an image RAW RGB, RGB 565/555, YUV / YCbCr 4: 2: 2
interface interaction I2C.

It would be ideal if not for one problem - connecting and getting at least a test image, as in any more or less complex hardware. There are a lot of discussions on the Internet, articles, recommendations, but it's impossible to find clear steps: someone is lazy to write them, someone lays only a diagram or code, somebody does not spread anything at all, but reports only about successful connection. Especially it would be desirable to note ComputerNerd which has laid out fine example with the small description, but for the beginner it is not enough.
This article is intended to show how to connect, configure and get a test image using a small program on java, which will be an excellent starting point for further experiments.
I conducted my experiments on Arduino Uno, as it was best described - connection schemes and articles. There was an attempt to set up on Arduino Mega, but it ended badly. It turned out that on the scaffold A4 and A5 this board already has a reference voltage of 5v, which burned the camera.
In my example, the camera will be used

AtmelStudio + arduino plugin
ov7670 without buffer, operating mode qvga (320 × 240), encoding YUV
Arduino Uno
2 resistors per 10kΩ
2 resistors at 4.7 kΩ
a computer.

Connection scheme for ov7670 to Arduino Uno

Programming the camera needs to start with the correct connection. The voltage of the camera inputs differs from Arduino voltage in places, so resistors are needed.

Connection scheme ov7670 to Arduino Uno

The program for ov7670 and Arduino Uno

To compile the program, we used an example from ComputerNerd, which had to be cut off a bit and then replaced in places. The code can be downloaded from the link .
The basic steps in the code are as follows:

Setting the Arduino Uno PWM, so that it gives out 8mhz on the 11th leg.

DDRB | = (1 << 3); // pin 11
ASSR & = ~ (_BV (EXCLK) | _BV (AS2));
TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
TCCR2B = (1 << WGM22) | (1 << CS20);
OCR2A = 0; // (F_CPU) / (2 * (X + 1))
DDRC & = ~ 15; // low d0-d3 camera
DDRD & = ~ 252; // d7-d4 and interrupt pins

Configuring the I2C Interface

TWSR & = ~ 3; // disable prescaler for TWI
TWBR = 72; // set to 100khz

Configuring RS232.

UBRR0H = 0;
UBRR0L = 1; // 0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
UCSR0A | = 2; // double speed aysnc
UCSR0B = (1 << RXEN0) | (1 << TXEN0); // Enable receiver and transmitter
UCSR0C = 6; // async 1 stop bit 8bit char no parity bits

Camera setup

....
wrReg (0x12, 0x80);
delay_ms (100);
wrSensorRegs8_8 (ov7670_default_regs);
wrReg (REG_COM10, 32); // PCLK does not toggle on HBLANK.
...

Obtaining an Image

The operating mode of the image transmission camera was set to YUV. In this case, each pixel is encoded with two bytes. The first byte encodes the gradation of gray, the second - color-difference component.

The task for us is to get at least a black and white image, so the second byte can be discarded.
Next, we need to bring an oscillogram from which it becomes clear what signals we expect with high and low values.

oscillogram ov7670
StringPgm (PSTR ( "* RDY *" ));

// VSYNC
while  (! (PIND &  8 )); // wait for high
while  ((PIND &  8 )); // wait for low

y = hg;
while  (y -) {
   x = wg;
   while  (x -) {
      // PCLK
      while  ((PIND &  4 )); // wait for low
      UDR0 = (PINC &  15 ) | (PIND &  240 );
      while  (! (UCSR0A & ( 1  << UDRE0))); // wait for byte to transmit
      while  (! (PIND &  4 )); // wait for high
      while  ((PIND &  4 )); // wait for low
      while  (! (PIND &  4 )); // wait for high
   }
}
_delay_ms ( 100 );

The program on java to get the image from ov7670 via Arduino Uno

The program for obtaining images is extremely simple. It receives data from the COM9 port using the Java Communication API  and saves it as bmp. All variables are set directly in the code, so you'll have to change it to your own.
grabber

Results

On the basis of the images you can immediately draw a conclusion about the shortcomings:

The lack of an internal buffer leads to the blurring of the picture, it is immediately transferred to the computer, and this takes time.
There are artifacts in the form of horizontal stripes - synchronization failure in obtaining a picture. Instead of the gradation of gray sent tsvetraznostnaya component.
The subject must be in the focus of the camera for a clear image

This article can be finished. Waiting for comments and suggestions.


text:
How can I add phonebook entry to sim card using Arduino GSM shield?
I am using Arduino GSM Module and Arduino UNO

I want my GSM module to be stand alone once I programmed it. It will store the phone number of the user if he sends a correct passcode. Since I want the data to available even after I power off my module. I need to store it to my sim. I don't want to use an SD card shield or store data to arduino's EEPROM.
I have read Getting the contacts/ storing contacts to SIM card. The only clear reply is reading from the SIM.
Is it possible to add phonebook entry to SIM card?
Do you know a tutorial?

.
Hope this helps.
Go check out (http://m2msupport.net/m2msupport/sim-phonebook-at-commands/) I use these commands on my AI Tinker A7 board for the Arduino.... 95% work perfectly...
Cheers,
Capt.K
ps. I made these numbers up but the formats are all correct.
//----------------------------------------------------------
//---Add Entry To PhoneBook:
//----------------------------------------------------------

AT+CPBW=1, "+61416199234",145, "Paul"    //-- add entry x1

OK

//----------------------------------------------------------
//--DELETE phonebook entry:
//----------------------------------------------------------

AT+CPBW=1  //-- delete entry x1

OK

//----------------------------------------------------------
//-- AT+CPBW=[<index>],<number> [ ,<type> [,<text>]]
//----------------------------------------------------------
//
//<index>   = Entry Number in SIM Memory
//<number>  = "The Phone number"
//<type>    = "The Phone Number" (TYPE ) ie. 129,161,145,177..
              //  129 – National number type
              //  161 – National number type
              //  145 – INternational number type
              //  177 – Network specific number
//<text>    = "Person Name" etc.

//----------------------------------------------------------
//  Add 4x new entries to the SIM card
//----------------------------------------------------------
AT+CPBW=1, "+61416199234",145, "Pops"
AT+CPBW=2, "+61420921234",145, "Mum"
AT+CPBW=3, "+61733728171",145, "Wendy"
AT+CPBW=4, "+61356821234",145, "Mr Smith"

//NOTE:  In Australia (above examples) the actual phone numbers
//       above are of these types
//
// Int.Format    Aust. Dial Internal       Phone_Type
// -----------------------------------------------------------
// +61416199234  (0416) 199 234             Mobile/Cell
// +61420921234  (0420) 921 234             Mobile/Cell
// +61356821234  (03)   5682 1234           Landline/PSTN


text:
Using Arduino to show images in Serial Monitor
Some time ago I came across a Vedic in which a person has hacked an optical mouse's camera and displayed the image in the Serial Monitors.
My question:
How to use Serial Monitor to display an image captured by the Arduino

Based on this guide, he doesn't actually display the images on the serial monitor, only the image data for each pixel.
Then another program (Javascript and some HTML) on the PC side collects the data and converts it to a greyscale image.

If you happen to know, could you tell me how those  programs work


text:
Sensors to use in Pets
I want to track my pets using some sensors (their location in space) but I could only find radio sensors. These radio sensors are big and cumbersome for my dogs to carry around.
Is there some sensor that I can use in order to locate them in space? I want to use my arduino board to capture the data.

Something like https://www.adafruit.com/products/746?

Is it inside or outside? You could place sensors on the ground around the dog to track where he is. Or are you looking for something like indeed a GPS 'sensor'? Do you want the data to be stored on the arduino/sd or transmitted directly? Add these things to your question, tracking items/pets can be done in a lot of ways.

@fuaze want to track them inside an apartment. Got count on walls and obstacles.

@Gerben, YES. that seems to solve it.

@Gerben, actually I would need something less fancy, but in the same vein. I'm interested only in raw data (distance from a certain point in 2D)

What kind of range are you talking about? I doubt you'll be able to do it cheaper than with a GPS unit though.

@Gerben talking about 100m^2

A cool project would be to use a camera to track the pet. But you'll need to hook it up to the PC to process the data and then send it to arduino, you wouldn't even need a pet, and probably not even an arduino.
But GPS is probably the best, though I'm not sure how accurate they are, inside an appartment.
Maybe even an accelerometer to check his speed/heading is enough? You should be able to guess where he is/goign from the data?
Or put ping sensors around the room, that measure the distance from the wall to said pet.List the possibilities (pros and cons) and choose the best one I guess.

@FuaZe accelerometer is a great idea. do you have some reference? I would need something easily rechargeable, for the pets to carry around

You are aware that an accelerometer does not provide a location by itself? And well, I've actually never used an accelerometer, you should check some tutorials I think.


text:
"variable must be const" fix for Arduino progrem
I am trying to upload to my nano the code attached. It is giving me an error saying variable must be const about something I am trying to put in progrem. I learned that installing a older version of the compiler worked. However I was wondering is there a way to just edit the code to make it work. I tried putting const before it but it didn't work. It is on line 78 and 79 of the first file.
const extern PGM_P *NApowerCodes[] PROGMEM;
const extern PGM_P *EUpowerCodes[] PROGMEM;

Could you please post the concerning lines of code. You can't expect us to go to a webpage, find and download a zip, open it, just to see the code.

Which version of the IDE are you using? I was able to compile to code on 1.0.5

I am using the latest version, I believe 1.0.06. I was able to compile it with your version but would like to know how to fix it.

Using the source from this link I got it to compile following these steps.

Before opening the sketch in the Arduino:

Rename TVB.pde to TVB.ino
Rename WORLDcodes.cpp to WORLDcodes.h

Open the sketch (TVB.ino) in the Arduino IDE

Edit main.h and change:
// The structure of compressed code entries
struct IrCode {
  uint8_t timer_val;
  uint8_t numpairs;
  uint8_t bitcompression;
  uint16_t const *times;
  uint8_t const*codes;
};

to:
// The structure of compressed code entries
struct IrCode {
  uint8_t timer_val;
  uint8_t numpairs;
  uint8_t bitcompression;
  uint16_t const *times;
  uint8_t const*codes PROGMEM;
};

That is, add PROGMEM to the codes line.

Edit TVB.ino and change:
extern PGM_P *NApowerCodes[] PROGMEM;
extern PGM_P *EUpowerCodes[] PROGMEM;
extern uint8_t num_NAcodes, num_EUcodes;

to:
#include "WORLDcodes.h"

This avoids some linker problems in the original code.

Edit WORLDcodes.h and delete the line:
 #include "main.h"

Continue editing WORLDcodes.h and change:
const struct IrCode *NApowerCodes[] PROGMEM = {

to:
const struct IrCode * const NApowerCodes[] PROGMEM = {

And also change:
const struct IrCode *EUpowerCodes[] PROGMEM = {

to:
const struct IrCode * const EUpowerCodes[] PROGMEM = {

It should now compile OK.


text:
Responding to a broken laser beam?
Firstly, I must apologise as I'm a complete noob but the Arduino kits / lego pieces are fantastic and I can't stop tinkering.  Unfortunatley my knowledge does not match my passion.
I picked up a laser from Amazon: FamilyMall(TM) KY-008 Laser Transmitter Module 650nm 5V Diode For Arduino AVR PIC.
I'm wondering what the middle pin is good for and if I can somehow manage to detect and respond to the beam being broken?
Thanks for looking. :)

http://www.linksprite.com/wiki/images/thumb/1/1a/KY008.png/300px-KY008.png . Middle pin should be 5v, so I think you miswired it. Signal I'd guess is kind of like an on/off switch.

@Gerben - I don't think it's of the highest quality, the '-' labelled pin is VCC and the 'S' pin is gnd.  Connected this way results in a functional beam.  I suspect the manufacturer is a troll :)

Without a data sheet or the device on hand not sure what the middle pin is used for.  On the topic of detecting a broken beam the item you purchased is purely an emitter, in order to detect the beam being broken there are two main ways, using a photodetector on the "opposite end" of the beam but this means having wires trailing the same path as the laser beam, alternatively you could mount a mirror where the beam lands and reflect it back to a photodetector mounted close to the laser diode.  You would them use the arduino to detect the state of the photodetector.

thank you!  That's exactly what I wanted to know.  I'll look into picking up a photodetector, assuming they're not mega expensive and continue playing.  thanks again!

can I ask if you'd mind looking at this item: http://www.amazon.co.uk/Generic-TCRT5000L-TCRT5000-Reflective-Infrared/dp/B00C0P98C4/ref=sr_1_2?s=electronics&ie=UTF8&qid=1429054085&sr=1-2&keywords=photodetector and saying if you think that this would be more suitable instead of buying the separate photodetector you mention

@SteveGreen That item you linked is fine if you want to detect paper, card or some other reflective material at a maximum distance of 12mm. If that's not what you want to do, then it's not suitable.

thanks @RogerRowland.  I was mainly jsut trying to mess around with setting off a buzzer if a door was opened or something along those lines.  My 'plan' is to play with automation stuff but I'm waiting on a ton of stuff to be delivered and might have bought a lot of 'bit' that are not neccesary but still fun to play with and learn how the arduino etc works :)

Sorry took so long to see your follow up, I assume you have found it to be a fairly powerful laser so you could use the mirror trick over quite a distance.  I looked this up for you to give you some ideas to get it done on the cheap:  http://www.instructables.com/id/Arduino-Laser-Tripwire/

oh and just in case it's still relevant no the items you linked to would not work.  They have a filter that selectively blocks "all" wavelengths of light apart from the one its interested in ie in this case 950nm .  Your laser on the other hand produces light in the 650nm wavelength and in theory would be blocked by the filter on the photodiode.  If you looked you may find one with a 650nm filter which would be perfect for your application.


text:
How to precisely control servo motor by changing duty cycle?
I developed a PWM using timer1,using arduino uno and digital output, and identified that when I send a wave with duration of 0.6ms in High level, the motor goes to 0º. If I send 2.1ms, it goes to 180º. I tried to make a relationship between these scales to send the angle and change the time period in order to achieve that angle and it did not work.
I would like to move with a precision of 1 degree, is that possible? Just adjusting the time period.
The model of the motor is mg996r.
Maybe I am missing something.
My code just generates an interrupt over 50 microsencods and I use this to set the frequency of 50Hz and the duty cycle in ms using digitalWrite associated with pin 9.
#include <TimerOne.h>

double t = 0.0;

double period = 0;

void setup()
{
  t = 0;
  Serial.begin(9600);

  pinMode(9, OUTPUT);
  Timer1.initialize(50);
  Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}

void loop()
{
  // Main code loop
  // TODO: Put your regular (non-ISR) logic here
  if (Serial.available() > 0) {
    float grau = Serial.parseFloat();

    // receive data as angle
    if (grau > 180) grau = 180;
    if (grau < 0) grau = 0;

    // set period for that angle
    // relationship developed between angle and period in ms
    //set it to period
    period = (0.00833*grau + 0.6)*1E-3;
  }

}

/// --------------------------
/// Custom ISR Timer Routine
/// --------------------------
void timerIsr()
{
    t += 50E-6;
    if (t <= period) {
      digitalWrite(9, HIGH);
    }
    else if (t < 20E-3) { // periodo max de 20ms -> 50Hz
      digitalWrite(9, LOW);
    }
    else {
      t = 0;
    }
}

UPDATE:
I just got it working by creating a timer1 interrupt on CTC mode with a frequency of 100kHz and counting the necessary time to get increments (~ 10us each) of around 1 degree on my servo motor.
More info here.

The relationship is like a map between 0.6 ms -> 2.1ms and 0 -> 180 angle degrees. It works, but the problem is that it does not work for a precision of 1 angle degree as Arduino Servo Library does...

For a precision of one degree, you need a minimum timer increment of 8.33us, which is optimistic. Your current 50us period gives you a resolution of ~6 degrees.

I tried a resolution of 1us but it didn't work, the motor did not move. Can I achieve this using timer1?

I found that it has a dead band of 5us. So it won't move until the width changes by 5us.

The best is to use 10us Period, instead of 50us.
That precision will be close to 1°

Thanks, @Mathsman, I got it working, you were right! Just created a timer1 interrupt using CTC mode and then generated an output signal with a frequency of 100kHz that I could increment the angle by approximately 1 degree.

Your welcome. I recommended this as I have already tried it.

It has precision of 1.1to 1.2 degrees.


text:
Adafruit Music Maker Shield - Retrieve song names from SD Card
I am currently working on a project that plays music for you. My question for this thread is, is it possible to retrieve the names of the songs within the micro SD card that is inserted into the shield?
Currently I am renaming the song files to track001, track002, track003, etc. As can be seen in the following code:
const int arraySize = 5;
char songs[arraySize][15] =
{
  {"track001.mp3"},
  {"track002.mp3"},
  {"track003.mp3"},
  {"track004.mp3"},
  {"track005.mp3"}
};

That is how am I currently playing music with this shield. I am not too happy with this as I would like to be able to insert different micro SD cards into the shield without having to rename them to track00X or without having to change the code every time to match the song names.
So, is it possible to code it to retrieve the song names from the SD card instead of having to specify their name in the code?
Below you can see my full code:
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)

#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

int volume = 20;
const int arraySize = 5;
char songs[arraySize][15] =
{
  {"track001.mp3"},
  {"track002.mp3"},
  {"track003.mp3"},
  {"track004.mp3"},
  {"track005.mp3"}
};

int songNumber = 0;

void setup()
{
  Serial.begin(9600);
  musicPlayer.begin();
  SD.begin(CARDCS);
  musicPlayer.setVolume(volume, volume);
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
}

void loop()
{
  // Lower Volume
  if (musicPlayer.GPIO_digitalRead(7) == HIGH)
  {
    if (volume < 70)
    {
      volume = volume + 1;
      musicPlayer.setVolume(volume, volume);
      delay(50);
    }
  }

  // Increase Volume
  if (musicPlayer.GPIO_digitalRead(6) == HIGH)
  {
    if (volume > 0)
    {
      volume = volume - 1;
      musicPlayer.setVolume(volume, volume);
      delay(50);
    }
  }

  // Start Music Player
  if (musicPlayer.GPIO_digitalRead(5) == HIGH)
  {
    if (! musicPlayer.playingMusic)
    {
      musicPlayer.startPlayingFile(songs[songNumber]);
    }
  }

  // Pause / Resume
  if (musicPlayer.GPIO_digitalRead(4) == HIGH)
  {
    if (! musicPlayer.paused())
    {
      musicPlayer.pausePlaying(true);
    }
    else
    {
      musicPlayer.pausePlaying(false);
    }
    delay(500);
  }

  // Prev Song
  if (musicPlayer.GPIO_digitalRead(3) == HIGH)
  {
    if (songNumber - 1 >= 0)
    {
      songNumber = songNumber - 1;
    }
    else
    {
      songNumber = arraySize - 1;
    }
    Serial.println(songNumber);
    musicPlayer.startPlayingFile(songs[songNumber]);

    delay(500);
  }

  // Next Song
  if (musicPlayer.GPIO_digitalRead(2) == HIGH)
  {
    if (songNumber + 1 < arraySize)
    {
      songNumber = songNumber + 1;
    }
    else
    {
      songNumber = 0;
    }
    Serial.println(songNumber);
    musicPlayer.startPlayingFile(songs[songNumber]);
    delay(500);
  }
}

If this is possible and someone reading this knows how to do so, I would truly appreciate it if you explained it to me and even provided an example or even edit my own code if you want. Thank you! :)

The adafruit library was is similar to the prior SFEMP3shield library (disclosure I am the main author of that). That said either library can work on either Adafruit or SFE shield or breakout board. AdaFruit's library is cleaner re-write. But in doing so it is minimal in its functions. The SFE library demonstrates many more features of the VS1053 chip.
That said; the ./Example/fileplayer.ino does exactly what you are asking. The directory command lists out the files with an enumerating number. Entering 0[number] plays that file. This is how I broke away from "track###.mp3", without having to implement a command prompt parser. And it also allows other file formats.
The bulk of this feature is in the LOOP() and not in the constrained to the library. So one can cut and paste it into a sketch using the Adafruit library in place of the SFEMP3 or any sketch with an SdCard. That said it would actually be easier to replace the play file calls and include in the FilePlayer.ino example. Or just use it straight up.
The SFEmp3 library is bit overwhelming because it supports so many features of the VS1053. And uses a different SdCard library, which is more upto date than the IDE's SD". While the Adafruit library is a very nice re-write and cleans much hte confusing #define's making it much easier code to read, it is not as feature rich. But most feature beyond play and stop are not really needed.
Good luck.


text:
What is the difference between Serial.write and Serial.print? And when are they used?
What is the difference between Serial.write and Serial.print? And when are they used?
Both have been used to print on serial monitor, what are their actual differences?

Serial.write is more down to earth , it is simple and fast, it is made to talk binary, one byte at a time.
example:
Serial.write(0x45);   // will write 0100 0101 to the cable

Serial.print in the other hand is more versatile , it will do the conversion for you from ASCII to binary it also can convert to BIN/ HEX/OCT/DEC but you need to specify a second argument like so
Serial.print(76, BIN) gives "0100 1100"
Serial.print(76, OCT) gives "114"
Serial.print("L", DEC) gives "76"
Serial.print(76, HEX) gives "4C"

more examples with visual serial output :
Code:
  Serial.write(0x48);   // H
  Serial.write(0x45);   // E
  Serial.write(0x4C);   // L
  Serial.write(0x4C);   // L
  Serial.write(0x4F);   // O

SERIAL OUTPUT :

Code:
  Serial.print("HELLO");

SERIAL OUTPUT :

Serial.println() in the other hand will add end of line 2 bytes 0x0D and 0x0A as you can see in the frame
Code:
  Serial.println("HELLO");

SERIAL OUTPUT :

From the Arduino site for Serial.write and Serial.print:
Serial.write()

Writes binary data to the serial port.
This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead.

Serial.print()

Prints data to the serial port as human-readable ASCII text.
This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is

Serial.write sends bytes to the serial port while Serial.print sends ASCII characters so people can read easily.
Some devices work using bytes to set configurations, commonly use packets of data and you need to use write function to communicate with them. Eventually they will send bytes through serial interface and then you can interpret by going each byte.

All of the examples above are correct, but maybe more clearly.... All data sent through the serial port is sent as 1's and 0's. (obvious.... I hope)... The difference in the two commands is how whatever is being sent is actually translated/interpreted to/from these 1's and 0's. The clearest example involves transmitting numbers.
Let's say you need to send the number 217. The binary (1's and 0's) representation of this number is 11011001. Using the command Serial.write(217) will literally just send 11011001 across the line. The Hex representation of the same number is 0xD9, and the command Serial.write(0xD9) will send the same thing ... 11011001.
Here is where it gets interesting... If you were to use the command Serial.write("217") you would instead get this: 00110010 00110001 00110111... WHAT?!?!?
When a string is passed as the argument it is broken down into individual characters, converted to ASCII, and then sent as a byte for each character. You would get the exact same output if you were to use the following:
Serial.write(50);
Serial.write(51);
Serial.write(55);

(00110010 00110001 00110111)
Now let's look at Serial.print(). The commands Serial.print(217) or Serial.print("217") will both print the same thing: 00110010 00110001 00110111. This is because the print command first converts any number to a string representation and then uses the command Serial.write() to send each character as individual ASCII bits.
Though this is not a COMPLETE description, I hope it helps to get you thinking in the right direction...

Yet another way to answer this is to state the Serial.write accepts single characters where Serial.print accepts strings. There may be some differences but this is the main one.

What about Serial.write(stringData.c_str());? if stringData is defined as String.

Please show how stringData is defined as String.

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


text:
Charging Li ion cell using arduino
2days back I opened my cousin brothers laptop battery as it was a spare one left unused over a year.
I disintegrated it and found 6x 18650 batteries when I checked them with voltmeter individually I found that 2 were dead I.e.0V and 2 read 2.15 V and the last two read 1.5V. I thought of making a power bank using them individually. The battery are ideal for a power bank because they have 2200ah capacity. I need a circuit to charge it. I thought of chraging it with arduino. But how?
To get the datasheet just search "lr1865ah" in google and click the one and only pdf link that is the cell's datasheet. I need the charing circuit using arduino.

2.15v is way too low. The cell might be damaged due to this. Damaged lithium cell can burst into fire. I personally wouldn't risk it. Just toss them in the trash.

There is a far easier (and safer) way to charge them without using an Arduino. Over-voltage is an issue and another crucial factor with the 18650 batteries is to not let the voltage drop below 2.5 volts when you are dis-charging them. There is a simple "Charge/Discharge Board Module for 18650 Lithium Batteries" that sell for approx. $1 US:
http://www.ebay.ca/itm/2in1-1A-USB-Charge-Discharge-Board-Module-for-18650-Lithium-Battery-Phone-Bank-/302039028674?hash=item4652edd3c2:g:bDkAAOSw9NdXrBoE.
The board has a "fast charge" current of 1000 mA until the battery reaches 4.2 volts, then it switches to a "trickle charge mode". The circuit board also stops current flowing out of the battery once the voltage drops to 2.5 volts. Most of the older charger boards do not have this feature and it's almost as important. It also has a "over-current" protection current of 3.0 amps in case you try to draw too much power from it.
The circuit board has a mirco USB connection on it but be VERY careful before you plug it into a computer USB port. My old MacBook only provides up to 500 mA at each USB port, half of what's required.
The circuit board is 0.700" X 1.050". Here is a picture of it:


text:
Scope error in arduino PinChangeInt library
#include<PinChangeInt.h>
#define SensorPin 2

int ledPin = 10;
int BuzzerPin = 12;
volatile byte blip = 0;

void blipcount(){
  blip++;
};

void setup() {
   // put your setup code here, to run once:
   pinMode(SensorPin,INPUT);
   pinMode(ledPin,OUTPUT);
   pinMode(BuzzerPin,OUTPUT);
   PCintPort::attachInterrupt(SensorPin,blipCount,FALLING);
   Serial.begin(9600);
}

void loop() {
   // put your main code here, to run repeatedly:
   if(digitalRead(SensorPin)==HIGH){
      digitalWrite(ledPin,HIGH);
      digitalWrite(BuzzerPin,HIGH);
      Serial.print("blipcoun:\t");
      Serial.println(blip,DEC);
   }

   if(digitalRead(SensorPin)==LOW){
      digitalWrite(ledPin,LOW);
      digitalWrite(BuzzerPin,LOW);
   }
}

I am using arduino uno for a project.I need to record when my sensor gives a high value but i need it to read only falls in pulses.The program is giving  error as
Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"

Sense.ino: In function 'void setup()':

Sense.ino:14:38: error: 'blipCount' was not declared in this scope

Error compiling

please tell me what is the problem with the function.
The library link is
https://code.google.com/p/arduino-pinchangeint/downloads/list
tested the code on both 1.72 and 2.19

void blipcount(){   blip++; }; why the ; at the end of the function?

You have a typo:
PCintPort::attachInterrupt(SensorPin,blipCount,FALLING);

Should be:
PCintPort::attachInterrupt(SensorPin,blipcount,FALLING);
                                         ^

Note the lower-case "c".


text:
Isolating IR receiver from disruption?
I'm using a simple IR receiver connected to the Arduino through A0 analog pin. The problem is that I want to stabilize the output of IR receiver when it's not receiving an IR signal from a specific IR source, or at least minimizing the disruption to a specific range that I can handle, no matter where its position, But in my case moving the IR receiver a few inches in any direction will results in different voltage output. the difference between values on disruption is very random to handle.
What can I do to isolate IR receiver, may be a specific material or a specific color?

What receiver are you using? If you read this comparison they mentioned that one of the receivers would give random pulses from the sunlight.

speaking of sunlight, when I was experiment with the IR receiver in my room, I didn't expect that the sunlight can cause such a huge disruption, I had to close my window, the output now is much more stabilized, but still there's a small disruption that I want to minimize it as much as I can.

I would suggest two things. First You could put electrical tape around the receiver in such a way that it will only pick up signals from a certain direction. Also you could use low and high pass filters to accept input only in the 38khz range(range of most infra red remotes).  Keep in mind that you will need a couple of rounds for it to work effectively.

Filtering is a good idea (if not already implemented in the receiver package) however it should be noted that even with filters, some will  output spurious pulses.  Software may be the best place to reject those - rejecting ones which occur in isolation are easy, recovering intended transmissions that have noise spikes in them is trickier, but generally still possible.

Thanks a lot Einstein Jr, putting electrical tape and setting transmitting frequency to 38khz solved my problem, it's may be useful to mention that I needed several rounds of electrical tape around my IR receiver to isolate it entirely from disruption.

Glad I could help. I editted my answer with your suggestions.


text:
how to send input values from host computer to arduino
how to send input values from host computer to arduino,such that speficing the number of rotations for a stepper motor etc

Via serial. Most CNCs and 3D printers send GCode over serial.

The easiest method is to use the serial communication. Use the sample code at http://arduino.cc/en/Tutorial/SwitchCase2, upload that to an Arduino, start the serial monitor (Ctrl+Shift+M), make sure the baud rate is the same as set in the code (9600 in this case), then write the commands and send them to the Arduino.
Edit
Since the serial characters are usually read one by one you need a character that will signal the end of the string. This is usually a newline \n, but can be any character you choose (and can be sent to Arduino).
Sample code (processString would be your function to do something with the string):
char buf[64];
byte cnt = 0;
void loop()
{
    while (Serial.available()>0) {
        byte c = Serial.read();
        // Check for terminator character or the size of buffer
        if (c == '\n' || cnt >= 63) {
            // Add the terminating 0
            buf[cnt] = 0;
            // Process the full string
            processString(buf);
            // Prepare to read the next string
            cnt = 0;
        } else {
            // Not terminator - add to string
            buf[cnt++] = c;
        }
    }
}

okay.If i want to sent a string the same read() is used? Is there any modifications needed for sending strings?

check my updated answer above


text:
Turning all 35 leds on sequentially with MM5451
I've been struggling for a long time trying to get the MM5451 chip to light up all 35 leds sequentially without any luck.  I've had intermittent help from the arduino forum, someone on youtube, and even found source code on here.  But all I've been able to accomplish is either to get all the lights lit up at once, or every other led lit up at once, or having two sets of 8 leds lighting up sequentially together.  I can't figure out how to get all of them lit on and off sequentially.  I'm sure it has to do with shifting bits but can't figure out how to do this.  Here's two sets of code that either light two sets of 8 bits together sequentially, and another program that lights every other led all at once.
Sequential lighting of two sets of 8 bits
#define CLK 2 // to MM5451 pin 21
#define dataBit  3 // to MM5451 pin 22

 byte singleled[]=  {1,2,4,8,16,32,64,128};
//   0b00000001, 0b00000010, 0b00000100,
 //  0b00001000, 0b00010000, 0b00100000,
 //  0b01000000, 0b10000000, 0b11111111 };

  byte singleled2[]=  {1,2,4,8,16,32,64,128};
 //  0b00000001, 0b00000010, 0b00000100,
 //  0b00001000, 0b00010000, 0b00100000,
 //  0b01000000, 0b10000000, 0b11111111 };

void setup() {
  pinMode(CLK, OUTPUT);
  pinMode(dataBit, OUTPUT);
  digitalWrite(CLK, 0);
  digitalWrite(dataBit, 0);
  Serial.begin(1200);
}

// the loop routine runs over and over again forever:
void loop() {

  for (int i=0; i<8; i++)   {
        // start bit
    digitalWrite(dataBit, 1);
    pulseCLK();
    // the "+ 0x80" turns on DP
    ssrWriteLSB(singleled2 [i]); // MOD myCount = 0-9
    ssrWriteMSB (singleled [i]); // eight LEDs binary count 0-255
      delay(500);
   // ssrWriteMSB(myCount);
    //Serial.println(myCount);
    delay(500);
   // Serial.println(myCount);
    zeroWrite(29); // pad remaining bits with 0s
    delay(500);
  }

} // end loop

void pulseCLK()   {
  digitalWrite(CLK, 1);
  digitalWrite(CLK, 0);
}

// LSB out first!
void ssrWriteLSB(byte value)   {
  Serial.println(value);
  for(int x =0; x < 8; x++)   {
    byte temp = value & 0x01;
    if (temp == 0x01)   digitalWrite(dataBit, 1); // data bit HIGH
    else digitalWrite(dataBit, 0); // data bit LOW
    pulseCLK();
   value = value >> 0x01; // shift right
  }
}

// MSB out first!
void ssrWriteMSB(byte value)   {
 Serial.println(value);
  for(int x =0; x < 8; x++)   {
    byte temp = value & 0x80;
    if (temp == 0x80)   digitalWrite(dataBit, 1); // data bit HIGH
    else digitalWrite(dataBit, 0); // data bit LOW
    pulseCLK();
    value = value << 0x01; // shift left
  }
}

void  zeroWrite(byte num1)   {
  digitalWrite(dataBit, 0); // data bit LOW
  for(int x = 0; x < num1; x++) pulseCLK();
}

Turns on every other light all at once:
#define dataBit 3
#define clk 2

void setup()  {
  Serial.begin(1200);
  pinMode(dataBit, OUTPUT);
  pinMode(clk, OUTPUT);
  digitalWrite(dataBit, 0);
  digitalWrite(clk, 0);
}

 void loop() {
     //digitalWrite(dataBit,1);
     for(int index=0; index < 36; index++)  {
          digitalWrite(dataBit,1);
          digitalWrite(clk,1);
          digitalWrite(clk,0);
          digitalWrite(dataBit,0);
          digitalWrite(clk,1);
          digitalWrite(clk,0);
      }
  }

Thanks in advance.
Bryan

I think you need something like this.
#define CLK 2 // to MM5451 pin 21
#define DATA  3 // to MM5451 pin 22

void setup()
{
    pinMode(CLK, OUTPUT);
    pinMode(DATA, OUTPUT);
    digitalWrite(CLK, 0);
    digitalWrite(DATA, 0);
    Serial.begin(1200);
}

// the loop routine runs over and over again forever:
void loop()
{
    for( byte led=0; led<35; led++ )
    {

        lightLed(led);

        delay(1000);
    }
}

void lightLed(byte index)
{
    //always send a one first
    sendOne();
    // turn off all leds preceding index
    for( byte i=0; i<index; i++ )
        sendZero();
    // one led on
    sendOne();
    // pad with leds off
    for( byte i=index+1; i<35; i++ )
        sendZero();
}

void sendOne()
{
    digitalWrite(DATA, HIGH);
    digitalWrite(CLK, HIGH);
    digitalWrite(CLK, LOW);
}
void sendZero()
{
    digitalWrite(DATA, LOW);
    digitalWrite(CLK, HIGH);
    digitalWrite(CLK, LOW);
}

Gerben You're a genius!!! Thank you soooo much! This works beautifully! I knew it needed two loops and two separate routines but all i had as a reference was an 8 bit count and just couldn't figure out how to implement it with a 36 bit count. Once again I can't thank you enough! Really appreciate it!!! Best regards, Bryan


text:
What is the actual range of Xbee RP-SMA antenna?
I'm building a Model rocket, and i will use xbee series 1 pro, so i think RP-SMA antenna would be the best to use because i will put the xbee into the rocket. So does anyone know what is the range of the xbee with this antenna?
Can it reach 1000 feet?

At https://www.sparkfun.com/pages/xbee_guide there is a table containing the ranges of the different models. I think your model says 1 Mile. Though these rating are probably very optimistic.


text:
Is it possible to detect host usb device connected to arduino? and how?
let's say that I've connected an arduino uno to a pc, or to a mobile phone via usb .. how can I detect the device type and the running operation system if it's possible?

You can't, using stock firmware. And with custom firmware it's still very difficult.
The USB communication chip on the Uno has no out-of-band means of telling the main MCU that it is connected to a host. You might be able to rewrite the communication firmware on the R3 to tell the main MCU over serial that it is connected, but the firmware on the main MCU will need to be written in such a manner that it will anticipate this.
If you want this to work then you should consider using one that has a native USB connection, such as the Leonardo. You will then be able to query the USB facility directly to know whether or not you are connected to a host.

No. The arduino sees usb through a USB-> UART converter (typically FTDI). UART doesn't allow you to do anything other than listen on the RX line and throw bits at the TX line.

I did not try to go further, but I know there is some information passing on Serial1 when you plug a device.
void setup() {
  Serial.begin(115200);
  Serial1.begin(250000);
}

void loop() {
  if(!Serial1.available()) {
    Serial.println("OFF");
    delay(500);
  }
  else {
    Serial.println("ON");
    Serial1.end();
    delay(500);
    Serial1.begin(250000);
  }
}

Maybe you can try to see if depending on the device, information is persistent, in which case you should be able to detect a specific device / kinf of device ?
I'll look at it tomorrow, maybe will have more code to show...

Unfortunately this proposal is fundamentally mistaken - the Arduion Uno which is the subject of the question does not have a "Serial1".  Also, even in the context of some hypothetical other board, the question is not about detecting if there is a host, but detecting which type and operating system it is running, something that would require identifying and categorizing differences in behavior.


text:
Simulating touchscreen input using PWM
I'm porting a project from a teensy microcontroller to the arduino. Essentially the project uses a microcontroller to simulate touchscreen input for the Nintendo 3DS console. I am doing this by unplugging the touchscreen digitizer of my Nintendo 3DS and putting my arduino in its place. See the link below for the original teensy code and schematics that I'm trying to modify. (The oscilloscope picture below is also credit of author of the teensy code)
https://github.com/dekuNukem/3xtDS
This is a fairly generic touchscreen I'm trying to simulate input for, so I'm not sure what's going wrong. I am not sure if my schematic has a problem, or if the Arduino's PWM frequency limitation is the problem. The teensy code was setup to output at 90khz, while the highest I can possibly set my arduino is around 31khz. I believe this should be good enough because I believe the Nintendo 3DS only samples at around 100 microsecond intervals.
What I have done:

I'm connecting two of my arduino pins to the X+ and Y+ pins where the Nintendo touchscreen digitizer used to be.
I have used a voltage divider to change the arduino's output voltage from 5v to 1.8v, which is the VCC of the nintendo device.
I have used a 0.22uf capacitor and 1k resistor as a DAC to change the PWM output to analog.

I tried troubleshooting by:

using 68 & 120 ohm resistors in my voltage divider for smoother analog PWM response, instead of 68k & 120k resistors
adding a 1N914 diode between the capacitor and ground (since I am using ceramic capacitors, which are bidirectional)
eliminating the while(analogRead(senseY) < 46) line in my code and instead using a static delay of 100 microseconds

Touchscreen press I want to simulate (Yellow is Y+, blue is X+):

My Schematic:

Teensy code ported to arduino:
// I've included the setPwmFrequency() function listed on the arduino site,
// but I'm omitting it here for clarity reasons.

// The main change between the Teensy and arduino is that the teensy uses
// software to lower the PWM voltage from teensy's native 3.3v down to the
// nintendo's 1.8v, while I have instead used a voltage divider on the PWM
// output of the arduino.

// X+ pin of touchscreen.
int touchX = 9;

// Y+ pin of touchscreen.
int touchY = 10;

// Pin to monitor arduino's output of Y+
int senseY = 11;

void setup() {
  // -Change pins 9 and 10 to have 31,250 hz PWM frequency. This is the
  // highest I can set it. Teensy originally set their frequency to 90khz.
  // My difference in frequencies MIGHT be the cause of my problems.
  // I picked pins 9 and 10 because they won't affect timing for millis()
  // and delay.
  setPwmFrequency(9, 1);
  setPwmFrequency(10, 1);

  // Original teensy code set analog write resolution to 9bits.
  // This was necessary because the nintendo touchscreen is 320x240, which is greater than 255 for an 8bit resolution.
  // However, I don't mind this minor accuracy loss! arduino's analog resolution is accurate enough for me.
  pinMode(touchX, OUTPUT);
  pinMode(touchY, OUTPUT);
  analogWrite(touchX, 0);
  disable_touch_screen();
}

void touch_screen_click(unsigned int x, unsigned int y, unsigned int duration_ms) {
  // Calculate PWM value to write  based on the xy touchscreen coordinates we want.
  unsigned int x_potential = ((double)x / 320) * 255;
  unsigned int y_potential = ((double)y / 240) * 255;

  // Start outputting the x value.
  analogWrite(touchX, x_potential);

  // Pull Y+ to ground.
  enable_touch_screen();

  unsigned int start = millis();

  // Keep touch screen pressed for tap duration.
  while(millis() - start < duration_ms) {
    // wait until Y+ pin is in output mode
    // original teensy code checked for 512, which was half of the max value 1024.
    // we're outputting 1.8v with our circuit, but reading analog at 5v
    // so the value we check for is half of this max value: 1.8/5*255=92
    // I COULD have used arduino's Aref, but math is faster than soldering
    while(analogRead(senseY) < 46)
    delayMicroseconds(490);

    // now Y+ pin is in output mode
    analogWrite(touchY, y_potential);
    delayMicroseconds(180);

    // pull Y+ down again to keep interrupt going
    enable_touch_screen();
  }
  disable_touch_screen();
  analogWrite(touchX, 0);
  delay(50);
}

void disable_touch_screen() {
  analogWrite(touchY, 255);
}

// pull Y+ pin low to initialize 3DS's touch interrupt
void enable_touch_screen() {
  analogWrite(touchY, 0);
}

// the loop routine runs over and over again forever:
void loop() {

delay(800);
// tap at 150x150 for 100ms.
touch_screen_click(150, 150, 100);

delay(800);

// tap at 50x50 for 100ms.
touch_screen_click(50, 50, 100);
}

I'm trying to do the same thing with a Nintendo DSi, I'll be watching here :)

Why do you wish to monitor the Arduino's Output of Y+?

@Austin Burk  Which Arduino Board are you using?

I'm using an Arduino Uno.

I am monitoring the Y+ pin because the 3DS console sends the touchscreen interrupt on that pin, according to dekunukem's documentation: https://github.com/dekuNukem/3xtDS/blob/master/overview.pdf
From what I understand, he uses a bit of a hack to get this working by using only two of the four pins for the touchscreen. I believe the 3DS uses a standard 4-wire resistive touchscreen such as this: https://www.sparkfun.com/datasheets/LCD/HOW%20DOES%20IT%20WORK.pdf

I see no mistakes in the code. If you have teensy board, do what Igor Stoppa tells you to, if the fault is not due to the PWM frequency , then I shall have another look at the code.

Do you have an Oscilloscope? If you do, check the analog output that comes after the PWM to Analog converter. It could be an Electronics fault also.

How many free pins do you have on your Arduino board ? If you have 10 or more , and don't mind using 5BIT precision , I have a solution for any electronics fault.

@Mathsman100 I decided to get a teensy so I could rule out the PWM frequency being an issue. No luck, even using the original teensy schematics and code from dekunukem's GitHub page. Unfortunately I do not have an oscilloscope on hand, but I am considering getting one. I have 17 pins free on my arduino. 5bit precision would be a huge accuracy loss for the touchscreen I'm trying to simulate (which has a resolution of 320x240), but I don't mind trying 5bit if you have an idea to troubleshoot. I have already done some basic troubleshooting using a multimeter to verify voltage outputs.

Basically, the problem could be that the ADC is reading faulty readings as the PWM to Analog never works properly if using a fast Microprocessor.

Use this link for reference and comment here if you need any help, or after you try using an OP-AMP DAC(5to8-BIT, you could use 8BIT if possible, but I recommend 5 or 6) to tell the results.

Remember to use 1.8V as supply for OP-AMP and to convert the 5V to 1.8 volt before sending the signal to the Resistors before the input of the OpAmp.(Preferably use transistors for this, instead of Voltage dividers.)

Link for Buffer Image:Buffer

Please Note:I am only telling this for troubleshooting, this may not serve your purpose.

To confirm your analysis that the issue is caused by the lower pwm frequency on the Arduino, did you try reproducing the problem with the teensy? Just divide by 3 the PWM frequency on the Teensy and see if you get the same problems that you are experiencing with the Arduino.

Yes, I have recently purchased a teensy 3.1 specifically for troubleshooting this project and I unfortunately have the same result. This confuses me greatly, because I used the exact same electrical schematic and code listed in dekunukem's documentation that I was referring to. At this point, the only thing I haven't tried is using all 4 pins of the touchscreen rather than just the 2 pin exploit that dekunukem used: https://www.sparkfun.com/datasheets/LCD/HOW%20DOES%20IT%20WORK.pdf


text:
Program arduino via USB while using a Bluetooth module (HC-06)
I have my Arduino Nano connected to the HC-06 module (with the RX/TX pins).
My issue is that when I try to upload new code to my Arduino (via the Arduino IDE, through the USB connection) the Arduino IDE doesn't succeed.
I get this error:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

I believe that it is just trying to upload the code to the HC-06 (instead of the Arduino). Is there a way to overcome this issue?.
Thanks.
Note: I found this entry https://stackoverflow.com/questions/27175937/arduino-program-upload-while-btooth-module-connected-avrdude-stk500-getsync indicating that it wasn't possible (that I need to unplug the module). I am trying to confirm it.

Your code might not work on leonardos/micros, but in any case they don't use pins 0 and 1 to upload so I believe you should be able to upload while the HC-06 is plugged in with either of those.

You might be able to electrically "remove" the blueooth module if it has a distinct reset line you can hold asserted, but unplugging it would be conceptually simplest.

The link in question was correct... you do need to unplug it.
The Arduino's serial chip uses pins 0 and 1 to communicate with the ATmega 328 PU chip onboard, thus you have two independent devices connected to the same wires and both the Arduino main chip and the Bluetooth module are trying to communicate at the same time (rendering all data unreadable by the computer).


text:
How to make sure Arduino's PWM pulses are phase shifted?
I'd like illuminate my room solely with several RGB LED strips using Arduino's PWM (together with LED amplifier and few transistors).
I want the Arduino to control 2 independent chains of LED strips, and I want to make sure, that the LEDs would not blink simultaneously, creating a very strong stroboscopic effect in my room.
How to delay three Arduino's PWM pins half a phase relative to the other three?

Why do you think you'll observe led blink?

@MertGülsoy I will not see LED blinking, but I will see that the stroboscopic effect the blinking would produce.

How much of a delay do you have in mind? A few microseconds? Half a second? What is the PWM frequency? What is its duty cycle? Which pins are you using?

@NickGammon I need to shift for half of the phase, so if I'd run PWN @ 32Hz, it would mean 1/64th of a second. I plan to use standard PWM pins, but now really consider an external PWM generator which could give me a much higher, not audible frequency (to avoid the annoying buzzing sound from the power source).

I'm not sure I understand here. Your eyes won't detect the difference of 1/64th of a second (or less). There are two figures here: the PWM frequency - which helps make the LEDs appear to be dim, and the rate at which they blink, which must be quite slow or you wouldn't notice it.

@NickGammon Yes, the eyes wouldn't notice the 1/64th directly, but they WILL notice the stroboscopic effect of this frequency. I am talking only about the PWM frequency. I never wrote I want to see my LEDS blinking.

You mentioned "I want to make sure, that the LEDs would not blink simultaneously". So there is a reference in the question to blinking LEDs. I'm a little curious now why you want to PWM at 32 Hz. Why not, say, 7813 Hz? I'd like to answer the question, but I want to make sure I'm answering the right question. :)

@NickGammon Thank you very much. I very appreciate your effort. My English might not be perfect, it's not the first language for me. I want simply to replace the traditional room lighting with RGB LEDS.

Your English is fine, I'm just trying to understand the requirements. Any particular reason the frequency has to be as low as you mentioned above? (32 Hz) And why two strips anyway? Are they going to be at different levels? Eg. one bright and one dull?

@Nick Two strips is the absolute minimum to have an acceptable luminosity. They will be mounted together. The RGB LEDS are not too bright... Sorry, I meant to write 32kHz, not Hz, my bad.

You can, see effects of mains frequency in LED's under some conditions.  I used to have an RC plane charger with a bi-color LED that would be green for one battery pack, red for the other, and amber for both. The amber was almost indistinguishable from the red, but I found if I shook my head I could see it as a distinct red and green.  I also noticed that my LED clock's digits would "swim" when I played low notes on the trumpet (later I had to replace the supply capacitor in that clock - I suspect it had been slowly failing for years, allowing the line frequency to modulate the LED brightness)

Have you actually observed this strobe effect?

This (short) code below will achieve what I think you are asking for, on the Atmega328 (eg. the Uno, Duemilanove, etc.).
byte dutyCycle = 80;

void setup()
 {
  pinMode (3, OUTPUT);    // Timer 2 "B" output: OC2B
  pinMode (11, OUTPUT);   // Timer 2 "A" output: OC2A

  // Set OC2A on Compare Match when up-counting.
  // Clear OC2B on Compare Match when up-counting.
  TCCR2A = bit (WGM20) | bit (COM2B1) | bit (COM2A1) | bit (COM2A0);
  TCCR2B = bit (CS21);         // phase correct PWM, prescaler of 8
  OCR2A = dutyCycle;           // duty cycle out of 255
  OCR2B = 255 - dutyCycle;     // duty cycle out of 255
  }  // end of setup

void loop() { }

How it works
The code uses Timer 2 (an 8-bit timer) to count up to 255 in phase-correct PWM mode. Outputs are to OC2A (the "A" output - pin D11) and OC2B (the "B" output - pin D3). The duty cycle is in variable dutyCycle which must be in the range 0 to 255. The timer counts up to 255 and sets OC2A on compare-equal to the dutyCycle number, and it also clears OC2B on compare-equal, when counting up. The second half of the phase-correct cycle does the reverse. Thus the two cycles are of opposite phase.
Frequency
The frequency of the timer is 3.9 kHz. This is because the timer has a prescaler of 8, then it counts up to 255, then it takes two cycles per period (one up, one down):
16000000 / 8 / 255 / 2 = 3921.56 Hz

As Edgar Bonet pointed out in the comments, phase-correct PWM counts are not zero-relative, unlike other counting modes. Thus you divide by 255 to work out the frequency, not 256.
You could select other frequencies by choosing different prescalers.
Proof of operation
The oscilloscope screen here shows the two outputs, out of phase with each other by 50%.

You can see from the circled cursor measurement that the OC2B pin is off for exactly the requested duty cycle (80 µs).
 1/ 16000000 * 80 * 8 * 2 = 8e-005 (0.00008)  --> 80 µs

Just nitpicking: the counter does not count up to 256: it stops at 255. It's frequency, according to the datasheet, is 16 MHz ÷ (8 × 510) = 3921.57 Hz.

grumble - In non-PWM modes a count of zero gives you one cycle, however observed results (from the screenshot above) appear to agree with your assessment. I must admit that the 80 µs on the screen seemed a little low. FWIW the counter is normally zero-relative, so a count of 255 is 256 cycles.

This is a feature of phase-correct PWM: it takes 255 (prescaled) cycles to count up from 0 to 255, then 255 cycles to get back to zero. In contrast, both normal counting (mode 0) and fast PWM (mode 3) have a period of 256 cycles: 255 cycles to count up, and then one extra cycle to roll back to zero.

@EdgarBonet - thanks for the correction, I have amended the answer.

Why not put a capacitor (and current limiting resistor) in the circuit for each color of each LED? (The output from the Arduino would lead first to a current limiting resistor, value picked to limit the current to the LED to it's max, as usual. Then a small capacitor between the signal line and ground.) That will average out the output and change a square wave output to a DC output (With a fair amount of ripple in it.) The ripple shouldn't matter, but the LEDs won't turn fully off, so the strobe effect should be all but eliminated, and the apparent brightness of each output should be the same.
Then you can use unmodified PWM and don't have to mess with the timers on your Arduino (which affects other things besides PWM.)

This is a very bad idea. Putting a capacitor on PWM signal kills the dimming effect - the light will stay simply ON for most dimming settings and will put a very high load on the driver especially on low light settings. The driver will frantically try to keep the capacitor full by providing increasingly large charging current during the shorter "on" phase (due to dimming).

I just edited my answer to add that you would also need a current limiting resistor. If you limit the max current to the capacitor to the max current for the LED, then lowering the duty cycle of the PWM should lower the average voltage coming out of the capacitor.

Current limiting resistor - is just a resistor that will limit the current by means of consumption. Something tells me, that to get a noticeable effect of dimming you would need such a resistor that would significantly reduce the voltage to the LEDS. Did you actually try what you propose?

No, you misunderstand. Put a current limiting resistor BEFORE a capacitor. The current limiting resistor would limit the max current that would flow out of the output pin to the max on current of the LED. Then any PWM duty cycle below 100% would further limit the average current flowing into the capacitor, which should reduce the brightness of the LED and create a (admittedly noisy) steady-state voltage to the LED, all but eliminating the strobing effect.

And no, current limiting resistors do not "limit current by means of consumption." They drop voltage by means of emitting heat (consumption). They also limit the total current through the circuit, as described by Ohms law.

I have not tried this specific application, but it's a straightforward RC filter.