text:
Why is my "mood cue" not working?
I am new to Arduino, and I am working through the "Arduino Projects book," with the Arduino Uno. I am working on project 5, "the mood cue." It is basically a potentiometer-controlled servo. I am certain that I have the code for it correct, and certain that I have all the wiring correct. I have the potentiometer value and the angle at which the potentiometer is turned printed on the serial monitor.
I upload the code, and the serial monitor begins printing correctly, changing when I twist the potentiometer. But the servo doesn't move. It lets off a faint buzzing sound, and that is it.
Does anyone know what the problem is? I don't know what I have done wrong. Do you think my servo is broken?
Here is my code:
#include <Servo.h>
Servo myServo;
int const potPin = A0;
int potVal;
int angle;

void setup() {
  myServo. attach(9);
  Serial.begin (9600);
}

void loop() {
  potVal = analogRead(potPin);
  Serial.print ("potVal:");
  Serial.print (potVal);
  angle = map(potVal, 0, 1023, 0, 179);
  Serial.print ("angle:");
  Serial.print (angle);
  myServo.write (angle);
  delay(15);
}

Here is my wiring:
file:///C:/Users/matth_000/Downloads/Arduino%20PotServ.jpg

Maybe you have your servo wired wrong.  Please post a photograph of your setup.

Buzzing, non-moving motors usually means not enough voltage and/or current.

file:///C:/Users/matth_000/Downloads/Arduino%20PotServ.jpg
is not gonna help much...

The classic way of wiring up motors, including servos, is to provide them with separate power. The image below should clarify this:

The batteries (in this case) have the sole function of providing power to the servo motor. The "data" pin however goes to the Arduino.
The Arduino itself is powered by the USB cable in this example.
The important point is the blue wire - the shared ground wire. Both the Arduino and the servo (and batteries) must have a common ground.

If you're using the components that came in the starter kit, the servo is wired differently in the book than it is in the actual kit.
Make sure the red wire on the servo is connected to the power, the black to the ground and the white to the data. The specs are also written on the side of the servo motor.
In the project book, the wires went into these rows on the breadboard:

GND
5V
Signal

Whereas for me that meant it was:

GND
Signal
5V

Hope this helps!

I'm new to arduino and I had the same problem of the servo buzzing but not moving.  I found the reason was the servo wires came in a different order than what was written in the book.  After correctly connecting the 5v, GND, and Signal by moving a few wires on the bread board things worked as planed.  Hoped this helps.

At first, I had similar behavior with the servo motor in this project. The servo buzzed and either did not move or made very slight erratic movements.
The problem in my case was that I had wrongly placed the wire that is supposed to connect the potentiometer to pin A0.
Here's how my board looked after I corrected the problem:

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


text:
Error in code saying "expected primary expression before "<" token" and other errors
I am Creating a laptop controlled robot using an arduino nano using the instructbles. I have tried running the code but it is throwing back lots off error and the main one is "expected primary expression before "<" token"
as well as various other error. if anyone could take a look and try help me out i would be grateful thank you!
#include <NewPing.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 8, 7, 4, 3, 2);
float temp =1;
int temppin = A0;
int r_motor_n = 9; //PWM control Right Motor +
int r_motor_p = 10; //PWM control Right Motor -
int l_motor_p = 6; //PWM control Left Motor -
int l_motor_n = 5; //PWM control Left Motor +
int f_light = A3;
int b_light = A4;
int horn = 12;
int n_light = 13;
int speedy = 255;
int incomingByte = 0; // for incoming serial data
#define TRIGGER A2 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO A1 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER, ECHO, MAX); // NewPing setup of pins and maximum distance.
void setup()
{
pinMode(r_motor_n, OUTPUT); //Set control pins to be outputs
pinMode(r_motor_p, OUTPUT);
pinMode(l_motor_p, OUTPUT);
pinMode(l_motor_n, OUTPUT);
pinMode(f_light, OUTPUT);
pinMode(b_light, OUTPUT);
pinMode(n_light, OUTPUT);
pinMode(horn, OUTPUT);
digitalWrite(r_motor_n, LOW); //set both motors off for start-up
digitalWrite(r_motor_p, LOW);
digitalWrite(l_motor_p, LOW);
digitalWrite(l_motor_n, LOW);
Serial.begin(9600);
Serial.println("Start");
lcd.begin(16,2);
lcd.clear();
lcd.print("     Hello      ");
lcd.setCursor(0,1);
lcd.print("   I'm Robot   ");
delay(3000);
}
void loop()
{</liquidcrystal.h></newping.h>

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

switch(incomingByte)
{

case 'S': // control to stop the robot
digitalWrite(r_motor_n, LOW);
digitalWrite(r_motor_p, LOW);
digitalWrite(l_motor_p, LOW);
digitalWrite(l_motor_n, LOW);
Serial.println("Stop");
lcd.clear();
lcd.print("Stop");
incomingByte='*';
break;

case 'R': //control for right
analogWrite(r_motor_n, speedy);
digitalWrite(r_motor_p, LOW);
analogWrite(l_motor_p, speedy);
digitalWrite(l_motor_n, LOW);
Serial.println("right");
lcd.clear();
lcd.print("Right");
incomingByte='*';
break;

case 'L': //control for left
digitalWrite(r_motor_n, LOW);
analogWrite(r_motor_p, speedy);
digitalWrite(l_motor_p, LOW);
analogWrite(l_motor_n, speedy);
Serial.println("left");
lcd.clear();
lcd.print("Left");
incomingByte='*';
break;

case 'F': //control for forward
analogWrite(r_motor_n, speedy);
digitalWrite(r_motor_p, LOW);
digitalWrite(l_motor_p, LOW);
analogWrite(l_motor_n, speedy);
Serial.println("forward");
lcd.clear();
lcd.print("Forward");
incomingByte='*';
break;

case 'B': //control for backward
digitalWrite(r_motor_n, LOW);
analogWrite(r_motor_p, speedy);
analogWrite(l_motor_p, speedy);
digitalWrite(l_motor_n, LOW);
Serial.println("backwards");
lcd.clear();
lcd.print("Backward");
incomingByte='*';
break;

case 'f': //control for stop
digitalWrite(r_motor_n, LOW);
digitalWrite(r_motor_p, LOW);
digitalWrite(l_motor_p, LOW);
digitalWrite(l_motor_n, LOW);
Serial.println("Stop");
lcd.clear();
lcd.print("Stop");
incomingByte='*';
break;

case 'd': // control for right
analogWrite(r_motor_n, speedy);
digitalWrite(r_motor_p, LOW);
analogWrite(l_motor_p, speedy);
digitalWrite(l_motor_n, LOW);
Serial.println("right");
lcd.clear();
lcd.print("Right");
incomingByte='*';
break;

case 'a': // control for left
digitalWrite(r_motor_n, LOW);
analogWrite(r_motor_p, speedy);
digitalWrite(l_motor_p, LOW);
analogWrite(l_motor_n, speedy);
Serial.println("left");
lcd.clear();
lcd.print("Left");
incomingByte='*';
break;

case 'w': // control for forward
analogWrite(r_motor_n, speedy);
digitalWrite(r_motor_p, LOW);
digitalWrite(l_motor_p, LOW);
analogWrite(l_motor_n, speedy);
Serial.println("forward");
lcd.clear();
lcd.print("Forward");
incomingByte='*';
break;

case 's': // control for backward
digitalWrite(r_motor_n, LOW);
analogWrite(r_motor_p, speedy);
analogWrite(l_motor_p, speedy);
digitalWrite(l_motor_n, LOW);
Serial.println("backwards");
lcd.clear();
lcd.print("Backward");
incomingByte='*';
break;

case 'J': // front lights on
digitalWrite(f_light, HIGH);
Serial.println("front lights on");
incomingByte='*';
break;

case 'j':
digitalWrite(f_light, LOW); // off
Serial.println("front lights off");
incomingByte='*';
break;

case 'K':
digitalWrite(b_light, HIGH); // back lights on
Serial.println("back lights on");
incomingByte='*';
break;

case 'k':
digitalWrite(b_light, LOW); // off
Serial.println("back lights off");
incomingByte='*';
break;

case 'G':
digitalWrite(n_light, HIGH); // neon lights on
Serial.println("neon lights on");
incomingByte='*';
break;

case 'g':
digitalWrite(n_light, LOW); off
Serial.println("neon lights off");
incomingByte='*';
break;

case 'H':
digitalWrite(horn, HIGH); // horn on
Serial.println("horn on");
incomingByte='*';
break;

case 'h':
digitalWrite(horn, LOW); off
Serial.println("horn off");
incomingByte='*';
break;

case 'O': // PWM speed values
speedy = 0 ;
Serial.println("speed= 0");
lcd.clear();
lcd.print("Speed=0");
incomingByte='*';
break;

case '1':
speedy = 155;
Serial.println("speed= 10");
lcd.clear();
lcd.print("Speed=10");
incomingByte='*';
break;

case '2':
speedy = 165;
Serial.println("speed= 20");
lcd.clear();
lcd.print("Speed=20");
incomingByte='*';
break;

case '3':
speedy = 175;
Serial.println("speed= 30");
lcd.clear();
lcd.print("Speed =30");
incomingByte='*';
break;

case '4':
speedy = 185;
Serial.println("speed= 40");
lcd.clear();
lcd.print("Speed=40");
incomingByte='*';
break;

case '5':
speedy = 195;
Serial.println("speed= 50");
lcd.clear();
lcd.print("Speed=50");
incomingByte='*';
break;

case '6':
speedy = 205;
Serial.println("speed= 60");
lcd.clear();
lcd.print("Speed=60");
incomingByte='*';
break;

case '7':
speedy = 215;
Serial.println("speed= 70");
lcd.clear();
lcd.print("Speed=70");
incomingByte='*';
break;

case '8':
speedy = 225;
Serial.println("speed= 80");
lcd.clear();
lcd.print("Speed=80");
incomingByte='*';
break;

case '9':
speedy = 235;
Serial.println("speed= 90");
lcd.clear();
lcd.print("Speed=90");
incomingByte='*';
break;

case 'q':
speedy = 255;
Serial.println("speed= 100");
lcd.clear();
lcd.print("Speed=100");
incomingByte='*';
break;

case 'p':
delay(50);  // display temp. and distance
unsigned int uS = sonar.ping();
Serial.print("Distance: ");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println("cm");
lcd.clear();
lcd.print("Distance: ");
lcd.print(uS / US_ROUNDTRIP_CM);
lcd.print("cm");
lcd.setCursor(0,1);
temp = analogRead(temppin);
temp = temp * 0.48828125;
Serial.print("Temperature = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
lcd.print("Temp. = ");
lcd.print(temp);
lcd.print("*C");
delay(1000);
incomingByte='*';
break;

delay(5000);
}
}

Did you bother reading the code you copied from this site? It seems not. Just a quick browse will reveal some HTML in the middle of it (
...) This is wrong on the instructable site, so you have to clean up the code by yourself.

your code is ridden with html tags, like

 or </liquidcrystal.h></newping.h>
Try removing them all, but it would be better if you could copy it from a plain ASCII source.
And when reporting a compiler bug, it's always good to paste it exactly as it is shown (it would have listed also line and possibly column where the error was detected)

It's like that on the Instructables site. Sigh. Laptop Controlled Robot v2.0

source: Stack Exchange

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

sort: votes


text:
How can I reference an object from another file?
I am trying to write some code to make it easy to add different buttons to a touch screen. I need each object to be a different object of class 'touchButton'. I'd like to be able to run a touchButton.Draw function, which in turn will run LCD library commands. Is there a way I could do that? Here is my source code:
TouchScreen.ino:
#include "touchButton.h"
#include <UTFT.h>
#include <UTouch.h>
#include <avr/pgmspace.h>
UTFT    myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch  myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  myGLCD.clrScr();
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  myGLCD.fillScr(51, 51, 51);
  //what I want to be able to do:
  //touchButton Button1 (10, 10, 20, 20, 'p');
  //Button1.Draw();
}

