Hi there
I´m working on an experiment atm that requires an arduino to listen to key presses ("1" to "7") from my laptop (via CoolTerm Serial Terminal). Furthermore, i also use a programmable power socket, in order to start/power another device when a specific (different) key ("z") is pressed on the keyboard.
Both parts work perfectly fine on their own. But when both are being used, the key press that starts the power socket, also leads to CoolTerm disconnecting the serial port, before reconnecting after 2-3 sec.
With this delay my experiment unfortunately doesnt work.
Does anyone have an idea where my problem/mistake could be located?
I´m very thankful for any help i can get
this is the short python code, that starts the programmable power socket by running a manufacturer .exe :
import subprocess, keyboard
from pynput.keyboard import Listener
def on_press(key):
if keyboard.is_pressed('z'):
subprocess.call(['C:\\Users\\Julius\\USBswitchCmd.exe', '1'])
def on_release(key):
subprocess.call(['C:\\Users\\Julius\\USBswitchCmd.exe', '0'])
with Listener(on_press=on_press, on_release=on_release) as listener: # Create an instance of Listener
listener.join()
and this is the arduino code, that starts a specific servo when a specific key is pressed on the keyboard:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
int val; // initial value of input
Adafruit_PWMServoDriver myServo = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
uint8_t servonum = 0;
uint8_t numberOfServos = 7;
void setup() {
Serial.begin(9600);
myServo.begin();
myServo.setPWMFreq(60);
delay(10);
myServo.setPWM(0, 0, 150); // set starting point
myServo.setPWM(1, 0, 150);
myServo.setPWM(2, 0, 150);
myServo.setPWM(3, 0, 150);
myServo.setPWM(4, 0, 150);
myServo.setPWM(5, 0, 150);
myServo.setPWM(6, 0, 150);
}
void loop() {
if (Serial.available()) // if serial value is available
{
val = Serial.read();// then read the serial value
if (val == '1') //if value input is equals to 1
{
myServo.setPWM(0, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '2') //if value input is equals to 2
{
myServo.setPWM(1, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '3') //if value input is equals to 2
{
myServo.setPWM(2, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '4') //if value input is equals to 2
{
myServo.setPWM(3, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '5') //if value input is equals to 2
{
myServo.setPWM(4, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '6') //if value input is equals to 2
{
myServo.setPWM(5, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == '7') //if value input is equals to 2
{
myServo.setPWM(6, 0, 400);
delay(15);//delay for the servo to get to the position
}
if (val == 'a') // zum wieder schließen!
{
myServo.setPWM(0, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 's') //if value input is equals to 2
{
myServo.setPWM(1, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 'd') //if value input is equals to 2
{
myServo.setPWM(2, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 'f') //if value input is equals to 2
{
myServo.setPWM(3, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 'g') //if value input is equals to 2
{
myServo.setPWM(4, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 'h') //if value input is equals to 2
{
myServo.setPWM(5, 0, 150);
delay(15);//delay for the servo to get to the position
}
if (val == 'j') //if value input is equals to 2
{
myServo.setPWM(6, 0, 150);
delay(15);//delay for the servo to get to the position
}
}
}
I´m sorry, if this isnt the right category for my question - I´m completely new to this forum!