text:
Arduino Due and BNO055
For a physical activity monitoring project, I am developing a prototype based on an Arduino Due and several IMUs (BNO055 from Bosch).
I have to collect the data from the sensors simultaneously (3 for the moment). I want to use a Serial connection (Since the Arduino Due has 4 hardware serial ports).

Here comes the first issue : I use the shuttleboard BNO0055, and because of my limited knowledge, I'm not sure I did the right wiring. As I understood in the datasheets, the PS0 pin must be connected to the GND and PS1 to the incoming voltage. The COM0 to the RX of the Arduino and COM1 to TX. I am confused by the documentation, I can't figure out which pin of the shuttleboard are the COM0 and COM1. (I can't post the pictures of my wiring since it's my first post here).
And now there is a second problem: If the wiring is good, how can I communicate with the sensor to get the Euler angles? The BNO055 sensor does the fusion data itself, and gives the quaternions or the Euler angle. Bosch provides a library. I have never used a library, and I don't know the syntax to ask the sensor to give the Euler angles. Can someone give me a code to do this? Or at least explanations on the syntax I should use?

PS0 pin must be connected to the GND and PS1 to the incoming voltage. The COM0 to the RX of the Arduino and COM1 to TX. according to figure 10 that would be correct. The library you linked to only works for I2C, so that won't work. Is there any reason to use UART over I2C?

At the end of the project I should have 5 IMU connected. With the Arduino due I know I can have 4 IMUs, but I would miss one. For now I can use I2C, I tried, and It's the same problem, I don't know if my wiring is good, I tried several wiring and each time I used the I2C Scanner and it failed everytime

Update : The I2C Scanner found the device at address 0x29, only when I link I2C_MODE_ADR_SEL to the incoming voltage


text:
nRF24L01 module using Mirf library was working and then stopped

I have two nRF24L01 modules, they are both attached to a sensor shield that has special ports for this type of module, on Arduino Unos.

I have this code on the Arduino that is sending the signal:
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <SPI.h>
#include <Wire.h>

//0 = stop, 1 = left, 2 = right, 3 = forward, 4 = backwards
long command;
long last_command;

long Joystick_1_X;
long Joystick_1_Y;
long Joystick_1;

void setup() {
  // put your setup code here, to run once:
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  Mirf.setTADDR((byte *)"serv1");
  Mirf.payload = sizeof(long);
  Mirf.config();
  Serial.begin(115200);
}

void loop() {
  Joystick_1_X = analogRead(A0);
  Joystick_1_Y = analogRead(A1);

  if(Joystick_1_X < 450){
     command = 1;
  }else if(Joystick_1_X > 600){
    command = 2;
  }else if(Joystick_1_Y > 600){
    command = 3;
  }else if(Joystick_1_Y < 400){
    command = 4;
  }else{
    command = 0;
  }
  if(command == last_command){
  }else{
    Mirf.send((byte *)&command);
    last_command = command;
   }
  }

and this code on the Arduino that is receiving
#include "SPI.h"
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"

int TN1= 3;
int TN2 = 4;
int ENA = 9;

int TN4 = 5;
int TN3 = 6;
int ENB = 10;

long data;

void setup() {
 pinMode(TN1, OUTPUT);
 pinMode(TN2, OUTPUT);
 pinMode(TN3, OUTPUT);
 pinMode(TN4, OUTPUT);
 pinMode(ENA, OUTPUT);
 pinMode(ENB, OUTPUT);

 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
 Mirf.setRADDR((byte *)"serv1");
 Mirf.payload = sizeof(long);
 Mirf.config();
 Serial.begin(115200);
 Serial.print("begin");

}

void loop() {

  // put your main code here, to run repeatedly:
  receiveCommand();
  if(data == 1){
    left();
  }else if(data == 2){
    right();
  }else if(data == 3){
    forward();
  }else if(data == 4){
    backwards();
  }else if(data == 0){
    stop_rover();
  }
}

void receiveCommand(){
  if(!Mirf.isSending() && Mirf.dataReady()){
    Mirf.getData((byte *)&data);
    Mirf.rxFifoEmpty();
    Serial.print(data);
  }else{
    Serial.println("No data to be recieved");
  }
}

void forward(){
  digitalWrite(ENB, HIGH);
  digitalWrite(ENA, HIGH);
  digitalWrite(TN4, HIGH);
  digitalWrite(TN3, LOW);
  digitalWrite(TN1, HIGH);
  digitalWrite(TN2, LOW);
}

void backwards(){
  digitalWrite(ENB, HIGH);
  digitalWrite(ENA, HIGH);
  digitalWrite(TN4, LOW);
  digitalWrite(TN3, HIGH);
  digitalWrite(TN1, LOW);
  digitalWrite(TN2, HIGH);
}

void left(){
   digitalWrite(ENA, HIGH);
   digitalWrite(TN1, HIGH);
   digitalWrite(TN2, LOW);
}

void right(){
  digitalWrite(ENB, HIGH);
  digitalWrite(TN4, HIGH);
  digitalWrite(TN3, LOW);
}

void stop_rover(){
  digitalWrite(ENB, LOW);
  digitalWrite(ENA, LOW);
  digitalWrite(TN4, LOW);
  digitalWrite(TN3, LOW);
  digitalWrite(TN1, LOW);
  digitalWrite(TN2, LOW);
}

This was working, and the rover did spin its wheels when the remote broadcasted a signal, but then it just stopped. The sensor shield says that they are plugged into the 3V port, I tried using the RF24 library and that did not work either.
Any help would be greatly appreciated.

Could you please try the builtin self test checks that come with RF24 library maintained by TMRh20? Do they all work properly?

I uploaded the GettingStarted.ino file to two Arduinos the trasmitting node printed out this Now sending
Sent 18204112, Got response 0, Round-trip delay 18204112 microseconds
Now sending
Sent 28434792, Got response 0, Round-trip delay 28434792 microseconds
and the receiving node printed out this Sent response 251854848
Sent response 0

Something is wrong. Check your wiring and if you can, solder electrolytic caps to the GND and 3.3V pins of the radio module.

There is no wiring the nRF24L01 is plugged into a sensor which is on the arduino, I put a picture of the sensor shield with the nRF24L01 above.

Are the defined pins in the sketch right? Could you please solder a cap to the power pins of the radio module?

I tried changing the defined pins to something else but I keep getting Now sending
failed
Sent 3496020, Got response 0, Round-trip delay 3496020 microseconds. And i do not have any caps

What does the other node say? Also, please go buy some capacitors and solder them on, it can solve your problem.

I soldered on capacitors, but I am still getting Sent 28434792, Got response 0,

What does the second node say? Have you checked if your CS and CE pins are defined correctly?

The receiving node is writing Sent response 1795, Sent response 0, Sent response 259, Sent response 0 and when I swaped around the defined CS and CE pins the node wrote Now sending
failed
Failed, response timed out.

Try the example named Transfer. The round trip delay and sent responses are weird although the pins are right and you have soldered capacitors on the NRF24L01+ modules. Weird.

I do not think that that worked, the receiving node wrote this Rate: 365.92
Payload Count: 11435
Rate: 16.54
Payload Count: 517
Rate: 0.00
Payload Count: 0
Rate: 0.00
Payload Count: 0
Rate: 0.00
Payload Count: 0
Rate: 0.00 and the transfering node wrote this Initiating Basic Data Transfer
Transfer complete at 219.18 KB/s
0 of 10000 Packets Failed to Send
Initiating Basic Data Transfer
Transfer complete at 219.18 KB/s
0 of 10000 Packets Failed to Send

Also they both wrote at the start this also at the start they both said this STATUS   = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1  = 0x0000000000 0x0000000000
RX_ADDR_P2-5  = 0x00 0x00 0x00 0x00
TX_ADDR   = 0x0000000000
RX_PW_P0-6  = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA   = 0x00
EN_RXADDR  = 0x00
RF_CH   = 0x00
RF_SETUP  = 0x00
CONFIG   = 0x00
DYNPD/FEATURE  = 0x00 0x00
Data Rate  = 1MBPS
Model   = nRF24L01
CRC Length  = Disabled
PA Power  = PA_MIN

If it is true that you have defined the CS and CE pins right, your nrf24l01+ modules are broken.

Using the MIRF Library that I got from here, and then using this code to send
 Mirf.send((byte *)&command);
    while(Mirf.isSending()){
        }

