text:
No such file or directory compilation terminated
I tried a simple blink for my fingerprint sensor which is GT-511C1R, but I have experienced of having an error.

FPS_Blink.ino:12:26: fatal error: FPS_GT511C1R.h: No such file or directory
  compilation terminated.

I downloaded the whole library but still same error.

If the OP has a basic lack of understanding of programming that is a valid topic for them to post about and request help.

@LookAlterno - I understand why you say that, but this is about the inability to find a file, which is an IDE setup issue.  Also I suspect the your original answer may have lost something in "translation", because it comes across quite elitist, which I'm sure is not what you meant.

Please learn how to install a library from here. And see if error is coming or not.


text:
How can i build mouseless technology with arduino?
I want to build mouseless technology with arduino as shown in this link
Can anyone tell me how to approach this with arduino? Or what can be the logic behind it?

Your question is far far far too broad. No one is going to come here, post all the electrical schematics you need, all the code you need, and walk you through step by step. That's not how this works. The stack exchange requires that the poster make some effort to make progress in thier project before posting specific problems they are having.
That being said I will say that what you want to achieve is not possible on only an arduino. The method you posted in the video requires a lot of image processing to track the blobs. This is not something a microcontroller such as the arduino can achieve. A more powerful Intel based device may have some potential for your project but I doubt it.
I once did image processing with the raspberry pi. The pi itself is still not powerful enough to perform real time image processing to a good level, however it's a possibility that it could work (my image processing was more complicated than processing a binary image and tracking dots).
The ideal solution for you would be to do exactly what this guy has done. Build an application on a laptop or desktop computer which has enough power for the image processing. I suggest taking this route first even if downscaling to a raspberry pi is possible in the future, it will introduce you to image processing, and at least you know that it CAN work, as there is a working example.
Look up OpenCV if you havnt already, download, build it, follow tutorials and start from there! Then I think you should aim to build an application that tracks white objects in the frame. And that would be your first step to completion.

Thanks C.W.G for explanation,
I will definitely try OpenCV as you suggested.

source: Stack Exchange

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

sort: votes


text:
Accelstepper run stepper backward
Update:
Below I implemented how I understood your suggestions. And it still does only turn in one direction (forward). Curiously if I entered M_DEST in the stepperOneForward() function it turned forward very long but smooth. The code below made it rotate as usual very jittery. Is this the acceleration part and if so how can I change that ? Ideally I would be able to tell the stepper go to position X and return to start and that in constant speed.
 #include <AccelStepper.h>

const int stepPin = 5;
const int dirPin = 4;
const int enPin = 12;

unsigned int DEST = 800;
unsigned int M_DEST = -800;
unsigned int SPD = 1600;
unsigned int ACCEL = 800;

AccelStepper stepper1(1,stepPin,dirPin);

void setup() {

  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(enPin,OUTPUT);

  stepper1.setEnablePin(enPin);
  stepper1.setPinsInverted(false, false, true);
  Serial.begin(9600);  // Start Serial
}

void loop() {

stepperOneForward();
Serial.println("Stepper1 turned forward.");
delay(1000);
stepperOneBackward();
Serial.println("Stepper1 turned backward.");
}

void stepperOneForward() {

  stepper1.enableOutputs();
  stepper1.setMaxSpeed(SPD);
  stepper1.setAcceleration(ACCEL);
  stepper1.move(DEST);
  if (DEST > 0) {
    while ( stepper1.distanceToGo() > 0) {
      stepper1.run();
      }
  //stepper1.disableOutputs();
  }
 }

 void stepperOneBackward() {

  stepper1.enableOutputs();
  stepper1.setMaxSpeed(SPD);
  stepper1.setAcceleration(ACCEL);
  stepper1.move(M_DEST);
  if (M_DEST < 0) {
    while ( stepper1.distanceToGo() > 0) {
      stepper1.run();
      }
  //stepper1.disableOutputs();
  }
 }

I have multiple steppers that I would like to run forward until they hit a microswitch and backwards to the initial position. But to simplify things I would like to control one stepper going forward and then backward. The code below always just turns clockwise.
I tried to set the dirPin to low, which did not work.
I tried to reverse the setMaxSpeed (by putting a minus in front of it).
I found the "enum AccelStepper::Direction" class in Accelstepper that did not explain how to to set DIRECTION_CCW or DIRECTION_CW.
What I would like to achieve is control these steppers so they move smoothly forward, wait and then backwards. This should be very easy, but has frustrated me now for too long. I would use any library at this point that can do this and control more than 1 stepper.
The SPD and ACCEL values are so high because I use microstepping (6400 is a full cycle).
#include <AccelStepper.h>

const int stepPin = 5;
const int dirPin = 4;
const int enPin = 12;

unsigned int DEST = 6400;
unsigned int SPD = 1600;
unsigned int ACCEL = 800;

void setup() {

  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(enPin,OUTPUT);
  Serial.begin(9600);  // Start Serial
}

void loop() {

stepperOneForward();
Serial.println("Stepper1 turned forward.");
stepperOneBackward();
Serial.println("Stepper1 turned backward.");
}

void stepperOneForward() {

  AccelStepper stepper1(1,stepPin,dirPin);
  digitalWrite(enPin,LOW);
  stepper1.setMaxSpeed(SPD);
  stepper1.setAcceleration(ACCEL);
  stepper1.move(DEST);
  if (DEST > 0) {
    while ( stepper1.distanceToGo() > 0) {
      stepper1.run();
      }
  digitalWrite(enPin,HIGH);
  }
 }

 void stepperOneBackward() {

  AccelStepper stepper1(1,stepPin,dirPin);
  digitalWrite(enPin,LOW);
  stepper1.setMaxSpeed(-SPD);
  stepper1.setAcceleration(ACCEL);
  stepper1.move(DEST);
  if (DEST < 0) {
    while ( stepper1.distanceToGo() > 0) {
      stepper1.run();
      }
  digitalWrite(enPin,HIGH);
  }
 }

I think the way to do this is to use stepper1.move(-DEST). PS I'd suggest creating the stepper1 object only once, as a global variable. And then use that global stepper1 in the two functions, instead of re-creating the object every time you call the two function.

First, you are creating/destroying the AccelStepper stepper1() object at every call. This is not right, as the library can no longer keep track of the stepper position and state.
The stepper object should be created in the global scope (that is, outside of setup() or loop()).
Second, you can call stepper1.setEnablePin(enPin) and stepper1.setPinsInverted(false, false, true) after you create the object to have the AccelStepper library control the enable pin and to set the enable pin to operate active-low. Then the driver is enabled or disabled with calls to stepper1.enableOutputs() and stepper1.disableOutputs(). In practice, you would not disable the driver except for power saving, as the stepper can no longer hold it's position when the outputs are not enabled. It will lose it's position.
Third, do not set the speed to a negative value. The direction of the stepper is determined by the library based on the current position and the desired end position. When the library is created, the position is zero. You can set the new position in several ways:

stepper1.move(): Set the target position relative to the current position. This means to go backwards you pass this function a negative value. It will add this (negative) number to the internal target position, and then run() will work to get it there.
stepper1.moveTo(): Set a new absolute position. If you initially set the position to 100 and move there, then set it to 50, the stepper will run in reverse to be able to reach position 50. If you start in position 0 and run to 50, it will run forward. If you start at 0 and set to -50, it will run in reverse to get there, and so on.

Thank you very much for your answer, above my update.

