Recent Posts

Pages: [1] 2 3 ... 10
1
actually all i need is reading GPIO data... 18 GPIO data will be read and then i need to pass  those GPIO data to another machine
So all you need to do is send and receive 18 bits GPIO that will arrive and be sent as 3 bytes.

...then I will have 2 options, making a String, <10110111101110101..> or composing a byte (2 or 3 based on need) as <F3> and then send it...
Where did the option for sending as a String come from?

String.h should be avoided in the micro world, best to use char[]...since char=byte this now means converting the bits of a byte into a single byte that represents each bit.

Based on the information you have provided, you have either left something out or have all the information you need on what you know you need/want to do.
2
Code: [Select]
if (Busy = 0);
  if (Button2 == HIGH);

Not a compilation error-causer, but you really need to lose the semicolons
3
Hardware / Re: Porta a ghigliottina, cons...
Last post by gpb01 - Today at 08:27 pm
Dopo che avrai fatto quanto richiesto ...
... se fai un po' di ricerche qui nella sezione Italiana del forum ... ricordo che è un progetto di cui si è già discusso in passato (... probabilmente una cosa molto simile). Prova a vedere ... con un po' di fortuna trovi qualche vecchia discussione che ti può essere di spunto.

Guglielmo
4
Code: [Select]
exit status 1

That's the useless message telling you that there was an error.  Before that was a bunch of output about what the error actually was.  That output would be much more helpful. 
5
Hardware / Re: Porta a ghigliottina, cons...
Last post by gpb01 - Today at 08:25 pm
Buonasera,
essendo il tuo primo post, nel rispetto del regolamento (… punto 13, primo capoverso), ti chiedo cortesemente di presentarti IN QUESTO THREAD (spiegando bene quali conoscenze hai di elettronica e di programmazione ... possibilmente evitando di scrivere solo una riga di saluto) e di leggere con MOLTA attenzione il su citato REGOLAMENTO ... Grazie.

Guglielmo

P.S.: Qui una serie di link utili, NON necessariamente inerenti alla tua domanda:
- serie di schede by xxxPighi per i collegamenti elettronici vari: ABC - Arduino Basic Connections
- pinout delle varie schede by xxxPighi: Pinout
- link generali utili: Link Utili
6
Hardware / Re: Alimentazione arduino
Last post by gpb01 - Today at 08:24 pm
Si, l'alimentatore da 1A in su va bene (anche 100A) tanto ... alimentando da 12V, più di 250mA NON puoi assorbire dal pin 5V perché poi, o va in protezione (come dovrebbe) o si brucia (se sei sfortunato), il regolatore a 5V.

Spero che i 5 servomotori li hai alimentati con un'altro alimentatore e NON con il pin 5V di Arduino ... ::)

Guglielmo
7
I have looked but can't seam to find just what I'm doing wrong. Can some one have a look and see what I did wrong.
Lots of people struggle with trying to get a servo to sweep and do other things simultaneously, so don't fret.

I find that the easiest way to accomplish it is also a difficult concept to grasp, particularly if you are not savvy in the way of Object Oriented programming.

Here is an example that basically adds a few functions to the Servo class (update(), moveTo() and moveAllTo()).  Even if you don't understand the class definition, it should get you a long way towards your goal of un-blocking loop().
Code: [Select]
#include <Servo.h>

/******************* BEGIN CLASS DEFINITION *******************/

#define MOTION_SPEED_INTERVAL 10  // milliseconds
#define MAX_SERVO_INSTANCES 5

class Sweep : public Servo {
  public:
    Sweep(void(*_startCallback)(int), void(*_endCallback)(int));
    Sweep();
    void begin(int servo);
    void moveTo(int newPosition);
    static void moveAllTo(int newPosition);
    static void update();
    static void update(uint32_t now);
    static int getServoCount();
    int getPosition (void) const;

  private:
    enum  {
      ARM_STANDBY,
      ARM_MOVING,
    } motionState = ARM_MOVING;
    void(*startCallback)(int);
    void(*endCallback)(int);
    static Sweep* instanceAddress;
    static int instanceCount;
    int servoPin;
    uint32_t lastMotionMillis = 0;
    int currentPosition;
    int targetPosition;
    uint32_t sensedChangedMillis;
    static void setTargetPosition(Sweep* instance, int position);
};

int Sweep::instanceCount = 0;
Sweep* instances[MAX_SERVO_INSTANCES] = {nullptr};

Sweep::Sweep() {
  instances[instanceCount++] = this;
}

Sweep::Sweep(void(*_startCallback)(int), void(*_endCallback)(int)) {
  instances[instanceCount++] = this;
  startCallback = _startCallback;
  endCallback = _endCallback;
}

int Sweep::getServoCount() {
  return instanceCount;
}

void Sweep::begin(int servo) {
  servoPin = servo;
  pinMode(servoPin, OUTPUT);
  attach(servoPin);
  moveTo(0);
  delay(1000);
  detach();
}

void Sweep::setTargetPosition(Sweep* instance, int position) {
  instance->targetPosition = position;
}

void Sweep::moveTo(int newPosition) {
  if (newPosition > 180) {
    newPosition = 180;
  } else if (newPosition < 0) {
    newPosition = 0;
  }
  setTargetPosition(this, newPosition);
}

void Sweep::moveAllTo(int newPosition) {
  if (newPosition > 180) {
    newPosition = 180;
  } else if (newPosition < 0) {
    newPosition = 0;
  }
  for (auto i : instances)
  {
    setTargetPosition(i, newPosition);
  }
}

void Sweep::update() {
  update(millis());
}

void Sweep::update(uint32_t now) {
  for (auto srv : instances) {
    switch (srv->motionState) {
      case ARM_MOVING:
        if (now - srv->lastMotionMillis > MOTION_SPEED_INTERVAL) {
          if (srv->targetPosition == srv->currentPosition) {
            if (srv->attached()) {
              srv->detach();
              srv->motionState = ARM_STANDBY;
              if (srv->endCallback) {
                srv->endCallback(srv->getPosition());
              }
            }
          } else {
            if (!srv->attached()) {
              srv->attach(srv->servoPin);
            }
            if (srv->targetPosition > srv->currentPosition) {
              srv->currentPosition++;
              srv->write(srv->currentPosition);
            } else {
              srv->currentPosition--;
              srv->write(srv->currentPosition);
            }
          }
          srv->lastMotionMillis = now;
        }
        break;
      case ARM_STANDBY:
        if (srv->targetPosition != srv->currentPosition) {
          srv->motionState = ARM_MOVING;
          if (srv->startCallback) {
            srv->startCallback(srv->getPosition());
          }
        }
        break;
    }
  }
}

int Sweep::getPosition(void) const {
  return currentPosition;
}

/******************** END CLASS DEFINITION ********************/

void startMoving(int value);
void stoppedMoving(int value);

Sweep servo1(startMoving, stoppedMoving);  //callback functions to execute when the servo starts or stops moving.
//Sweep servo2;  // callback functions not required

void setup() {
  Serial.begin(9600);
  servo1.begin(4);

  pinMode(13, OUTPUT);
  Serial.print("Total Attached Servos:\t");
  Serial.println(Sweep::getServoCount());
}

void loop() {
  Sweep::update();  // this is necessary
  if (Serial.available()) {
    int destination = Serial.parseInt();
    Serial.print(F("servo1 asked to move to: "));
    Serial.print(destination);
    Serial.print(F(" degrees\n"));
    servo1.moveTo(destination);
  }
}

void startMoving(int value) {
  Serial.print(F("servo1 motion started at: "));
  Serial.print(value);
  Serial.print(F(" degrees\n"));
  digitalWrite(13, HIGH);
}

void stoppedMoving(int value) {
  Serial.print(F("servo1 motion completed at: "));
  Serial.print(value);
  Serial.print(F(" degrees\n"));
  digitalWrite(13, LOW);
}
8
There should be no interaction between the analogWrite() and the encoder interrupts. It would appear there is some sort of cross talk between the input and output wires.

How are they arranged?

You may try putting a capacitor or low pass filter on the encoder output to give some hardware debounce.

You could also try some software debounce with a lockout on the interrupt execution
Code: [Select]
void doEncoder()
{
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time > = 50)//adjust lock out time as necessary
  {
    encoder0Movement = 1;
    if (digitalRead(encoder0PinA) == HIGH && digitalRead(encoder0PinB) == LOW) {    //If encoder is turning clockwise . . .
      encoder0Pos++;                  //Add 1
    } else {
      encoder0Pos--;                  //Subtract 1
    }
  }
  last_interrupt_time = interrupt_time;
}
9
Hello,
I am pretty new on Arduino coding. I created the following code foe a 3 stores elevator
The idea is that once pushed the botton the motor will rotate in one or the other direction based on the position of the elevator to get to the floor.
I am getting the following error message:
[collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.]

