Curso Raspberry Pi – #13 – PWM, Entradas, Scripts com uma Câmara

Anteriormente falamos dos fundamentos do GPIO e dos primeiros scripts. Desta vez, vamos testar a geração de sinal PWM na prática. Também usaremos pinos como entradas do nosso sistema. No final, escreva um script que conecte o GPIO e uma câmara. Graças a isso, vamos substituir o Raspberry Pi por uma câmara.

 

Simulação de semáforos no Raspberry Pi

É hora de um breve replay da última parte do curso. Quem é que tentou escrever um script que simulará o funcionamento dos semáforos?

Aqui está a nossa versão desta tarefa. Os díodos foram conectados por resistências de 1,2k Ω aos seguintes pinos: 16 (vermelho), 20 (amarelo) e 21 (verde). O diagrama de fiação foi muito simples:

Na prática, o layout era o seguinte:

No início, configure 3 pinos como saídas e, em seguida, no loop, acendemos ou apagamos díodos individuais:

#!/bin/bash
 
gpio -g mode 16 out
gpio -g mode 20 out
gpio -g mode 21 out
 
while true
do
   gpio -g write 16 1
   gpio -g write 20 0
   gpio -g write 21 0
   sleep 1
   gpio -g write 20 1
   sleep 1
   gpio -g write 16 0
   gpio -g write 20 0
   gpio -g write 21 1
   sleep 1
   gpio -g write 20 1
   gpio -g write 21 0
   sleep 1
   gpio -g write 16 1
   gpio -g write 20 0
   sleep 1
done

Como resultado, recebemos um dispositivo de sinalização simples que exibe alternadamente as combinações individuais:

É hora de mudar para algo novo!

Geração de sinal PWM em Raspberry Pi

O Raspberry pode gerar o sinal PWM , que é usado com mais frequência para alterar o brilho dos LEDs (incluindo faixas de LED). Também é útil quando quer controlar a velocidade dos motores.

No nosso caso, será mais fácil começar com um díodo emissor de luz. Vamos conectá-lo através de uma resistência de 1,2kΩ para fixar o número 12, de acordo com o seguinte diagrama:

De seguida, emitimos o seguinte comando, que irá configurar o pino. O comando pode ser inserido diretamente no terminal ou num script (como fizemos na  parte anterior do curso).

gpio -g mode 12 pwm

Anteriormente, usamos a palavra-chave write para alterar o estado do pin, desta vez seria pwm. Além do número de pinos, também devemos especificar um parâmetro que especificará o preenchimento do sinal PWM. Este parâmetro assume valores no intervalo 0-1024, em que 1024 significa 100% de preenchimento.

Por exemplo, para que o díodo brilhe com brilho total, emitiremos o comando:

gpio -g pwm 12 1024

Para desativá-lo, digite:

gpio -g pwm 12 0

Se o argumento for um número diferente (por exemplo, 800), o LED acenderá com menos brilho. É melhor experimentar aqui testando alguns valores diferentes, por exemplo, 300, 400, 800.

 

 

 

 

 

Num momento nós usaremos o mecanismo de interrupção na prática – então tudo será explicado.

Raspberry Pi como uma câmera

Nós já sabemos como escrever scripts e controlar portas GPIO. É hora de usá-lo para construir algo prático. Vamos tornar um Raspberry numa câmara.

Ele será adicionalmente equipado com um botão, um díodo e uma campainha. A foto será tirada após pressionar o botão, e os elementos restantes sinalizarão (com luz e som) o estado da câmara. Graças a isso todos poderão tirar uma foto com um Raspberry.

Adicionamos um módulo de campainha ao sistema previamente montado e conectamos uma câmara ao Raspberry Pi. Os pinos atualmente usados ​​são:

  • pino número 21 – o módulo de campainha,
  • pino número 12 – diodo conectado através de um resistor de 1,2kΩ,
  • pino número 26 – botão.

Na prática, teremos que “domar” um pequeno emaranhado de cabos:

Vamos começar a escrever. No início, a configuração do GPIO é necessária. Conecte a campainha ao pino 21, o pino 12 controlará o díodo e, para fixar o número 26, conecte o botão:

# configuração de pinos
gpio -g mode 21 out #Buzzer
gpio -g mode 12 pwm #LED
gpio -g mode 26 up #Przycisk

De seguida, informa-mos (incluindo o LED) que a câmara está pronta e a aguardar que o botão seja pressionado. A saída à qual conectamos o díodo foi configurada como PWM, para que possamos controlar o brilho de nossa sirene. Quando o usuário pressiona o botão, o programa executa:

gpio -g pwm 12 800
gpio -g wfi 26 falling

Agora desligamos o díodo e ligamos a campainha que sinalizará tirar uma foto:

gpio -g pwm 12 0
gpio -g write 21 0

O próximo passo, mais importante, é tirar a foto . Para este propósito, usamos o conhecido programa raspistill. Como lembrete, uma linha é suficiente:

raspistill -t 200 -n -o 'zdjecie-%d.jpg' -dt

No final, desligue a campainha:

gpio -g write 21 1

Por fim, o script aparat.sh tem o formato:

#!/bin/sh
 

gpio -g mode 21 out #Buzzer
gpio -g mode 12 pwm #LED
gpio -g mode 26 up #Przycisk
 

gpio -g pwm 12 800
gpio -g wfi 26 falling
 

gpio -g pwm 12 0
gpio -g write 21 0
 

raspistill -t 200 -n -o 'zdjecie-%d.jpg' -dt
 

gpio -g write 21 1

No final, damos as permissões certas (discutimos os detalhes anteriormente):

chmod +x aparat.sh

Agora nós executamos a “câmara”:

./aparat.sh

Depois de iniciar o programa, um díodo acenderá para informar o usuário quando a câmara estiver pronta. Pressionando o botão irá desligar o díodo e iniciar a campainha. O som irá parar quando a foto for tirada. A operação do programa é mostrada graficamente na seguinte animação:

Podemos ver as fotos tiradas, por exemplo, pelo WinSCP:

Sumário

Durante este artigo, nós completamos informações sobre o uso do GPIO. Também criamos um script que combinava portas de E/S universais com outros periféricos (câmara). Os princípios descritos aqui são suficientes para criar muitos scripts úteis. Na parte posterior do curso, escrevemos programas Python simples. Graças a isso, o uso do GPIO será ainda mais fácil, especialmente quando quiser conectar periféricos mais complexos.

___________

O que achou deste artigo? Deixe o seu comentário abaixo, e partilhe nas Redes Sociais que certamente será útil e interessante para os seus amigos!

 

 

 Curso Raspberry Pi – #1 – Introdução, Índice

 Curso Raspberry Pi – #2 – O que é o Raspberry Pi?

Curso Raspberry Pi – #3 – Caixa, Dissipadores de Calor

 Curso Raspberry Pi – #4 – Instalação do Sistema, Raspberry Pi como PC 

 Curso Raspberry Pi – #5 – Instalação / Comunicação Via UART

 Curso Raspberry Pi – #6 – Instalação / Comunicação Através da Rede

 Curso Raspberry Pi – #7 – Acesso Remoto VNC, Chaves SCP, RSA

 Curso Raspberry Pi – #8 – O Básico do Linux

 Curso Raspberry Pi – #9 – Processadores de Texto

 Curso Raspberry Pi – #10 – Câmara, Fotos, Transmissão de Imagem

 Curso Raspberry Pi – #11 – Filmes, Slowmotion, Timelapse

 Curso Raspberry Pi – #12 – Noções Básicas sobre GPIO, Scripts

 Curso Raspberry Pi – #13 – PWM, Entradas, Scripts com uma Câmara

 Curso Raspberry Pi – #14 – Python Básico, GPIO

