sparkfun / pxt-weather-bit

MakeCode package for the SparkFun weather:bit board - beta
https://makecode.microbit.org/pkg/sparkfun/pxt-weather-bit
12 stars 22 forks source link

Incompatibility with the Bluetooth extension. #22

Closed mats1729 closed 5 years ago

mats1729 commented 5 years ago

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.

mats1729 commented 5 years ago

This seems to be an issue with the Bluetooth extension. The method getDigitalValue always returns MICROBIT_NOT_SUPPORTED.

mats1729 commented 5 years ago

The problem appears to be that the micro:bit pins are not properly initialized when the Bluetooth extension is added. Using the full constructors for the pins seems to solve the problem, e.g. MicroBitPin P12(MICROBIT_ID_IO_P12, MICROBIT_PIN_P12, PIN_CAPABILITY_DIGITAL); rather than MicroBitPin P12 = uBit.io.P12

AndyEngland521 commented 5 years ago

Hi @mats1729, looks like you fixed the issue, can I ask a favor and have you submit your code as a pull request so I can pull it in and release it? If not I'll have time in a few days when I'll be looking in depth into some issues. Make sure you bump the version number in pxt.json

apsoliveira commented 5 years ago

Hello @mats1729 and @AndyEngland521!

I experienced a similar issue with my Temperature Sensor (DS18B20), it was always returning the same temperature values: -12 (if I didn't divide the "soil temperature" function by 100) or 0 (if I divided the "soil temperature" function by 100). I put the sensors on cold water, hot water and soil samples and the result was always the same: temperature values of -12 or 0. On MakeCode I wasn't using the Bluetooth extension and the same issue was happening to me. I even removed the Radio extension and the problem persisted. So I used @mats1729 's fork as an extension on MakeCode with the update containing the full constructors lines for the pins (12 and 13) and it solved my problem too.

Thank you very much!!!

Patrícia

mats1729 commented 5 years ago

I tried to make a pull request, but it failed due to nodejs 8.9.4 not being available and the build timed out.

I would label my fix as a workaround, since I do not know why uBit.io.P12 and uBit.io.P12 are not properly initialized in some cases and how and where this should really be fixed. Since apsoliveira had the problem even though she didn't use Bluetooth, it is obviously not specific to Bluetooth even though in my case, it was triggered by the presence of Bluetooth.

@apsoliveira : thanks for sharing your information. I'm glad to hear that your problem was solved.

AndyEngland521 commented 5 years ago

@mats1729 no problem, I'll build your changes on my machine and push the version, thank you!

AndyEngland521 commented 5 years ago

Changes are in v0.0.14! Thanks @mats1729