void loop() {
}

touchButton.h
#ifndef touchButton_h
#define touchButton_h
#include "Arduino.h"
class touchButton {
  public:
    touchButton(int x, int y, int xs, int ys, char use);
    void Draw();
    int x1;
    int y1;
    int xsize;
    int ysize;
    char use;
    boolean toggle = false;
};
#endif

touchButton.cpp
  #include "Arduino.h"
  #include "touchButton.h"
  touchButton::touchButton(int x, int y, int xs, int ys, char myuse) {
    x1 = x;
    y1 = y;
    xsize = xs;
    ysize = ys;
    use = myuse;
  }

  void touchButton::Draw() {
    switch (use) {
      case 'p':
      //this is what I would like to have called from the main file.
      //myGLCD.drawRoundRect(x1, y1, x1+xsize, y1+ysize);
        break;

       default:
        break;
    }
  }

The best way is to provide the myGLCD object as a parameter to the constructor:
touchButton::touchButton(UTFT &glcddev, int x, int y, int xs, int ys, char myuse) {
  x1 = x;
  y1 = y;
  xsize = xs;
  ysize = ys;
  use = myuse;
  glcd = &glcddev;
}

Then in your header you provide a:
private:
  UTFT *glcd;

Your library code then uses the glcd pointer to the object:
glcd->drawRoundedRectangle(...);

Note the use of -> since glcd is a pointer to the object (as created by the & operator when it was assigned in the constructor).
Of course, as Miagma mentions, you need to ensure that anywhere that references any UTFT functions or objects has the UTFT.h header included or it won't know what you're talking about.
You can also do the same with the UTouch class - pass that object as a parameter, then each widget can have its own routine to deal with the touch events.
You can see all this kind of thing in action in the same context in the Widget class of my DisplayCore system for chipKIT boards:

https://github.com/MajenkoLibraries/DisplayCore/blob/master/DisplayCore/DisplayCore.h#L464
https://github.com/MajenkoLibraries/DisplayCore/blob/master/DisplayCore/DisplayCore.cpp#L1587

The simplest solution (ignoring possible improvements) is to add the following to touchButton.cpp.
#include "Arduino.h"
#include "touchButton.h"

// Extern reference to the LCD instance
#include <UTFT.h>
extern UTFT myGLCD;

touchButton::touchButton(int x, int y, int xs, int ys, char myuse) {
  x1 = x;
  y1 = y;
  xsize = xs;
  ysize = ys;
  use = myuse;
}

void touchButton::Draw() {
  switch (use) {
    case 'p':
      myGLCD.drawRoundRect(x1, y1, x1+xsize, y1+ysize);
    break;

   default:
    break;
  }
}

There are several improvements such as passing the UTFT instance reference as parameter, moving myGLCD to a separate .h/.cpp file, etc.
An example of "extern" object reference may be found in HardwareSerial.h.
Cheers!

