《NanoPi NEO Air》①入手配置

最近看上了全志H3的芯片,开发板有香橙派和友善两家的板子,最后因为友善的 NanoPi NEO Airwifi蓝牙而选择了它。

1. NanoPi NEO Air简介

NanoPi NEO Air的相关简介可以查看其 中文文档

2.镜像TF卡制作

NanoPi NEO Air 板卡自带了8GB的eMMC,上面官方已经默认烧录了 Linux-4.14 的系统固件,直接使用是可以的。
接下来我讲的是TF卡启动的方式,NanoPi NEO Air 的资料你可以在【下载地址】下载,进行解压后,找到文件目录:

NanoPi-NEO-Air\official-ROMs\nanopi-neo-air_sd_friendlycore-xenial_4.14_armhf_20200817.img

使用 balenaEtcher 软件烧录目录下的 img 镜像到SD卡,烧录完成后直接拔下来插入到 NanoPi NEO Air 板卡卡槽。

3.连接WiFi

# 进入root账户
su root#输入fa
# 开启WiFi
nmcli r wifi on
# 扫描附近的 WiFi 热点
nmcli dev wifi
# 连接到指定的 WiFi 热点(更换"SSID"和"PASSWORD"为自己的人WiFi账户账号和密码)
nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0
# 重启开发板
reboot

4.换源

国内大陆的用户为了获得更快的安装速度,可以在安装之前先将软件包的源设置为国内源:

wget http://112.124.9.243/aptsouce.sh
chmod 755 aptsouce.sh
sudo ./aptsouce.sh
sudo apt-get update

5.安装0.96OLED驱动

安装参考

# 下载代码包
cd  ~
git clone https://github.com/friendlyarm/BakeBit.git
# 安装BakeBit包
cd BakeBit/Script
chmod +x install.sh
sudo ./install.sh

安装完成之后,便可以调用例程看下效果了:

# 进入python例程目录
cd ~/BakeBit/Software/Python
# 运行动画例程
sudo python bakebit_128_64_oled_animate.py

接下来,使用之前【树莓派播放badapple】的方式,修改显示函数,即可在NanoPi上播放badapple,代码如下:
由于在显示图片时,发现显示驱动有些问题,先修改驱动,打开绝对目录下sudo nano ~/BakeBit/Software/Python/bakebit_128_64_oled.py文件,将其drawImage(image)函数修改为:

def drawImage(image):
    """Set buffer to value of Python Imaging Library image.  The image should
    be in 1 bit mode and a size equal to the display size.
    """
    if image.mode != '1':
        raise ValueError('Image must be in mode 1.')
    imwidth, imheight = image.size
    if imwidth != SeeedOLED_Width or imheight != SeeedOLED_Height:
        raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
            .format(SeeedOLED_Width, SeeedOLED_Height))
    # Grab all the pixels from the image, faster than getpixel.
    pix = image.load()
    # Iterate through the memory pages
    bitList = []
    pages=SeeedOLED_Height/8
    for page in range(pages):
        # Iterate through all x axis columns.
        for x in range(SeeedOLED_Width):
            # Set the bits for the column of pixels at the current position.
            bits = 0
            # Don't use range here as it's a bit slow
            for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
                bits = bits << 1
                bits |= 0 if pix[x,(page-1)*8+7-bit] == 0 else 1
            bitList.append(bits)

    for chunk in chunks(bitList, 32):
        sendArrayData(chunk)

然后使用 FinalShell 工具将 badapple 的帧照片文件夹导入cd ~/BakeBit/Software/Python目录,badapple 的帧照片怎么生成请查看【视频 转换为 可调分辨率 的图片】,然后新建文件sudo nano badapple.py,添入如下代码:

import bakebit_128_64_oled as oled
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import time
import subprocess
 
oled.init()  #initialze SEEED OLED display

oled.clearDisplay()          #clear the screen and set start position to top left corner
oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)
oled.setHorizontalMode()
 
while True:
    x = 0
    y = 0
    # Create blank image for drawing.
    # Make sure to create image with mode '1' for 1-bit color.
    width = 128
    height = 64
    image = Image.new('1', (width, height))
    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)
    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)
    
    font = ImageFont.truetype('DejaVuSansMono.ttf', 10)
    
    for Test in range(1,500):
        # Draw a black filled box to clear the image.
        draw.rectangle((0,0,width,height), outline=0, fill=0)
 
        # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
        cmd = "hostname -I | cut -d\' \' -f1"
        IP = subprocess.check_output(cmd, shell = True )
        cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
        CPU = subprocess.check_output(cmd, shell = True )
        cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
        MemUsage = subprocess.check_output(cmd, shell = True )
        cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'"
        Disk = subprocess.check_output(cmd, shell = True )
 
        # Write two lines of text.
        draw.text((x+32, y),    "Liuzewen pi",  font=font, fill=255)
        draw.text((x, y+11),    "Test: ",  font=font, fill=255)
        draw.text((x, y+22),    "IP: " + str(IP),  font=font, fill=255)
        draw.text((x, y+32),    str(CPU), font=font, fill=255)
        draw.text((x, y+42),    str(MemUsage),  font=font, fill=255)
        draw.text((x, y+52),    str(Disk),  font=font, fill=255)
 
        # Display image.
        oled.drawImage(image)
        time.sleep(.1)
    
    for I_image in range(1,6540,2):#6540
        image = Image.open('badapple/'+str(I_image)+'.jpg').convert('1')
        oled.drawImage(image)

接下来在cd ~/BakeBit/Software/Python目录下执行sudo python badapple.py即可看到OLED屏幕上在显示系统信息和badapple之间来回切换。
如果想让OLED在开机时就开始显示系统参数。则需要在cd ~/BakeBit/Software/Python目录下新建sudo nano start.sh文件,修改其内容为:

#!/bin/sh
cd /home/pi/BakeBit/Software/Python
sudo python badapple.py&

按下ctrl+o保存,使用ctrl+x退出编辑。
修改shell脚本权限sudo chmod 777 /home/pi/BakeBit/Software/Python/start.sh
写好了shell脚本,接下来【设置程序开机自启动】,输入sudo nano /etc/rc.local,在exit 0的上一行添加如下代码:

/home/pi/BakeBit/Software/Python/start.sh start

执行sudo reboot重启板子即可看到OLED已经运行了起来!

6.安装mp3解码库

为了使板子能正常播放音频:

# 安装音频驱动
sudo apt-get update
sudo apt-get install libasound2
sudo apt-get install alsa-base
sudo apt-get install alsa-utils
# 安装 sox 播放器
sudo apt-get install sox
# 安装WAV,MP3,MPG,OGG,FLAC等格式的解码支持
sudo apt-get install libsox-fmt-all
# 播放方式
play *.mp3

未完,待续~~~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值