<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Cantinho Pessoal</title>
<subtitle></subtitle>
<link href="http://www.asw.pt/blog/feed.php" rel="self" />
<id>http://www.asw.pt/blog/feed.php</id>
<updated>2020-10-27T01:07:38+00:00</updated>
<entry>
<title type="html">Covid-19 no mundo</title>
<content type="html">&lt;p&gt;Este vídeo é produzido diariamente de forma totalmente automática por volta das 20h GMT ou BST conforme a época do ano.&lt;/p&gt;
&lt;p&gt;&lt;video width=&quot;680&quot; height=&quot;440&quot; controls=&quot;controls&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt;
&lt;source src=&quot;https://asw.pt/covid/covid.mp4&quot; type=&quot;video/mp4&quot; /&gt;
&lt;/video&gt;&lt;/p&gt;</content>
<link href="http://www.asw.pt/blog/index.php?controller=post&amp;amp;action=view&amp;amp;id_post=4" />
<id>http://www.asw.pt/blog/index.php?controller=post&amp;amp;action=view&amp;amp;id_post=4</id>
<updated>2020-10-27T01:07:38+00:00</updated>
<category term="Covid-19"/>
</entry>
<entry>
<title type="html">Ecrã Informativo para Raspberry Pi</title>
<content type="html">&lt;p&gt;Este ecrã funciona com Raspberry 2/3/4 e Zero que tenham uma entrada JTAG de 40 pinos.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.asw.pt/blog/content/public/upload/rpipinout_0_o.png&quot; alt=&quot;undefined&quot; width=&quot;294&quot; height=&quot;206&quot; /&gt;&lt;img src=&quot;http://www.asw.pt/blog/content/public/upload/rbpiinfofan_0_o.jpg&quot; alt=&quot;undefined&quot; width=&quot;169&quot; height=&quot;226&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span style=&quot;color: #ff6600;&quot;&gt;Material Necessário:&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;1 x Raspberry Pi com JTAG de 40 pinos.&lt;br /&gt;1 x PDC8544, ecrã Nokia 5110&lt;/p&gt;
&lt;h3&gt;Para apenas acender a iluminação do ecrã:&lt;/h3&gt;
&lt;p&gt;1 x Resistência 470 ohms&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Para acender a iluminação do ecrã com regulação de intensidade:&lt;/h3&gt;
&lt;p&gt;1 x Resistência variável de 5K&lt;/p&gt;
&lt;h3&gt;Para activar uma ventoínha de acordo com a temperatura do CPU:&lt;/h3&gt;
&lt;p&gt;1 x Transistor 2N2519&lt;br /&gt;1 x Resistência de 100 ohms&lt;/p&gt;
&lt;h3&gt;Requisitos de Software:&lt;/h3&gt;
&lt;p&gt;Executar o raspi-config e activar o interface SPI&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Adafruit Circuit Python lib, Adafruit PCD8544 lib, Python Pillow, psutil e netifaces&lt;/p&gt;
&lt;pre&gt;&lt;code data-language=&quot;shell&quot;&gt;$ sudo pip3 install adafruit-circuitpython-lis3d adafruit-circuitpython-pcd8544 Pillow psutil netiface&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Esquemáticos:&lt;/h3&gt;
&lt;p&gt;Para ligação da iluminação através do próprio RBPi sem controlo de intensidade:&lt;/p&gt;
&lt;p&gt;RST -&amp;gt; GPIO22 (Pin 15)&lt;br /&gt;CE (ou CS) -&amp;gt; GPIO5 (Pin 29)&lt;br /&gt;DC -&amp;gt; GPIO6 (Pin 31)&lt;br /&gt;Din -&amp;gt; MOSI (Pin 19)&lt;br /&gt;CLK -&amp;gt; SCLK (Pin 23)&lt;br /&gt;VCC -&amp;gt; Qualquer pino 3V3 (Pins 1 ou 17)&lt;br /&gt;BkLgt -&amp;gt; Resistência de 470R -&amp;gt; GPIO13 (Pin 33)&lt;br /&gt;GND -&amp;gt; Qualquer GND disponível no Raspberry (Pins 6, 9, 14, 20, 25, 30, 34 ou 39).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.asw.pt/blog/content/public/upload/rbpis1_0_o.png&quot; alt=&quot;undefined&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Para utilizar um potenciómetro para definir a intensidade da iluminação do ecrã:&lt;/p&gt;
&lt;p&gt;BkLgt -&amp;gt; Potenciómetro&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.asw.pt/blog/content/public/upload/rbpis2_0_o.png&quot; alt=&quot;undefined&quot; width=&quot;376&quot; height=&quot;490&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Com ventoínha:&lt;/p&gt;
&lt;p&gt;GPIO17 (Pin 11) -&amp;gt; Resistência de 100 ohms -&amp;gt; Base do transistor 2N2519&lt;br /&gt;É possível tirar os +5V do RBPi, mas para uma ventoínha de baixo consumo, &amp;lt;1W a 5V, ou usar uma fonte externa para alimentar a ventoínha, neste caso o Ground dessa fonte tem que estar ligado a um pin GND do Raspberry:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.asw.pt/blog/content/public/upload/rbpis2fan_0_o.png&quot; alt=&quot;undefined&quot; /&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h3&gt;Código:&lt;/h3&gt;
&lt;pre&gt;&lt;code data-language=&quot;python&quot;&gt;import time
import board
import busio
import digitalio
import os
import psutil
import adafruit_pcd8544
from datetime import datetime
import netifaces as ni
from PIL import Image, ImageDraw, ImageFont
##CONFIGURAÇÕES
tempoPorSlide = 5 #Segundos a mostrar cada slide
hddExtra = False #Se existe algum disco externo ligado
hddMountPoint = &quot;&quot; #Se existir onde está montado
usarVentoinha = False #Se se usa ou não uma ventoínha externa
ventoinhaPin = digitalio.DigitalInOut(board.D17) #Pino no qual se encontra a ventoínha, se existir
tempOff = 30 #Temperatura em ºC a desligar a ventoínha
tempOn = 45 #Temperatura em ºC a ligar a ventoínha
thermalKey = &quot;cpu_thermal&quot; #No RBPi 4 é cpu_thermal, no Zero é cpu-thermal...
backLight = False #Usar o GPIO 13 para ligar o LED

