First, we had to find a way to implement the keypad properly. After searching for the schematic on the internet, we realized that one pin was connected to all four buttons. The schematic is below. To understand the functionality of the keypad, we began the code by only using the first button. We connected one of the pins attached to all buttons to VCC on the J2 header. The other pin connected to button one is connected to ADC2 pin of the J2 header as well. We decided on using the J2 header because they are ADC/DAC pins on the microcontroller. Also, the J2 header pins were defined in the code as COL1, COL2, COL3, and COL4 for the column of each button. The code stated that the light on the microcontroller, LED0, will turn on when button one is pushed via an if statement. We also added a string of code to display on the LCD screen to show what button was pressed. At first, the LCD screen seemed to act a bit intermittent, and after speaking with the professor, a 10k resistor was added to eliminate floating values. By adding the resistor, we were able to have button one work successfully. We started to implement button two. After a bit of troubleshooting we were able to get button two working successfully, and from there it was just a matter of duplicating the code.
One of the most difficult parts of our projects was figuring out how to initialize our keypad and retrieve inputs to the A3BU. In the code below, we initialize the 4 ADC pins to receive inputs from the 4 buttons on the keypad. Then we have to set each of the inputs to -1 initially. The code stated that the light on the microcontroller, LED0, will turn on when button one is pushed via an if statement. We also added a string of code to display on the LCD screen to show what button was pressed. At first, the LCD screen seemed to act a bit intermittent, and after speaking with the professor, a 10k resistor was added. By adding the resistor, we were able to have button one work successfully. We started to implement button two. We had the issue of something not working properly. Both buttons were wired exactly the same and the code was also identical. After a bit of troubleshooting, the code was changed from “if (ioport_get_pin_level(COL1) > 0)” to “if (ioport_get_pin_level(COL1) == 1)”. By setting a more definite condition, we were able to clear that issue up. We were able to get button one and two to work successfully. We, then, added button three and four. They were tested and passed with no errors. When not pressed, the keypad button in question is set to 0: off. When pressed, it is set to 1: on.
Once we programmed our A3BU to receive inputs from the keypad, we had to create the desired output. To create our short jingles, we used pulse width modulation to vary the frequencies and duty cycles. The desired notes corresponded with a specific frequency, and we chose 85 as the optimum duty cycle to get the clearest tone. By adding in delays, we were able to control the length of the note and the length of the pauses between the notes.
For our final project, we wanted to incorporate some of the skills we’ve learned in previous labs to create a unique and interactive device. Using pulse width modulation from Lab 4, we incorporated our AVR XMEGA-A3BU XPLAINED with a 4-input number pad, four 10K ohm resistors, a piezo buzzer and jumper wires to create a musical touch pad that plays different songs based on which button is pressed. After getting a general understanding of the keypad schematic, we connected the common connection to VCC on the J2 header of the A3BU. The other 4 buttons were connected to 4 of the ADC pins on the J2 header. We connected the piezo buzzer to the SDA and GND pins on the J1 header. After researching the frequency limits of our piezo buzzer, we were able to assign certain frequency values to specific pitches and program the A3BU to play 4 different songs: Twinkle Twinkle Little Star (button 1), Mary Had a Little Lab (button 2), Jingle Bells (button 3), and Ode to Joy (button 4).
General A3BU Setup