Giter Club home page Giter Club logo

pxt-weather-bit's Introduction

weatherbit Build Status

To use this package, go to https://makecode.microbit.org, click Add package and search for weatherbit.

Usage

The package adds support for the weather:bit add-on board from SparkFun.

Micro:bit Pins Used

The following micro:bit pins are used for weather, atmospheric and aquaponics monitoring:

  • P0 -- Soil Mositure Data
  • P1 -- Wind Direction
  • P2 -- Rain Data (in inches)
  • P8 -- Wind Speed Data
  • P12 -- Temperature Data
  • P14 -- RXI (UART)
  • P15 -- TXO (UART)
  • P16 -- Soil Moisture Power
  • P19 -- BME280 I2C - SCL
  • P20 -- BME280 I2C - SDA

Set Up Function

At the start of any program which will use the BME280 Sensor data (Pressure, Humidity, Altitude, Temperature) place the "Set up Weather Monitoring" in a "Forever" block. It is unknown at this time why this block will not work in the "On Start" block.

Start Monitoring Functions

At the start of any program which will use the weather meter data (Wind Speed, Wind Direction, Rain) place the |start wind monitoring| and |start rain monitoring| in a |on start| block.

weatherbit.startWindMonitoring();
weatherbit.startRainMonitoring();
weatherbit.startWeatherMonitoring()

Atmospheric Data (BME280)

The BME280 sensor onboard the weather:bit communicates via I2C. The data is returned as a number which can be stored in a variable, shown on the LED matrix, or sent serially to OpenLog.

  • |temperature|block returns a 4 digit number, when divided by 100 will provide the temperature in degree C with two decimals.
  • |humidity| block returns a 5 digit number, when divided by 1024 will provide the percent Relative Humidity.
  • |altitude| block returns altitude in meters rounded to the nearest whole number-given P0=1013.25hPa at seal level. (Absolute Altitude)
  • |pressure|block returns an 8 digit number, when divided by 256 will provide the pressure in Pa. Diving again by 100 will provide measurement in hPa.
basic.forever(() => {
    weatherbit.startWeatherMonitoring()
})
basic.showNumber(weatherbit.temperature())
basic.showNumber(weatherbit.pressure())
basic.showNumber(weatherbit.humidity())
basic.showNumber(weatherbit.altitude())

Aquaponics Data

The two central screw terminal blocks on the weather:bit provide space for the Soil Moisture Sensor and the DS18B20 Waterproof Temperature Sensor. Use the logical plug-in blocks to read the soil moisture and temperature of the garden system.

  • |soil moisture| block returns a value between 0 and 1023. 0 being totally dry and 1023 being as wet as water.
  • |soil temperature| block a 4 digit number, when divided by 100 provides the temperature in hundreths of a degree centigrade.
basic.forever(() => {
    basic.showNumber(weatherbit.soilTemperature())
    basic.showNumber(weatherbit.soilMoisture())
})

Weather Meter Data

Using SparkFun's Weather Meters it is possible to obtain wind speed, inches of rain, and wind direction using weather:bit.

  • |wind speed| returns an integer-the wind speed in mph.
  • |wind direction| returns a string corresponding to the direction of the wind. (N, S, E, W, NE, NW, SE, SW)
  • |rain| returns an integer - inches of rain.
basic.forever(() => {
    basic.showNumber(weatherbit.windSpeed())
    basic.showString(weatherbit.windDirection())
    basic.pause(300)
    // serial.writeValue("wind direction",
    // weatherbit.windDirection())
    basic.showNumber(weatherbit.rain())
})
weatherbit.startRainMonitoring()

Serial Logging with OpenLog

OpenLog is meant to be mated with the weather:bit with the SD card facing into the board. Make sure the RXI on Openlog connects to TXO on the weather:bit. Using the |serial redirect| block choose TX as P15 and RX as P14 at a baud rate of 9600. The firmware on OpenLog will do the rest! When you want to review the data simple open the txt file created by OpenLog to view the data.

