

lesthegrngo
Members-
Posts
1245 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Everything posted by lesthegrngo
-
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
-
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; }
-
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
-
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
-
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
-
Thanks Vinc, that is exactly what I am looking for! Cheers Les
-
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
-
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 }
-
Thanks - wish I'd known that about 2 hours ago! Cheers Les
-
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
-
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
-
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
-
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
-
HUD view seems to disable some DCS Bios devices ***Solved***
lesthegrngo replied to lesthegrngo's topic in Home Cockpits
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 -
HUD view seems to disable some DCS Bios devices ***Solved***
lesthegrngo replied to lesthegrngo's topic in Home Cockpits
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 -
Yeah did that, but it was windows itself that refused to see the USB devices, not DCS - thanks for the input though Les
-
I have a load of little servos and was looking into it, looks like I could make some sprung mechanical link from the servo arm to control it using the following sketch although of course this will continue to cycle because the instructions are in the loop part - ***EDIT*** I made a second sketch to change that putting the movement in the setup so it only runs once, and it works perfectly // Include the Servo library #include <Servo.h> // Declare the Servo pin int servoPin = 3; // Create a servo object Servo Servo1; void setup() { // We need to attach the servo to the used pin number Servo1.attach(servoPin); } void loop(){ // Make servo go to 0 degrees Servo1.write(0); delay(1000); // Make servo go to 90 degrees Servo1.write(90); delay(1000); // Make servo go to 0 degrees Servo1.write(0); delay(1000); } // Include the Servo library #include <Servo.h> // Declare the Servo pin int servoPin = 5; // Create a servo object Servo Servo1; void setup() { // We need to attach the servo to the used pin number Servo1.attach(servoPin); // Make servo go to 0 degrees Servo1.write(0); delay(1000); // Make servo go to 90 degrees Servo1.write(90); delay(1000); // Make servo go to 180 degrees Servo1.write(0); delay(1000); } void loop(){ }
-
Thanks guys - I do have two USB hubs that as you point out take 5v supply, but they just don't work, whereas the Aukey 12v unit does work. I'm assuming it's power related As for rigging up something to press the button, yes, I have idly been mulling that. Even if it is a button I have to press to activate, that would work as that could be sited on the outside of the assembly. The USB hub itself is positioned inside behind a panel where I can't get to the button which is why the need arises. If it wasn't for that I'd have moved on by now. I was thinking maybe a little servo with a short program that cycles it once on startup, which as you say if you link the controller to the power supply it will automatically actuate. An arduino could do that but feels like a sledgehammer to crack a nut Les
-
If any of you have been following this issue, it turns out making a USB cable setup using non-standard USB connectors is more tricky that it first looks. In the end I got there by using good quality USB cable cannibalised from existing USB cables, and ensuring that there was complete grounding on the connectors etc., however it still was an imperfect solution as it needs a good quality powered USB hub to work properly. I do have one of those, but it has one major drawback; it is a switched USB hub. This particular USB hub (Aukey 7 Port USB 3.0 hub model CB-H3) is switched off by default so if it has been depowered, it remains off until you press the switch, which is a momentary press button rather than a bi-stable rocker. This means that I have to have the hub accessible so that I can press the switch every time I repower the rig, which defeats the object of having a monolithic module that is fitted inside the back rest of the seat. My design has it tucked neatly out of sight with no wires everywhere, and all the switches and cables are positioned to ensure they are not in the way What I need to find is a a 12v four (min) port powered USB hub that is either unswitched or with a latching type switch which will stay 'on' even when depowered. There are none here where I live, so I have searched on Amazon to see if I can identify a candidate. Trouble is I am unable to zero in on one that is 12v powered. For instance, this https://www.amazon.co.uk/Portable-Extension-Multiport-Splitter-Extender-Black/dp/B0CD5JPV5G/ref=sr_1_20?crid=3E5E01E29CPNE&dib=eyJ2IjoiMSJ9.Ie1Bw1g3RPScfK3ZvdJlPiVrt69--px9kd3CtdMTnLSR6k3NuHWVhGwt5Xvk-nIce0zn8RlJx3YC0UlseZzmNuUXgkkaTuv_xQszt7dyQD6F-P-rXTs2ZuQ1H-hkL4HoJxWT_RtJ2T7zkHudzak6b5BGo24ZvkK2_Z2dbb9XBIQUX_vSoDyiETdbwPWfxx1CLHoUO7q_wi6e4VANiNBHvpSpnAZgRwzI5UVwcydTlxs.lWW3-rNhDvu_ARfDmY3Xev9QRYG9-_BMF_O4GYJu7Tw&dib_tag=se&keywords=Powered%2B4%2Bport%2BUSB%2Bhub&qid=1726634743&sprefix=powered%2B4%2Bport%2Busb%2Bhub%2Caps%2C192&sr=8-20&th=1 clearly has rocker switches, but I have no information on what the input voltage to the hub. There is a clearly visible DC input but no specs So has anyone got a specific 12v powered USB hub with 4 or more ports that they can point me to that would fulfil this? With luck I can get an American friend to bring me one when he returns from the states later this month Les
-
I took this issue to a more electronics related forum, take a look here https://forums.tomshardware.com/threads/usb-issue-using-homemade-cables.3854148/ There's some interesting discussion about how USB works and requirements, might be interesting for anyone messing around with USB devices Cheers Les
-
It's plugged in to the motherboard I did a back to back test, where the only thing I changed was either my own multi piece USB cable, or the one piece commercially purchased one. With my cables the fault re-appears after a while, with the commercially produced cable with nothing else changing the fault never appears It must be something to do with my cables, so I have to do some investigating Les
-
Thanks, I will take a look - however since I wrote the original post I have left the setup connected with the USB cable to the same USB port and hours later it is still all connected. Interestingly, once the PC starts giving the 'USB device not recognised' message (with my home made hardware), it will not resurrect by unplugging and replugging, even on another port I think I've messed something up! if it didn't work at all I would be less confused, but working for a while then giving up is weird Les
-
Hi all, recently I added some bass shakers to my rig, which do add to the experience. I have 8 small transducers ranged around the seat driven by four USB 'sound card / amplifier' things (check out Nobsound amps on Amazon for the type of unit). I could get away with less transducers, however due to the way that they work I use Sim Haptics to drive some and Sim Shaker for the others, as at the moment there is a curious effect where some effects (eg the gun) blank out the other effects. By separating the effects between the programs I stop that from happening as much. In time I may simplify the setup if the program designers resolve that issue. In the meantime, I am stuck with four amps, and I made a module to fit into the seat backrest area that includes a dedicated 24v power supply for the amps, a powered USB hub that takes a single USB input and splits it to the four amps, and of course the four amps themselves. Mains power is supplied to the 24v power supply via a dedicated switched line using G16 aviation style connectors. As for the USB, again a dedicated USB line goes from the PC motherboard USB 3.0 port, but due to the fact that I didn't want a plate of spaghetti it uses 6 separate parts to keep it all neat. First is a male to male USB A 3.0 cable from the PC, to a captive female to female USB 3.0 connector mounted on the front of the console. A USB cable with a USB A connector at the front then runs inside the console to the rear, where the wires have been soldered into a four way male G12 aviation connector mounted on a dedicated output plate (shared with the G16 connector for the mains power). A short fly lead with G12 female connectors at either end then connects to the seat where an input plate again with a G12 and G16 connector for the USB and mains input are mounted. These then have internal fly leads to the power supply coupling and one last G12 connection for the USB, which is then soldered to the input lead for the hub. It sounds more complicated that it is, and when you actually se it it makes a lot more sense that my word salad above. It is also very neat, with minimal exposed wires So the issue I have is that I connect it all up , and Windows duly recognises the four amps and it all starts working fine. Then about an hour later, the USB amps are no longer recognised, and disconnecting and reconnecting the USB connection does nothing, apart from sometimes, but not always, coming up with a 'the last USB device connected was not recognised). To test, I have rigged up a single USB cable that goes directly from the Motherboard to the USB hub input, and this does not fail over time, meaning something about my setup is causing the issues. I have checked continuity, resistance, short circuits on all the cables I have made and cannot find anything wrong, meaning that something else must be at play. The fact that it works fine for a while in itself shows that the cables appear to be fundamentally ok in theory. Can it be that too many connections can cause interference, or maybe pick up some interference from outside? I can obviously revert to using the single USB cable if I have to, which would grate on my OCD but I could probably hide it somehow - but I would like to know how to resolve the issue to ensure that I can implement other setups without problems So, anyone got any ideas what I am doing wrong? Les
-
Cannot save controller settings
lesthegrngo replied to lesthegrngo's topic in Controller & Assignment Bugs
I got a response from someone on the Discord channel "You realize that if you OK at the bottom of the controller screen that will save ALL your new settings right? You don't need to use the profiles unless you're trying to do something specific with it and realize they are saved by individual controller column rather than the whole thing." So 'Save' does not, you have to use 'OK' instead....... Les -
Thanks- and yes, they are not cheap, so incredibly cannibalising the old Chinese car gauges may actually be cheaper! I'll give it a go and see it it is worth it on one of them Les