I want to control the LEDs with my hand, for this I used the repository https://github.com/paveldat/finger_counter/tree/main. I want to control the LEDs with my hand, for this I used the repository. To connect to the arduino mega serial port, I use the pyserial library, here is the code to which I pass variables.
arduinoData = serial.Serial("com9", 9600)
arduinoData.write(bytes(str(variable), "utf-8"))
to control the LEDs and process data from the serial port, I wrote the following code in the Arduino IDE:
void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
/*
if (Serial.available() > 0){
serialData = Serial.read();
for (int i = 3; i<serialData; i++){
digitalWrite(i, HIGH);
}
}
*/
if (Serial.available() > 0){
char serialData = Serial.read();
if (serialData == '3'){
digitalWrite(3, HIGH);
}
else if (serialData == '4'){
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
else if (serialData == '5'){
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else if (serialData == '6'){
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
else if (serialData == '7'){
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
else if (serialData == '0'){
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
}
//Serial.println(serialData);
//digitalWrite(serialData, HIGH);
//delay(1000);
}
}
when I run this code without connecting the camera and just pass the values to the serial port, then everything works. However, when I try to run this code together with the camera, the following error occurs:
serial.serialutil.SerialException: could not open port 'com9': PermissionError(13, 'Access denied.', None, 5)
The camera is a laptop webcam, I have not tested the code with the USB camera, the assumption is that the USB camera will not occupy all serial ports.
del arduinoData