I have a v2 microbit attached to a Raspberry Pi via USB (/dev/ttyACM0), which is running Node-Red. I want to show a weather icon on the Microbit, based on the 'weather' icon returned from the openweathermap node-red module. I can extract the icon (e.g. "03d') using the node-red flow and a 'serial' module, but am finding it impossible to get it to display on the microbit, which shows as 'connected' in the node-red flow. I'll eventually use a (probably really ugly) set of 'if' statements to get the icon from the returned code, but that seems a million miles away rn.
My code on the Microbit (which was built using Blocks) is:
serial.set_baud_rate(BaudRate.BAUD_RATE115200)
serial.set_rx_buffer_size(128)
def on_forever():
basic.show_string(serial.read_string())
basic.pause(5000)
basic.forever(on_forever)
That is just one version I have tried. The closest I have got is to receive the following:
[Object Object Object]
...on the microbit, which is odd because the debug message for the flow shows that the right payload is being passed to the serial node by the Pi.
I know this is probably obvious and is likely my misunderstanding of 'string' and 'number'. I have successfully written to a different microbit with a different pi, but that was a number, not a string. At the end of my tether. All advice greatly appreciated.
TIA, Warwick
ps. in an additional frustrating twist, I cannot use Mu to 'borrow' others code, as the microbit is a version that Mu 1.02 can't work with, and I've failed to update that (mu) too!
[EDIT to include Node-Red flow]
[
{
"id":"6ed3221a.52c58c",
"type":"inject",
"z":"1696e88b.74d287",
"name":".#.#.#.#.#.#.#.#.#.#.#.#.",
"props":[
{
"p":"payload"
}
],
"repeat":"10",
"crontab":"",
"once":false,
"onceDelay":0.1,
"topic":"",
"payload":".#.#.#.#.#.#.#.#.#.#.#.#.",
"payloadType":"str",
"x":560,
"y":120,
"wires":[
[
"af95ece7.418f2"
]
]
},
{
"id":"af95ece7.418f2",
"type":"serial out",
"z":"1696e88b.74d287",
"name":"",
"serial":"92c2150.d6fbee8",
"x":860,
"y":120,
"wires":[
]
},
{
"id":"92c2150.d6fbee8",
"type":"serial-port",
"serialport":"/dev/ttyACM0",
"serialbaud":"115200",
"databits":"8",
"parity":"none",
"stopbits":"1",
"waitfor":"",
"dtr":"none",
"rts":"none",
"cts":"none",
"dsr":"none",
"newline":"200",
"bin":"false",
"out":"time",
"addchar":"",
"responsetimeout":"10000"
}
]