I'm not 100% certain I understand what you mean. It's clear that you understand object-oriented code and some of the murkier aspects of c++, judging from what you wrote.
I apologize if you already know this (and I'm guessing you do) or if this is completely off base, but your code should already work. That is, you defined your class in your header, implemented it in the .cpp file, and then instantiated it in the .ino file. If you want to operate on it in another file, you could declare the variable as an "extern" data type, which is rather dangerous, or pass it as a reference to a function in another file.
However, I don't believe this is what you mean. From reading your code, I feel that you're asking how you can execute function "x" from another object every time you create a button.
If this is the case, it's definitely possible. myGLCD looks like it's an object (can't read it at the moment), which is good. What you can do is declare your touchLCD class as a derived class of whomever myGLCD belongs to -adding the appropriate header of course:
#include <Parent Class Name.h>

class touchLCD : public <Parent Class Name>.

If the functions you want are public or protected, then you can access them without restriction. Here you have a few options. The easiest would probably be calling the function from within the constructor. If you don't have access to the desired function, you'll have to define your class as a friend class.
Hope this helps.

You are asking a question that can be considered as the classical:
"is a" vs. "has a"
If you want, you can find more details here.
On this specific case, I sort of agree with Majenko, that proposes to pass the address of the LCD object to each button, but I would prefer a different implementation where the pointer is stored in a static field shared by all the instances of touchButton, because you are always referring to the same object. That will of course change if you have more than 1 LCD.

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


text:
Arduino sketch behaves differently depending on version of Arduino IDE
I am assisting some friends on an Arduino Uno project, and we've noticed that when using some earlier versions of the Arduino IDE (In this case 1.0.5), the sketch behaves as desired. However, when using 1.6.5, the program behaves differently. The sketch in question is here:
https://github.com/CymaSpace/Programs---Sketches/tree/master/Tim%20Gorbunov/a3%20with%20monosetting/a3
I have noticed that when enabling verbose compilation output, the size of the compiled binary is different between the two different IDE versions. There are also some warnings in the older IDE that are not present in the newer version. There is at least one other version before 1.6.5 that is behaving the same way as 1.0.5 (it's a later version but at the moment I don't know which, I will see if I can find out and post it here later).
Any idea why the two sketches might be behaving differently and how to go about troubleshooting the problem? This occurred on both a windows and mac computer. Thanks!

Because they're using different versions of the compiler.

@IgnacioVazquez-Abrams Is there a way to rectify the differences or at the very least to figure out what has changed between the two compiled sketches?

You can use avr-objdump to disassemble the compiled binaries.

Could you be more specific about how the behaviors differ? Maybe you can pinpoint the specific function that is behaving differently? You could try to disassemble and look for the differences, or upload the ELF files somewhere to get help on this.

The sketch is intended to display colors on a strip of WS2812b's based on sound input from two MSGEQ7's. In the older version, the animations stop when there is no more audio input. In the new version, the animations continue even if there is no input coming in. This is somewhat of a simplified explanation. I'm thinking that the code likely needs to be refactored, as there are a few flaws that were pointed out that could be making the sketch behave erratically. After refactoring the code, I will retest it and if it's still having problems, I'll upload the ELF files and disassemble the binaries

There are also some warnings in the older IDE that are not present in
  the newer version.

It is a huge mistake to disregards those warnings, especially:

warning: array subscript is above array bounds

You declared an array int useColor[2]. Its length is 2 and its indices
can be either 0 or 1. Yet you are using useColor[2], which is out of
bounds and likely to corrupt memory.
From the language point of view, this is called undefined behavior,
which means that anything can happen. In particular, it could very
well happen that the program behaves as you expect... which seems to be
the case with IDE 1.0.5. Simply changing the compiler version, or event
the compiler settings, can change the behavior.

Good point. I think the best thing to do at this point might be to revisit the code, clean it up, resolve any errors, and make sure there isn't any undefined behavior. It might be a waste of time to compare the binaries if the code has inherent problems. I'm going to try to refactor some of it and see if the discrepancy still exists. Thanks for the tips and for catching that array out of bounds problem!

@Hendeca: I tried some minimal cleanup on your code. Check your github repo for the pull request.

Thanks very much! Very helpful. We will test this out and keep refactoring from there. Also, this is collaborative and I was unaware that this is an earlier version of the code. I'll edit the question to point to the new version of the code. I will likely just do the same changes you made in your pull request to the newer sketch. If you so desire, feel free to put in another pull request on the new sketch. Sorry about the confusion and thanks again for your help, it's much appreciated!

The original code was contributed to by many different people over a long period of time. I went through and completely refactored and cleaned up the code. It now works and I believe that the array out of bounds problem was likely the culprit. To me it explains most reasonably why it would behave so different between two different compilations on different versions of the Arduino IDE. Accepting this as the correct answer. Thanks!


text:
Outlet switcher using servo motor
I am building a small-scale watering system to water my plants, controlled by Arduino. I have designed most of the project except for how to switch water between multiple pipes.
A little more background:
I want to be able to use a servo motor to control the amount of water that is sent to each plant (based on pot size and plant type). The motor needs to be able to switch input (a 1/2 inch pipe carrying water) to a set of outputs (similarly sized pipes all going to different plants). I am not able to find something off the shelf that does this. So, I am about to 3D print something. Is there something available that I can use instead?

A typical hobby servo may not have enough torque. Try searching for 'miniature rotary valve' or 'miniature solenoid valve'.

Pressure tight valving is tricky.  If you can locate your selector above the targets, you might be able to make gravity feed, open-to-atmosphere system following a single pressure value where some sort of rotary diverter channel would direct the stream of water into the end of any one of a number of open-ended hoses (maybe with little funnels?) placed around the perimeter and leading from there to the various plants.  Hopefully you are doing this over a concrete floor with a drain..

As JRobert mentioned in a comment, you could use a solenoid valve, some of which you can get for about $5.
If you want to water one line at a time, get Normally Closed, one per line. Naturally, since most of them are 12v DC, you can't directly power them from your Arduino. You'll need some power transistors or some relays, and a 12v supply capable of steadily powering the solenoid.

To me it would seem simpler to use a faucet for each line, each faucet controlled by a motor.
Then you can even water the plants in parallel.
Even better, why not using submersion pumps, like those used in water tanks? Here too, you can control them in parallel.
The amount of time you keep a motor running is proportional tothe amount of water delivered.

Yes, this is simpler but also not very cost effective and does not scale well. Since, I have to buy one faucet motor (a solenoid valve) per plant and separate wiring for it in my circuit board. This is why I was looking at a servo motor to switch between multiple output lines for water.

Ok, then there is a solution that is even simpler and definitely cheaper: just connect all the pipes together and, for each pipe, on the ending for the vase, apply a sort of cork with a hole of custom size.
Of course it's not exactly programmable, but you can easily swap corks.
It scales indefinitely and you need 1 single master actuator/tap.


text:
How do I add additional compiler switches in Visual Studio
Using Visual Studio to program my Arduino. I want to add additional compiler switches and include paths.
How can this be done?

Use the ExtraFlags in the project properties. The flags can be specified for the currently selected configuration or for all builds of the current project.
The feature was released in the 15.06 version of the Visual Micro Arduino plugin for Visual Studio.
This guide shows how to access the project properties


text:
Is it possible to see a graphical view of digital and analog pin values?
Using Visual Studio for my Arduino project I am struggling to know the states of various pins during operation.
I do use the Visual Micro debugger but I don't want to have to set a watch for every pin.
How can this be done easily?

Visual Micro provides this for you if you have the debug module enabled. It also optionally shows analog, memory and i2c. Read more about Arduino debug and the digital pin viewer

The Arduino Dashboard project sounds promising but quite likely it loops through the I/O pins periodically and uploads the results to your PC. I'm guessing you want live monitoring (as opposed to snapshots) while your own program (not the Dashboard sketch) is running. In that case, you'd need to isolate the relevant parts of the Dashboard sketch and integrate them with your code, and unless your are looking for fairly low frequency signal changes, have a timer interrupt function that runs the Dashboard frequently, which will have an impact on your own code. If the signals are fairly low frequency you might get away with putting a call to Dashboard in your loop() function instead of running it from a timer interrupt. If you're looking for program bugs that are changing your outputs, once per loop() may be fairly useless. A timer-interrupt would be necessary, and might have to analyze the stack and output the names or addresses of functions that had run recently. At that point you'd be on your way to implementing a debuggerand may want to consider an in-circuit emulator or a bus analyzer to capture the event. Or get smarter about isolating the code responsible for the event until you have a manageable, printf-debuggable code segment.


text:
Arduino WiFi shield working intermittently, "WiFi Shield not present"
I am trying to use the official arduino wifi shield, It works occasionally, but most of the time (when running the WiFi web server example code, or my derivitave program, it outputs WiFi shield not present on the terminal. I have tried updating the firmware several times, but it has not fixed the problem. Is the wifi shield always this unreliable? What can I do to fix it?

Are you using a Uno rev3? See https://www.arduino.cc/en/Main/arduinoBoardUno for differences between Revs-1/2/3

yes, I got an r3 Uno just for use with this project (although I also got it intermittently working with an r2 uno (using wires to compensate for missing pins, before the firmware update).

also, it seems to be getting worse, I haven't been able to get it to detect the shield at all for the last hour :(

Ok, what are you powering the setup from? The other main possibility I can think of is that the WiFi shield is drawing too much power for your USB port (some PCs can limit to 100mA). You could try a wall adapter.

I am using a USB port, but it was able to power a 60 LED strip with the arduino, It also does not work with a wall adapter. Could the LED strip (of which I intended only a few LEDs are lit (but all of which briefly lit accidentally) at a time have damaged the wifi module?

How did you wire the LED strip? If it was in series it would explain a lot, and the WiFi could possibly have received to much current.

I connected the led strip's Power to the arduino's Vin and Ground. It is the led strip here https://www.sparkfun.com/products/12021 .

Let us continue this discussion in chat.

It seems to not be letting me post in the chat :( (it say you must be logged in (which I obviously am))

It's because of your low reputation. Don't worry about it, a mod will probably clean this up later.

I'm running out of ideas. The next thing I'd try is taking a multimeter to the pins and checking each one is making a good connection. Give the boards a gentle shake between tests to see if it's intermittent.

ok, I will try that. so you don't think that connecting the LEDs to Vin for power would harm it?

the multimeter shows that the pins are connected, shaking the boards did not help.

Connecting the LEDs to Vin while powered from the USB is not good.  You are feeding power backwards through the 5V regulator.  You should be running the LEDs from the +5V pin of the Arduino.

I'm afraid I'm out of ideas. I'll take a look at the software and library and see if anything jumps out, but I think you need someone with more experience of the shield.

@Majenko, thanks for the warning, I intended to be using the Vin while powering the arduino and leds from a 7V wall adapter, and meant to (but forgot) switch it to the +5V pin when using usb. Do you think that could have damaged the wifi shield? How much power can the 5V regulator output? Could I leave the LEDs on the 5V pin all the time?

@ForgeMonkey, thanks for your help anyway :) .

@PatrickL It won't have damaged the WiFi shield, no.  The 5V regulator has a limit of 800mA, though the lack of proper heatsinking limits it to around 500mA before it gets too hot.

@Majenko, The 800 (or 500 unheatsinked) mA limit of the regulator is why I used the Vin pin, my power source can provide 7V at 2 Amps, which is enough to power half of the LED strip at full brightness white, or more of it when not full brightness or white. Although I suppose I should use the 5V pin (and limit the number of lit LEDs) when connected to the USB port.

There is another limit, which is the diode that is inline with the barrel jack.  That typically has a 1A limit, as do the physical pin connectors of the headers.  To power more than that you should run your LEDs direct from the 7V supply external to the arduino.

@Majenko Ah, I guess I need to rethink more of the design of this project then. :(

Be sure the shield is not shorting out on the metal USB socket on the Arduino board. I don't know if this is still an issue but I've seen many Arduino boards with black electric tape on the top of the USB socket to insulate it from shorting out the shield.


text:
rfid_default_keys check with RC522
I just received a RC522 board and since i am new to RFID, I tried out some examples from "Arduino RFID Library for MFRC522". Here's one of them
rfid_default_keys
/*
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * Example sketch/program which will try the most used default keys listed in
 * https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys to dump the
 * block 0 of a MIFARE RFID card using a RFID-RC522 reader.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          10          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

// Number of known default keys (hard-coded)
// NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
#define NR_KNOWN_KEYS   8
// Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] =  {
    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
    {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
    {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
    {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
    {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
    {0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
    {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}  // 00 00 00 00 00 00
};

/*
 * Initialize.
 */
void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card
    Serial.println(F("Try the most used default keys to print block 0 of a MIFARE PICC."));
}

/*
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

/*
 * Try using the PICC (the tag/card) with the given key to access block 0.
 * On success, it will show the key details, and dump the block data on Serial.
 *
 * @return true when the given key worked, false otherwise.
 */
boolean try_key(MFRC522::MIFARE_Key *key)
{
    boolean result = false;
    byte buffer[18];
    byte block = 0;
    byte status;

    // Serial.println(F("Authenticating using key A..."));
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("PCD_Authenticate() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
        return false;
    }

    // Read block
    byte byteCount = sizeof(buffer);
    status = mfrc522.MIFARE_Read(block, buffer, &byteCount);
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("MIFARE_Read() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
    }
    else {
        // Successful read
        result = true;
        Serial.print(F("Success with key:"));
        dump_byte_array((*key).keyByte, MFRC522::MF_KEY_SIZE);
        Serial.println();
        // Dump block data
        Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":"));
        dump_byte_array(buffer, 16);
        Serial.println();
    }
    Serial.println();

    mfrc522.PICC_HaltA();       // Halt PICC
    mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
    return result;
}

/*
 * Main loop.
 */
void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    // Show some details of the PICC (that is: the tag/card)
    Serial.print(F("Card UID:"));
    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println();
    Serial.print(F("PICC type: "));
    byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    Serial.println(mfrc522.PICC_GetTypeName(piccType));

    // Try the known default keys
    MFRC522::MIFARE_Key key;
    for (byte k = 0; k < NR_KNOWN_KEYS; k++) {
        // Copy the known key into the MIFARE_Key structure
        for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) {
            key.keyByte[i] = knownKeys[k][i];
        }
        // Try the key
        if (try_key(&key)) {
            // Found and reported on the key and block,
            // no need to try other keys for this PICC
            break;
        }
    }
}

So i modified the code to see exactly what is happening there and here is my output:

Everything looks fine, right ?
So i tried to modify it again by adding some more stuff to the knownKeys array
but it looks like that only the first key is used in the actual authentication.
Here's an output for the same card but i moved {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},  // FF FF FF FF FF FF = factory default to the end of that array.

So.. as you can see even if it used the right key, nothing happened.
For the solution i tried few things but without a success. Thanks in advance for answering.

Call:
if ( ! mfrc522.PICC_IsNewCardPresent()) return false;
if ( ! mfrc522.PICC_ReadCardSerial()) return false;

before every re-authenticate.

According to NXPs application note (AN1304) regarding MIFARE CLASSIC cards (page 24/25):

Each time an Authentication operation, a Read operation or a Write operation fails, the MIFARE Classic or MIFARE Plus remains silent and it does not respond anymore to any commands. In this situation in order to continue the NDEF Detection Procedure the MIFARE Classic or MIFARE Plus needs to be re-activated and selected.

PICC_IsNewCardPresent resets modulation parameters and performs RequestA - activates the PICC (Card).
PICC_ReadCardSerial basically just performs Select - with anti-collision algorithm.

In case there are multiple cards present it would be better to manually call mfrc522.PICC_Select(&mfrc522.uid, mfrc522.uid.size * 8), the second argument tells it that you already know all of the bits for UID, thus it will select the same PICC that was selected previously.

Based on some experimenting, I believe the 1st key is skipped for one of two reasons:

If you follow the code flow, in loop(), PICC_IsNewCardPresent() and PICC_ReadCardSerial() called. If a "new" card/tag is present, then try_key() is called which calls PICC_IsNewCardPresent() [and PICC_ReadCardSerial()] again. Since the card/tag is not "new", PICC_IsNewCardPresent() returns false.
   or
It appears that if the correct key is the default of all 0xFF's, then a call to PCD_Authenticate() will fail.

I'm still working a new version of rfid_default_keys to fix the problem.

If called:
if ( ! mfrc522.PICC_IsNewCardPresent()) return false;
if ( ! mfrc522.PICC_ReadCardSerial()) return false;

before every re-authenticate.
You will skip the FIRST item in array knownKeys
so you will never test the default key FF FF FF FF FF FF.


text:
How to reverse BLDC motor using programming arduino?
I bought ESC from here but it rotates motor in one direction only.
Is there any program which will control direction of rotation clockwise or anticlockwise with same wire configuration.

I don't know - that page won't load.  If the ESC has a direction input then you need to control that with an IO pin.  If no, then it's probably not possible.

R/C Hobby ESC's come in unidirectional (for aircraft) and bidirectional (for surface vehicles) versions.  If you have the latter and configure the throttle ranges correctly, part of the PWM range will be reverse.   But you may not be out of luck even with the former, as many ESC's are built in common ways around ATmega or SiLabs chips for which open source replacement firmwares have been published, and these typical have a bidirectional option.

If above link does not work it is the RS695 unit here. With same leads, maybe no. If you use a DPDT relay (double pile changeover) to swap 2 leads it will usually reverse direction.

Manual here - not helpful in this case, alas.

If you mean the FUFEI-12A, a web search shows several hits implying people have put the popular "simonk" firmware on that, and there are versions of that online which have been modified with reversing.  So the goal seems achievable, the question is if it would be more expedient to just buy a small car ESC.  I'd be very hesitant to use a relay, both given the currents involved and that the ESC may really, really dislike having the windings interchanged when it is even slightly active, so careful locking out will be required.


text:
DIY Watering - Required components
I am looking as a first project after some simple project kits, to make a watering system for my indoor plants. I have seen  a few projects on instructables, so I went to look for components. I am not sure how to power the pump from the Arduino.
My idea is the following:
A bucket of water with a water pump inside. An irrigation system linked to the pump, which then goes to all the plants. The pump linked to arduino which turns it on and off based on a timer.
The components that I will be using are an Arduino uno and:

DV12 subversive pump
Irrigation watering kit

Also I guess I will need some tube to connect the pump to the watering kit.
I am not sure how to connect and power the pump (12V) with the arduino. The arduino it self will be powered by a USB on a wall socket.

Use an external 12V power supply and switch it with a suitable transistor or MOSFET.

I have some details about running motors etc. from Arduino pins at Driving motors, lights, etc. from an Arduino output pin.
Quite possibly what would work for you is a MOSFET - as Majenko suggested - connected up like this:

In this case you connect the positive side of your 12V supply for your pump to the pump, and the MOSFET sinks current to ground, when you require the pump on.
Don't forget the diode D1 which prevents damage from the inductive load of the pump generating high-voltage spikes.

Yes, though getting a MOSTFET setup right can take some care as they are a bit delicate electrically, so someone doing this for the first time may find it easier to use one of those extremely cheap relay boards.  If the pump is going to either be off or on for at least a few seconds at a time this should work just as well - where a MOSFET really recommends itself is when the pump speed is to be controlled by rapidly switching it on and off hundreds to thousands of times a second.

I was about to ask this, I was aware of these Relays, but now I guess I learn something new. I do only care only for On/Off

You can get digital relays which I'm not sure if that is what @ChrisStratton meant. Effectively they would have a MOSFET in them. If you get a mechanical relay you have the issue of adequately driving the relay coil, and installing a flyback diode to protect yourself from that coil.

No, electromechanical.  Small electromechanical relays require very little to drive - and are commonly sold on boards with an isolated driver and flyback diode.  These are conceptually a lot simpler to deal with, and don't have the same ESD fragility, making them a lot more beginner-friendly.


text:
HC-SR04 quits pinging when distance < 0 || distance < MAXDISTANCE
so here is the issue. I have a mega 1280, a handful of neopixels and a HC-SR04. I am using the New Ping library (tried both 1.5 and 1.6). I am trying to make a device that will tell my mom when she has pulled into the garage enough so she don't get hit by the garage door AND doesn't run into the wall. I wrote a bunch of code to handle the lights and what colors to do when and this part works perfectly. My issue is with the sensor. It works great except for 2 specific conditions.

if you are too close. I normally either cover one of the 2 sonic sensor part or just barley touch then with a piece of cardboard (or anything for that matter
If you go outside the scope of the max distance

when either of this are met, the ping sensor stops clicking and it just returns all 0's for the output. I am including the code less the part for the lights because even if i remove that part of the code, it still fails on those 2 conditions.
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include <NewPing.h>
#define TRIGGER_PIN  52
#define ECHO_PIN     53
#define MAX_DISTANCE 120
#define PIN 6
#define LEDNUM 8

int codeFact = (MAX_DISTANCE / (LEDNUM * 3));
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDNUM, PIN, NEO_RGB +     NEO_KHZ800);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  strip.begin();
    strip.show();
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(0, 255, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(255, 255, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(255, 0, 0));
      strip.show();
      delay(50);
    }
    for(uint16_t i=0; i<strip.numPixels(); i++)
    {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
      strip.show();
      delay(50);
    }

Serial.begin(115200);
}

