body:
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);
        }

title: Capturing images from OV7670 (w/o FIFO) using Arduino Uno?

Answers: 2

body:
You should start from connecting Arduino UNO to PC. For this purpose use the following article: [Arduino Uno и камера ov7670 — пример использования][1]. 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:

1. 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.

2. 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.

3. 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][2].

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 телефон][3]. 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.

  [1]: http://privateblog.info/arduino-uno-i-kamera-ov7670-primer-ispolzovaniya/
  [2]: http://privateblog.info/files/FrameGrabber.7z
  [3]: http://privateblog.info/peredacha-kartinki-s-ov7670-cherez-arduino-uno-na-android-telefon/

body:
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:

>1. different resolution VGA (640 x 480); - QVGA (320 x 240); - CIF (352 x 240); - QCIF (176 × 144);

>2. transmission speed up to 30 fps,

>3. several ways to encode an image RAW RGB, RGB 565/555, YUV / YCbCr 4: 2: 2

>4. 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.

1. 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.

[![enter image description here][1]][1]

Connection scheme ov7670 to Arduino Uno

2. 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:

1. 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

2. Configuring the I2C Interface

>TWSR & = ~ 3; // disable prescaler for TWI

>TWBR = 72; // set to 100khz

3. 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

4. Camera setup

>....

>wrReg (0x12, 0x80);

>delay_ms (100);

>wrSensorRegs8_8 (ov7670_default_regs);

>wrReg (REG_COM10, 32); // PCLK does not toggle on HBLANK.

>...

5. 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.

[![enter image description here][2]][2]

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.

[![enter image description here][3]][3]

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 );

3. 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

4. Results

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

>1. The lack of an internal buffer leads to the blurring of the picture, it is immediately transferred to the computer, and this takes time.

>2. There are artifacts in the form of horizontal stripes - synchronization failure in obtaining a picture. Instead of the gradation of gray sent tsvetraznostnaya component.

>3. The subject must be in the focus of the camera for a clear image

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

  [1]: https://i.stack.imgur.com/r7TsL.jpg
  [2]: https://i.stack.imgur.com/grxzk.gif
  [3]: https://i.stack.imgur.com/eSTbM.gif


body:
I am using Arduino GSM Module and Arduino UNO

![enter image description here][1]

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][2]. The only clear reply is reading from the SIM.

Is it possible to add phonebook entry to SIM card?
Do you know a tutorial?

  [1]: https://i.stack.imgur.com/0Kf9Y.gif
  [2]: https://arduino.stackexchange.com/questions/1370/getting-the-contacts-storing-contacts-to-sim-card

title: How can I add phonebook entry to sim card using Arduino GSM shield?

Answers: 1

body:
.

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


body:
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

title: Using Arduino to show images in Serial Monitor

Answers: 1

body:
Based on [this guide](http://frenki.net/2013/12/convert-optical-mouse-into-arduino-web-camera/), 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.


body:
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.

title: Sensors to use in Pets

Answers: 0


body:
I am trying to upload to my nano the code [attached][1]. 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;

  [1]: http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html

title: "variable must be const" fix for Arduino progrem

Answers: 1

body:
<!-- language-all: lang-C++ -->

Using the source from [this link](http://arcfn.com/files/arduino-tv-b-gone-1.2.zip) 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.


body:
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](http://www.amazon.co.uk/FamilyMall-KY-008-Transmitter-Module-Arduino/dp/B00KYHL7HO).

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. :)

title: Responding to a broken laser beam?

Answers: 1

body: 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.


body:
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][1].

  [1]: https://arduino.stackexchange.com/questions/10389/why-timer1-does-not-generate-correct-period-on-ctc-mode-with-a-resolution-of-5us

title: How to precisely control servo motor by changing duty cycle?

Answers: 1

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


body:
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! :)

title: Adafruit Music Maker Shield - Retrieve song names from SD Card

Answers: 1

