![]() Very neat tutorial, well documented and very detailed Can be used as a prototype example for many other tutorials. Below is a simple sketch for using the I2C Relay Boards. You can connect TX2 and RX2 back once you have successfully uploaded the code. Connect the board to your Arduino as shown. Then, select your Arduino board and the correct COM port in your Arduino IDE, and click the upload button to upload the code. To upload the program code to your Arduino board, you need to unplug the TX2 and RX2 pins from the DWIN Display. The system then resets the “Buffer_Len” variable to 0 and sets the “flag” variable to false. If these conditions are met, the system reads the ninth byte in the “Buffer” array as a binary value and uses it to control the relays. When there is no more data to read and the “flag” variable is true, it checks if the first byte in the “Buffer” array is 0X5A and the fifth byte is 0X50. If the DEBAG flag is set to 1, the system also prints the data in hexadecimal to the serial monitor. It reads data from the serial port and stores it in the “Buffer” array. This is the “ReadSerial” function, which is called in the loop function. In the loop function, the code reads serial data and processes it using the ReadSerial function.ĭigitalWrite(relays, level = 0 ? !bitRead(Buffer, i) : bitRead(Buffer, i)) īuffer_Len = 0 //Resetting the element number in an array It then sets the pin modes for the relay connections to OUTPUT, and if the “level” variable is set to 0, it sets the initial state of the relays to HIGH. If the DEBAG flag is set to 1, the function initializes serial communication at a baud rate of 115200 and prints a message to the serial monitor. This is the setup function, which is called once when the program starts. ![]() This line defines the “flag” variable as a boolean that is used as a flag for reading data from the monitor. bool flag = false // Data read flag from monitor It defines the “Buffer_Len” variable as a byte that stores the length of the “Buffer” array. This line defines the “Buffer” array as an array of bytes that is used to store data read from the display. This code defines the “relays” array as an array of bytes that stores the pin numbers for the relay connections. #define DEBAG 1 // Debugging: 1 - on, 0 - offĬonst bool level = 0 // 1 - high level relay, 0 - low level relayĬonst byte relays_num = 8 // Number of relaysīyte relays = // Relay connection pins * Relay ontrol system using Arduino & DWIN Display */ The code is written in C++ and is intended to run on any 5V-compatible Arduino microcontroller. ![]() This code is for controlling 8-16 relays using a DWIN touchscreen display and an Arduino. This will ensure that both devices are using the same reference voltage. Note: If you are using separate power sources for the Arduino and the LCD, make sure to connect the GND (ground) pin of the display to the GND pin of the Arduino. Circuit Diagram: Relay Control with Arduino & DWIN Display
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |