Jump to content

lesthegrngo

Members
  • Posts

    1245
  • Joined

  • Last visited

7 Followers

About lesthegrngo

  • Birthday December 27

Personal Information

  • Flight Simulators
    DCS A-10C
  • Location
    Doha
  • Interests
    Bitchin' about stuff

Recent Profile Visitors

6960 profile views
  1. The original sketch in the initial post was using code culled from another sketch while researching how to do the pulse signal, so the delayMicroseconds(20); came from that. For the #define vs const int thing, again I suspect that was a legacy of Frankensteining bits of sketches together. I tidied it up and the revised sketch below is functionally working exactly the same #define pulsePin1 2 // pin that sends trigger pulse #define pulsePin2 3 // pin that sends trigger pulse #define BUTTON_PIN1 4 // pin that inputs command signal #define BUTTON_PIN2 5 // pin that inputs command signal bool buttonState1, buttonState2; bool lastButtonState1, lastButtonState2; int pulseWidth = 20; // pulse width in milliseconds - suggested value 20ms int debounce = 20; // debounce delay to prevent multiple triggering void setup() { Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds pinMode(BUTTON_PIN1, INPUT_PULLUP); pinMode(BUTTON_PIN2, INPUT_PULLUP); pinMode(pulsePin1, OUTPUT); // define control pin as output pinMode(pulsePin2, OUTPUT); // define control pin as output } void loop() { buttonState1 = digitalRead(BUTTON_PIN1); buttonState2 = digitalRead(BUTTON_PIN2); if (buttonState1 != lastButtonState1) { if (buttonState1 == LOW) { digitalWrite(pulsePin1, 1); // Set output to 1 delay(pulseWidth); // pulse delay digitalWrite(pulsePin1, 0); // Set output to 0 } delay(debounce); // debounce delay } // save the current state as the last state, // for next time through the loop lastButtonState1 = buttonState1; if (buttonState2 != lastButtonState2) { if (buttonState2 == LOW) { digitalWrite(pulsePin2, 1); // Set output to 1 delay(pulseWidth); // pulse delay digitalWrite(pulsePin2, 0); // Set output to 0 } delay(debounce); // debounce delay } // save the current state as the last state, // for next time through the loop lastButtonState2 = buttonState2; } As for the Arduino forum helping out, it wasn't before they tried to change my whole project, question my reason for existence and my whole philosophy about electronics
  2. Someone on the Arduino forum helped out with this, works perfectly #define control1 2 #define control2 3 #define pulsePin1 2 #define pulsePin2 3 bool buttonState1, buttonState2; bool lastButtonState1, lastButtonState2; int pulseWidth = 20; // pulse width in milliseconds - suggested value 20ms int debounce = 20; // debounce delay to prevent multiple triggering const int BUTTON_PIN1 = 4; // the number of the pushbutton pin const int BUTTON_PIN2 = 5; // the number of the pushbutton pin void setup() { Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds pinMode(BUTTON_PIN1, INPUT_PULLUP); pinMode(BUTTON_PIN2, INPUT_PULLUP); pinMode(control1, OUTPUT); // define control pin as output pinMode(control2, OUTPUT); // define control pin as output } void loop() { buttonState1 = digitalRead(BUTTON_PIN1); buttonState2 = digitalRead(BUTTON_PIN2); if (buttonState1 != lastButtonState1) { if (buttonState1 == LOW) { digitalWrite(pulsePin1, 1); // Set output to 1 delay(pulseWidth); // pulse delay digitalWrite(pulsePin1, 0); // Set output to 0 } delay(debounce); // debounce delay } // save the current state as the last state, // for next time through the loop lastButtonState1 = buttonState1 ; if (buttonState2 != lastButtonState2) { if (buttonState2 == LOW) { digitalWrite(pulsePin2, 1); // Set output to 1 delay(pulseWidth); // pulse delay digitalWrite(pulsePin2, 0); // Set output to 0 } delay(debounce); // debounce delay } // save the current state as the last state, // for next time through the loop lastButtonState2 = buttonState2; }
  3. The 'state change detection' seems to have something like that. I have been looking at the standard IDE example, but it seems to be more about counting button presses
  4. All, I am trying to set up a solenoid so that it moves when a toggle switch is moved from one position to another, but the output from the Arduino needs to be a pulse about 20ms long so that the solenoid doesn't remain powered. I am using the Arduino to drive a MOSFET The sketch below seems to keep repeating the pulse, whereas I want just one pulse, then only when the toggle is moved to the other position should it then send another pulse to the other pole of the solenoid. I looked at the change of state example in Arduino IDE but that seems to more tailored to counting button presses How can I stop the Arduino sending repeated pulses? #define control1 2 // pin that controls the MOSFET #define control2 3 // pin that controls the MOSFET #define pulsePin1 2 // pin that controls the MOSFET #define pulsePin2 3 // pin that controls the MOSFET bool buttonState1, buttonState2, buttonState3, buttonState4, buttonState5; const int BUTTON_PIN1 = 4; // the number of the pushbutton pin const int BUTTON_PIN2 = 5; // the number of the pushbutton pin void setup() { Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds pinMode(BUTTON_PIN1, INPUT_PULLUP); pinMode(BUTTON_PIN2, INPUT_PULLUP); pinMode(control1, OUTPUT); // define control pin as output pinMode(control2, OUTPUT); // define control pin as output } void loop() { buttonState1 = digitalRead(BUTTON_PIN1); buttonState2 = digitalRead(BUTTON_PIN2); if (buttonState1 == LOW) { digitalWrite(pulsePin1, 1); // Set output to 1 delayMicroseconds(20); // set this yourself digitalWrite(pulsePin1, 0); // Set output to 0 } if (buttonState2 == LOW) { digitalWrite(pulsePin2, 1); // Set output to 1 delayMicroseconds(20); // set this yourself digitalWrite(pulsePin2, 0); // Set output to 0 } } Cheers Les
  5. Amazing, I obviously used the wrong search criteria, once I used the Adafruit description, I found a load on all sorts of sites Says it all about my computing skills that I can't even use a search engine properly! Les
  6. Thanks Vinc, that is exactly what I am looking for! Cheers Les
  7. Hi all I use male 0.1" PCB headers on a lot of my projects, but sometimes (like on a Mega) it's to make a shield where I convert the female connection into a male connection. Up until now I just used two lots of male PCB headers, one each side of the PCB, then traces on each side and a through PCB pin soldered on both sides. It works fine, but it makes production of one of the boards a lot more laborious that in should be What I want is a male PCB header that is twice the length so that I can solder it on one side, and it protrudes both above and below the PCB, and that way I can just plug it in to the Mega, and then have the connecting pins on the upper face. I searched on the likes of e-bay (remembering it is a pain to get things here) but couldn't find anything like it. Do they exist or is it wishful thinking? Les
  8. Hi Vinc I couldn't get your sketch to work exactly how I wanted, but studied it and wondered if the homing should be in the setup in order to not interfere with the switches I ended up with this, which works exactly as I need it to - thanks for all your help as always! #include "AccelStepper.h" #define HALFSTEP 8 #define motorPin1 8 #define motorPin2 9 #define motorPin3 10 #define motorPin4 11 int endPoint = 1024; // Move this many steps; 1024 = approx 1/4 turn // NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ-48 AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); bool buttonState1, buttonState2; const int BUTTON_PIN1 = 5; // the number of the pushbutton pin const int BUTTON_PIN2 = 6; // the number of the pushbutton pin // Define the Pins used #define home_switch 7 // Pin 9 connected to Home Switch (MicroSwitch) // Stepper Travel Variables int move_finished = 1; // Used to check if move is completed long initial_homing = -1; // Used to Home Stepper at startup void setup() { Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds pinMode(BUTTON_PIN1, INPUT_PULLUP); pinMode(BUTTON_PIN2, INPUT_PULLUP); pinMode(home_switch, INPUT_PULLUP); // Set Max Speed and Acceleration of each Steppers at startup for homing stepper.setMaxSpeed(100.0); // Set Max Speed of Stepper (Slower to get better accuracy) stepper.setAcceleration(100.0); // Set Acceleration of Stepper // Start Homing procedure of Stepper Motor at startup while (digitalRead(home_switch)) { // Make the Stepper move CCW until the switch is activated stepper.moveTo(initial_homing); // Set the position to move to initial_homing--; stepper.run(); // Start moving the stepper delay(5); } stepper.setCurrentPosition(0); // Set the current position as zero for now stepper.setMaxSpeed(100.0); // Set Max Speed of Stepper stepper.setAcceleration(100.0); // Set Acceleration of Stepper initial_homing = 1; stepper.setCurrentPosition(0); Serial.println("Homing Completed"); Serial.println(""); stepper.setMaxSpeed(1000.0); // Set Max Speed of Stepper (Faster for regular movements) stepper.setAcceleration(1000.0); // Set Acceleration of Stepper } void loop() { buttonState1 = digitalRead(BUTTON_PIN1); buttonState2 = digitalRead(BUTTON_PIN2); stepper.setMaxSpeed(1000.0); stepper.setAcceleration(500.0); if (buttonState1 == LOW) // if control switch is in position A move stepper to position defined on the next line stepper.moveTo(200); // change number in brackets to suit the required throw stepper.run(); if (buttonState2 == LOW) // if control switch is in position B move stepper to zero position stepper.moveTo(0); // this is the same position as the microswitch used for homing }
  9. Thanks - wish I'd known that about 2 hours ago! Cheers Les
  10. Thanks Vinc, I'll give that a go However, a word to the wise - never inadvertently plug a 9v AC adapter into a ULN2003 stepper motor driver instead of a 9v DC........ Les
  11. It's actually really simple, at least for the small variety - I resin printed them, and before they are fully cured I push them onto the lever. When you let them cure in UV light, they shrink a little and then hold on due to the geometry of the lever. For the larger toggle switches, it's a bit more complicated. I took the switches apart, and put the levers on my little lathe and turned the lever so it was 5mm diameter straight shaft instead of slightly conical. You then put the switch back together, then do the same as for the little switches, just push the uncured resin caps on and do the curing process If want pictures of how to do it I can try and do some Les
  12. it will be moving a lever, and a microswitch was what I was thinking as the limiting sensing device I'm using these steppers 'cos I have a load of them! Let me have a look at how he did it Cheers Les
  13. I am using one of the 28-BYJ-48 steppers with the ULN2003 driver board and the TinyStepper_28BYJ_48.h Library as it is geared it has a higher torque, but it has no positional feedback. The position of the stepper is commanded by a toggle switch to go to either position A or B, with the position set by the sketch values. However the problem is that when you depower, whatever the position it is in when depowered becomes the default O position I want to use a microswitch for a simple home movement, does anyone have a snippet of code that would do that? Here's the code I have, pretty simple #include <TinyStepper_28BYJ_48.h> bool buttonState1, buttonState2; const int BUTTON_PIN1 = 5; // the number of the pushbutton pin const int BUTTON_PIN2 = 6; // the number of the pushbutton pin const int BUTTON_PIN3 = 7; // the number of the pin for the homing switch // and connect pins 8,9,10,11 to IN1,IN2,IN3,IN4 on ULN2003 board const int MOTOR_IN1_PIN = 8; const int MOTOR_IN2_PIN = 9; const int MOTOR_IN3_PIN = 10; const int MOTOR_IN4_PIN = 11; const int STEPS_PER_REVOLUTION = 2048; int pos = 0; // variable to store the servo position unsigned int closePos = 0; //Angle at closed position // create the stepper motor object TinyStepper_28BYJ_48 stepper; void setup() { pinMode(BUTTON_PIN1, INPUT_PULLUP); pinMode(BUTTON_PIN2, INPUT_PULLUP); pinMode(BUTTON_PIN3, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); Serial.begin(9600); // connect and configure the stepper motor to its IO pins stepper.connectToPins(MOTOR_IN1_PIN, MOTOR_IN2_PIN, MOTOR_IN3_PIN, MOTOR_IN4_PIN); } void loop() { buttonState1 = digitalRead(BUTTON_PIN1); buttonState2 = digitalRead(BUTTON_PIN2); // set the speed and acceleration rates for the stepper motor stepper.setSpeedInStepsPerSecond(150); stepper.setAccelerationInStepsPerSecondPerSecond(500); // set the position of the stepper for when switch 1 is connected, probably best left at zero as will be the starting position //if (buttonState1 == LOW) { if (buttonState1 == LOW && pos <= -0) { for (pos = 0; pos <= 20; pos += 1) { stepper.moveToPositionInSteps(0); } } // set the position of the stepper for when switch 2 is connected, set as positive number between 10 and 200 depending on throw required //if (buttonState2 == LOW) { if (buttonState2 == LOW && pos >= 20) { for (pos = 20; pos >= 0; pos -= 1) { stepper.moveToPositionInSteps(200); //delay(1000); } } } Cheers Les
  14. I have noted that stuff like the RWR, LCD clock plus a couple of other things like the UHF radio and repeater are not working. Let me delve into the code and see Les
  15. Have you tried to repeat the steps above? I'm not in front of the PC to check myself, but give it a go Les
×
×
  • Create New...