Example Project: The following project will read all atmospheric sensor data from the BME280 on button A press, will read all weather meter data on button B press, and aquaponics data on Button A+B press with all values from all sensors logged to OpenLog.

input.onButtonPressed(Button.AB, () => {
    basic.showNumber(weatherbit.soilTemperature())
    serial.writeValue("soil temperature", weatherbit.soilTemperature())
    basic.showNumber(weatherbit.soilMoisture())
    serial.writeValue("soil moisture", weatherbit.soilMoisture())
})
input.onButtonPressed(Button.A, () => {
    basic.showNumber(weatherbit.temperature())
    serial.writeValue("temperature", weatherbit.temperature())
    basic.showNumber(weatherbit.humidity())
    serial.writeValue("humidity", weatherbit.humidity())
    basic.showNumber(weatherbit.pressure())
    serial.writeValue("pressure", weatherbit.pressure())
    basic.showNumber(weatherbit.altitude())
    serial.writeValue("altitude", weatherbit.altitude())
})
input.onButtonPressed(Button.B, () => {
    basic.showNumber(weatherbit.windSpeed())
    serial.writeValue("wind speed", weatherbit.windSpeed())
    basic.showString(weatherbit.windDirection())
    basic.pause(300)
    // serial.writeValue("wind direction",
    // weatherbit.windDirection())
    basic.showNumber(weatherbit.rain())
    serial.writeValue("rain", weatherbit.rain())
})
weatherbit.startRainMonitoring()
weatherbit.startWindMonitoring()
weatherbit.startWeatherMonitoring()
serial.redirect(
SerialPin.P15,
SerialPin.P14,
BaudRate.BaudRate9600
)

License

MIT

Supported targets

  • for PXT/microbit

pxt-weather-bit's People

Contributors

adatadate avatar andyengland521 avatar englandsaurus avatar pelikhan avatar ryanjmortenson avatar seanburford avatar soubsoub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-weather-bit's Issues

BME280 reading issues.

Hello!

First thing first, I made use of weatherbit.ts to rewrite the code into C and mbed.
Secondly, when I try to read values from BME280, I end up with this:

Humidity: 100.0
Temperature: 0.0
Pressure: -31251.0
Altitude: 0

Anybody who can point me in the right direction?
Also, the code I used is available here.

Thank you very much.

Use ``pxt-open-log`` library to handle openlog