void loop()
{
 delay(2000);
  int uS = sonar.ping();
  int dis = uS / US_ROUNDTRIP_CM;
  Serial.println(dis);
  /*
  Light code normally goes here
  */
}

What is the problem with exceeding the maximum distance (which you have as 120 cm)? The library is supposed to return NO_ECHO which is zero, which is what you say it is doing. As for the minimum distance, possibly the echo return is so short it can't be measured, thus it times out, returning NO_ECHO.

my issue is once it reaches these conditions, even if you bring some in the 1 - 120cm range, it does nothing at all...still returns 0's...you have to shut off the device and turn it back on to get it to work again.

Let's tackle this from a different direction. Once it fails, does pressing the Reset button on the Arduino help, or not help? (Without powering off the sensor)

yes...the reset does the trick (it resets everything and it starts working again

So just to clarify, once you get too close/far it just prints 0 every 2 seconds, regardless of where the sensor is? Or prints nothing at all?

I can't reproduce your problem. I commented out the Neopixel code and the sensor seems to work OK, recovering from being too close or too far. This was with the NewPing library v1.5. Can you try a cut-down version without any reference to the Neopixel library?

i haven't tried without the neopixel library, but that would defeat the purpose of the project...when i get too close or too far it just returns 0 for everything...I have tried both the 1.5 and 1.6 libraries for the ping

Yes, but the point is to isolate the problem. Either there is an issue with the Neopixel library and the NewPing library, working together, which can be resolved, or there is something else going on.

I'll try later on

The HC-SR04's range is 2cm to 300 cm, if you exceed this range or come below this range, which is exactly what you are doing, the utrasonic sensor will not receive any echo and hence there will be no data on the output.
If you bring it too close and since both the transmitter and receiver located close to each other, the receiver will not receive any ultrasonic.
Put a function that checks if the ultrasonic comes down to 2-3. If it becomes true beep a buzzer that tells you that you are too close. Don't let it reach 0.


text:
HLK-RM04 wifi shield factory reset?
I have this HLK-RM04:

It came with  no catalogue or manual
all threads about it are in Chinese
after when I found the configuration webpage and changing it to client
it wont connect and it stopped board casting hlink wifi
how could i reset to factory settings?
After very long search I found an English manual.

What does Trst means ?
I don’t understand what I must do to reset it!

Since no one has posted an answer, and I finally found one myself. Ground pin 10 for 6 seconds.

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


text:
best way to protect a digital or analog input from 12volts
At work, I have connected an Arduino to a security key (which has a 12v power supply) in order to give us a more versatile door lock.  Unfortunately, people keep removing the key pad, disconnecting the wires and re-connecting them (defective keypad I guess.)  In the process, I am afraid that they will accidentally send 12v into the Vcc, ground, digital in, and/or analog in pins.  What is the best way to protect my Arduino from the 12 volts?  I really need a component or two that I can to my pins.
Edit: it is difficult for me to describe this problem without mentioning the danger to all components.  Please describe ways to protect digital outputs HERE

There are some suggestions at Protecting Inputs in Digital Electronics .
Amended answer
Testing of my earlier answer involving clamping diodes gave unsatisfactory results. Due to the small current flow the diodes allowed a considerable voltage to reach the input pin (like, 9 V).
The amended circuit below, tested with 12V input, satisfactorily keeps the Arduino input pin to 4.9 V, even with 12 V from the device. The current through R1 is around 7 mA which is what you would expect:
I = V / R
I = 7 / 1000
I = 7 mA

The 1N4733A is a 5.1 V, 1 W zener diode which can therefore handle dropping 5 V at 7 mA.
In case you are wondering where the number 7 comes from in the calculations above:

The input voltage is 12 volts
The desired output is 5 volts
Therefore we need to drop (12 - 5) volts over the resistor
Thus 7 volts are dropped over the resistor

Further reference material:

10 Ways to Destroy An Arduino
Protection
Microcontroller Input Protection Techniques

Is D2 and C1 connected to +5v or ground?  I don't see a lable

As per Electrical Symbols & Electronic Symbols the downwards pointing triangles are common ground. So yes, D2 and C1 are connected to ground.

Thanks, great link for someone that is not a trained electrical engineer (me.)

Can this same circuit protect Digital outputs too, or should a different circuit be used?

A 10 ohm resistor, will mean around 0.7 A will go through the diodes if +12 volt is connected. That's 5Watts being dissipated by R1. Fine for 12v spikes, but not for continues 12v being applied.

That's true - probably R1 should be at least 100 Ω instead of 10 Ω . That means it will have 70 mA through it, which would be 0.49 W. The circuit was really for spikes rather than connecting a high-current supply. And since that wasn't really the question asked, I have amended the answer to have a higher value for R1. Since we had a 1 k resistor there anyway, I changed R1 to 1 k. Assuming the security key is just sending serial data that should still work.

@Hoytman - that isn't really required for an output circuit. I suggest you browse some of the references in my answer to see if they help.

Note: circuit changed again as testing of the clamping diodes solution revealed that with the low current through the resistor (due to the high impedance of the Arduino input) they were not effectively protecting the input pin. The zener diode solution, however, does.


text:
Implement a discrete controller /transfer function with arduino uno
i want to implement a discrete transfer function at z domain with arduino UNO.I  know that i must do the inverse z transform and find the difference equation.Afterwards i must use PWM because arduino UNO has not DAC.
Is there anyone who knows about this ?and can help me.... i want a code as an example  .Thank you.

At the very least your question should include the nature of the inputs, and it would be helpful if you included the equation in the form to be implemented - ie, document every part of the problem except the Arduino.

the reference input is a unit step signal 1 volt.i should use pwm and filters for DAC.Have you got any idea ?

authors: Νίκος-Μάριος Κοκολάκης


text:
can I create an on/off switch for my Arduino using the reset pin?
If i connect a switch to the reset pin, can I create an effective way of turning off the Arduino (overnight) without removing its power supply?

It wouldn't really be off, but the I/O pins would be high impedance, and the sketch would not be running. If you just want to stop it doing something (like feeding fish or something) you could just have the code test a pin, and if that pin was in a particular state, stop doing whatever it  usually does.

If your concern is power consumption, you'd have to see how much of the chip the reset shuts down (and what is consumed by the built-in pullup resistor on the reset itself).  There are also ways to shut down nearly everything, until it is woken up again by a pin interrupt.  Note that neither will shut down the USB-serial chip and its consumption.

The question is, why do you want to do this? If it is to save power, my experiments show that holding the chip in reset is not the most effective way.

Wouldn't connecting the switch to the power supply be just as  easy? Holding reset will not power down the AVR, nor will it shut down the other parts that are on the Arduino board (voltage regulator, led, usb-to-serial etc.)

Tests show that connecting Reset to Ground on a Uno reduces the power consumption from 47 mA to 41 mA. So it is hardly "off".
All that would do is stop the currently-loaded sketch running, and save a few milliamps.


text:
Fading from color to color using for-loop FastLEDs
I'm attempting to fade a strip of ws2812 7 pixels in length. Below I am using a for loop to increment the color red. I can fade it to red (from blue) but it will do it one pixel at a time or it just stays blue, depending where I move my r for-loop to. I need it to fade from color to color all 7 LEDs at once.
I get no errors.
I don't understand the process of getting NUM_LEDS leds all into x then proceeding with my color changing. Seems like I'm grabbing one pixel, fading it to red, then another...
fastLeds 3.03 library, arduino 1.0.6
#include <FastLED.h>
#define DATA_PIN 6
#define NUM_LEDS 7

#define BRIGHTNESS 45
#define COLOR_ORDER GRB
#define g 50
#define b 100
int r;
CRGB leds[NUM_LEDS];

void setup(){
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
}

void loop(){
  for(int x = 0; x < NUM_LEDS; x++){
    delay(10);
    leds[x] = CRGB(r,g,b);
  }
  FastLED.show();
  delay(10);

  //-------------------------

  for(int x = 0; x < NUM_LEDS; x++){
    for(int r = 0; r < 254; r++) {

if NUM_LEDS is holding the number 7 why can't I just do it like this below: leds[NUM_LEDS]?
      leds[x] = CRGB(r,g,b);
      FastLED.show();
      delay(100);
    }
  }
}

If you want to fade all the LEDs form blue to red at the same time, I think you want code like this (explanatory comments embedded)...
#include <FastLED.h>
#define DATA_PIN 6
#define NUM_LEDS 7

#define COLOR_ORDER GRB

CRGB leds[NUM_LEDS];

void setup(){
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);

}
void loop(){

  // Let's take 256 steps to get from blue to red
  // (the most possible with an LED with 8 bit RGB values)

  for( int colorStep=0; colorStep<256; colorStep++ ) {

      int r = colorStep;  // Redness starts at zero and goes up to full
      int b = 255-colorStep;  // Blue starts at full and goes down to zero
      int g = 0;              // No green needed to go from blue to red

      // Now loop though each of the LEDs and set each one to the current color

      for(int x = 0; x < NUM_LEDS; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
      FastLED.show();

      delay(10);
  }

}

Hi bigjosh. Thank you for taking the time to look over and edit my code. But it isnt working. It just lights up red. no blue. no fading. was I suppose to add anything or is it complete above?

Doh! Misplaced parenthesis. Edited- should work now. Sorry!

AHHH! Thank you bigjosh. Im embarrassed to say how long ive been trying to fade my led strip. Thanks again man, Youve been a big help.

Here is the initial 0-255 rainbow.  I dunno if this is what you are trying to achieve but i took initiative from @bigjosh's answer.  This just cycles thru each rgb from 0-255. @bigjosh does start red at 0-255 allowing for more for red colors.
void loop(){

//start from red
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {

  int r = 255;
  int g = 0;
  int b = colorStep;

  // Now loop though each of the LEDs and set each one to the current color
  for(int x = 0; x < LED_COUNT; x++){
      leds[x] = CRGB(r,g,b);
  }

  // Display the colors we just set on the actual LEDs
      delay(10);
      FastLED.show();
      }

    //into blue
      for( int colorStep=255; colorStep >= 0; colorStep-- ) {

      int r = colorStep;
      int g = 0;
      int b = 255;

      // Now loop though each of the LEDs and set each one to the current color
      for(int x = 0; x < LED_COUNT; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
  delay(10);
  FastLED.show();
  }

//start from blue
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {

      int r = 0;
      int g = colorStep;
      int b = 255;

      // Now loop though each of the LEDs and set each one to the current color
      for(int x = 0; x < LED_COUNT; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
  delay(10);
  FastLED.show();
  }

//into green
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {

      int r = 0;
      int g = 255;
      int b = colorStep;

      // Now loop though each of the LEDs and set each one to the current color
      for(int x = 0; x < LED_COUNT; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
  delay(wait_time);
  LEDS.show();
  }

//start from green
  for( int colorStep=0; colorStep <= 255; colorStep++ ) {

      int r = colorStep;
      int g = 255;
      int b = 0;

      // Now loop though each of the LEDs and set each one to the current color
      for(int x = 0; x < LED_COUNT; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
  delay(wait_time);
  LEDS.show();
  }

//into yellow
  for( int colorStep=255; colorStep >= 0; colorStep-- ) {

      int r = 255;
      int g = colorStep;
      int b = 0;

      // Now loop though each of the LEDs and set each one to the current color
      for(int x = 0; x < LED_COUNT; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
  delay(wait_time);
  LEDS.show();
  }

} //end main loop


text:
Connect an mp3 player to an Arduino?
I have been looking for a good way to play sounds using an Arduino.  I started to consider just buying a cheap mp3 player and replacing the player's buttons with optical switches, which connect to an Arduino.  I wanted to know if anyone has done this before and if there was a good mp3 player for this (one that may have some sort of control port / ir sensor.)

It's probably going to be very challenging to select the desired track, and it will have start up delay.  You can play lower fidelity digital audio directly from an Arduino or related chips, or comparable with add-ons - though there is a challenge in storing the clips uncompressed unless you opt for an sdcard.  What sorts of things do you want to play?

Yes, people have done this before, and they have documented it on their own blogs and similar sites.  Maybe you should have asked Google first before you came here?  You'd most likely have ended up on instructables, where someone has documented exactly what you want to do and how to do it. and saved yourself this entire step.


text:
fading colors on a ws2812 strip
I have a strip of 7 leds. its ws2812. Im starting them on blue. Next I want them to do a slow fade into pink. So all Im trying right now is to increment r.
I can get them to work one by one. But I need them to all fade together from blue to pink.
Ive moved my r++ loop around till I was cross-eyed. Still it didnt fade all 7 leds to pink all at once.
sometimes it would stay blue and do nothing sometimes fade to pink one pixel at a time.
How do I get all 7 leds to fade together?
Thank you.
#include <FastLED.h>
#define NUM_LEDS 7
#define DATA_PIN 6
#define BRIGHTNESS 45
#define COLOR_ORDER GRB
#define g 50
#define b 100

int r; //changed it to undefined

CRGB leds[NUM_LEDS];

void setup(){
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);

 }
void loop(){

this lights all leds to blue
  for(int x = 0; x < NUM_LEDS; x++){

  leds[x] = CRGB(r,g,b);
 }
  FastLED.show();
  delay(10);

this code should grab all 7 leds in NUM_LEDS store it in x
  for(int x = 0; x < NUM_LEDS; x++){

  leds[x] = CRGB(r,g,b);

Heres the problem area. I get no errors but it doesnt fade all 7 leds at a time.
Ive tried moving my code around but it either doesnt fade or fades to pink one led at a time. where should my 'for loop' for incrementing r be at?
Should I be changing rgb all at once using array?
//take r and fade it up to 254

for(int r = 0; r < 254; r++) {

  }
  }
     FastLED.show();
 delay(100);

}

What library are you using?

FastLEDs library. 3.03

If you want to fade all the LEDs form blue to red at the same time, I think you want code like this (explanatory comments embedded)...
#include <FastLED.h>
#define DATA_PIN 6
#define NUM_LEDS 7

#define COLOR_ORDER GRB

CRGB leds[NUM_LEDS];

void setup(){
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);

}

void loop(){

  // Let's take 256 steps to get from blue to red
  // (the most possible with an LED with 8 bit RGB values)

  for( int colorStep=0; colorStep<256; colorStep++ ) {

      int r = colorStep;  // Redness starts at zero and goes up to full
      int b = 255-colorStep;  // Blue starts at full and goes down to zero
      int g = 0;              // No green needed to go from blue to red

      // Now loop though each of the LEDs and set each one to the current color

      for(int x = 0; x < NUM_LEDS; x++){
          leds[x] = CRGB(r,g,b);
      }

      // Display the colors we just set on the actual LEDs
      FastLED.show();

      delay(10);
  }

}

@bigjosh has provided code, so I will provide some plain text logic to explain what you should be doing.
To fade from one color to the next, in this case from Solid Blue (0,0,255) to Pink (Red + Blue, 255,0,255), you need to change the value a little, latch it, then wait before you change the value again. Pseudo code:

rgb = 0,0,255
write rgb
wait X milliseconds
rgb = r + 1,0,255
write rgb
wait X milliseconds
loop until r = 255

At each step, you need to push out the value to the leds before delaying and then starting again. The delay can and should be varied to your satisfaction. I find a fast fade better. At single steps of r + 1, even slow delays will seem mostly smooth.


text:
Motor Shield StepMotor

What the two yellow cables as you can see in the picture do not know?

There are two types of stepper motors: unipolar and bipolar. Bipolars usually have four wires and unipolars have six.

--http://hobbymilling.com/wp-content/uploads/2011/05/Unipolar-stepper-motor-windings.png

--https://www.codeproject.com/KB/system/steppermotorcontrol/pic6.jpg

The motor shield is designed to drive a bipolar motor (4 wires) but the motor is unipolar (6 wires). As you can see in the pictures, if you ignore the middle wire of the unipolar motor, it is the exact same as a bipolar stepper motor.

Here is the link from the original answer that you rudely deleted. You will read that there is a difference between the two http://digital.ni.com/public.nsf/allkb/C4A024DA9F197E6286257BC8005DC236. I also +1'd the querstion because you or someone else -1'd it unfairly. It's a good question!

@VisualMicro please read the comment I left on your answer: “Whilst you link may answer the question, it would be preferable to include the essential parts of the linked here, and provide the link for citation. I've deleted this answer for now. Feel free to add another answer. Thanks! –  Annonomus Penguin♦ 3 hours ago”

I read your message and think my post gave an accurate answer which is a link to a very simple overview. You deleted my post and added an incorrect answer. You seem to be purely interested in gaining points for your Annonomus account. You should be brave, tell people who you are, stop deleting correct answers to gain points and give accurate responses.

Please see the stack exchange policy on link only answers: http://meta.stackexchange.com/q/225370/190823. Your post basically said "there are two configurations, both outlined HERE." If you have an issue, please create a meta post where I and I (and the rest of the community) will be happy to discuss this further. Until then, please post an answer here that is valid without any links that is the correct answer. Thanks.

See above I already posted the link. I think the policy requires accurate answers 1st. It's a long answer and best read via the link I posted. I won't be adding another answer I think the user has the answer now. I am not here to waste people time.


text:
What pins to use to externally power an Arduino Fio (without battery)
I need to power an enclosed Arduino Fio project with 12V. The intention is not to attach a battery because there is no need as this is a fixed installation with a 12V DC available (for a pair of relays which will be controlled by the Fio).
My question is what Pins should I use. The Fio page (https://www.arduino.cc/en/Main/ArduinoBoardFio) on the Arduino web site says...
Input Voltage   3.35 -12 V
Input Voltage for Charge    3.7 - 7 V
Unfortunately, there is no indication what pins these specs refer to. I assume that the "Input Voltage for Charge" refers to the mini-USB port and unlike other Arduino boards, there is no Vin pin to supply the board externally. Looking at the board layout on the same web page, I think the only possible option is via the two pins in parallel to the battery port which I suppose are then going into the voltage regulator on the board.
Any comments or suggestions? Has anyone done something similar?

Check the schematic. You can connect the voltage the the JST battery connector, or JP3 (I'd double check those two holes are connected to the JSP using a mulimeter). But I'm slightly doubtful about that 12v rating they give on the webpage. The voltage regulator can handle that, but I don't think the battery charger IC (MAX1555) can handle 12v on the BAT pin, looking at the datasheet.

Max1555 can only handle of 7v input (see datasheet). Based on the schematic, I won't trust the info on the website. I think it will be better and easier for you to find a power supply of 5V with micro USB. Even if you use the 12V supply applying to JP7, there will be too much voltage drop on the 3V regulator that it will generate heat than it should be.

I used the external switch input JP7-1 for 12v, any GND hole, and make sure the switch is off.  This bypasses the charge circuit which doesn't like 12v.


text:
Is there any way to run binary code from RAM?
I am looking for an inexpensive single board computer that I could program in assembly language, using limited facilities to load the object code from a PC and simple I/O peripherals.
Ideally I would like to be able to write in a reasonable time all the code on the machine myself. I don't want an OS in the way, as I want to have a program that writes in RAM some code and then branches to execute it.
Arduino would probably be my best choice, as far as system simplicity suitable for assembly programming goes, but it has a Harvard architecture and it won't allow me to execute from RAM.
Years ago I was using a Von Neumann architecture 8-bit CPU that could branch execution to any address, no matter whether it was mapped to ROM, RAM or whatever. This is what I would like to do now.
I probably could write and load in Flash memory an interpreter of op codes written in RAM, but it is a very complex and time-consuming solution, unless virtual machines of this kind exist already.
Any suggestions on other workarounds with Arduino or of other micro-controllers I might use?
Thanks!
Pierre

The PIC32 is a Princeton (Von Neumann) architecture chip.  It's a MIPS CPU so is well documented and standardized, though somewhat more complex than a lowly AVR.  The chipKIT boards may be more to your liking.

Although optimized as a Harvard Architecture, the ARM Cortex-M series can execute from RAM at a tolerable efficiency loss and would still be a lot faster than an AVR when doing so.   At least a half dozen chip companies make widely used offerings based on licensing this core, and while many people use vendor and/or semi-standard libraries, it is entirely possible to do it all yourself based on the data sheets.  I went with STM32 first as their discovery boards are very cheap, work on Linux/OSX with open source tools, and can program chips on custom boards, but have now used Kinetis as well.

The main question is Why? Why do you require ASM execution from RAM? And what kind of assembly do you want to use? Since every architecture has its own language... Do you do this for learning purposes? Or you have a specific target?

I beg to differ, why I wished to do this is irrelevant to the question I asked at the time as this is not a workaround to some other issue. Incidentally, I followed Majenko's advice and I currently have a Uno32 plus external interfaces running assembly (and calling C functions from assembly), writing its own modified asm code in RAM and executing it.

Forth is what you are looking for :)

@ChrisStratton putting code in RAM, instead of Flash, can actually result in faster code, at least in those processors, in which part of the internal RAM is in the code region. (address up to 0x1FFFFFFF) . Flash is typically slow, and, despite the "memory accelerator/buffer" (which is simply a small cache), you never get a true 1-cycle access. Therefore you'll have a lot of penalties, especially if the code has a lot of jumps (the buffer must be refilled) and it's executing from Flash instead of RAM. Different thing is the external RAM, which might be very slow (e.g. due to bus constraints).

@next-hack if you have RAM optimized for code access, yes.  But many basic micros that permit code access to RAM are only optimized for data access to it - while you can run them from RAM, it's slower than running them from flash as the instruction fetch and data access have to share the same memory bus, when ordinarily they would not.  But if you have one specifically designed for this, then sure, go ahead.  And that might explain why (if I recall correctly) in some of the Kinetis parts the RAM sizes grow symmetrically around 0x20000000, rather than linearly above it as in say STM32's.

In my opinion the interpreter idea is much more feasible. The notion of writing, in assembler, code that itself generates machine code, in RAM, and then executes it, is itself incredibly complex.
You haven't said why you want to do this, so this is somewhat of an X-Y problem.

I don't want an o.s. in the way ...

The normal Arduinos do not have an OS in the way - basically the code you write is what gets loaded onto the chip.

In a word, no.  The inability to execute modifiable memory is a rather unusual limitation in this day and age, where most other nominally Harvard architecture devices are modified to be able to avoid that limitation.  Writing a software interpreter is both going to be a lot more work, and a lot less efficient, than dealing with one of the many inexpensive, high performance, and easy to use chips that has the necessary internal connections to simply execute code from RAM.  The slightly less efficient pipeline operation in that mode is still far, far ahead of software interpretation.

I think you are underestimating the requirement to have "a program that writes in RAM some code and then branches to execute it". Now if the question said "load some code from disk and execute it" well yes, that would be trivial on the architectures that support loading code into RAM. But to have code that generates machine code? A compiler/assembler in other words? Maybe I misunderstood the question as meaning "generate code" rather than "load code". But the OP said " I would like to be able to write in a reasonable time all the code on the machine myself." Sounds like code generation to me.

No.  If you are going to do runtime code modification, it is by far easier to directly generate machine code than to generate high level code and also have to create a compiler or interpreter as in your recommendation.   It might be worth spending some time hand-writing instructions to get some perspective.  And no, "write all the code on the machine myself" does not refer to run time code generation to begin with, but rather merely to creating original work vs. relying on other authors for supporting components.

I think this answer could be improved with a link to a list of interpreters that already run on Arduino. Is there a more complete list than http://playground.arduino.cc/CommonTopics/InterpretedLanguages ?

Here is a simple forth style shell for the Arduino that executes code from any of the memory storages (SRAM, EEMEM, EEPROM). Not the fastest interpreter but shows how the instruction fetch (memory access) and instruction pointer (call/return addresses) can be abstracted. https://github.com/mikaelpatel/Arduino-Shell

I'm impressed, Mikael. I wrote a Forth interpreter for the Apple II years ago. I doubt I can even find the code these days. Good old Forth, still alive and kicking! :)

@NickGammon I recently wrote a more traditional forth virtual machine (fvm) for the Arduino. It allows embedding a byte instruction interpreter in an Arduino sketch as it is multi-tasking (allows yield of the fvm). https://github.com/mikaelpatel/Arduino-FVM. There is a token compiler (runs on the Arduino :) and a traditional forth interactive interpreter. Please see the example sketches.

@MikaelPatel - well that's impressive! I used token mapping in my Pascal compiler years ago, and tail call reduction as well, mainly to squeeze the code into the available space. :)


text:
Arduino not responding while trying to flash over BLE
I'm working on wireless uploader for Arduino from iOS devices. I'm using HM-10 BLE module which seems to work ok. PIO 2 is used as DTR for resetting (see A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 1 [0x31] and A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 0 [0x30] below)- using 0.1uF capacitor and 10K resistor wired to MCU reset pin. Reset seems to be done correctly as i'm getting ready output (in 'setup()' body in uploaded sketch).
For some reason i'm getting 0x14 0x10 for 0x30 0x20 request (to ping bootloader) but not getting response for A [0x41] . [0x81]   [0x20] within almost 1 second.
Uploading over BLE:
2015-07-04 19:24:10.955 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 1 [0x31]
2015-07-04 19:24:10.955 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 8
2015-07-04 19:24:11.106 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 8 bytes
2015-07-04 19:24:11.106 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 0 [0x30]
2015-07-04 19:24:11.106 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 8
2015-07-04 19:24:11.148 xctest[54864:5122867] [DEBUG  ] [   ]: Draining for 230 ms ...
2015-07-04 19:24:11.148 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.323 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 9 bytes: O [0x4F] K [0x4B] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] : [0x3A] 1 [0x31]
2015-07-04 19:24:11.323 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 9 bytes: O [0x4F] K [0x4B] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] : [0x3A] 0 [0x30]
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [IN ]: Ble clear buffer
2015-07-04 19:24:11.381 xctest[54864:5122867] [DEBUG  ] [IN ]: Drained 18 bytes
2015-07-04 19:24:11.381 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 2 bytes
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [OUT]: Send: 0 [0x30]   [0x20]
2015-07-04 19:24:11.382 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 2
2015-07-04 19:24:11.382 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.382 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.746 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 1 bytes: . [0x00]
2015-07-04 19:24:11.747 xctest[54864:5122914] [TRACE  ] [IN ]: Ignoring single 0x00 char
2015-07-04 19:24:11.747 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 2 bytes: . [0x14] . [0x10]
2015-07-04 19:24:11.748 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.748 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: . [0x14]
2015-07-04 19:24:11.749 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 2 bytes
2015-07-04 19:24:11.749 xctest[54864:5122867] [TRACE  ] [IN ]: 1 bytes in incoming buffer remaining for next receive
2015-07-04 19:24:11.749 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Having current receive buffer: . [0x10]
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.751 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: . [0x10]
2015-07-04 19:24:11.751 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 1 bytes
2015-07-04 19:24:11.751 xctest[54864:5122867] [TRACE  ] [IN ]: Ble clear buffer
2015-07-04 19:24:11.752 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 3 bytes
2015-07-04 19:24:11.752 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] . [0x81]   [0x20]
2015-07-04 19:24:11.752 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 3
2015-07-04 19:24:11.752 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.753 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.821 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 1 bytes: . [0x00]
2015-07-04 19:24:11.821 xctest[54864:5122914] [TRACE  ] [IN ]: Ignoring single 0x00 char
2015-07-04 19:24:12.721 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 5 bytes: r [0x72] e [0x65] a [0x61] d [0x64] y [0x79]
2015-07-04 19:24:12.722 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:12.722 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: r [0x72]
2015-07-04 19:24:12.723 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 5 bytes
2015-07-04 19:24:12.723 xctest[54864:5122867] [TRACE  ] [IN ]: 4 bytes in incoming buffer remaining for next receive
2015-07-04 19:24:12.723 xctest[54864:5122867] [ERROR  ] [   ]: STK500:getParameter: protocol error #1, expected [0x14], received [0x72]

When uploading over usb it's ok:
2015-06-29 16:34:10.829 xctest[36585:3703900] [TRACE  ] [   ]: DTR/RTS supported by Serial, resetting
2015-06-29 16:34:11.140 xctest[36585:3703900] [DEBUG  ] [IN ]: Draining ...
2015-06-29 16:34:11.392 xctest[36585:3703900] [DEBUG  ] [IN ]: Drain done
2015-06-29 16:34:11.392 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.392 xctest[36585:3703900] [TRACE  ] [OUT]: Send: 0 [0x30]   [0x20]
2015-06-29 16:34:11.393 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.531 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.531 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.532 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.532 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 3 bytes
2015-06-29 16:34:11.532 xctest[36585:3703900] [TRACE  ] [OUT]: Send: A [0x41] . [0x81]   [0x20]
2015-06-29 16:34:11.533 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.535 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.536 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.536 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x04]
2015-06-29 16:34:11.536 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.536 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.537 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 3 bytes
2015-06-29 16:34:11.537 xctest[36585:3703900] [TRACE  ] [OUT]: Send: A [0x41] . [0x82]   [0x20]
2015-06-29 16:34:11.537 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.540 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.540 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.540 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x04]
2015-06-29 16:34:11.540 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.541 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.541 xctest[36585:3703900] [DEBUG  ] [   ]: STK500:initialize: n_extparms = 4
2015-06-29 16:34:11.541 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 22 bytes
2015-06-29 16:34:11.542 xctest[36585:3703900] [TRACE  ] [OUT]: Send: B [0x42] . [0x86] . [0x00] . [0x01] . [0x00] . [0x01] . [0x01] . [0x01] . [0x03] . [0xFF] . [0xFF] . [0xFF] . [0xFF] . [0x00] . [0x80] . [0x04] . [0x00] . [0x00] . [0x00] . [0x80] . [0x00]   [0x20]
2015-06-29 16:34:11.542 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.548 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.548 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.548 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.548 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 7 bytes
2015-06-29 16:34:11.549 xctest[36585:3703900] [TRACE  ] [OUT]: Send: E [0x45] . [0x05] . [0x04] . [0xD7] . [0xC2] . [0x00]   [0x20]
2015-06-29 16:34:11.549 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.552 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.552 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.552 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.553 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.553 xctest[36585:3703900] [TRACE  ] [OUT]: Send: P [0x50]   [0x20]
2015-06-29 16:34:11.553 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.556 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.556 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.556 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.569 xctest[36585:3703900] Reading |                                                    | 0% 0ms
2015-06-29 16:34:11.570 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.571 xctest[36585:3703900] [TRACE  ] [OUT]: Send: u [0x75]   [0x20]
2015-06-29 16:34:11.571 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 5 bytes
2015-06-29 16:34:11.572 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14] . [0x1E] . [0x95] . [0x0F] . [0x10]
2015-06-29 16:34:11.572 xctest[36585:3703900] Reading | ################################################## | 100% 2ms

