text:
matrix buttons 8x8
Hi I have 8 buttons on my Arduino uno and I want to create a matrix 8x8 and give each button a row and a column respectively it is not a keypad just 8 buttons each button have a row  and a column  ex:                   y
                                                          x(0,0,0,0,0,0,0,1)
                                                            1,0,0,0,0,0,0,0
                                                              .....
to compare it with other values on my visual studio c# , I can't find anything about this .
anyone can help ?

... ... ... um... what?

sorry it's not very clear / I want to create a 8x8 matrix

An 8x8 matrix has, by its simple definition, 64 buttons. Do you have 64 buttons?

And I have 8 push buttons for each button I want to assign a row and a culomn like row[1]column[1] to push button 1

You have "8 buttons for each button" - you aren't making any sense whatsoever.

An 8x8 matrix has 64 buttons. That's what an 8x8 matrix is. The reason why you can't find an answer to your problem whilst searching is simply because you do not know what your problem is. I think you need to rewind and think about what you want to achieve, not how you think you want to go about achieving it.

@Majenko There's punctuation missing. This is how I think he means it to read: "I have 8 push buttons. For each button I want to assign a row and a column."  The question still doesn't make sense, but at least that sentence does.

I have a windows form application that have 8x8 labels each label have an x and y

Does this do what you want?
int col;
int row;

int buttonPressed = readButtons();  // <-- You implement this!

switch (buttonPressed) {
    case 1:
       row = 7;
       col = 3;
       break;
    case 2:
       row = 1;
       col = 2;
       break;
    case 3:
       row = 0;
       col = 4;
       break;
    // and so on
}

something like that , when i press the button if it have the same value of x and y of the labels the label will change color , hhow can i post a pic to clarfy

The code above lets you specify an x and y (actually row and col but you can rename them) value associated with each button.  To compare them with other numbers -- use if (row == someOtherRow) and so on. If you want someone to plumb this into some other code you have, you'll need to post the code -- we can't guess it.

is there a way to discuss this with you by email? i'm getting a lot off errors here

Break the problem down into little pieces and get each piece working one at a time. If you're getting compiler errors, strip out all the code, and just put your little piece in, and get that working. Compare it to examples (Google...). If you can't work out a particular thing, you can post a question here (Arduino specific) or in StackOverflow (C++ questions).  If it's related to code in my answer, ask here :)

I can't add a picture here ?

i added a question please check it

authors: Вихор Дмитрий


text:
Can I safely power my UNO and DC motors with the 5v1A and 5v2.1A ports on a USB charger?
I have USB charger battery pack with two output ports (Fremo C510).  One is marked as 5 volts 1 amp, and the other as 5 volts 2 amps.
I'm building a toy robot and would like to run the UNO off of one of those ports, and the motors off of the other.
Can I safely do that?  I have two main concerns:

Can I safely power the arduino with that current?
If I power both the motors and the arduino from that source (two usb ports connected to the same battery), will I still have to worry about spikes from switching the motors on and off?  I don't know how those ports are wired to the actual battery inside.

I don't know how those ports are wired to the actual battery inside. -- Neither do we.

You can power the Arduino from either side, since it will only draw what it needs, and most arduinos are powered from a .5 amp USB port. But you'll want to reserve the higher current side for the motors.
Make sure your motors' total draw (including starting current) doesn't exceed the 2 amps available.
Unless you can find out for sure that the two power ports are isolated from one another, you're better off to assume they are not and provide motor spike damping yourself.

Sometimes the small-print in these chargers says that they can supply a max of 2.1A in total - you might want to  check that.

Even if that is the case with this charger, the Arduino very likely won't draw even half an amp, leaving well over 1 amp out of the of the total for the motors. They would require the 2 amp port to take full advantage of it. In that case the motors will have to use less than the full capacity by however much the Arduino needs to function.

source: Stack Exchange

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

sort: votes


text:
Get pixel data with OV7670 (w/o FIFO) and Arduino Uno
I have read a great deal today about interfacing the OV7670 with the Arduino Uno. I decided to jump in and start tinkering with this thing. I wired it up according to this schematic:

And I copied and pasted the sketch I found here (http://www.instructables.com/id/OV7670-Without-FIFO-Very-Simple-Framecapture-With-/step3/Upload-sketch-to-Arduino/):
// Source code for application to transmit image from ov7670 to PC via USB
// By Siarhei Charkes in 2015
// http://privateblog.info
//

#include <stdint.h>
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

#define F_CPU 16000000UL
#define vga   0
#define qvga  1
#define qqvga   2
#define yuv422  0
#define rgb565  1
#define bayerRGB  2
#define camAddr_WR  0x42
#define camAddr_RD  0x43

/* Registers */
#define REG_GAIN    0x00  /* Gain lower 8 bits (rest in vref) */
#define REG_BLUE    0x01  /* blue gain */
#define REG_RED       0x02  /* red gain */
#define REG_VREF    0x03  /* Pieces of GAIN, VSTART, VSTOP */
#define REG_COM1    0x04  /* Control 1 */
#define COM1_CCIR656  0x40    /* CCIR656 enable */

#define REG_BAVE    0x05  /* U/B Average level */
#define REG_GbAVE   0x06  /* Y/Gb Average level */
#define REG_AECHH   0x07  /* AEC MS 5 bits */
#define REG_RAVE    0x08  /* V/R Average level */
#define REG_COM2    0x09  /* Control 2 */
#define COM2_SSLEEP         0x10  /* Soft sleep mode */
#define REG_PID           0x0a  /* Product ID MSB */
#define REG_VER           0x0b  /* Product ID LSB */
#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_COM4    0x0d  /* Control 4 */
#define REG_COM5    0x0e  /* All "reserved" */
#define REG_COM6    0x0f  /* Control 6 */
#define REG_AECH    0x10  /* More bits of AEC value */
#define REG_CLKRC   0x11  /* Clocl control */
#define CLK_EXT           0x40  /* Use external clock directly */
#define CLK_SCALE   0x3f  /* Mask for internal clock scale */
#define REG_COM7    0x12  /* Control 7 */ //REG mean address.
#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_COM8    0x13  /* Control 8 */
#define COM8_FASTAEC          0x80  /* Enable fast AGC/AEC */
#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_COM9    0x14  /* Control 9- gain ceiling */
#define REG_COM10   0x15  /* Control 10 */
#define COM10_HSYNC         0x40  /* HSYNC instead of HREF */
#define COM10_PCLK_HB         0x20  /* Suppress PCLK on horiz blank */
#define COM10_HREF_REV          0x08  /* Reverse HREF */
#define COM10_VS_LEAD         0x04  /* VSYNC on clock leading edge */
#define COM10_VS_NEG          0x02  /* VSYNC negative */
#define COM10_HS_NEG          0x01  /* HSYNC negative */
#define REG_HSTART    0x17  /* Horiz start high bits */
#define REG_HSTOP   0x18  /* Horiz stop high bits */
#define REG_VSTART    0x19  /* Vert start high bits */
#define REG_VSTOP   0x1a  /* Vert stop high bits */
#define REG_PSHFT   0x1b  /* Pixel delay after HREF */
#define REG_MIDH    0x1c  /* Manuf. ID high */
#define REG_MIDL    0x1d  /* Manuf. ID low */
#define REG_MVFP    0x1e  /* Mirror / vflip */
#define MVFP_MIRROR         0x20  /* Mirror image */
#define MVFP_FLIP   0x10  /* Vertical flip */

#define REG_AEW           0x24  /* AGC upper limit */
#define REG_AEB           0x25    /* AGC lower limit */
#define REG_VPT           0x26  /* AGC/AEC fast mode op region */
#define REG_HSYST   0x30  /* HSYNC rising edge delay */
#define REG_HSYEN   0x31  /* HSYNC falling edge delay */
#define REG_HREF    0x32  /* HREF pieces */
#define REG_TSLB    0x3a  /* lots of stuff */
#define TSLB_YLAST    0x04  /* UYVY or VYUY - see com13 */
#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_COM12   0x3c  /* Control 12 */
#define COM12_HREF          0x80  /* HREF always */
#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_COM14   0x3e  /* Control 14 */
#define COM14_DCWEN         0x10  /* DCW/PCLK-scale enable */
#define REG_EDGE    0x3f  /* Edge enhancement factor */
#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_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 */
/*
* This matrix defines how the colors are generated, must be
* tweaked to adjust hue and saturation.
*
* Order: v-red, v-green, v-blue, u-red, u-green, u-blue
* They are nine-bit signed quantities, with the sign bit
* stored in0x58.Sign for v-red is bit 0, and up from there.
*/
#define REG_CMATRIX_BASE  0x4f
#define CMATRIX_LEN           6
#define REG_CMATRIX_SIGN  0x58
#define REG_BRIGHT    0x55  /* Brightness */
#define REG_CONTRAS         0x56  /* Contrast control */
#define REG_GFIX    0x69  /* Fix gain control */
#define REG_REG76   0x76  /* OV's name */
#define R76_BLKPCOR         0x80  /* Black pixel correction enable */
#define R76_WHTPCOR         0x40  /* White pixel correction enable */
#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_HAECC1    0x9f  /* Hist AEC/AGC control 1 */
#define REG_HAECC2    0xa0  /* Hist AEC/AGC control 2 */
#define REG_BD50MAX         0xa5  /* 50hz banding step limit */
#define REG_HAECC3    0xa6  /* Hist AEC/AGC control 3 */
#define REG_HAECC4    0xa7  /* Hist AEC/AGC control 4 */
#define REG_HAECC5    0xa8  /* Hist AEC/AGC control 5 */
#define REG_HAECC6    0xa9  /* Hist AEC/AGC control 6 */
#define REG_HAECC7    0xaa  /* Hist AEC/AGC control 7 */
#define REG_BD60MAX         0xab  /* 60hz banding step limit */
#define REG_GAIN    0x00  /* Gain lower 8 bits (rest in vref) */
#define REG_BLUE    0x01  /* blue gain */
#define REG_RED           0x02  /* red gain */
#define REG_VREF    0x03  /* Pieces of GAIN, VSTART, VSTOP */
#define REG_COM1    0x04  /* Control 1 */
#define COM1_CCIR656          0x40  /* CCIR656 enable */
#define REG_BAVE    0x05  /* U/B Average level */
#define REG_GbAVE   0x06  /* Y/Gb Average level */
#define REG_AECHH   0x07  /* AEC MS 5 bits */
#define REG_RAVE    0x08  /* V/R Average level */
#define REG_COM2    0x09  /* Control 2 */
#define COM2_SSLEEP         0x10  /* Soft sleep mode */
#define REG_PID           0x0a  /* Product ID MSB */
#define REG_VER           0x0b  /* Product ID LSB */
#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_COM4    0x0d  /* Control 4 */
#define REG_COM5    0x0e  /* All "reserved" */
#define REG_COM6    0x0f  /* Control 6 */
#define REG_AECH    0x10  /* More bits of AEC value */
#define REG_CLKRC   0x11  /* Clocl control */
#define CLK_EXT           0x40  /* Use external clock directly */
#define CLK_SCALE   0x3f  /* Mask for internal clock scale */
#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_COM8    0x13  /* Control 8 */
#define COM8_FASTAEC          0x80  /* Enable fast AGC/AEC */
#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_COM9    0x14  /* Control 9- gain ceiling */
#define REG_COM10   0x15  /* Control 10 */
#define COM10_HSYNC         0x40  /* HSYNC instead of HREF */
#define COM10_PCLK_HB         0x20  /* Suppress PCLK on horiz blank */
#define COM10_HREF_REV          0x08  /* Reverse HREF */
#define COM10_VS_LEAD           0x04  /* VSYNC on clock leading edge */
#define COM10_VS_NEG          0x02  /* VSYNC negative */
#define COM10_HS_NEG          0x01  /* HSYNC negative */
#define REG_HSTART    0x17  /* Horiz start high bits */
#define REG_HSTOP   0x18  /* Horiz stop high bits */
#define REG_VSTART    0x19  /* Vert start high bits */
#define REG_VSTOP   0x1a  /* Vert stop high bits */
#define REG_PSHFT   0x1b  /* Pixel delay after HREF */
#define REG_MIDH    0x1c  /* Manuf. ID high */
#define REG_MIDL    0x1d  /* Manuf. ID low */
#define REG_MVFP    0x1e  /* Mirror / vflip */
#define MVFP_MIRROR         0x20  /* Mirror image */
#define MVFP_FLIP   0x10  /* Vertical flip */
#define REG_AEW           0x24  /* AGC upper limit */
#define REG_AEB           0x25  /* AGC lower limit */
#define REG_VPT           0x26  /* AGC/AEC fast mode op region */
#define REG_HSYST   0x30  /* HSYNC rising edge delay */
#define REG_HSYEN   0x31  /* HSYNC falling edge delay */
#define REG_HREF    0x32  /* HREF pieces */
#define REG_TSLB    0x3a  /* lots of stuff */
#define TSLB_YLAST    0x04  /* UYVY or VYUY - see com13 */
#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_COM12   0x3c  /* Control 12 */
#define COM12_HREF          0x80  /* HREF always */
#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_COM14   0x3e  /* Control 14 */
#define COM14_DCWEN         0x10  /* DCW/PCLK-scale enable */
#define REG_EDGE    0x3f  /* Edge enhancement factor */
#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_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 CMATRIX_LEN             6
#define REG_BRIGHT    0x55  /* Brightness */
#define REG_REG76   0x76  /* OV's name */
#define R76_BLKPCOR         0x80  /* Black pixel correction enable */
#define R76_WHTPCOR         0x40  /* White pixel correction enable */
#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_HAECC1    0x9f  /* Hist AEC/AGC control 1 */
#define REG_HAECC2    0xa0  /* Hist AEC/AGC control 2 */
#define REG_BD50MAX         0xa5  /* 50hz banding step limit */
#define REG_HAECC3    0xa6  /* Hist AEC/AGC control 3 */
#define REG_HAECC4    0xa7  /* Hist AEC/AGC control 4 */
#define REG_HAECC5    0xa8  /* Hist AEC/AGC control 5 */
#define REG_HAECC6    0xa9  /* Hist AEC/AGC control 6 */
#define REG_HAECC7    0xaa  /* Hist AEC/AGC control 7 */
#define REG_BD60MAX         0xab  /* 60hz banding step limit */
#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_GFI           0x69  /* Fix gain control */
#define GGAIN           0x6a  /* G Channel AWB Gain */
#define DBLV            0x6b
#define AWBCTR3           0x6c  /* AWB Control 3 */
#define AWBCTR2           0x6d  /* AWB Control 2 */
#define AWBCTR1           0x6e  /* AWB Control 1 */
#define AWBCTR0           0x6f  /* AWB Control 0 */

struct regval_list{
  uint8_t reg_num;
  uint16_t value;
};

const struct regval_list qvga_ov7670[] PROGMEM = {
  { REG_COM14, 0x19 },
  { 0x72, 0x11 },
  { 0x73, 0xf1 },

  { REG_HSTART, 0x16 },
  { REG_HSTOP, 0x04 },
  { REG_HREF, 0xa4 },
  { REG_VSTART, 0x02 },
  { REG_VSTOP, 0x7a },
  { REG_VREF, 0x0a },

/*  { REG_HSTART, 0x16 },
  { REG_HSTOP, 0x04 },
  { REG_HREF, 0x24 },
  { REG_VSTART, 0x02 },
  { REG_VSTOP, 0x7a },
  { REG_VREF, 0x0a },*/
  { 0xff, 0xff }, /* END MARKER */
};

const struct regval_list yuv422_ov7670[] PROGMEM = {
  { REG_COM7, 0x0 },  /* Selects YUV mode */
  { REG_RGB444, 0 },  /* No RGB444 please */
  { REG_COM1, 0 },
  { REG_COM15, COM15_R00FF },
  { REG_COM9, 0x6A }, /* 128x gain ceiling; 0x8 is reserved bit */
  { 0x4f, 0x80 },   /* "matrix coefficient 1" */
  { 0x50, 0x80 },   /* "matrix coefficient 2" */
  { 0x51, 0 },    /* vb */
  { 0x52, 0x22 },   /* "matrix coefficient 4" */
  { 0x53, 0x5e },   /* "matrix coefficient 5" */
  { 0x54, 0x80 },   /* "matrix coefficient 6" */
  { REG_COM13, COM13_UVSAT },
  { 0xff, 0xff },   /* END MARKER */
};

const struct regval_list ov7670_default_regs[] PROGMEM = {//from the linux driver
  { REG_COM7, COM7_RESET },
  { REG_TSLB, 0x04 }, /* OV */
  { REG_COM7, 0 },  /* VGA */
  /*
  * Set the hardware window.  These values from OV don't entirely
  * make sense - hstop is less than hstart.  But they work...
  */
  { REG_HSTART, 0x13 }, { REG_HSTOP, 0x01 },
  { REG_HREF, 0xb6 }, { REG_VSTART, 0x02 },
  { REG_VSTOP, 0x7a }, { REG_VREF, 0x0a },

  { REG_COM3, 0 }, { REG_COM14, 0 },
  /* Mystery scaling numbers */
  { 0x70, 0x3a }, { 0x71, 0x35 },
  { 0x72, 0x11 }, { 0x73, 0xf0 },
  { 0xa2,/* 0x02 changed to 1*/1 }, { REG_COM10, 0x0 },
  /* Gamma curve values */
  { 0x7a, 0x20 }, { 0x7b, 0x10 },
  { 0x7c, 0x1e }, { 0x7d, 0x35 },
  { 0x7e, 0x5a }, { 0x7f, 0x69 },
  { 0x80, 0x76 }, { 0x81, 0x80 },
  { 0x82, 0x88 }, { 0x83, 0x8f },
  { 0x84, 0x96 }, { 0x85, 0xa3 },
  { 0x86, 0xaf }, { 0x87, 0xc4 },
  { 0x88, 0xd7 }, { 0x89, 0xe8 },
  /* AGC and AEC parameters.  Note we start by disabling those features,
  then turn them only after tweaking the values. */
  { REG_COM8, COM8_FASTAEC | COM8_AECSTEP },
  { REG_GAIN, 0 }, { REG_AECH, 0 },
  { REG_COM4, 0x40 }, /* magic reserved bit */
  { REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
  { REG_BD50MAX, 0x05 }, { REG_BD60MAX, 0x07 },
  { REG_AEW, 0x95 }, { REG_AEB, 0x33 },
  { REG_VPT, 0xe3 }, { REG_HAECC1, 0x78 },
  { REG_HAECC2, 0x68 }, { 0xa1, 0x03 }, /* magic */
  { REG_HAECC3, 0xd8 }, { REG_HAECC4, 0xd8 },
  { REG_HAECC5, 0xf0 }, { REG_HAECC6, 0x90 },
  { REG_HAECC7, 0x94 },
  { REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_AGC | COM8_AEC },
  { 0x30, 0 }, { 0x31, 0 },//disable some delays
  /* Almost all of these are magic "reserved" values.  */
  { REG_COM5, 0x61 }, { REG_COM6, 0x4b },
  { 0x16, 0x02 }, { REG_MVFP, 0x07 },
  { 0x21, 0x02 }, { 0x22, 0x91 },
  { 0x29, 0x07 }, { 0x33, 0x0b },
  { 0x35, 0x0b }, { 0x37, 0x1d },
  { 0x38, 0x71 }, { 0x39, 0x2a },
  { REG_COM12, 0x78 }, { 0x4d, 0x40 },
  { 0x4e, 0x20 }, { REG_GFIX, 0 },
  /*{0x6b, 0x4a},*/{ 0x74, 0x10 },
  { 0x8d, 0x4f }, { 0x8e, 0 },
  { 0x8f, 0 }, { 0x90, 0 },
  { 0x91, 0 }, { 0x96, 0 },
  { 0x9a, 0 }, { 0xb0, 0x84 },
  { 0xb1, 0x0c }, { 0xb2, 0x0e },
  { 0xb3, 0x82 }, { 0xb8, 0x0a },

  /* More reserved magic, some of which tweaks white balance */
  { 0x43, 0x0a }, { 0x44, 0xf0 },
  { 0x45, 0x34 }, { 0x46, 0x58 },
  { 0x47, 0x28 }, { 0x48, 0x3a },
  { 0x59, 0x88 }, { 0x5a, 0x88 },
  { 0x5b, 0x44 }, { 0x5c, 0x67 },
  { 0x5d, 0x49 }, { 0x5e, 0x0e },
  { 0x6c, 0x0a }, { 0x6d, 0x55 },
  { 0x6e, 0x11 }, { 0x6f, 0x9e }, /* it was 0x9F "9e for advance AWB" */
  { 0x6a, 0x40 }, { REG_BLUE, 0x40 },
  { REG_RED, 0x60 },
  { REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_AGC | COM8_AEC | COM8_AWB },

  /* Matrix coefficients */
  { 0x4f, 0x80 }, { 0x50, 0x80 },
  { 0x51, 0 },    { 0x52, 0x22 },
  { 0x53, 0x5e }, { 0x54, 0x80 },
  { 0x58, 0x9e },

  { REG_COM16, COM16_AWBGAIN }, { REG_EDGE, 0 },
  { 0x75, 0x05 }, { REG_REG76, 0xe1 },
  { 0x4c, 0 },     { 0x77, 0x01 },
  { REG_COM13, /*0xc3*/0x48 }, { 0x4b, 0x09 },
  { 0xc9, 0x60 },   /*{REG_COM16, 0x38},*/
  { 0x56, 0x40 },

  { 0x34, 0x11 }, { REG_COM11, COM11_EXP | COM11_HZAUTO },
  { 0xa4, 0x82/*Was 0x88*/ }, { 0x96, 0 },
  { 0x97, 0x30 }, { 0x98, 0x20 },
  { 0x99, 0x30 }, { 0x9a, 0x84 },
  { 0x9b, 0x29 }, { 0x9c, 0x03 },
  { 0x9d, 0x4c }, { 0x9e, 0x3f },
  { 0x78, 0x04 },

  /* Extra-weird stuff.  Some sort of multiplexor register */
  { 0x79, 0x01 }, { 0xc8, 0xf0 },
  { 0x79, 0x0f }, { 0xc8, 0x00 },
  { 0x79, 0x10 }, { 0xc8, 0x7e },
  { 0x79, 0x0a }, { 0xc8, 0x80 },
  { 0x79, 0x0b }, { 0xc8, 0x01 },
  { 0x79, 0x0c }, { 0xc8, 0x0f },
  { 0x79, 0x0d }, { 0xc8, 0x20 },
  { 0x79, 0x09 }, { 0xc8, 0x80 },
  { 0x79, 0x02 }, { 0xc8, 0xc0 },
  { 0x79, 0x03 }, { 0xc8, 0x40 },
  { 0x79, 0x05 }, { 0xc8, 0x30 },
  { 0x79, 0x26 },
  { 0xff, 0xff }, /* END MARKER */
};

void error_led(void){
  DDRB |= 32;//make sure led is output
  while (1){//wait for reset
    PORTB ^= 32;// toggle led
    _delay_ms(100);
  }
}

void twiStart(void){
  TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);//send start
  while (!(TWCR & (1 << TWINT)));//wait for start to be transmitted
  if ((TWSR & 0xF8) != TW_START)
    error_led();
}

void twiWriteByte(uint8_t DATA, uint8_t type){
  TWDR = DATA;
  TWCR = _BV(TWINT) | _BV(TWEN);
  while (!(TWCR & (1 << TWINT))) {}
  if ((TWSR & 0xF8) != type)
    error_led();
}

void twiAddr(uint8_t addr, uint8_t typeTWI){
  TWDR = addr;//send address
  TWCR = _BV(TWINT) | _BV(TWEN);    /* clear interrupt to start transmission */
  while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
  if ((TWSR & 0xF8) != typeTWI)
    error_led();
}

void wrReg(uint8_t reg, uint8_t dat){
  //send start condition
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  twiWriteByte(dat, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
}

static uint8_t twiRd(uint8_t nack){
  if (nack){
    TWCR = _BV(TWINT) | _BV(TWEN);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_NACK)
      error_led();
    return TWDR;
  }
  else{
    TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWEA);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_ACK)
      error_led();
    return TWDR;
  }
}

