EmbDev.net

Forum: µC & Digital Electronics Serial port disconnects, when programmable power socket is activated


von Julius (juliusre)


Rate this post
useful
not useful
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 :slight_smile:


this is the short python code, that starts the programmable power socket 
by running a manufacturer .exe :
1
import subprocess, keyboard
2
3
from pynput.keyboard import Listener
4
5
6
def on_press(key):
7
    if keyboard.is_pressed('z'):
8
        subprocess.call(['C:\\Users\\Julius\\USBswitchCmd.exe', '1'])
9
10
11
def on_release(key):
12
    subprocess.call(['C:\\Users\\Julius\\USBswitchCmd.exe', '0'])
13
14
15
with Listener(on_press=on_press, on_release=on_release) as listener:  # Create an instance of Listener
16
    listener.join()

and this is the arduino code, that starts a specific servo when a 
specific key is pressed on the keyboard:
1
#include <Wire.h>
2
#include <Adafruit_PWMServoDriver.h>
3
int val; // initial value of input
4
5
Adafruit_PWMServoDriver myServo = Adafruit_PWMServoDriver();
6
7
#define SERVOMIN 150
8
#define SERVOMAX 600
9
10
uint8_t servonum = 0;
11
uint8_t numberOfServos = 7;
12
13
void setup() {
14
  Serial.begin(9600);
15
  myServo.begin();
16
  myServo.setPWMFreq(60);
17
  delay(10);
18
19
  myServo.setPWM(0, 0, 150); // set starting point
20
  myServo.setPWM(1, 0, 150);
21
  myServo.setPWM(2, 0, 150);
22
  myServo.setPWM(3, 0, 150);
23
  myServo.setPWM(4, 0, 150);
24
  myServo.setPWM(5, 0, 150);
25
  myServo.setPWM(6, 0, 150);
26
27
}
28
29
void loop() {
30
31
if (Serial.available()) // if serial value is available 
32
33
  {
34
    val = Serial.read();// then read the serial value
35
36
    if (val == '1') //if value input is equals to 1
37
38
    {
39
      myServo.setPWM(0, 0, 400);
40
      delay(15);//delay for the servo to get to the position
41
     }
42
43
    if (val == '2') //if value input is equals to 2
44
    {
45
      myServo.setPWM(1, 0, 400);
46
      delay(15);//delay for the servo to get to the position
47
    }
48
    if (val == '3') //if value input is equals to 2
49
    {
50
      myServo.setPWM(2, 0, 400);
51
      delay(15);//delay for the servo to get to the position
52
    }
53
    if (val == '4') //if value input is equals to 2
54
    {
55
      myServo.setPWM(3, 0, 400);
56
      delay(15);//delay for the servo to get to the position
57
    }
58
    if (val == '5') //if value input is equals to 2
59
    {
60
      myServo.setPWM(4, 0, 400);
61
      delay(15);//delay for the servo to get to the position
62
    }
63
    if (val == '6') //if value input is equals to 2
64
    {
65
      myServo.setPWM(5, 0, 400);
66
      delay(15);//delay for the servo to get to the position
67
    }
68
    if (val == '7') //if value input is equals to 2
69
    {
70
      myServo.setPWM(6, 0, 400);
71
      delay(15);//delay for the servo to get to the position
72
    }
73
74
    if (val == 'a') // zum wieder schließen!
75
76
    {
77
      myServo.setPWM(0, 0, 150);
78
      delay(15);//delay for the servo to get to the position
79
     }
80
81
    if (val == 's') //if value input is equals to 2
82
    {
83
      myServo.setPWM(1, 0, 150);
84
      delay(15);//delay for the servo to get to the position
85
    }
86
    if (val == 'd') //if value input is equals to 2
87
    {
88
      myServo.setPWM(2, 0, 150);
89
      delay(15);//delay for the servo to get to the position
90
    }
91
    if (val == 'f') //if value input is equals to 2
92
    {
93
      myServo.setPWM(3, 0, 150);
94
      delay(15);//delay for the servo to get to the position
95
    }
96
    if (val == 'g') //if value input is equals to 2
97
    {
98
      myServo.setPWM(4, 0, 150);
99
      delay(15);//delay for the servo to get to the position
100
    }
101
    if (val == 'h') //if value input is equals to 2
102
    {
103
      myServo.setPWM(5, 0, 150);
104
      delay(15);//delay for the servo to get to the position
105
    }
106
    if (val == 'j') //if value input is equals to 2
107
    {
108
      myServo.setPWM(6, 0, 150);
109
      delay(15);//delay for the servo to get to the position
110
    }
111
112
  }
113
114
}


I´m sorry, if this isnt the right category for my question - I´m 
completely new to this forum!

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.