and this code to receive
 if(!Mirf.isSending() && Mirf.dataReady()){
    Mirf.getData((byte *)&data);
    Mirf.rxFifoEmpty();
else(){
}

I was able to get it to work

source: Stack Exchange

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

sort: votes


text:
Arduino can't find my custom library: fatal error, Motor.h not found etc
I have been working on a project building a robot and using my own custom-built libraries to control it. However after converting all my old code into libraries Arduino can't find them.
Everything thing I have seen says to save them in the 'libraries' folder in with the sketches in MyDocuments and to reboot the Arduino Environment so it will recognize them.
Did that.
It even recognizes them in the sketch menu as libraries that can be imported. However, when I click on them to be included, a new blank line is entered into the sketch instead of an include statement. Perhaps this is some clue? I am really out of ideas at this point as to what I have done wrong.

Which version of the IDE? What is the library name? What are the file names in this library? Personally I never use the "import library" menu item, I simply type the include in myself.

its 1.6.3, its a library I made myself called Motor.h and I actually did write the include statement in myself too. I thought maybe I was doing it wrong somehow. The files are just Motor.h and Motor.cpp but it doesn't find them even though they are in the libraries folder

Are they in a folder, called Motor which is itself inside the libraries folder?

yes it is. the libraries folder in with all my saved sketches not the one in the C drive (though I tried adding it to that one too).

It should not be in the Arduino distribution folder (the one with the Arduino program in it). It should be in libraries in the sketchbook folder.

It is in the correct libraries folder. However the program still insists the file Motor.h doesn't exist

I wanted to vote for the answer from trpropst, but I don't seem to be authorised to do so.
I had the same problem as Caleb. It turned out that the problem was that the user library directory /Arduino/libraries/ contained a library with a missing ".h" file. The Arduino IDE stopped loading the user libraries when it reached the library with the missing ".h" file.
i.e.
the folder "/Arduino/libraries/libraryA" existed
the file "/Arduino/libraries/libraryA/libraryA.h" existed
but the file "/Arduino/libraries/libraryA/libraryA.h" had an include
"#include <libraryB>" for which the folder "/Arduino/libraries/libraryB" existed but it did not contain a file "/Arduino/libraries/libraryB/libraryB.h"
I was trying to compile a program using libraryC, but not using libraryA or libraryB. I guess the lesson is do not develop libraries using the production tool chain.
edited to print < and > correctly

I had the same symptom described here. In my case, there was a broken link in my libraries directory. Removing that link made the problem go away. It seems that you need to be careful that there is nothing in that directory that could cause the IDE to have difficulty parsing it.
I saw this on a Linux environment (the original poster didn't specify the OS but the reference to "MyDocuments" sounds like Windows). The link I referenced was a symbolic link I had created to a custom library that I subsequently moved, breaking the link.

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


text:
Using union to return a range of bits from a data frame: wrong approach?
I'm working on an adaptation of Jason Leyrer's Guitar Hero Library for Arduino.  My version is for a DJ Hero controller, and I've also borrowed some code from this Arduino forum thread: topic=120527 (sorry can't post links yet).
The protocol is i2c and I am successfully reading data from it, however I'm not 100% sure what to do with the data.
The buttons are fine, as they are mapped to just one bit in a given byte.  However the other controls are a combination of 4, 5 and 6 bit longs.
The format according to Wiibrew is like so:

BE is for Euphoria button
CS : Crossfade Slider, lower is left and upper is right
SX and SY are the black analog stick.
ED is the Effect Dial
RTT is the turntable on the right as a 6-bit signed integer (positive = CW; negative = CCW)
RBG,RBR,RBB are the Green, Red and Blue buttons on the right
LTT is the turntable on the left as a 6-bit signed integer (positive = CW; negative = CCW)
LBG,LBR,LBB are the Green, Red and Blue buttons on the left

I'm trying to do this:
 signed long DJ_ED()
{
  pack5 ED;
  ED[0] = (DJ_buf[3] >> 5) & 1;
  ED[1] = (DJ_buf[3] >> 6) & 1;
  ED[2] = (DJ_buf[3] >> 7) & 1;
  ED[3] = (DJ_buf[2] >> 5) & 1;
  ED[4] = (DJ_buf[2] >> 6) & 1;

  return ED;
}

Where pack5 is the following:
#define packet5
union pack5
{
   signed long value;
   int ints[5];
};

but I'm getting the following error:
no match for 'operator[]' (operand types are 'pack5' and 'int')
What am I doing wrong?

Why are you not using a bitwise struct?

@IgnacioVazquez-Abrams tbh I'm not very experienced in C and don't really know what I'm doing!  Is a bitwise struct the same as a bitfield?

You are using a union so you have to specify which part of the union you want. Your function should read:
 signed long DJ_ED()
{
  pack5 ED;
  ED.ints[0] = (DJ_buf[3] >> 5) & 1;
  ED.ints[1] = (DJ_buf[3] >> 6) & 1;
  ED.ints[2] = (DJ_buf[3] >> 7) & 1;
  ED.ints[3] = (DJ_buf[2] >> 5) & 1;
  ED.ints[4] = (DJ_buf[2] >> 6) & 1;

  return ED.value;
}

It still looks wrong because you are only putting a single bit into those 5 bytes (because of the & 1). And 5 x int will be a lot longer than one signed long.

The code below seems to match the data structure you posted an image of:
struct packedFields
{
  // byte 0
  unsigned int sx      : 5;
  unsigned int rtt_4_3 : 3;

  // byte 1
  unsigned int sy      : 5;
  unsigned int rtt_2_1 : 3;

  // byte 2
  unsigned int rtt_5   : 1;
  unsigned int cs      : 4;
  unsigned int ed_4_3  : 2;
  unsigned int rtt_0   : 1;

  // byte 3
  unsigned int ltt_4_0  : 5;
  unsigned int ed       : 3;

  // byte 4
  unsigned int ltt_5    : 1;
  unsigned int rbr      : 1;
  unsigned int b_plus   : 1;
  unsigned int filler_2 : 1;
  unsigned int b_minus  : 1;
  unsigned int lbr      : 1;
  unsigned int filler_1 : 2;

  // byte 5
  unsigned int filler_4 : 2;
  unsigned int rbb      : 1;
  unsigned int lbg      : 1;
  unsigned int be       : 1;
  unsigned int rbg      : 1;
  unsigned int filler_3 : 1;
  unsigned int lbb      : 1;

};

union packedFieldsUnion
  {
  packedFields a;
  byte b [6];
  };

void doSomethingWithTheFields (packedFieldsUnion & theFields);  // prototype
void doSomethingWithTheFields (packedFieldsUnion & theFields)
  {
  theFields.a.rtt_4_3 = 3;
  theFields.a.ltt_4_0 = 2;
  }  // end of doSomethingWithTheFields

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  Serial.print (F("packedFields sized = "));
  Serial.println (sizeof (packedFields));

  packedFieldsUnion foo;
  memset (&foo, 0, sizeof foo);

  doSomethingWithTheFields (foo);

  Serial.println (F("-- packedFields bytes --"));
  for (int i = 0; i < sizeof foo; i++)
    Serial.println ((int) foo.b [i], HEX);

  }  // end of setup

void loop ()
  {
  }  // end of loop

I have a bitwise struct, as Ignacio Vazquez-Abrams suggested. Testing indicates you put the low-order bits first. Then I made a union of this struct and 6 bytes. You can't fit the whole thing into a signed long anyway (a long is 4 bytes) so that part of your code was doomed to fail.
A small bit of test code proves that the bits are being accessed in the correct way. You still need to fiddle around with things like RTT which has individual bits scattered in different places.

If you look at the data format you posted there are 6 bytes, not 5. They are numbered 0, 1, 2, 3, 4, 5. A total of six of them.

... hit enter too early!  This has saved me at least an evening or two so I greatly appreciate the effort.  I hope you don't mind if I ask a follow-up question... since I'm trying to make this into a library I'm planning on passing foo to my library functions which I've named DJ_funcs.ino.  I'm presuming declaring foo globally here would be a no-no?  Is there a best practise here?

Just pass it by reference. See amended post above, I show an example of doing that.

Hi @nick-gammon, sorry I thought I replied to your above comment! I checked it late at night and ended up practically falling asleep in front of the laptop... your revision was extremely helpful but I'm still having trouble connecting the dots.  I've made a post on the arduino forum; any help I can get is hugely appreciated!


text:
Good tips for how to connect cables into Mux Shield II?
I just got a Mux Shield 2 and got it working as I expected. Now I started to find out how to actually connect the I/O cables to the board. Doesn't seem to be as simple as I thought. I don't want to solder cables into the board for maintenance reasons. So, does anyone have any good tips on how to do this?

if you want plugs, solder plugs onto it.

Solder 100-mil male headers onto the board, then use 100-mil crimp terminals to connect the wires.


text:
I2Cdev #include weirdness
I am using Jeff Rowberg's MPU6050 library, and I simply don't understand what is going on in the following lines of the first example (MPU6050_raw.ino):
#include "I2Cdev.h"
#include "MPU6050.h"

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE
// implementation is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include <Wire.h>
#endif

So, what I got from that is, if I2Cdev is using Wire instead of some alternative I2C library, I should include Wire.h. I really don't see why that's necessary, so I removed the line in which Wire.h is included, and got this error:
C:\Users\Franco2500k\Documents\Arduino\libraries\I2Cdev/I2Cdev.h:80:26: fatal error: Wire.h: No such file or directory
     #include <Wire.h>

So, apparently, I2Cdev.h already tries to include Wire.h, but somehow fails? And another #include a few lines later goes back in time and fixes everything? Can someone explain what is going on?

The Arduino IDE means well, really it does. It copies your source, the device core, and any libraries used by your source all to a separate directory so that it doesn't poison any of their original locations unintentionally.
But of course, there's something missing from that list. The IDE doesn't copy libraries used by other libraries. Therefore if you don't include Wire.h in your .ino file then Wire will be missing from the build and you get the error observed. Cracktastic.

Indeed. I describe this process here: http://arduino.stackexchange.com/questions/13178/classes-and-objects-how-many-and-which-file-types-i-actually-need-to-use-them/13182#13182

Weird. So, if I understood that right, I2Cdev.cpp is not compiled, waiting to be linked; it is instead compiled with the entire project every time I build it, and the IDE knows which sources to compile by scanning the my source for #includes. Is that right?


text:
How can I turn this into an (Ableton) controller?
I found this lovely decade box in a demolished house recently and want to turn it into an Ableton controller. As you see, there are 18 knobs, each with 12 individual states.
I'd like to have a program which can access the states of all the knobs at any time, and I have an arduino which I can use. Is this possible to do without a shield?
My first thought is that, since many of the leads on the back already have resistors on them, I could use a sort of total-resistance-across-the-connection approach which would suit itself to the analog inputs. But I'm not sure that's the way to go, especially if I want very low latency.
How can I wire up a board that has digital access to all the pins here? How does a multiplexer play into this? How many inputs would I need? I am super new to this kind of stuff, so I imagine this must be a pretty simple answer.
Thanks for your help.

The other answers are excellent, however I want to address this question:

How does a multiplexer play into this?

Just as an example of how multiplexing helps, I opened up a scrolling LED sign which has 504 individual LEDs which "appear" to be all on at once (if wanted).
Internally were 10 x 74HC595 serial shift registers. 9 of them were hooked up to the individual columns (giving 72 columns), and the last one was connected to the 7 rows.
 9 * 8 =  72    columns
72 * 7 = 504    LEDs

Thus we could turn on 504 LEDs. However to have individual LEDs appear to come on the code has to turn on one row (out of the 7) and then output the pattern for that row to the 72 columns. Then it switches to another row, does the next pattern, and so on.
I have a video of this effect on Vimeo.
If you do it fast enough, all the LEDs appear to be one at once.

Now you can do this for switches too, just connect all the individual positions together, and then apply "power" to each switch in sequence, and read the results. This time you want an input shift register, eg. the 74HC165 for the reading, and an output register for powering each switch.
The problem is with switches though, that you would get "phantom" reads because switches aren't diodes (or, worse, the inactive switches would short the power to ground). So you would need a diode in series with each switch to prevent that. Ah well, diodes are cheap.
This is exactly the same concept as the way keypads work. Say, a 16-key keypad will have 8 wires: 4 rows and 4 columns.

Having said all that, you will still need quite a few chips unless you set up quite a complex "simulated" keypad array. Maybe it wouldn't be too bad.
You have 17 switches so that would be 2 x 74HC595 for activating each switch, plus one spare pin on the Arduino. And the switches seem to have around 12 positions, so that would be 2 x 74HC165 to read which position it was at.
So, for each switch, you make that one HIGH and the others LOW. Current will flow through the diodes and the rotary switch, presenting a HIGH on one of the 12 "reading" pins. The diodes stop the current from shorting the HIGH to the LOW through other switches.
You take a reading, and move onto the next switch. This can be done quickly, in the same way the LED sign scrolls so fast you can't spot any flickering.
This schematic illustrates the idea:

In this example we apply a HIGH to the common part (rotor) of the left switch. It goes through the diode, and the selected position, to make input "read 1" high. The diode on the other switch prevents the HIGH from being shorted to the LOW, even though both switches are in the same position.
You would need a pull-down resistor for each of the 12 "reading" lines, so that if they weren't being forced HIGH, they would read LOW. And one diode per rotary switch. So, not too many extra parts. And the wiring is simple, just connect each corresponding switch pin together (except for the common one, of course).
I think this will work, unless anyone can see a major flaw. :)

Wow, this is great! Thanks so much. The LED example really helps to illustrate the point. I think this idea is workable, and seems like it would be pretty cheap.

I'm beginning to think Nick is some sort of super human. How else do you explain being able to generate so many high quality, educational solutions? :D

The hard part here is that you essentially have 216 inputs you need to read.
You could multiplex the analog pins using two 74HC4051. Analogread takes around 0.1ms, so around 2ms for all 18 knobs. Debouncing would however be pretty hard.
I'd probably go with input shift registers, and remove all the resistors. You would however need 27 8-bit shift register (3 registers per 2 knobs).
To reduce this you could encode the rotary position into 4-bit using a diode network. That way you can use only 1 shift register per 2 knobs. So 9 in total.

You can use the analog route by using a CD74HC4067, then you can hook it up to a analog demultiplexer, such as the CD74HC4067(breakout from SFE) which has 16 analog/digital inputs. You would use one of these and two analog pins, one from the breakout and one from the panel, as there are 17 dials from what I can see.
An example of a resistor ladder:

The 4067 is addressed using 4 digital pins to make up a binary address relating to each input. You would put this into a for loop and read from each address and put in an array of values each time you loop. And when leaving the loop read the last analog value.
I would use port manipulation to write the address as it would speed up the operation.
Once you have the values in the array you can then do the math require to get where the dial is or you can do that as you read the analog pin the the for loop, kind of keep it all in one function. You can find the calculation for converting in the Wikipedia article, the R-2R style.
Bildr have a nice write up with some code, an image of the basic setup:

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


text:
ATtiny461 PWM CTC mode help
I am a beginner at AVR and programming. I am using ATtiny461 and asked to make code to use timer in PWM and CTC mode and use interrupts and pin toggle, this code worked for me with normal timer and toggle but I don't know how to make it work with CTC and PWM:
#include <avr/io.h>
#include <avr/interrupt.h>

//Init PD6 pin as output
void InitPort(void)
{
    PORTB&=~(1<<PB1);//initial value 0
    DDRB|=(1<<PB1);
}
//Initialize Timer0
void InitTimer0(void)
{
    //Enable Timer0 overflow Interrupt
    TIMSK|=(1<<TOIE0);
    //Set Initial Timer value
    TCNT1=5;
}
void StartTimer0(void)
{
    //Set prescaller 64 and start timer
    TCCR0B|=(1<<CS01)|(1<<CS00);
    //Enable global interrupts
    sei();
}
//Timer0 Overflow ISR
ISR(TIMER0_OVF_vect)
{
    //Reset Initial Timer value
    TCNT1=5;
    //toggle PD6 pin
    PINB=(1<<PB1);
}

int main(void)
{
    InitPort();
    InitTimer0();
    StartTimer0();
    while(1)
    {
        //doing nothing
    }
}

and I know those commands for setting fast PWM and CTC:
TCCR1D |= (0<<WGM10)|(0<<WGM11);
TCCR1A |= (1<<PWM1A)|(1<<COM1A0)|(0<<COM1A1);

PWM is only supported for timer1 on the ATTiny461. Not in timer0.
Look at TCCR1A; specifically the COM1xn bits.

ok,thank you,good so i use timer1...but where can i include using PWM,TCCR1A und com1A,B  bits in this code...since the code above worked for me but i didnt understand the whole sequnce..since the company asked me for results.

You can put it at the beginning of main. Or copy/replace the functions InitTimer0 and startTimer0 and change 0 to 1. Change the contents to apply to timer 1, and call those functions in main, just like with timer0


text:
Suggest me a power source for my Arduino UNO project
I am working on a Project with:

1 Arduino UNO
5 micro 9g servos (Only one Working at a time)
2 small LED bulbs
1 MicroSD reader module
1 Speaker

Can I power my Arduino UNO with a common 9v Battery?
I also have in mind to use an external power supply for servos... but what to use?
Please suggest me a perfect power supply system

Have you looked into methods of voltage regulation? What about different batteries? Do you have any size, space or cost restrictions? You're really asking too much of Arduiono.SE to do all the work.

Unfortunately, the perfect power supply system doesn't exist yet. However, powering an Arduino is simple.  You have to main options 9V for standard "full size" Arduinos (such as the UNO that you mention), although you could go for the low voltage 3.3V options.
Covering just the 9V option, from the Power section of Arduino Uno:

Power
The Arduino Uno can be powered via the USB connection or with an
external power supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter
(wall-wart) or battery. The adapter can be connected by plugging a
2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER
connector.
The board can operate on an external supply of 6 to 20 volts. If
supplied with less than 7V, however, the 5V pin may supply less than
five volts and the board may be unstable. If using more than 12V, the
voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.

You should probably also take a look at Power Supplies, in particular the section on Batteries and cells, also from the following section Voltage conversion and regulation, it states:

In a very simple scenario, you connect a disposable 9v battery
(probably one of the (approx) 4cm x 2.5cm x 1.5cm units with two snap
connectors on one end) to your Arduino, and the Arduino's built in
voltage regulator takes care of reducing the voltage to a consistent
5v or 3.3v, depending on the sort of Arduino you have.

So you have a couple of choices regarding 9V, either the P9 cell

or a pack that holds six 1.5V AA or AAA batteries.
You may find this link, How to run an Arduino (clone) on (AA) batteries for over a year – part 2, an interesting read. Here the chap uses four AA batteries, which only gives 6V, to power an UNO:

I have just highlighted some information, you should take the time to read the links fully, and google for more information.

Regarding the servo motors, more current may be required. You can use the same four AA battery pack, thusly:

but the capacity of the batteries may leave something to be desired, especially if you use rechargeable batteries (which in today's eco-concious world, you should), so you may require something more hefty. A quick google will show you the options available.
Addendum
The video Flite Test : RC Planes for Beginners: Batteries and Safety - Beginner Series - Ep. 7 is an extremely useful video tutorial about LiPO batteries for RC projects.

Everything @Greenonline said plus...
A 2 Cell Lipo battery is 7.4 V. A modest 500 mAH battery would run your project for several hours, perhaps days. If you're not satisfied with the run time, buy a battery with more mAH, they go well past 5000 mAH! After all, these are the same types of batteries used in all forms of Radio Control Aeromodeling (lots of servos and brushless DC motors).
The Uno can regulate the 7.4 V although you'll need to buy/build a cable to connect the battery to the Uno. I'm not sure how much current the Uno regulator can provide but I've driven two micro servos with mine.
If the servos chatter, hum, are otherwise not working right or if there is smoke coming out of the regulator, you probably need a separate power source for the servos. A BEC like this https://en.wikipedia.org/wiki/Battery_eliminator_circuit is an inexpensive alternate and also a common RC part. :)

If you can, run it all off a 1S Lipo battery, which may involve finding servos that can tolerate the lower voltage. Also, the on-board regulator can handle about 1A but I really wouldn't try it for more than 500mA given the board's construction.

+1 - Good point about LiPO... I've added a link to a video tutorial to my answer.

Selecting a power supply involves considering the following:
1. Voltage Requirement
2. Current Required
3. Running duration
4. Cost
Voltage Requirement:
From the list of items specified all of your items except the microSD card (which works at 3.3V) works at 5V.
Current Requirement:
Arduino UNO: about 50mA
9G servo motor: 730mA peak
LED 5mm: 20mA*2 = 40mA
microSD Card Reader: 200mA peak
Speaker: 350mA
Total Current: 1.370 Amps
Running Duration:
Say I want this device to run for 1 hour straight, in order to this I will need a battery supplying 5V 1370mAh and a 1C rating. So if you want your device to run longer you will need to get a battery with a higher capacity (for 2 hours 2740 mAh and so on)
Cost
I dont think i need to mention much in this criteria
Solution 1:
For these requirements your easiest solution is to use a USB power bank with 2000mAh or more.
On a protoboard solder 1x USB male, 1x USB female, 2x header pins. Solder All the positives together and all the negative together. And now you have a breakout for the power rails from the USB as well.
Power the Arduino via usb, microsd card via the 3.3V on the arduino and the rest via the breakout pins.
Solution 2:
Using lipo batteries. Lipo batteries have the advantage of having a large capacity in a small package (or a high power to weight ratio). In order to use this you will need a voltage regulator to get 5V. Please note that as per the calculation you will need a total of 1.37A to power your device at peak, this cannot be done via the on board regulator of the Arduino.
In total you will the following components to get this to work:
LiPo battery
Voltage regulator
LiPo Charger
Solution 3:
Using Alkaline battery. You can refer to the Minty Boost tutorial over at Adafruit to learn about this.
Conclusion:
If you want a headache free solution to your problem, buy a USB power bank , but if you want a more customizable and low cost solution go for the LiPo battery
And if you dont need a portable solution. Go for a wall adapter 5V/2A, thats pretty much every high end mobile phone charger

I have had a lot of success using an off-the-shelf power bank - they're easy to get, already have charging circuits (from USB), and are at the right voltage (+5V). You can plug the power bank directly into the USB port of the Arduino.
The only problem I've had is that some power banks shut down if there is not enough current being drawn - a resistor from +5V to GND solves that problem (make sure you work out how many watts your resistor is letting through, to make sure it can dissipate the heat - I used a 100Ohm resistor, at 5v; I put "Ohms Law calculator" into google, filled in 5V & 100 Ohm, and found that it needed to be a 1/4 watt resistor - perfect! I also noted that it drew 50 milli amps AKA 0.05 amps. I tried resistors with a higher resistance e.g. 200 Ohm, and the power bank powered down. If your project is drawing more power (continuously!) then you might get away with a higher resistance).
My power bank can supply 1.5 Amps, which should be plenty for your project.

You can use 9v battery and use separate one for servos. Due to voltage being "relative," you still need to connect the grounds.
You can connect the + of the battery to the VIN of the Arduino.


text:
How can I build a simple "Smartwatch" with Arduino Pro Mini and Display?
I want to know how I can build a simple "Smartwatch" with an Arduino Pro Mini and a Display with a size from maybe 1,5" what Display should I use for Touch and color?
I only want simple things like synchonising the time with my Smartphone trough a HC-06 Bluetooth Module.

Please tell us what display you eventually end up using, especially it it's not one already listed at http://www.opencircuits.com/Watch_display .

If your goal is to make a watch you'll need a RTC (Real Time Clock) this can take the form of breakout board, or you can build the circuit yourself. The RTC is needed if you want the mini to display the time. The mini (in fact, most micros) have no internal clock (though they may have a crystal that can simulate time keeping, but this isn't as useful if you want the time)
It sounds like you want an OLED display. They come in watch-like sizes. There are a few small ones. None are touch displays. I have seen larger touch displays. Maybe combine an OLED with a clear capacitive surface?

