Example Code for UNIHIKER-Python-Weather Data

This article details how to use UNIHIKER and Python to collect and display real-time weather data, including hardware and software setup, wiring instructions, and sample code for utilizing the Pinpong and Lark Weather Station libraries.

Hardware Preparation

  • UNIHIKER x1
  • Lark Weather Station x1

Software Preparation

Wiring Diagram

Other Preparation Work

  1. Install the Pinpong library (pip install pinpong).
  2. Download and import the Lark Weather Station Library for UNIHIKER.

Sample Code

from DFRobot_Atmospherlum import *
from pinpong.board import Board
import time 
Board().begin()
yunque_i2c = DFRobot_Atmospherlum_I2C(0x42)
while (yunque_i2c.begin() != 0):
    print("yunque_i2c initialize failed!!")
    time.sleep(1)
print("Sensor initialize success!!")
yunque_i2c.set_local_time()
time.sleep(1)
while  True:
    print((yunque_i2c.get_time_stamp()))
    print((str((yunque_i2c.get_value("Speed"))) + str((yunque_i2c.get_unit("Speed")))))
    print((yunque_i2c.get_value("Dir")))
    print((str((yunque_i2c.get_value("Temp"))) + str((yunque_i2c.get_unit("Temp")))))
    print((str((yunque_i2c.get_value("Humi"))) + str((yunque_i2c.get_unit("Humi")))))
    print((str((yunque_i2c.get_value("Pressure"))) + str((yunque_i2c.get_unit("Pressure")))))
    time.sleep(1)

Result

The terminal will output the time stamp, wind speed (with unit), wind direction, temperature (with unit), humidity (with unit), and air pressure (with unit) at 1-second intervals.

Was this article helpful?

TOP