How to Use Arduino Control Board LY-F2 and STONE Serial Display to Implement Piano Key Project
by greyli1987 in Circuits > Arduino
535 Views, 0 Favorites, 0 Comments
How to Use Arduino Control Board LY-F2 and STONE Serial Display to Implement Piano Key Project
This project uses a serial touch screen STVI056WT-01 with Arduino control board LY-F2 design, the main accessories are as follows.
1, STVI056WT-01 serial touch screen and STONE adapter board V1.2.
2, gift box speaker.
3, LY-F2 development board.
Design Idea
The serial screen carries piano keys, returns different key values, serial port notifies Arduino decoding, Arduino development board uses instruction tone (), outputs the corresponding key tone.
Working Steps
1. import the piano key images into the STONE screen development platform Toolbox.
a. add return value touch keys to the piano keys.
b. Plan the data address and return value of the keys.
c. Set the power-on screen to piano keys, check the return value to upload the serial port immediately.
2. debugging speaker sounding using Arduino programming.
a) connect the speaker and microcontroller output IO.
b) programming different frequencies, debugging sound compared with the actual piano.
c) create a table of key output frequencies.
3. Connect the touch screen and Arduino development board through the serial port, decoding, and coupling to achieve real-time analog-sounding function.
Next, Record the Specific Development Process.
First, create the piano keys image.
The 640*480 piano keys picture made according to the resolution of the STONE
screen used in this project is as follows.
Next, Import the Image Into Tool4.3 and Create a Return Value Button.
Check "Return
pressed key value" under the menu Touch Cinfiguration (M) in STONETool BOX (GUI Design software), or click on the button tool in the picture above to create a button in the desired location, and fill in the variable address and key value in the marker as above. Check the box to automatically upload the return value when pressed. The 10 piano key variable addresses here are 0x0800, 0X0802, 0X0804 ..... .0X0812, and the key return values are 0x0060, 0x0061, 0x0062...... , 0x0069; as follows.
As monitored by the serial assistant, the values returned by the serial
assistant for each key are as follows
a5 5a 06 83 08 00 01 00 60
A5 5A 06 83 08 02 01 00 61
A5 5A 06 83 08 04 01 00 62
A5 5A 06 83 08 06 01 00 63
......
a5 5a 06 83 08 12 01 00 69
Arduino Development Platform
Here, we introduce the arduino development platform before we do the
programming of the sound control function.
The following figure is the arduino development board used in this project, the model is LY-F2.
Arduino Platform
Arduino platform is very good, no need to layout and play the board, also do not need to find parts welding, simple development environment, also comes with a variety of routines.
To the "arduino language instructions" focus on the application of part of the serial port transceiver function, instructions are extracted as follows.
Serial Port Send/receive Function
Serial.begin(speed) Serial port definition baud rate
function, speed means baud rate, such as 9600, 19200, etc.
int Serial.available() Determine the buffer status.
int Serial.read() Read the serial port and return the received parameters.
Serial.flush() flushes the buffer.
Serial.print(data) Output data from the serial port.
Serial.println(data) Serial port outputs data with a carriage return character.
(arduino Serial Port Maximum Baud Rate Setting)
There is a more detailed description of the instructions in the 232
page "Getting.Started.with.Arduino" pdf full English electronic document, screenshot saved below.
As you can see, arduino can support up to 115200 baud rate of serial
screen, this time the selected one is 9600.
Testing With the Serial Assistant
After testing with the serial assistant, the two print functions above transmit in character form.
For Example:
Serial.print(75,HEX);
The string transmitted is "4B", which is the ASCII value of the characters "4" and "B" (0x34, 0x42); therefore, serial. print() function, whether string, or data, are sent ASCII, not suitable for command transmission!
In arduino 1.0.5, under the menu help, click on "Reference", then you will see the function descriptions of each function, among which the latest serial function is serial.write(Val), the screenshot is as follows.
Function Transmits
The function transmits the binary code, and the test transmission is correct and can jump pages correctly; as follows.
Serial.write(Val) Function
The serial.write(Val) function supports writing hexadecimal directly,
such as serial.write(0x80), which compiles and uploads successfully, as shown below. Therefore, the serialwrite() function sends the value VAL in binary and string in ASCII.
Arduino Development Environment
For the arduino development environment, just run the arduino.exe
directly under the arduino-1.0.5 package directory.
After Double-clicking, Wait for a While, the Following Startup Screen Will Appear.
The extension .ino is the arduino file and must be placed in the folder
with the same name; to download the program written in arduino to the development board is to use "upload" under the menu "file". In other places (such as Tool4.3), it may be "download".
Arduino will first compile the .ino file during the upload operation, and the status bar below will show "uploading" after compiling and "Done uploading" after finishing. ". If there is an error in the compilation process, it will be displayed (e.g., variable not defined, etc.) and the upload operation will be terminated. When finished, if there is a red warning under the status bar, it means that there is an error and you need to check and re-upload.
How About Making a Sound?
In the main menu of arduino 1.0.5 software, help--->Reference, a
browser will pop up, which has the function of tone().
The speaker of this project is connected to 8 pins, and the frequency table is in notes[]. Each keystroke sounds last 0.36 seconds. It can be used like this: tone(8, notes[], 360). The notes[] array holds the frequency of the 10 keys. With the key value returned by the serial port, you can use this tone() function to drive the speaker to emit the corresponding tone!
The frequencies determined by debugging this project are as follows.
int notes[] = {262, 294, 330, 349, 389, 430, 449, 469, 489, 509};
These 10 frequencies emit a detailed breakdown of the variation of each tone, which sounds great with the chosen speakers!
Next, Connect the Serial Screen to the MCU.
Check the "Datasheet STVI056WT-01" pdf, find the serial
screen circuit diagram on page 31, and find that the DIN and DOUT signals of the screen interface are RS232. STONE included an adapter board with the screen, but I didn't see any circuit diagram of the adapter board, so I drew one myself. From the drawing, we found that there is MAX232E1 chip on the adapter board, and the TX and RX signals are led out through the jumper, it plays a conversion role, the serial TTL of the arduino development board can match the RS232 signal of the STVI056WT-01 serial screen! From the drawing also know that the STONE adapter board DC12V power supply is supplied to the serial screen, the internal MAX232E1, CH340C power supply +5V are provided by the USB, so when using RS232 to serial TTL level conversion, the USB needs to be powered. For the adapter board MAX232 chip, Tin, Rout are 0-5V, while Tout, Rin pin is + - 15V logic. Detailed connection see the hand drawing, STONE adapter board USB and 12V power supply, LY-F2 development board USB power supply should be connected, LY-F2 development board TX ----- adapter board TX, LY-F2 development board RX ------ adapter board Rout (if you connect RX you need to short the Rout and RX).
RS232 Level
As you can see in the picture, the serial screen comes out at RS232 level, and since RS232 is plus or minus 15V logic, it is able to transmit farther!
Check the "LY-F2 Development Board Circuit Diagram", Screenshot As Follows.
Serial Communication and Control Functions
Then secondly, the serial communication and control functions are programmed.
With the Above Introduction, It Is Easy to Program and the Demo Code Is As Follows.
Finally, Online Debugging.
STONE Tool4.3 software to edit a good
screen file download, arduino code file upload, connect the power supply, communication, arduino development board IO8 and GND connected to the speaker two lines, operation touch screen piano keys, pronunciation function are demonstrated normal!