Yes but I'd like to synchronice the time my Smartphone is showing and is there no small oled Display with 1.5" with Touch ?


text:
Uploading a simple sketch takes forever
I am trying to upload this simple sketch into my arduino with a shield I made. It takes forever (note I have the right COM port on)
  int sensorValue = 0;

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

  void loop(){
     sensorValue = analogRead(A4);
     delay(10000000);
     Serial.println(sensorValue);
     delay(10000000);
  }

Enable verbose output in the settings. That way you can see what's going on, and what part of the compiling and uploading process takes so long. Also make sure you have an up to date version of the Arduino IDE, as some previous version didn't cache the previously compiled libraries properly.

if you want such a long delay in loop(), you should use the millis() function, it should free the MCU for other stuff.

Please copy and paste the messages you see when uploading. Why are you waiting 2.7 hours before displaying the value you read? How does that help?

My solution was to select the right version of the board (Tools->Board) mine was Arduino Leonardo. It was selected something else..

Are you sure the problem is in the upload time? delay() takes the number of milliseconds you want to wait. In your code, it should take about 3 hours before the Arduino sends some data through the serial port.

I think this is a reasonable answer - sometimes people misinterpret one delay for another

I had the same problem. I noticed that the RX & TX LEDs we're not flashing as they normally do when I upload a file. I'm using an older knock off nano.
My solution:
Under Tools> processor.... I switched from the defaulted "ATmega328P" to the "ATmega328P(Old Bootloader)" option. The next upload attempt was quick and successful. Normal flashing RX &TX LEDs during the upload as well. Hope this helps someone.

If the problem does indeed lie in the upload (see DoubtBearer's answer), then you should turn on verbose output, to see exactly what part of the upload is giving issues.
In your IDE, click File -> preferences; look for the section "Show verbose output during:" and tick both Compilation and Upload.
Re-run your upload, and see what is taking up all the time. If you can't figure it out from that, please post the log (it will appear in the black area at the bottom of the IDE, you should be able to cut & paste).

Check the end of this thread for the reply by 'Toshibass', Unbelievable slow compilation of simple sketches

I was having same same problem compile took > 3 minutes for small sketch using serial or OTA however I found solution The program that was slowing down compile was IBM's Trusteer .. Rapport which is a fraud prevention program distributed by my bank once I de-installed it, same compile took 10 seconds, now all I need to do is find an alternative or hope IBM produce a fix after I filled in a issue report to them.

It worked for me, the culprit was some software called 'Trusteer'.

I have added a direct link to the post that you refer to, as well as quoting the reply. As it stood, your answer was a "link-only answer". Please provide greater detail in your future answers. :-)

If you are taking too much time for uploading means there is communication between another device is happening, please remove all TX and RX pins.

Try downloading CH340 drivers. You must not have drivers for uploading the code to arduino board and to identify the right COM port.
Download and install the drivers, find the COM port number from device manager and update Tools->Port in your Arduino IDE.

I'm curious to know what the thinking behind this is.

I am not that active so sorry to reply so late. I believe that OS had drivers for some of the Arduino devices but it didn't had the appropriate drivers to communicate with my Arduino Nano. I struggled through the comments with no benefit and as soon as I figured out, I posted the solution here.


text:
Arduino + 4051 -> noise on certain 4051 pins

I am trying to use two 4051 ICs with an Arduino Micro right now. The idea was to have an 16-sensor demo station (8 sensors per 4051) wherein each 4051 pin selection is controlled by a potentiometer as input. I am new to using MUX's, so I mocked the following up as a quick demo based on this help document via Arduino (it's basically the same), which only uses one 4051 and does not use a potentiometer as selector input. So, I should be able to set the variable which to whatever number (0 - 7) to change the sensor selection that shows up at A2 on the Arduino.
Setting which to 0 is fine, but when I have more than two sensors plugged into 4051 and set the selector pin to any other number than 0 there is a strong likelihood that the output that shows up in the Serial Monitor is both unresponsive to the selected sensor change and appears to be simply noise (random numbers around 200 or so). I have been trying to isolate where this noise is coming from and am totally stumped. Has anyone had this issue and, if so, any suggestions on how to further diagnose what is happening? I am currently powering everything off of the Arduino 5V, which I am under the impression should be okay, though I have tried this with external power supplies (12V at 2A, for example) and gotten the same results (so I am fairly certain power is not the issue here).
Measuring voltage on pins 2, 3, and 4, I am seeing 1mV on pin 2, 1mV on pin 3, and 0.9mV on pin 4 following the initial spike during upload. When comparing against the Arduino 4051 doc I linked to above, I see that in that file pins 2, 3, and 4 show a Voltage of 2.5V following the initial spike during upload. Any idea what I am doing incorrectly?
/*
Sensor Station via MUX

 * code example for useing a 4051 * analog multiplexer / demultiplexer
 * by david c. and tomek n.* for k3 / malmï¿½ hï¿½gskola
 *
 * edited by Ross R.
 */

int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)
int which = 0;   //which y pin we are selecting
int val;

void setup() {
  pinMode(A2, INPUT);       // mux1 input
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
}

void loop () {

  which = (0);

  // select the bit
  r0 = bitRead(which, 0);
  r1 = bitRead(which, 1);
  r2 = bitRead(which, 2);    // use this with arduino 0013 (and newer     versions)

  digitalWrite(2, r0);
  digitalWrite(3, r1);
  digitalWrite(4, r2);

  //Either read or write the multiplexed pin here
  // refactor, this should be digitalWrite with millis or something
  val = analogRead(A2);     // MUX ouputs here

  Serial.print("sensor number ");
  Serial.print(which);
  Serial.print('\t');
  Serial.print("val is ");
  Serial.println(val);

  delay(2);
}

In the linked code, the for loop repeatedly cycles count from 0 to 7, so Ard. pins 2-3-4 will average 2.5 V.  In your code, they should sit close to 0 V.  What do you have 4051 pin 6, INH, set at?  What is another value of which that you tried, and what was connected to the corresponding 4051 input pin?   Try connecting all of the 4051 input pins (NO0-NO7, pins 13, 1, 15, 2, 14, 5, 12, 4) together and to the sensor or a pot and see if you get the same reading on all 8 channels.

You don't have a Serial.begin() call there so I'm a little surprised you see anything in the serial monitor.

I have a post about that chip at 74HC4051 multiplexer / demultiplexer.
I made up the circuit shown on my page above with modifications as described below:

I moved the A/B/C and O/I pins to match your code.
A is the low-order bit so pin 11 on the 74HC4051 should go to D2 on the Arduino.
74HC4051  Arduino   Meaning
    11       D2        A
    10       D3        B
     9       D4        C
     3       A2        O/I

I put a pot on I/O0 (pin 13 on the 74HC4051) and randomly set the other pins to +5 V or Gnd, as shown.

In setup() I added:
Serial.begin (115200);

I also modified it to automatically sequence through all 8 possible ports, and then stop after 1000 iterations to stop flooding the USB port on my computer. Code is:
int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)
int which = 0;   //which y pin we are selecting
int val;

void setup() {
  Serial.begin (115200);
  pinMode(A2, INPUT);       // mux1 input
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
}  // end of setup

unsigned long counter;

void loop () {

  // select the bit
  r0 = bitRead(which, 0);
  r1 = bitRead(which, 1);
  r2 = bitRead(which, 2);    // use this with arduino 0013 (and newer     versions)

  digitalWrite(2, r0);
  digitalWrite(3, r1);
  digitalWrite(4, r2);

  //Either read or write the multiplexed pin here
  // refactor, this should be digitalWrite with millis or something
  val = analogRead(A2);     // MUX ouputs here

  Serial.print("sensor number ");
  Serial.print(which);
  Serial.print('\t');
  Serial.print("val is ");
  Serial.println(val);

  delay(2);

  if (++which > 7)
    which = 0;

  if (++counter >= 1000)
    {
    Serial.flush ();
    exit (1);
    }
}  // end of loop

The output from your sketch was as expected:
sensor number 0 val is 781
sensor number 1 val is 0
sensor number 2 val is 1023
sensor number 3 val is 1023
sensor number 4 val is 0
sensor number 5 val is 0
sensor number 6 val is 0
sensor number 7 val is 1023

I suggest you check that your wiring agrees with mine.

Re “I moved the A/B/C and O/I pins to match your code”, your diagram connects 4051 A,B,C to Ard 6,5,4 instead of to Ard 2,3,4.  Also, the code shown in the question doesn't have a loop, so it might be good to include your code in your answer

@nick, Thanks for your input on this. The omission of Serial.begin was an oversight on my part but has been added. Your answer resolved my issue: I had the digital pins connected in the wrong order. Thanks!

@jwpat7 - I have modified the post to include my test code. your diagram connects 4051 A,B,C to Ard 6,5,4 instead of to Ard 2,3,4 - true, that was one of my stock schematics. I noted underneath which changes had been made. The code on my linked page matches the schematic. I wanted to use the OP's exact code (as far as possible) in case there were subtle problems with those pins.

@jwpat7: To make my answer more useful, I redrew the schematic to match the code on this page, to avoid confusion.

@NickGammon, +1


text:
Converting Arduino UNO's analog pins to digital I/O
I am working on an Arduino UNO Project and running out of digital pins.
Can I convert the six analog pins to digital I/O and use them to drive servos?
Please suggest me a method

Just putting it out there that it is a Uno, not a UNO. It is not an acronym.

A0 through A5 already have GPIO capability; treat them as you would any other non-PWM pin.
A6 and A7, found in similar boards that use a SMD package, do not have any GPIO capability whatsoever and can only be used for analog input.

Please explain.  Can I use A1 To A6 to drive my servos Normally ??

Only PWM-capable pins can drive servos normally.

The servo library uses software pwm if I'm not mistaken. So you should be able to use any pin.

@RanjanJha: A0 to A5 can be referred to as  D14 to D20. You could use digitalWrite(A0)  or digitalWrite(14) and the effect would be the same.