So when uploading over USB DTR/RTS and similar schematic is used.
I think the problem is in resetting approach - wiring to reset does not work when trying to upload. Am i right? Is it bootloader issue?
PS. Arduino sketch uploaded:

void setup() {
  Serial.begin(115200);
  Serial.print("ready");

  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:

}

I forgot to say i've tested with Arduino Uno r3. i've just tested uploading to Arduino Mega2560 and it works - Mega's bootloader replies as expected and uploading succeed. What's wrong with Uno?


text:
Attiny88 as SPI slave
I have programmed Attiny88 with Arduino IDE 1.6.5 using https://github.com/SpenceKonde/ATTinyCore . I chose Attiny88 because it's the cheapest Attiny (as low as $0.5) and at the same time has 28 pins with dedicated SPI.  I wrote a code for arduino to work as SPI master, and a code for Attiny88 as SPI slave but I get only 0 as answer from Attiny.
SPI master code for ARduino UNO
#include <SPI.h>

// set up the speed, data order and data mode
SPISettings settingsA(2000000, MSBFIRST, SPI_MODE0);
const int slaveAPin = 10;

void setup() {
  // set the Slave Select Pins as outputs:
  Serial.begin(9600);
  Serial.println("SPI ON");
  pinMode (slaveAPin, OUTPUT);
  SPI.begin();
}