uint8_t rdReg(uint8_t reg){
  uint8_t dat;
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  twiStart();
  twiAddr(camAddr_RD, TW_MR_SLA_ACK);
  dat = twiRd(1);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  return dat;
}

void wrSensorRegs8_8(const struct regval_list reglist[]){
  uint8_t reg_addr, reg_val;
  const struct regval_list *next = reglist;
  while ((reg_addr != 0xff) | (reg_val != 0xff)){
    reg_addr = pgm_read_byte(&next->reg_num);
    reg_val = pgm_read_byte(&next->value);
    wrReg(reg_addr, reg_val);
    next++;
  }
}

void setColor(void){
  wrSensorRegs8_8(yuv422_ov7670);
}

void setRes(void){
  wrReg(REG_COM3, 4); // REG_COM3 enable scaling
  wrSensorRegs8_8(qvga_ov7670);
}

void camInit(void){
  wrReg(0x12, 0x80);
  _delay_ms(100);
  wrSensorRegs8_8(ov7670_default_regs);
  wrReg(REG_COM10, 32);//PCLK does not toggle on HBLANK.
}

void arduinoUnoInut(void) {
  cli();//disable interrupts

    /* Setup the 8mhz PWM clock
  * This will be on pin 11*/
  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
  _delay_ms(3000);

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

    //enable serial
  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
}

void StringPgm(const char * str){
  do{
      while (!(UCSR0A & (1 << UDRE0)));//wait for byte to transmit
      UDR0 = pgm_read_byte_near(str);
      while (!(UCSR0A & (1 << UDRE0)));//wait for byte to transmit
  } while (pgm_read_byte_near(++str));
}

static void captureImg(uint16_t wg, uint16_t hg){
  uint16_t y, x;

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

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

    y = hg;
  while (y--){
        x = wg;
      //while (!(PIND & 256));//wait for high
    while (x--){
      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
    }
    //  while ((PIND & 256));//wait for low
  }
    _delay_ms(100);
}

void setup(){
  arduinoUnoInut();
  camInit();
  setRes();
  setColor();
  wrReg(0x11, 11); //Earlier it had the value: wrReg(0x11, 12); New version works better for me :) !!!!
}

void loop(){
  captureImg(320, 240);
}

The sketch has way too many #defines, and isn't exactly straightforward, but at least it loads, although there is one warning:
/Users/charles/Documents/Arduino/cameraTest2/cameraTest2.ino:13:0: warning: "F_CPU" redefined
 #define F_CPU 16000000UL
 ^
<command-line>:0:0: note: this is the location of the previous definition

To validate that this does anything, I tried playing around with ComputerNerd's SimpleFrameGrabber, but I'm on a mac and I ran into problems when trying to ./build:
main.c:26:10: fatal error: 'SDL/SDL.h' file not found
#include <SDL/SDL.h>

I then tried opening up the Arduino IDE Serial Monitor, and am not seeing anything. Should I be seeing anything? I was expecting I would at least see gibberish..
Ideally, I would like to find some simple example code that would setup the camera (the defaults might even be just fine), and allow me to get RGB pixel data for a 320x240 or 640x480 image. If I could just print that to the Serial Output, I could then write a simple python script to save it as a jpg or a png or something.
I just need to get to a sanity state with this thing. Or find another inexpensive camera module that's easier to work with.

The warning you received in the compilation of SimpleFrameGrabber is caused by the lack of SDL library. Refer to the docs or any tutorial, like http://lazyfoo.net/tutorials/SDL/01_hello_SDL/mac/index.php

It is nice that you refer to copy of an original article from http://privateblog.info. Orinal example for Uno was compiled using AtmelStudio. I would recommend use two articles:
Uno version is for AtmelStudio: http://privateblog.info/arduino-uno-i-kamera-ov7670-primer-ispolzovaniya/
Due version is for Arduino IDE: http://privateblog.info/arduino-due-i-kamera-ov7670-primer-ispolzovaniya/
Using them, you can compile program which will work.

//enable serial
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

This bit enables Serial (Rx=0, Tx=1) at 1M baud. Is the Serial Monitor set to the right baud rate?

I tried changing the baud rate on the serial monitor and still don't see anything.

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