text:
Strange comportment of stepper motor while connected to internet
Problem moving a stepper motor after reading a value from a webpage....
I have a project to move a stepper motor from an angle after reading a number from internet; I have a typical 28BYJ-48 stepper with the hardware driver and an arduino + ethernet shield.
I have tested the motor alone with different library and it is working very well, the motor turn correctly to the proper angle and without shaking.
I have also been able to read a specific page with a number on it with the Ethernet shield and library. I am able to light a led whenever a certain value is read from this webpage.
Once I connect the 2 parts, either the stepper motot is vibrating a lot and moving from half the correct angle, either it is only shaking and not moving at all....
Note: I have powered it with an external power source thinking it was because of power issues but it doesn't change anything.....
I don't get it... Why would it work well before the etheret connection an not after?? Maybe it's late and I miss something obvious, but frankly I spent a lot of time looking online and checking my code
Here is my sketch if it anyone could help... thanks a lot in advance, I know it's quite long....but i'm quite desperate :-(
#include <AccelStepper.h>
#include <Ethernet.h>
#include <SPI.h>

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////

#define HALFSTEP 8

// Motor pin definitions
#define motorPin1  8     // IN1 on the ULN2003 driver 1
#define motorPin2  9     // IN2 on the ULN2003 driver 1
#define motorPin3  10     // IN3 on the ULN2003 driver 1
#define motorPin4  11    // IN4 on the ULN2003 driver 1

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
const int stepsPerRev =  2038;

byte server[] = { 192,168,0,11 }; //ip Address of the server you will connect to
String serverIP = "192.168.0.11";

int port = 8888; // server port

// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// byte ip[] = { 192, 168, 0, 188 }; // case we want to use fixed IP

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String webPage = "/index.php HTTP/1.0";

EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?
int ledPin = 5;
String pageValue;

//////////////////////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////////////////////

// setup the stepper parameters

void setup() {
  stepper1.setMaxSpeed(3000.0);
  stepper1.setAcceleration(1000.0);
  stepper1.setSpeed(500);

// start a full rotation ==> this is perfectly working!!

int steps = degreesToSteps(360);
  stepper1.moveTo(steps);
  stepper1.runToPosition();

   Serial.begin(9600);

   Serial.println("starting communication");

  //Connect the Ethernet Shield by specifying the board's mac and ip address

  if(Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
   }else{
    Serial.println("Ethernet shield connected & obtained IP address : ");
    Serial.println(Ethernet.localIP());

   //Shield already connected during setup phase, now connect to the webpage and retrieve the value

    //Connect to the server
    if(!connectToServer(server, port, webPage)){
        Serial.println("Failed to connect to server");

        }else{

               Serial.println("connected to server page");

               //Read the output value written on the webpage

              int angle = readPage().toInt();
              Serial.println(angle);

              int steps = degreesToSteps(angle);
              Serial.println(steps);

              stepper1.moveTo(steps);

              stepper1.runToPosition();

              delay(1000);

      //end of success case connection
      }

   }

 //end of setup
 }

void loop(){}

///////////////////////////////////////////////////////////////////////////////////////////
//Connect to a web page
////////////////////////////////////////////////////////////////////////////////////////////

boolean connectToServer(byte* server, int port, String webPage)
{
  //connect to the server
  Serial.println("connecting...");

  //port 8888 for our mamp server
  if (client.connect(server, port)) {
    Serial.println("connected");
    client.print("GET ");
    client.println(webPage);
    client.println();
    return true;
  }else{
    Serial.println("connection failed");
    return false;
  }

}

///////////////////////////////////////////////////////////////////////////////////////////
//Parse a value located between a < and a >
////////////////////////////////////////////////////////////////////////////////////////////

String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now

          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }

}

///////////////////////////////////////////////////////////////////////////////////////////
//Convert the degrees into the closest number of steps relative to the step motor model.
////////////////////////////////////////////////////////////////////////////////////////////

int degreesToSteps(float angleDegrees) {
  //return the closest number of steps to accomplish to move the motor for the specified angle

  const float stepsPerDegree = stepsPerRev/360.00;
  int steps = angleDegrees * stepsPerDegree + 0.5;  // we add 0.5 as when converting to an int the floating part is truncated, this allows to round the value to the nearest Int
  return steps;

}

Pin 11 is used for SPI to communicate with the Ethernet Shield. And pin 10 is used for the ChipSelect.
 So using the ethernet shield will toggle those pins, making the motor shake around.
Try using pins 6, 7, 8, and 9 instead.

Top!!!  It worked perfectly!! Thanks a lot you helped me a lot!!! Now I will have this interferences in mind and check each shield for each pin configuration inside the libraries!