uint8_t stat, val1, result;

void loop() {
   // read two bytes from device A
   SPI.beginTransaction(settingsA);
   digitalWrite (slaveAPin, LOW);
   // reading only, so data sent does not matter
  stat = SPI.transfer(0);
  val1 = SPI.transfer(0);
  digitalWrite (slaveAPin, HIGH);
  SPI.endTransaction();
  Serial.println("data");
  Serial.println(stat);
  Serial.println(val1);
  Serial.println("end");
  SPI.endTransaction();
  delay(300);
}

SPI slave code for Attiny88:
#include <SPI.h>

// set up the speed, data order and data mode
SPISettings settingsA(2000000, MSBFIRST, SPI_MODE0);
const int slavePin = 14;
const int ledPin = 9;

uint8_t stat, val1, val2, result;

void setup() {
  // set the Slave Select Pins as outputs:
  pinMode (slavePin, INPUT);
  pinMode (ledPin, OUTPUT);
  // initialize SPI:
  digitalWrite(ledPin, HIGH);
  delay(1000);
  SPI.begin();
  stat =128;
  val1= 1;
}

void loop() {

  if (slavePin==LOW) {
    SPI.beginTransaction(settingsA);
    SPI.transfer(stat);
    SPI.transfer(val1);
    result = SPI.transfer(0);
    digitalWrite(ledPin, result);
    SPI.endTransaction();
  }

}