body:
The adafruit library was is similar to the prior [SFEMP3shield library](https://github.com/mpflaga/Sparkfun-MP3-Player-Shield-Arduino-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](https://github.com/mpflaga/Sparkfun-MP3-Player-Shield-Arduino-Library/blob/master/SFEMP3Shield/Examples/FilePlayer/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.


body:
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?

Answers: 5

body:
From the Arduino site for [Serial.write](http://arduino.cc/en/Serial/Write) and [Serial.print](http://arduino.cc/en/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

body:
`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.

body: 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.

body:
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 :**
[![enter image description here][1]][1]

**Code:**

      Serial.print("HELLO");

**SERIAL OUTPUT :**
[![enter image description here][1]][1]

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 :**

[![enter image description here][2]][2]

  [1]: https://i.stack.imgur.com/nVEeo.jpg
  [2]: https://i.stack.imgur.com/f6U7E.jpg

body:
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...


body:
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.

title: Charging Li ion cell using arduino

Answers: 1

body:
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:

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/bGQGH.jpg


body:
    #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

title: Scope error in arduino PinChangeInt library

Answers: 1

body:
You have a typo:

    PCintPort::attachInterrupt(SensorPin,blipCount,FALLING);

Should be:

    PCintPort::attachInterrupt(SensorPin,blipcount,FALLING);
                                             ^
Note the lower-case "c".


body:
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?

title: Isolating IR receiver from disruption?

Answers: 1

body: 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.


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

Answers: 1

body:
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;
         }
        }
    }


body:
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

title: Turning all 35 leds on sequentially with MM5451

Answers: 1

body:
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);
    }


body:
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?

title: What is the actual range of Xbee RP-SMA antenna?

Answers: 0


body: 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?

title: Is it possible to detect host usb device connected to arduino? and how?

Answers: 3

body:
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.

body: 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.

body:
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...


body:
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+):**
![][1]

**My Schematic:**
![enter image description here][2]

**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);
    }

  [1]: https://i.stack.imgur.com/mwlpq.png
  [2]: https://i.stack.imgur.com/YSW6R.png

title: Simulating touchscreen input using PWM

Answers: 1

body: 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.


body:
I have my Arduino Nano connected to the [HC-06][1] 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.

  [1]: http://www.banggood.com/HC-06-Wireless-Bluetooth-Transceiver-RF-Main-Module-Serial-For-Arduino-p-80364.html "HC-06"

title: Program arduino via USB while using a Bluetooth module (HC-06)

Answers: 1

body:
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).


body:
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?

title: How to make sure Arduino's PWM pulses are phase shifted?

Answers: 2

body:
<!-- language-all: lang-C++ -->

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%.

![Timer output][1]

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

  [1]: https://i.stack.imgur.com/khmVI.png

body:
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.)


body:
I want to use Arduino Yun as a client, that connects to my nodejs server, receives a message from nodejs and then change led pin 13 on/off according to the message send.

I have this example of a nodejs server:

      var express = require('express');
    var http = require('http');
    var url = require('url');

    var app = express();

    //app.set('port', 8080);

    var server = http.createServer(function(request, response){
     console.log('Connection');                  var path = url.parse(request.url).pathname;

     switch(path){
      case'/':
       response.writeHead(200, {'Content-Type': 'text/html'});
       response.write('Hello World');
       response.end();
       break;
      case '/arduino/digital/13/0':
       response.writeHead(200, {'Content-Type': 'text/html'});
       response.write('Led 13 is off');
       console.log('Led 13 is off');
       response.end();
       break;
      case '/arduino/digital/13/1':
       response.writeHead(200, {'Content-Type': 'text/html'});
       response.write('Led 13 is on');
       console.log('Led 13 is on');
       response.end();
       break;
      default:
       response.writeHead(404);
       response.write("Oops, this doesn't exist - 404");
       response.end();
       break;
     }

    });

    //server.listen(8080);

    var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
    var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'

    server.listen(server_port, server_ip_address, function () {
      console.log( "Listening on " + server_ip_address + ", server_port " + server_port )
    });

The server is running on an openshift nodejs server - It's not Localhost!

Here is the Arduino sketch I use:

    /*
     Possible commands created in this shetch:
     * "http://yunobomber-cuebo.rhcloud.com"                         -> Serial Monitor "Hello World"
     * "http://yunobomber-cuebo.rhcloud.com/arduino/digital/13/1"    -> Serial Monitor "Led 13 is on"  &  digitalWrite(13, HIGH)
     * "http://yunobomber-cuebo.rhcloud.com//arduino/digital/13/0"   -> Serial Monitor "Led 13 is off" &  digitalWrite(13, LOW)
     */

    #include <Bridge.h>
    #include <HttpClient.h>

    HttpClient client;

    void setup() {
      Bridge.begin();                                                          // Bridge startup

      Serial.begin(9600);
      while (!Serial);                                                         // wait for a serial connection
    }

    void loop() {
      // Initialize the client library
      HttpClient client;

      // Make a HTTP request:
      client.get("http://yunobomber-cuebo.rhcloud.com");       // Insert alternative url for other commands - See explanation at top

      while (client.available()) {                             // Read message from server
        char c = client.read();
        Serial.print(c);
      }
      Serial.flush();
      delay(5000);
    }

    void process(HttpClient client) {
      String command = client.readStringUntil('/');

      if (command == "digital") {
        digitalCommand(client);
      }
    }

    void digitalCommand(HttpClient client) {
      int pin, value;

      // Read pin number
      pin = client.parseInt();

      // If the next character is a '/' it means we have an URL
      // with a value like: "/digital/13/1"
      if (client.read() == '/') {
        value = client.parseInt();
        digitalWrite(pin, value);
      }
      else {
        Serial.println('Error: Could not read url!');
      }
    }

The serve works as it should, which can be seen here:
http://yunobomber-cuebo.rhcloud.com

I'm also get the message send from the server, when I read serial monitor, so the connection to the server from the Yun is also working. I can also console.log on the server side and see that a connection is established from the Yun.

The problem seems to be with the readStringUntil(); method, what I want to do is actually readStringAfter(arduino/), but such a method doesn't exist or at least I'm not sure how to make one?

Also I wonder if my approach is wrong, since I use REST calls to control the Yun, maybe I should solve it diffenrently, since I've already established a connection to and receiving input from the nodejs server?

Hope that someone can help my understand and solve this issue?

title: How to use console.log message from nodejs server, to control led pin 13?

Answers: 0


body:
I don't want the same string to be printed again and again. I'm getting the data into an Excel sheet.

    byte readValue1=0;
    byte readValue2=0;
    int add=0;
    int row=0;
    int Zigbee1=0,Zigbee2=0,Zigbee3=0;
    void setup() {
     Serial.begin(9600);
            Serial.println("CLEARDATA");
            Serial.println("LABEL,Time,Zigbee,a1,a2,a3,a4,a5,a6,a7");
            row++;
    }

    void loop(){
      String a1,a2,a3;
      String c1,c2,c3;
      int b;

      if (Serial.available()>21){
      if(Serial.read() == 0x7E) {
       for(int i=0; i<10; i++){
        byte discard = Serial.read();
       }
                            add = Serial.read();
                           if(add == 33)
                            {
                            a1 = func1();
                            if(a1==c1){
                              b=0;
                            }
                            else
                            {
                              b = a1.length();
                            }
                            if(b != 0)
                           {
                            Zigbee=1;
                            Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                            Serial.print(","); Serial.println(a1);
                            row++;
                            }
                            }
                          else if(add == 48)
                            {
                            a2 = func1();
                            b = a2.length();
                            if(b != 0)
                          {
                            Zigbee=2;
                            if(a2!=c2){
                           Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                           Serial.print(","); Serial.println(a2);
                            }
                            c2=a2;
                           row++;
                            }
                            }

                           else if(add == 69)
                            {
                              a3 = func1();
                              b = a3.length();
                              if(b != 0)
                             {
                              Zigbee=3;
                              Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                              Serial.print(","); Serial.println(a3);
                              row++;
                        }
                            }
    }
    }
    }

title: How to discard same string received at Arduino

Answers: 2

body:
Only print the string when he has changed?

    String previousString = "";
    String newString = "";

    if(newString != previousString){
       println(newString);
       previousString = newString;
    }

I'm not sure if it's applicable in your situation, just the first thing that came to my mind. You (kinda) should make a function of it, so that you don't have to copy/paste it all the time and it'll look way better.

EDIT:

A fuction could be made like so:

    String previousString = ""; //Put this above your setup code (global variables)

    void NoSpamString(String input){ //Put this block before the setup
       if(input != previousString){
          println(input);
          previousString = input;
       }
    }

You can then use: `NoSpamString("text");` to print a line withouth spamming it.

body:
i solved it out by using comparing the received bits in that frame..
here is my code..

                       if(add == 33)
                        {
                        a1 = func1();
                        b = a1.length();
                        if(b != 0)
                       {
                        Zigbee=1;
                        if(a1!=c1)
                        {
                        Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                        Serial.print(","); Serial.println(a1);
                        }
                        c1=a1;
                        row++;
                        }
                        }
                      else if(add == 48)
                        {
                        a2 = func1();
                        b = a2.length();
                        if(b != 0)
                      {
                        Zigbee=2;
                        if(a2!=c2){
                       Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                       Serial.print(","); Serial.println(a2);
                        }
                        c2=a2;
                       row++;
                        }
                        }

                       else if(add == 69)
                        {
                          a3 = func1();
                          b = a3.length();
                          if(b != 0)
                         {
                          Zigbee=3;
                          if(a3!=c3)
                         {
                          Serial.print("DATA,TIME,"); Serial.print(Zigbee);
                          Serial.print(","); Serial.println(a3);
                         }
                         c3=a3;
                         row++;
                    }
                        }


body:
I'm trying to start with the SainSmart 4x20 serial LCD, and copied the library to the Arduino library:

![enter image description here][1]

So `LiquidCrystal_I2C.h` is included. But when I try to compile an example sketch it says

> Arduino: 1.7.0 (Windows 7), Board: "Arduino Uno"
>
> HelloWorld_i2c.pde:2:31: fatal error: LiquidCrystal_I2C.h: No such file or directory
>
> compilation terminated.
>
> Error compiling.

Any ideas how to fix this?

  [1]: https://i.stack.imgur.com/QLGNM.png

title: Arduino IDE doesn't find header file

Answers: 2

body:
There is not enough info to give a specific answer so I will give some troubleshooting tips:

 1. First make sure at the top of your code you have: #include <LiquidCrystal_I2C.h> - with angle brackets
 2. You may also need the Wire header file: #include <Wire.h>  - with angle brackets
 3. Make sure you Include Serial
 4. Make sure there are no extra folders in the library for example there should be a folder called liquidcrystal inside the liquidcrystal folder
 5. If all fails copy the code from the header file make a new file in the IDE paste it in there and call it LiquidCrystal_I2C.h

Hope one of those solves your problem.

body:
I copied the SainSmart library to the IDE's library folder, not noticing that there was already a folder named "LiquidCrystal". Apparently the files added to the existing folder are being ignored.

Renaming the SainSmart library before adding it solves the problem.


body:
I am trying to make [Ken Sherriff's version][1] of the TV-Be-Gone with the Arduino using the updated v1.2 software.  He uses this setup:
## His Setup ##
![Setup][2]
## My Setup ##
I used the Arduino Nano with same MCU (Atmel ATmega328) as Uno but changed a few other things also. For power I supplied 9v to the vin pin but supplied the transistor with 5v from the 5v pin. I used this [Instructable][3] by the same person.  The only major change was I used a PN2222A transistor instead of 2N4401.

![enter image description here][4]

## Problem ##

My problem is that even though when I push the button the infrared light blinks for a while sending the different codes my receiver won't pick it up. I checked my receiver with other remotes and it works and I tried at close and far range. My receiver just blinks if it senses any infrared command regardless of what type of remote but it doesn't work with my Arduino TV-Be-Gone. I haven't tried it with a real TV yet but would like for it to work before I try it on a real one.

  [1]: http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html
  [2]: https://i.stack.imgur.com/8dqTQ.png
  [3]: http://www.instructables.com/id/Arduino-TV-B-Gone/
  [4]: https://i.stack.imgur.com/vPldJ.jpg

title: Ken Sherriff Arduino Version Tv-Be-Gone

Answers: 0


body:
After execute the program of below, the 13 pin output is 4.8v. Why it's not 3.3v?

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

    void loop() {
      // put your main code here, to run repeatedly:
      digitalWrite(13, HIGH);
    }

title: output of yun is not 3.3

Answers: 1

body: The Atheros chip on the Yún is run off 3.3V, but the AVR chip, which is what is connected to the external pins, runs off 5V. What you are seeing is normal (a bit low though, but within spec).


body:
I'm testing out an accelerometer and I want to know if there's a way to make it so that the serial monitor will update the values without printing a new line. Ideally the serial monitor would say something like:

    Accelerometer X: $xval
    Accelerometer y: $yval

and then instead of printing two new lines each time, it just updates the values. Is there anyway to do that in Arduino? Thanks.

title: How do I update the serial monitor without printing a new line each time?

Answers: 3

body: No. The serial monitor does not support terminal handling. Either use a serial communications program that does and use those features, or write a custom client that will only update those values in its interface.

body:
You might want to look into [processing][1]. You can use that to view the accelerometers position in 3d and see the values changing if that's what you want. The official Arduino site talks about it [here][2].  Here is a great [tutorial][3] on it.

  [1]: https://processing.org/
  [2]: http://playground.arduino.cc/interfacing/processing
  [3]: https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing

body:
The ultra-basic "serial monitor" in the Arduino IDE cannot do what you want.

Instead you need to either write a special client program, or use a more standard serial terminal program, such as Tera Term (Windows), Minicom (Linux), etc.

These standard serial terminal programs use a special sequence of characters called *ANSI escape codes* which manipulate the display, doing such things as setting colours, moving the cursor around, etc.

More information on ANSI escape codes can be found here: http://en.wikipedia.org/wiki/ANSI_escape_code


body:
in "Disabling the Bridge Script" of http://cylonjs.com/documentation/platforms/yun/

I did:

> Edit the /etc/inittab file to comment out the ttyATH0 line (put a # before it)

    ::sysinit:/etc/init.d/rcS S boot
    ::shutdown:/etc/init.d/rcS K shutdown
    #ttyATH0::askfirst:/bin/ash --login

But I want to turn it on or off manually. Then I can program through WiFi if I want.

How to do that?

title: yun manage bridge manually

Answers: 0


body:
Can I turn Yun to ad hoc mode?

How to?

![ad hoc mode][1]

  [1]: https://i.stack.imgur.com/TL5Yi.png

As the image above I can see the Ad-Hoc model in that drop down list. But only WEP for its security.

title: how to turn yun to ad hoc mode?

Answers: 0


body:
I just got a Serial LCD and wanted to test it out with a game. I found this [site][1] with game conversions and wanted to use [this game][2].  However since my serial LCD use the LiquidCrystalic2 library the code in its current state won't work. Is there a simple method of converting or porting liquidcrystal to LiquidCrystalic2? Or if someone knows of a simple game in regards to hardware that uses a serial lcd and could direct me to a link that would be great.

  [1]: http://eturnerx.blogspot.com/2012/08/arduino-lcd-hunt-wumpus-conversion.html
  [2]: http://eturnerx.com/files/arduino/003_wumpus_hunt_eturnerx_arduino_lcd.html

title: Converting Arduino LCD Programs to Serial I2C LCD code

Answers: 1

body: i got my lcd working on I2C following the steps in this link http://forum.arduino.cc/index.php?topic=128635.0


body:
I purchased a half dozen fake Arduinos hoping to build a bunch of projects without paying a fortune. I have all the drivers installed, and the port shows up in the Arduino IDE. The problem is when I try and upload the code I get the following error:

>can't open device "/dev/cu.wch": No such file or directory

I played around a little and tried running:

    sudo ln -s cu.wch\ ch341\ USB\=\>RS232\ 1a1220  cu.wch

After running this a new port shows up called `cu.wch`, and if I select that it works.

The issue is the Arduino's port is `cu.wch ch341 USB=>RS232 1a1220`, but for some reason the IDE is trying to write to `cu.wch`. By linking the folders I can fix this but since it is a hack every time I restart my computer I have to rerun the command. Is there a way I can either rename the Arduino port or permanently link the folder?

*I am using OSX 10.10 and Arduino IDE v1.6.3*

title: Arduino uploading to the wrong port

Answers: 2

body: I would guess the problem is the IDE not properly handling device names containing spaces. Consider your symlink a workaround rather than a hack - unless you want to repair the IDE itself.

body: You must download the CH431 drivers to your computer and restart. This will solve your problem. Google these drivers, you should be able to find them. If not, let me know and I can send you a link to my drive.


body:
I bought a Arduino Wi-Fi Module it does not have any manual or catalog

my project is to turn on/off a motor wireless
![enter image description here][1]
 it is working grate for the serial/usb cable but i couldn't make it work for wireless/wifi

after some walking around i found that my wifi module is making a wifi network called "HL-link_A49D"
with password from 1-8 and after network scanning i found that the module ip is 192.168.16.254/ username and pass are admin/admin
here is what i found

![enter image description here][2]

my question is how could i connect to the wifi module and send commands to it ?

  [1]: https://i.stack.imgur.com/EvYip.jpg
  [2]: https://i.stack.imgur.com/hanz4.jpg

title: Wi-Fi Module communication?

Answers: 1

body:
Good detective work so far!
In the admin page you found one can see the name of the module: `HLK-RM04`. Googling on that I found the [manufacturer/seller page](http://www.hlktech.net/product_detail.php?ProId=39).

A PDF with some information can be found [here](http://www.hlktech.net/inc/lib/download/download.php?DId=21).

Also one link with [somebody's experience](http://rayshobby.net/first-impression-on-hlk-rm04-serial-to-wifi-module/) with the module.

For other projects you might want to try as well the ESP8266 - very cheap and seems a lot of people have experience with it, so you might find more information on the net.


body:
I'm doing a project for school with an arduino uno. I want to control a motor using a RF-module as remote control. I need the library Virtualwire.h to use the RF-module and the library Servo.h to control the motor. I downloaded the library Servotimer2.h because Virtualwire.h and Servo.h both want to use timer 1 of the arduino. I added this library to arduino libraries but arduino doesn't recognise it as a library when I include it to my program.
can someone help me with this issue? I tried to find a solution but can't find it.
Many thanks allready!

title: Servotimer2.h is not recognised as a library by arduino uno

Answers: 0


body:
So my question is that I am trying to use a arduino library called Accel Stepper to control a stepper motor, I made code that makes the stepper motor move one rev clockwise and then one rev counter clockwise

however as i run the code, the motor has no problem going clockwise, however when it comes to reversing the shaft of the motor stays still and doesn't move while the whole motor itself vibrates, what could be my problem?

here is my code:

        // MultiStepper.pde
        // -*- mode: C++ -*-
        //
        // Shows how to multiple simultaneous steppers
        // Runs one stepper forwards and backwards, accelerating and decelerating
        // at the limits. Runs other steppers at the same time
        //
        // Copyright (C) 2009 Mike McCauley
        // $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

        #include <AccelStepper.h>
        int user = 800;
        // Define some steppers and the pins the will use

        AccelStepper stepper2(AccelStepper::DRIVER, 9,8 );
        AccelStepper stepper3(AccelStepper::DRIVER, 4, 7);

        void setup()
        {

            stepper2.setMaxSpeed(1000);
            stepper2.setSpeed(300);

        }

        void loop()
        {
            // Change direction at the limits
          stepper2.moveTo(user);
          stepper2.setSpeed(300);
          stepper2.runSpeedToPosition();
          if (stepper2.distanceToGo() == 0){
            stepper2.moveTo(-stepper2.currentPosition());
            stepper2.setSpeed(300);
            stepper2.runSpeedToPosition();
          }

        }

title: Accel Stepper help, stepper not going backwards

Answers: 2

body:
Work through your code. When it gets to the target position, your loop looks like this:

    void loop()
    {
        // Change direction at the limits
      stepper2.moveTo(user);
      stepper2.setSpeed(300);
      stepper2.runSpeedToPosition();
        stepper2.moveTo(-stepper2.currentPosition());
        stepper2.setSpeed(300);
        stepper2.runSpeedToPosition();

    }

So you say, move to position 'user', then move to position '-stepper2.currentPosition'. Then as the loop comes around you again say move to position 'user', and so on.

The loop will repeat hundreds if no thousands of times per second, so you are basically telling the stepper motor to change direction thousands of times per second which will be why the motor starts vibrating when it gets to the user position.

If, just for the sake of argument, you were to move the first three lines of code in the loop() function to the setup() function, what behaviour do you think you will observe?

body:
to reverse the direction try passing negative speed value to speed

like

stepper2.setSpeed(-300);


body:
I came across this post

https://stackoverflow.com/questions/10327506/android-arduino-bluetooth-data-transfer

where the author sends files from the arduino to android platform over bluetooth.

I am wondering, is this possible to achieve with the ESP8266 SoC?

I have no experience with it, but i am willing to buy and experiment, if it hads that functionality.

title: Sending file from SD card to android using ESP8266

Answers: 0


body: I am making a moving robot that will be autonomous in many respects. However if something goes wrong I want to be able to use a remote to push a button and it stop in its tracks no matter what function its in.  My understanding is that interrupts can do that. The official site I did not find to be helpful. Any ideas? Or if the scheduler library would be of use.

title: Intterupts For Arduino

Answers: 2

body:
An interrupt can not *always* stop the code, although that is almost always the case. Certainly having an interrupt based kill switch would be better than a "regular code" polled one, which would still be better than nothing. If possible I would feel safest with a cut-power-to-the-whole-thing style safety switch.

Many functions that have sensitive timing constrains disable interrupts while they are active. It is rare for any of these to take a noticable amount of time, but it is possible that a bug in an interrupt dissabled function or another interrupt function could cause it to block and in that case your stop switch wouldn't work. rare, but possible.

I suppose you could turn on the chip watchdog timer, have a regular timer based interrupt reset the watchdog timer at a certain interval, and have your interrupt safety switch enabled. Then if interrupts ever stopped firing for too long the chip would reset itself. [Checkout AVR132: Using the Enhanced Watchdog Timer][1]. I've never used the watchdog myself, but it exists for a reason.

I don't have enough experience with a scheduler system to know if they would be helpful.

  [1]: http://www.atmel.com/images/doc2551.pdf

body:
If you are using an arduino uno, pin 2 and 3 are the hardware interrupt pins. You may send rising , falling, high or low signals to these pins using a Bluetooth module (for eg). Say for eg when you press the remote switch, Bluetooth gets a low signal and triggers an interrupt. If the output of Bluetooth is connected to pin 2, then in the setup you have to declare

    attachInterrupt(0, stoprobo, LOW);

And in the function stoprobo, you can write the code to stop your robot.


body:
I am using Arduino Uno Rev 3, and according to [this link][1] we can achieve 2000000 baud rate.

This problem can be easily repeated by the following code:
<!-- language-all: lang-cpp -->

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

    void loop() {
      int val = 234;
      Serial.println(val);
    }

I am using the serial-USB cable. To read the data, I used Python pyserial (< 20 lines of code including empty lines and import lines):

    import serial
    import matplotlib.pyplot as plt

    LEN = 10000
    data = []
    ser = serial.Serial('COM3', baudrate=2000000)
    for i in range(LEN):
        try:
            data.append(int(ser.readline()))
        except:
            pass
    ser.close()

    # %% Plot data
    plt.figure(figsize=(6, 4))
    plt.plot(data)
    plt.savefig('data.png')

Here is what I got:

![Plot of data][2]

Edit below
----------

Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?

Code:

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

    void loop() {
      int val = 234;
      val += int(512 * (sin(float(millis()) * 0.01) + 1)) * 0.1;
      Serial.println(val);
    }

Output:

![Output][3]

  [1]: https://arduino.stackexchange.com/questions/296/how-high-of-a-baud-rate-can-i-go-without-errors
  [2]: https://i.stack.imgur.com/sFZUG.png
  [3]: https://i.stack.imgur.com/UeP9p.png

title: Sending constant int from Arduino to PC causes error

Answers: 0


body:
I know this is very common project and it's already been done, however, most of the guides don't have a clear instruction, and being this inexperienced, I struggle to understand exactly what's going on.

I'm currently working on a line following robot, but I'm largely inexperienced. For the most part, I'm going to be using SparkFun's Magician Chassis with Inventors Kit. The main sensor available is the Line Sensor Breakout(QRE113), which I have 3 of, but I'm not sure if whether I should use the Digital or Analog model.

Also, I'm having trouble finding how to wire this circuit. I know as much that, I have to connect the motors, diode, simple transistor(with emitter, collector, and base), some sort of resistors, and maybe a capacitor(this one I'm not too sure of). All of this has to be set on a breadboard, and be jointly connected to the arduino. I think there has to be two identical circuits on the breadboard for each motor, as the voltage of the sensor is expected to decrease when it encounters a white reflective surface(tape), this in turn will slow down the motor, which would allow the robot to turn in the direction of the tape, due to the other wheel not slowing down. One part of the circuit, should handle the motor drive circuit, this should be the output of the transistor, but I'm not sure how to use the arduino(redboard) to control the speeds of the motors using the sensors, which I think will go into the base of the emitter. Which pins should I use basically?

Apart from this, how will the code look? But I think this is dependent on how I wire it, right?

This is what I'm using...

https://www.sparkfun.com/products/12060

https://www.sparkfun.com/products/9453

title: Line Follow Vehicle

Answers: 1

body:
You should, really, cut this complete project into smaller little projects.
Actually, first you should get clear what you want, there are a lot of possibilities.

 - Try to get one line sensor working
 - Try to get one motor working (check Pulse Width Modulation)
 - Try to get the two motors working and put them on the chassis.
 - Make the motors drive around a little, turn and reverse.
 - Get the three line sensors working (I think you're following a single line withouth crossroads etc.?)
 - Make your arduino check for changes in the pattern 0 1 0 respectively for the line sensors would mean that you're on the line. If the pattern is 0 0 1, you're driving off the line to the left.
 - Use the engines to adjust back onto the line.

I've actually done a project similiar to this one, but we used a motor-board instead. Driving the motors with a transistor&diode(&mosfet?) should indeed also be possible... but it'll get difficult once you want to be able to also reverse the motor (check H-Bridge motor driver).

For the patterns, you should make a `switch case` which checks the last pattern and keeps steering until he finds the right pattern again. But this can be achieved in many other ways.

Try to get a line sensor working, be sure to check some tutorials before you ask here and try to use different kinds of tape, blue tape didn't work for us :)

It's a really fun project, with lots of possibilities.

----------

Below the schematics we used in the project.

 - We used a motor controller board.
 - Bluetooth module to receive command/routes from the server.
 - (LS) line sensors, 5 of them, to see crossroads/sideroads.
 - (Infrarood) IR sensors for collision detection.
 - (RS) I actually have no idea which sensors these are.
 - (Ultrasonic Sensor) Ping sensor to determine distance to other robots.

![schematics][1]

  [1]: https://i.stack.imgur.com/9MGwa.png