@digit You may want to look into what the Acceleration and Speed values mean. The docs (https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#ae79c49ad69d5ccc9da0ee691fa4ca235) say that speeds over 1000 are unreliable. Try lowering the speed and accel values to something in 200 range. 1600 steps per second is too fast for the physical rotor to respond to the coil changes.

Well this is because I am microstepping and if I set the Speed to 200, but the Stepper has to run for 800 steps, it becomes very slow. I read this part of the Accelstepper. But all of this still does not solve the problem that never ran backwards. Only forwards.

If it runs forward and not backward with a stepper driver, then double-check your wiring... With AccelStepper using a driver, it only pulls the direction pin high or low and the driver handles the coil sequencing.

If I use a different driver and code (but same wiring) it works like a charm, so it can't be the wiring (or am I missing something here). I would like to just have one example code that turns the stepper backward with Accelstepper and ideally in a dedicated void that only enables the motor when needed (and thus keep the stepper cool for continuous running. Still could not find a solution for that after 5 days :)

You say different driver and code, same wiring. What about same code, but different driver, or different driver but same code? To eliminate the driver or the wiring as the culprit, you must change only one thing at a time.

If the wiring would be wrong, would it be able to rotate forward ?

It might. Is this a 4-wire bipolar stepper? Measure the resistance between set of the 6 combinations (A+B, A+C, A+D, B+C, B+D, C+D) of wires. The 2 coils will be the pair with about the same resistance. If it runs erratically, switch the polarity of one of the coils.

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


text:
Execute code only once
I am trying to create an if statement that only runs once, the very first time the void loop is started and switches to another code after that. But the following only executes stepper1a(). Any help would be great. Thx !
int var;
int var2;
bool executed = false;

const int M1dirpin = 4; //Stepper Dir Pin
const int M1steppin = 5; //Stepper Step Pin

void setup() {

pinMode(A2,INPUT);
pinMode(M1dirpin,OUTPUT);
pinMode(M1steppin,OUTPUT);
Serial.begin(9600);

}

void stepper1() {
  int j;
    delayMicroseconds(10);
    digitalWrite(M1dirpin,HIGH);
  for(j=0;j<=200;j++){
    digitalWrite(M1steppin,LOW);
    delayMicroseconds(10);
    digitalWrite(M1steppin,HIGH);
    delay(2);
  }
}

void stepper1a() {
  int j;
    delayMicroseconds(10);
    digitalWrite(M1dirpin,HIGH);
  for(j=0;j<=1600;j++){
    digitalWrite(M1steppin,LOW);
    delayMicroseconds(10);
    digitalWrite(M1steppin,HIGH);
    delay(2);
  }
}

void loop() {

if (executed == false) {
var = analogRead(A2);
delay(10);
if (var > 500) {
  stepper1a();
  delay(2000);
  executed = true;
  Serial.println("turned 1600");
  Serial.println(executed);
  }
else if (executed == true) {
 var2 = analogRead(A2);
delay(10);
if (var > 500) {
  stepper1();
  delay(2000);
  Serial.println("turned 200");
}
}
}
}

Updated void loop:
void loop() {

    static bool yes_we_did_the_one_time_job = false;

    if (yes_we_did_the_one_time_job) {
        var = analogRead(A2);
        delay(10);
        if (var > 500) {
            stepper2();
            delay(2000);
            Serial.println("turned 1600");
        }
    }
    else {
        var2 = analogRead(A2);
        delay(10);
        if (var > 500) {
            stepper1();
            delay(2000);
            Serial.println("turned 200");
            yes_we_did_the_one_time_job = true;
        }
    }
}

This works now, thx !!!:
void loop() {
  static bool yeswedid = false;

  if(yeswedid) {
    if(analogRead(A2) > 500) {
    stepper1();
    stepper2();
    }
  }
  else {
    if(analogRead(A2) > 500) {
    stepper1();
    yeswedid = true;
  }

  }
}

you have a typo. else if (executed == true) { is else to if (var > 500) {, not to if (executed == false) {. add one } before else if (executed == true) { and remove one } at the end

and if (executed) {} else {} would be cleaner

Your updated code is still wrong. You have have the code that sets yes_we_did_the_one_time_job to true inside a second if statement, which means it won't get set until after var > 500.

@DuncanC, that is the goal as I understand it. Wait until the analogRead first time reaches 500 and then do the special initialization move. because without the condition it could be executed in setup()

@digit - Question regarding your "Updated void loop:" code. The code if (var > 500) { in the else statement, is it suppose to be var or var2?

Generic solution:
void loop() {
    static bool yes_we_did_the_one_time_job = false;
    if (yes_we_did_the_one_time_job) {
        do_the_other_jobs();
    } else {
        do_the_one_time_job();
        yes_we_did_the_one_time_job = true;
    }
}

if this is what you suggest, it did not work:

see updated question. Thanks for your help

@digit: Re “it did not work”: you did not quite implement my suggestion. Read your code carefully and you will see it is not equivalent to what I posted here.

great solution thanks man !

If you have any code you want to run only once at the beggining of your program you can use the setup() method. It can actually do much more than just setting up pins and default values.
The code of main function of Arduino (main.cpp) looks like this:
int main(void)
{
    //(...) I cut some stuff from here

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}

As you can see setup() is just a method and it can do almost exactly the same things as loop().
The setup() method can actually contain a for(;;) loop that will stop the program from running the loop() method. From inside it you can check the sensor value and break from it when condition is met.
void setup()
{
  for (;;)
  {
    var = analogRead(A2);
    delay(10);
    if (var > 500) {
      stepper1();
      delay(2000);
      Serial.println("turned 200");
      break;
    }
  }
}

in this case the loop() is very simple:
void loop()
{
  var = analogRead(A2);
  delay(10);
  if (var > 500)
  {
    stepper2();
    delay(2000);
    Serial.println("turned 1600");
  }
}

It has to react to a sensor while in void loop and not run once at startup. Thanks.

only once, but after a starting condition is met. the OP's code is usable, only a { is missing

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


text:
Control Stepper via Serial Monitor
I would like to control my stepper via serial monitor and unfortunatley the code below did not work. Serial monitor works (Serial.println()), but it does not execute the stepperOne() part. Any ideas why would be awesome.
Thank you.
#include <AccelStepper.h>

const int stepPin = 5;
const int dirPin = 4;
const int enPin = 12;

String msg;

unsigned int DEST = 800;
unsigned int SPD = 1600;
unsigned int ACCEL = 1600;
const int TEST = 3;

void setup() {

  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,HIGH);
  Serial.begin(9600);  // Start Serial

}

void loop() {

if (Serial.available()>0) {
    msg = "";
    while (Serial.available()) {
      delay(10);
      char tmp = Serial.read();
      // msg += tmp;
     if( tmp!='\r' && tmp!='\n' ) msg+=tmp; // Does not work either
    }
    msg.replace(" ","");
    if (msg=="G") {
      stepperOne();
      Serial.println("Stepper turned.");
    }
    Serial.flush();
  }
}

void stepperOne() {

  AccelStepper stepper(1,stepPin,dirPin);
  digitalWrite(enPin,LOW);
  stepper.setMaxSpeed(SPD);
  stepper.setAcceleration(ACCEL);
  stepper.move(DEST);
  if (DEST > 0) {
    while ( stepper.distanceToGo() > 0 ) {
      stepper.run();
      }
  digitalWrite(enPin,HIGH);
  }
 }

It you type "G" in the serial console, it will send "G\r\n" (with an "enter" at the end). Your code doesn't account for the carriage return and newline at the end.

How can I account for carriage return ?

You could opt to ignore it. if( tmp!='\r' && tmp!='\n' ) msg+=tmp;

Thanks. I added it in the code (see above) and it still does not work. Serial works though. I am confused.

Stupid question can the Arduino version (older Uno) be the reason for this ? Or am I missing something ? Thanks

does the stepper work without the Serial code?

The serial.println works so I guess the Serial port works.

I found the solution, it was the Arduino, older version R2, the R3 works like a charm. I didn't know that the version could cause so much trouble. Sorry.

Write this as an answer!

I found the solution, it was the Arduino, older version R2, the R3 works like a charm. I didn't know that the version could cause so much trouble. But in case someone encounters the same problem R3 did it for me.


text:
Controlling 3 Steppers exactly
Update
Here the update regarding the code I tried to program. I have a stepper with an attached disc with little holes every 45 degrees where a microswitch can rest into (hole is the exact size of the microswitch; and be in off position then). I would like the stepper to move 45 degree (until hole 1) and then (as a first step) wait for 3 seconds and then move another 45 degree to hole and stop etc.
As a next step I would like the same to be controlled via serial from another software. So I can send to serial a "move" command and then the same as described above will happen once the Arduino get the "move" command.
Below my attempt. It does do the homing, but not very smoothly and the next step (just moving 3 seconds) is a very rough movement. Here my qestions:

How can I make this move smoothly ?
How should I adapt this code to make the stepper stop once it is in the hole ?
How can I make the microswitch get out of the hole after it rests in there ?

Thank you very much for your help !
Code
#include "AccelStepper.h"

int M2dirpin = 4;  //Motor Y direction pin
int M2steppin = 5; //Motor Y step pin
int M2en=12;  //Motor Y enable pin
#define home_switch 9 // Pin 9 connected to Home Switch (MicroSwitch)

// AccelStepper Setup
AccelStepper stepperX(1, 5, 4);   // (1,2,3) = (Dedicated Board, STEP, DIR)
// Stepper Travel Variables
long initial_homing = -1; // Used to Home Stepper at startup

void setup() {

  pinMode(home_switch, INPUT_PULLUP);
  pinMode(M2dirpin,OUTPUT);
  pinMode(M2steppin,OUTPUT);
  pinMode(M2en,OUTPUT);
  digitalWrite(M2en,LOW);
  Serial.begin(9600);  // Start the Serial monitor with speed of 9600 Bauds
  stepperX.setMaxSpeed(50.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(50.0);  // Set Acceleration of Stepper

  // Start Homing procedure of Stepper Motor at startup
  Serial.print("Stepper is Homing . . . . . . . . . . . ");

  while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated
    stepperX.moveTo(initial_homing);  // Set the position to move to
    initial_homing--;  // Decrease by 1 for next move if needed
    stepperX.run();  // Start moving the stepper
    delay(20);
  }

  stepperX.setCurrentPosition(0);  // Set the current position as zero for now
  stepperX.setMaxSpeed(50.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepperX.setAcceleration(50.0);  // Set Acceleration of Stepper
  initial_homing = 1;

  while (!digitalRead(home_switch)) { // Make the Stepper move CW until the switch is deactivated
    stepperX.moveTo(initial_homing);
    stepperX.run();
    initial_homing++;
    delay(20);
  }

  stepperX.setCurrentPosition(0);
  Serial.println("Homing Completed");
  Serial.println("");

 // Move 10 steps forward from the limit switch (to get out of the switch)
  while (stepperX.currentPosition() != 10)
  {
    stepperX.setSpeed(10);
    stepperX.run();

}
}
void loop()
{
stepper1();
}

void stepper1()
{
  stepperX.move(22);
  unsigned long startMillis = millis();
  while( millis()-startMillis<3000 )
{
  stepperX.run();
}
}

Old question:
I apologize for the high level, pseudo code question, but I am trying to understand conceptional how I can achieve the following:
I have 3 steppers (1 circular motion, 2 linear motion) which I would like to stop every time at the exact same position. The first stepper should rotate e.g. 45 degrees and stop, after which the second stepper should push down (like a linear actuator) stay at that position for a certain time and move back to the initial position, after that the 3rd stepper should also (linear motion) move to certain position and return.
These three steps would than repeat for a very long time.
Do Steppers accumulate errors in position and if yes how can I make sure that this is not happening ?
I read abut "homing" and tried microswitches, but wasn't able to combine it with the three stepper setup. Also 3D printers should always stop exactly at the same place and therefore I assumed there must be a solution for this.
Is there a template code I can start from that is similar to the setup described ?
How can I make sure these steps are done strictly after each other.
Again I apologize for the high level question, but all my attempts so far to solve this failed.
Thank you !

Stepper motors can miss steps if they experience to high a resistance (or too fast acceleration)

You could home all three steppers every time it moves back. So move forward X amount of steps, move back as many steps as needed for the limit switch to activate

How can I make sure these steps are done strictly after each other. ..... i think that you need to run a few example sketches in the Arduino IDE to get a feel for how a microcontroller operates

all my attempts so far to solve this failed ..... please add the code which you tried and a connection diagram to your post

About errors with stepper motors: Stepper motors introduce errors depending on the forces, that act upon them. For example: If your stepper does not have enough power to accellerate the attached weight, it will loose steps when trying (meaning that the rotor does not do a step despite the coils being controlled for the step). (The same of course also goes for deacceleration or moving against a barrier) Since you only know the position bei counting the steps, that you "send" to the motor, you get an error.
You have basically 2 options to prevent this from happening:
1. Choose the correct strength for motors for your application and don't overburden the motors at any moment in operation.
2. You can attach a rotary encoder to the rotor, so that you can check, if the rotor really moved the number of steps, that you instructed it to do. (Here be sure, that the numbers of steps for rotary encoder and motor match, or calculate correctly, if they don't). The position in your program would then only be updated based on the rotary encoder. This solution is more difficult, since you need extra parts and good code, that will not miss any of the rotary encoder pulses.
About Homing: Yes, this can be used to prevent the accumulation of errors during a longer operation. Also this is often used, so that the device does not have to constantly save it's current position to peristent storage. If the power is cut off, the device will forget it's position and calibrate it again after powered on again by using the end switches. Also this means, that in the powered off state it's not a problem, when the motor is moved away from it's position by outer forces.
It is unclear, how precise you need the application to be and what errors are really introduced. It may be sufficient for you to just get the position of the motors by homing, when you power your device on, and then simply letting it work. If that's not sufficient, you might do a homing cycle after every sequence. The same goes for the rotary encoder solution. It might be an overkill here, depending on the exact properties of the application.
Template code: I simply googled "Arduino stepper homing" and found some articles about it, which also contain example code. That should enable you to write code for your own application. Since you didn't really described, what your setup is, we cannot see, if this really fits your application. But Homing is the same everywhere.
Steps strictly after each other: You can just write your program to finish one part and then go on to the next (blocking code). Or, if you want it to be more elaborate and flexible, you can use non-blocking code (like in the BlinkWithoutDelay example of the Arduino library) with a finite state machine. The states could be the 3 parts of your program, or divided further. In each state you are doing only 1 thing and change to the next state, when finished. The code in each state should be non-blocking, so that it only does something, when it needs to, and else let's the program continue (for example: When moving a stepper at a certain speed, you are doing 1 step, then waiting a bit, then doing the next step and so on. While waiting you can do other things.)
You didn't mention, what your problems with the limit switches were, so we cannot help you with that. Thus this answer is as high level as your question. Hope, that helps.

Thanks for the long and detailed answer, this is very useful. I know the substeps (as described above), but seem to have problems to unify these steps into one code. Thank you anyway, I will try to find a solution.


text:
Linear Actuator Arduino Control
Update:
Here is my first try based on the code I found and it did not work.
The first time I uploaded it, it move to the "current positional value". But did not do the void loop part. Just holds the positions.
Thanks.
    //Includes
    #include <Servo.h>

    //Defines
    #define LINEAR_1_100PIN 11        //Linear Actuator Digital Pin
    #define LINEAR_2_100PIN 6      //Linear Actuator Digital Pin

    String msg;

    //max/min pulse values in microseconds for the linear actuators
    #define LINEAR_1_100_MIN      1050  //
    #define LINEAR_1_100_MAX      2000 //
    #define LINEAR_2_100_MIN  1050     //
    #define LINEAR_2_100_MAX  2000    //

    Servo LINEAR_1_100, LINEAR_2_100;  // create servo objects to control the linear actuators
    //int knobValue, sliderValue;  //variables to hold the last reading from the analog pins

    int linear100Value_1 = 1051;   //current positional value being sent to the linear actuator.
    int linear100Value_2 = 1051;  //current positional value being sent to the linear actuator.

    int speed = 10;

    void setup()
    {
      //initialize servos
      LINEAR_1_100.attach(LINEAR_1_100PIN, LINEAR_1_100_MIN, LINEAR_1_100_MAX);      // attaches/activates the linear actuator as a servo object
      LINEAR_2_100.attach(LINEAR_2_100PIN, LINEAR_2_100_MIN, LINEAR_2_100_MAX);  // attaches/activates the linear actuator as a servo object

      //Analog pins do not need to be initialized

      //use the writeMicroseconds to set the linear actuators to their default positions
      LINEAR_1_100.writeMicroseconds(linear100Value_1);
      LINEAR_2_100.writeMicroseconds(linear100Value_2);
    }

    void loop()
    {
   LINEAR_1_100.write(90);
   delay(1000);
   LINEAR_1_100.write(0);
   delay(1000);
   LINEAR_2_100.write(90);
   delay(1000);
   LINEAR_2_100.write(0);
   delay(1000);
    }

Old Question:
I am trying to make the code described in this tutorial:
http://learn.robotgeek.com/demo-code/118-arduino-linear-actuator-tutorial-analog-direct-control-of-small-linear-actuator.html
https://github.com/robotgeek/firgelliDirectControl/blob/master/firgelliDirectControl/firgelliDirectControl.ino
work with PWM from an Arduino, without the additional board.
So far the Arduino Examples>Servo>Sweep works as I would like to achieve it (delay changed to 30 ms) but very slowly and it does not seem to just go 180 steps out wait 30 ms and 180 steps in again. It sometimes moves twice in one direction. If I change the steps from 1 to 5 the servo does not move anymore (I expected it to go faster).
With the code above I understand I can control the servo with a Knob or Slider, but I would like to understand how I can control this Linear Actuator Servo with PWM from an Arduino PMW Pin (e.g. 11) and change the speed. Finally I would like to make the Servo consistently go x amount of steps out, wait for x ms and the same amount back in again.
Most importantly I would like to make sure it always ends at position 0, and that it does not accumulate errors.
Thank you for any help.

About being sure about returning to position 0 this is not a problem. You are not actually controlling anything with your PWM. You are only sending a signal to the IC inside the servo to tell it where to move the actuator. That IC knows in what position the actuator is located in any moment, usually using some kind of encoder (it's called a closed loop system) and it will make sure that it will move back exactly to 0 whenever you tell it to move to 0.
If you want to make things clearer you can use write method to send value to the servo.
void Servo::write(int value)
{
  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
  }
  this->writeMicroseconds(value);
}

Any value from 0 to 180 will set a position to which servo will move from MIN to MAX possible position. No need for manual calculation of microseconds.
You have to remember that PWM works constantly. If you write for example LINEAR_1_100.writeMicroseconds(1051) this code will set some timers, counters and prescalers inside the ATmega chip on the Arduino board and the value of PWM will be sent constantly until you change it.
So the delay(2000) doesn't stop the PWM signal, and servo remains in constant position.
The issue is here:
LINEAR_1_100.writeMicroseconds(1800);
LINEAR_1_100.writeMicroseconds(1051);

You set the value of 1800 and then immediatelly set value of 1051, but the ATmega didn't even have the time to send the first value to the servo.
Add a delay(1000) after every call of write or writeMicroseconds to allow the PWM to actually be sent to the servo.

Thank you for the clarification. But how can I integrate this into my code ? Do I just call void servo from void loop ? Do I have to define the MIN_PULSE_WIDTH, SERVO_MIN, MAX ? This sounds like the solution, but how can I change my code. Also the :: seems like C++ code to me and I am not as frequent with this. Thanks again.

Sorry for confusing you. You already defined those values when you created/attached LINEAR_1_100 and LINEAR_2_100 the code is taken from the Servo.h library. Don't look to much into it. All you need to do is write LINEAR_1_100.write(90) in the code and add delay(1000) after it to give Arduino some time to actually send the PWM value to the servo.

I changed my code (see above), but it still doesn't move. I just hear it ticking, but no movement.

Are you by any chance powering the servo directly from the Arduino that's connected to your PC? I simulated your code in Tinkercad and it works fine with virtual normal servos. Maybe your linear servos draw to much current and protection circuitry (in laptop) kicks in and disable power. Power them from external 5V source (not through Arduino because it can also burn)

Ok, thanks for the feedback. I don't but maybe the MA is not enough.


text:
serial data transfer on gps shield duinopeak
I'm using an arduino uno r3 with a gps shield duinopeak.

The shield is configured using RX pin 3 and Tx pin 2, as image below:

I'm using the TinyGPSPlus library to read NMEA data. This is my code:
/******************************************************************************
  This example uses SoftwareSerial to communicate with the GPS module on
  pins 8 and 9, then communicates over SPI to log that data to a uSD card.

  It uses the TinyGPS++ library to parse the NMEA strings sent by the GPS module,
  and prints interesting GPS information - comma separated - to a newly created
  file on the SD card.

  Resources:
  TinyGPS++ Library  - https://github.com/mikalhart/TinyGPSPlus/releases
  SD Library (Built-in)
  SoftwareSerial Library (Built-in)

  Development/hardware environment specifics:
  Arduino IDE 1.6.7
  GPS Logger Shield v2.0 - Make sure the UART switch is set to SW-UART
  Arduino Uno, RedBoard, Pro, Mega, etc.
******************************************************************************/

#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>

#define ARDUINO_USD_CS 8 // uSD card CS pin (pin 8 on Duinopeak GPS Logger Shield)

/////////////////////////
// Log File Defintions //
/////////////////////////
// Keep in mind, the SD library has max file name lengths of 8.3 - 8 char prefix,
// and a 3 char suffix.
// Our log files are called "gpslogXX.csv, so "gpslog99.csv" is our max file.
#define LOG_FILE_PREFIX "gpslog" // Name of the log file.
#define MAX_LOG_FILES 100 // Number of log files that can be made
#define LOG_FILE_SUFFIX "csv" // Suffix of the log file
char logFileName[13]; // Char string to store the log file name
// Data to be logged:
#define LOG_COLUMN_COUNT 8
char * log_col_names[LOG_COLUMN_COUNT] = {
  "longitude", "latitude", "altitude", "speed", "course", "date", "time", "satellites"
}; // log_col_names is printed at the top of the file.

//////////////////////
// Log Rate Control //
//////////////////////
#define LOG_RATE 5000 // Log every 5 seconds
unsigned long lastLog = 0; // Global var to keep of last time we logged

/////////////////////////
// TinyGPS Definitions //
/////////////////////////
TinyGPSPlus tinyGPS; // tinyGPSPlus object to be used throughout
#define GPS_BAUD 9600 // GPS module's default baud rate

////////////////////////////////////////////////
// Arduino GPS Shield Serial Port Definitions //
////////////////////////////////////////////////
// If you're using an Arduino Uno, Mega, RedBoard, or any board that uses the
// 0/1 UART for programming/Serial monitor-ing, use SoftwareSerial:
#include <SoftwareSerial.h>
#define ARDUINO_GPS_RX 3 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 2 // GPS RX, Arduino TX pin
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX); // Create a SoftwareSerial

// Set gpsPort to either ssGPS if using SoftwareSerial or Serial1 if using an
// Arduino with a dedicated hardware serial port
#define gpsPort ssGPS  // Alternatively, use Serial1 on the Leonardo

// Define the serial monitor port. On the Uno, Mega, and Leonardo this is 'Serial'
//  on other boards this may be 'SerialUSB'
#define SerialMonitor Serial

void setup()
{
  SerialMonitor.begin(9600);
  gpsPort.begin(GPS_BAUD);

  SerialMonitor.println("Setting up SD card.");
  // see if the card is present and can be initialized:
  if (!SD.begin(ARDUINO_USD_CS))
  {
    SerialMonitor.println("Error initializing SD card.");
  }
  updateFileName(); // Each time we start, create a new file, increment the number
  printHeader(); // Print a header at the top of the new file
}

void loop()
{
  if ((lastLog + LOG_RATE) <= millis())
  { // If it's been LOG_RATE milliseconds since the last log:
    if (tinyGPS.location.isUpdated()) // If the GPS data is vaild
    {
      if (logGPSData()) // Log the GPS data
      {
        SerialMonitor.println("GPS logged."); // Print a debug message
        lastLog = millis(); // Update the lastLog variable
      }
      else // If we failed to log GPS
      { // Print an error, don't update lastLog
        SerialMonitor.println("Failed to log new GPS data.");
      }
    }
    else // If GPS data isn't valid
    {
      // Print a debug message. Maybe we don't have enough satellites yet.
      SerialMonitor.print("No GPS data. Sats: ");
      SerialMonitor.println(tinyGPS.satellites.value());
    }
  }

  // If we're not logging, continue to "feed" the tinyGPS object:
  while (gpsPort.available())
    tinyGPS.encode(gpsPort.read());
}

byte logGPSData()
{
  File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

  if (logFile)
  { // Print longitude, latitude, altitude (in feet), speed (in mph), course
    // in (degrees), date, time, and number of satellites.
    logFile.print(tinyGPS.location.lng(), 6);
    logFile.print(',');
    logFile.print(tinyGPS.location.lat(), 6);
    logFile.print(',');
    logFile.print(tinyGPS.altitude.feet(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.speed.mph(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.course.deg(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.date.value());
    logFile.print(',');
    logFile.print(tinyGPS.time.value());
    logFile.print(',');
    logFile.print(tinyGPS.satellites.value());
    logFile.println();
    logFile.close();

    return 1; // Return success
  }

  return 0; // If we failed to open the file, return fail
}

// printHeader() - prints our eight column names to the top of our log file
void printHeader()
{
  File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

  if (logFile) // If the log file opened, print our column names to the file
  {
    int i = 0;
    for (; i < LOG_COLUMN_COUNT; i++)
    {
      logFile.print(log_col_names[i]);
      if (i < LOG_COLUMN_COUNT - 1) // If it's anything but the last column
        logFile.print(','); // print a comma
      else // If it's the last column
        logFile.println(); // print a new line
    }
    logFile.close(); // close the file
  }
}

// updateFileName() - Looks through the log files already present on a card,
// and creates a new file with an incremented file index.
void updateFileName()
{
  int i = 0;
  for (; i < MAX_LOG_FILES; i++)
  {
    memset(logFileName, 0, strlen(logFileName)); // Clear logFileName string
    // Set logFileName to "gpslogXX.csv":
    sprintf(logFileName, "%s%d.%s", LOG_FILE_PREFIX, i, LOG_FILE_SUFFIX);
    if (!SD.exists(logFileName)) // If a file doesn't exist
    {
      break; // Break out of this loop. We found our index
    }
    else // Otherwise:
    {
      SerialMonitor.print(logFileName);
      SerialMonitor.println(" exists"); // Print a debug statement
    }
  }
  SerialMonitor.print("File name: ");
  SerialMonitor.println(logFileName); // Debug print the file name
}

Basically the code get the values os lat, long, alt, etc and log into csv file on sdcard. Unfortunately I'm always get no gps data. What's wrong with my code?
Update:
Test serial connection with this code:
#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Teensy 3.0 & 3.1  21        20         22
// Teensy 2.0         9        10       (none)
// Teensy++ 2.0      25         4       26, 27
// Arduino Uno        9         8         10
// Arduino Leonardo   5        13       (none)
// Arduino Mega      46        48       44, 45
// Wiring-S           5         6          4
// Sanguino          13        14         12

AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  altSerial.println("Hello World");
}

void loop() {
  char c;

  if (Serial.available()) {
    c = Serial.read();
    altSerial.print(c);
  }
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
  }
}

I just receive the menssage "AltSoftSerial Test Begin", so the problem may be the serial port?

Hi How do you adjust the date and time to be the same in my country? I am from the Philippines. thanks!

The comments in the AltSoftSerial Test say that you have to connect the GPS to pins 8 (RX for GPS TX) and 9 (TX for GPS RX).  Your shield does not have jumpers for those pins, but you could use a jumper wire to connect any of the TX pins (0-7) to Arduino pin 8 (on the edge of the shield).
I would also recommend looking at my NeoGPS library.  It's smaller, faster, more accurate and more reliable than all other GPS libraries.  Even if you don't use it, there are lots of tips on the Troubleshooting page.
Be sure to read about choosing a serial port for the GPS device.  That's especially important.  In your case, you could use pins 0 and 1.  SoftwareSerial is the worst choice and is NOT recommended.
There is also an NMEASDlog example.  Unlike examples from other libraries, the NeoGPS examples will reliably work at high update rates and with slow SD cards.
NeoGPS is also available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

Please see my update with a image of my shield, so the pin 0 and 1 already are connected, ok? I opened the file GPSPort.h in the NeoGPS library and uncomment the line #include <NeoHWSerial.h>    // NeoSerial or NeoSerial1 Interrupt-style processing, but a receive the menssage h:159:84: fatal error: NeoHWSerial.h: No such file or directory

The images above show pins 2 & 3 are connected.  That would require downloading NeoSWSerial for all examples.  If you want to use Arduino pins 0 & 1, most examples should work on Serial.  Start with NMEA.ino and NMEAorder.ino.  Before trying to run the NMEASDlog example, you should try NMEA_isr.ino.  You will need to download NeoHWSerial and enable NMEAGPS_INTERRUPT_PROCESSING in Arduino/Libraries/NeoGPS/src/NMEAGPS_cfg.h.  When that works, you can try NMEASDlog.ino

Thank you for help, I'm very newbie on arduino, in my case I don't know how to do the connection/wiring on ports 0 and 1 using that shield.

Put one jumper block connecting the TX / Digital at column 0, and one on the RX / Digital to column 1 (or vice versa).  From your picture, just move the 2 yellow jumper block rectangles to the right by 2 spaces.

This is the problem, there is no the pins check in the image

"There is no the pins" ?  Please edit your original post and insert the image.

The RX/TX pins do not line up with the Arduino pins, so RX/TX pins 0 and 1 are the two columns at the right side, under Arduino pins 2 & 3.  That's confusing, but that should connect the GPS to Arduino pins 0 and 1, as I described earlier.

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


text:
Adafruit Huzzah Feather not resetting and serial monitor garbage

Hi there,
I have an Adafruit Huzzah Feather project laid out as you can see in the diagram above.
Currently I am having trouble getting it to reliably reset and start the sketch. More often than not I receive garbage in the serial monitor and the sketch doesn't begin.
The baud rate is set to 115200 and when the sketch occasionally I begin to see the expected behaviour and serial messages.
I have done some tests to see if the serial connection is causing a problem. I uploaded a sketch with and without Serial.begin(115200);. Without this the sketch behaves as expected (I'm flashing an LED sequence to know when the loop has begun). When I add serial communication back I get about 50/50 success rate when resetting.
Here are some thoughts about what could be the problem:

A problem with circuitry. Not sure if something is causing the board to occasionally activate the bootloader? After reading some of the FAQs I'm wondering if I'm accidentally pulling a GPIO pin low. However time has been spent making sure the problematic GPIO pins (0, 2 15) aren't being used.
Possible problem with the board itself - but this is unlikely because there are two of them with exactly the same problem.
Problem with the code. (https://pastebin.com/VAEreu6b)

Any thoughts and suggestions are very welcome at this stage.
Best,
Gareth
EDIT: Forgot to add code. Now here: https://pastebin.com/VAEreu6b

... and the code is?

Ah yes! That would be helpful: https://pastebin.com/VAEreu6b

GPIO1 and 3 are used by serial, is there a conflict there?

GPIO1 isn't being used and 3 is connected to an accelerometer using i2c. Would that cause a problem?

@gfte yes it is the problem. pin 4 and 5 are default for I2C in esp8266 arduino core. the accelerometer library uses pin 3?

Serial is connected to USB, so pin 1 and 3 should not be used if USB communication is used


text:
HTTP Requests using Arduino
I use this simple HTTP Post request to post some values on my API from Arduino using Switch. each time I push the switch it send a different values to API.
void switch_led() {
bool SwitchReading = digitalRead(SWITCH);
if (SwitchReading == HIGH) {
Serial.println("Now pressed....");
state = state + 1;
if (state % 2 != 0) {
  digitalWrite(LED, HIGH);
  char data1[] = "{""LDRValue"": 88888888}";
  Serial.println("\nStarting connection to led server...");
  if (client.connect(server, 8040)) {
    Serial.println("connected to post server");
    client.println("POST /api/sensor HTTP/1.1");
    client.println("Host: 192.168.2.116:8040");
    client.println("Content-Type: application/json");
    client.print("Content-Length: ");
    client.println(sizeof(data1));
    client.println();
    client.print(data1);
    Serial.println("1.finish");
  }
  Serial.println("2.finish");
}
else {
  digitalWrite(LED, LOW);
  char data2[] = "{""LDRValue"": 1111111111}";
  Serial.println("\nStarting connection to led server...");
  if (client.connect(server, 8040)) {
    Serial.println("connected to post server");
    client.println("POST /api/sensor HTTP/1.1");
    client.println("Host: 192.168.2.116:8040");
    client.println("Content-Type: application/json");
    client.print("Content-Length: ");
    client.println(sizeof(data2));
    client.println();
    client.print(data2);
    Serial.println("3.finish");
  }
  Serial.println("4.finish");
}
delay(500);
   }
}

It works perfect for the first and second posts in both Arduino and API but at the third post it works fine on Arduino but it takes long time on the API(about 2 minutes to get the post).
The fourth and the fifth posts also works fine but the sixth is same as the third.
Knowing that my API works 100% with Raspberry Pi and it has no errors.
The same thing for PUT and GET.
After Edition:
After I remove the port number from the host line and using strlen(data)instead of sizeof(data), the POST request works but only for first 7th posts. The output of serial monitor on Arduino is like that:
Attempting to connect to WPA SSID: WiFi-Repeater1

WiFi connected
SSID: WiFi-Repeater1
IP Address: 192.168.2.149
signal strength (RSSI):-66 dBm

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...
connected to post server

Starting connection to post server...

Starting connection to post server...

Starting connection to post server...

Before the Editing, it was always giving me "connected to post server" and It always posts but as I told you before It takes a lot of time at the 3rd 6th 9th 12th ..... Now after the 7th post it will not posts.

Escape the quotes in your strings. Don't include the port number in the HTTP host header. Use strlen() instead of sizeof().

@TisteAndii which quotes to escape ?

@TisteAndii please see the output in the question

I figure out the problem.
To solve the session between Arduino and the server must ended after each Post using  client.stop();
void switch_led() {
      bool SwitchReading = digitalRead(SWITCH);
      if (SwitchReading == HIGH) {
        state = state + 1;
        if (state % 2 != 0) {
          digitalWrite(LED, HIGH);
          char data1[] = "{""LDRValue"": 88888888}";
          Serial.println("\nStarting connection to post server...");
          if (client.connect(server, 8040)) {
            Serial.println("connected to post server");
            client.println("POST /api/sensor HTTP/1.1");
            client.println("Host: 192.168.2.116");
            client.println("Content-Type: application/json");
            client.print("Content-Length: ");
            client.println(strlen(data1));
            client.println();
            client.print(data1);
          }
          client.stop();
        }
        else {
          digitalWrite(LED, LOW);
          char data2[] = "{""LDRValue"": 11111111111}";
          Serial.println("\nStarting connection to post server...");
          if (client.connect(server, 8040)) {
            Serial.println("connected to post server");
            client.println("POST /api/sensor HTTP/1.1");
            client.println("Host: 192.168.2.116");
            client.println("Content-Type: application/json");
            client.print("Content-Length: ");
            client.println(strlen(data2));
            client.println();
            client.print(data2);
          }
          client.stop();
        }
       }

you may wish to do more than just client.stop:
// ensure the client is clean
while (client.connected()) { while (client.available()) client.flush(); }
client.stop();

also; if you are using a WiFi shield; you may want to take a look at a known issue where on a failed connection; the socket isn't released. i simple patch is required to make it work flawlessly:
https://github.com/arduino-libraries/WiFi/issues/5

I THINK the problem might be the client.println() statement.  I believe REST messages should be terminated with a \r\n and I think println just does \n.  So if you change it to client.println("\r") it should start working on every message.
Also you might want to consider moving creating the message into a function to reduce the amount of code you have.

It doesn't work.

No it doesn't because it should be client.println(sizeof(data2));  client.println(); client.print(data2); client.println("\r");  I misread that you hadn't added the new line at the end of the message.

It works but the same problem appears. First 2 posts works fine the 3rd needs a lot of time, and then 4th and 5th are ok, 6th same as 3rd.

3rd, 6th, 9th, .......and so on are not working well. But all the other posts works 100%

The pattern that is happening sound like it may be a leak of some sort, or a lack of resources.  You are not leaking memory. Do you need to disconnect or call a function to mark that you have finished? Could it be that the data1 and data2 values need Null terminating and extra space to allow for that?  What does sizeof (data2) actually return, is it right, would strlen(data2) be better? Is your server expecting 8 byte characters or UTF-16, should you message define that?

Please see the output in the question

So it was "Do you need to disconnect or call a function to mark that you have finished?"
Glad it solved. :)

I've observed that virtually every example of an Arduino web server posted online fails to adhere to the HTTP standard. When a "GET" request is received, the server should parse the "Content-Length: xxx" attribute to get "xxx", then read xxx characters. When sending a web page to a client, the length of the request should be calculated, omitting the HTTP headers (everything before the "html" tag) and the "Content-Length: xxx" attribute should be included in the header, where xxx is the length of the response from "html" tag to "/html" tag, inclusively.
I had the same problem described here, and nothing I did fixed it until I implemented the standard-compliant code described here.

How does this answer the question? The code in the question isn't missing the Content-Length header. If you are commenting on the code in the question as a solution to your problem, then this obviously isn't an answer to the question.

It highlights what the poster is doing right, which the original post didn't draw much attention to. I just spent lots of time figuring this out for myself, and thought highlighting the correct use of Content-Length here might be helpful to others.


text:
Is this Arduino NANO counterfeit?
Today i bought my second NANO(First one was made of Gravitech).I have some doubts that if it is a counterfeit product.I have noticed some points & they are as follows.
1)No "NANO" printed on the top of the board.
2)The atmega328p is in MLF package.
3)A diode soldered on the back side of a board is not properly positioned.
4)No version is printed anywhere.
5)The word "ICSP" not printed near the ICSP header.
6)No pin marking(white dot) for ICSP pin#1.
The seller is a very reputable one in India.That's why i can't be 100% sure if it is a counterfeit product.
I am attaching some pics.Please take a look & give your valuable feedback.

enter image description here

I am just guessing when I say: the mlf package is no problem, the missing label "nano" on top and missing version might indicate a first test run. The misalignment is bad, that should not happen. The soldering quality is good. Is that a real ftdi chip, it probably is or else it stops working in windows. Overall it seems a genuine arduino board, but it might be a production test run.

Thanks a lot,that is a news of relief!
I tested the FTDI chip & it is still running correctly(without getting bricked).Also i have a counterfeit FTDI & some real FTDIs laying around.I compared this one with those side by side.Also from the physical appearance,this one looks genuine.

Have you seen the newest photos? https://store.arduino.cc/arduino-nano Two of the three photos have the mlf package, the white button, the yellow foil on the usb connector. After they made your board, they decided to add the name "nano" on top and the dot at pin 1 of the icsp connector.

Where did you find the arduino nano with mlf package in the Arduino page?I can see only two images both with tqfp packages!!And in my case,seems like they didn't decide to put the name nano on it

This is the same as the package in your photo: https://store-cdn.arduino.cc/uni/catalog/product/cache/1/image/500x375/f8876a31b63532bbba4e781c30024a0a/a/0/a000005_iso.jpg

strange!
I can't find this photo in arduino.cc website...But the direct link you provided is working fine!!


text:
Digispark / Digikeyboard code doesn't execute inside setup{}
Here's sample code to demonstrate my problem:
#include <DigiKeyboard.h>

void setup() {
  // put your setup code here, to run once:
  delay(5000);
  DigiKeyboard.print("TESTING TESTING");
  pinMode(1,OUTPUT);
  digitalWrite(1,HIGH);
}

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

My problem is that I can't get Digikeyboard.print() or other Digikeyboard commands (e.g. sendKeyStroke()) to do anything while they are located inside the setup function. The led command after the print command executes properly.
The print command will work if I place it inside the loop function. However, I want to only execute this code once.
Any assistance would be appreciated, and I would be happy to provide more information if necessary.
EDIT: I worked around this by using a if-expression inside the loop function to only run the code once. However, I am still interested in learning why my original code doesn't work.

The (hard to find) documentation on the DigiKeyboard example:
http://digistump.com/wiki/digispark/tutorials/digikeyboard
States:

It is essential that DigiKeyboard.update() is called regularly (the
  beginning of the loop is good) to maintain USB communication. Using
  DigiKeyboard.delay() will automatically spam DigiKeyboard.update()
  calls during the delay period. If your loop code is fast just using
  DigiKeyboard.delay() will be sufficient.

Without looking deeper into it, I suspect that your initial call to DigiKeyboard.print() fills a buffer and DigiKeyboard needs subsequent repeated calls in order to empty the buffer.
Does the problem still exist if you put DigiKeyboard.update() as the only statement in the loop() function?

Problem still persists. However, after reading your cited part from the documentation, I changed delay(5000) to DigiKeyboard.delay(5000), and the code works properly.

In your initial try, did you put the DigiKeyboard.update() in your run-once loop, or outside it?

For your suggestion, I used the code written in the original post, and placed DigiKeyboard.update() as the only statement in the loop() function

DigiKeyboard.delay() will allow the USB interface to enumerate, which is essential before you can communicate in any form over the interface.


text:
Recognize Morse-like code words
In a line there're voltage levels representing words of dots and dashes. In particular, the device is intended to raise an output each time a given pattern of five short/long signals (say 1s and 2s durations, respectively) is recognized (and restart if nothing comes in for a given time). A sort of Morse code recognizer (Arduino Uno preferred, but others are also OK) would be a good starting point. Any hint is welcome, I'm new in this community.

Use a GPIO of an Arduino and check (at the speed you need) the HIGH/LOW state.
Depending on the speed at which is sent, you can check the dots and dashes being sent, e.g. by keeping a timer since the last change checking if it is a short or long 'HIGH'.
You have to sample often enough to check if there is a drop (between dots/dashes).

Is Arduino Uno the best selection to implement this device? Since it's going to be embedded (the smallest, the better), I would like to know the best fitting option.

There are many microcontrollers. Arduino is not the smallest or cheapest, but probably the easiest to program, especially if you are new to microcontrollers). There are smaller, like Arduino micro/nano etc, which also are not difficult to program.
There are also other (small) microcontrollers, even cheaper, but mostly those have a more steep learning curve, like PIC, STM8/32.


