Hello everybody,
as I am wanting to interact with an arduino uno REV3 using a stream deck and there does not seem to be a plugin to do serial communication for the stream deck I found a possible workaround by using a batch file converted to an exe which I can start from the streamdeck. That converted batch file is then meant to send an integer to the comport to which the Arduino is connected.
The "Serial Input Basics - updated" thread Serial Input Basics - updated gave me some insights like sending single character messages via serial is advised due to the rather slow speed of this connection.
Anyhow I have tried to send either
echo 1 > COM5
echo 1 >\.\COM5
set /p x="1" \.\COM5
Via a batch file, but also via the command prompt directly as user and as Admin. At least I found out that you have to close the serial monitor to at least get access to the COM port but thats it .
None of the sent commands seem to be received by the arduino uno REV3 using the following sketch in the Arduino IDE 2.0.3:
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int light_group_1_active = 0;
int light_group_2_active = 0;
void setup() {
Serial.begin(9600);
pinMode(10, INPUT); // for button at pin 10
pinMode(11, INPUT); // for button at pin 11
mySwitch.enableTransmit(3); // transmitter at digital pin 3 of arduino uno
mySwitch.enableReceive(0); // receiver at digital pin 2 of arduino uno
mySwitch.setProtocol(2);
Serial.println("");
Serial.println("ready");
}
void loop() {
/////// SEND 433MHZ
if (digitalRead(10) == HIGH) {
button_1_toggle();
}
if (digitalRead(11) == HIGH) {
button_2_toggle();
}
//////// RECEIVE 433MHZ
if (mySwitch.available()) {
Serial.print("Received ");
Serial.print(mySwitch.getReceivedValue());
Serial.print(" / ");
Serial.print(mySwitch.getReceivedBitlength());
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println(mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
//////// RECEIVE string from COM port
while (Serial.available() > 0) {
int received_data = Serial.read();
if (received_data == "1") {
button_1_toggle();
} else if (received_data == "2") {
button_2_toggle();
} else {
Serial.println(Serial.read());
}
}
}
void button_1_toggle() {
if (light_group_1_active == 0) {
Serial.println("activate light group 1");
mySwitch.send(907438080, 32);
light_group_1_active = 1;
} else {
Serial.println("de-activate light group 1");
mySwitch.send(1041655808, 32);
light_group_1_active = 0;
}
delay(500);
}
void button_2_toggle() {
if (light_group_2_active == 0) {
Serial.println("activate light group 2");
mySwitch.send(236349440, 32);
light_group_2_active = 1;
} else {
Serial.println("de-activate light group 2");
mySwitch.send(18245632, 32);
light_group_2_active = 0;
}
delay(500);
}
Hope I have included all the needed info, and wonder what I am missing or if there is another easy way to call the functions button_1_toggle and button_2_toggle from the stream deck ...
Oh by the way: Using the physical buttons connected directly to the arduino to call the functions and trigger the lights works perfectly fine
Cheers
Ralf