LoginSignup
0
0

Milk-v duo上のPythonでpinpongライブラリを使ってBMP280で気圧と気温を測定

Last updated at Posted at 2023-12-13

はじめに

秋葉原ロボット部の有志で、milk-v duoを購入し、個々人が様々な実験を行って、勉強会内で報告しています。

Milk-v duoは9ドルのrisc-vコンピュータとして知られています。
ハードウェアは以下の通りです。

  1. CPUはCVITEKのCV1800B (C906@1Ghz + C906@700MHz)
  2. 最高1 GHzで動作するデュアルRV64コア
  3. 64 MBのラム
  4. オプションのアドオンボードを接続すると10/100Mbpsの速度でイーサーネットに接続可能## はじめに
    秋葉原ロボット部の有志で、milk-v duoを購入し、個々人が様々な実験を行って、勉強会内で報告しています。

12月2日の記事では「BMP280をI2C接続したmilk-v duo上でPythonを使って温度と気圧を測定する」では、pimoroniのgithubに掲載の例を利用するために、pipを使ってPyPiからbmp280用ライブラリをダウンロードしてインストールしました。
pinpongにライブラリが存在すると、新たにライブラリをインストールすることなしに、センサ類を利用可能となります。
この記事では、pinpongライブラリ用意されているセンサ利用例として、BMP280を使用する例を紹介します。

pinpongを利用したスクリプト例

pinpongライブラリを使用する例は、milk-v duoの「/usr/lib/python3.9/site-packages/pinpong/examples/milkv-Duo」にあります。

以下にその一覧を示します。
init.py adc.py as7341.py blink.py bme280.py
bme680.py bmi160_acc.py bmi160_step.py bmp280.py
bmp388.py button.py buzzer.py ccs811_read_baseline.py
ccs811_read_data.py dht.py dht20.py ds0469.py
ds1307.py ds18b20.py ens160.py gp2y1010au0f.py
gravityPM2.5.py i2c.py i2c_scan.py iic_to_serial.py
ir_recv.py ir_send.py irq.py lcd1602.py lis2dh.py
max30103.py mics_enable_power.py mics_get_adc_data.py
mics_get_gas_exist.py mics_get_gas_ppm.py mlx90614.py
mp3.py neopixel.py nfc.py nfc_card_info.py
nfc_uart.py nfc_uart_card.py oled2864.py ozone.py
paj7620.py ph1.py ph2.py pwm.py rgb_panel.py
sen0483.py servo.py sht31.py speech_synthesis.py
spi.py sr04_urm10.py st7789-as7341.py st7789.py
tcs34725.py tds.py tone.py uart.py urm09.py
vl53l0.py 

bmp280.py

この中の「bmp280.py」は以下の通りです。
コメント部分は中国語でしたので、英語に翻訳してあります。

# -*- coding: utf-8 -*-

#Effect: Take I2C BMP280 gas sensor
#Connect: Use windows or linux to connect to an arduino main control board, and the air sensor to the I2C port SCL SDA
import time
from pinpong.board import Board
from pinpong.libs.dfrobot_bmp280 import BMP280

Board("MILKV-DUO").begin()                      #Initialization, check the board type and port number, do not enter the port number and run automatically???
#Board("uno","COM36").begin()                   #Specify port initialization under windows
#Board("uno","/dev/ttyACM0").begin()            #Specified port initialization under linux
#Board("uno","/dev/cu.usbmodem14101").begin()   #Initialize the specified port under mac

bmp = BMP280(bus_num=0)

while not bmp.begin():
  print("bmp begin failed")
  time.sleep(2)

while True:
  temp = bmp.temp_c()
  press = bmp.pressure_p()
  alti = bmp.altitude_m(press)
  print("=========== start print ==========")
  print("temperature: %.2f Celsius" % temp)
  print("pressure: %d pa" % press)
  print("altitude: %.2f meter" % alti)
  print("=========== end print ===========")
  time.sleep(1)

使用するピンは

bmp = BMP280(bus_num=0)

から、I2Cの端子のI2C0_SCLとI2C0_SDAであることがわかります。

実際の動作では、私はプログラムの修正が行いやすいように、作業ディレクトリにファイルをコピーしています。

# cp /usr/lib/python3.9/site-packages/pinpong/examples/milkv-Du
o/bmp280.py bmp280pinpong.py

これで、pinpongライブラリを使ってBMP280を動作可能になりました。
例えば、ソースファイルを修正して、BMP280の接続位置を変えて、気温と気圧を計測してみましょう。

参考1 https://forum.sophgo.com/t/duo-pinpong/208
参考2 https://pinpong.readthedocs.io/zh-cn/latest/#

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0