Coder Social home page Coder Social logo

micropython-envirobit's Introduction

MicroPython envirobit:bit library for the BBC micro:bit

Installing

enviro:bit consists of:

  • a tcs3472 colour sensor,
  • a bme280 temperature, pressure and humidity sensor
  • a mems microphone

Files are supplied for each of these features, and you can pick and choose what to use in your project.

Copy the driver files from you need from the library/ folder into your "mu_code" folder, this might be in:

  • C:\Users\YourUserName\mu_code on Windows
  • /Users/YourUserName/mu_code on macOS

Create a new blank file in Mu for your project, leave it blank and Flash it to your micro:bit with the Flash button. You can close this for now.

Create another new file, save this one as "main.py" and keep it open.

Now open the "Files" dialog (you might have to close the "Repl" first) and drag and drop main.py and the driver .py files from the right pane, to the left pane.

When you reset your micro:bit, it will load main.py- so you can "import" the libraries and start writing your code here!

Function Reference

bme280

For temperature, pressure and humidity readings you must use the bme280 driver. First initialise it like so:

import bme280
bme = bme280.bme280

Your class instance, bme, will now have the following methods:

  • bme.temperature() - return the temperature in degrees C
  • bme.pressure() - return the pressure in hectopascals
  • bme.humidity() - return the relative humidity in %
  • bme.altitude() - return the altitude in feet, calculated against the current QNH value
  • bme.set_qnh(value) - set the QNH value for calculating altitude

sound

For sound readings you must use the sound driver. First initialise it like so:

import sound
sound = sound.sound()

Your class instance, sound, will now have the following methods:

  • sound.read() - take a reading of the sound level which you can use to compare different sound levels
  • sound.wait_for_double_clap() - listen for a high sound level twice in a second, returns True if detected
  • sound.wait_for_clap() - listen for a high sound level once in a second, returns True if detected

tcs3472

For tcs3472 readings you must use the tcs3472 driver. First initialise it like so:

import tcs3472

light_sensor = tcs3472.tcs3472() 

Your class instance, light_sensor, will now have the following methods:

  • light_sensor.rgb() - returns the corrected levels of red, green and blue out of 255
  • light_sensor.scaled() - return the amounts of red, green and blue on a scale of 0-1
  • light_sensor.light() - return a raw reading of light level on a scale of 0-65535
  • light_sensor.set_leds() - turn the leds on and off with 0 or 1

micropython-envirobit's People

Contributors

gadgetoid avatar jedifodder avatar tanyafish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

micropython-envirobit's Issues

Altitude values clearly incorrect

HI
the altitude values drift all over the shop, so I question their value. The following data was collected over the weekend, when the envirobit was stationary on a desk..

image

humidity values seem to be wrong

I am running little DIY weather stations with 2 microbits each. One is running with the enviro:bit and sending the data to the second one which writes it to an SD-card through an OpenLog.
The reported humidity values are definitely not correct though, as the appear to be directly proportional to the temperature. (See the attached images for the logged values over a period of roughly 6 days)


As an comparison I have data from a weather station run by an university in my city, which covers roughly the same timeframe:

The code was written in the Mu editor, I have attached the code for the microbit that is running the envirobit:
main.txt

If a similar setup is run with the makecode blocks language, reasonable values were obtained (same devices, same enclosure, slightly different weather conditions). For energy efficiency reasons, I tried to do it via micropython which allows me to send the microbit to sleep. Removing the sleep command does not change the reported values.

How to use the drivers without MU?

Not an issue, but I'm kinda new to python and I'm wondering how I could use this drivers without running MU. I'm currently building from Sublime Text 3. Any hints on how I can include the files using (any) other editor? Sorry for the newbie question ...

TypeError on bme.temperature()

On following the instructions:

import bme280
bme = bme280.bme280
bme.temperature()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function takes 1 positional arguments but 0 were given

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.