# Initialize SPI bus and control pins
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
dc = digitalio.DigitalInOut(board.D6) # data/command
cs = digitalio.DigitalInOut(board.D5) # Chip select
reset = digitalio.DigitalInOut(board.D22) # reset

display = adafruit_pcd8544.PCD8544(spi, dc, cs, reset)
if backLigth:
   ##LED com PWM   
   backlight = digitalio.DigitalInOut(board.D13)
   backlight.switch_to_output()
   #Ligar o LED, é activeLow, portanto False liga, True desliga
   backlight.value = False 

display.bias = 10
display.contrast = 80
display.fill(0)
display.show()
#Carregar os tipos de letra
font = ImageFont.truetype(&quot;6px-Normal.ttf&quot;,8) 
tfont = ImageFont.truetype(&quot;PressStart2P-Regular.ttf&quot;,10)
ifaces = ni.interfaces()
nrifaces = len(ifaces)

def ifaceup(iface):
   addr = ni.ifaddresses(iface)
   return ni.AF_INET in addr

def checkIfaces():
   ifups = list()
   ups = 0
   for i in range(0,nrifaces):
      if ifaces[i] == &quot;lo&quot;:
         continue
      if ifaceup(ifaces[i]):
         ifups.append(ifaces[i])
         ups+=1
   return ups,ifups

def sz_to_txt(sz):
   if sz &amp;gt; 1073741824:
      return &#039;{:.2f}&#039;.format(sz/1073741824) + &quot; Gb&quot;
   if sz &amp;gt; 1048576:
      return &#039;{:.2f}&#039;.format(sz/1048576) + &quot; Mb&quot;
   if sz &amp;gt; 1024:
      return &#039;{:.2f}&#039;.format(sz/1024) + &quot; kb&quot;
   return sz + &quot; b&quot;

def clock():
   data = Image.new(&quot;1&quot;,(display.width,display.height))
   draw = ImageDraw.Draw(data)
   now = datetime.now()
   dt = now.strftime(&quot;%d/%m/%Y&quot;)
   hr = now.strftime(&quot;%H:%M:%S&quot;)
   (font_w, font_h) = font.getsize(dt)
   draw.text((0, 0),dt,font=font,fill=255)
   (hr_sz, hr_h) = font.getsize(hr)
   draw.text((display.width - hr_sz,0),hr,font=font,fill=255)
   return (data,draw,hr_h)

