Hot answers tagged

4

You should learn how to use bitwise operators. These are needed to do what you want. We can save the state of each switch in one bit each. For this we first define our global variable that will hold the switch states: byte switch_states = 0; Then in getLimitSwitch() we loop through our pins. The result of digitalRead() is always one of 0 and 1. So we can ...


4

First of all, I will challenge your assumption that you have to send the three bytes in the same call to Serial.write(). There is no real advantage in doing so. Serial output is handled through a memory buffer that is consumed by the serial port within an interrupt service routine. Serial.write() only writes to that memory buffer. Thus, you can simply: ...


3

There is something wrong with some new kernels of Ubuntu 20.04 LTS, interfering with ESP8266 core uploading process 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux I had the same issue and downgraded the kernel to 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux solved the ...


2

You can use a byte array for this: // at the appropriate place in your code: byte message[] = { '@', 'M', 0x01 }; Serial.write(message, sizeof message); If you need, you can prepare the array and just assign the value: byte message[] = { '@', 'M', 0 }; // ... byte value = 0x01; // or any other assignment // at the appropriate place in ...


1

You have to connect ground between the modules. Without common ground the logic level of signal can't be measured. While both boards were powered over USB from the same laptop the boards had common ground. read returns -1 if nothing is available so check if some character was received: void loop() { if (Serial1.available()) { Keyboard.write(Serial1....


1

Edit as follows: Serial.begin(115200); Serial.setTimeout(10); //Maximum time in ms that it should wait for data The default delay is 1000ms. The code above sets it to 10ms. Play around with the Timeout value and check for faults. https://www.arduino.cc/reference/en/language/functions/communication/serial/settimeout/


1

Here is what I've ended up with: I dropped Serial1 as I did not find anyway to make it run and I switched to Serial2, where everything works as expected.


Only top voted, non community-wiki answers of a minimum length are eligible