Hide away OpenLog details by creating a ```sparkfun/pxt-open-log`` package that takes care of setting serial, etc... The package can be cross-referenced through the pxt.json file and will be usefull in other shields/projects.

Add icon.png file

File will appear in "add package" list when searching. Use the SparkFun store image.

Possible fix for "start weather monitoring" not working in "on start" block

In the readme, you say:

Set Up Function
At the start of any program which will use the BME280 Sensor data (Pressure, Humidity, Altitude, Temperature) place the "Set up Weather Monitoring" in a "Forever" block. It is unknown at this time why this block will not work in the "On Start" block.

Is it possible that the "on start" block usually runs less than 2 ms after the BME280 gets power but the "forever" block usually starts after 2 ms? The BME280 datasheet lists tstartup (time to first communication after VDD and VDDIO at proper voltage) as 2ms (see section 1.1 General Electrical Specification, page 7 in the pdf I've got). Maybe I overlooked it, but I didn't notice anything in weatherbit.ts:startWeatherMonitoring() that looked like it would account for the start-up time.

I'm submitting this as an issue rather than pull request because I don't have a micro:bit or a weather:bit to test with, and I also am not set up to do PXT development. But, from reading your code, I'm wondering if it will magically start working if you do this:

screen shot 2017-09-01 at 9 17 26 pm

If so, then maybe you could fix the problem by adding a delay in startWeatherMonitoring() before trying to write to the I2C bus.

P.S. Your SEN-13676 BME280 breakout board is great.

Update Readme

-update readme to include new makecode site
-delete comment about where to place the "startweatheronitoring" block - this is now fixed.
-remove beta tags

Incompatibility with the Bluetooth extension.

If the Bluetooth extension is added to a project, the soilTemp function doesn't work. As far as tested, it will then always return the result -12. Presumably this means that it reads the value -2 from the sensor.
No Bluetooth function or service need to be added to the application. For example, the following MakeCode code will make the micro:bit display -12 if Bluetooth is added and a reasonable value (such as 2143) if Bluetooth is not added.

weatherbit.startWeatherMonitoring()
while (true) {
basic.showNumber(weatherbit.soilTemperature())
basic.pause(2000)
}

If the Bluetooth extension is added to a project, some code will be added to the application behind the scene, to make it possible to connect to the micro:bit using Bluetooth. Somehow this code interfers with the soilTemp function.

Tested with micro:bit firmware 0250.

Pressure problem

Hello,

probably you have changed something, but in version 0.0.19 pressure is not displaying correctly. In version 0.0.12 it was working smoothly.

Raw value from v0.0.12 (weatherbit.pressure()): 26479239
Formated value from v0.0.12 (Math.idiv(weatherbit.pressure(), 25600)): 1034 hPa

Raw value from v0.0.19 (weatherbit.pressure()): 49921
Formated value from v0.0.19 (Math.idiv(weatherbit.pressure(), 25600)): 1 hPa

icon.png is too large

The icon will be shown in the project dialog. It should be as light as possible (kb) while retaining a good visual quality.

Rain gauge counting double events about 80% of the time (and triple otherwise)

When using https://makecode.microbit.org, adding the weatherbit extension and looking at how rain (in inches) increases as the tipping bucket performs single events, I have noticed that, if I divide the rain measurement by 0.011, I observe that most of the events trigger a +2 in the reading, while about 15-20% I register +3. Never +1 as I would expect.

Unfortunately, I can't help with the code, since I don't know TS.

I have tried with 3 different weather stations and 3 different microbit cards, so the problem is quite reproducible.

These readings are obtained regardless of the bucket's speed or if it bounces a little or not.

Changing the baud rate did not have any effect.

Temperature doesn't change while program is running

Hi,

While in a forever loop, I cannot get the temperature to change from the weather:bit board. If I hold my finger over the sensor, the temperature remains constant until I reset the board.

I've tried the "Start Weather Monitoring" in a Start block and Forever block. I've tried the Start weather monitoring in the same forever block and set up. I've tried delays between the setup and reading section...

This is my latest attempt...

image

Thanks

Wind direction shows question marks if light measurement is in place

I've created a setup using my micro:bit and my weather:bit. I've set up the whole system.
I've wrote an example code (using makecode.microbit.org), which reads almost all sensor data (including the built in light sensor) and sends it over USB.

The problem is that the first measurement of wind direction is right, but after that I get three questionmarks. (https://github.com/sparkfun/pxt-weather-bit/blob/master/weatherbit.ts#L156)

If I limit the measurements to weather:bit related measurements, it works fine. Adding the light measurement ruins the wind measurement.

I've set up |start rain monitoring| and |start wind monitoring| on start, while the |start weather monitoring| is in the forever loop.

Validate the use of division operator in this package for MakeCode update

MakeCode for the micro:bit update is coming soon. Part of the update is floating point support. Existing MakeCode website supports only integer division which means
1/2 = 0
With this update 1/2 = 0.5

Action for you:
We have automatically detected this package uses division operator. Please take one of the following actions

  • If the change to floating point division doesn't matter you can ignore and close this issue.
  • If you want integer division then update your package typescript code to use integer division. Change a/b to Math.idiv(a, b)

You can test your package on the update here: https://makecode.microbit.org/beta

All the details on the update: https://makecode.com/blog/microbit/v1-beta

div found in weatherbit.ts

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.