SparkFun Forums 

Where electronics enthusiasts find answers.

#205566
Cannt Reading Wind Direction after reading LightLevel from MicroBit.
always get "???"
without "input.lightLevel()" is ok
I changed to a different microbit, but the same phenomenon occurred.

plz help.

Code this
--------------
input.onButtonPressed(Button.A, function () {
control.reset()
})
weatherbit.startWindMonitoring()
weatherbit.startRainMonitoring()
weatherbit.startWeatherMonitoring()

basic.forever(function () {
serial.writeLine(weatherbit.windDirection())
serial.writeLine("" + input.lightLevel())
basic.pause(1000)
})
#205637
Hi azuma52s,

It most likely is an issue with your code and, unfortunately, SparkFun's Tech Support cannot assist with debugging custom code. I would recommend adjusting the print statement for the Light Sensor to try and get it working or create a string for both Wind Direction and Light Level similar to the example here.
#205747
Sorry for any confusion here but the code you have written, while using the weather:bit extension, is not in any of our guides so that would constitute custom code. We cannot help you debug this but again, I would recommend referring to the completed examples from the Experiment Guide to identify what is causing the issue with your code with known-good example code.

Most likely, it is how you are trying to print the Light Sensor data since it constantly returns "???" meaning the print statement is probably invalid.
#205750
TS-Mark wrote: Wed Jul 10, 2019 3:48 pm Sorry for any confusion here but the code you have written, while using the weather:bit extension, is not in any of our guides so that would constitute custom code. We cannot help you debug this but again, I would recommend referring to the completed examples from the Experiment Guide to identify what is causing the issue with your code with known-good example code.

Most likely, it is how you are trying to print the Light Sensor data since it constantly returns "???" meaning the print statement is probably invalid.
OK. I remake the code most simple.

I bought another weather:bit to check hardware problem. but I got same problem.
code this. (sorry Im a Japanese)
You do not have the required permissions to view the files attached to this post.
#205809
Hi again,

I'm pretty sure it is a code issue since you're having the same issue with two boards. Try modifying the Light Level Experiment to redirect serial to USB. Then use the "Serial Write Number" block and duplicate the "Light Level" block and place that in the "serial write number" block. I tried that with a micro:bit here and it works just fine to print the light level values over serial to a terminal program. Here is the JavaScript of that MakeCode:
Code: Select all
let lightVal = 0
basic.forever(function () {
    serial.redirectToUSB()
    lightVal = input.lightLevel()
    serial.writeNumber(input.lightLevel())
})
I cannot help you get everything working together but hopefully this gives you a place to start. Also, the MakeCode Reference Page is a great resource to learn the various functions of MakeCode to keep learning and developing your own code.
#205817
I found a bug in ex. weatherbit.windDirection()
this function returns "???" after call input.lightlevel()

basic.forever(function () {
lightlevel = input.lightLevel()
let i = 0
for (i = 0; i < 5; i++) {
dir = weatherbit.windDirection()
basic.pause(1)
if (dir != "???") break;
}
serial.writeLine("" + i + ":" + dir + lightlevel)
})

'No one wants to admit self mistakes.'

outpus like this
3:S32
3:S33
2:S32
3:S33
3:S32
3:S33