text:
Arduino Disconnects after router password changes
I am working with arduino Uno R3 connected with EPS8266(http://www.amazon.in/ESP8266-Serial-Wireless-Transceiver-Module/dp/B00O34AGSU?tag=googinhydr18418-21&tag=googinkenshoo-21&ascsubtag=858e5035-7713-403a-942e-487a0fe24800). After router password is changed, it should be re programmed with new password. Is there any another way not to do so repeatedly. I managed 2 SSID for router which one have always unique password. But I think this is not a solution. Is there any technique or idea that says only for particular mac address, the SSID will be opened.

Routers have multiple "passwords".  I assume you are talking about your wireless encryption key (i.e. WPA/WPA2 key).  When the encryption key is changed, you are correct: you have to re-program the ESP8266 with the new key, because it can't learn this information on its own.  If this key were broadcast, then your network would not be secure as everyone would be informed of the encryption key.
Why is the key changing?  Is there really a need to change the encryption key often?
MAC addresses can be spoofed, so permitting a specific MAC address to "always connect" is not secure.

Thanks for ur valuable reply.. I am making a very secure wifi protocol that has a function to allow network for particular mac address. Because the device in which it is gonna be loaded will not be touch for next 5 years. In between if router changes may occur than this problem may arise.


text:
Checking what ESP8266 module that is in use
I have this script where I have connected an ESP-01 to an SSD1306 OLED screen. However, the script I'm using needs adaption for ESP-01 as this module requires the I2C pins to be defined.
So basically I need to add a line that says Wire.begin(2, 0); so make the screen work with the ESP-01.
Whoever, I would love to have a check that is wrapped in a #ifdef so the code will work out of the box with multiple ESP modules without changing the source code.
Is there some way I can check if the module in use is an ESP-01?

you can check with ifdef which board is selected in Tools menu

@Juraj As programming the ESP01 requires me to use the Generic 8266 Module option, I guess it's not possible then?

try the ARDUINO_BOARD macro, which is different for wemos and nodemcu and esp01, not sure about others...

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


text:
No contact between DS18B20 and WeMos D1 Mini
I have a waterproof DS18B20 sensor that I have connected to a WeMos D1 Mini microcontroller. This controller connects to Wifi and an MQTT broker, sending the temperature from the sensor and goes to deep sleep.
Everything works nicely, except for the sensor reading. It returns -127, which means the sensor is disconnected. I have checked cables, measured voltage and everything should be just fine.
I have data cable for the sensor connected to D2, so in my sketch I have tried the following pins without success: oneWire(D2) - oneWire(2) - oneWire(GPIO4) - oneWire(4). No success.
Can anyone please help me with the following sketch?
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// WiFi settings
const char* ssid     = "[REDACTED]";
const char* password = "[REDACTED]";

// MQTT settings
const char* mqttServer   = "[REDACTED]";
const char* mqttUser     = "[REDACTED]";
const char* mqttPassword = "[REDACTED]";
const int   mqttPort     = 1883;
const char* mqttClient   = "[REDACTED]";
const char* mqttTopic    = "[REDACTED]";

#define durationSleep   15 // deep sleep length in minutes
#define NB_TRYWIFI      20 // number of wifi connection tries
#define ONE_WIRE_BUS     4 // temperature sensor connection

WiFiClient        espClient;
PubSubClient      client(espClient);
OneWire           oneWire(ONE_WIRE_BUS);
DallasTemperature sensor(&oneWire);

float celsius = 0;

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

  // Connect to sensors
  sensor.begin();

  // Setup WiFi
  WiFi.begin(ssid, password);
  int _try = 0;

  // Connect to WiFi
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    _try++;
    if (_try >= NB_TRYWIFI) {
      ESP.deepSleep(durationSleep * 1000000);
    }
  }

  // Setup MQTT
  client.setServer(mqttServer, mqttPort);

  // Get temperature in celsius
  sensor.setResolution(10);
  sensor.requestTemperatures();
  celsius = sensor.getTempCByIndex(0);

  // Connect to MQTT broker
  while (!client.connected()) {
    if (client.connect(mqttClient, mqttUser, mqttPassword)) {
      client.publish("mspa/temperature", String(celsius).c_str(), true);
      delay(1000);
    } else {
      delay(2000);
    }
  }

  // Go to sleep
  ESP.deepSleep((durationSleep * 60) * 1000000);
}

void loop() {
}

Did you add a pull-up resistor to the DS18B20 data pin?

And for the stability (Read the comments) of your solution (Change anyway!) instead of
// IMPORTANT: This leads to crashes due to heap fracturing and imho does not work stable on micro controllers
 client.publish("mspa/temperature", String(celsius).c_str(), true);

 // Do this - define fixed chars before Setup - the compiler puts themto the stack
 char mqttBuffer[16] = '\0';
 char topic[] = "mspa/temperature";
 .....
 dtostrf(celsius,6,2,mqttBuffer); // convert a float to char
 client.publish(topic, mqttBuffer, true); // We use the fixed chars instead of heap fracturing Strings

Read more on evil Strings: https://hackingmajenkoblog.wordpress.com/2016/02/04/the-evils-of-arduino-strings/
Hope this helps

//Call this function after sensor begin in setup.. share output
uint8_t findDevices(int DSPIN)
{
  OneWire ow(pin);

  uint8_t address[8];
  uint8_t count = 0;

  if (ow.search(address))
  {
    Serial.print("\nuint8_t pin");
    Serial.print(pin, DEC);
    Serial.println("[][8] = {");
    do {
      count++;
      Serial.println("  {");
      for (uint8_t i = 0; i < 8; i++)
      {
        Serial.print("0x");
        if (address[i] < 0x10) Serial.print("0");
        Serial.print(address[i], HEX);
        if (i < 7) Serial.print(", ");
      }
      Serial.println("  },");
    } while (ow.search(address));

    Serial.println("};");
    Serial.print("// nr devices found: ");
    Serial.println(count);
  }

  return count;
}

Thanks for your answer! Unfortunately this doesn't return anything: ets Jan  8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

Btw, I also tried multiple DS18B20 sensors, with no luck. Not sure what I am doing wrong. I also tested with other D1s, no luck.

Did you add a pull-up resistor to the DS18B20 data pin?

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


text:
Scroll one line of text while another line is static on a SSD1306 OLED
I have an SSD1306 OLED that I have connected to a Wemos D1 Mini. It works like a charm, but I was wondering if it was possible to have two lines of code, where one line is static, and the other one scrolls? No example on the web as far as I have tried to find.

I just found the answer on the following site: https://lastminuteengineers.com/oled-display-arduino-tutorial/
Basically, the method startscroll* on the display takes some arguments.
By passing the proper start page and stope page you can scroll parts of the screen.
Refer to OLED Memory Map for explanation of the pages on the screen. There are eight pages in the display from 0 to 7, so we can scroll a certain part of the screen by passing specific page numbers as parameters.
In this example, we pass both the parameters as 0x00. This will scoll the first page only (first 8 rows) of the display:
// Scroll part of the screen
display.setCursor(0,0);
display.setTextSize(1);
display.println("Scroll");
display.println("some part");
display.println("of the screen.");
display.display();
display.startscrollright(0x00, 0x00);

Source: https://lastminuteengineers.com/oled-display-arduino-tutorial/

Please either explain more about the solution in your answer or delete your question. These Q&A are supposed to serve as knowledgebase and links tend to get broken rather fast, which would make your answer completely useless for others

@chrisl Updated my post. Thanks for telling me, you are completely right.


text:
Scheduled loops using same function
I am using an Arduino due and have multiple schedules running at the same time. I am using this Library.
I have a function that 3 different loops use. Two of the loops are driven by user interaction so timing is not possible. The function does reset global variables and I would have no issue with the variables being reset multiple times as it wouldn't cause any problems for me.
What I was wondering, on the very slim chance that two loops called the function at the same time, is it possible for the loops to modify the same variable at identical times?
My understanding of the scheduler would lead me to believe that the scheduler will only yield to another loop after it has completed a line of code and thus the to instructions to reset the global variable could not happen at the very same time, just extremely quickly one after the other.
Would this be a correct assumption?

From the [Arduino Reference][1] pages:

This is a cooperative scheduler in that the CPU switches from one task
  to another. The library includes methods for passing control between
  tasks.