You do not appear to be configuring the slave as an SPI slave. Merely changing the pin modes won't achieve this. Example code at SPI - Serial Peripheral Interface - for Arduino - however that does not specifically mention the Attiny88.
In my example in reply #1 on that page I have this code:
  // turn on SPI in slave mode
  SPCR |= bit (SPE);

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);

This sets SPCR bit MSTR to zero (by not mentioning it). If you call SPI.begin() it will be activated in master mode.
It looks like the Attiny88 has the same register.
So in my opinion your code merely has two SPI masters.
Also, you seem to be doing 3 transfers in the master, but only 2 transfers in the slave.


text:
Best way to protect a digital output?
I am looking for a way to protect my Arduino's digital outputs from unwanted, outside voltages. My project uses about 20 different outputs, each connected to a wire (run) that can range from 20 to 100 feet (I used cat5 cable, with each inner wire (randomly chosen) dedicated to a single digital in, out, +5, +9 or ground.)  There is a good change that outside voltages could impact these digital outs (or any other pin or power wire.)
I have a good resource on protecting digital in's but I ma not sure how to protect the digital outs.  Each needs to be able to both pull a connect component to ground, and push it up to 5 volts (am I saying this correctly?)
This should be able to protect the digital outs from shorts or 12v spikes.
How can I build this circuit?
Edit: it is difficult for me to describe this problem without mentioning the danger to all components.
Note that ways of protecting digital inputs is HERE.

Some good results you can get with optocouplers.

It's electrically disconnects one part of your circuit from another.
For example, here is my IoT-ish device, which is detects water leaks in my bathroom:

I use the transformer (T1), which have two separate output windings, so, that windings does not connected electrically, only magnetically. The block in border "Sensing unit" doesn't have any wires with other scheme - only magnetic field, which is gives it power, and infrared light in the optocoupler (u2, PC817), which informs ESP01 about leak presence.
How does it work? Very simple! When the water shorts JP1 (long naked wires on the floor), Q1 opens and lights-up the IR diode in PC817. Light from this diode opens another transistor - and pulls the RxD PIN of ESP01 down.
Small sketch, written on Arduino for ESP8266 periodically sends pin state by HTTPS on my web server, where monitor software, Nagios, checks the information age and the pin state, and send to me notifications, when something goes wrong.

Can you add a bit more detail please? This is basically a link-only answer that says the link will solve your problems.

@NickGammon - Done!

Add a resistor in the circuit to limit the current in case of a short.
Add clamping diode to prevent voltages higher than 5v (combined with the resistor from before). The AVR has internal clamping diodes, but those can only handle very little current. Since you are running such long wires, you probably need to add the lowest value resistor, to limit noise.
PS The possibility of have a external voltage applied to an output sound pretty troubling to me.

The possibility of have a external voltage trouble me too.  My circuits are accessible to other 'technicians' who disconnect / reconnect them without powering down everything.  There is a very real chance that a 12 volt wire will touch a digital in, digital out, a 5 volt supply wire or the Arduino's ground.  I have discussed this with them and the boss, and the response is to build a circuit that will not be damage by such things.

Just add a 220v wire. That way they are required to power everything down. That will protect the rest of the circuit from idiots messing with a powered circuit. q-:

Would love to, but the Arduino is a part of a drama stage, so the techs have to be really fast and really safe.

Related to: best way to protect a digital or analog input from 12volts by @Hoytman

Should the same configuration be used for both inputs and outputs?

@Hoytman - you asked the same question in the other thread. This is kind-of confusing, asking in one thread about inputs, and in the other about outputs, and then in both threads asking about the alternate (output/input). This is spreading the answers over multiple threads which is confusing.

Your right, I'll ask that answers are specific to the thread title.

The configuration mentioned in the other thread, which has a 1 k resistor in series with the signal, won't work so well for an output. For a start, due to Ohm's Law, it would limit the amount of current it could source, or sink, to 5 mA. If the output is just something like a serial port, that may not matter. If you are trying to turn on a relay or LED, you may find it a limitation.

Would it be a good idea to use the same configuration, but play with the values till I find something that works?

@Hoytman Could you not use a transistor to switch it on and off and also add a pull-down resistor to pull down the wire to ground after turning it off and a diode to protect the transistor?

Check with your favorite automotive semiconductor supplier such as ST. In there automotive listings you will find drivers that will do exactly what you want and if shorted to long will shut down and come back when the short is removed.  I am not going to make a recommendation as there are literally hundreds of possibilities. These come from 1 driver per unit to 8 that would be easy to purchase. They have parallel and serial interfaces depending on what you want. If you want to be nasty get a 50 amp driver and put a huge power supply behind it, then enjoy the looks and smoke when shorted and you get the last laugh your Arduino will be OK.  Have Fun!

See 10 Ways to Destroy An Arduino
One of the suggestions there for output pins was:

Put a 30mA resettable fuse (PTC) in series with every I/O pin. Not only is the current safely limited to 30mA under all conditions (more on this below), but the built-in 220 ohm resistance of the fuse naturally limits the current to 5V/220 = 23mA right off the bat.

You may also want to look at some of the suggestions on the question about protecting input pins which could help with keeping spikes out of the output circuits.


text:
Encrypting data for webserver
I'd like to send sensor values over ethernet shield to a webserver. But for this I'd like to encrypt the data on the arduino and decrypt it on the webserver (PHP).
Do you have any suggestions or examples?

XTEA is probably your best bet.  It's lightweight, easy to implement, and secure enough for a bit of sensor data...

https://en.wikipedia.org/wiki/XTEA

There's also the slightly more complex, and also slightly more secure, XXTEA:

https://en.wikipedia.org/wiki/XXTEA


text:
Servo Speed Control
I work in a robot using arduino, and i have a few questions:
It is possible to increase the speed of a servo, for example a parallax?
It is possible to measure the current that pass through a servo?

Assuming the on-board controller is already driving the motor with full effort, the only way to increase speed is to lessen the load at the servo output, increase the voltage, or change the servo.  You can of course measure the current, perhaps by measuring the voltage drop across a very small sense resistor.  Generally speaking, continuous rotation servos (presumably what you mean when you reference parallax) are rather crude (and arguably open loop, not "servos" at all once so modified) so before investing much effort you may want to start with something better.

If you are powering the servo from the arduino 5v rail you could try to power it from something else, if you use a battery pack or powersupply, then put the Vin of the servo directly to that instead of using the arduino 5v rail. It is not healthy to run high current stuff from the arduino rails anyways.

Part 1: Can I increase the speed of the servo motor?
Solution #1 :
You can run your servo motor at its maximum rated voltage, which will give you the fastest response. If angle is all you want, that should be ok.
Solution #2 :
If speed control is just as important, you're better off using a DC motor with an encoder. You will have to write a PI control loop, but in return you will be granted a fine-tune control and potentially superior performance.
Solution #3 :
If you need to hold a physical load accurately at a certain angle, then I would go for a stepper motor. But you need to make sure that you do not overload it, as it will cause a misstep.
Part 2: Can I measure the current?
The simplest and cheapest method, is to connect a current sensing resistor to your servo and measure the potential difference using the analog input. Since the resistance is known, you can calculate the current using the formula I = V/R.
Two things to make sure:
1) Your resistor power rating is not exceeded.
2) The voltage difference has to be large enough to be measurable. (e.g. 2 ohm resistor gives .05V @ 100mA, .5V @ 1A and your Arduino analog input may have the resolution of roughly 0.005V)
What? Did I hear you say that the accuracy isn't good enough? Well actually you can buy an op amp to amplify to the scale that you need. Or to make life easier: buy one from Adafruit. :p
Hope this helps.

The speed of most servos cannot be changed in your code (unless your code is limiting the speed by changing the position in small increments with long delays between your writes). Most servos, in my experience, try to get to the set position as fast as the physical motors can possibly move while keeping the motion somewhat motors. However, motors can only go so fast, so you are limited.
One thing to note: some servo motors can be powered at higher voltages, but still controlled at 5V. With the increase in voltage, it might allow the motor to go a little faster, although the results will vary based on the servo's electrical characteristics and the motor driver's algorithm.
As for the current, you can buy cheap current sensors online that can be interfaced with the Arduino. You will want to measure the current (in series) flowing either from your power source to the VCC of the stepper, or from the GND of the stepper back to the GND of your Arduino.

Thank you very much, your answer was so complete and helped me so much, now things are so much clear. Sorry for my English, I am not a native speaker.