165 thoughts on “Curso Raspberry Pi – #13 – PWM, Entradas, Scripts com uma Câmara

  • 9 Março, 2020 at 14:58
    Permalink

    Good write-up, I am regular visitor of one?¦s web site, maintain up the excellent operate, and It is going to be a regular visitor for a lengthy time.

  • 9 Março, 2020 at 15:01
    Permalink

    Hi, Neat post. There’s a problem with your website in internet explorer, would test this… IE still is the market leader and a big portion of people will miss your wonderful writing because of this problem.

  • 18 Março, 2020 at 20:45
    Permalink

    is berlin

    f371 is telephone us

    f371 achat de is canada

    f371 get a prescription for is

    f371

  • 19 Março, 2020 at 0:17
    Permalink

    fast shipping on is

    0584 is ou commander

    0584 30 pills is usa

    0584 levitra cheaper than is

    0584

  • 21 Março, 2020 at 1:13
    Permalink

    WONDERFUL Post.thanks for share..more wait .. …

  • 21 Março, 2020 at 2:33
    Permalink

    Heya are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own. Do you require any coding knowledge to make your own blog? Any help would be really appreciated!

  • 21 Março, 2020 at 3:48
    Permalink

    It?¦s really a cool and helpful piece of information. I am satisfied that you simply shared this helpful info with us. Please stay us up to date like this. Thank you for sharing.

  • 21 Março, 2020 at 5:07
    Permalink

    Pretty section of content. I simply stumbled upon your site and in accession capital to say that I acquire actually loved account your blog posts. Anyway I’ll be subscribing in your feeds or even I achievement you get admission to constantly rapidly.

  • 21 Março, 2020 at 6:17
    Permalink

    Hiya, I’m really glad I have found this info. Nowadays bloggers publish only about gossips and web and this is really irritating. A good blog with exciting content, this is what I need. Thank you for keeping this website, I will be visiting it. Do you do newsletters? Can not find it.

  • 21 Março, 2020 at 7:27
    Permalink

    he blog was how do i say it… relevant, finally something that helped me. Thanks

  • 21 Março, 2020 at 8:47
    Permalink

    Outstanding post, you have pointed out some superb details , I too believe this s a very excellent website.

  • 13 Abril, 2020 at 11:03
    Permalink

    Whats up are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own. Do you need any coding expertise to make your own blog? Any help would be greatly appreciated!

  • 14 Abril, 2020 at 2:08
    Permalink

    I have not checked in here for some time as I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend 🙂

  • Pingback: vagragenericaar.org

  • 19 Abril, 2020 at 22:21
    Permalink

    never present [url=http://cialisles.com#]tadalafil[/url] often win please fall cialis necessarily thought tadalafil extremely mine http://cialisles.com/

  • 20 Abril, 2020 at 4:29
    Permalink

    This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want?HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  • Pingback: levitra vs viagra

  • Pingback: can i buy naltrexone over the counter

  • Pingback: tylenol 500 mg tablets

  • 22 Maio, 2020 at 15:15
    Permalink

    This is a bleeding compelling post. Thwart my position mambo jambo

  • 22 Maio, 2020 at 20:40
    Permalink

    Wanna hear some quality music ? Check this out: videography

  • 27 Maio, 2020 at 8:42
    Permalink

    Wanna hear some quality music ? Check this out: 網頁

  • 28 Maio, 2020 at 11:25
    Permalink

    Here is some high quality website ! Check this out: xbody

  • 6 Junho, 2020 at 8:24
    Permalink

    I simply want to mention I am just beginner to blogging and truly enjoyed you’re web blog. Likely I’m going to bookmark your blog post . You really have tremendous stories. Thanks a bunch for sharing your web-site.

  • 7 Junho, 2020 at 13:40
    Permalink

    Simply wish to say your article is as amazing.
    The clearness in your post is just spectacular and that i
    can suppose you are a professional on this subject. Fine along with your permission let me to seize your RSS feed to stay up
    to date with imminent post. Thank you 1,000,000 and please carry on the rewarding work.

  • 7 Junho, 2020 at 13:59
    Permalink

    Howdy! This is my first visit to your blog! We are a collection of
    volunteers and starting a new initiative in a
    community in the same niche. Your blog provided us
    useful information to work on. You have done a outstanding job!

  • 8 Junho, 2020 at 13:36
    Permalink

    Good website! I truly love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I’ve subscribed to your feed which must do the trick! Have a great day!

  • 10 Junho, 2020 at 4:44
    Permalink

    gold jewelry bracelets are a bit pricey but they last longer and are very durable too-

  • 12 Junho, 2020 at 4:55
    Permalink

    You are so awesome! I do not believe I have read through anything like that before. So good to discover somebody with a few original thoughts on this topic. Seriously.. many thanks for starting this up. This website is one thing that’s needed on the web, someone with some originality.

  • 12 Junho, 2020 at 7:16
    Permalink

    Hi! I could have sworn I’ve visited your blog before but after browsing through many of the articles I realized it’s new to me. Anyhow, I’m certainly happy I came across it and I’ll be book-marking it and checking back often!

  • 12 Junho, 2020 at 9:39
    Permalink

    Spot on with this write-up, I actually believe this amazing site needs a great deal more attention. I’ll probably be back again to see more, thanks for the advice.

  • 12 Junho, 2020 at 21:23
    Permalink

    This is a topic that’s near to my heart… Best wishes! Exactly where can I find the contact details for questions?

  • 13 Junho, 2020 at 4:24
    Permalink

    The next time I read a blog, Hopefully it won’t fail me as much as this one. After all, I know it was my choice to read, however I actually believed you would probably have something helpful to talk about. All I hear is a bunch of moaning about something you could possibly fix if you were not too busy seeking attention.

  • 14 Junho, 2020 at 0:59
    Permalink

    You made some good points there. I checked
    on the net to learn more about the issue and found most individuals will go along with your views on this site.

  • 14 Junho, 2020 at 20:33
    Permalink

    Nice post. I learn something new and challenging on sites I stumbleupon on a daily basis. It will always be interesting to read through articles from other writers and practice a little something from their websites.

  • 15 Junho, 2020 at 6:26
    Permalink

    Everyone loves it when folks come together and share opinions. Great website, stick with it!

  • 15 Junho, 2020 at 11:22
    Permalink

    After looking at a few of the blog articles on your web page, I truly appreciate your technique of blogging. I saved it to my bookmark site list and will be checking back soon. Please visit my web site as well and let me know how you feel.

  • 16 Junho, 2020 at 20:12
    Permalink

    Having read this I thought it was very enlightening. I appreciate you taking the time and energy to put this short article together. I once again find myself spending a lot of time both reading and posting comments. But so what, it was still worthwhile.

  • 17 Junho, 2020 at 1:59
    Permalink

    You need to be a part of a contest for one of the greatest sites on the net. I most certainly will highly recommend this blog!

  • 19 Junho, 2020 at 2:47
    Permalink

    I needed to thank you for this fantastic read!! I certainly enjoyed every bit of it. I have got you bookmarked to check out new things you post…

  • 19 Junho, 2020 at 7:25
    Permalink

    I have to thank you for the efforts you’ve put in writing this site. I’m hoping to see the same high-grade content by you later on as well. In truth, your creative writing abilities has inspired me to get my own, personal site now 😉

  • 19 Junho, 2020 at 8:33
    Permalink

    That is a great tip especially to those new to the blogosphere. Brief but very accurate info… Many thanks for sharing this one. A must read post.

  • 21 Junho, 2020 at 5:31
    Permalink

    MetroClick specializes in building completely interactive products like Photo Booth for rental or sale, Touch Screen Kiosks, Large Touch Screen Displays , Monitors, Digital Signages and experiences. With our own hardware production facility and in-house software development teams, we are able to achieve the highest level of customization and versatility for Photo Booths, Touch Screen Kiosks, Touch Screen Monitors and Digital Signage. Visit MetroClick in NYC at http://www.metroclick.com/ or , 121 Varick St, New York, NY 10013, +1 646-843-0888.

  • 21 Junho, 2020 at 8:11
    Permalink

    Way cool! Some extremely valid points! I appreciate you penning this article and the rest of the website is very good.

  • 21 Junho, 2020 at 13:31
    Permalink

    It’s difficult to find educated people about this topic, however, you sound like you know what you’re talking about! Thanks

  • 21 Junho, 2020 at 15:11
    Permalink

    Oh my goodness! Amazing article dude! Thank you, However I am encountering troubles with your RSS. I don’t know why I cannot join it. Is there anybody else having similar RSS problems? Anyone that knows the answer will you kindly respond? Thanx!!

  • 21 Junho, 2020 at 15:53
    Permalink

    This is a extremely fascinating post. Thwart my purlieus see more

  • 21 Junho, 2020 at 15:56
    Permalink

    I like reading through an article that can make men and women think. Also, thanks for allowing for me to comment.

  • 21 Junho, 2020 at 16:54
    Permalink

    This is a topic which is near to my heart… Many thanks! Exactly where are your contact details though?

  • 21 Junho, 2020 at 18:24
    Permalink

    An interesting discussion is definitely worth comment. I do believe that you need to publish more on this subject matter, it may not be a taboo matter but typically people do not speak about such topics. To the next! Cheers.

  • 21 Junho, 2020 at 20:48
    Permalink

    This page truly has all the information I wanted concerning this subject and didn’t know who to ask.

  • 22 Junho, 2020 at 0:51
    Permalink

    Pretty! This has been a really wonderful post. Thanks for providing this information.

  • 22 Junho, 2020 at 3:01
    Permalink

    After I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get four emails with the same comment. Is there an easy method you are able to remove me from that service? Thanks a lot.

  • 22 Junho, 2020 at 4:26
    Permalink

    I truly love your website.. Pleasant colors & theme. Did you make this web site yourself? Please reply back as I’m attempting to create my own website and want to learn where you got this from or exactly what the theme is called. Cheers.

  • 22 Junho, 2020 at 6:56
    Permalink

    I have to thank you for the efforts you have put in writing this blog. I really hope to see the same high-grade content from you in the future as well. In truth, your creative writing abilities has encouraged me to get my very own blog now 😉

  • 22 Junho, 2020 at 7:41
    Permalink

    This is a bleeding interesting post. Thwart my purlieus see more

  • 22 Junho, 2020 at 10:10
    Permalink

    I’m excited to uncover this great site. I wanted to thank you for your time just for this wonderful read!! I definitely appreciated every part of it and i also have you book marked to check out new information in your site.

  • 22 Junho, 2020 at 10:19
    Permalink

    I quite like reading a post that can make men and women think. Also, many thanks for allowing me to comment.

  • 22 Junho, 2020 at 13:12
    Permalink

    This is a bleeding compelling post. Report register my site see my website

  • 22 Junho, 2020 at 15:07
    Permalink

    Hey, visit my website . Your website is cool btw . check my site

  • 23 Junho, 2020 at 0:08
    Permalink

    I’m impressed, I have to admit. Rarely do I encounter a blog that’s both equally educative and entertaining, and let me tell you, you’ve hit the nail on the head. The problem is an issue that too few men and women are speaking intelligently about. Now i’m very happy that I found this during my search for something relating to this.

  • 23 Junho, 2020 at 0:49
    Permalink

    This is the perfect web site for anyone who would like to find out about this topic. You understand a whole lot its almost tough to argue with you (not that I actually will need to…HaHa). You definitely put a fresh spin on a topic which has been written about for many years. Wonderful stuff, just excellent.

  • 23 Junho, 2020 at 3:24
    Permalink

    Good day! I could have sworn I’ve been to this web site before but after going through a few of the articles I realized it’s new to me. Anyways, I’m certainly happy I found it and I’ll be book-marking it and checking back frequently!

  • 23 Junho, 2020 at 8:12
    Permalink

    Your style is so unique in comparison to other folks I have read stuff from. Thank you for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

  • 23 Junho, 2020 at 9:32
    Permalink

    You’re so interesting! I do not suppose I’ve truly read through a single thing like that before. So nice to discover another person with genuine thoughts on this subject matter. Really.. thanks for starting this up. This site is one thing that is needed on the internet, someone with a little originality.

  • 23 Junho, 2020 at 10:50
    Permalink

    May I simply just say what a relief to find an individual who genuinely knows what they are talking about on the internet. You definitely know how to bring an issue to light and make it important. More and more people really need to check this out and understand this side of the story. It’s surprising you’re not more popular given that you definitely have the gift.

  • 23 Junho, 2020 at 11:43
    Permalink

    Very interesting details you have remarked, thankyou for putting up. “I’ve made a couple of mistakes I’d like to do over.” by Jerry Coleman.

  • 23 Junho, 2020 at 12:16
    Permalink

    A fascinating discussion is worth comment. I do believe that you need to publish more on this subject matter, it might not be a taboo matter but usually people don’t talk about these topics. To the next! Many thanks.

  • 23 Junho, 2020 at 14:50
    Permalink

    Excellent article. I absolutely appreciate this website. Keep it up!

  • 23 Junho, 2020 at 20:01
    Permalink

    Right here is the perfect webpage for anyone who wants to understand this topic. You understand so much its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a new spin on a subject that has been written about for years. Excellent stuff, just great.

  • 24 Junho, 2020 at 2:20
    Permalink

    I do trust all the ideas you have introduced on your post. They’re very convincing and will certainly work. Nonetheless, the posts are too brief for newbies. Could you please lengthen them a bit from subsequent time? Thanks for the post.

  • 24 Junho, 2020 at 3:30
    Permalink

    I must thank you for the efforts you have put in writing this blog. I am hoping to see the same high-grade content by you in the future as well. In fact, your creative writing abilities has inspired me to get my own site now 😉

  • 24 Junho, 2020 at 4:34
    Permalink

    Hi there, I do think your site may be having internet browser compatibility problems. When I look at your web site in Safari, it looks fine however, if opening in Internet Explorer, it has some overlapping issues. I just wanted to give you a quick heads up! Apart from that, great site!

  • 24 Junho, 2020 at 6:54
    Permalink

    Hello! I simply would like to offer you a huge thumbs up for your great information you have here on this post. I am coming back to your blog for more soon.

  • 24 Junho, 2020 at 7:40
    Permalink

    This site was… how do you say it? Relevant!! Finally I have found something that helped me. Thank you.

  • 24 Junho, 2020 at 9:21
    Permalink

    A fascinating discussion is worth comment. I think that you need to write more on this subject matter, it might not be a taboo subject but usually people don’t talk about these subjects. To the next! Kind regards.

  • 24 Junho, 2020 at 10:07
    Permalink

    Great information. Lucky me I discovered your website by chance (stumbleupon). I’ve book marked it for later.

  • 24 Junho, 2020 at 10:58
    Permalink

    This page definitely has all the info I needed about this subject and didn’t know who to ask.

  • 24 Junho, 2020 at 12:33
    Permalink

    Good site you’ve got here.. It’s difficult to find excellent writing like yours these days. I honestly appreciate individuals like you! Take care!!

  • 24 Junho, 2020 at 13:33
    Permalink

    A motivating discussion is worth comment. I think that you need to write more on this subject matter, it may not be a taboo matter but generally people don’t speak about such issues. To the next! All the best.

  • 24 Junho, 2020 at 14:12
    Permalink

    This is a extremely captivating post. Report register my purlieus click here

  • 24 Junho, 2020 at 14:39
    Permalink

    Way cool! Some very valid points! I appreciate you penning this write-up plus the rest of the site is really good.

  • 24 Junho, 2020 at 15:17
    Permalink

    I blog often and I seriously appreciate your content. This article has truly peaked my interest. I’m going to take a note of your website and keep checking for new information about once a week. I subscribed to your Feed as well.

  • 24 Junho, 2020 at 17:17
    Permalink

    Spot on with this write-up, I honestly believe this website needs a lot more attention. I’ll probably be returning to read through more, thanks for the advice.

Comments are closed.