dhorton668
Published © CC BY-SA

Bluetooth Weather Station

Exploring the basics of Bluetooth by polling Arduino Nano 33 Sense temperature, humidity and barometer readings from Raspberry Pi.

BeginnerFull instructions provided11,126
Bluetooth Weather Station

Things used in this project

Hardware components

Nano 33 BLE Sense
Arduino Nano 33 BLE Sense
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
I am using an RPi 3B+, but any RPi 3 or 4 should work.
×1
Android device
Android device
The Android device is optional. It is simple used to verify results using the Nordic nRF app.
×1

Software apps and online services

nRF Connect SDK
Nordic Semiconductor nRF Connect SDK
Optional app to help debug Bluetooth

Story

Read more

Code

read_model.py

Python
Another example from the Bleak home page with the MODEL_NBR_UUID slightly tweaked for the Arduino Nano. Must be run with sudo or it will fail.
#!/usr/bin/env python3

import asyncio
from bleak import BleakClient

address = input("Device Address (e.g. 12:34:56:78:9A:BC): ")
MODEL_NBR_UUID = "00002a00-0000-1000-8000-00805f9b34fb"
async def run(address):
    async with BleakClient(address) as client:
        model_number = await client.read_gatt_char(MODEL_NBR_UUID)
        print("Model Number: {0}".format("".join(map(chr, model_number))))

loop = asyncio.get_event_loop()
loop.run_until_complete(run(address))

read_temperature.py

Python
Python code to read GATT characteristic temperature from Arduino Nano. Must be run with sudo or it will fail.
#!/usr/bin/env python3

import asyncio
from bleak import BleakClient

address = input("Device Address (e.g. 12:34:56:78:9A:BC): ")
TEMPERATURE_UUID = "00002a6e-0000-1000-8000-00805f9b34fb"
async def run(address):
    async with BleakClient(address) as client:
        temperature = await client.read_gatt_char(TEMPERATURE_UUID)
        print("Temperature: {0}C".format(int.from_bytes(temperature, byteorder='little', signed=True) / 100))

loop = asyncio.get_event_loop()
loop.run_until_complete(run(address))

discover.py

Python
This is the device discovery code from the Bleak library home page. Remember to run it with sudo or it will fail.
#!/usr/bin/env python3

import asyncio
from bleak import discover

async def run():
    devices = await discover()
    for d in devices:
        print(d)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

read_pressure.py

Python
Python code based on samples from the Bleak library home page, but changed to read and display barometric pressure. Must be run with sudo or it will fail.
#!/usr/bin/env python3

import asyncio
from bleak import BleakClient

address = input("Device Address (e.g. 12:34:56:78:9A:BC): ")
PRESSURE_UUID = "00002a6d-0000-1000-8000-00805f9b34fb"
async def run(address):
    async with BleakClient(address) as client:
        pressure = await client.read_gatt_char(PRESSURE_UUID)
        print("Barometric Pressure: {0}kPa".format(int.from_bytes(pressure, byteorder='little', signed=False) / 10000))

loop = asyncio.get_event_loop()
loop.run_until_complete(run(address))

read_humidity.py

Python
Python code to read GATT characteristic humidity from Arduino Nano. Must be run with sudo or it will fail.
#!/usr/bin/env python3

import asyncio
from bleak import BleakClient

address = input("Device Address (e.g. 12:34:56:78:9A:BC): ")
HUMIDITY_UUID = "00002a6f-0000-1000-8000-00805f9b34fb"
async def run(address):
    async with BleakClient(address) as client:
        humidity = await client.read_gatt_char(HUMIDITY_UUID)
        print("Humidity: {0}%".format(int.from_bytes(humidity, byteorder='little', signed=False) / 100))

loop = asyncio.get_event_loop()
loop.run_until_complete(run(address))

Bluetooth Weather

This sketch runs on the Arduino Nano 33 BLE Sense. It gathers data from temperature, humidity, and barometric pressure sensors and makes it available over a Bluetooth Low Energy connection

Credits

dhorton668

dhorton668

4 projects • 5 followers

Comments