User Tools

Site Tools


notes:c4eng:fall2023:projects:ptb0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:c4eng:fall2023:projects:ptb0 [2023/10/05 02:53] – [SPEAKER (PASSIVE BUZZER - SPEAKER WITH STICKER)] wjohns11notes:c4eng:fall2023:projects:ptb0 [2023/10/05 12:32] (current) – [CODING THE SPEAKER] acuno
Line 11: Line 11:
  
 After identifying the pin number with <wrap hi>GPIO readall</wrap>, we can then use commands such as <wrap hi>GPIO mode PIN# OUTPUT</wrap> and <wrap hi>GPIO write PIN# 1</wrap> and observe the result on our circuit. If we set the GPIO pin connected to our red LED to high, and the red LED doesn't turn on, we know something is wrong.  After identifying the pin number with <wrap hi>GPIO readall</wrap>, we can then use commands such as <wrap hi>GPIO mode PIN# OUTPUT</wrap> and <wrap hi>GPIO write PIN# 1</wrap> and observe the result on our circuit. If we set the GPIO pin connected to our red LED to high, and the red LED doesn't turn on, we know something is wrong. 
-=====SPEAKER (PASSIVE BUZZER - SPEAKER WITH STICKER)=====+=====SPEAKER=====
  
-Passive speaker has one leg longer than the other. It also has a closed bottom while the active speaker has an open bottom.  +Active speaker has one leg longer than the other. It also has a closed bottom while the active speaker has an open bottom.  
-The long lead is the positive connection.+The long lead is the positive connection.  The active speaker behaves in an on or off state.  The tone cannot be altered. 
 + 
 +For this project, the intent is to use a passive speaker and alter the tone.  The passive speaker has the green PCB on the bottom.  Many folks had trouble with the passive speaker, so substituted with the active speaker.
 transister 8050 transister 8050
 +
 +The transistor will be acting as a solenoid to control the continuity between the negative lead on the speaker, and ground. The reason we will be using the transistor to control ground is because the speaker needs 5 volts which can only come from the constant 5v pin. The output pin that controls speaker activation will be the "trigger wire" for the transistor to make continuity between the speaker and ground.
 +
 +=====CODING THE SPEAKER=====
 +The active speaker simply needs to be toggled on or off to work.
 +
 +<code>
 +digitalWrite (GPIO_PIN, STATE) 
 +</code>
 +Where:
 +  * GPIO_PIN = the wiringPi pin number or the name you declared for that pin
 +  * STATE = HIGH or LOW to either enable or disable the GPIO_PIN
 +     
 +The passive speaker needs to also be given a tone, in Hz, to function.
 +
 +<code>
 +softToneWrite (GPIO_PIN, TONE)
 +</code>
 +Where:
 +  * GPIO_PIN = the wiringPi pin number or the name you declared for that pin
 +  * TONE = Frequencyof tone to use, or the name you declared for that variable
 ====GPIO MODE SETTING==== ====GPIO MODE SETTING====
 To initialize our GPIO pins, we use the pinMode() function with the first argument being the pin number, and the second argument being the state (input or output).  To initialize our GPIO pins, we use the pinMode() function with the first argument being the pin number, and the second argument being the state (input or output). 
Line 38: Line 61:
 <code/>if (state  == LOW) { </code> <code/>if (state  == LOW) { </code>
 Then you can use an else, which will only take effect when the button is not being pushed. Then you can use an else, which will only take effect when the button is not being pushed.
 +The entire outline of the code should look like:
 +<code/> if (state == LOW){
 +functions when button is pressed}
 +else {
 +functions to do when button isnt pressed } </code>
  
  
notes/c4eng/fall2023/projects/ptb0.1696474392.txt.gz · Last modified: 2023/10/05 02:53 by wjohns11