text:
Cannot spin motor 28BYJ-48 with controller board ULN2003APG
I'm a beginner with Arduino. I managed to grasp the basic understanding and try to use each component/shield that came with my Arduino kit.
I'm unable to use the following component:

Step Motor 28BYJ-48
Step Motor controller board ULN2003APG

I connected the Arduino to the ULN2003APG and put some coding such that I can see that the ULN2003APG's LED turned on from 1, 2, 3, 4, 1, 2, 3, 4, and so on. So this is as expected as per programming below.
My issue:

I noticed the LED in the ULN2003APG is not as bright as a regular
LED.
Once I plugged in the 28BYJ-48 to the ULN2003APG, the ULN2003APG's LED all off.
The motor (28BYJ-48) doesn't spin - at all.
I tried to spin the motor with my 2 fingers, it seems pretty heavy - is this normal?

Is this a faulty ULN2003APG or is it a faulty 28BYJ-48 or is it a faulty programming? please help.
Program:
#include <Stepper.h>

int pin1=8;
int pin2=9;
int pin3=10;
int pin4=11;
int _step=0;
void setup() {
    Serial.begin(9600);
    pinMode(pin1, INPUT);
    pinMode(pin2, INPUT);
    pinMode(pin3, INPUT);
    pinMode(pin4, INPUT);
}

void loop() {
  switch (_step){
    case 0:
      digitalWrite (pin1, HIGH);
      digitalWrite (pin2, LOW);
      digitalWrite (pin3, LOW);
      digitalWrite (pin4, LOW);
      break;
    case 1:
      digitalWrite (pin1, LOW);
      digitalWrite (pin2, HIGH);
      digitalWrite (pin3, LOW);
      digitalWrite (pin4, LOW);
      break;
    case 2:
      digitalWrite (pin1, LOW);
      digitalWrite (pin2, LOW);
      digitalWrite (pin3, HIGH);
      digitalWrite (pin4, LOW);
      break;
    case 3:
      digitalWrite (pin1, LOW);
      digitalWrite (pin2, LOW);
      digitalWrite (pin3, LOW);
      digitalWrite (pin4, HIGH);
      break;
  }
  _step ++;
  if (_step == 4){
    _step = 0;
  }
  Serial.println(_step);
  delay(250);

}

What happens if you change
pinMode(pin1, INPUT);
pinMode(pin1, INPUT); // Pin 2 ?
pinMode(pin3, INPUT);
pinMode(pin4, INPUT);

to
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);

Answer for Q1 - Q3. You are using pinMode as an input. Using digitalWrite() on an INPUT will enable (HIGH) or disable (LOW) the internal pullup resistor on the input pin. The pin will not be able to "source" enough current to operate the stepper motor.
A4. The stepper motor has a "mechanical" 1/64 gear ratio. This is why it is hard to turn by hand.
Here are 2 pages that will help you to understand the issue: https://www.arduino.cc/en/Reference/PinMode and https://www.arduino.cc/en/Reference/DigitalWrite.