[emphasis mine]
Which means that your code decides when it yields control to another scheduled loop (by calling yield(). At a quick glance, it appears that it also yields by returning. So yes, your assumption is correct.

Awesome that will work, I just wanted to ensure they ran 1 by 1 so that no corruption of global data could occur.  Great news, thanks JRobert

It is a simple schedular. It only changes to another task when yield() is called. The delay() function uses yield() and a lot of code and libraries use delay().
That means that if you code does not contain a delay() then you need to call delay() or yield() now and then, or other tasks will never execute.
It is probably safe to use the same function, but every time a delay() is used, an other task could run or another task will continue from there.

Awesome, thanks for that Jot looks like It will work for what I need.

I'm testing that Scheduler library at the moment. It is very simple, but useful. The stack for the new tasks are allocated in the heap. The original Arduino loop() function uses the normal stack. It might therefor be better to do big things like Ethernet in the Arduino loop() and do smaller things in the created tasks.


text:
Sublime Text Compilation Issue
I've tried searching for this issue but came up empty. Due to the desire to use a better IDE, I installed Sublime Text 3 and Stino. I have installed the Stino package and now have the Arduino menu inside the Sublime Text editor. I have selected the Arduino application folder appropriately. However, when I compile the simple Blink example, I'm presented with the following error. This error comes up when I attempt to compile any Arduino project. Have I forgotten to configure a setting? All videos and tutorials I've seen just follow the same steps as I have and don't seem to include any additional configuration (besides selecting the Arduino application folder).
[Stino - Start building "Blink"...]
[  3%] Creating C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp.o...
"C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD  -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=161 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\examples\01.Basics\Blink" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp" -o "C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp.o"
The filename, directory name, or volume label syntax is incorrect.

[Stino - Exit with error code 1.]

You might need an older version of the IDE. Which version are you using?

@Majenko I am using Arduino 1.6.1. I noticed in the Arduino forums that some were having trouble with 1.6.2 and suggested reverting back to 1.6.1. I can try with a pre-1.6 version this evening. I receive the same error at compilation with both Sublime Text 2 and 3.

As a quick update for anyone who runs into a similar issue (granted, a week later)...
I upgraded to 1.6.5 of the Arduino IDE, making sure to set my Arduino application folder appropriately, and the compilation issue has disappeared. I am able to compile and upload projects successfully.


text:
Arduino Due SPI speed reduction
I need to reduce the SPI clock speed of the Arduino Due down to about 100 kHz. Unfortunately my hardware doesn't support higher speeds.
With the current maximum divider of 255, I can only reach a speed of still 320 kHz (SPI.setClockDivider(10, 255);).
Of course I could use a software SPI, but I'm still interested in using the build-in hardware. A possible solution could be to lower the overall clock speed of 84 MHz. Any idea how to achieve this?

You can try using the SPISettings interface:
SPISettings settings(100000, MSBFIRST, SPI_MODE0);

SPI.beginTransaction(settings);
... do your stuff ...
SPI.endTransaction();

Very interesting, it seemed that "setDataMode()" function didn't work correctly, just with SPISettings interface I got the correct mode. Additionally I had to slow down the CS line. The SPI speed was ok in my case. Thanks!


text:
No reply from GSM module
I have an arduino due sending and receiving data from a server using a GSM module (UBLOX SARA-U270). The issue I am having with it is that after a period of time working correctly the module stops replying or replies with random characters. It has been suggested to me that if I receive no reply to a command and continue to send commands it can cause issues like this and I need to take action before I send any more commands but I am unsure of what this action should be.
I was wondering is there a recommended action to be taken if I receive an empty response from an AT command to a GSM module after it has been previously working. I am currently working to find out the cause of the issue but I just wanted to know what should be done if an AT command that replies with nothing.
To try and correct this issue I have a function in place which if the module hasn't received data correctly for 1 minute will clear the modules setting using the AT+CFUN=1,1 command and resend all the setting to the module. My issue is that because the module is not replying, my AT+CFUN=1,1 command does nothing.  Physically removing the power to the module seems to be the only thing that will get it running correctly again.
And suggestions or advice would be greatly appreciated, Thanks guys.

Good question, I'm experiencing similar problems (different GSM module). My initial thoughts were something to do with the baud rate, however, tried various different options and same issue eventually happens. Second thought was then power, I've read on few occassions that if the correct power isn't supplied then it can cause undesirable behaviour.

Hi James, I think the most important thing, with regards to these modules is to pay close attention to the timeouts for each command. Ensure that you don't send any other commands to the module until you either receive a reply to the last command or have waited the full timeout for the sent command. I rewrote my code paying close attention to this and had much more success.


text:
LCD not displaying text
I am working with an Arduino due and currently using the Arduino liquid crystal library to display data on an LCD screen (mc42004A6wk-bnmlw) which uses the Hitachi HD44780 controller. The LCD has been update to v2 and is now using the Sitronix ST7066U controller.
From what I have read the two controllers are compatible and the liquid crystal library should work for both. I am using the same software and hardware setup as before but the screen will not display anything.
The software I use is quite complex so I moved to a simple hello world program (below) to test and I still have the same issues. Any advice would be greatly appreciated.
#include <LiquidCrystal.h>
#include <Arduino.h>

LiquidCrystal lcd(30, 31, 32, 33, 46, 47);

void setup()
{

  pinMode(36,OUTPUT);

  digitalWrite(36, LOW);

  delay(5000);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  lcd.clear();

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{

  delay(5000);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

Did you adjust the contrast?

I did indeed, no luck. I think its a problem with how the liquid crystal library initializes the screen. Just cant nail down the reason.

So after further investigation into the IDE, Libraries, board manager, hardware etc I discovered what was causing the issue.
On the initial hardware design the hardware engineer placed a capacitor on the enable leg between the LCD screen and the microcontroller. I have no idea why as I have not seen this done in any wiring diagrams but removing it has done the trick. The V2 board now works with all the original code and libraries.

Try using this code, I have edited some parts of your code so this should work.
#include <LiquidCrystal.h>

const int rs = 30, en = 31, d4 = 32, d5 = 33, d6 = 46, d7 = 47;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{

  pinMode(36, OUTPUT);
  digitalWrite(36, LOW);
  delay(5000);    //Its okay to use delay here since its in the setup() function and will run only once

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

For this Hello World sketch, avoid using delay(); statement in the void loop() as it is not good to use when you have the millis(); used.
If the above wont work, check your LCD Wiring, many problems usually arouse from wrong wirings.
Also I may suggest you to use some cheap LCD I2C Backpacks as this will ease the coding and will use less wire and pins on your Arduino. Here is a example

If your'e going to use a I2C LCD Backpack, here is a working sample code.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN     13

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }

};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );

  //lcd.begin(16,2);
  lcd.begin(20,4); // initialize the lcd

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("LCD TESTER - BY:");
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print ("ABBAS (PRJCT.ME)");
  delay ( 3000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   //for ( int i = 0; i < 2; i++ )
    for ( int i = 0; i < 4; i++ )
   {
      //for ( int j = 0; j < 16; j++ )
      for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 2 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 3 );

   }
   delay (200);
}

Hi EngrAbbas, thank you so much for the reply and code.Removing the delay has given me some progress. The screen is not printing correctly but is now printing random chars on screen such as "?/?/ooo|||" etc. I'm really starting to think that the liquid crystal library is not compatible with the screen. Using the previous version I have no issues, even when using delays and milli's.

I did notice that the controllers have different timing with regards to initialization. Do you think this could be causing the issue?                                Initializing by Instruction - Wait time after power on
ST7066U = Wait time > 40mS       , Hitachi HD44780 = Wait time > 15mS
. Initializing by Instruction - Wait time after first function set
ST7066U = Wait time > 37uS      , Hitachi HD44780 = Wait time > 4.1mS