Any help/ suggestion would be appreciated

[
int potPin = 0;
int Button1 = 1;
int Button2 = 2;
int Button3 = 3;
int Switch1 = 4;
int Switch2 = 5;
int Switch3 = 6;
int Led1 = 7;
int Led2 = 8;
int Led3 = 9;
int L2 = 10;
int L1 = 11;
int St = 12;
int FLOOR;
int Busy;

void setup() {
  pinMode(Button1, INPUT); // Button 1st floor
  pinMode(Button2, INPUT); // Button 2nd floor
  pinMode(Button3, INPUT); // Button 3rd floor
  pinMode(Switch1, INPUT); // position swith Elevator 1st floor
  pinMode(Switch2, INPUT); // position swith Elevator 2nd floor
  pinMode(Switch3, INPUT); // position swith Elevator 3rd floor
  pinMode(Led1, OUTPUT);   // led 1st floor
  pinMode(Led2, OUTPUT);   // led 2nd floor
  pinMode(Led3, OUTPUT);   // led 3rd floor
  pinMode(St, OUTPUT);     // Power switches
  pinMode(L1, OUTPUT);     // Power motor exit 1
  pinMode(L2, OUTPUT);     // Power motor exit 2
  Busy = 0;                // internal variable define if the elevator is workind and unable push buttons
  FLOOR = 0;               // internal variable determine on which floor the elevator is going
}

void loop1() {  //1ST FLOOR
  if (Busy = 0);
  if (Button1 == HIGH);
  {
    digitalWrite(St, HIGH);
  }
  if (Switch1 == LOW);
  { analogWrite(Led1, HIGH);
    analogWrite(L1, HIGH);
    analogWrite(L2, LOW);
    Busy = 1;
    FLOOR = 1;
  }
}

void loop2() {  //2ND FLOOR
  if (Busy = 0);
  if (Button2 == HIGH);
  {
    digitalWrite(St, HIGH);
  }
  if ((Switch2 == LOW) and (FLOOR == 1))
  { analogWrite(L1, LOW);
    analogWrite(L2, HIGH);
    analogWrite(Led2, HIGH);
    Busy = 1;
    FLOOR = 2;
  }
  else
  { analogWrite(L1, HIGH);
    analogWrite(L2, LOW);
    analogWrite(Led2, HIGH);
    Busy = 1;
    FLOOR = 2;
  }
}

void loop3() {  //3RD FLOOR
  if (Busy = 0);
  if (Button3 == HIGH);
  {
    digitalWrite(St, HIGH);
  }
  if (Switch3 == LOW);
  { analogWrite(Led3, HIGH);
    analogWrite(L1, LOW);
    analogWrite(L2, HIGH);
    Busy = 1;
    FLOOR = 3;
  }
}


void loop4 () { //El_stop
  if (Busy = 1);
  if ((FLOOR == 1) and (Switch1 == HIGH))
  { (St == LOW);
    analogWrite(St, LOW);
    analogWrite(L1, LOW);
    Busy = 0;
    FLOOR = 0;
  }
  else if ((FLOOR == 2) and (Switch2 == HIGH))
  { (St == LOW);
    analogWrite(St, LOW);
    analogWrite(L1, LOW);
    Busy = 0;
    FLOOR = 0;
  }
  else if  ((FLOOR == 3) and (Switch3 == HIGH))
  { (St == LOW);
    analogWrite(St, LOW);
    analogWrite(L1, LOW);
    Busy = 0;
    FLOOR = 0;
  }
}
]

10
Deutsch / Re: Arduino Nano als Türklinge...
Last post by modellbahner67 - Today at 08:23 pm
vergiss bitte #87. Das habe ich doch schon so gebaut.
Aber: Dein Aufbau ist etwas anders. Bei Dir sind zwichen dem Arduino und dem Player zwei Widerstände und die andere Seite GND am Player ist nicht angeschlossen.
Das probiere ich mal so aus.
Gruß
Günter
Pages: [1] 2 3 ... 10