Hey, sorry let me fix that.

It works, thanks a lot! I noticed the typo on the pin1 and pin1. Then, as you point out the INPUT should be OUTPUT. Thanks again!


text:
Arduino Serial Communication Issue
I state that I have already written a similar question on StackOverflow thinking that the problem is with my computer software. Anyway, after some shell debugs, I notice that the real issue is on the Arduino Due serial communication.
I am trying to send several data (around 500) from an Arduino Due to a computer software. In order to perform some test I write this little software:
  int dle = 10;
  int stx = 2;
  int etx = 3;
  int counter = 0; //It define the sample frequency
  int dataLength = 7; //How many data I have to read
  // The array of byte will be with this structure
  // DLE,STX,Data1HighByte,Data1LowByte,..,Data7LowByte,CounterHigh,CounterLow,DLE,ETX
  //int arrayLength = (dataLength + 1 ) * 2 + 4;
  byte buff[20];
  int val = 0;

  int myTime = 0; //it is used in order to define the sampleFrequency

  void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200, SERIAL_8N1);
    buff[0] = dle;
    buff[1] = stx;
    for (int i = 2; i < sizeof(buff) - 2; i++) buff[i] = 0;
    buff[sizeof(buff) - 2] = dle;
    buff[sizeof(buff) - 1] = etx;

    myTime = millis();
  }

  void loop() {

    //fill the buffer
    for (int c = 0; c < dataLength; c++) {
      val = analogRead(c);
      val = 30 + c; //as a test
      buff[c * 2 + 2] = (byte)((val & 0xFF00) >> 8);
      buff[c * 2 + 3] = ((byte)(val & 0x00FF));
    }
    buff[dataLength * 2 + 2] = (byte)((counter & 0xFF00) >> 8);
    buff[dataLength * 2 + 3] = ((byte)(counter & 0x00FF));

    counter++;

  //print the content on serial
    for (int i = 0; i < sizeof(buff); i++) {
      Serial.write(buff[i]);

    }

    if ( millis() - myTime >= 1000 ) { //if is passed 1 sec, the counter will be reset
     // Serial.println(counter);
     // delay(1000);
      myTime = millis();
      counter = 0; //This identify the sample frequency
    }
  }