I had so many troubles with a 20x4 LCD that required numerous data lines. It would work once then I'd power it down & up again & it wouldn't work -- instead showing nothing. I checked all the wiring and tried it again and then got same result as @user1649972 with the random characters showing up.  I thought I had fried the LCD.  I ordered the I2C version (https://amzn.to/2MAOAjL).  It is so much easier. But, I still wanted to see if my orig. LCD worked.  I connected a line from each data line from the new I2C LCD to the old one and lo & behold, it worked!. If any data line isn't 100% it fails.


text:
Most efficent way to adjust value
I am working on a system that starts a process based of a set time value (startHour). The user sets the start hour and can only select values from 00-23. I have been asked to start the same process at 6 hour intervals so that it occurs 4 times during the day.
My initial though is to add three more variable, secondStartHour, thirdStartHour and fourthStartHour. secondStartHour would be assigned a value 6 hours ahead of the startHour, thirdstartHour a value 12 hours ahead of startHour and fourthStartHour would be assigned a value 18 hours ahead of start hour. I could then use any of the startHour variables to trigger the process.
I wrote some code (below) that will work but I'm wondering if there is a better, more efficient way of doing it.
//set up secondStartHour 6 hours ahead of startHour
if (startHour <= 5)
{
    secondStartHour = startHour - 18;
}
else
{
    secondStartHour = startHour + 6;
}

//set up thirdStartHour 12 hours ahead of startHour
if (startHour <= 11)
{
    thirdStartHour = startHour - 12;
}
else
{
    thirdStartHour = startHour + 12;
}

//set up fourthStartHour 18 hours ahead of startHour
if (startHour <= 17)
{
    fourthStartHour = startHour - 6;
}
else
{
    fourthStartHour = startHour + 18;
}

I had to write the code in the way I did above because I am working with a 24 hour clock so in some cases adding time to a startHour will actually reduce the value. By this I mean if startHour is 23 (23:00) and I need to add 6 hours to it to get secondStartHour the result will be 5 (05:00) so I can't simply write code to say secondStartHour = startHour + 6. The code just seems too long winded and messy but I cant think of a better way to write it. I could use a switch case statement but then I would have 24 cases with assignments for each of the new variables in each case so that seems worse, any ideas would be appreciated.

If you think about it - if it happens 4 times during the day at regular intervals, you actually can only have 6 start times...

Hi Majenko, thank you for the reply but this is not the case as the user selects the time period at which they want the first process to occur

But that's the opposite of what you say in your question: "I have been asked to start the same process at 6 hour intervals so that it occurs 4 times during the day."

Yes it is every 6 hours but it is based on the fact that  "The user sets the start hour and can only select values from 00-23" So it is every 6 hours but changes based on the selected time

Yes, but what is the difference between them entering 4 and entering 10?

Instead of comparing, you can use the modulo operator:
 secondStartHour = (startHour +  6) % 24;

And similar for the others:
 thirdStartHour  = (startHour + 12) % 24;
 fourthStartHour = (startHour + 18) % 24;

While xxxStartHour >= 24, 24 will be removed until it is within range [0, 24).
If you need an offset, you also can add some hours of course after the module (I don't fully understand your example which can have values >= 24.
Also, if you need to do the same task every 6 hours, you can use with one time and 'restart' it every 6 hours (and maybe taking summer/winter time into account).

thank you so much Michel, the mod operator is exactly what I am after, it will make the code much shorted and cleaner. Thanks again

You are welcome. You can use it in many cases which involves something periodical.

If you think about it logically you actually only have 6 start hours. Things can only start at a time between 0 and 5 am inclusive.  Everything else is a multiple of 6 hours on from that start.  Any time provided that's past 5am is actually a future time of an earlier start time.
So you can just "modulus" the given time so it is one of the first 6 hours of the day:
startHour = startHour % 6;

And then add 6 each time for the other hours:
secondStartHour = startHour + 6;
thirdStartHour = startHour + 12;
fourthStartHour = startHour + 18;

So your hour arrangements can only be:
0  6  12  18
1  7  13  19
2  8  14  20
3  9  15  21
4 10  16  22
5 11  17  23

If you provide the hour 15 as a start time, 15 % 6 is 3 (divide 15 by 6, you get 2 with 3 remaining), so you are in the time pattern "3 9 15 21".


text:
Arduino uno, 2x parallax continous servos (BOE), wifi shield power draw
I am unable to properly connect those things together with batteries:
Arduino Uno
Parallax continuous servo
Arduino wifi shield

5xAA batteries are connected through power jack to arduino which I assumed would power both arduino and the wifi shield and then I have 1 9 volt battery to power 2 servo motors.
With this setup it seems like I can only get to run 1 servo at a time.
Here is a picture how it looks like: https://i.sstatic.net/7mGKe.jpg
I'm really desperate for any advice/guidance when it comes to powering this thing.

9v is too high for servos and risks destroying them. 5x AA is not enough for an Arduino's input except when they are new.

9V batteries can only supply  very little current. So two servo's is too much.
Just use another set of multiple AA batteries for the servo's.


text:
Use terminal command to verify software
I've seen that it is possible to use terminal command to verify software instead of using the IDE. Something like arduino --verify lab.ino.
Is there a way to do so on Mac OS?
Thank you

I managed to verify code from terminal by invoking /Applications/Arduino.app/Contents/MacOS/Arduino --verify lab.ino BUT this command automatically starts the IDE and exits it afterwards. Even with an IDE instance open it will start a new one. This is annoying since it will switch the active workspace away, but it kinda works. See arduino manpage.

Currently, you have the option to compile it using Arduino CLI.
You just need to know the Fully Qualified Board Name that you are using and inside your project directory you run:
arduino-cli compile --fqbn arduino:avr:uno main.ino

Replace main.ino for your entry file, if applicable.
In order to know your fqbn, you can list them:
arduino-cli board listall

Use AVRDude, and set the op field to v for verify. E.g.:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbserial-A703114N -b57600 -D -Uflash:v:/var/folders/tp/grrlc56j3z7057f12_7f1_0r0000gn/T/build7a7055aab8d0564b6a7844b201562ffe.tmp/CV-turner.ino.hex:i

change /dev/cu.usbserial-A703114N to your serial port.
change /var/folders/tp/grrlc56j3z7057f12_7f1_0r0000gn/T/build7a7055aab8d0564b6a7844b201562ffe.tmp/CV-turner.ino.hex to your hex file.
More info on avrdude at http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions
Sample output would be:
avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Volumes/Lion-Data/home/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbserial-A703114N
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: verifying flash memory against /var/folders/tp/grrlc56j3z7057f12_7f1_0r0000gn/T/build7a7055aab8d0564b6a7844b201562ffe.tmp/CV-turner.ino.hex:
avrdude: load data flash data from input file /var/folders/tp/grrlc56j3z7057f12_7f1_0r0000gn/T/build7a7055aab8d0564b6a7844b201562ffe.tmp/CV-turner.ino.hex:
avrdude: input file /var/folders/tp/grrlc56j3z7057f12_7f1_0r0000gn/T/build7a7055aab8d0564b6a7844b201562ffe.tmp/CV-turner.ino.hex contains 7902 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.34s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x64 != 0x6a
avrdude: verification error; content mismatch

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (H:00, E:00, L:00)

avrdude done.  Thank you.

Notice the verification error, first mismatch at byte 0x0002
PS. you need an actual hex file, not an ino file. Different compilers and different versions of the Arduino IDE can produce slightly different hex files, for the exact same C-program.

I'm not sure that's what he's after - I think he wants to "verify" (i.e., compile) his sketch from the command line.

@Gerben I am sorry but I dont have an arduino, I realy just want to verify my code. I am coding for a project and just want to commit verified code.


text:
Connector for I2C sensor
Im about to develop some home automation. It should be possible to connect new sensors to the main computer. Thats a Arduino.
What can be used as a connector for the I2C sensors? It should be customer friendly. So something like RJ11 or USB. What can be used for that?
Is it possible to send data wirelessly from a I2C sensor?
Regards

What can be used as a connector for the I2C sensors? It should be customer friendly. So something like RJ11 or USB. What can be used for that?

Almost anything you like. Whatever is easy to get hold of and use. You only need 4 wires, and they are all low voltage, so nothing too fancy is needed.

Is it possible to send data wirelessly from a I2C sensor?

No. But you can connect the I2C sensor to an Arduino then use that with a wireless interface of some form to send the data wirelessly.
One thing for you to know though:
I2C is not suitable for long distance communications. A few inches to a foot or so is about the limit. Anything longer and you will start running into communication problems. For longer distance communications you need to use a more reliable protocol.

Thanks a lot Majenko.
So i could use USB or RJ11? And would that work only work with a very short cable? So no 4m cable?
If i go for wireless, would i then be able to use like a Arduino Nano?

You could use those connectors if you choose, yes. But no 4m is not really on for I2C. Yes, you could use an Arduino Nano.

If i should find sensors that could be used with 4m of cable, what kind of sensors type is that?

Probably expensive and specialised. Most sensors are designed to be interfaced with something close by - often within the same circuit board or one closely connected. Normally you would take a sensor, add a small microcontroller, and some kind of transceiver (radio, RS-485, whatever) to transfer the data over a long distance. It's not the role of the sensor to do that sort of thing.

So i guess the easiest way is to make it wirelessly :-)
Thanks a lot for the help


text:
Best 2a stepper motor driver for Arduino Uno
What is the simplest (from a user/install standpoint) 2a stepper motor driver for an Arduino Uno?
I would like something simple and easy to stack like the Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit  but unfortunately it only handles 1.2a. I can do basic soldering but I would like to keep things simple and physically stacked or connected if possible. I don't want to use jumpers or a breadboard.
I am trying to run this stepper to simply open and close a door every few hours:
14:1 Planetary Gearbox High Torque Nema 17 Stepper
Using this battery from Amazon:
ExpertPower EXP1250 12V 5Ah
If I'm missing anything please let me know. Your feedback is appreciated.

While you can do it, this doesn't sound like an application for a stepper motor, but rather some sort of ordinary motor with a mechanical reduction and a limit switch.  If you want to go with this anyway, MOSFET bridges like the TB6612FNG on that Adafruit shield can theoretically be paralleled, but it may also be that setting a reduced current level below the motors rating would be fine for your needs.


text:
Flash Arduino Due via UART
I would like to write code in Arduino language, compile it in the Arduino IDE, grab the resulting binary code, and flash it to the Due via the TX/RX UART pins, bypassing both the USB Programming Port and Atmel16U2 chip. Before the UART flash, I am manually toggling the Erase and Reset pins on the Due to initiate a hard reset of the SAM3X chip, and SAM-BA now waits for the code. I would like to know: can I directly grab the binary code compiled by the Arduino IDE and give it to SAM3X via UART or is there extra code baked into that binary by the Arduino compiler that would cause this method to fail?

The compiled code never cares how you upload it.

My thoughts were that there could be additional code intended for the Atmel16U2 and Programming Port flash method which would have to be removed in this situation.

Nope, just use avrdude to upload it and you are done ;)

But you can also upload it from the IDE with a serial interface of your own; you are not forced to use the 16u2

It depends
This may not have been the answer the question was originally asked, but now it appears to be: it depends on which revision of the Due you have.
The V03 schematics on the website show a 74LVC1G125DCK part designated IC10 that is being used to translate the 5V TXD signal from the ATMega16u2 (being used as a serial transceiver) to the 3.3V logic needed for the ATSAM3X8.  As drawn the TXD line is connected to the buffer/level converter input but it is also connected to its active-low output-enable line.  In effect, they're not just using it to convert logic levels, they are also converting the signal to a kind of open collector signal.  Looking at the ATSAM3X8 datasheet shows that, yes, there is an internal pullup in the pin receiving the signal.
If your Due is of this design, then yes, you can program the chip by attaching a USB->logic-level-serial adapter to D0 and D1 (USART) pins and program using the SAM-BA protocol. You need to make sure you are not sending over the on-board serial transceiver while this is happening so as to not have it wired-ORing its data with your adapter. The ATMega16U2 has code in it that controls the ATSAM3X8's erase pin, as well as reset pin, by request of the PC via serial-over-USB's DTR and RTS.  Since the erase signal is not routed to outside of the Due (on its headers), you would need to use the erase button, barring some modification to the board.
However, not all Due are of this design. Some DUE boards have the output-enable of 74LVC1G125DCK hard-wired active rather than connected to the transceiver TXD; so on these designs it does not behave as open-collector, and the ATMega16u2 serial transceiver is actively driving the line when idle.  This destroys the ability to program the board over UART via pins D0 and D1.  It does however make cleaner rising edges.  Without modifying the board, no, you can't do it with this design.
Identification
So far as I can tell, whether or not your ATMega16U2->ATSAM3X8 connection is open collector/UART-programming-friendly follows the location of the buffer part.  The chip is an SC70 package, a small 5-pin thing that looks a bit like SOT23-5.  If it is located off the ATMega16U2 itself it seems you have a open-collector configuration, again so far as I've been able to tell.  If it is located next to D0, between D0 and the "COMMUNICATION" header, then you have one that drives-high.
If you have a scope, you can put it on D0 and watch the edges generated when you send traffic from the PC over the ATMega16U2 at higher baud rates.  You will either see characteristic open-collector rising edges or you won't and that will answer the question.


text:
How to interface with generic IR RGB LED controller?
I want to hook up an arduino to one of those generic RGB LED controllers, you see them everywhere, they are these little white boxes with power input and RGB strip plug and an IR LED lead. Is there a way to take to the IR + and - and connect them the arduino? Then spoof an IR signal to control the control module? I want to do it this way because I already own both the arduino and control module and that module handles the power for the LEDs. All I am hoping I have to do is send the controller the hex value for the IR command through the the arduino in order to control it. Here's a link to what the module looks like and the remote it comes
https://www.amazon.com/dp/B00ASHQQKI/ref=cm_sw_r_cp_awd_htMywb1W85962

The IRRemote Library is a good starting point, but you'll probably need a RAW mode.   I've got a couple IR controllers from different companies, and they use different codes for the same things.

Mine were basic NEC protocol.


text:
Reading Analog values of bluetooth module HC 05
I am working on a project which requires signal strength of a bluetooth TX and RX. what i assume is that in bluetooth module like hc05, there is an antenna receiver which reads the analog signal and then passes it to its ADC to get data in terms of 0's and 1's. But is there any way i can read the analog signal strength of the reveiver antenna directly? Please help

Start by getting the data sheet for the HC05 and reading up on how it works. If anybody has written drivers for the HC05 you may also find useful information there.

Try looking up the datasheet to see if there is a command for signal strength. It's impossible to directly read the the analog value since the signal strength is way too low in amplitude.


text:
Get LFN from SFN with SDFat
I am trying to optimize the memory usage of my ESP8266 arduino sketch by using 8.3 SFN folder names internally, but LFN when needed for user output. Unfortunately when opening a folder by using the SFN, getName also returns the SFN:
sdfat::SdFile _currentFolder;
_currentFolder.open("BLUBBE~1");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "BLUBBE~1" while
sdfat::SdFile _currentFolder;
_currentFolder.open("blubberblub");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "blubberblub" (and getSFN would return "BLUBBE~1"). Is there any chance to open the folder using the SFN "BLUBBE~1", but get the LFN ("blubberblub") later on?