text:
Processing error with processing-arduino examples
I have followed the instructions to run the Arduino processing examples but with no success.
Always import processing.serial.*; does not name a type. Which is perhaps a library (processing-arduino) related error.
My sketch is a sketch that comes with processing-arduino library.
I have searched for a long time with no solution. Any suggestion?
Errors:
arduino_output:28: error: 'import' does not name a type
arduino_output:30: error: 'import' does not name a type
arduino_output:32: error: 'Arduino' does not name a type
arduino_output:34: error: 'color' does not name a type
arduino_output:35: error: 'color' does not name a type
arduino_output:37: error: expected unqualified-id before '[' token
arduino_output.pde: In function 'void setup()':
arduino_output:42: error: 'size' was not declared in this scope
arduino_output:45: error: 'Arduino' was not declared in this scope
arduino_output:45: error: 'println' was not declared in this scope
arduino_output:50: error: 'arduino' was not declared in this scope
arduino_output:50: error: expected type-specifier before 'Arduino'
arduino_output:50: error: expected `;' before 'Arduino'
arduino_output:58: error: expected unqualified-id before numeric constant
arduino_output.pde: In function 'void draw()':
arduino_output:62: error: 'off' was not declared in this scope
arduino_output:62: error: 'background' was not declared in this scope
arduino_output:63: error: 'on' was not declared in this scope
arduino_output:63: error: 'stroke' was not declared in this scope
arduino_output:66: error: 'values' was not declared in this scope
arduino_output:66: error: 'Arduino' was not declared in this scope
arduino_output:66: error: expected unqualified-id before numeric constant
arduino_output:66: error: expected `)' before numeric constant
arduino_output:67: error: 'fill' was not declared in this scope
arduino_output:69: error: 'fill' was not declared in this scope
arduino_output:71: error: 'rect' was not declared in this scope
arduino_output.pde: In function 'void mousePressed()':
arduino_output:77: error: 'mouseX' was not declared in this scope
arduino_output:80: error: 'values' was not declared in this scope
arduino_output:80: error: 'Arduino' was not declared in this scope
arduino_output:80: error: expected unqualified-id before numeric constant
arduino_output:80: error: expected `)' before numeric constant
arduino_output:81: error: 'arduino' was not declared in this scope
arduino_output:81: error: expected unqualified-id before numeric constant
arduino_output:82: error: expected unqualified-id before numeric constant
arduino_output:82: error: expected `;' before numeric constant
arduino_output:84: error: 'arduino' was not declared in this scope
arduino_output:84: error: expected unqualified-id before numeric constant
arduino_output:85: error: expected unqualified-id before numeric constant
arduino_output:85: error: expected `;' before numeric constant

Welcome to Stack Exchange ibrahim. Can you edit your answer to include the example code? Is it the example that is near the bottom of the page that you link to? Also, you may like to take a tour of this site.

Which processing-arduino package version are you using, processing-arduino.zip or processing2-arduino.zip? Which version of the processing application are you using? Are you using it with the correct version of Processing?

Note: I am testing this on OS X, so my paths may differ slightly from yours.

I have managed to reproduce your issue, by incorrectly copying the arduino directory, from the unzipped processing2-arduino.zip package, to the libraries directory under the Arduino directory in my home directory, thus
/Users/user/Documents/Arduino/libraries/arduino

Then opening the Arduino IDE and running the arduino_output example, via the menu, File -> Sketchbook -> Libraries -> Arduino -> arduino_output. When I hit the compile button, in the Arduino IDE, the compiler throws up the exact same errors that you describe in your question.
However this is not the correct usage of this package. This package is intended to be used in conjunction with the Processing application, not the Arduino IDE. You should download Processing and then follow the instructions again:

Unzip the library and copy the "arduino" folder into the "libraries" sub-folder of your Processing Sketchbook. (You can find
  the location of your Sketchbook by opening the Processing Preferences.
  If you haven't made a "libraries" sub-folder, create one.)

Thus, on OS X, the path should now be
/Users/user/Documents/Processing/libraries/arduino

However, as usual, the documentation on the Arduino website leaves a lot to be desired. Pay careful attention to the following paragraph if you are running OS X or Linux:

Note: if you run Linux, you need to change Arduino.jar into
  arduino.jar, because Linux is case sensitive and it does not work if
  you don't change this letter (Arduino.jar is in the folder "library"
  of this Processing Library).

So,
/Users/user/Documents/Arduino/libraries/arduino/library/Arduino.jar

becomes
/Users/user/Documents/Arduino/libraries/arduino/library/arduino.jar

Relaunch the Processing application. File -> Examples..., opens up a window, scroll down to Contributed Libraries, open that, open Arduino (Firmata), open the arduino_output example. Hit the Run button, and after compiling you should see the window below:

HTH.


text:
Arduino Bluetooth connection with Android
I am wondering why my Arduino program won't start its sketch to connect a bluesmirf to an android device and send data to the android whenever I use an external power supply. The sketch starts whenever i open the serial monitor, but using the power supply, it wont work.

What type of arduino do you have?

You'll probably find that you are not supplying enough power to operate the Arduino and the components attached to the Arduino. Your current (Amps) draw is most likely higher than your external power supply can output.
I had this problem when using a 9v battery to power an Arduino with an XBee chip and some LEDs attached. The 9v would be able to power the kit for a while but would then not output enough current to power the Arduino. In the end I had to scrap a few LEDs.
You need to find out how much current your Arduino and its components are using and use a suitable power supply that can output enough current to power your Arduino.
Also remember when you send and receive a packet out of a Bluetooth radio - more current is required than when the Bluetooth radio is idle.


text:
Are static variables in a function bad?
For my code I use a couple of static variables.
But when I search the internet, they seem "evil".
For example: I have a function which will be executed every loop (5ms looptime).
to increase the speed I added some static variables to it.
Is the way I am doing this bad? Are there simple solutions for it?
Code:
int ProgFormula() {
  static int StartPosition;
  static int DeltaPosition;
  static int LoopTime = 5;
  static int AccelerationLoops;
  static int TotalLoops;
  static int EndOne;

  static float VelocityLoop;
  static float VelocityFactor;

  int Setpoint;

  if (Iteration == -1) {
    StartPosition = PID.ActualPosition;
    DeltaPosition = abs(SetPosition - StartPosition);
    VelocityLoop = Velocity / (1000 / LoopTime);
    TotalLoops = DeltaPosition / VelocityLoop;
    if (TotalLoops <= (AccelerationLoops * 2)) {
      AccelerationLoops = (TotalLoops / 2);
      VelocityFactor = (VelocityLoop * 0.5 / AccelerationLoops) / 2;
    }
    else {
      AccelerationLoops = 70;

      VelocityFactor = VelocityLoop * 0.5 / AccelerationLoops;
    }
    TotalLoops = DeltaPosition / VelocityLoop + AccelerationLoops;
    EndOne = (VelocityFactor * pow(AccelerationLoops, 2));
  }
  else if (Iteration >= 0 && Iteration <= AccelerationLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
    else {
      Setpoint = -VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
  }
  else if (Iteration > AccelerationLoops && Iteration <= (TotalLoops - AccelerationLoops)) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityLoop * Iteration - EndOne + StartPosition;
    }
    else {
      Setpoint = -VelocityLoop * Iteration + EndOne + StartPosition;
    }
  }
  else if (Iteration >= (TotalLoops - AccelerationLoops) && Iteration <= TotalLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = -VelocityFactor * pow((TotalLoops - Iteration), 2) + DeltaPosition + StartPosition;
    }
    else {
      Setpoint = VelocityFactor * pow((TotalLoops - Iteration), 2) - DeltaPosition + StartPosition;
    }
  }
  else {
    Setpoint = Setpoint;
  }
  return(Setpoint);
}

Is it better to avoid statics? If so why?
Thanks in advance,
Koen

Why do you need static variables in the above example? I can't see them being any use here. If you just want a variable that you can change easily because you're 'tweaking' your code (e.g. changing LoopTime so you get as many loops per second without compromising accuracy) then pull that variable into global scope; you can #define <name> <value> or const <Type> <name> = <value>. These declarations/definitions get 'smoothed out' by the compiler and so don't take up any program memory.

to increase the speed I added some static variables to it. - how does that increase the speed?

pow(AccelerationLoops, 2) - you want fast speed but then you call a function that will be slow?

I am still a newbie haha, hmm better replace that pow function...

No but my idea was to calculate some variables infront (iteration -1) how could i use those  otherwise?

So you mean you want to 'create' variables so that they already exist before you start the beefy calculations, thus saving time? I don't think it works like that. All the calculations after the if (iteration == 1) is going to get torn apart by the compiler and then rearranged as optimally as it thinks it can be. If you need execution of these to be quicker, you might be better off asking in StackOverflow, as this topic transcends Arduino and is definitely within the realm of programmers and compilers.

That too, but I actually meant the calculations of the statics at iteration == -1. Won't this save? If not, I can make those local

I understand better what you are attempting now. I gather you call the function with Iteration == -1 at some stage to "preload" the static variables, and then multiple times with other iteration values. To answer better we would need to know how often you do that. For example, do you do 1000 iterations before re-calculating the static variables? Or three iterations? Judging by the fact that you get PID.ActualPosition in the "preload" part, you must be calling it with Iteration == -1 reasonably often.

Hello Nick, yes you are right, when the function "starts up" it is calledwith Iteration -1. The amount of iterations it takes is depended on the DeltaPosition and the Velocity. Normally this will 500+

There is no point in making LoopTime static, as it is set on every call to the function. The whole point of static is to make sure the contents of the variable is preserved between calls. Static locals are much like globals in this respect, only they have a restricted scope. On the other hand, Setpoint should probably be static, otherwise it seems it may be returned uninitialized. And the line Setpoint = Setpoint; has no effect.

I made up a test by adding enough to the posted code to get it to compile:
float ActualPosition, SetPosition, Velocity;

int Iteration;

int ProgFormula() {

  static int StartPosition;
  static int DeltaPosition;
  static int LoopTime = 5;
  static int AccelerationLoops;
  static int TotalLoops;
  static int EndOne;

  static float VelocityLoop;
  static float VelocityFactor;

  int Setpoint;

  if (Iteration == -1) {
    StartPosition = ActualPosition;
    DeltaPosition = abs(SetPosition - StartPosition);
    VelocityLoop = Velocity / (1000 / LoopTime);
    TotalLoops = DeltaPosition / VelocityLoop;
    if (TotalLoops <= (AccelerationLoops * 2)) {
      AccelerationLoops = (TotalLoops / 2);
      VelocityFactor = (VelocityLoop * 0.5 / AccelerationLoops) / 2;
    }
    else {
      AccelerationLoops = 70;

      VelocityFactor = VelocityLoop * 0.5 / AccelerationLoops;
    }
    TotalLoops = DeltaPosition / VelocityLoop + AccelerationLoops;
    EndOne = (VelocityFactor * pow(AccelerationLoops, 2));
  }
  else if (Iteration >= 0 && Iteration <= AccelerationLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
    else {
      Setpoint = -VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
  }
  else if (Iteration > AccelerationLoops && Iteration <= (TotalLoops - AccelerationLoops)) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityLoop * Iteration - EndOne + StartPosition;
    }
    else {
      Setpoint = -VelocityLoop * Iteration + EndOne + StartPosition;
    }
  }
  else if (Iteration >= (TotalLoops - AccelerationLoops) && Iteration <= TotalLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = -VelocityFactor * pow((TotalLoops - Iteration), 2) + DeltaPosition + StartPosition;
    }
    else {
      Setpoint = VelocityFactor * pow((TotalLoops - Iteration), 2) - DeltaPosition + StartPosition;
    }
  }
  else {
    Setpoint = Setpoint;
  }
  return(Setpoint);
}

void setup ()
  {
   ProgFormula ();
  }  // end of setup

void loop ()
  {

  }  // end of loop

Disassembling this I got the following assembler:
000000a8 <_Z11ProgFormulav>:
  a8:   6f 92           push    r6
  aa:   7f 92           push    r7
  ac:   8f 92           push    r8
  ae:   9f 92           push    r9
  b0:   af 92           push    r10
  b2:   bf 92           push    r11
  b4:   cf 92           push    r12
  b6:   df 92           push    r13
  b8:   ef 92           push    r14
  ba:   ff 92           push    r15
  bc:   0f 93           push    r16
  be:   1f 93           push    r17
  c0:   cf 93           push    r28
  c2:   df 93           push    r29
  c4:   00 91 0c 01     lds r16, 0x010C
  c8:   10 91 0d 01     lds r17, 0x010D
  cc:   8f ef           ldi r24, 0xFF   ; 255
  ce:   0f 3f           cpi r16, 0xFF   ; 255
  d0:   18 07           cpc r17, r24
...
 4ec:   cb 01           movw    r24, r22
 4ee:   df 91           pop r29
 4f0:   cf 91           pop r28
 4f2:   1f 91           pop r17
 4f4:   0f 91           pop r16
 4f6:   ff 90           pop r15
 4f8:   ef 90           pop r14
 4fa:   df 90           pop r13
 4fc:   cf 90           pop r12
 4fe:   bf 90           pop r11
 500:   af 90           pop r10
 502:   9f 90           pop r9
 504:   8f 90           pop r8
 506:   7f 90           pop r7
 508:   6f 90           pop r6
 50a:   08 95           ret

0000050c <setup>:

So that function (ProgFormula) has taken up:
0x50a - 0xa8 = 1122 bytes

Now by removing the "static" declarations, like this:
   int StartPosition;
   int DeltaPosition;
   int LoopTime = 5;
   int AccelerationLoops;
   int TotalLoops;
   int EndOne;

   float VelocityLoop;
   float VelocityFactor;

It now compiles to:
000000a8 <_Z11ProgFormulav>:
  a8:   6f 92           push    r6
  aa:   7f 92           push    r7
  ac:   8f 92           push    r8
  ae:   9f 92           push    r9
  b0:   af 92           push    r10
  b2:   bf 92           push    r11
  b4:   cf 92           push    r12
  b6:   df 92           push    r13
  b8:   ef 92           push    r14
  ba:   ff 92           push    r15
  bc:   0f 93           push    r16
  be:   1f 93           push    r17
  c0:   cf 93           push    r28
  c2:   df 93           push    r29
  c4:   c0 91 04 01     lds r28, 0x0104
  c8:   d0 91 05 01     lds r29, 0x0105
  cc:   8f ef           ldi r24, 0xFF   ; 255
  ce:   cf 3f           cpi r28, 0xFF   ; 255
  d0:   d8 07           cpc r29, r24
...
 27e:   cb 01           movw    r24, r22
 280:   df 91           pop r29
 282:   cf 91           pop r28
 284:   1f 91           pop r17
 286:   0f 91           pop r16
 288:   ff 90           pop r15
 28a:   ef 90           pop r14
 28c:   df 90           pop r13
 28e:   cf 90           pop r12
 290:   bf 90           pop r11
 292:   af 90           pop r10
 294:   9f 90           pop r9
 296:   8f 90           pop r8
 298:   7f 90           pop r7
 29a:   6f 90           pop r6
 29c:   08 95           ret

0000029e <setup>:

That is now:
0x29e - 0xa8 = 502 bytes

Conclusion
Adding "static" has made the function over twice as long. Presumably it is also slower. After all, those extra instructions have be doing something.

to increase the speed I added some static variables to it.

Your belief that making variables static increases the speed does not seem to be supported.

Hmm that is a huge difference. Unfortunately that is not what I meant. When Iteration == -1, then those variables are calculated. These variables will be used in further iterations. Because I intitialized them as statics they remember their value, now these do not have to be calculated over and over again. But is it worth the memory loss?

Could you actually time the functions? I don't fully trust your assumption about longer code being slower, since it doesn't account for how much might be skipped/replayed by jumps.

@KoenR - can you please run a test and post the calculated values when Iteration == -1? I tried timing the two methods but without knowing what values you are using the results are pretty meaningless. Or you could simply time it yourself, by calling micros() at the start, and again at the end, subtract one from the other, and work out which is faster.

@BrettAM - you are quite right to not trust assumptions. I try not to make them if I can, however in this case without any knowledge of the figures involved, I had to guess.

@NickGammon timed the calculations. WOW! When using the static variables the calculation took +- 150 micros. Now if use it the formula without the statics it will take an astonishing 0 - 4 microseconds to calculate. Then I realised that the compiler still exists. All my variables were predefined (not changing). Now I runned it like it should, all the iterations with a static variable took 50 micros whereas the one without took 200 micros. In the end, statics are sometimes viable I guess

When using the static variables the calculation took +- 150 micros. - I'm not sure if you are saying it took more or less there. However it looks like static variables worked for you in this case. :) It is always nice to test these ideas. Sometimes it is hard to predict what the compiler will do to your code.

A lot what you are seeing here may be due to the the compiler's ability to keep local variables in registers rather than in memory.  In a situation where that does not apply (due to program complexity, architectural limits, or a volatile keyword), it may come down more to the availability of other base + offset indexing modes vs. stack pointer + offset ones.

You comparison is flawed because you replaced static variables with automatic variables, which changes the semantics of the program, as static variables remember their values between calls. C.f. the compilation warnings you get: “XXX may be used uninitialized in this function”. For the comparison to be fair, you have to replace the local statics with global variables. My tests show static variables have no size penalty.

Your comparison - whose? If I understand correctly the suggested code uses Memoization to save calculating things as often. The savings probably need to be measured empirically, because the cost of calculating the static variables (as opposed to register variables) would not be nil. Whether or not you get the benefit would depend on how often you have to recalculate.

to increase the speed I added some static variables to it. Is the way
  I am doing this bad? ... Is it better to avoid statics? If so why?

I use this technique too ... IMHO it is neither good nor bad.  In a logger, for instance, all the wall clock time stamp information has to be looked up (perhaps time(0)), and formatted at least once in any given second.  I use function static variables to prevent duplicating that effort for the 10's to 100's (or even more on a really fast machine) of log entries that happen in the same second.
I suspect your saying "to increase speed" is what the other answers focus on, and many contributors in SE jump on the 'premature optimization' concept. I think you unintentionally misled them.
Maybe your audience would respond more positively to the term 'memoize' ... this technique avoids some work (when it can).
And, just to be complete - Wikipedia agrees with you:

In computing, memoization is an optimization technique used primarily
  to speed up computer programs by storing the results of expensive
  function calls and returning the cached result when the same inputs
  occur again.

Note 1. I think memoization implies that there is work that need not be duplicated every time through the function (sometimes only initialization) ... thus there often will be an if-clause to skip over the un-necessary work.
Note 2. static is not the only way to hold onto previous values, but is probably somewhat more appropriate for a function when you do not want a class object (to hold the previous values).
Note 3. 'memoize' has impact because it avoids work, and this speeds up the whole system.

That is exactly what I meant. This function will be called every 5 milliseconds. So that is why I wanted to know which is faster. But next time better to call memoize

Any style recommendation is going to be a bit subjective and conditional, but the biggest problem I see here is that the function can only be running one set of variables at a time. What if you wanted to do two of the task your ProgFormula function is a part of simultaneously? You have no way to switch the state of those variables between calls.
You could make a struct to store the state that your function modifies, that way the calling code could swap out the state between calls. Or you could wrap it in a class so the calling code can make as many instances as it needs and not worry about the data each owns.
As a side note, Premature optimization is the root of all evil. The state you are storing is built with a few subtractions and divisions, but the pow function your loop sometimes calls may be the part dominating its running time.

I know it are some beefy calculations, for now those cannot be replaced. Luckely this function will not be called twice, once every loop. If one of the variables change then the Iteration starts at -1 again. I did remove the pow function, rather complex for a simple square


text:
Why I could not read the other sms's except the first SMS?
I have to read the incoming SMS on my GSM module SIM900, and I want to print the sender number and message to the serial monitor.
I first configure the GSM module with AT commands and Response() function will give me the response to AT commands.
as any SMS will be in the following pattern
+CMT: "[Mobile number]", "[Date and Time]>"
   [message body]
So, I first extract +CMT and after that I will take mobile number and at last we have message body. The code I have used is
char RcvdMsg[200] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[50];
int MsgLength = 0;

void Config() // This function is configuring our SIM900 module i.e. sending the initial AT commands
{
    delay(1000);
    Serial.print("ATE0\r");
    Response();
    Serial.print("AT\r");
    Response();
    Serial.print("AT+CMGF=1\r");
    Response();
    Serial.print("AT+CNMI=1,2,0,0,0\r");
    Response();
}

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

void loop()
{
  RecSMS();
}

void Response() // Get the Response of each AT Command
{
    int count = 0;
    Serial.println();
    while(1)
    {
        if(Serial.available())
        {
            char data =Serial.read();
            if(data == 'K')
            {
                Serial.println("OK");
                break;
            }
            if(data == 'R')
            {
                Serial.println("GSM Not Working");
                break;
            }
        }
        count++;
        delay(10);
        if(count == 1000)
        {
            Serial.println("GSM not Found");
            break;
        }
    }
}

void RecSMS() // Receiving the SMS and extracting the Sender Mobile number & Message Text
{
    if(Serial.available())
    {
        char data = Serial.read();
        if(data == '+'){RcvdCheck = 1;}
        if((data == 'C') && (RcvdCheck == 1)) {RcvdCheck = 2;}
        if((data == 'M') && (RcvdCheck == 2)) {RcvdCheck = 3;}
        if((data == 'T') && (RcvdCheck == 3)) {RcvdCheck = 4;}
        if(RcvdCheck == 4)
        {
            RcvdConf = 1;
            RcvdCheck = 0;
        }

        if(RcvdConf == 1)
        {
            if(data == '\n'){RcvdEnd++;}
            if(RcvdEnd == 3){RcvdEnd = 0;}
            RcvdMsg[index] = data;

            index++;
            if(RcvdEnd == 2){RcvdConf = 0;MsgLength = index-2;index = 0;}
            if(RcvdConf == 0)
            {
                Serial.print("Mobile Number is: ");
                for(int x = 4;x < 17;x++)
                {
                    MsgMob[x-4] = RcvdMsg[x];
                    Serial.print(MsgMob[x-4]);
                }
                Serial.println();
                Serial.print("Message Text: ");
                for(int x = 46; x < MsgLength; x++)
                {
                    MsgTxt[x-46] = RcvdMsg[x];
                    Serial.print(MsgTxt[x-46]);
                }

                Serial.println();
                Serial.flush();
            }
        }
    }
}

The problem of the code is
After receiving first SMS I am getting my mobile number and message body. After that I am only getting the sender number printed to my serial monitor but not the message body.
Where has it gone wrong. I could not understood.
Please help me.......Thanks in advance.

Can you provide me this code if you found solution for your bug. It will be very important for my college project. Thank you for your support!

It looks like RcvdEnd never gets reset back to zero because RcvdConf is set to zero when RcvdEnd is 2, which means it will never get to 3 and reset it (at least not when you are expecting it to). I'm not sure how many new lines you are supposed to be checking for but the way it is set up now or is looking for two on the first message, and three for every message thereafter. You might want to rework the logic and maybe move where that value gets reset.

             {
                MsgTxt[x-46] = RcvdMsg[x];
                Serial.print(MsgTxt[x-46]);
            }
             RcvdEnd =0;
            Serial.println();
            Serial.flush();

Perhaps you'd like to edit your answer to explain why you think this answers the question.


text:
Can't program Atmega644p over ISP
I am using the Arbotix-M (Atmega644p). I am trying to program it using an ISP from Pololu. Until yesterday, everything seemed to be working okay and we were able to upload to it without problems. However, recently our board intermittently returns the error.

"avrdude: stk_500() initialization failed, rc =-1,
    Double check connections and try again or use -F to override this check"

Most of the other people who get this error appear to have damaged the microcontroller in some way, but our board appears to still be functioning because it can still run the code that is already installed on it. At the moment, it basically always fails to upload, so we aren't able to change the code on the board very easily.
I have checked the voltage outputs from the device and they seem to be right. (12.5 from the main line and 5V from the auxiliary one). I don't have an oscilloscope to check the signals with, but it seems to be able to output commands fine. Thanks for reading.


text:
Arduino Nano with Mac OS Yosemite 10.10
I have an Arduino Nano and I’m trying to use it with Mac OS Yosemite (10.10). However, I’m having issues with the data transfer between the computer and the device. The Arduino is powered (LED is illuminated), however, I can’t upload anything to it. The serial port is not recognised and after installing a multitude of drivers, nothing seems to work.
Is there a specific driver or process I need to follow to enable data transfer?

Is this a genuine Arduino device, or a clone?

It looks like a genuine device, but was very cheap and of poor quality - most likely a clone.

Setting kext-dev-mode=1 allows unsigned kernel extensions to load, which is not recommended, as it lowers OS X security.
Instead, try the signed 64-bit kernel extension from FTDI here: http://www.ftdichip.com/Drivers/VCP.htm , version 2.3, which does require changing OS security permissions.

In theory that one should be much better - but I cannot get it work. It keeps unloading the kext and nothing shows up under /dev. Works for you?

This is only applicable to boards having an FTDI USB serial chip.  It is not needed for boards using an ATmega16u2 and will not help with boards having a CH340/CH341.

From this blogpost you can download signed macOS driver for CH340. Works fine on Sierra 10.12!

Without commenting on the legitimacy of the linked software, it should be noted that a CH340 driver will only work on boards using a CH340 or CH341 - it will not help for boards using an FTDI part or an ATmega16u2.  Blind installation is probably not to be recommended.

I think if this kext is signed by Apple, they trust it, aren't they?

Regardless of who allegedly signed it, that driver will not help anyone who doesn't have a CH340/CH341 or functionally identical adapter.  The actual Arduino Nano uses an FT232RL chip, requiring a different driver (which may well be built in).   The point is to figure out what you have before installing drivers - this can be determined either by reading the part numbers or from the USB tab in system report.


text:
Updating MAX7456 library to work with Arduino 1.6.6
I've got this library for communicating with the MAX7456 chip.
The library is abandoned and the only one I found that actually works, so I'd really like to use it.

It compiles fine with Arduino IDE 1.0.5, but not with Arduino IDE 1.6.6 .
This happens with 1.6.6, I tried to fix it but I only made it worse.
Arduino: 1.6.6 Hourly Build 2015/07/03 10:26 (Linux), Board: "Arduino Nano, ATmega328"

Using library SPI at version 1.0.0 in folder: /home/t/Dropbox/Arduino-IDE/hardware/arduino/avr/libraries/SPI
Using library max7456 in folder: /home/t/Dropbox/Arduino/libraries/max7456 (legacy)

/home/t/Dropbox/Arduino-IDE/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=10606 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR -I/home/t/Dropbox/Arduino-IDE/hardware/arduino/avr/cores/arduino -I/home/t/Dropbox/Arduino-IDE/hardware/arduino/avr/variants/eightanaloginputs -I/home/t/Dropbox/Arduino-IDE/hardware/arduino/avr/libraries/SPI -I/home/t/Dropbox/Arduino/libraries/max7456 /tmp/build4912026784583215357.tmp/sketch/HelloWorld.cpp -o /tmp/build4912026784583215357.tmp/sketch/HelloWorld.cpp.o
In file included from HelloWorld.ino:2:0:
/home/t/Dropbox/Arduino/libraries/max7456/max7456.h:228:40: error: 'prog_uchar' does not name a type
static void getCARACFromProgMem(const prog_uchar *table, byte i,charact c);
                                    ^
/home/t/Dropbox/Arduino/libraries/max7456/max7456.h:228:52: error: ISO C++ forbids declaration of 'table' with no type [-fpermissive]
static void getCARACFromProgMem(const prog_uchar *table, byte i,charact c);
                                                ^
Error compiling.

How would one make the library compatible with 1.6.6?

In the file max7456.h at line 228 change it from:
static void getCARACFromProgMem(const prog_uchar *table, byte i,charact c);

to:
static void getCARACFromProgMem(const char *table, byte i,charact c);

In the file max7456.cpp at line 484 change it from:
void Max7456::getCARACFromProgMem(const prog_uchar *table, byte i, charact car)

to:
void Max7456::getCARACFromProgMem(const char *table, byte i, charact car)

Then it compiles OK (under 1.6.4 at least).

The character map updating code does not work, but that is not a major flaw.


text:
Can I use a 6 pin Bluetooth module in a 4 pin socket?
I have a Funduino joystick shield and it features a 4 pin bluetooth socket in the top right hand corner (just above the D, T, - and + legends).

For some reason, on eBay, 6 pin bluetooth modules are cheaper and more common than 4 pin bluetooth modules.

The joystick shield's 4 pin socket is labelled R T - +. Obviously these correspond with RXD, TXD, GND and VCC on the bluetooth module.
I was wondering:

What is the difference between the 4 pin and 6 pin modules?
Can I use a 6 pin module in the four pin socket on the joystick shield?
What is the function of additional STATE and EN pins on the bluetooth module?
Are these two additional pins necessary as other modules do not have them?

What is the difference between the 4 pin and 6 pin modules?

The 6-pin modules have more pins, used for other features.

Can I use a 6 pin module in the four pin socket on the joystick shield?

I don't see why not, as long as you tie/float the other pins appropriately.

What is the function of additional STATE and EN pins on the bluetooth module?

Whatever the documentation says they do.

Are these two additional pins necessary as other modules do not have them?

Probably not. But they provide additional functionality.

Thanks for the confirmation. Butchering a 6 pin module down to 4 pins certainly seems to be the cheaper option.

Just poked around, and EN is connected to the voltage regulator; pulling it low will shut down the whole module. No idea what STATE does though, since it connects to a GPIO.

After some more concerted searching I have found the answer on Success Using the JY-MCU (linvor) Bluetooth Module:

The module has 6 pins labeled on the back, but most modules only have
  4 of those populated with pogo pins.  KEY & STATE seem to be not
  required, as KEY is used for flashing the device and STATE simply
  indicates if the device is awake or not.  So that leaves only GND,
  VCC, TXD, RXD.  Not shown is Pin 11 which is the RESET pin, resetting
  the module when pulled LOW.

So, the answer is apparently yes, and you can buy a cheaper 6 pin module and remove (snip/desolder) the two additional pins.  The EN pin is also apparently labelled as KEY on some modules.


text:
Building a digital camera?
Does anyone know of a way to DIY a digital camera by buying a sensor and lens and processing the image using an Arduino?

I assume you know that you can purchase a sensor that captures images and libraries exist to process that signal into an image file (such as a .jpg file)? There are tons of tutorials online for this... but maybe you are wanting something specific? Please clarify if so

can you be more specific please? what do you want to build, why don't you use a sensor, as Ben said?

You can buy a camera module for the Arduino, and you can interface it fairly simply.  There are numerous modules around - ask Google, it knows more than me.
But I have yet to work out why people do it.  All you can do with an Uno is to pass the data through to something else like a PC to process the image - so why wouldn't you just use a simple webcam?
The Arduino UNO has 2KB of RAM.  A 24-bit 640x480 image (VGA) requires (640*480*3)/1024 = 900KB to store it in memory.  If you really wanted to process an image on an Uno then you would be limited to (say 8-bit grayscale) 48x32 pixels (1.5KB) which is pretty pointless really.
Even a Due would only allow (again grayscale) around 320x240 (which is better) but nothing colour unless you want to start messing with CLUTs which aren't fun when receiving a truecolour (24-bit) image from a camera.
For this kind of task you are better off with an embedded computer with plenty of RAM such as a Raspberry Pi or maybe a Galileo or something.


text:
Pyserial and Arduino
I am trying to send an integer value from Python to Arduino. The integer value is a position given by a webcam, which will determine how many turns a stepper motor moves.
Arduino:
#include <AccelStepper.h>
AccelStepper stepper(AccelStepper::DRIVER,8,9);

void setup() {
  Serial.begin(9600);
  stepper.setMaxSpeed(1000.0);
  stepper.setAcceleration(700.0);
}

void loop() {
  int val = 0;
  if(Serial.available()){
    val = map(Serial.parseInt(), 0, 1280, 0, 551);
    Serial.println(val);
  }
  stepper.runToNewPosition(val);
}

Python:
# source: http://www.steinm.com/blog/motion-detection-webcam-python-opencv-differential-images/

import cv2
import numpy as np
import serial
import time

def diffImg(t0, t1, t2):
    d1 = cv2.absdiff(t2, t1)
    d2 = cv2.absdiff(t1, t0)
    dif = cv2.bitwise_and(d1, d2)
    return np.fliplr(dif)

cam = cv2.VideoCapture(0)

#winName = "Movement Indicator" #camera window
#cv2.namedWindow(winName, cv2.WINDOW_NORMAL)

# Read three images first:
t_minus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)

h, w = t.shape

winTest = "Test Window" #test window
cv2.namedWindow(winTest, cv2.WINDOW_NORMAL)

thresh = 100

ser=serial.Serial('/dev/cu.usbmodem1411',9600,timeout=0)
time.sleep(2)

while True:

    img = diffImg(t_minus, t, t_plus)

#    cv2.imshow(winName, img )

    nz = np.transpose(np.nonzero(img>thresh))
    a = 0
    b = 0
    c = 0
    d = 0
    avg=0
    if nz.size>0:
        a,b = nz[0]
        c,d = nz[-1]
        avg = (b+d)/2
        if 0<=avg and avg<=1280:
            print avg
            ser.write(str(int(avg))+" ")

    test = np.zeros((h,w))

    cv2.rectangle(test, ((avg-5),a), ((avg+5),c), (255), -1)
    cv2.imshow(winTest, test )

    # Read next image
    t_minus = t
    t = t_plus
    t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
    print ser.readline();

    key = cv2.waitKey(10)
    if key == 27:
       cv2.destroyWindow(winName)
       ser.close()
       break

print "Goodbye"

This works OK but occasionally 'val' will take some ridiculous value, say 7182, and the motor spins out of control. I realize I can check values with an if statement before I actually write to the stepper motor, but I think my problem is with reading and writing to the Arduino.
My other issue is I feel Arduino is not receiving some of the data sent to it via serial connection. This is hard to say, as Serial.print() is slow and mostly doesn't make it through to my terminal before it's already been rewritten.

Serial.print() is slow - try a faster baud rate, like 115200?

Mr Gammon's comment about using a faster baud rate is an excellent idea.
You also seem to be sending the number as a string.  Sending the integer as binary data (using python's struct module) would also reduce the amount of data that needs to be sent - significantly for larger numbers.
import struct

...

ser.write(struct.pack('I',int(avg)))

On the Arduino Side
uint8_t buffer[4];
uint32_t position;

if (my_serial.read(buffer, sizeof(uint32_t)) == sizeof(uint32_t))
    memcpy(&position, buffer, sizeof(uint32_t));

// alternatively in one step, without error checking
my_serial.read(&position, sizeof(uint32_t));

This assumes a 32-bit integer is needed.
Maybe you only need an unsigned short - this would halve the amount needed to transmit.


text:
Bluetooth connection and RX ,TX
I have connected a RN-42 bluetooth (TX-D0, RX-D1, VCC-5V, GND_GND) to arduino.The problem is that when I run this code ,nothing happens it just upload to infinite or it doesn't. I am checking with tera term. Is there a problem with the connection of the pins? Also when I pair my android phone to the bluetooth it says paired on the phone but the blue light of the bluetooth doesn't switch on, like it's not connected.
  #include <SoftwareSerial.h>// import the serial library
   SoftwareSerial Genotronex(1, 0); // TX,RX
   int ledpin=13; // led on D13 will show blink on / off
   int BluetoothData; // the data given from Computer

  void setup() {
  // put your setup code here, to run once:
   Genotronex.begin(9600);
   Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
   pinMode(ledpin,OUTPUT);
  }

  void loop() {
    // put your main code here, to run repeatedly:
  if (Genotronex.available()){
     BluetoothData=Genotronex.read();
   if(BluetoothData=='1'){   // if number 1 pressed ....
  digitalWrite(ledpin,1);
  Genotronex.println("LED  On D13 ON ! ");
   }
  if (BluetoothData=='0'){// if number 0 pressed ....
   digitalWrite(ledpin,0);
   Genotronex.println("LED  On D13 Off ! ");
   }
}
   delay(100);// prepare for next data ...
 }

There is no need to use software serial on the hardware UART, the D0 and D1 pins are for communication with the PC, in line with what Owen answered try his suggestion.

Are you sure that the bluetooth module is already connected/paired correctly? Is your bluetooth module in master or slave mode?

VCC to 3.3V? https://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-42-ds.pdf

As commenter by RSM
The issue you are facing is because you are using pins 0 and 1
These are used by the arduino for uart.
So for starters please use any pin other that 0 and 1.  But if you insist that you do need to use these pins,  then you don't need softwareserial you can use the default serial itself, but you will need to disconnect the bluetooth while programming.

If you use RX, and TX in default pin then it is not necessary that you should include SoftwareSerial library.

The simplest solution to this is to just unplug the Bluetooth module from the TX and RX ports and click to upload. Your sketch will be uploaded and you can plug the pins back.
For a permanent solution use the digital pins aside 1 and 0 because they are the same pins your computer uses to upload your sketch to the Arduino board.

Try taking off the bluetooth module, this will allow communication with
the computer, not the bluetooth module. I had the same problems with my
hc-06, and have not solved the ladder yet.


text:
What are the connectors used in the arduino mega?
I am trying to build a shield for an arduino mega.For that i need to know the type of the female connectors that are soldered in the pins of the arduino mega in order to choose the correct male connectors.

What kind of shield are you trying to build? Have you looked at the Arduino documentation...? Take a look! Mega link

Those are standard 0.1inch female/male headers.

I looke for sure but couldn't find anything about mechanical design

Look for male pin header strip, with 0.1 inch (2.54mm) pitch.
In single and dual row form.
Specifically they are:

8x1 ADCL
8x1 ADCH
8x1 PWML
8x1 PWMH
8x1 Communication
6x1 Power
18x2   digital IO (on the side)

Source: Schematics