text:
Problem with deploying matlab simulink mode to Arduino UNO
I encounter a problem when deploy matlab simulink model to Arduino UNO
Following shows the error
*The call to realtime_make_rtw_hook, during the after_make hook generated  the following error:
The build failed with the following message: The system cannot find the path specified
The build process will terminate as a result.
The build failed with the following message: The system cannot find the path specified。
Component: Simulink | Category: Block error*

When type >> getenv('path')
ans =

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\MathWorks\runtime\win64;E:\MathWorks\bin;E:\MathWorks\polyspace\bin;C:\Program Files\MATLAB\R2014b\runtime\win64;C:\Program Files\MATLAB\R2014b\bin;C:\Program Files\MATLAB\R2014b\polyspace\bin;C:\Program Files\Microsoft Windows Performance Toolkit\

I did not see anything wrong with the path. I tried to solve the problem following the "http://www.mathworks.com/matlabcentral/answers/168555-what-does-the-path-in-the-system-cannot-find-the-path-specified-refer-to". However it does not work.
Anyone know how to solve it?
OS:Win8.1 Matlab 2014b 64bit

Right click on your MATLAB shortcut and click "run as administrator". See if helps. Then do all the necessary steps and see if it happens again.
Also test with x86 version. I have seen lots of these kinds of error with x64 version. Always had compiling related issues with MATLAB x64 and Simulink!


text:
How to use Induino R3 on Ubuntu 14.04
I have just got Induino R3. I have installed Arduino on my Ubuntu. I tried blink example but it shows error serial port COM1 not found
I think i need to select proper option from serial port. But i can't click on it!
P.S. I am completely new to Arduino

is your user in the dialout group?

@BrettAM Yes it is i did it from http://askubuntu.com/a/146523/283650

does /dev/ttyACM# appear in your filesystem when the arduino is plugged in?

@BrettAM It is working now. I don't know how but as soon i upgraded Ubuntu from 14.04 to 14.10 is started working!! BTW thanks for help :-)

Not 100% sure of the specific differences between your board and a normal Arduino[clone], but I've never seen serial devices referenced in Ubuntu via COM# labels(Granted I've only used or needed to use serial type devices in the last year, so I could be a bit under experienced).
Anyhow, usually I find serial devices available at /dev/ttyXXX. On my Lubuntu 14.04 installs, my USB connected Arduinos all show up as /dev/ttyACM#. I have an FTDI programmer I usually use on wifi routers which generally shows up as /dev/tty#.
Rule of thumb in Linux, everything is a file somewhere.

I did not get how to fix it from this answer

Did you by any chance, download the Windows version of the Arduino IDE and install it under Wine? Then I would expect it to seek a COM# serial port. In which case you will have to create a symbolic link from the relevant /dev/ttyUSBx to COMx for your Arduino IDE to work.
The right way is to download the Arduino for Linux tar.gz file and extract it to a path of your choice in your Home folder.

I upgraded Ubuntu version 14.04 to 15.04 and now it is working fine!

source: Stack Exchange

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

sort: votes


text:
Why use .h files with .cpp?
At school, our teacher always taught us to use .hpp (C++ Header files) with our .cpp (C++ files). But Arduino seems to use .h files (with .cpp links?).

When someone is programming in C (without C++ compiler) they have the chance to get linked to a .cpp file through a .h file?

So why isn't a .cpp file always with a .hpp file?
What are the drawbacks of using .hpp files with your .cpp files?

This is not to start a discussion on what's best, please provide an answer with arguments that are not based on "what you like to do more".

The extension you use for a header file doesn't technically matter because the compiler never sees it. You could name it with the extension .this-is-a-header-file and it would probably still work.
The compiler only handles the C/C++ source files, typically named .c and .cpp. However, before that happens, the preprocessor goes through and looks for any #include lines. When it sees one, it basically copies the entire contents of the included file into the source file before it gets compiled.
This is normally used to include header files. However, the preprocessor doesn't know or care about different programming languages. All it does is process the raw text so there's nothing stopping you from including any text file you like, with any name or extension.
Choosing to use .h or .hpp is mostly just personal preference. You could certainly argue that it lets you (as a programmer) distinguish between C/C++ code more easily.
However, the reason why .h is more common is probably that C and C++ code is mixed so freely. You can generally compile C code as C++ without any problems, in which case it's the context (rather than the file itself) that tells you if it's C or C++. It's also possible to write a library in C++ which only exposes a C interface, meaning it could be used by C programs.
You could definitely include a C++-specific header file in a C program by mistake. All that would happen is that the compiler wouldn't understand the contents of that header file. Sensible development environments don't link to a project/library when it sees a #include directive (the Arduino IDE is the only one which does this, as far as I'm aware).

So there isn't really a standard for this? Or well, it defines that it doesn't really matter wethether it's a .hpp or .h... interesting...

Also .cxx and .hxx. I've seen those too. Because they look like pluses that fell over, or something.

It doesn't matter which one you use in most cases, but there are conventions.  For example, many libraries have both C and C++ bindings.  You can't put the C++ syntax into a C header, because it wont compile.  In such situations, it is common to have the .h file contain the C header, and a matching .hpp containing the C++ interface (which often, includes the .h and then wraps it in more C++ friendly notation)

@MarkAllen using xx instead of ++ seems to prevent problem with special char is some obscure fs. Maybe there is no real problem, but someone decided to not risk.

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


text:
Multiple SoftwareSerial ports - how to handle the limitations
I am building an access control project which uses two SoftwareSerial ports. One will be used for communication with an RFID reader and another one to receive serial messages via an Xbee (e.g. remote commands). The hardware serial port is used for a cabled serial connection to another remote "server"-Arduino, which then actuates the relays.
According to the Arduino website, the SoftwareSerial Library has, amongst others, the following limitation:  - "If using multiple software serial ports, only one can receive data at a time."
My plan is to poll constantly / on regular intervals both SoftwareSerial ports, e.g. by checking RFID_Serial.available() and XBeeSerial.available(), and if it turns out that data is available, to read it out and parse it accordingly. This obviouosly has to be done in an alternating fashion, i.e. one after the other. My questions are the following.
(1) Can I initialise the ports in void setup()
RFID_Serial.begin(..);
XBeeSerial.begin(..);
... and are they then both actually active simultaneously (i.e. ready for commans like xxxxSerial.available(), or xxxxSerial.read(), or is in this case only the XBeeSerial active, because I it was the last one to be initialised?
(2) If I want to poll one after the other, do I have to "close" one SoftwareSerial port, e.g. by RFID_Serial.end(); and open the other (XbeeSerial.begin(..)) before I can do XBeeSerial.available() or read out by XBeeSerial.read()?

softwareSerial uses interrupts (rather than hardware) to acquire data. Because you cannot run two interrupts at the same time, 2 software serials' cannot receive both at the same time. I'm listing some options below.

Take a gamble. Hope they won't occure on the same time (bad idea)
Manage the flow. Make the other device not send data while one is sending. (Maybe impossible)
Check the priorities, make the XBee's priority vector lower as the RFID, and when you do not get a full/known RFID key, give feedback (with a light/buzzer) so the person will try his RFID key again.

You might want to use the XBEE with the hardware serial. And use the RFID on software serial. IF you're not receiving a lot from the master (since you only send the master which relays he has to actuate?) Why would you actually use two arduino's? The "slave" could, itself, actuate the relays?

@FuaZe: Thanks for your comments. Well, even if both, the RFID and the Xbee generate (the RFID)/receive (the Xbee) data at the same time, is it really a problem, because doesn't the data remain in the respective buffer until it gets read out during the next polling?

@Fuaze: There are several reasons why I use two arduinos. I have a limited number of available wires (3) between the slave and the master and I need a two-way communication. The master actuates three relays (door and two alarm systems), and needs to send the status to the slave, which, upon activation through the RFID tag, displays the status of the alarm system (on/off). The activation of the unit also activates three buttons to toggle the three relays.

The problem is that those buffers are filled by software, and your arduino can only do one software task at once (generally). So if two things send info to your arduino at the same time, there will be a problem. But you're explaining that the master sends the status after an RFID tag? So these van be two software serials as it's not on the same time?


text:
Interfacing Arduino Uno with OV7670 (with FIFO)?
I need help with interfacing ov7670 to Aduino Uno. I know there is a lot of literature available but the problem is that all this literature is for ov7670 without FIFO. I have Ov7670 with FIFO and its a 22-pin image sensor. I haven't been able to relate the available tutorials to my module. Any help in this regard is appreciated. (I need Wire Configuration as well as Code to get images).
Kind Regards,

so your module is different that standard  oc7670? (from first look at the first datasheet from google) the chip itself has its own FIFO does your module have additional IC with FIFO ... how about link to datasheet of your module or at least circuit diagram ...Also as usually for arduino platform what MCU you have and what pins available (Arduino is not processor !!!)....


text:
How to power Arduino only when light is on
I want Arduino to conserve energy and turn it on automatically only when the lights is on. Can I use some kind of light sensor and put it in between power supply and arduino somehow? Ideally light sensor will power from the same power source, if possible.
I'm not an electrical engineer - just enthusiast, so please explain your idea as detailed as possible. Many thanks!

I'm quite sure there are indeed purely-electrical schematics for this. Though you could always use powersave functions on arduino?
You probably want a light sensor, with a comparator and something like a relais. Sure there are no sources for this on the internet? I don't know that much of electronics either.

Beware that Arduino boards can be very power-inefficient. You may want to use a barebones configuration, maybe just an ATmega chip alone. Then you can save significant power by just calling sleep_mode(), and save even more with power_*_disable().

For a chip like the basic Arduino's ATmega, you don't really "turn it off" to save power, rather you put it into a low-power sleep mode.
First, make sure you aren't consuming more power than needed normally.  Make sure unused peripherals like the ADC are off.  If your program spends most of its time waiting for external events, try reducing the clock speed either with a slower crystal or the 8 MHz oscillator, and with the clock prescale register.
Next, implement a sleep cycle.  Turn off everything you can, and program a hardware timer to generate an interrupt at some point in the future.  Enter sleep mode, so the processor stops and only the logic in the counter is still running.  When the interrupt fires, the ATmega CPU will wake up and continue operating, at which point you enable the ADC, use a GPIO to drive your light sensor, and take a reading from it.  If it doesn't meet your conditions, turn it all off again and go back to sleep until it's worth checking again.
In low power design you must be very careful of things outside the processor stealing power.  Watch out for any resistors pulling signals, if the signals are actively drive against the resistor.  LEDs are an obvious issue.  Also watch out for voltage regulators which may have high quiescent current.  And finally beware of peripheral chips - a stock Arduino has an entire second processor sitting there in the USB-serial adapter wasting power.  So you will either need to customize the firmware of that to shut down too, or else use a simpler board that doesn't have one (don't just hold it in hardware reset, as the reset pin has an internal pullup which will then consume power).