text:
Issue with PIR sensor
I have been using a HC-SR501 PIR module with my Arduino Mega and it was tracking presence pretty well.
Because of cost constraints, I decided to go with the low cost HC-SR505 sensor - bought a bunch of them. The performance is very bad. It almost seems like it is giving random HIGH and LOW values. Out of the 20 odd sensors I bought, may be one or two are fairly ok - others are all behaving weird. Have someone experienced this kind of behavior with HC-SR505 sensor?
Are they highly sensitive to noise in the power supply - is there any workaround to mitigate the effect? Would an RC filter across the input help?


text:
How to run functions concurrently
I'm building a scale which reads a value (from a load cell) and outputs it on a LED screen.
There is a function for the scale, read which will read the value from the scale.
However this is not instantaneous - it uses the yield function to wait until the scale is ready.
The LED screen has a function, display which will display an integer on the screen with no delay. However, this lasts barely a fraction of a second, so it must be repeatedly called.
These functions as is are called one after another inside loop(), but it causes only a quick flash of the LED screen followed by a half second of reading.
How would I allow the LED screen to keep displaying a value while the scale reads? I know there's BlinkWithoutDelay - but I'm not using specific times. There is no instance of the function delay anywhere in the program. I also am not going to edit the library which reads the load cell.

What LED screen are you using, and how have you connected it?

Which libraries are you using and how does your code look like?

You should post a more complete code, since to make a sort of "multithread" you need to make non-blocking functions. But I think that the problem is not multithreading, but the fact that in the display function you mistakenly reset the display...

@frarugi OP stated that the display is LED (matrix?) and not LCD, and seems it is dynamically driven (have no reset) - so frequently updating it is important.

@Flanker yeah, the only way to have that behavior is through a LED matrix; since I never used them I did not think about that. Maybe it is a couple of 7-segment displays...

Please post your code and schematics.

There is similar questions answered a day ago - Multithreading with Arduino. What your are asking is multitasking or multithreading. Tasks have own loop and task scheduler stops and switches tasks periodically so they appear as if running simultaneously. Task scheduler in turn is usually driver by timer ISR, for AVR a 50-100Hz scheduler timer tick frequency is reasonable.
If there are 2 tasks with same priority (given task scheduler supports priority), they will spare MCU time ~ 50% / 50%. So if timer is 100Hz, each task runs 5ms and interrupted.
Surely task scheduler have overhead, but for small frequency it is negligible, less than 1%. There is no need to modify existing code/library, time sharing is organized transparently.
There are rules to follow when doing multitasking: for example when the scale related function is writing measured value of double type into some variable, this task might be interrupted (by scheduler) during the writing (when only half of the values is written) - and another task will see an incorrect value. The easiest way would be disabling the interrupts during such shared variable update. Google for "race condition", atomic operation, synchronization.

IMHO this is not the best solution, since it can break timings... The best solution is to look at the code and rewrite it in order to get a non-blocking function, so you can switch actions at predefined times without the so-called preemption

@frarugi87 maybe for this particular case updating the the display from timer ISR would be a better solution. To make a cooperative multitasking, OP has to rewrite the scale library code, which OP doesn't want to

I used a timer interrupt, which works fine.
However, when I implemented the solution and uploaded it to the arduino, I became unable to upload sketches to the arduino anymore.

Since it is unrelated issue, you shall create a new question (describe the problem, steps you made etc)

There is only one execution unit in this MCU so you can not truly run multiple tasks concurrently.
However, you can achieve the appearance of concurrency by running a higher priority task through an interrupt. For example, you cannot afford to have flickering disspplay. So set up a timer that invokees the display routine periodically. If you set the timer interrupt sufficiently small (over 25hz for example), the display will not flicker.
Your other routines can be run in other isr or in the main loop so they are interrupted by the display routine periodically. In a way that's fully transparent to you.

This solution is only applicable when the display set function is relatively fast, otherwise you can get problems in other parts of the program

Here is sketch in pseudo-code that can keep your display going and still make frequent weight measurements, without having to do any multi-threading or similar. The value of 'if a measurement is ready' (below) may come from a status bit in the scale, or simply a time difference using the millis() function; I don't know the specifics of your hardware.
I showed weight being an integer. Again, you may need to adapt this to your own hardware. But it is an uncomplicated process for displaying frequently to maintain the display, and reading whenever data is available so the display updates as you get new data, no concurrency required.
void setup()
{
   // initialize everything;
   // start the first measurement;
}

void loop()
{
   static int16_t weight = 0;

   // if a measurement is ready,
      // read the value and store it in 'weight;'
      // start a new measurement
   // endif

   // display 'weight' on the LCD;
}

Put the value variable outside the loop (as a global variable).
Then, call the display function BEFORE the read function.

This is not the best, but if should work fine.

And why should this help with the issue he has? void loop() { read(); display(); } and void loop() { display(); read(); } behave (almost) identically, at least in normal usage