def slideLabel(label,y,draw):
   t = label
   (f_w,f_h) = tfont.getsize(t)
   draw.text((display.width // 2 - f_w // 2,y+2),t,font=tfont,fill=255)
   return y+2+f_h

def infoLine(label,content,y,draw):
   draw.text((0,y+2),label,font=font,fill=255)
   (f_w,f_h)=font.getsize(content)
   draw.text((display.width - f_w,y+2),content,font=font,fill=255)
   y+=2+f_h
   return y

def infoChart(whole,chunk,y,draw):
   val = round((chunk * 360)/whole)
   draw.pieslice([(24,y+2),(58,48)],start=20, end=val+20,fill=255)

def barChart(whole,chunk,y,draw):
   val = round((chunk * 80)/whole)
   y=y+5
   draw.rectangle((0, y, display.width, y+20), outline=255, fill=255)
   draw.rectangle((2,y+2,val,y+18), outline=0, fill=0)

def slideOne(start=0):
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;Rede&quot;,y,draw)
   ifs, iface = checkIfaces()
   net_count = 0
   all_nets = True
   for x in range(start,ifs):
      net_count+=1
      if len(iface[x]) &amp;gt; 5:
         iname = iface[x][0:5]
      else:
         iname = iface[x]
         ifname = iname + &quot;:&quot;
      ip = ni.ifaddresses(iface[x])[ni.AF_INET][0][&#039;addr&#039;]
      y = infoLine(ifname,ip,y,draw)
      if x &amp;lt; ifs - 1 and net_count == 3:
         all_nets = False
         break
   display.image(data)
   display.show()
   if not all_nets:
      time.sleep(5)
      slideOne(x+1)

def slideTwo():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;SD&quot;,y,draw)
   stat= os.statvfs(&quot;/&quot;)
   sz = stat.f_blocks*stat.f_bsize
   free = stat.f_bfree*stat.f_bsize
   used = sz - free
   y = infoLine(&quot;Usado:&quot;,sz_to_txt(used),y,draw)
   y = infoLine(&quot;Livre:&quot;,sz_to_txt(free),y,draw)
   y = infoLine(&quot;Total:&quot;,sz_to_txt(sz),y,draw)
   display.image(data)
   display.show()

def slideThree():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;SD&quot;,y,draw)
   stat= os.statvfs(&quot;/&quot;)
   sz = stat.f_blocks*stat.f_bsize
   free = stat.f_bfree*stat.f_bsize
   infoChart(sz,free,y,draw)
   display.image(data)
   display.show()

def slideFour():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;HDD&quot;,y,draw)
   stat= os.statvfs(hddMountPoint)
   sz = stat.f_blocks*stat.f_bsize
   free = stat.f_bfree*stat.f_bsize
   used = sz - free
   y = infoLine(&quot;Usado:&quot;,sz_to_txt(used),y,draw)
   y = infoLine(&quot;Livre:&quot;,sz_to_txt(free),y,draw)
   y = infoLine(&quot;Total:&quot;,sz_to_txt(sz),y,draw)
   display.image(data)
   display.show()

def slideFive():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;HDD&quot;,y,draw)
   stat= os.statvfs(hddMountPoint)
   sz = stat.f_blocks*stat.f_bsize
   free = stat.f_bfree*stat.f_bsize
   infoChart(sz,free,y,draw)
   display.image(data)
   display.show()

def slideSix():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;RAM&quot;,y,draw)
   mem= psutil.virtual_memory()
   sz = mem.total
   free = mem.free
   used = sz-free
   y = infoLine(&quot;Usado:&quot;,sz_to_txt(used),y,draw)
   y = infoLine(&quot;Livre:&quot;,sz_to_txt(free),y,draw)
   y = infoLine(&quot;Total:&quot;,sz_to_txt(sz),y,draw)
   display.image(data)
   display.show()

def slideSeven():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;RAM&quot;,y,draw)
   mem= psutil.virtual_memory()
   sz = mem.total
   free = mem.free
   barChart(sz,free,y,draw)
   display.image(data)
   display.show()

def slideEight():
   display.fill(0)
   data,draw,y = clock()
   y = slideLabel(&quot;Temp.&quot;,y,draw)
   tr = psutil.sensors_temperatures()
   tx = tr[thermalKey][0].current
   if usarVentoinha:
      if tx &amp;gt; tempOn and fan.value == False:
         fan.value = True
      elif tx &amp;lt; tempOff and fan.value == True:
         fan.value = False
   stemp = &#039;{:.1f}&#039;.format(tx)+&quot; ºC&quot;
   y = slideLabel(stemp,y,draw)
   display.image(data)
   display.show()

while 1:
   slideOne()
   time.sleep(tempoPorSlide)
   slideTwo()
   time.sleep(tempoPorSlide)
   slideThree()
   time.sleep(tempoPorSlide)
   if hddExtra:
      slideFour()
      time.sleep(tempoPorSlide)
      slideFive()
      time.sleep(tempoPorSlide)
   slideSix()
   time.sleep(tempoPorSlide)
   slideSeven()
   time.sleep(tempoPorSlide)
   slideEight()
   time.sleep(tempoPorSlide)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tipos de Letra:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/blog/Info_Fonts.zip&quot;&gt;Download&lt;/a&gt;&lt;/p&gt;</content>
<link href="http://www.asw.pt/blog/index.php?controller=post&amp;amp;action=view&amp;amp;id_post=2" />
<id>http://www.asw.pt/blog/index.php?controller=post&amp;amp;action=view&amp;amp;id_post=2</id>
<updated>2020-10-26T21:58:49+00:00</updated>
<category term="Raspberry Pi"/>
</entry>
</feed>