As you can see, the arrays of bytes that I send have the form of DLE-STX-DATA-DLE-ETX. Anyway, some data are missing and some other data get strange values.
Here are an output example (1000 samples):
    Reading 0 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,44,10,3
    Reading 1 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,45,10,3
    Reading 2 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,46,10,3
    Reading 3 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,47,10,3
    Reading 4 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,48,10,3
    Reading 5 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,49,10,3
    Reading 6 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,50,10,3
    Reading 7 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,51,10,3
    Reading 8 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,52,10,3
    ...
    Reading 173 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,217,10,3
    Reading 174 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,218,10,3
    Reading 175 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,219,10,3
    Reading 176 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,220,10,3
    Reading 177 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,221,10,3
    Reading 178 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,222,10,3
    Reading 179 time: ,0,33,0,34,0,35,0,36,0,170,10,3,10,2,0,30,0,31,0,32
    Reading 180 time: ,0,33,0,34,0,35,0,36,0,171,10,3,10,2,0,30,0,31,0,32
    Reading 181 time: ,0,33,0,34,0,35,0,36,0,172,10,3,10,2,0,30,0,166,10,
    Reading 182 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,167,10,3
    Reading 183 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,168,10,3
    Reading 184 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,169,10,3
    Reading 185 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,170,10,3
    Reading 186 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,171,10,3
    Reading 187 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,172,10,3
    Reading 188 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,173,10,3
    Reading 189 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,174,10,3
    ...
    Reading 607 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,8,10,3
    Reading 608 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,9,10,3
    Reading 609 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,10,10,3
    Reading 610 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,11,10,3
    Reading 611 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,12,10,3
    Reading 612 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,13,10,3
    Reading 613 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,14,10,3
    Reading 614 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,10,30,0
    Reading 615 time: ,31,0,32,0,33,0,34,0,35,0,36,1,145,10,3,10,2,0,30,0
    Reading 616 time: ,31,0,32,0,33,0,34,0,35,0,36,1,146,10,3,10,2,0,30,1
    Reading 617 time: ,140,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 618 time: ,141,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 619 time: ,142,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 620 time: ,143,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 621 time: ,144,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 622 time: ,145,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 623 time: ,146,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 624 time: ,147,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 625 time: ,148,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 626 time: ,149,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    Reading 627 time: ,150,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1
    ...
    Reading 994 time: ,189,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0
    Reading 995 time: ,190,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0
    Reading 996 time: ,191,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0
    Reading 997 time: ,192,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0
    Reading 998 time: ,193,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0
    Reading 999 time: ,194,10,3,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0

As you can see, in this example, Arduino lost some bytes. In addition, the counter has a strange behavior. It, when I "lost" the data jump to another "random" value. For example in the line 178-182
Reading 178 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,1,222,10,3
Reading 179 time: ,0,33,0,34,0,35,0,36,0,170,10,3,10,2,0,30,0,31,0,32
Reading 180 time: ,0,33,0,34,0,35,0,36,0,171,10,3,10,2,0,30,0,31,0,32
Reading 181 time: ,0,33,0,34,0,35,0,36,0,172,10,3,10,2,0,30,0,166,10,
Reading 182 time: ,10,2,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,167,10,3

it has the value of 1 in high byte and 222 in low byte. Anyway, at the next reading, the value become 0 for high byte and 170 for low byte. And lastly (line 181), it restarts normally to count with 0 in high byte and 166 in low byte.
I try to change the device (I test on an Uno and the problem is the same), the communication protocol (with parity, etc), change the baud and use another PC. The issue is always the same.

I suggest you start smaller and work up to your whole program.  Begin with just sending the same thing over and over with a counter that increments.  That way you will make sure you have a good serial connection to start with.

I try to send a simple package with this structure: DATA-COUNTER-DLE-ETX. In this test the data is a simple 30, the counter is a counter, and DLE=254, ETX=255. So, the array of bytes is composed of 6 bytes (2 for the data and 2 for the counter). Anway, the problem persist.

How about if you send only the counter and no other data?    My point is that you want to try to trap the bug by proving the basics work.

authors: ИП-312 Борис Цилько


text:
ESP8266 not working. No response

Hello. I have begun working with an ESP8266 and an Arduino Uno. The connection I used is shown below, except I am using an Arduino Uno. The rest of the connection is the same.
The code I'm using is:
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX

void setup() {
  Serial.begin(9600);
  ESPserial.begin(9600);
  Serial.println("");
  Serial.println("Remember to to set Both NL & CR in the serial monitor.");
  Serial.println("Ready");
  Serial.println("");
}

void loop() {
  if (ESPserial.available()) {
    Serial.write( ESPserial.read() );
  }
  if (Serial.available()) {
    ESPserial.write(Serial.read());
  }
}

But the serial monitor is only printing:

Remember to to set Both NL & CR in the serial monitor.
Ready

What to do?

assume same connection as in diagram. Still not working.

thanks dear..i have edited the ques. Can  u tell me i have to connect RST to GND. right?

thanks. Can u give me your email id. I have to complete a project. I need help.

still not working. i have connected the RST and CH_PD pin to 3.3V via 10K resistor.

I don't know then, sorry. Are you sure 9600 is the default baud rate for the ESP? Does resetting the ESP (quickly connect RST to GND) make anything appear, even junk?

Most esp's default Baud rate is 74880 or 115200 ... try connecting ESP directly to your computer (you'll need a USB->Serial board, FTDI or similar) and find which baud rate is correct

ESP8266 WiFi modules typically have a baud-rate of 115200. This not only won't work with a 9600 baud host but SoftwareSerial can't go that fast. Or, more precisely, it can generally push out characters at that speed but it can't keep up with incoming ones. See this answer for how to change the speed of your module to 9600 baud.
Short answer: You have to reconfigure your ESP module to 9600 baud to use it with SoftwareSerial. You can do it blind (transmit a baud-change command to it at 115200 baud, even though you won't be able to read the reply). Once done, it will remain at 9600 baud and successfully communicate in both directions.

ESP01 has two variants (blue PCB and black PCB), the old is configured to use 9600 baud (blue PCB) and the newer one uses 115200 baud (black PCB) as default.
There is also a difference in memory, 512kByte (4Mbit) or 1MB (8Mb) between the old and new version.
So try to change
ESPserial.begin(9600);

to
ESPserial.begin(115200);

And preferably both 9600 to 115200.

You need to pull RST high - that is, connect a 10k between +3.3v and the ESP8266-01's RST pin.

still not working. i have connected the RST and CH_PD pin to 3.3V via 10K resistor

gpio0 and gpio2 should also be high (gpio0 low for flash mode though) ... however, all my dev boards (for 07, 12E and 12F modules) have the pullups on 0 and 2 and a pulldown on 15. The base modules also seem to have a pullup on CH_PD and RST as well, so you can literally connect gnd/vcc/rx/tx and away you go -


text:
Which relay module to buy and what is the difference between 1 channel and 2 channel relay boards
I wanted to d a simple circuit using Arduino to control the lights in my house. But i do not know which relay module to use my house runs on standard 220v ac.
Can anyone tell me weather this relay board will be enough
https://www.roboelements.com/wp-content/uploads/2018/10/1-Channel-5V-Relay-Module-for-Arduino-with-Optocoupler.jpg
Or should I buy a 2 channel one?
And another thing what is the difference between 1 channel and 2 channel relay board.
I'm a complete beginner, so please help me out.

A 1-channel relay board can switch one load, a 2-channel relay board can switch two loads independently. I don't want to sound patronizing but it looks like you have little experience with mains voltage. Please be very, very careful!

Yes, you can use those. You have to watch a few things:

Input voltage: 5V, perfect for Arduino
Output voltage: 220 V, perfect for 220V AC
Output amperage: 10A, what you control should use max 10 A, and I would use max 5A, and also consider switching on current into account. However, 10A is a lot of current.

The difference between 1 and 2 channels relay boards, is just that there are either 1 or 2 of them, meaning you can control 1 or 2 motors independently from each other.

really helpful ;))

Good luck with your project


text:
Using Sleep AND LowPower.h
I am trying to set up the low power module for an instance case,
I have installed the low power library but when I am using the
line
LowPower.powerDown (SlEEP_5S, ADC_OFF, BOD_OFF) ;

