10. Output devices¶
Individual assignment¶
- Add an output device to a microcontroller board you’ve designed, and program it to do something.
Group assignment¶
- Measure the power consumption of an output device. link to group assignment
What is an output device?¶
Output devices in electronics are the external devices that are connceted to a microcontroller that transform electrical energy into another type of energy, such as light, sound or kinetic energy. Examples of such output devices are given below: - Buzzer. - Speaker. - lamp. - Led. - Motor. - Relay.
The output device that I chose for this week’s assignment is the servo motor. A servo motor is a self-contained electrical device, that rotate parts of a machine with high efficiency and with great precision. The output shaft of this motor can be moved to a particular angle, position and velocity that a regular motor does not have. Since I am new to electronics and trying to learn through trial and error principle I decided to do redesigning of Neil’s board for servo with Attiny 44. The following image is Neil’s board with Attiny 44 which I shall be redesigning using Autodesk Eagle software.
So I start with the re-designing using Autodesk Eagle software.
Designing¶
As usual first open the Eagle software and add the fab libraries for components.
Next up open a new schematic to add the components and to connect them. After adding all the needed components and doing the connections, my schematic came out to be something like this.
Now that the schematic is done, I switch to Board design for routing and checking whether the electronic connections are done correctly or not.
After routing my board design came out something like this.
Now time to do the DRC check.
I found around 3 wire stubs in my board design so had to delete them. I had no other errors so it was time to export the png files of the board and the border of the board.
While exporting the traces, you have to hide the dimesions(border) of the board and while exporting the border of the board, you have to hide the traces and other layers. To export, go to File>> export>> image and while exporting dont forget to choose monochrome and to set the image resolution to 1000 dpi.
Change of plans¶
I was trying to use the servo but I messed up the regulator connections which let to burning up of the microcontroller so I cancelled using the sevo and started planning to test the audio output which I will be using in the final project. For output I will be making my final project board will use that board for the output assignment. So I start designing the board. As usual I added the fab libraries and this time I decided to use ESP32 as microcontroller as it has got a lot of features that I can use and doesn’t get burnt out easily. It was recommended to me by Mr. Suhas Labade who helped me a lot with the electronics parts and because of him now I know what components are necessary, how to do the connections, use of different programmer, libraries and lots more. So my schematic design for my final project is given below.
For the speaker I used an MP3 module to connect the speaker to my board. The mp3 module I used has 3 pins namely, GND, VCC and Sinal(in) pin.
After completing the schematic, I switch to Board view where I manually did the routing manually which took me more than two hours and made me use around 6 zero ohm resistors. Phewww… The successfully routed board design is shown in the image below.
After routing you have to do the DRC check where the computer finds out if there is any errors. For me I found a number of wire stubs and airwires which I had to remove and some errors which I corrected. Some of the design rules I set are given in the following images;
Now all is done with regards to designing. Now I drew the border for my board and exported both the traces and border png images. Next up for generation of toolpath I went to MitMods to calculate the toolpath. Right click>> Programs>> Open server program>> SRM20 PCB Png.
Next upload the png file for traces and border>> calculate. Delete the web socket device and save the file and calculate again and then the rml file gets downloaded automatically.
Next up take the rml file for traces to V-panel for srm20 and cut and repeat for the border also.
After cutting
Next up I went for soldering. First I soldered the ESP32, header pins and rest of the components which took me almost an hour. The best part for me with electronics has become the soldering. I really enjoy soldering, its so satisfying.
Programming¶
To play sound with ESP32 we need a speaker and LM386 Amplifier Module(mp3 module). The VCC and GND pins of the amplifier module is connected to VCC and GND of ESP32 and the ‘IN’ pin is connected to GPIO25 pin of ESP32. GPIO 25 is one of the 2 DAC (Digital to Analog Converter) pins. The Speaker’s VCC and GND are connected with VCC and GND of the amplifier module. I tried using a SD card module to load an audio file in the SD card and play through the speaker but after going through this documentation online I found out that ESP32 is enough to store the audio file instead of using a SD card module so I cancelled using the SD card module.
If you want to know more about the LM386 amplifier module you can follow this website where its detailed about the amplifier module.
Since the ESP32 reads only .wav files for audio, we cannot use other formats to upload the audio. Once you have your audio file ready, you need dto download Audacity software to change the file type, Sample Rate, and other properties. Once you are done downloading and installing the Audacity software go to File>> Open>> Select the audio file as shown below;
The next thing that needed to be changed is the sampling rate. For playing an audio file on ESP32, a sampling rate of 8000 to 16000 will be good as ESP32 doesn’t have much memory. So change the Project Rate to 16000 as shown below;
Next go to File>> Export>> Export as WAV and convert the audio file to WAV format.
Select file format as WAV(microsoft) and in the encoding section choose ‘Unsigned 8-bit PCM’ and save the file in the prefered destination on your computer.
Next we need HEX editor software to make hex code from the audio file. You can download the HXD(HEX editor) from here. After downloading and installing the HXD, go to file>> Open and open the WAV file.
Next select all the code and go to Edit>> Copy as>> Select’C’.
Next is the coding. First I connected the board to my computer with the help of FTDI cable. Connected the LM386 Amplifier Module(mp3 module) to the board using the GPIO25 pin as ‘In’ pin of the MP3 module. Then I connected the Speaker to the LM386 Amplifier Module.
The code for the Audio output is given below;
// Playing a simple melody using the XTronical DAC Audio library
// Demonstrates use of the music score object
// See www.xtronical.com for write ups on sound and for hardware required
// edited by Thinlay Namgyal
#include "MusicDefinitions.h";
#include "XT_DAC_Audio.h";
// Data for the melody. Note followed by optional change in playing length in 1/4 beats. See documentation for more details
int8_t PROGMEM TwinkleTwinkle[] = {
NOTE_C5,NOTE_C5,NOTE_G5,NOTE_G5,NOTE_A5,NOTE_A5,NOTE_G5,BEAT_2,
NOTE_F5,NOTE_F5,NOTE_E5,NOTE_E5,NOTE_D5,NOTE_D5,NOTE_C5,BEAT_2,
NOTE_G5,NOTE_G5,NOTE_F5,NOTE_F5,NOTE_E5,NOTE_E5,NOTE_D5,BEAT_2,
NOTE_G5,NOTE_G5,NOTE_F5,NOTE_F5,NOTE_E5,NOTE_E5,NOTE_D5,BEAT_2,
NOTE_C5,NOTE_C5,NOTE_G5,NOTE_G5,NOTE_A5,NOTE_A5,NOTE_G5,BEAT_2,
NOTE_F5,NOTE_F5,NOTE_E5,NOTE_E5,NOTE_D5,NOTE_D5,NOTE_C5,BEAT_4,
NOTE_SILENCE,BEAT_5,SCORE_END
};
XT_DAC_Audio_Class DacAudio(25,0); // Create the main player class object. Use GPIO 25 (DAC pin) and timer 0
XT_MusicScore_Class Music(TwinkleTwinkle,TEMPO_ALLEGRO,INSTRUMENT_PIANO); // Music score object, handles tunes. Pass Music Data,Tempo
// You can just pass the music data and the rest will default to... well.... default values!
void setup() {
Music.Repeat=5; // We'll repeat it 5 times
DacAudio.Play(&Music);
}
void loop() {
DacAudio.FillBuffer(); // This needs only be in your main loop once, suggest here at the top.
// put whatever code you want here that you would normally have on your loop
}
Select the board as ESP32 DEV Module and compile and upload the code. It was a sigh of relief when finally the speaker started giving audio output as I tried alot of times and failed alot of times like it took me 3 days to finally break through. The following video shows that the audio is finally being played through the speaker.
I would like to acknowledge Mr. Suhas Labade(our local instructor) from Vigyan Ashram for teaching and helping me with this week’s assignment as without him I would have had a tough time.
Design files¶
output board shcematic designe file
output board design file