If it's OK for it go off (not just to sleep) when the light is off, power it from the lighting circuit. These two parts will do it without messing with the electrics:

The light socket adapter with two outlets is a hardware-store part, probably about USD$3, and the USB charger makes a compact and useful Arduino 5v power supply, USD$6 at Amazon right now. (Apple's little USB power cube might fit better but is more expensive). I use the Nokias for Arduino power supplies and their no-load voltage is just barely over 5v. If you substitute a different one, that would be a worthwhile test to make before you connect it to your Arduino.

Conserve energy?
There are many ways to conserve energy in an Arduino(e.g. Use a USB adapter that does not waste energy as heat, instead of using Battery power)
But if you want to save energy by only switching on the Arduino when light is on, it depends on the intensity of the light.
If it is supposed to switch on only during the day, use Solar Panels to power the Arduino.
Else, use an LDR.

You may keep your Arduino powered, but have it sleep when the lights are
off. During sleep, it would periodically awake to check the light level:
if it's low enough, it goes back to sleep, otherwise it resumes its
work. Here are the detailed steps:

Try to find a power-efficient Arduino or clone (no ON LED, no USB
bridge...) or learn how to build and program a barebones one. If you
can live with a 8 MHz clock, a bare ATmega, or even ATtiny, may
be a good option.
Get an LDR (light-dependent resistor) and an ohmmeter.
Measure the resistance of the LDR at the relevant light levels, and
decide for a value of resistance that will serve as a threshold for
switching on and off. I will call this LDR_THRESHOLD_RES in the
code.
Get a plain resistor with a value close to the previous threshold
(within a factor 10 should be OK), but not lower than 1 kΩ.
This will be your "pullup" resistor, and its resistance will be
LDR_PULLUP_RES.
Decide how often the program will check for the lights being turned
on. This delay, in milliseconds, will be LDR_CHECK_DELAY.
Assign both a digital and an analog pin for measuring the LDR. These
will be LDR_DRIVE_PIN and LDR_SENSE_PIN respectively.
Connect the LDR between LDR_SENSE_PIN and ground; connect the
pullup resistor between LDR_SENSE_PIN and LDR_DRIVE_PIN.
Update the code below (the first 5 #defines) and include it in your
sketch.
Add pinMode(LDR_DRIVE_PIN, OUTPUT); to your setup().
Call wait_for_lights() inside loop(), wherever you want your
program to pause if the lights are off.

#include <avr/sleep.h>

#define LDR_THRESHOLD_RES 25e3  // 25 kOhm
#define LDR_PULLUP_RES    10e3  // 10 kOhm
#define LDR_CHECK_DELAY    200  // 200 ms
#define LDR_DRIVE_PIN        2  // digital 2
#define LDR_SENSE_PIN        0  // analog 0

#define LDR_THRESHOLD_RATIO (1.0*LDR_PULLUP_RES/LDR_THRESHOLD_RES)
#define LDR_THRESHOLD_READING ((int)(1024 / (1 + LDR_THRESHOLD_RATIO)))

/* Sleep until the light is on. */
void wait_for_lights() {
    for (;;) {
        // Sense light level.
        digitalWrite(LDR_DRIVE_PIN, HIGH);
        int reading = analogRead(LDR_SENSE_PIN);
        digitalWrite(LDR_DRIVE_PIN, LOW);

        // Low reading means the light is on.
        if (reading < LDR_THRESHOLD_READING) return;

        // Wait for a few milliseconds.
        unsigned long start = millis();
        do sleep_mode();
        while (millis() - start < LDR_CHECK_DELAY);
    }
}

This should already get your power consumption pretty low. If you want
to save further power, you will likely have to dig into your
microcontroller's datasheet. You can try the various power_*_disable()
functions and turn off all the peripherals you do not need. You can also
try a deeper sleep mode than the default one (IDLE), but then your
millis() clock will freeze during sleep, and you will have to set up
some wake up source if you do not want to sleep forever. The watchdog
timer is a good option.


text:
Alternative Way to Power Components on an Arduino
I have very limited knowledge regarding electronics. Please help me cure my ignorance on the subject of robotics.
I want to power the Arduino Uno R3, US-015 ultrasonic sensor, and the L298N motor controller from a single power source (7.2v). However, I'm not sure if this diagram is correct. If it is functional, will it last that way?

If this diagram is deemed wrong, please suggest alternatives with one power source.
Advance thanks to those who would reply. Elaborate answers would be very much appreciated. :D
Edit: Since it's deemed incorrect, I'm going to power Arduino through the DC barrel jack and power the L298N motor controller through the Vin and the ultrasonic sensor from the Arduino 5v output. Is it wise to do this?

Using a motor controller to power an Arduino or analog peripherals is probably unwise as the source is liable to be noisy. Better probably is to power Aduino from 7.2V into Vin - with a small series resistor from 7.2V to Von and a large filter cap at Vin to ground. Then power sensor from Arduino 5 V. Series R must drop < 2V - probably about 22 Ohms to start.Capacitor at Vin - the larger the better. 100 uF good. 1000 uF better.

@RussellMcMahon Why the 22ohm resistor. The voltage regulator on the arduino will smooth things to 5v. Is it like a low-pass filter? Wouldn't a diode, or inductor be more useful?

In the diagram, there is nothing producing the 5v.

@Gerben Presumably the motor board OUT{URS 5V on Vcc for 7.2V in -  just as most Arduino's accept > 5V on Vin and output 5V.

@Gerben - the 22 Ohm resistor and large capacitor form an RC (Resistor + Capacitor)  noise filter. This greatly redcues motor noise which appears on the 7.2V line. This is vry standard practice in real world installations like ythis. An inductor based filter can be better but RC should suffice.

@RussellMcMahon Well, that's the suggestion I got from the LMR forum.  I'm thinking of powering the L298N motor controller from the Vin and the ultrasonic sensor from the 5v output on the Arduino. I'll power the Arduino from the DC barrel jack. Will this be correct?

If  "the barrel jack" is the 7.2V line and you use a resistor and capacitor as I suggested INTO ARDUINO VIN, must be VIN, NOT 5V, then you are doing as I suggested overall so it's just as correct or not) as when I first suggested it. If LMR forum (who I know not) suggest otherwise you have to choose whose advice to follow. I know whose I would choose :-).

Using a motor controller to power an Arduino or analog peripherals is probably unwise as the source is liable to be noisy.
Better, probably, is to power the Arduino from the 7.2V supply via a noise filtering resistor into the Arduino's Vin terminal.
NBNBNB 7.2V input MUST be to Arduino Vin.
Use a small series resistor from 7.2V to Vin and a large filter cap at Vin to ground. Then power the sensor from Arduino 5 V output.
Voltage drop in series resistor from 7.2V to Vin must drop under 2V.
Rmz is <= Vdrop / Iload
For say 50 mA load Rseries = V/I = 2V max / 0.05 = 40 Ohms .
For 100 mA R <= 2/.1 20 Ohms.
So probably try about 22 Ohms to start.
If Vdrop is > 2V a smaller R is needed.
If Vdrop is << 2V increase R.
For the capacitor at Vin - the larger the better.
100 uF good. 1000 uF better.
Resistor power dissipation is I^2 x R.
So at even 100 mA Pres = 0.1^2 x 22R = 0.22W
A 1/2 Watt resistors would suffice.
A  1 W resistor would do no harm and would tolerate the heat better.

The 22 Ohm resistor and large capacitor form an RC (Resistor + Capacitor) noise filter.
This greatly reduces motor noise which appears on the 7.2V line.
This is very standard practice in real world installations like this.
An inductor based filter can be better but RC should suffice.


text:
Issues with PIR Sensor triggering by itself
I am currently working on my first Arduino project and I am having some issues that I am seeking help with. The robot I am building must have human following capabilities and to do so I am using 3 PIR sensors (One on the front, one on the left and one on the right) and an Ultrasonic Sensor so the robot won't run into a wall or a person it is following. To handle the motors I am using the Adafruit Motor Shield (V.1)
The way I am trying to make this work is as follows.
The robot's main PIR sensor is the one attached to the front. If this sensor reads HIGH then the robot will move forward while checking its distance from any objects in front of it in which case it stops and reverses until there is at least 30cm of space between itself and the object in front. The radius of this sensor had to be reduced so that it only reads HIGH if the person is exactly in front of the robot. This was done using carton paper and black duct tape. Two images of this have been provided below in case this has something to do with my issue.

The other 2 PIR sensors attached to the sides will tell the robot if it should turn left or right. If the left PIR is triggered then the robot will start turning left and keep doing so until the front PIR finally reads HIGH, and then it moves forward. The same thing is done with the right PIR except that it moves right. These PIR sensors are handled using interrupts on the Arduino Mega 2560 board as can be seen in the provided code.
The code I am using can be found below:
#include <AFMotor.h>
#include <NewPing.h>

#define trigPin 34
#define echoPin 32

NewPing sonar(trigPin, echoPin);
int minimumDistance = 30;
int currentDistance = 0;

int calibrationTime = 60;
int redLED = 22;
int greenLED = 24;

int PIR = 26;
volatile int PIR_val = 0;
int PIR_left = 19; // (interrupt 4)
int PIR_right = 18; // (interrupt 5)

AF_DCMotor motorL(1, MOTOR12_64KHZ);
AF_DCMotor motorR(2, MOTOR12_64KHZ);

void setup()
{
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);

  pinMode(PIR, INPUT);
  pinMode(PIR_left, INPUT);
  pinMode(PIR_right, INPUT);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  digitalWrite(redLED, HIGH);
  // Calibration for PIR sensors
  for (int i = 0; i < calibrationTime; i++)
  {
    delay(1000);
  }
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);

  attachInterrupt(4, turnLeft, RISING);
  attachInterrupt(5, turnRight, RISING);
}

void loop()
{
  delay(50);
  currentDistance = sonar.ping_cm();

  if (currentDistance < minimumDistance && currentDistance > 0)
  {
    moveBackward();
  }
  else
  {
    PIR_val = digitalRead(PIR);

    if (PIR_val == HIGH)
    {
      moveForward();
    }
  }
}

void moveForward()
{
  motorL.run(FORWARD);
  motorL.setSpeed(180);
  motorR.run(FORWARD);
  motorR.setSpeed(200);
}

void moveBackward()
{
  motorL.run(RELEASE);
  motorR.run(RELEASE);
  motorL.run(BACKWARD);
  motorL.setSpeed(190);
  motorR.run(BACKWARD);
  motorR.setSpeed(225);

  while (currentDistance < 30 && currentDistance > 0)
  {
    currentDistance = sonar.ping_cm();
  }

  motorL.run(RELEASE);
  motorR.run(RELEASE);
}

void turnLeft()
{
  motorL.run(BACKWARD);
  motorL.setSpeed(150);
  motorR.run(FORWARD);
  motorR.setSpeed(150);

  // While front PIR is reading LOW
  while (PIR_val == LOW)
  {
    PIR_val = digitalRead(PIR);
  }
  // After front PIR reads HIGH
  moveForward();
}

void turnRight()
{
  motorR.run(BACKWARD);
  motorR.setSpeed(150);
  motorL.run(FORWARD);
  motorL.setSpeed(150);

  // While front PIR is reading low
  while (PIR_val == LOW)
  {
    PIR_val = digitalRead(PIR);
  }
  // After front PIR reads HIGH
  moveForward();
}

The first issue I am having is that as soon as the PIR sensors are done calibrating, the robot starts moving forward by itself. Even if I leave the robot alone inside a room with the door closed, after the calibration time passes the robot automatically moves forward on its own.
The other issue I am having is also with the front PIR sensor. While the robot is turning and looking for a human as seen in the 'turnLeft()' and 'turnRight()' methods, the robot will sometimes move forward toward a random direction instead of towards me.
I have already tried replacing the front PIR sensor twice and the sensor itself does not seem to be the issue.
The PIR sensors I am using are the 'HC-SR501' model.
For all PIR sensors, the delay time is set to the lowest possible time (5 seconds) and the sensitivity is set to full.
I welcome any input or suggestions whatsoever. If you would like me to provide any additional information about this project please ask and I will do so.

http://arduino.stackexchange.com/questions/9965/detect-movement-on-moving-robot-pir-sensor
Probably, the answer on your other question will also answer this question.

Try:

turn sensor OFF when robot is moving
turn sensor ON while robot is standing still
look for some prey
repeat from 1 one

Same schema goes with rotating :

rotate to some angle,
stop rotation
detect

xD I was wondering bout it too, but only thinking, not implemented yet!
I think that simple is best, but something advanced with faster reaction would be better!

Could you please edit this answer so that it uses correct grammar? Currently, it is hard to follow what you are trying to say.


text:
Detect movement on moving robot? PIR Sensor
I am working on a human following robot project and I am trying to achieve this with 1 Ultrasonic sensor that makes sure the robot won't crash into something and 3 PIR sensors that will detect human movement.
The robot has an Ultrasonic Sensor and a PIR sensor attached to the front and a PIR sensor attached to the right side and another PIR sensor attached to the left side.
If the front PIR reads HIGH, then the robot will move forward. If the left or right PIR reads HIGH, then the robot will start turning in a 360 degree motion to the left/right side and will keep on doing so until the front PIR reads HIGH, and the robot moves forward again.
I am currently working with this build and I am having issues with the sensors. Sometimes they read HIGH when they shouldn't and sometimes they read LOW when they should be reading HIGH.
So my question is, what can I do to help the PIR sensors with getting the correct reading and is it possible to do so while the robot is turning?
Also, how will calibration work here? Am I able to let the robot turn slowly in 360 degree motion so the 3 PIR sensors will be calibrated with the rooms surrounding or is this a dumb question? If so I'm sorry, I am pretty new to PIR sensors.

UPDATE:
Thanks for the help everyone. I have now replaced the side PIR sensors with Ultrasonic sensors. I have kept the front PIR sensor though. It is working a lot better than with the side PIR sensors and I thank you all for your input.

I don't think its fundamentally possible for a PIR sensor to tell the difference between the an object moving while the sensor sits still and a still object while the sensor moves.

Same, I think  that if you move a PIR sensor around, it's likely to detect 'movement'. I should do it with some distance sensors and then just track whatever is closest to you. So if you stand near the robot, it'll move towards you (and brake when he is close) So he will keep following you. (If you also implement these sensors at the 'sides'). Detecting movement, while moving yourself isn't really going to work. You could let the robot sit until he sees movement and then use range-sensors to track the moving object.

Basically you have a robot and sensors that can detect movement.
There is one caveat though. For the PIR sensors to (non false-positive) detect motion, they have to be stationary (as far as I know).
So with only these PIR sensors it's unlikely that you can track something well.
Tracking something would be done best by using a range/proximity sensor.

The image below, seems to be a cute robot, with eyes.
You could take 3 sensors and place them under an angle (one forward, one forward/left and one forward/right) [picture 2]. Or just have one that rotates (will be more difficult) [picture 1].
You would want the robot to start following anything that comes close (or when one of the sensors sees a difference in distance. And then the robot will try to keep that distance, brake when he gets closer, drive when he gets further.
If that's working, you can implement the sensors at the side, that if suddenly he loses track of the object/person, he'll adjust his alignment so that the middle sensor sees it again. This could also be done by simpler sensors [picture 3]
When the robot gets to close, and the other object doesn't try to run for quite a time, you can make him check for another target. (With a PIR or by rotating and stopping rotating to check range/pir)
I believe this solution is more applicable as with only PIR sensors, as it's usefull to know the range when you're following something. You don't want to bash into it.

Thanks for your answer Fuaze. I will go ahead and use Ultrasonic sensors instead of the PIR sensors then. I just wish I had done more research on PIR sensors before hand ^^.

No point, those PIR sensors can be used to detect the initial movement around the robot anyway, to decrease the amount of ultrasonic sensors needed. And to give a view all around the robot.
And bet you can find another great use of the PIR sensors in another project! You already know how they work, which is great for further usage.

Try using heat detectors(technically speaking, Infrared sensors) (along with >1 Ultrasonic sensors and PIR motion sensors for greater accuracy) with 1 ultrasonic sensor.
Comment if you want more help.


text:
What board to use to send a text message via an arduino board
I am fairly new to arduino boards and I was wondering which board to use. I was looking into the edison board because it has built in wifi and bluetooth.

The GSM Shield will suit your needs. This is a shield, meaning that is a board that will go on top of another Arduino board (e.g UNO, Leonardo, ..., choose whatever you'll need).
This is what it will look like:

To send SMS you'll also need a working SIM card and the GSM library to program the shield. On the previously linked page there are some tutorials to follow in order to check the basic functioning of the setup.

Another option is the Spark Core or Photon.  It's not an Arduino but it's very close.  I have Arduino sketches that I have ported right over with no modification.
The Spark boards are internet-connected and you can send text messages or emails using IFTTT.  It's also going to be a lot more cost effective than an Arduino plus wifi shield, particularly if you can wait until June for the $19 Photon to ship.
You could also use a Raspberry Pi connected to the internet to just do the email part but that's a little more trouble than it's worth.

I actually checked the price for the GSM shield and Wow, I didn't know that it was so pricey. Thank you for pointing that out.

Sure, no problem.  Arduino shields can definitely get pricey depending on what you want to do.

Actually, you should use a Raspberyy Pi if your project involves complex processing in it.
But if the project is very simple, just use one of those Spark Core or Photon.
Using an Arduino and a Sheild to do it is certainly not a good idea, as the Pi is much faster in processing and costs about the same.


text:
Problem reading HMC5843 - Magnetometer in Simulink
I'm having a SparkFun 9 DoF sensor stick including the following components:

ADLX345 - Accelerometer
ITG3200 Gyroscope
HMC5843 - Magnetometer

Im currently working on a project in which I need to calculate the yaw angle, I tried using the gyroscope and the accelerometer for this and found out that it didn't work for the yaw angle but only for the roll and pitch angles.
Im trying to do my implmentation in Simulink where I read the sensors via I2C through an S-function. My sensor stick is connected to an Arduino Mega and it works well for both the accelerometer and the gyroscope but when I try to do the same thing for the magnetometer all the signals have a constant value of zero.
For doing this i include the two libraries wire.h, wire.cpp, twi.h and twi.c. This is the same libraries that are used in many Arduino sketches for reading I2C-devices.
I use the following code for the initialization:
    if (xD[0]!=1) {

  # ifndef MATLAB_MEX_FILE

  Wire.begin(); // start i2c bus

  Wire.beginTransmission(MAG_ADDRESS); // 0x3C
  Wire.write(MAG_MEASMODE);            // 0x02
  Wire.write(MAG_MEASMODEC);           // 0x00
  Wire.endTransmission();

  # endif
  // initialization done
  xD[0]=1;
}

For the output I use the following code
// wait until after initialization is done
if (xD[0]==1) {

# ifndef MATLAB_MEX_FILE

    unsigned int i = 0;         // counter var.

    unsigned char lb_mag[6] = {0};

    int temp_mag[6] = {0};

    Wire.beginTransmission(MAG_ADDRESS); //0x3C
    Wire.write(MAG_XMSB);                //0x03
    Wire.requestFrom(MAG_ADDRESS,6);     //requesting MSB,LSB of XYZ-component
    while (Wire.available()){
        lb_mag[i++] = Wire.read();
    }

    Wire.endTransmission();

    temp_mag[0] = (lb_mag[0] << 8) + lb_mag[1];  // convert x reading to int16
    temp_mag[1] = (lb_mag[2] << 8) + lb_mag[3];  // convert y reading to int16
    temp_mag[2] = (lb_mag[4] << 8) + lb_mag[5];  // convert z reading to int16

    for(i=0;i<3;i++){
       magnet[i] = temp_mag[i];
    }

# endif
}

Does anyone have any ideas on why this does not work? As I mentioned before it works for both the gyroscope and the accelerometer. Anyhow, all help is appreciated! Thanks in advance!

Are you sure you have the correct address for the magnetometer? I mixed up the accelerometer and magnetometer and naturally got zeros on all outputs.


text:
Is it possible for a HC-05 Bluetooth module to have multiple slaves
For a project I am interested in using the HC-05 Bluetooth module to control five LEGO Mindstorms Bricks simultaneously. For this to work the Bluetooth module will obviously have to be paired / connected with the five bricks at the same time. This means that the HC-05 Bluetooth module will have to be master in the piconet and the five bricks the slaves.
Is there anyone who has any experience with using the Arduino Uno and HC-05 Bluetooth module to send data to multiple, connected, slaves? If not, are there any alternative Bluetooth modules? And if Bluetooth modules compatible with the Arduino Uno cannot connect to multiple slaves at the same time, are there other ways that an Arduino can control multiple Bluetooth slaves at the same time?

Would it be possible to have multiple slaves and talk to each of them individually? I don't need multiple simultaneous connections but one device talking to multiple and I have to be able to set which device it talks to when and what information is passed.

After some research, it looks like multiple slaves aren't possible with this particular module.
According to Wikipedia the Bluetooth technology allows a master to communicate with 7 slaves, but this option isn't implemented in the HC-05.

I feared as much. Would you happen to know if there are any other Bluetooth modules or shields that support multiple slaves? Or that are worth looking into. Also, would you happen to know how long it takes for the HC-05 module to disconnect / connect to a Bluetooth device?

No I never used any Bluetooth module so I can't help you, sorry. Google is still an option though.

The connection/disconnection takes about 2/3 seconds to be achieved.

Sadly that'd take too long for it to be practical.


text:
7-Segment Common Anode
I accidently bought a "Common Anode" 7-segment display instead of a "Common Cathode".
I understand that the polarity of the leds within the display is 'reversed'. So instead of putting the common pin on GND I have to put it to 5v (with current limiting resistor)
My questions on this are:

Can I still use only one current limiting resistor on the common pin? Instead of a resistor on every segment pin.
Can I use the pins from arduino to drive it (withouth pull-up/pull-down?) By making the signal LOW the current will flow from 5V common anode to the arduino and thus the segment wil light?
Can I still use a shift register to drive the segment led? (By inversing the outputs (in software))

Obviously I would like to have wiring more like this (but then I would ofcourse change  the GND line to a 5V line.

The wiring below is the worst-case wiring I can think of.

^ So can I avoid this, when using a Common Anode 7-segment display or am I forced to buy a Common Cathode 7-segment display?

Both thanks for the help and explanation!
I was able to test the segments :) (They arrived today)
They'll fit nicely in my "Alarm clock" project.
For further reference, be sure to read both answers, especially note that the maximal sink current for all the pins together is different as for each pin itself.

@mathsman, are you sure that there are small 7 segment displays that consume 80mA per chip? That would correspond to ~ 10 mA per segment. I've been looking around a lot and haven't found anything that matches those specifications. The closest that I have found is the yellow displays here:
http://www.jameco.com/Jameco/Products/ProdDS/24782.PDF But those are still 20mA / segment, so ~ 160mA total. I'd love to find a concrete example of a display that can be driven directly from the arduino without requiring a bunch of transistors.

You can use a single resistor on the common pin if you want. The problem is that lighting up multiple segments at the same time will substantially reduce the brightness of each one. You could work around that by lighting each segment one at a time in very quick succession though.
It should be possible to control the display directly from the IO pins by setting them LOW. In this configuration, they will be sinking current (rather than sourcing it). It depends on the specification of the display and on what resistor you use though.
Basically, try to keep the current below 20mA and it should be OK (assuming you're using a standard 5V Arduino). For example, if each segment has a forward voltage drop of 2V, you would want to use a resistor of around 180 Ohm.
Controlling the display directly from a shift register is probably not possible, although once again it depends on its specification. Shift registers usually aren't designed to sink enough current so you'll need something like a transistor on each output.

So, if I find out how much current my shift register can sink, I have to use a resistor that limits the current to this level (taken into account my arduino is 5V). Though the brightness of the led's will be lower the less current flows through.
And by sourcing it, the only problem would be sourcing too much current to the LED's thus be safer for arduino/shift register than sinking it in most cases.
Basically I should buy "Common Cathode" next time :) (did check it on the RGB leds and 8x8 segment I bought though)

@FuaZe There will be a limit on how much current the Arduino or shift register pins can safely source too, so it's not necessarily any safer than sinking.

Peter R. Ah, ofcourse, I was thinking that sourcing too much will cause your LED to fail, but yeah, it's not safe to rely on that.

Sorry about the crudity of my image, but you don't always need those transistors. Peter has already said so, but I wanted to explain a bit further.

The only thing is that you need to set a pin to LOW to light up the led, and HIGH to turn it off. Just use a ! to make your code more intuitive if your like. So e.g. digitalWrite(segmentA, !HIGH)
Some limitations. A pin can sink up to 40mA (no problem here), but the total sink current for the digital pins 0 to 4 shouldn't exceed 100mA. The same goes for pins 5 to 13. And the same goes for the analog pins. So either limit the current through the leds to around 10mA, or make sure no more than 5 leds are lit at the same time, or connect half of the segments to on of the above mentioned groups, and the other half another (f.y.i. analog pins can be used just like digital pins).

Thanks for the heads up on the total sink limitation!
I didn't know that, what would go wrong if I sink more than 100mA?

Fry the input pin, fry the entire chip, unstable behavior, having less current going through the pins (dimmer leds), who knows. The ratings are conservative, so you're probably fine if you go a little over.

PS I prefer common anode displays. Easier to wire.

How's common anode easier to wire? The pic of my fritzing drawing is a common cathode, the only thing is that you have a GND and not a 5V?
And I think arduino can source more current than sink, so it should be safer for your arduino to source, or you'll have brighter segments?

Like I said above, you are going to hit the 100mA limit. Easiest way to solve this is by adding transistors. Having the transistors at the low side, sinking the current, means you can always use regular NPN transistors. Sourcing the current can be done with NPNs but only if you use the same voltage for the leds, as you do the arduino. Otherwise you'd need PNP which are a bit of a pain (to me at least). If you are just using resistors, there is no real difference. Source limit is 150mA, so that's a bit higher. PS see edit above.

PS group restrictions for sourcing current are different than sinking 1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.

Peter and Gerben have already said what is needed , but I wish to explain things even further.
A normal small 7-Segment display consumes only 70-80mA when all segments are HIGH.So you can use the Arduino directly without damaging it. Also note, depending on the quality of the project, you could either use a common resistor for all segments, or use separate ones. Separate ones will give much brighter light and better quality.
A medium size one will require max consumption of around 400mA current, so use cheap transistors.
A large size one will require max consumption of upto 1.5-2A current , so use MOSFETS or other high current Transistors.
An Extra Large one will require max consumption of upto 10-25A current, so use good MOSFETS or maybe even Relays.
Usage
Small- Wrist watches
Medium- Small clocks
Large- Big clocks
Extra Large- Very big clocks like ones in Railway stations


text:
Arduino voltage drop while communicating with another Arduino
I have an Arduino Uno rev 3 and an Arduino Nano in my Setup. I want to create a proof of concept, where one Arduino triggers the other via the Digital IOs.
Arduino 1 sets a blinking signal on a digital pin (500ms delay between high/low), which is received by arduino 2. If the signal is high, Arduino 2 triggers a LED (digital pin to LED+; LED- over 330 Ohm resistor to ground), so the signal gets looped through somehow. The grounds of the two Arduinos are connected, too.

Code Arduino #1:
void setup() {
  DDRD |=_BV(PD7); //Sets Digital Pin 7 as Output
}

void loop() {
 PORTD |=_BV(PD7); // equivalent with digitalWrite(7, HIGH);
 delay(500);
 PORTD &=~_BV(PD7); // equivalent with digitalWrite(7, LOW);
 delay(500);
}

Code Arduino #2:
void setup() {
  DDRD &=~_BV(PD7); //Sets Digital Pin 7 as Input
  DDRD |=_BV(PB0); //Set Digital Pin 8 as Output
}

bool set = false;

void loop() {
  if((PIND&_BV(PD7))==_BV(PD7)) { //true if digital pin 7 is set
    if(!set) {
      //PORTB |= _BV(PB0);
      digitalWrite(8, HIGH);
      set = true;
    }
  } else {
    //PORTB &=~_BV(PB0);
      digitalWrite(8, LOW);
    set = false;
  }

}

But instead of emitting a bright light, which can be seen if connecting the blinking signal directly to the LED, it emits a faint light. The voltmeter also shows an significant Voltage drop. Whilst the digital pin should have a voltage of ~5V when set to HIGH (never reached because of inner resitance inside the arduino), it measures about 1.6-1.8V.
I also switched the both Arduinos which showed the same result, so it shouldn't be a hardware defect.
Thanks in Advance!

Draw a schematic. That text description is very difficult to follow.

How are the two arduino's powered and at what voltage?

Both powered via USB, schematic is following

While you're at it, show us the code that's running on Arduino #2 as well.

Added Schematic and code sample

the line DDRD |=_BV(PB0); should be DDRB |=_BV(PB0); currently PB0 is set as an input so when you set it high it is just turning on the pull-up resistor, which is basically adding another ~10k in series with the LED, hence the dim light.

Works like a charm, thanks i didn't see that one

A couple of delays in the Arduido #2 if(!set) { } else { } might allow the LED to stay on long enough to be seen.
At the moment this is rapidly switching the LED whenever the digital pin7 is set.

Thought about that one too, but the else block is in another scope. The else condition reacts on wether or not the signal is set, and not the bool! The nested if(!set) has no else block and is encapsulated in the wrapping if.
For simplification, you could add an else block containing a return.

Misread that one.


text:
SoftSerial freezes on comparing getInt to int
I have a robot application on my Arduino which basically takes values from a SoftSerial instance on my 0/1 pins (connected to a Bluetooth board).
From the 'driver station' I send speed values to the Arduino through the aforementioned Bluetooth controller. The freezing happens when I compare the data (an integer) to a local integer (i.e 500). If I send the reverse command, I'm actually sending the int 500. If I compare my SoftSerial data like so:
if(softSerial.parseInt() == 500)
{
 //Reverse
}else{
 //Forward
}

it freezes. It only happens when I'm using my SoftSerial stack over Bluetooth, over USB it doesn't freeze. What are my options?

Why are you using software serial on pins 0 and 1? Why not hardware serial?

@PeterR.Bloomfield would I have any issues uploading programs to my Arduino if I do?

freezes permanently or freezes for one second? does the BT message have a whitespace character after the 500?

@BrettAM freezes permanently. It doesn't, so maybe I should do a contains method?

@KeatonBurleson What you do with pins 0 and 1 when the program is running won't affect upload. The only potential issue is having something else physically connected to those pins while the upload is happening. It depends on the specific hardware though.

Have you tried looking at the raw data coming over as opposed to trying parseInt()? Also I wonder if something w/ the Bluetooth controller is interfering with SoftSerial, but I don't know the specifics of what you are using. Are you just connecting 2 wires from the controller to the Arduino and that's that?

@sdcharle no I haven't. I shall soon enough. Its two wires, to TX/RX/

There is no point in using SoftwareSerial on pins 0 and 1, as you have HardwareSerial for that. Whatever the sketch does once it starts will not affect whether or not it uploads. If you have something connected to pins 0 and 1, during the upload, that may well stop the upload working, but what the sketch does afterwards does not.
It is hard to tell from your snippet, but if you also have activated HardwareSerial - eg. Serial.begin(9600); - then the hardware takes over those two pins and SoftwareSerial won't work anyway.


text:
Questions Concerning Arduino Compatible Boards
I've seen an Arduino-compatible board called Bluno from DFRobot. I'm curious if a shield, specifically the DFRobot motor shield can be connected to the Bluno.
Can anyone confirm if it can be connected with a shield?

The Bluno is identical to the Uno, except the USB-to-serial chip, also supports BT. So it won't be a problem.


text:
Dallas Temperature Sensor DS18B20 not showing correct Result with Ethernet Shield
I am using Arduino Uno R3 board and a wiznet W5100 ethernet Shield. The temperature from the One wire sensors before using Ethernet Shield was showing correct. However later after connecting the shield, the temperature is showing to be 85. The server and everything else works fine, but the data is all wrong. Now I am pretty sure the connections are correct and it is not in parasite mode. Any suggestions of how I might get the accurate reading ?
/*
  Web Server

  A simple web server that shows the value of the analog input pins.
  using an Arduino Wiznet Ethernet shield.

*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
            0xF0, 0xBF, 0x97, 0x67, 0xF6, 0x98
        };
IPAddress ip(192, 168, XXX, XXX);

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
EthernetServer server(80);

void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    sensors.begin();
    while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
    // start the Ethernet connection and the server:
    Ethernet.begin(mac, ip);
    server.begin();
    Serial.println(sensors.getTempCByIndex(0));
    Serial.print("Siddhartha Temperature ");
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
}

void loop() {
    // listen for incoming clients
    EthernetClient client = server.available();
    if (client) {
        Serial.println("new client");
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();
                Serial.write(c);
                // if you've gotten to the end of the line (received a newline
                // character) and the line is blank, the http request has ended,
                // so you can send a reply
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println("Refresh: 2");
                    client.println();
                    client.println("<!DOCTYPE HTML>");
                    client.println("");
                    // output the value of each analog input pin
                    for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
                        float sensorReading = sensors.getTempCByIndex(0);
                        client.print("Temperature ");
                        client.print(analogChannel);
                        client.print(" is ");
                        client.print(sensorReading);
                        Serial.println(sensorReading);
                        client.println("
");
                    }
                    client.println("");
                    break;
                }
                if (c == '\n') {
                    // you're starting a new line
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
                    // you've gotten a character on the current line
                    currentLineIsBlank = false;
                }
            }
        }
        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disconnected");
    }
}

The power-on reset value of the temperature register is 85 degC. Is it possible that something is interrupting the power to your sensors?

I highly doubt that ! I checked it using the multimeter, and everythings connected just as fine.

It looks like digital pin 2 might be connected (solder jumper) to the INT pin of the W5100. Try using pin 3 instead.

The Solution was actually much simpler. Apparently the Ground on the voltage I/O ports wasn't the right place to connect the ground terminal of the sensor. rather The Ground of the Digital I/O should be connected. Mistake retrieved by trail and error!! Its working just fine now.


text:
Overriding main function in Leonardo
I've trying to write my code in plain C++ dropping out the Arduino's IDE. Although I've succeed in compiling the code, whenever I try to upload it to the board it doesn't run, seems that it stucks at some unknown point.
After that, everytime I try to upload a new code to the board it stops responding and avrdude throws this message:
$ ino upload -m leonardo -p /dev/ttyACM1
/dev/ttyACM1 doesn't exist. Is Arduino connected?

It doesn't matter if I unplug and then plug again the board, that message is still showing up.
In order to restart the board, I open the Arduino IDE and then I upload any sketch, then the board comes to live again.
The first time I tried overriding the main() function and the program didn't run I thought it was the tool I was using at that moment, arduino.mk, the one that was doing something strange.
Then I tried the ino tool, but the result was the same.
I don't think avrdude is failing because it actually uploads the .hex to the board.
My original main() code was:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
    return 0;
}

Then I tried to mimic the one that comes with Arduino:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

#if defined (USBCON)
    USBDevice.attach();
#endif

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }
    return 0;
}

Sadly, with both codes the board gets stucked at some point.
While I figure out how to solve this issue I've been exercising this solution inside a sketch:
const int LED_PIN = 13;

void setup() {
}

void loop() {
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
}

Any ideas that led me to a solution? Thank you!

Solved!
It was a (big) silly mistake of my own. I overloocked the init() function right after entering the main() function. I'm shure it initializes the hardware and the entire system, so my board stucks when I skipped it.
So my code now looks like this:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    init();

#if defined (USBCON)
    USBDevice.attach();
#endif

    pinMode(LED_PIN, OUTPUT);

    while (1)
    {

        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }

    return 0;
}

BTW, the mix: Arduino + Vim + ino, rocks! Now I can do whatever I want from the console :)


text:
Having trouble bootloading my Two-Up printer
I am following these instructions to set up my Two-Up 3D printer, and I have no problems all the way up until step 18.  The board uses the arduino IDE to burn the bootloader, which is why I am posting this here.
I have my board set to "[BootloaderCDC]Teensylu/Printrboard" in the tools menu, and I have selected the appropriate COM port.  I use arduino for tons of other things so I know my way around the IDE reasonably well, but I have never encountered this error before so I'm not quite sure what to make of it or how to fix it.
Here is the error.
I have the red board (version 2) and I am using Arduino version 1.0.6.  As far as I can tell, I have perfectly followed all of the steps up until this part with no noticible problems.  I remembered to bridge the boot pins and everything.
In the video the guy says there may be an error when you go to program the board but my error is way different than his error in the video, and hbe says you should hear the dissconnect and reconnect sounds as the board gets reset after a bootload (I didn't hear them).
Anyone have any idea how to fix this issue?


text:
Not able to upload any code to Arduino Uno
NOTE: Using the Arduino Uno
I am WORKING on a project that I have to submit in a few days. My arduino was all set up and was working fine.
Project:Arduino controls a 9v motor depending on the command given. As the arduino only provides 5v , i added a 9v battery to it through a transistor
I decided to add new code into the arduino but when I tried it failed. I have uploaded code thousands of times before (successfully) all of a sudden the IDE keeps giving the following message

avrdude: ser_open(): can't open device "\.\COM3": Access is denied.

I have looked up for a lot of solutions on this forum and elsewhere. Here are the things I have tried so far:

Changing the COM port
Disabling all the other devices CONNECTED to COM
Tightening the CONNECTIONS
Re installing all the drivers and the IDE
Rebooting the system
Using another laptop to upload code

All the above have given me the same output for some reason. The built in LED light and the power LED switch on when the board is CONNECTED to a power source (my laptop). Could the board have been damaged by any chance ? How can I check if the board is spoilt ? Should I buy a new board ?

Have you tried this on another computer?

@AnnonomusPenguin yes

@AnnonomusPenguin I get the same error

Well, either your board is fried or you keep making the same mistake when installing the drivers on all of the computers. Have you tried reinstalling the Arduino bootloader, also?

According to this solution: http://www.instructables.com/id/How-to-upload-codes-to-Lilypad-Arduino-Without-FTD/ You may use your board instead of Lilypad on the link above, to program your board, you may make a connection the same in URL above. I guess this will solve your problem.

Could you please tell us how you exactly connected the battery to the UNO, a MS paint drawing would be enough.

@Avamander turns out the arduino was fried, got a replacement and it works well

I have a post Have I bricked my Arduino Uno? Problems with uploading to board - that describes various tests you can carry out to isolate where the problem is.

Have you tried changing the Microprocessor in the Arduino Uno?
An AtMega320P is much cheaper than new Arduino, and usually only the microprocessor gets spoilt, rest of the board remains intact.

Could be the OS not allowing the application to access the COM ports, there is a terminal command to give the Arduino IDE access to the specific COM port.

Remove all device connect to uno, and upload code to uno. Because,
your device like motor will confuse uno.
Check you usb to serial device.
Check your uno

All the connections are removed . Still does not work

How do I check if the uno is spoilt

Maybe change a uno? I meet the same stage when I try to connect a motor to micro pro. I fixed that by change a micro pro.

So basically I need to buy a new one?

yeah, I think so.

Check the device that the IDE says you're connected to.
http://forum.arduino.cc/index.php?topic=51489.0


text:
Ultimate GPS Logger Shield : Soft Serial Sketch Error
Im using a OSEPP Uno R3 Plus to connect with a Ultimate GPS Logger Shield. I am currently working through the Adafruit Ultimate GPS Logger Shield pdf. When connecting in Soft Serial Mode and loading a parsing sketch. In the com window my values are showing but unreadable. I have included an image. Any help is appreciated.

You should describe your problem with further details if you expect some help. Currently I get no idea of what you have done so far to get there (eg source code). It seems likely you have an issue with Serialconfiguration, but without any code, it is hard to tell. Also you did not mention how the serial console is setup (speed in particular).

jfpoilpret > My apologies for not including enough information and details. But your comments did lead to me resolving my issue. I did not change my baud rate to match the baud rate of the source code and the script is working now. Appreciated.


text:
How exactly is voltage measured on an Arduino?
How do the analog pins on an Arduino measure voltage?
Do they either measure current and calculate the voltage with Ohm's law? (If so, why can we only read voltage and not current directly?)
Or do they compare the unknown input voltage with a known internal one? (If so, how does that work? What's the known voltage?)

Known voltage is usually provided by a diode or similar reference. The atmega328p chip has a separate aref pin so you can choose your own reference.
An ADC or analog to digital converter http://en.m.wikipedia.org/wiki/Analog-to-digital_converter is a collection of comparators. A comparator is a logic gate that simply tells which of two inputs has more voltage. This aref voltage is divided evenly into 2^10 values (it's a 10 bit ADC). Then the incoming signal is compared against all of these and the largest comparator which triggers is the reading you get in your arduino code.

A flash converter is a collection of comparators. The ADC in the ATmega328/1280/2560 is a successive approximation converter, which uses a DAC and comparator. This is all described in the datasheet.

Thanks! Really satisfying to finally know how it works. Would you mind quickly explaining how comparators are triggered, if you happen to know?

The Arduino uses a 10 bit Analog to Digital Converter(ADC). A good ADC  is made such that it has only as many comparators as is the resolution of the ADC (in BITS) . Therefore the Arduino should have only ten comparators.
More detailed:
Comparator Number      Trigger voltage
        1.(LSB)..............................       (5/1024)V
        2........................................             (5/512)V
        3........................................(5/256)V
       ..........and so on till
        4.(MSB)..............................(5/2)V
So, for a voltage of say 2.75V, you will get a value of 768(11000000 in Binary)
Update:If you choose to give and use a separate Ref Voltage to the Arduino, It replaces the 5V with the new ref voltage.
Update 2: Sometimes a single comparator may be used in exchange of all 10 comparators.i.e., it is used to trigger all the bits .But the voltage at which each bit is triggered remains same.

@PenguinCake The simplest comparator is an Op-Amp.Search Google for more info on Op-Amps.

Op amps make terrible comparators. And the ADC in AVRs only uses a single comparator.

Are you sure? Is it a single comparator or a single device that has 10 comparators?  While it is possible to use a single comparator, it is usually much slower.

It is a single comparator. It is used to compare the input versus the output of a DAC. I can't think of any way of using 10 comparators that would be any faster than using 1.

When using single comparator, it uses 2 cycles per bit, whereas with 10 different ones, it takes one per bit.

The Arduino uses a analog-to-digital converter. For instance on the Arduino Uno there is a 10-bit ADC. Therefore the resolution is 2^10 bits which is 1024 different representations. As the Uno runs at 5V, each step represents 4.9mV.
The actual inner workings of the ADC can be quite complex and I don't exactly know which specific type it uses, but there can be many ways. One example is measuring time to discharge of a known capacitor. Another is comparing the voltage to the running voltage and using a counter.

"The ATmega48A/PA/88A/PA/168A/PA/328/P features a 10-bit successive approximation ADC."

I'm not sure what the answer is or why no one has addressed the second part of your question. To calculate current you need to know voltage and resistance (I=E/R). The ADC is giving you the voltage but I don't know what value to use for resistance in order to calculate the current. I do better with digital electronics but I suspect you might be able to use a resistor divider network to measure the voltage drop across a known resistor to measure current but do not take my word for this.


text:
Weight sensor / load cell not working
I just got all my parts together that I needed for my project and put everything together like said here: https://web.archive.org/web/20140303140445/http://cerulean.dk/words/?page_id=42 but the serial monitor gives me all random outputs:
analogValue: 865.52
             load: 43.27584
analogValue: 865.54
             load: 43.27717
analogValue: 865.50
             load: 43.27517
analogValue: 865.43
             load: 43.27151
analogValue: 865.32
             load: 43.26601
analogValue: 865.45
             load: 43.27255
analogValue: 865.45
             load: 43.27241

So I can't calibrate everything to even continue, what is wrong? I checked all my connections like 50 times and everything is wired up like shown in the tutorial.
Here are my parts:

INA125P:
http://www.reichelt.de/INA-125-PA/3/index.html?&ACTION=3&LA=446&ARTICLE=147252&artnr=INA+125+PA&SEARCH=ina125p
Load cell from a simple 5kg kitchen scale (tested it before removing
and it worked)
10 Ohm resistor

Thank you in advanced, Greetings

Doesn't look random to me. Pretty consistent. Did you calibrate, and update the values for analogvalA and analogvalB?

It always returns something around 866 - so I can't really set those values.

Does the value change if you place some weight on it?

Sometimes - but most of the time not, it stays at like 866.

I solved it by replacing the resistor with a potentiometer.

You might be driving the amplifier to its limits, and getting a value at its limits.
The INA125 isn't a rail-to-rail amplifier, so if you are wiring it up to ground and +5V as described, its output is limited to be between 0+1V=+1V and 5V-1.7V=+3.3V, so it would be easy to saturate it and bump up against those limits and give you a constant value.
If you are using the 10ohm resistor as the INA125 gain, the gain G=4+60000/10=6004x so the input voltage difference needs to be between 0.00016V and 0.00055V volts to be unsaturated within its output linear range.  If it is outside of those limits, the amplifier will act as a comparator.
You could check this by putting a voltmeter on the output of the amp and measuring what is is and if it changes.  If it isn't near 2.5V when the scale is unloaded and is saturated at the limit of the amp, then you might need to balance the loadcell closer to zero so it doesn't peg the scale, or reduce the amplification.

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


text:
TCCR1A and TCCR2A on Leonardo
I'm trying to use the TTS library for Arduino on an Arduino Micro board, which is based on the Leonardo. When I try to compile my sketch I get some errors;
/libraries/TTS/TTS.cpp: In function 'void soundOff()':
/libraries/TTS/TTS.cpp:355: error: 'TCCR2A' was not declared in this scope
/libraries/TTS/TTS.cpp:355: error: 'COM2B1' was not declared in this scope
/libraries/TTS/TTS.cpp: In function 'void soundOn()':
/libraries/TTS/TTS.cpp:382: error: 'TCCR2A' was not declared in this scope
/libraries/TTS/TTS.cpp:382: error: 'COM2B1' was not declared in this scope
/libraries/TTS/TTS.cpp:382: error: 'WGM20' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'TCCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'CS20' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'WGM22' was not declared in this scope
/libraries/TTS/TTS.cpp:384: error: 'OCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:385: error: 'TCNT2' was not declared in this scope
/libraries/TTS/TTS.cpp: In function 'void sound(byte)':
/libraries/TTS/TTS.cpp:424: error: 'OCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:425: error: 'TCNT2' was not declared in this scope

Googling revealed that the Leonardo uses different timers. And other things I don't understand! But I couldn't piece together an answer beyond that.
What are the correct constants to use for Leonardo boards, and is there a way I can update the library to work across both?

The hilarious part is that the Arduino libraries provide MCU-independent ways to do all that and this code completely ignores all of them.

@IgnacioVazquez-Abrams Great news! Do you have a link on how to use that feature of the library, or an example please?

This "library" is written specifically for the ATMega328 (not the ATmega32u4 inside the Leonardo).  You should be able to port it. Not hard, but not also a task for a beginner.

Eh. I just noticed that it uses parameters not controlled by the basic libraries. You'd need to find a more fully-featured PWM library for it. But barring that conditional compilation would be the way to go.

Do you have to use a Micro? Your code will probably work on a Uno (or some other ATmega328 based board). To check, select Uno under the Tools->Board menu and then try to compile it.

Apparently the library in the OP's link has been updated to support the Leonardo, so this problem should now be solved.

This is the Leonardo patch in case its useful to anyone https://github.com/jscrane/TTS/pull/6/commits/d84cbd2eb39e513e62b4f33a55ccfad412f5aec8


text:
MP3 Shield stacked on DMX Shield - Arduino Uno
We are using Arduino Uno revision 3, with TinkerKit DMX Shield rev. 4 and Sparkfun Mp3 Shield.
We uploaded the Mp3 Shield example called FilePlayer and after we open the serial monitor, the interface is there and working. The problem is that it won't output the music from the SD card.
If we ONLY stack the Mp3 Shield onto Arduino, it works.
Is there some king od incompatibility between the DMX and Mp3 Shield, and if there is, what would be the solution, maybe some kind of bypass, since we aren't that familiar with what pins the DMX shield uses for it's purpose. ATM the Tinkerit site is down so we can't acess the TinkerKit DMX Shield datasheet.

Yes, overlapping is a problem, by default the MP3 Shield uses digital pins 2(DREQ),6(mp3CS),7(mp3DCS),8(RST),9(SD-CS),11(MOSI),12(MISO),13(SCK)
The Tinkerkit DMX Master Shield R4 uses 2(RE-ENn),3(VTX),4(VRX),5(DE-EN),6(D6)
So there are conflicts with D2 DREQ vs RE-ENn and D6 mp3CS vs D6.
The DMX Master Shield basically converts the UNO's serial to DMX. If nothing is at first included into the Sketch for this, then the problem is with only D6. Leave this jumper OFF. And I suspect the MP3 Shield will work stacked.
To use them together you can move the pins, as demonstrated at https://www.youtube.com/watch?v=behMgV3tUr4. Noting that is for different pins. And of course you will need to subsequently change their definition, in the sketch.

We swapped pins D2 -> D5 and D6 -> D10 following your tutorial, changed the input declaration in the SFEMP3ShieldConfig.h script and after we plugged in everything it still didn't play (Arduino , stack DMXShield and MP3Shield). We removed the DMXShield and stacked just the MP3Shield (still with the bypass), and in the interface used the BEEP test, and it works. But the music from SD card is now playing just for 1 second and stops.

Please note that D2 on the Arduino UNO is a interrupt pin for INT0. The default behavior of the SFEMP3 shield's library is to use interrupts. As per your YouTube comment you moved D2 of the SFEMP3. I would not recommend moving this wire. As it must be moved to another INTx pin. And on the UNO that is only INT1(D3). Rather I would recommend moving the DMX shields with this technique to pins not used by the SFEMP3 shield. That is why it plays 1/2 second and stops there is no IRQ to do a refill. Did you leave the D6 jumper OPEN? that is likely the hot problem, blocking the SdCard.

I would recommend a simple Debug technique of using jumper wires. Stack the MP3 on top of the UNO and Jump all the wires from the MP3 to DMX. This emulates it being stacked. Then start pulling wires until it works. Or the opposite. start with just GND and VCC and then add wires until it stops. Bingo you will know what broke it. and then can learn from the schematics as to why. I have learned very little from what works. But much more from what does not.

Thx for the continuous support. It still doesn't work, but your advices have been very educational. We did as you suggested: we wired the MP3 interupt pin (D2) to the D2 on Uno. And instead, made the bypass from D2 to D5 on the DMX shield. As for the D6: we wired the MP3 D6 to Uno D6, and bypassed DMX D6 to D10. All of this to prevent the DMX from getting into the MP3's wheels. To answer you question, no, in any of our attempts, the D6 was never "cut-off" without being wired to another pin). Although the serial monitor didn't show any errors, the beep sound test and track made no sound.

We had also tried using Analog pins for bypass since on the MP3 shield, according to Sparkfun's docs., pins free to use for other than the MP3 itself are just D5 and D10 + the analog ones, and always the same story: MP3 alone works as it should, but as soon as we bring in the DMX it stops working. On the side note, the DMX always work as he shuould, bypass or no bypass. No problems there. Our next step is the Debug technique as you recommended, to find exactly where the conflicts happen. Maybe there is  something more that the DMX uses, other thanD2 and D6? Will post results tommorow.

We solved the communication problem! The conflict was only on D4(VRX) with the DMX Shield, we used the Debug technique and started with just the GND and VCC,, started to add wires. D4 is apparently the only one blocking the MP3 Shield from playing the song. In our Script for the DMX Shield we added the function to play the song for the MP3 Shield and it worked. Thank you for the support!

Hmm. I see d4 affects the boot mode of the vs1053.

yes, D4 needs to be LOW as to put the VS1053 into MP3 mode. HIGH will put it into Real Time MIDI mode. The Tinkerkit DMX Master Shield uses D4 as the Receive from RS485 and drives it into the D4 of the Arduino. Where RS485 is normally HIGH, jamming the VS1053 into MIDI mode. Remove R6 of from the Tinkerkit DMX Master Shield. And jumper the center of the RX-SEL to any available pin on the UNO. THen when you define your SoftwareSerial port use that pin instead of 4 as the RX.


text:
Modify the call stack of interrupts on Arduino
I'm working with Arduino's libraries. And my interest in the possibility to change the call stack of the SPI interrupt, this because I want: after the interrupt happen, the program could jump to other function and not to the interrupted address.
I mean:
This is the Main code.
void loop ()
{
    func();
}

void func()
{
   // code
   // here happens the ISR interrupt
}

ISR happens inside func()
ISR(SPI_STC_vect)
{
    // code
    // SPDR = 0x00; // MY ANSWER to SPI
    // MODIFY CALL STACK TO GO TO LOOP()
}

Now, after answering the SPI, I want to go back to loop() instead of continue func().
How can I do this?
Thanks for your help.

For what reason (or purpose) you don't want to return to the interrupted code?

Since the ISR entry code itself is probably pushing stuff on the stack, on top of the return address, you will have to write your ISR in assembly. This way you can pop the return address first thing in the ISR. Also, make sure func() is not using the stack and not touching the callee-saved registers. You may want to write that one in assembly too.

Arduino is open source, so just modify the ISR to set a global flag when ran. Within func() just check for this flag and return when the condition is met. Little can be offered as little contextual information is given. To modify the stack you would have to work with avr assembly, but either way you must modify the ISR
Something like the following would work, but performance depends heavily on your application.
#define SPI_ISR_RAN 0x00
static volatile uint8_t flagByte;

void loop(){
    func();
}

void func(){
    uint8_t indicator;
    do {
        // Do something

        //Check for SPI condition
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ //Atomic access is required
            indicator = flagByte;
        }
    }while( !(indicator & 1<<SPI_ISR_RAN) );

    ATOMIC_BLOCK(ATOMIC_RESTORESTATE){
        flagByte &= ~(1<<SPI_ISR_RAN); //Don't forget to clear the flag!
    }
}

ISR(SPI_STC_vect){
    // Do ISR necessities

    // Set flag when appropriate
    flagByte & 1<<SPI_ISR_RAN;
}

You can achieve almost what you are describing with the setjmp() and
longjmp() functions. Here is an example, using INT0 to interrupt a
function calling delay():
/*
 * Test non local return from ISR:
 *   - wire a pushbutton between digital 2 and GND
 *   - monitor the serial port at 9600/8N1
 *   - pressing the button should skip "func() ending" and immediately
 *     write "func() returned"
 */

#include <setjmp.h>

jmp_buf saved_context;

/*
 * ISR triggered by low level of INT0 = PD2 = Arduino digital 2.
 * Should only be allowed to trigger while inside loop().
 */
ISR(INT0_vect) {
    EIMSK &= ~_BV(INT0);        // disable further interrupts
    longjmp(saved_context, 1);  // return to loop()
}

void func() {
    Serial.println("  func() beginning");
    EIMSK |= _BV(INT0);   // enable INT0 interrupt
    delay(3e3);           // wait 3 s for an interrupt
    EIMSK &= ~_BV(INT0);  // disable INT0 interrupt
    Serial.println("  func() ending");
}

void setup() {
    pinMode(2, INPUT_PULLUP);  // pin 2 is INT0
    Serial.begin(9600);
}

void loop() {
    Serial.println("Calling func()");
    if (setjmp(saved_context) == 0) func();
    Serial.println("func() returned");
    Serial.println();
    delay(2e3);
}

Now, after answering the SPI, I want to go back to loop() instead of continue func().

This is an extremely bad idea, and not what ISRs are for.
It is all very well wanting to go back to loop, but you would also have to discard whatever is on the stack, since loop started. The suggested method of using setjmp / longjmp may possibly achieve that, but almost certainly you are doing this for the wrong reason.
Jumping back to loop is like saying:

I don't care what was happening when the interrupt occurred
I don't care if it is half-way through sending some message
I don't care if it is half-way through turning on or off some device

In addition to this memory which was allocated (eg. by String objects) might not be freed. In fact the interrupt might occur during memory allocation in which case variables used by the memory allocation routine could be in an indeterminate state.
I strongly disagree with any suggested work-arounds. You simply should not be "jumping out of" an ISR and going somewhere else. Re-think the design.


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

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

I played around a little and tried running:
sudo ln -s cu.wch\ ch341\ USB\=\>RS232\ 1a1220  cu.wch

After running this a new port shows up called cu.wch, and if I select that it works.
The issue is the Arduino's port is cu.wch ch341 USB=>RS232 1a1220, but for some reason the IDE is trying to write to cu.wch. By linking the folders I can fix this but since it is a hack every time I restart my computer I have to rerun the command. Is there a way I can either rename the Arduino port or permanently link the folder?
I am using OSX 10.10 and Arduino IDE v1.6.3

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

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

Already did that. Please note as I mentioned I am using OSX 10.10.2 Yosemite. Before 10.10 (Mavericks) this solution would have worked, but the update seems to have broken this method. Please read my question carefully where I said "I have all the drivers installed".


text:
Wi-Fi Module communication?
I bought a Arduino Wi-Fi Module it does not have any manual or catalog
my project is to turn on/off a motor wireless

 it is working grate for the serial/usb cable but i couldn't make it work for wireless/wifi
after some walking around i found that my wifi module is making a wifi network called "HL-link_A49D"
with password from 1-8 and after network scanning i found that the module ip is 192.168.16.254/ username and pass are admin/admin
here is what i found

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

Good detective work so far!
In the admin page you found one can see the name of the module: HLK-RM04. Googling on that I found the manufacturer/seller page.
A PDF with some information can be found here.
Also one link with somebody's experience with the module.
For other projects you might want to try as well the ESP8266 - very cheap and seems a lot of people have experience with it, so you might find more information on the net.


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

Could you explain exactly how and where you added the Servertimer2.h library? Also, how are you including it in your source code?

Thanks allready for your first reaction.
This is the proces I followed : I downloaded the library Servotimer2.h as a Zip file. Then I added this zip file by clicking -> include library -> add ZIP library... an then selected the zip file servotimer2.

Afterwards I included the library to my program. And allready from hereone I remark that the library is not accepted like other libraries. Arduino doesn't seem to recognize it as a library because the name of the library stays black.
When I compile this, I get this error messages:
error: conflicting declaration 'typedef bool boolean'
typedef bool boolean;
error: 'boolean' has a previous declaration as 'typedef uint8_t boolean'
typedef uint8_t boolean;
I am just starting to use arduino and error could be obvious, but I don't get it yet.
Thanks for your help.


text:
Accel Stepper help, stepper not going backwards
So my question is that I am trying to use a arduino library called Accel Stepper to control a stepper motor, I made code that makes the stepper motor move one rev clockwise and then one rev counter clockwise
however as i run the code, the motor has no problem going clockwise, however when it comes to reversing the shaft of the motor stays still and doesn't move while the whole motor itself vibrates, what could be my problem?
here is my code:
    // MultiStepper.pde
    // -*- mode: C++ -*-
    //
    // Shows how to multiple simultaneous steppers
    // Runs one stepper forwards and backwards, accelerating and decelerating
    // at the limits. Runs other steppers at the same time
    //
    // Copyright (C) 2009 Mike McCauley
    // $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

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

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

    void setup()
    {

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

    }

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

    }

by the, as a stepper motor driver, I used the sparkfun easydriver

Work through your code. When it gets to the target position, your loop looks like this:
void loop()
{
    // Change direction at the limits
  stepper2.moveTo(user);
  stepper2.setSpeed(300);
  stepper2.runSpeedToPosition();
    stepper2.moveTo(-stepper2.currentPosition());
    stepper2.setSpeed(300);
    stepper2.runSpeedToPosition();

}

So you say, move to position 'user', then move to position '-stepper2.currentPosition'. Then as the loop comes around you again say move to position 'user', and so on.
The loop will repeat hundreds if no thousands of times per second, so you are basically telling the stepper motor to change direction thousands of times per second which will be why the motor starts vibrating when it gets to the user position.
If, just for the sake of argument, you were to move the first three lines of code in the loop() function to the setup() function, what behaviour do you think you will observe?

okay I see however one thing I don't understand stand is that I have a condition, it is not like I am directly telling the stepper motor to change a thousand times, I was trying to have a condition in which the stepper would reach a position then once it reaches that position it will have a new target to go to then it will run to that position, however as you have said I will try to put the first 3 lines of code in my setup function and I will observe the results

also anoyher concern that i have is that if i have to input code into the setup for the code in the loop to work what if i want the stepper to do a series of movments like moving from one position to another then back to its original position and moving foward again

You have to think about how your program goes together. What inputs do you have? When do you start the sequence of movements? Do you need to do things at timed intervals. Drawing up flow charts is very useful when it comes to learning how a program is going to go together.

well yeah I need things to go at timed intervals since I am attemping at making a cnc gui where a user can input directions or measurements for the stepper to go this is why I need things to happen right after each other in intervals, the inputs for now are going to be simple directions because the cnc "gui" I planing to build is going to be very basic not to complicated just the arduino serial monitor I am going to use

to reverse the direction try passing negative speed value to speed
like
stepper2.setSpeed(-300);


text:
Sending file from SD card to android using ESP8266
I came across this post
https://stackoverflow.com/questions/10327506/android-arduino-bluetooth-data-transfer
where the author sends files from the arduino to android platform over bluetooth.
I am wondering, is this possible to achieve with the ESP8266 SoC?
I have no experience with it, but i am willing to buy and experiment, if it hads that functionality.

Will you be using an Arduino to transfer the data from the SD card to the ESP8266?  If so it should be possible.  If not it gets trickier - it might still be possible, but also ceases to be on topic here.

yeah, using the arduino of course


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

Yes, you could use an interrupt for this. Anything else?

An interrupt can not always stop the code, although that is almost always the case. Certainly having an interrupt based kill switch would be better than a "regular code" polled one, which would still be better than nothing. If possible I would feel safest with a cut-power-to-the-whole-thing style safety switch.
Many functions that have sensitive timing constrains disable interrupts while they are active. It is rare for any of these to take a noticable amount of time, but it is possible that a bug in an interrupt dissabled function or another interrupt function could cause it to block and in that case your stop switch wouldn't work. rare, but possible.
I suppose you could turn on the chip watchdog timer, have a regular timer based interrupt reset the watchdog timer at a certain interval, and have your interrupt safety switch enabled. Then if interrupts ever stopped firing for too long the chip would reset itself. Checkout AVR132: Using the Enhanced Watchdog Timer. I've never used the watchdog myself, but it exists for a reason.
I don't have enough experience with a scheduler system to know if they would be helpful.

Is there an overview of arduino functions that disable interrupts for a (short) period?
Anyway, watchdog-timer would be the most professional way to handle this. Though you should try to handle the it and only reset when needed. Then make sure the robot won't move after a reset. And that it's easy to see when it has resetted (so you know it was due the WDT).
I would reset the watch-dog timer in software though, because if your main code dead-locks, the timer interrupts might still work and reset the WDT. But an interrupt will do well generally. Don't use too much code that disables interrupts?

A clear overview of intterupts was what I was looking for although I appreciate advice given.

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

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


text:
Sending constant int from Arduino to PC causes error
I am using Arduino Uno Rev 3, and according to this link we can achieve 2000000 baud rate.
This problem can be easily repeated by the following code:

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

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

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

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

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

Here is what I got:

Edit below
Chris mentioned a good point that it might be the high baud rate of 2,000,000 causing the instability. I did think about that when I first ran into this, but then I did a little trick: adding a sinusoid into the constant. If I do that, the weird spiking goes away! I think it indicate that this is not a high baud rate issue... Is it?
Code:
void setup() {
  Serial.begin(2000000);
}

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

Output:

Your link overlooks many potential issues, such as buffer management in the USB converter.  Just because the hardware UARTs can both divide a 16 MHz clock by 8, doesn't mean you can actually move bulk data at that rate reliably, or flush it through the USB backhaul before more comes in.  Try capturing the actual data received.

Setting a high baud rate isn't necessarily going to move your data any faster anyway - if the bottleneck is elsewhere, it may just make it less reliable.  For maximum throughput, look at a Leonardo-style board (or better yet, one of the ARM-based ones) as there, the baud rate is ignored and the USB will simply move the data as fast as the embedded processor can keep up with.

Please merge your two questions of today on this topic by editing all the content into one and deleting the other.

@ChrisStratton I thought about that too, but then if I do a little trick and add a sinusoid into it, it will transfer all right! I will update the OP now to show that.

You are probably just delaying things with the time consuming calculation, allowing time for something to catch up.  Your overall problem is that your baud rate is unreliably high for one or more of the pieces in the chain.

@ChrisStratton That makes total sense. I think you are right - would you mind posting this as an answer so I can accept it?

Actually I'm not convinced that this relies to unstability due to the high baud rate. In that case I would expect the incorrect values to be more random. In your (initial) case, you seem to have false 0s and (I guess) 23400s which would be the right valie plus additional zero's. At least when running such a python script on a RPi, the arduino is way too fast for the python script.

So, in your initial example you could add a delay between the Serial.println()s to check...

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


text:
Line Follow Vehicle
I know this is very common project and it's already been done, however, most of the guides don't have a clear instruction, and being this inexperienced, I struggle to understand exactly what's going on.
I'm currently working on a line following robot, but I'm largely inexperienced. For the most part, I'm going to be using SparkFun's Magician Chassis with Inventors Kit. The main sensor available is the Line Sensor Breakout(QRE113), which I have 3 of, but I'm not sure if whether I should use the Digital or Analog model.
Also, I'm having trouble finding how to wire this circuit. I know as much that, I have to connect the motors, diode, simple transistor(with emitter, collector, and base), some sort of resistors, and maybe a capacitor(this one I'm not too sure of). All of this has to be set on a breadboard, and be jointly connected to the arduino. I think there has to be two identical circuits on the breadboard for each motor, as the voltage of the sensor is expected to decrease when it encounters a white reflective surface(tape), this in turn will slow down the motor, which would allow the robot to turn in the direction of the tape, due to the other wheel not slowing down. One part of the circuit, should handle the motor drive circuit, this should be the output of the transistor, but I'm not sure how to use the arduino(redboard) to control the speeds of the motors using the sensors, which I think will go into the base of the emitter. Which pins should I use basically?
Apart from this, how will the code look? But I think this is dependent on how I wire it, right?
This is what I'm using...
https://www.sparkfun.com/products/12060
https://www.sparkfun.com/products/9453

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

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

I've actually done a project similiar to this one, but we used a motor-board instead. Driving the motors with a transistor&diode(&mosfet?) should indeed also be possible... but it'll get difficult once you want to be able to also reverse the motor (check H-Bridge motor driver).
For the patterns, you should make a switch case which checks the last pattern and keeps steering until he finds the right pattern again. But this can be achieved in many other ways.
Try to get a line sensor working, be sure to check some tutorials before you ask here and try to use different kinds of tape, blue tape didn't work for us :)
It's a really fun project, with lots of possibilities.

Below the schematics we used in the project.

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

I can actually provide more reference material, but I would suggest you try it yourself (with the help of internet) and at the moment it starts to bother you, you should create a question specific for your problem. So as an example: You check some tutorials and FAQ on your line sensors, on how to get them working. After struggling for some time, you shouldn't drop the project but instead post a question with all details on this linesensor. So we can help you out to get that part working. Then you can happily move on towards the motors etc.

Thanks a lot guys.  I'll get back to you guys if I run into more problems.