text:
sending room temp data from multiple esp8266's to Mega 2560 to control CH gas boiler
My existing Arduino Mega set up has been in use for about 4 years controlling my gas CH system & heat pump HW system using an Arduino mega & 13 'wired' DS18B20 sensors; 2 of these sensors monitor the main room (lounge) temperature & 1 sensor monitors the outside temp. These 3 sensors control the CH by gas boiler using an algorithm that constantly adjusts the room temp setting as the outside temp changes. The others monitor HW tank temps, heat pump inlet & outlet temps.
I want to change this 'single zone' CH control to a 'multi zone' control using many more temp sensors (DS18B20 or ESP8266?) but laying in hidden wiring would be a real pain.
I've been looking at using ESP8266-07 as a wireless temp sensor for each 'zone', sending its data to the Mega for processing by the above refered to algorithm, so that the Mega can control the CH system better but I can't find any reference to receiving this wireless data at the Mega for processing within the IDE sketch.
I've tried testing the nRF24L01 & nRF24L01+ but my house has many 'black' reception areas & transmission is unreliable.
My 2.4GHz wireless LAN has 3 extenders around the house so this would be my prefered wireless solution.
Could a wireless 'master' be used at the Mega to process data coming in from the 'slave' sensors or am I misunderstanding this?
My programming skill is limited to 'basic IDE' & I find 'wireless' a bit of a black art (I'm a retired mechanical engineer!)

I am also in the middle of converting the control of my heating, multi-zone, but using Ciseco / Wirelessthings units as temperature sensors both inside and out. See https://www.wirelessthings.net
Simple serial interface is all you need from the Arduino to run these on a network. The coin cell battery lasts for over 1 year running 1 sample / 10min - the sample rate is configured but obviously the more samples you send the more the battery drains. Range seems to be OK and gets through 3 floors in the house and from the outside. I do use external antenna on the Arduino wireless unit to ensure I get all of the sensor readings.
However sounds like your house is BIG if running 3x WIFI extensions where as a single WIFI base station does me fine.

I've had a look at wirelessthings.net web site.  I want to monitor (zone) each room in the house that is fitted with wireless EQ3 thermostatic radiator valves (8 so far) so using the wirelessthings temperature sensors would amount to around £100!  Also, I need to sample the sensors every 30s or so as it controls the gas boiler hence my intent to not use battery powered devices but mains powered.  I'm still looking for a way to use the ESP8266 with the Arduino Mega.  My house is not that big but being 'split level' has produced a number of poor reception areas hence he use of wireless extenders


text:
What is more power efficient: GPRS or SMS for a GSM sim Arduino application?
I have a GSM shield for my arduino and am wondering the most efficient way to receive and send data to the cloud.
The specific project I am looking to accomplish is starting my car from a web browser (or custom built ionic mobile app) that will send data to my GSM shielded arduino and the arduino then "press the button" of an already installed remote car starter (which is all probably in the car's trunk).
What is more power efficient, sending and receiving a SMS (text message) or sending and receiving data via GPRS?
What is best when considering strategies like sleep, or deep sleep cycles?

I'd use Bluetooth instead.

@Gerben: Thanks Gerben, but the range of Bluetooth is too small for the project's needs. The GSM shield will enable me to start my car from any where in the world, where as bluetooth would limit me to to a range of 10 to 100 meters depending on the Class (1,2, or 3).

My gut response is SMS, just because it's a simpler protocol.  Not a scientific answer...

Looking at it logically SMS is probably the most power efficient method.
The thinking is this:
With SMS:

The shield sits there connected to the mobile network doing nothing much
An SMS is sent by you which travels through the mobile network
The SMS is sent from the mobile network to your GSM shield which then wakes up and does things with it
The shield sits there connected to the mobile network doing nothing much

With GPRS:

The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service and sees a request is available
The shield downloads the request
The shield acts on the request
The shield goes back to querying the on-line service
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
The shield queries an on-line service to see if a request is available
... etc ad nausium ...

As you can see with SMS the onus is on the mobile network to send the data to the shield, whereas with GPRS the onus is on the shield to keep querying an on-line service to see if there is any requests to handle. There is no way of you sending data to the shield directly (indeed, most GPRS services include at least one layer of NAT gatewaying). So your shield has to be active all the time and constantly looking at something online - not only power hungry, but potentially financially expensive too.

There is no way of you sending data to the shield directly. I'm not sure if this is entirely correct. Though you have to occasionally connect to the server to let it know what your IP is, and to keep the port open. And that is where things get messy, as none of the phone networks provide any data on these things.

If you are behind NAT, and chances you are (I am right now, on 4G) there is absolutely no way to get in from the outside.

@Majenko: Thanks for you response Majenko. Are you saying that protocols like MQTT (over TCP which simply keep an open connection without polling) won't work with GPRS? Are you suggesting that, through a GPRS connection, you can't "Push" messages to the arduino, but can only "Pull" messages? I would be curious as how iOS and Android do "Push" notifications, as is definitely seems like a real "Push", not a "Pull".

For those kind of connections you need a proper network connection. Whether or not you can do it with a GPRS shield is questionable and will depend on what the shield is capable. In general I don't think it is something that they do provide. Regardless, maintaining open connection whether you are using it or not will still be expensive on power.

@Majenko: Thanks for further explaining. How are SMS's sent to a phone/GSM shield. Do they keep an open network connection with the Cell Tower? Is that why, in general, GSM shields train so much power?

Yes but generally they are mainly listening. SMS is much lower bandwidth than the likes of 3G and uses less power to maintain a connection. It is also more reliable with poor signal levels.

@Majenko: I really appreciate your dialog. Thanks for your insight!

You could theoretically use a SIP Server in the middle to keep the session alive over GPRS or higher. And there are techniques you can use to make it as power efficient as can be, depending on your application (which is a rather simple one I assume with little data throughput).
However, as @Majenko stated above, it may not be as power efficient as SMS.
That said, there may be other considerations, such as cost of sending/receiving SMS messages that may matter as you weigh the totality of requirements for your application.
I haven't worked personally on a Particle board (particle.io) but they do have a MCU/3G board that provides a certain amount of free (as in no $) bandwidth per month that might be a reasonable solution to consider for your application.
Please keep us posted. I'm considering something similar myself.


text:
RFID stops working when I place the servo
I've successfully implemented Door Unlock system described in this tutorial.
At first I used Arduino Uno and RFID RC522 Reader and MG90S Micro servo.
When I used Arduino Uno with Arduino Pro Micro for arduino ATmega32U4 5V/16MHz, the RFID reader stops working after plugging the servo.
Since Arduino Pro Micro have only 5V output, I used resistors to downgrade 5V to 3V in order to poser the RFID reader. I used same output 'vcc' to select 5V for the servo and 3V converted to the reader.
The problem is that each component works perfectly independent of each other, however, when I place them together they stop working.

Which voltage did you "downgrade"?

5v to 3v, so I can power the rfid reader

With resistors?!?!

I'm newbie in electronics.
What is the correct way to do it ?

With a voltage regulator. Resistors cannot do what you want.

so, when we use resistors ?

You use resistors when using resistors is a viable option and when the circuit demands resistors. They are not, can not be, never will be, nor ever have been, a way of changing a power supply voltage.

I found that this is possible:https://www.youtube.com/watch?v=zrq4n5tOoTI

The magic words there are written on the paper: "Logic to convert". It's only for changing logic levels not for converting power. If you try drawing more than a couple of microamps the voltage will rapidly drop to nothing.

https://hackingmajenkoblog.wordpress.com/2016/08/30/why-you-cant-use-resistors-as-a-voltage-regulator/

The code you are using is not complete. You should check the second code given at Interfacing of RFID RC522 with Arduino UNO. In this second code they have a function:

void dump_byte_array(byte *buffer, byte bufferSize)

In this funtin place your servo Motor Routines. Like when First card is detected then move serbo in one direction and when second card is detected then move your servo in opposite direction. I have tried it and it works perfectly fine.

Use a 3.3VDC regulator for your RFID board a small boxed DC-DC buck converter will be easiest, if linear use an LDO type. Ideally also use a level shifter on your data lines. This could be a resistor voltage divider or zener diode clamp at the most basic, FETs or a dedicated IC is a bit more involved but gets better results.

The current may be not enough. Try using extra power supply for Servo Motor


text:
MIDI controlled analog RGB LED strip (code problem)
I have a an Arduino Uno doing PWM on an RGB analog LED strip ala the Adafruit guide: https://learn.adafruit.com/rgb-led-strips?view=all. I've written a sketch that accepts MIDI data over USB and uses it to control the LEDs.
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3

byte commandByte;
byte noteByte;
byte velocityByte;

byte noteOn = 144;
byte noteOff = 128;

int colorGroup;
int pColor;
int sColor;

void setup()
{
    pinMode(REDPIN, OUTPUT);
    pinMode(GREENPIN, OUTPUT);
    pinMode(BLUEPIN, OUTPUT);
    MIDI.begin(1);
    Serial.begin(115200);
}

void checkMIDI(){
  do{
    if (Serial.available()){
      commandByte = Serial.read();//read first byte
      noteByte = Serial.read();//read next byte
      velocityByte = Serial.read();//read final byte
      }
    }
  while (Serial.available() > 2);//when at least three bytes available
}

void updateLights(){
  colorGroup = noteByte/42;
  pColor = noteByte%41*127/41;
  sColor = 127 - pColor;
  pColor = pColor*velocityByte/127;
  sColor = sColor*velocityByte/127;
  if (commandByte == noteOn && velocityByte > 0){
    if (colorGroup == 1){
      analogWrite(REDPIN, pColor);
      analogWrite(GREENPIN, sColor);
      analogWrite(BLUEPIN, 0);
    }
    else if(colorGroup == 1){
      analogWrite(GREENPIN, pColor);
      analogWrite(BLUEPIN, sColor);
      analogWrite(REDPIN, 0);
    }
    else{
      analogWrite(BLUEPIN, pColor);
      analogWrite(REDPIN, sColor);
      analogWrite(GREENPIN, 0);
    }
  }
  else if(commandByte == noteOff || velocityByte == 0){
    analogWrite(REDPIN, 0);
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN, 0);
  }
}

void loop()
{
    checkMIDI();
    updateLights();
}

Currently this code will turn the lights on and off in accordance with noteOn and noteOff messages. However, the color doesn't seem responsive to the note value and the brightness doesn't seem responsive to the velocity value. I suspect that the problem has to do with my arithmetic combined with the data type (maybe a problem with the order of operations), but I haven't been successful in debugging this.
The idea behind the RGB control is that I take the possible note values (0–127) and map it onto three different combinations of colors: R+G, G+B, and B+R. That's three groups of 42 values: 0-41, 42-84, and 85-127. Then I rescale the 42 values onto 0-127 for the intensity values of the LEDs. Finally I scale the intensity of all the colors by the velocity value over its possible max value.

I suggest that you write separate test programs for MIDI input and LED control, before trying to combine them together.  That is, write a sketch to report back on Serial what MIDI data was read, and a sketch to cycle the LEDs through obvious patterns.
For example, if you read 10,20,30 as the three MIDI bytes, output "Got 10,20,30" (or similar).  If that appears to be working, then add your arithmetic and output the results of colorGroup, pColor, and sColor calculations.
Note, the comment after do{ ...} while (Serial.available() > 2); says //when at least three bytes available, which does not correctly represent what that do loop does.  When one or more bytes are available, that loop immediately reads three bytes (getting a value of -1 for any not-available byte).  To do the read only if three bytes are available, get rid of the do{ ...} while construct, and instead say if (Serial.available() > 2) { <read 3 bytes> }.
Note, use parentheses in expressions like pColor*velocityByte/127.  IIRC the C spec allows evaluation of that as either (pColor*velocityByte)/127 or as pColor*(velocityByte/127).  Since velocityByte/127 can only evaluate to 0 or 1, the result of the latter form is either pColor or 0.
Note, your code shows if (colorGroup == 1){ twice.  Change 1 to some other number in the second instance.
To cycle the LEDs through obvious patterns, you could have three different sketches, one that gradually raises and lowers the PWM level on Red, one that does the same for Green, and another for Blue.

Thanks. I haven't tried these suggestions yet, but I'm fairly certain a combination of the errors you pointed out is the source of problems, and also I was unaware that you could print with the Arduino back to the computer over USB. That will be very helpful for debugging (which I'll do w/ the functions separate/piecemeal as you suggested).

Okay – slight problem. Because I am sending MIDI over the USB, I think the serial monitor is not working properly, or is interfering with the incoming MIDI data. I was able to use the serial monitor to check that the arithmetic is working properly, but when I use it to simply print the incoming MIDI data bytes, it will print different sorts of nonsense (e.g. it will print "144" [noteOn] as "14" and then it will pause and print another "4").
I'm unsure how to use the serial monitor concurrently with a MIDI to serial converter.

I figured out a solution. Hairless has a debug window that interprets MIDI data outgoing and incoming. If I use Serial.write (rather than print) then Hairless will show both the outgoing MIDI and the MIDI that's echoed back from the Arduino!


text:
Qduino Mini bricked?
So I have been experimenting with keyboard inputs and I think I may have accidentally put a loop in my code that never actually ends the keyboard input thus not allowing me to upload any sketches to fix the problem.
Here is the error code I got when I tried to upload a blank into the qduino:
Arduino: 1.8.1 (Windows Store 1.8.1.0) (Windows 10), Board: "Qduino Mini"

Build options changed, rebuilding all
Sketch uses 4136 bytes (14%) of program storage space. Maximum is 28672 bytes.
Global variables use 148 bytes (5%) of dynamic memory, leaving 2412 bytes for local variables. Maximum is 2560 bytes.
An error occurred while uploading the sketch
processing.app.SerialException: Error opening serial port 'COM11'.
    at processing.app.Serial.<init>(Serial.java:125)
    at processing.app.Serial.<init>(Serial.java:66)
    at processing.app.SerialMonitor$3.<init>(SerialMonitor.java:93)
    at processing.app.SerialMonitor.open(SerialMonitor.java:93)
    at processing.app.AbstractMonitor.resume(AbstractMonitor.java:110)
    at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2240)
    at processing.app.Editor.access$2400(Editor.java:77)
    at processing.app.Editor$DefaultExportAppHandler.run(Editor.java:2315)
    at java.lang.Thread.run(Thread.java:745)
Caused by: jssc.SerialPortException: Port name - COM11; Method name - openPort(); Exception type - Port busy.
    at jssc.SerialPort.openPort(SerialPort.java:164)
    at processing.app.Serial.<init>(Serial.java:114)
    ... 8 more
Error opening serial port 'COM11'.

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

Ok strange, just after posting this the qduino decided to flash a different light on me so I try to upload again and it works... So apperantly just by keeping the qduino connected for some time it will start to work again...