Programming XinaBox using Python on Raspberry Pi

Programming XinaBox using Python on Raspberry Pi

In this blog post, we will code the RasPi in Python, and access the XinaBox SW01 weather sensor and the OD01 display using the I2C bus.

 

Contents

  1. What you need
  2. Installations
  3. To do
  4. When things don't work as expected
  5. Next steps
  6. References

 

1. What you need

  • a RasPi Zero or RasPi 3 B, connected and set up as per the RasPi Setup document
  • the XinaBox BR01, SW01, and OD01 devices and two xChip connectors

RasPi 3 B with XinaBox BR01, SW01, OD01, power, HDMI, keyboard, and mouse

XinaBox BR01 plugged into RasPi 3 B

  • access to the internet
  • successful completion of the I2C setup as presented in the document "Communicating with the SW01 on Raspberry Pi"
  • some familiarity with the Python programming language
  • the Pi_SW01.py file

 

2. Installations

  • follow the installation instructions below in order to install the Python code libraries for the BME820 advanced weather sensor on the XinaBox SW01 xChip, and the XinaBox OD01 xChip with 128x64 I2C OLED compatible display

 

3. To do

  • connect the Raspberry Pi and xChips as shown above, and power up the devices
  • open a command terminal by clicking the Terminal icon  from the RasPi Desktop, or use an SSH application such as Putty to log in if this is preferred
  • run the following command to install the BME280 driver for Python - change the version number (i.e. 0.2.2) to the latest release version as presented at https://libraries.io/pypi/RPi.bme280
~ $ sudo pip install RPi.bme280
  • run the following command to ensure that required Python libraries which support the OLED libraries, are installed
~ $ sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev build-essential
  • run the following command to install the luma.oled device driver libraries
~ $ sudo -H pip install --upgrade luma.oled
  • copy the Pi_SW01.py file into a directory of your choosing
  • start Thonny Python IDE from the RPi programming menu

  • navigate to the directory where you placed the Pi_SW01.py file using the File -> Open menu in Thonny IDE, and open the file
  • browse the file in order to become familiar with the code
  • run the application and observe the output on the oled display

 

4. When things don't work as expected

  • refer to this section in the RasPi Setup document

 

5. Next steps

  • attempt to add further XinaBox xChips and add code for accessing these

 

6. References

 

Please see our Raspberry Pi XK03 kit, and especially the online instructions for other useful links to getting started, sample code and projects.

Previous article XinaBox Supports Microsoft's Recommended IoT Development Platforms
Next article Communicating with xChip SW01 on Raspberry Pi

Leave a comment

Comments must be approved before appearing

* Required fields