It is throwing an error stating that the 'SLEEP' was not declared in the scope.
Any suggestion for that ? Do I have to include a library for sleep too ?
#include "LowPower.h"
  /// DON' t worry about the setup and loop, i have defined all those.

This set of code is in
  void Loop()
    ...
    else
    {
       LowPower.powerDown (SLEEP_10S, ADC_OFF, BOD_OFF) ;

SlEEP_5S ... should that be SLEEP_5S ?

Sorry ! I didnt get you

you can't see the difference between SlEEP and SLEEP?

nope i tried that, doesn't work.

i defined along with the package #include "LowPower.h"  #define SlEEP_5S, this leads me to an error that expected primary-expression before ','token

Void instead of void? An else without an if?  Your program will have many more problems right now. Note that the language is case sensitive.

I updated your code assuming that you typed it over (so changed void / else.

There is no 5 or 10 second sleep. You can't just arbitrarily choose how long to sleep for. The watchdog timer only has specific periods (defined by dividing the clock by a set amount) that it can sleep for:
enum period_t
{
    SLEEP_15MS,
    SLEEP_30MS,
    SLEEP_60MS,
    SLEEP_120MS,
    SLEEP_250MS,
    SLEEP_500MS,
    SLEEP_1S,
    SLEEP_2S,
    SLEEP_4S,
    SLEEP_8S,
    SLEEP_FOREVER
};

To sleep for 5 seconds you would need to sleep first for 4 seconds, then wake up, and then sleep for a further 1 second after that. For 10 seconds sleep for 8 seconds followed by 2 seconds.
Note that they aren't exact values, however, since the watchdog oscillator is very crude and varies wildly in frequency with both temperature and power supply voltage.


text:
Motor driver not working properly in case we connect motor to it
We are making a Bluetooth controlled RC car. when we connect our motor (moderate power) to motor driver then  Bluetooth module is automatically disconnected after taking initial command from Arduino code ,and if we connect our led (low power) instead of Motors to motor driver then project is working fine. what could be the possible problem?

Tell us which motor it is and which battery you use. The motor might ask ten times more current than the battery can deliver.

I am using a 4volts rechargeable battery with a supply of 2Ampere hour.and motors are of moderate power and taking current of 7 amperes each when connected independently to battery.

And motor driver is L298n type.

Can you give the brand and type of the battery and the motor and a link to them? Please add the extra information to your question. The l298n can be used with a 12v battery and a small motor, but not with a 4v battery. Do you know the stall current of the motor?

Ok let me try a 12volts battery to my setup.

Are those 12v motors?

@Jot, that appears to be a secret .... lol

These motors can also be run by 4volts supply. As you suggested to give motor driver 12volts supply,it worked fine. And thanks for your precious suggestions.

@jot ,if you want to help me more ,please post a circuit diagram showing different connections to arduino uno,motor driver l298n, and hc05 bluetooth module to the motors. Thanks in advance.

I used an external battery to supply the motor, and a BJT as a switch to trigger it (Base connected to Arduino).


text:
Not getting data from GPS
When I run FullExample program from TinyGPS++, I get following types of entries,
Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum
          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail
---------------------------------------------------------------------------------------------------------------------------------------

0    9999 ********** *********** **** 07/01/2016 07:32:50 689  ****** ****** ***** ***   ******** ****** ***   75128 0         0
0    9999 ********** *********** **** 07/01/2016 07:32:51 857  ****** ****** ***** ***   ******** ****** ***   75389 0         0
0    9999 ********** *********** **** 07/01/2016 07:32:52 864  ****** ****** ***** ***   ******** ****** ***   75642 0         0
0    9999 ********** *********** **** 07/01/2016 07:32:53 870  ****** ****** ***** ***   ******** ****** ***   75895 0         0
0    9999 ********** *********** **** 07/01/2016 07:32:54 878  ****** ****** ***** ***   ******** ****** ***   76148 0         0

Other details:
GPSBaud = 9600;
RXPin = 11;
TXPin = 10
Module: GY-NEO6MV2

you've failed to mention which GPS module

@JaromandaX: I have updated he module name.

That is a perfect printout of a GPS system that can see zero satellites.
The fact that the timestamps are one second apart shows that you have correctly interfaced with the GPS device. Now, the GPS device has to 'interface' with the satellites!
Many people don't realise two things:

The GPS antenna really does need a clear view of the sky. A tiny view through a window may show one or two satellites, but you need a minimum of three, and preferaby four or more at a number of points around the sky to get a fix.
If the GPS unit has been completely powered off (called 'cold'), when it first powers on it has NO idea where anything is. It simply listens for any signal anywhere until it "hears" the current time. It can then guess where satellites might be, and listens for updates on satellite positions.

All of this listening, guessing and waiting takes time before it can start to actually lock on to satellites and start to get a fix. This time could easily be 90 seconds or more - you need to be patient. Check your GPS device specifications for "cold start" times.
Edit
I'm impressed! The GY-NEO6MV2 that you list has a cold-start of 27 seconds - but that assumes it has a clear view of the sky.

Yes, putting it outside, I get 6 sats. Thanks.

The GPS actually seems to be getting some data: the date and time.
Which means it can be used to set the time (and date) in a clock if the timezone is known without needing a fix (useful inside).


text:
Arduino Micro Println prints 0
I am having troubles with my arduino micro.
In my programming, I am using the serial. When I use println, nothing shows up in the serial monitor except for 0. So if I type 1, I get back 0 instead of 1, same goes for 3241234 or any random number.
Here is the code:
void setup() {
  Serial.begin(9600); //Connect to the serial monitor console
}

void loop() {
    while (Serial.available() == 0); //Wait until Serial is available

    //Read val
    int val = Serial.read() - '0'; //Val that represents input
    delay(500);
    Serial.println(val);
}

So I have another problem and people have asked for the code. Basically, printing a string returns 0.
 void setup() {
  Serial.begin(9600); //Connect to the serial monitor console
}

void loop() {
    while (Serial.available() == 0); //Wait until Serial is available

    //Read val
    int val = Serial.read(); //Val that represents input

    delay(1000);
    if (val == 1) {
      Serial.print('Firing the motor');
    } else {
      Serial.print('Please press 1 to fire the motor.');
    }

    delay(4000);
}

Instead of printing Please press 1 to fire the motor, I get 0 in the console.
Thanks for the help!

To your second question, strings in C are surrounded by the double-quote character: ", not the the single-quote or apostrophe character.

This time you are comparing an integer 1 with a character '1'.
int val = Serial.read();

Is reading  you pressing the one key and storing it in an integer variable as the number 49 (ASCII '1')
if (val == 1) {

You are now seeing it 49 is the same as 1, which it isn't.
To make your code easier stick to characters.
Change the Serial.Read line to:
const char val = Serial.read(); // Val that represents input
                                // (const because it will not change).

and the if line to:
if (val == '1')  // '1' character 1

By making val const you stop yourself accidentally changing it so if you do
if (val = '4') // Compilation error.

Hope that helps.

Hi Matt, thanks for the help. This is useful. I still cant print the strings I want to: Firing the motor or Please press 1 to fire the motor. I tried replace the ' ' with " " but that doesnt fix it either.

You are right you need double not single quotes so Serial.println("Firing the motor"); is what you need.  println will print a whole line of text.  I am guessing, but it might be something to do with the Serial.Read commands.  Replace you print statements with Serial.write  calls, you will need to look in the manual on www,arduino.cc to get the right parameters.  Make sure you add \n\0 to the end of your strings when you use serial.write.

Hey Matt, using .write returns the amount of characters in a string, so this is not helpful to me. I am going to keep looking, thanks for the help!

@TinoCaer  Serial.write(“hello”);  has the same superficial behaviour as Serial.print("hello");  You can ignore the return value.  Having read the man page I can't see it will help though. :(


text:
'content' is not captured
I try to make a variable that can be modified from the server, using and ESP8266.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

const char* ssid = "********";
const char* password = "*********";

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
    digitalWrite(led, 1);
    server.send(200, "text/plain", "hello from esp8266!");
    digitalWrite(led, 0);
}

void handleNotFound() {
    digitalWrite(led, 1);
    String message = "File Not Found\n\n";
    message += "URI: ";
    message += server.uri();
    message += "\nMethod: ";
    message += (server.method() == HTTP_GET)?"GET":"POST";
    message += "\nArguments: ";
    message += server.args();
    message += "\n";

    for (uint8_t i=0; i<server.args(); i++){
        message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
    }

    server.send(404, "text/plain", message);
        digitalWrite(led, 0);
    }
}

void setup(void) {
    pinMode(led, OUTPUT);
    digitalWrite(led, 0);
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    Serial.println("");

    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());

    if (MDNS.begin("esp8266")) {
        Serial.println("MDNS responder started");
    }

    String content = "Basic";
    content += "<form action='action_page.php' method='POST'>
";
    content += "User:<input type='text' name='USERNAME' placeholder='user name'>
";
    content += "<input type='submit' name='SUBMIT' value='Submit'></form>
";

    server.on("/led", [](){
        server.send(200, "text/html", content);
        Serial.println(USERNAME);
    }

    server.on("/", handleRoot);

    server.on("/inline", [](){
        server.send(200, "text/plain", "this works as well");
    });

    server.onNotFound(handleNotFound);
    server.begin();
    Serial.println("HTTP server started");
}

void loop(void){
    server.handleClient();
}

When I compile it, it says

'content' is not captured

I thought it may be from the input, and I tried to name it "Basic" for the start, but it still failed.

@jwpat7 This code is (in most of its part) took from other examples from libraries and I am not (very) good at this so I can't figure out what do you mean by corecting it.

Possibly  Lambda of a lambda : the function is not captured will be more useful than my previous comment.

And that would be used here like : " server.on("/led" , content{..... " ?

Something like that -- But I'm not familiar enough with C++ lambda syntax to say, perhaps someone else will know.

Ok , I am not in a hurry anyway. Many thanks !

Let's look at a simpler example:
void setup ()
{
  String content = "Basic";

  attachInterrupt (digitalPinToInterrupt (2),
                   []()
  {
    Serial.println(content);
  },

  FALLING );

}  // end of setup

void loop () { }

This gives the error:
/tmp/arduino_modified_sketch_182173/sketch_jan25a.ino: In lambda function:
sketch_jan25a:8: error: 'content' is not captured
     Serial.println(content);

Why? Because you are using a local variable content in a lambda function which runs at global scope. That is, content is not available to it, because it is inside setup.
To capture it, you can put it in the capture list:
  attachInterrupt (digitalPinToInterrupt (2),
                   [content]()  // capture content

However I found that my example doesn't compile even then.

I think the reason for that can be found here: Lambda Functions in C++11 - the Definitive Guide

How are Lambda Closures Implemented?
So how does the magic of variable capture really work? It turns out that the way lambdas are implemented is by creating a small class; this class overloads the operator(), so that it acts just like a function. A lambda function is an instance of this class; when the class is constructed, any variables in the surrounding enviroment are passed into the constructor of the lambda function class and saved as member variables.

You can't pass an instance of a class to attachInterrupt because there is a hidden *this variable that needs to be passed to class instances, and ISRs don't do that.
Now your example isn't an ISR, but probably the same remarks apply.

I don't think there is an enormous amount of point of using lambda functions here. If you must, move content inside the lambda, since that is where you are using it.
Or failing that, make it global scope.

The closest I could get to something that compiled was:
void setup ()
{
  const int content = 42;

  attachInterrupt (digitalPinToInterrupt (2),
                   [=]()
  {
    Serial.println(content);
  },

  FALLING );

}  // end of setup

void loop () { }

Honestly though, I think using lambda functions here just makes your code obscure.

I wrote led instead of lcd. What I am trying to do is : calling a page from the esp8266 that gives me an input box and a submit button. I want to print on the lcd what is written in that box.

Thanks , it solved my error , but , now I have another one : 'void setup()':
lcdWirelessPrint:69: error: expected ')' before 'server'
server.on("/", handleRoot);
^
exit status 1
'User' was not declared in this scope
Another question is , how/where do I declare the name of the variable that I want to have the name of the input .

This sounds like a different question. I suggest you start a new question and post this new code.

Ok , I didn't wanted to open too many , thought it would be anoying.

Are you looking at the last compiler error ? The first one is the most most important one. In the preferences, the compiler output can be turned on to show more. Then scroll up to see the first compiler error. The compiler has troubles with the `` at the very end of your sketch.

They are normal " , they changed when I pasted here. I'll check it tomorrow anyway.


text:
ESP2866 and java ServerSocket
So I have an application that runs on the Arduino that passes info over serial.
I'm using a ESP2866 to make it wireless.
Arduino->Serial->Esp2866->SocketConn->JavaSocket->Console

I have a working java socket server, that I can connect to with other applications. (Java, c++, ext.) And even across the network.
I just cant seem to get my ESP2866 to connect.
Iv tried several ESP2866 units, no success. Iv tried updating the firmware on each, nope.
AT                      ->  OK
AT+RST                  ->  ready
AT+CWMODE=1             ->  OK
AT+CWJAP="name","pass"  ->  CONNECTED,GOTIP,OK
AT+CIPMUX=0             ->  OK
AT+CIFSR                ->  192.168.0.30
AT+CIPSTART="TCP","192.168.0.9","4160"  ->  ERROR

The lack of debug info is... Aggravating.
Iv Seen other examples of this that worked. So whats the problem?
Additional info:
netstat -tulpn | grep 4160
tcp6       0      0 :::4160          :::*      LISTEN      23058/java

(Edit 1:)Just tried restricting to IPV4 and rebinding the port. Nope.
InetAddress localAddress = Inet4Address.getByAddress(new byte[]{(byte) 192,(byte) 168,0,9});
System.setProperty("java.net.preferIPv4Stack", "true");
ServerSocket listener = new ServerSocket(port,20,localAddress);
//...Code to make socket work.

The ESP trys to connect to port 4160, but the server is listing on port 20.

java.net.ServerSocket.ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException

try just writing ServerSocket listener = new ServerSocket(port/ 4160/);

is the port answer solved your problem?


text:
Why is the stack pointer out of range?
I have a function that dumps the contents of the arduino's ram, and it works, but I still dont understand why it says my stack pointer is at 0x08C9 If the ram of the arduino is 2kb, or 2048 bytes, shouldent the max addressable size be 0x0800?
RAM: SP->0x08C9 HP->0x0371 FREE:1368

And the code:
void printAddress(uint16_t val)
{
  Serial.print(F("0x"));
  if(val < 16)
{
 Serial.print(F("0"));
}
if(val < 256)
 {
  Serial.print(F("0"));
}
if(val < 4096)
{
  Serial.print(F("0"));
}
Serial.print(val,HEX);
}

void setup(){
Serial.begin(115200);
//0x0800 2048
uint8_t *heapptr, *stackptr;
stackptr = (uint8_t *)malloc(4);        // use stackptr temporarily
heapptr = stackptr;                     // save value of heap pointer
free(stackptr);                         // free up the memory again (sets stackptr to 0)
stackptr =  (uint8_t *)(SP);            // save value of stack pointer

Serial.print(F("RAM: SP->"));
printAddress(stackptr);
Serial.print(F(" HP->"));
printAddress(heapptr);//(int)&__heap_start);
Serial.print(F(" FREE:"));
Serial.print(stackptr - heapptr);
Serial.println();
}

As a note, Comments are not mine.

Your code comments contain serious conceptual mistakes - free() should not alter the stack pointer at all, and its effect on what it is freeing is undefined (or perhaps better said, access to what was free()'d is subsequently undefined)

Okay, let me rephrase that in light of the edit; the uncredited author of the code you posted has made serious conceptual errors.  You should probably find a different source of inspiration.

Sure... if the RAM started at address 0, which it doesn't.
According to the datasheet the RAM starts at address 0x0100, below which are all the SFRs:

Is the internal Rom mapped below that?

No. The flash (not ROM) is on a separate bus with its own address range.

Sad, cause if it was mapped below the sram that would make it it easy to handle Progmem variables...

That's why there are special helper function ctions to assist you.

True, but it makes it difficult. PROGMEM Variables are treated as char* so creating functions to determine if I need to load it from ROM (Flash, ROM potato, potahto) or not is a crap-shoot. The F() macro Is all well and good to solve that but cant be used with Static variable so that wouldn't work. Had to Use the FLASH_STRING library to do what I wanted. Would have made alot more sense to keep with the memory hierarchy then just throwing it off somewhere else.

But then you need a larger address register to address a larger address space. That adds lots more complexity, not only to the logic implementation in the chip, but also to the instruction set, the ALU, everything. If you want a princeton memory map instead of harvard then you want a PIC32 or an ARM based chip instead of a little 8-bitter.

You could synthesis a linear address space with C++ smart pointers. Writing a byte threaded virtual machine for the Arduino has to deal with the fact that AVR is a Harvard architecture (and not Von-Neumann). https://github.com/mikaelpatel/Arduino-FVM Anyway this is a very interesting challenge and hiding the physical address spaces with C++ even more so.

free up the memory again (sets stackptr to 0)

Freeing memory alters the heap, not the stack. In any case the heap is not like the stack, it is a piece of memory from which memory is allocated, not necessarily contiguously. If you were to allocate A B C from the heap, and then delete B, the heap pointer would be untouched, because it would now have a gap: A ... C

shouldn't the max addressable size be 0x0800?

As Majenko pointed out, RAM starts past the "internal registers" of the processor, so the maximum RAM would be 0x8FF in this particular case.


text:
Unable to issue any AT commands to BT BLE Breakout Board
I'm a programmer, more from the software side but I do have hardware working knowledge too. I've completed the Arduino Starter Kit's 15 projects, Now trying to build some things with ESP8266 and HM-10 BLE.
I was able to connect ESP8266 to my network and start a TCP server too via AT commands(using  Arduino's Serial Monitor and FTDI 232RL USB to TTL converter)
I also have a HM-10 Bluetooth Breakout+connector board (Its based on CC2541 by TI (visible on the SMD chip)) brought from here.
Using the same setup I was able to issue AT commands successfully for ESP8266. However I tried many things, different baud rates and \r\n combinations; I just couldnt get the HM-10 to acknowledge my AT commands.
Setup: link
Connections:
Arduino +5V --> +ve input of LDO regulator --> 3.3v OUPUT to Vcc of HM-10
Common GND for LDO regulator input and output pins, FTDI 232RL and HM10

FTDI TX --> voltage divider (1k ohms --> connection output to HM 10 RX --> 1k ohms --> 1k ohms --> GND)

There is no code/sketch as of now. I'm just trying to hook up the HM-10 BLE chip. I can pair my Android phone to it but that's not the concern here.
The concern here is I cannot configure the HM-10 using AT commands.
The HM-10 does not reply an "OK" acknowledge for my "AT" command. Nothing happens in the serial monitor after hitting enter. Just a blank screen.
Is there a way by which I can determine what baud rate to use and what combination of \r and \n?
What am I missing here?

You might find this helpful: ftp://imall.iteadstudio.com/Modules/IM130614001_Serial_Port_BLE_Module_Master_Slave_HM-10/DS_IM130614001_Serial_Port_BLE_Module_Master_Slave_HM-10.pdf

I found out that there is no need for a voltage divider to reduce the voltage being given to RX pin of BLE from FTDI's TX since both FTDI232RL and HM-10 are 3.3V devices (from here)
I connected the TX from FTDI directly to the RX of BLE using female to female jumpers.
Used No Line Ending and 9600 as the baud rate.
Then it worked fine, I got an OK acknowledge for my AT command.


text:
How can i tell the power status of a GSM900
What I am after is a reliable way of telling whether the GSM900 shield is powered up or not.  "Obviously" the shield power is the constant green light.  But i'm talking about the red light on the other side (next to the flashing green light).
I know i can PowerUp/Down by using the code
digitalWrite(9, HIGH);
Serial.println("write 9 high");
delay(1000);
digitalWrite(9, LOW);
Serial.println("write 9 low");
delay(5000);

And from the AT command manual, I can Power it down by using the command...
AT+CPOWD=1

So it seems that the only way I can ensure that the board is On, is to power it down and then toggle the power.  Surely there's a better way than that?
Another idea is to issue a simple "AT" command, and if I get back "OK" then its on, and if I dont get anything back (timeout of maybe 2 seconds), then its off - thoughts?

the AT command seems decent, but 2 secs is a long time, shouldn't it be a few dozen ms max? you can also solder a bodge wire to the red led annode and feed that to an input to read().


text:
What is recommended color recognition sensor RGB for different cases?
What is recommended color recognition sensor in the following two cases:

To determine the color of the floor while the robot is moving (multi-color line follower).
To determine the color of an object in distance 10cm at least.

For both cases above, I am looking for a sensor so that I can get values like (R: 252 , G: 217 , B: 0) not only red, green or blue as an result, and no problem with small errors.

@LookAlterno e.g. (R: 252 , G: 217 , B: 0)

Why analog? Digital ones are far more common and some give more sensitivity and accuracy than the Arduino ADC can give.

@LookAlterno How many pins do you need to read this three values as digital output? 3 * log2(256) pins !!

@Majenko Could you explain to me how to get values like (R: 252, G: 217, B: 0) using few number of pins, please? (I'm really a newbie).

Question edited, waiting for your answers, thank you all.