LoginSignup
15
9

Raspberry Pi Pico 単3電池拡張ボードでハンダ付けなしの電池駆動IoTを試してみた

Last updated at Posted at 2023-08-05

ビット・トレード・ワンから販売されているRaspberry Pi Pico 単3電池拡張ボードを試してみました。
このボードを使えば、簡単にRaspberry Pi PicoやRaspberry Pi Pico Wを単3電池2本で駆動できます。
リセットスイッチやGrove互換コネクタも実装されています。Grove互換コネクタは、GP4,GP5に接続されているので、GPIOやI2CのGroveモジュールを接続することができます。

image.png

Raspberry Pi Pico WHを搭載して、Grove互換コネクタには、GROVE - 温湿度・気圧センサ(BME280)を繋げてAmbientに10分周期で温度を飛ばしてグラフ化するというのを試してみました。
ハンダ付け無しで実現できます。

image.png

プログラム

普段、Raspberry Pi PicoのプログラムはArduino IDEでプログラミングしていますが、今回はThonnyを使ってMicroPythonで初プログラミングしてみました。
環境の準備は、以下のサイトを参考にしました。

BME280は、micropython-bme280というパッケージが用意されていたので、簡単にセンサからの情報を取得できました。

プログラムは、次の通りです。(Pythonは不慣れたなため、雑なプログラムなのはご了承下さい)
Wi-FiやAmbientの設定値は環境に合わせて変更して下さい

SSID = "ssid"
PASS = "password"
ambient_chid='channel id'
ambient_wkey='write key'
amdient_tag='d1' 

import network
import urequests
from sys import exit
from machine import ADC, Pin, lightsleep, reset
from time import sleep
from machine import I2C
from bme280 import BME280

url = 'https://ambidata.io/api/v2/channels/'+ambient_chid+'/data'
http_headers = {'Content-Type':'application/json'}
http_body = {'writeKey':ambient_wkey, amdient_tag:0.0}

machine.Pin(23, machine.Pin.OUT).high()
led = Pin("LED", Pin.OUT)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASS)
while not wlan.isconnected():
    print('.', end='')
    led.toggle()
    sleep(1)
print(wlan.ifconfig()[0])

i2c = I2C(0)
bme = BME280(i2c=i2c)

while True:
    temp = bme.read_compensated_data()[0]/100
    temp_s = str(round(temp,1))
    print('Temperature =',temp_s,end=',')
    http_body[amdient_tag] = temp
    try:
        res = urequests.post(url, json=http_body, headers=http_headers)
        print(' HTTP Stat =', res.status_code)
    except Exception as e:
        print(e)
    res.close()
    wlan.disconnect()
    wlan.active(False)
    machine.Pin(23, machine.Pin.OUT).low()
    machine.deepsleep(10 * 60 * 1000)

動作確認

Ambientのコンソールからグラフを確認できました。

image.png

プログラムは、必要な処理を終えたらWi-Fiの通信を停止し、Wi-Fiモジュールの電源を切ってから10分間deep sleepするようにしています。そのため、平均の消費電力を約2mAまで抑えることができました。

image.png

単3電池でこのぐらいの消費電力だと計算上は1ヶ月以上持つ計算になります。いろんな条件で変わると思うので、Ambient上でデータが入らなくなるまで動作させて実測してみたいと思います。

15
9
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
15
9